diff options
Diffstat (limited to 'libjava/java')
1026 files changed, 0 insertions, 254750 deletions
diff --git a/libjava/java/applet/Applet.java b/libjava/java/applet/Applet.java deleted file mode 100644 index 861aaa95bff..00000000000 --- a/libjava/java/applet/Applet.java +++ /dev/null @@ -1,523 +0,0 @@ -/* Applet.java -- Java base applet class - Copyright (C) 1999, 2002, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.applet; - -import java.awt.Dimension; -import java.awt.GraphicsEnvironment; -import java.awt.HeadlessException; -import java.awt.Image; -import java.awt.Panel; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.Locale; - -import javax.accessibility.AccessibleContext; -import javax.accessibility.AccessibleRole; -import javax.accessibility.AccessibleState; -import javax.accessibility.AccessibleStateSet; - -/** - * This is the base applet class. An applet is a Java program that - * runs inside a web browser or other applet viewer in a restricted - * environment. - * - * <p>To be useful, a subclass should override at least start(). Also useful - * are init, stop, and destroy for control purposes, and getAppletInfo and - * getParameterInfo for descriptive purposes. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.0 - * @status updated to 1.4 - */ -public class Applet extends Panel -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = -5836846270535785031L; - - /** The applet stub for this applet. */ - private transient AppletStub stub; - - /** Some applets call setSize in their constructors. In that case, - these fields are used to store width and height values until a - stub is set. */ - private transient int width; - private transient int height; - - /** - * The accessibility context for this applet. - * - * @serial the accessibleContext for this - * @since 1.2 - */ - private AccessibleContext accessibleContext; - - /** - * Default constructor for subclasses. - * - * @throws HeadlessException if in a headless environment - */ - public Applet() - { - if (GraphicsEnvironment.isHeadless()) - throw new HeadlessException(); - } - - /** - * The browser calls this method to set the applet's stub, which is the - * low level interface to the browser. Manually setting this to null is - * asking for problems down the road. - * - * @param stub the applet stub for this applet - */ - public final void setStub(AppletStub stub) - { - this.stub = stub; - - if (width != 0 && height != 0) - stub.appletResize (width, height); - } - - /** - * Tests whether or not this applet is currently active. An applet is active - * just before the browser invokes start(), and becomes inactive just - * before the browser invokes stop(). - * - * @return <code>true</code> if this applet is active - */ - public boolean isActive() - { - return stub.isActive(); - } - - /** - * Returns the basename URL of the document this applet is embedded in. This - * is everything up to the final '/'. - * - * @return the URL of the document this applet is embedded in - * @see #getCodeBase() - */ - public URL getDocumentBase() - { - return stub.getDocumentBase(); - } - - /** - * Returns the URL of the code base for this applet. - * - * @return the URL of the code base for this applet - */ - public URL getCodeBase() - { - return stub.getCodeBase(); - } - - /** - * Returns the value of the specified parameter that was specified in - * the <code><APPLET></code> tag for this applet. - * - * @param name the parameter name - * @return the parameter value, or null if the parameter does not exist - * @throws NullPointerException if name is null - */ - public String getParameter(String name) - { - return stub.getParameter(name); - } - - /** - * Returns the applet context for this applet. - * - * @return the applet context for this applet - */ - public AppletContext getAppletContext() - { - return stub.getAppletContext(); - } - - /** - * Requests that the applet window for this applet be resized. - * - * @param width the new width in pixels - * @param height the new height in pixels - */ - public void resize(int width, int height) - { - if (stub == null) - { - this.width = width; - this.height = height; - } - else - stub.appletResize(width, height); - } - - /** - * Requests that the applet window for this applet be resized. - * - * @param dim the requested dimensions - * @throws NullPointerException if dim is null - */ - public void resize(Dimension dim) - { - resize(dim.width, dim.height); - } - - /** - * Displays the specified message in the status window if that window - * exists. - * - * @param message the status message, may be null - */ - public void showStatus(String message) - { - getAppletContext().showStatus(message); - } - - /** - * Returns an image from the specified URL. Note that the image is not - * actually retrieved until the applet attempts to display it, so this - * method returns immediately. - * - * @param url the URL of the image - * @return the retrieved image - * @throws NullPointerException if url is null - */ - public Image getImage(URL url) - { - return getAppletContext().getImage(url); - } - - /** - * Returns an image from the specified absolute URL, and relative path - * from that URL. Note that the image is not actually retrieved until the - * applet attempts to display it, so this method returns immediately. - * This calls <code>getImage(new URL(url, name))</code>, but if building - * the new URL fails, this returns null. - * - * @param url the base URL of the image - * @param name the name of the image relative to the URL - * @return the retrieved image, or null on failure - * @see #getImage(URL) - */ - public Image getImage(URL url, String name) - { - try - { - return getImage(new URL(url, name)); - } - catch (MalformedURLException e) - { - return null; - } - } - - /** - * Returns an audio clip from the specified URL. This clip is not tied to - * any particular applet. - * - * XXX Classpath does not yet implement this. - * - * @param url the URL of the audio clip - * @return the retrieved audio clip - * @throws NullPointerException if url is null - * @see #getAudioClip(URL) - * @since 1.2 - */ - public static final AudioClip newAudioClip(URL url) - { - // This requires an implementation of AudioClip in gnu.java.applet. - throw new Error("Not implemented"); - } - - /** - * Returns an audio clip from the specified URL. Note that the clip is not - * actually retrieved until the applet attempts to play it, so this method - * returns immediately. - * - * @param url the URL of the audio clip - * @return the retrieved audio clip - * @throws NullPointerException if url is null - */ - public AudioClip getAudioClip(URL url) - { - return getAppletContext().getAudioClip(url); - } - - /** - * Returns an audio clip from the specified absolute URL, and relative path - * from that URL. Note that the clip is not actually retrieved until the - * applet attempts to play it, so this method returns immediately. This - * calls <code>getAudioClip(new URL(url, name))</code>, but if building - * the new URL fails, this returns null. - * - * @param url the base URL of the audio clip - * @param name the name of the clip relative to the URL - * @return the retrieved audio clip, or null on failure - * @see #getAudioClip(URL) - */ - public AudioClip getAudioClip(URL url, String name) - { - try - { - return getAudioClip(new URL(url, name)); - } - catch (MalformedURLException e) - { - return null; - } - } - - /** - * Returns a descriptive string with applet defined information. The - * implementation in this class returns <code>null</code>, so subclasses - * must override to return information. - * - * @return a string describing the author, version, and applet copyright - */ - public String getAppletInfo() - { - return null; - } - - /** - * Returns the locale for this applet, if it has been set. If no applet - * specific locale has been set, the default locale is returned. - * - * @return the locale for this applet - * @see Component#setLocale(Locale) - * @since 1.1 - */ - public Locale getLocale() - { - return super.getLocale(); - } - - /** - * Returns a list of parameters this applet supports. Each element of - * the outer array is an array of three strings with the name of the - * parameter, the data type or valid values, and a description. This - * method is optional and the default implementation returns null. - * - * @return the list of parameters supported by this applet - */ - public String[][] getParameterInfo() - { - return null; - } - - /** - * Loads and plays the audio clip pointed to by the specified URL. This does - * nothing if the URL does not point to a valid audio clip. - * - * @param url the URL of the audio clip - * @throws NullPointerException if url is null - * @see #getAudioClip(URL) - */ - public void play(URL url) - { - AudioClip ac = getAudioClip(url); - try - { - ac.play(); - } - catch (Exception ignored) - { - } - } - - /** - * Loads and plays the audio clip pointed to by the specified absolute URL, - * and relative path from that URL. This does nothing if the URL cannot be - * constructed, or if it does not point to a valid audio clip. - * - * @param url the base URL of the audio clip - * @param name the name of the audio clip relative to the URL - * @see #getAudioClip(URL, String) - * @see #play(URL) - */ - public void play(URL url, String name) - { - try - { - getAudioClip(url, name).play(); - } - catch (Exception ignored) - { - } - } - - /** - * This method is called when the applet is first loaded, before start(). - * The default implementation does nothing; override to do any one-time - * initialization. - * - * @see #start() - * @see #stop() - * @see #destroy() - */ - public void init() - { - } - - /** - * This method is called when the applet should start running. This is - * normally each time a web page containing it is loaded. The default - * implemention does nothing; override for your applet to be useful. - * - * @see #init() - * @see #stop() - * @see #destroy() - */ - public void start() - { - } - - /** - * This method is called when the applet should stop running. This is - * normally when the next web page is loaded. The default implementation - * does nothing; override for your applet to stop using resources when - * it is no longer visible, but may be restarted soon. - * - * @see #init() - * @see #start() - * @see #destroy() - */ - public void stop() - { - } - - /** - * This method is called when the applet is being unloaded. The default - * implementation does nothing; override for your applet to clean up - * resources on exit. - * - * @see #init() - * @see #start() - * @see #stop() - */ - public void destroy() - { - } - - /** - * Gets the AccessibleContext associated with this applet, creating one if - * necessary. This always returns an instance of {@link AccessibleApplet}. - * - * @return the accessibility context of this applet - * @since 1.3 - */ - public AccessibleContext getAccessibleContext() - { - if (accessibleContext == null) - accessibleContext = new AccessibleApplet(); - return accessibleContext; - } - - /** - * Read an applet from an object stream. This checks for a headless - * environment, then does the normal read. - * - * @param s the stream to read from - * @throws ClassNotFoundException if a class is not found - * @throws IOException if deserialization fails - * @throws HeadlessException if this is a headless environment - * @see GraphicsEnvironment#isHeadless() - * @since 1.4 - */ - private void readObject(ObjectInputStream s) - throws ClassNotFoundException, IOException - { - if (GraphicsEnvironment.isHeadless()) - throw new HeadlessException(); - s.defaultReadObject(); - } - - /** - * This class provides accessibility support for Applets, and is the - * runtime type returned by {@link #getAccessibleContext()}. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.3 - */ - protected class AccessibleApplet extends AccessibleAWTPanel - { - /** - * Compatible with JDK 1.4+. - */ - private static final long serialVersionUID = 8127374778187708896L; - - /** - * The default constructor. - */ - protected AccessibleApplet() - { - } - - /** - * Get the role of this accessible object, a frame. - * - * @return the role of the object - * @see AccessibleRole#FRAME - */ - public AccessibleRole getAccessibleRole() - { - return AccessibleRole.FRAME; - } - - /** - * Get the state set of this accessible object. In addition to the default - * states of a Component, the applet can also be active. - * - * @return the role of the object - * @see AccessibleState - */ - public AccessibleStateSet getAccessibleStateSet() - { - AccessibleStateSet s = super.getAccessibleStateSet(); - if (isActive()) - s.add(AccessibleState.ACTIVE); - return s; - } - } // class AccessibleApplet -} // class Applet diff --git a/libjava/java/applet/AppletContext.java b/libjava/java/applet/AppletContext.java deleted file mode 100644 index a17508fd4a4..00000000000 --- a/libjava/java/applet/AppletContext.java +++ /dev/null @@ -1,154 +0,0 @@ -/* AppletContext.java -- access the applet's runtime environment - Copyright (C) 1999, 2002, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.applet; - -import java.awt.Image; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.util.Enumeration; -import java.util.Iterator; - -/** - * This interface allows an applet access to the browser to retrieve - * additional data files and display documents. It also allows the - * applet to find out other applets in the same document. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @since 1.0 - * @status updated to 1.4 - */ -public interface AppletContext -{ - /** - * Returns an audio clip from the specified URL. - * - * @param url the URL of the audio clip - * @return the retrieved audio clip - * @throws NullPointerException if url is null - */ - AudioClip getAudioClip(URL url); - - /** - * Returns an image from the specified URL. Note that the image is not - * actually retrieved until the applet attempts to display it, so this - * method returns immediately. - * - * @param url the absolute URL of the image - * @return the retrieved image - * @throws NullPointerException if url is null - */ - Image getImage(URL url); - - /** - * Returns the applet in the document for this object that has the - * specified name. - * - * @param name the applet name - * @return the requested applet, or <code>null</code> if not found - */ - Applet getApplet(String name); - - /** - * Returns a list of all the applets in the document for this object. - * - * @return a list of all the applets - */ - Enumeration getApplets(); - - /** - * Displays the web page pointed to by the specified URL in the window - * for this object. This page replaces the document that is currently - * there. - * - * @param url the URL of the web page to load; unspecified on an error - */ - void showDocument(URL url); - - /** - * Displays the web page pointed to be the sepcified URL in the window - * with the specified name. The standard names "_top", "_blank", - * "_parent", and "_self" are allowed. An applet viewer may disregard - * this request. - * - * @param url the URL of the web page to load - * @param target the target window - */ - void showDocument(URL url, String target); - - /** - * Displays the specified message in the status window if that window - * exists. - * - * @param message the status message, may be null - */ - void showStatus(String message); - - /** - * Associate a stream to a key for this applet context, possibly replacing - * the old value. Stream associations are local to the applet context, for - * security purposes. - * - * @param key the key to associate with - * @param stream the stream value to tie to the key, or null to remove - * @throws IOException if the stream is too large - * @since 1.4 - */ - void setStream(String key, InputStream stream) throws IOException; - - /** - * Return the stream associated with a given key in this applet context, or - * null if nothing is associated. Stream associations are local to the - * applet context, for security purposes. - * - * @param key the key to look up - * @return the associated stream, or null - * @since 1.4 - */ - InputStream getStream(String key); - - /** - * Iterate over all keys that have associated streams. Stream associated - * are local to the applet context, for security purposes. - * - * @return an iterator over the association keys - * @since 1.4 - */ - Iterator getStreamKeys(); -} // interface AppletContext diff --git a/libjava/java/applet/AppletStub.java b/libjava/java/applet/AppletStub.java deleted file mode 100644 index 879a01638a5..00000000000 --- a/libjava/java/applet/AppletStub.java +++ /dev/null @@ -1,103 +0,0 @@ -/* AppletStub.java -- low level interface to the browser - Copyright (C) 1999, 2002, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.applet; - -import java.net.URL; - -/** - * This interface is the low level interface between the applet and the - * browser. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @see Applet#setStub(AppletStub) - * @since 1.0 - * @status updated to 1.4 - */ -public interface AppletStub -{ - /** - * Tests whether or not this applet is currently active. An applet is active - * just before the browser invokes start(), and becomes inactive just - * before the browser invokes stop(). - * - * @return <code>true</code> if this applet is active - */ - boolean isActive(); - - /** - * Returns the basename URL of the document this applet is embedded in. This - * is everything up to the final '/'. - * - * @return the URL of the document this applet is embedded in - * @see #getCodeBase() - */ - URL getDocumentBase(); - - /** - * Returns the URL of the code base for this applet. - * - * @return the URL of the code base for this applet - */ - URL getCodeBase(); - - /** - * Returns the value of the specified parameter that was specified in - * the <code><APPLET></code> tag for this applet. - * - * @param name the parameter name - * @return the parameter value, or null if the parameter does not exist - * @throws NullPointerException if name is null - */ - String getParameter(String name); - - /** - * Returns the applet context for this applet. - * - * @return the applet context for this applet - */ - AppletContext getAppletContext(); - - /** - * Requests that the applet window for this applet be resized. - * - * @param width the new width in pixels - * @param height the new height in pixels - */ - void appletResize(int width, int height); -} // interface AppletStub diff --git a/libjava/java/applet/AudioClip.java b/libjava/java/applet/AudioClip.java deleted file mode 100644 index eeafa8aa7a8..00000000000 --- a/libjava/java/applet/AudioClip.java +++ /dev/null @@ -1,68 +0,0 @@ -/* AudioClip.java -- play an audio clip in an applet - Copyright (C) 1999, 2002, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.applet; - - -/** - * This interface provides a simple mechanism for playing audio clips. - * If multiple clips are played at once, the browser combines them into a - * composite clip. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @since 1.0 - * @status updated to 1.4 - */ -public interface AudioClip -{ - /** - * Plays the audio clip starting from the beginning. - */ - void play(); - - /** - * Stops playing this audio clip. There is no mechanism for restarting - * at the point where the clip is stopped. - */ - void stop(); - - /** - * Plays this audio clip in a continuous loop. - */ - void loop(); -} // interface AudioClip diff --git a/libjava/java/awt/AWTError.java b/libjava/java/awt/AWTError.java deleted file mode 100644 index 80356eee440..00000000000 --- a/libjava/java/awt/AWTError.java +++ /dev/null @@ -1,64 +0,0 @@ -/* AWTError.java -- A serious AWT error occurred. - Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -/** - * This error is thrown when a critical Abstract Window Toolkit (AWT) error - * occurs. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @status updated to 1.4 - */ -public class AWTError extends Error -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = -1819846354050686206L; - - /** - * Create a new instance with the specified descriptive error message. - * - * @param message the descriptive error message - */ - public AWTError(String message) - { - super(message); - } -} // class AWTError diff --git a/libjava/java/awt/AWTEvent.java b/libjava/java/awt/AWTEvent.java deleted file mode 100644 index b90a9090988..00000000000 --- a/libjava/java/awt/AWTEvent.java +++ /dev/null @@ -1,286 +0,0 @@ -/* AWTEvent.java -- the root event in AWT - Copyright (C) 1999, 2000, 2002, 2005 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.util.EventObject; - -/** - * AWTEvent is the root event class for all AWT events in the JDK 1.1 event - * model. It supersedes the Event class from JDK 1.0. Subclasses outside of - * the java.awt package should have IDs greater than RESERVED_ID_MAX. - * - * <p>Event masks defined here are used by components in - * <code>enableEvents</code> to select event types not selected by registered - * listeners. Event masks are appropriately set when registering on - * components. - * - * @author Warren Levy (warrenl@cygnus.com) - * @author Aaron M. Renn (arenn@urbanophile.com) - * @since 1.1 - * @status updated to 1.4 - */ -public abstract class AWTEvent extends EventObject -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = -1825314779160409405L; - - /** - * The ID of the event. - * - * @see #getID() - * @see #AWTEvent(Object, int) - * @serial the identifier number of this event - */ - protected int id; - - /** - * Indicates if the event has been consumed. False mean it is passed to - * the peer, true means it has already been processed. Semantic events - * generated by low-level events always have the value true. - * - * @see #consume() - * @see #isConsumed() - * @serial whether the event has been consumed - */ - protected boolean consumed; - - /** - * Who knows? It's in the serial version. - * - * @serial No idea what this is for. - */ - byte[] bdata; - - /** Mask for selecting component events. */ - public static final long COMPONENT_EVENT_MASK = 0x00001; - - /** Mask for selecting container events. */ - public static final long CONTAINER_EVENT_MASK = 0x00002; - - /** Mask for selecting component focus events. */ - public static final long FOCUS_EVENT_MASK = 0x00004; - - /** Mask for selecting keyboard events. */ - public static final long KEY_EVENT_MASK = 0x00008; - - /** Mask for mouse button events. */ - public static final long MOUSE_EVENT_MASK = 0x00010; - - /** Mask for mouse motion events. */ - public static final long MOUSE_MOTION_EVENT_MASK = 0x00020; - - /** Mask for window events. */ - public static final long WINDOW_EVENT_MASK = 0x00040; - - /** Mask for action events. */ - public static final long ACTION_EVENT_MASK = 0x00080; - - /** Mask for adjustment events. */ - public static final long ADJUSTMENT_EVENT_MASK = 0x00100; - - /** Mask for item events. */ - public static final long ITEM_EVENT_MASK = 0x00200; - - /** Mask for text events. */ - public static final long TEXT_EVENT_MASK = 0x00400; - - /** - * Mask for input method events. - * @since 1.3 - */ - public static final long INPUT_METHOD_EVENT_MASK = 0x00800; - - /** - * Mask if input methods are enabled. Package visible only. - */ - static final long INPUT_ENABLED_EVENT_MASK = 0x01000; - - /** - * Mask for paint events. - * @since 1.3 - */ - public static final long PAINT_EVENT_MASK = 0x02000; - - /** - * Mask for invocation events. - * @since 1.3 - */ - public static final long INVOCATION_EVENT_MASK = 0x04000; - - /** - * Mask for hierarchy events. - * @since 1.3 - */ - public static final long HIERARCHY_EVENT_MASK = 0x08000; - - /** - * Mask for hierarchy bounds events. - * @since 1.3 - */ - public static final long HIERARCHY_BOUNDS_EVENT_MASK = 0x10000; - - /** - * Mask for mouse wheel events. - * @since 1.4 - */ - public static final long MOUSE_WHEEL_EVENT_MASK = 0x20000; - - /** - * Mask for window state events. - * @since 1.4 - */ - public static final long WINDOW_STATE_EVENT_MASK = 0x40000; - - /** - * Mask for window focus events. - * @since 1.4 - */ - public static final long WINDOW_FOCUS_EVENT_MASK = 0x80000; - - /** - * This is the highest number for event ids that are reserved for use by - * the AWT system itself. Subclasses outside of java.awt should use higher - * ids. - */ - public static final int RESERVED_ID_MAX = 1999; - - - /** - * Initializes a new AWTEvent from the old Java 1.0 event object. - * - * @param event the old-style event - * @throws NullPointerException if event is null - */ - public AWTEvent(Event event) - { - this(event.target, event.id); - consumed = event.consumed; - } - - /** - * Create an event on the specified source object and id. - * - * @param source the object that caused the event - * @param id the event id - * @throws IllegalArgumentException if source is null - */ - public AWTEvent(Object source, int id) - { - super(source); - this.id = id; - } - - /** - * Retarget the event, such as converting a heavyweight component to a - * lightweight child of the original. This is not for general use, but - * is for event targeting systems like KeyboardFocusManager. - * - * @param source the new source - */ - public void setSource(Object source) - { - this.source = source; - } - - /** - * Returns the event type id. - * - * @return the id number of this event - */ - public int getID() - { - return id; - } - - /** - * Create a string that represents this event in the format - * <code>classname[eventstring] on sourcecomponentname</code>. - * - * @return a string representing this event - */ - public String toString () - { - String string = null; - - if (source instanceof Component) - string = getClass ().getName () + "[" + paramString () + "] on " - + ((Component) source).getName (); - else if (source instanceof MenuComponent) - string = getClass ().getName () + "[" + paramString () + "] on " - + ((MenuComponent) source).getName (); - else - string = getClass ().getName () + "[" + paramString () + "] on " - + source; - - return string; - } - - /** - * Returns a string representation of the state of this event. It may be - * empty, but must not be null; it is implementation defined. - * - * @return a string representation of this event - */ - public String paramString() - { - return ""; - } - - /** - * Consumes this event so that it will not be processed in the default - * manner. - */ - protected void consume() - { - consumed = true; - } - - /** - * Tests whether not not this event has been consumed. A consumed event - * is not processed in the default manner. - * - * @return true if this event has been consumed - */ - protected boolean isConsumed() - { - return consumed; - } -} // class AWTEvent diff --git a/libjava/java/awt/AWTEventMulticaster.java b/libjava/java/awt/AWTEventMulticaster.java deleted file mode 100644 index f7b9163cf67..00000000000 --- a/libjava/java/awt/AWTEventMulticaster.java +++ /dev/null @@ -1,1209 +0,0 @@ -/* AWTEventMulticaster.java -- allows multicast chaining of listeners - Copyright (C) 1999, 2000, 2002 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.AdjustmentEvent; -import java.awt.event.AdjustmentListener; -import java.awt.event.ComponentEvent; -import java.awt.event.ComponentListener; -import java.awt.event.ContainerEvent; -import java.awt.event.ContainerListener; -import java.awt.event.FocusEvent; -import java.awt.event.FocusListener; -import java.awt.event.HierarchyBoundsListener; -import java.awt.event.HierarchyEvent; -import java.awt.event.HierarchyListener; -import java.awt.event.InputMethodEvent; -import java.awt.event.InputMethodListener; -import java.awt.event.ItemEvent; -import java.awt.event.ItemListener; -import java.awt.event.KeyEvent; -import java.awt.event.KeyListener; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; -import java.awt.event.MouseMotionListener; -import java.awt.event.MouseWheelEvent; -import java.awt.event.MouseWheelListener; -import java.awt.event.TextEvent; -import java.awt.event.TextListener; -import java.awt.event.WindowEvent; -import java.awt.event.WindowFocusListener; -import java.awt.event.WindowListener; -import java.awt.event.WindowStateListener; -import java.io.IOException; -import java.io.ObjectOutputStream; -import java.io.Serializable; -import java.lang.reflect.Array; -import java.util.ArrayList; -import java.util.EventListener; - -/** - * This class is used to implement a chain of event handlers. Dispatching - * using this class is thread safe. Here is a quick example of how to - * add and delete listeners using this class. For this example, we will - * assume are firing <code>AdjustmentEvent</code>'s. However, this - * same approach is useful for all events in the <code>java.awt.event</code> - * package, and more if this class is subclassed. - * - * <p><code> - * AdjustmentListener al; - * public void addAdjustmentListener(AdjustmentListener listener) - * { - * al = AWTEventMulticaster.add(al, listener); - * } - * public void removeAdjustmentListener(AdjustmentListener listener) - * { - * al = AWTEventMulticaster.remove(al, listener); - * } - * </code> - * - * <p>When it come time to process an event, simply call <code>al</code>, - * assuming it is not <code>null</code>, and all listeners in the chain will - * be fired. - * - * <p>The first time <code>add</code> is called it is passed - * <code>null</code> and <code>listener</code> as its arguments. This - * starts building the chain. This class returns <code>listener</code> - * which becomes the new <code>al</code>. The next time, <code>add</code> - * is called with <code>al</code> and <code>listener</code> and the - * new listener is then chained to the old. - * - * @author Bryce McKinlay - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.1 - * @status updated to 1.4 - */ -public class AWTEventMulticaster - implements ComponentListener, ContainerListener, FocusListener, KeyListener, - MouseListener, MouseMotionListener, WindowListener, - WindowFocusListener, WindowStateListener, ActionListener, - ItemListener, AdjustmentListener, TextListener, - InputMethodListener, HierarchyListener, HierarchyBoundsListener, - MouseWheelListener -{ - /** - * A variable in the event chain. - */ - protected final EventListener a; - - /** - * A variable in the event chain. - */ - protected final EventListener b; - - /** - * Initializes a new instance of <code>AWTEventMulticaster</code> with - * the specified event listener parameters. The parameters should not be - * null, although it is not required to enforce this with a - * NullPointerException. - * - * @param a the "a" listener object - * @param b the "b" listener object - */ - protected AWTEventMulticaster(EventListener a, EventListener b) - { - this.a = a; - this.b = b; - } - - /** - * Removes one instance of the specified listener from this multicaster - * chain. This descends recursively if either child is a multicaster, and - * returns a multicaster chain with the old listener removed. - * - * @param oldl the object to remove from this multicaster - * @return the resulting multicaster with the specified listener removed - */ - protected EventListener remove(EventListener oldl) - { - // If oldl is an immediate child, return the other child. - if (a == oldl) - return b; - if (b == oldl) - return a; - // If a and/or b are Multicaster's, search them recursively. - if (a instanceof AWTEventMulticaster) - { - EventListener newa = ((AWTEventMulticaster) a).remove(oldl); - if (newa != a) - return new AWTEventMulticaster(newa, b); - } - if (b instanceof AWTEventMulticaster) - { - EventListener newb = ((AWTEventMulticaster) b).remove(oldl); - if (newb != b) - return new AWTEventMulticaster(a, newb); - } - // oldl was not found. - return this; - } - - /** - * Handles this event by dispatching it to the "a" and "b" listener - * instances. - * - * @param e the event to handle - */ - public void componentResized(ComponentEvent e) - { - ((ComponentListener) a).componentResized(e); - ((ComponentListener) b).componentResized(e); - } - - /** - * Handles this event by dispatching it to the "a" and "b" listener - * instances. - * - * @param e the event to handle - */ - public void componentMoved(ComponentEvent e) - { - ((ComponentListener) a).componentMoved(e); - ((ComponentListener) b).componentMoved(e); - } - - /** - * Handles this event by dispatching it to the "a" and "b" listener - * instances. - * - * @param e the event to handle - */ - public void componentShown(ComponentEvent e) - { - ((ComponentListener) a).componentShown(e); - ((ComponentListener) b).componentShown(e); - } - - /** - * Handles this event by dispatching it to the "a" and "b" listener - * instances. - * - * @param e the event to handle - */ - public void componentHidden(ComponentEvent e) - { - ((ComponentListener) a).componentHidden(e); - ((ComponentListener) b).componentHidden(e); - } - - /** - * Handles this event by dispatching it to the "a" and "b" listener - * instances. - * - * @param e the event to handle - */ - public void componentAdded(ContainerEvent e) - { - ((ContainerListener) a).componentAdded(e); - ((ContainerListener) b).componentAdded(e); - } - - /** - * Handles this event by dispatching it to the "a" and "b" listener - * instances. - * - * @param e the event to handle - */ - public void componentRemoved(ContainerEvent e) - { - ((ContainerListener) a).componentRemoved(e); - ((ContainerListener) b).componentRemoved(e); - } - - /** - * Handles this event by dispatching it to the "a" and "b" listener - * instances. - * - * @param e the event to handle - */ - public void focusGained(FocusEvent e) - { - ((FocusListener) a).focusGained(e); - ((FocusListener) b).focusGained(e); - } - - /** - * Handles this event by dispatching it to the "a" and "b" listener - * instances. - * - * @param e the event to handle - */ - public void focusLost(FocusEvent e) - { - ((FocusListener) a).focusLost(e); - ((FocusListener) b).focusLost(e); - } - - /** - * Handles this event by dispatching it to the "a" and "b" listener - * instances. - * - * @param e the event to handle - */ - public void keyTyped(KeyEvent e) - { - ((KeyListener) a).keyTyped(e); - ((KeyListener) b).keyTyped(e); - } - - /** - * Handles this event by dispatching it to the "a" and "b" listener - * instances. - * - * @param e the event to handle - */ - public void keyPressed(KeyEvent e) - { - ((KeyListener) a).keyPressed(e); - ((KeyListener) b).keyPressed(e); - } - - /** - * Handles this event by dispatching it to the "a" and "b" listener - * instances. - * - * @param e the event to handle - */ - public void keyReleased(KeyEvent e) - { - ((KeyListener) a).keyReleased(e); - ((KeyListener) b).keyReleased(e); - } - - /** - * Handles this event by dispatching it to the "a" and "b" listener - * instances. - * - * @param e the event to handle - */ - public void mouseClicked(MouseEvent e) - { - ((MouseListener) a).mouseClicked(e); - ((MouseListener) b).mouseClicked(e); - } - - /** - * Handles this event by dispatching it to the "a" and "b" listener - * instances. - * - * @param e the event to handle - */ - public void mousePressed(MouseEvent e) - { - ((MouseListener) a).mousePressed(e); - ((MouseListener) b).mousePressed(e); - } - - /** - * Handles this event by dispatching it to the "a" and "b" listener - * instances. - * - * @param e the event to handle - */ - public void mouseReleased(MouseEvent e) - { - ((MouseListener) a).mouseReleased(e); - ((MouseListener) b).mouseReleased(e); - } - - /** - * Handles this event by dispatching it to the "a" and "b" listener - * instances. - * - * @param e the event to handle - */ - public void mouseEntered(MouseEvent e) - { - ((MouseListener) a).mouseEntered(e); - ((MouseListener) b).mouseEntered(e); - } - - /** - * Handles this event by dispatching it to the "a" and "b" listener - * instances. - * - * @param e the event to handle - */ - public void mouseExited(MouseEvent e) - { - ((MouseListener) a).mouseExited(e); - ((MouseListener) b).mouseExited(e); - } - - /** - * Handles this event by dispatching it to the "a" and "b" listener - * instances. - * - * @param e the event to handle - */ - public void mouseDragged(MouseEvent e) - { - ((MouseMotionListener) a).mouseDragged(e); - ((MouseMotionListener) b).mouseDragged(e); - } - - /** - * Handles this event by dispatching it to the "a" and "b" listener - * instances. - * - * @param e the event to handle - */ - public void mouseMoved(MouseEvent e) - { - ((MouseMotionListener) a).mouseMoved(e); - ((MouseMotionListener) b).mouseMoved(e); - } - - /** - * Handles this event by dispatching it to the "a" and "b" listener - * instances. - * - * @param e the event to handle - */ - public void windowOpened(WindowEvent e) - { - ((WindowListener) a).windowOpened(e); - ((WindowListener) b).windowOpened(e); - } - - /** - * Handles this event by dispatching it to the "a" and "b" listener - * instances. - * - * @param e the event to handle - */ - public void windowClosing(WindowEvent e) - { - ((WindowListener) a).windowClosing(e); - ((WindowListener) b).windowClosing(e); - } - - /** - * Handles this event by dispatching it to the "a" and "b" listener - * instances. - * - * @param e the event to handle - */ - public void windowClosed(WindowEvent e) - { - ((WindowListener) a).windowClosed(e); - ((WindowListener) b).windowClosed(e); - } - - /** - * Handles this event by dispatching it to the "a" and "b" listener - * instances. - * - * @param e the event to handle - */ - public void windowIconified(WindowEvent e) - { - ((WindowListener) a).windowIconified(e); - ((WindowListener) b).windowIconified(e); - } - - /** - * Handles this event by dispatching it to the "a" and "b" listener - * instances. - * - * @param e the event to handle - */ - public void windowDeiconified(WindowEvent e) - { - ((WindowListener) a).windowDeiconified(e); - ((WindowListener) b).windowDeiconified(e); - } - - /** - * Handles this event by dispatching it to the "a" and "b" listener - * instances. - * - * @param e the event to handle - */ - public void windowActivated(WindowEvent e) - { - ((WindowListener) a).windowActivated(e); - ((WindowListener) b).windowActivated(e); - } - - /** - * Handles this event by dispatching it to the "a" and "b" listener - * instances. - * - * @param e the event to handle - */ - public void windowDeactivated(WindowEvent e) - { - ((WindowListener) a).windowDeactivated(e); - ((WindowListener) b).windowDeactivated(e); - } - - /** - * Handles this event by dispatching it to the "a" and "b" listener - * instances. - * - * @param e the event to handle - * @since 1.4 - */ - public void windowStateChanged(WindowEvent e) - { - ((WindowStateListener) a).windowStateChanged(e); - ((WindowStateListener) b).windowStateChanged(e); - } - - /** - * Handles this event by dispatching it to the "a" and "b" listener - * instances. - * - * @param e the event to handle - * @since 1.4 - */ - public void windowGainedFocus(WindowEvent e) - { - ((WindowFocusListener) a).windowGainedFocus(e); - ((WindowFocusListener) b).windowGainedFocus(e); - } - - /** - * Handles this event by dispatching it to the "a" and "b" listener - * instances. - * - * @param e the event to handle - * @since 1.4 - */ - public void windowLostFocus(WindowEvent e) - { - ((WindowFocusListener) a).windowLostFocus(e); - ((WindowFocusListener) b).windowLostFocus(e); - } - - /** - * Handles this event by dispatching it to the "a" and "b" listener - * instances. - * - * @param e the event to handle - */ - public void actionPerformed(ActionEvent e) - { - ((ActionListener) a).actionPerformed(e); - ((ActionListener) b).actionPerformed(e); - } - - /** - * Handles this event by dispatching it to the "a" and "b" listener - * instances. - * - * @param e the event to handle - */ - public void itemStateChanged(ItemEvent e) - { - ((ItemListener) a).itemStateChanged(e); - ((ItemListener) b).itemStateChanged(e); - } - - /** - * Handles this event by dispatching it to the "a" and "b" listener - * instances. - * - * @param e the event to handle - */ - public void adjustmentValueChanged(AdjustmentEvent e) - { - ((AdjustmentListener) a).adjustmentValueChanged(e); - ((AdjustmentListener) b).adjustmentValueChanged(e); - } - - /** - * Handles this event by dispatching it to the "a" and "b" listener - * instances. - * - * @param e the event to handle - */ - public void textValueChanged(TextEvent e) - { - ((TextListener) a).textValueChanged(e); - ((TextListener) b).textValueChanged(e); - } - - /** - * Handles this event by dispatching it to the "a" and "b" listener - * instances. - * - * @param e the event to handle - * @since 1.2 - */ - public void inputMethodTextChanged(InputMethodEvent e) - { - ((InputMethodListener) a).inputMethodTextChanged(e); - ((InputMethodListener) b).inputMethodTextChanged(e); - } - - /** - * Handles this event by dispatching it to the "a" and "b" listener - * instances. - * - * @param e the event to handle - * @since 1.2 - */ - public void caretPositionChanged(InputMethodEvent e) - { - ((InputMethodListener) a).caretPositionChanged(e); - ((InputMethodListener) b).caretPositionChanged(e); - } - - /** - * Handles this event by dispatching it to the "a" and "b" listener - * instances. - * - * @param e the event to handle - * @since 1.3 - */ - public void hierarchyChanged(HierarchyEvent e) - { - ((HierarchyListener) a).hierarchyChanged(e); - ((HierarchyListener) b).hierarchyChanged(e); - } - - /** - * Handles this event by dispatching it to the "a" and "b" listener - * instances. - * - * @param e the event to handle - * @since 1.3 - */ - public void ancestorMoved(HierarchyEvent e) - { - ((HierarchyBoundsListener) a).ancestorMoved(e); - ((HierarchyBoundsListener) b).ancestorMoved(e); - } - - /** - * Handles this event by dispatching it to the "a" and "b" listener - * instances. - * - * @param e the event to handle - * @since 1.3 - */ - public void ancestorResized(HierarchyEvent e) - { - ((HierarchyBoundsListener) a).ancestorResized(e); - ((HierarchyBoundsListener) b).ancestorResized(e); - } - - /** - * Handles this event by dispatching it to the "a" and "b" listener - * instances. - * - * @param e the event to handle - * @since 1.4 - */ - public void mouseWheelMoved(MouseWheelEvent e) - { - ((MouseWheelListener) a).mouseWheelMoved(e); - ((MouseWheelListener) b).mouseWheelMoved(e); - } - - /** - * Chain <code>ComponentListener</code> a and b. - * - * @param a the "a" listener, may be null - * @param b the "b" listener, may be null - * @return latest entry in the chain - */ - public static ComponentListener add(ComponentListener a, ComponentListener b) - { - return (ComponentListener) addInternal(a, b); - } - - /** - * Chain <code>ContainerListener</code> a and b. - * - * @param a the "a" listener, may be null - * @param b the "b" listener, may be null - * @return latest entry in the chain - */ - public static ContainerListener add(ContainerListener a, ContainerListener b) - { - return (ContainerListener) addInternal(a, b); - } - - /** - * Chain <code>FocusListener</code> a and b. - * - * @param a the "a" listener, may be null - * @param b the "b" listener, may be null - * @return latest entry in the chain - */ - public static FocusListener add(FocusListener a, FocusListener b) - { - return (FocusListener) addInternal(a, b); - } - - /** - * Chain <code>KeyListener</code> a and b. - * - * @param a the "a" listener, may be null - * @param b the "b" listener, may be null - * @return latest entry in the chain - */ - public static KeyListener add(KeyListener a, KeyListener b) - { - return (KeyListener) addInternal(a, b); - } - - /** - * Chain <code>MouseListener</code> a and b. - * - * @param a the "a" listener, may be null - * @param b the "b" listener, may be null - * @return latest entry in the chain - */ - public static MouseListener add(MouseListener a, MouseListener b) - { - return (MouseListener) addInternal(a, b); - } - - /** - * Chain <code>MouseMotionListener</code> a and b. - * - * @param a the "a" listener, may be null - * @param b the "b" listener, may be null - * @return latest entry in the chain - */ - public static MouseMotionListener add(MouseMotionListener a, - MouseMotionListener b) - { - return (MouseMotionListener) addInternal(a, b); - } - - /** - * Chain <code>WindowListener</code> a and b. - * - * @param a the "a" listener, may be null - * @param b the "b" listener, may be null - * @return latest entry in the chain - */ - public static WindowListener add(WindowListener a, WindowListener b) - { - return (WindowListener) addInternal(a, b); - } - - /** - * Chain <code>WindowStateListener</code> a and b. - * - * @param a the "a" listener, may be null - * @param b the "b" listener, may be null - * @return latest entry in the chain - * @since 1.4 - */ - public static WindowStateListener add(WindowStateListener a, - WindowStateListener b) - { - return (WindowStateListener) addInternal(a, b); - } - - /** - * Chain <code>WindowFocusListener</code> a and b. - * - * @param a the "a" listener, may be null - * @param b the "b" listener, may be null - * @return latest entry in the chain - * @since 1.4 - */ - public static WindowFocusListener add(WindowFocusListener a, - WindowFocusListener b) - { - return (WindowFocusListener) addInternal(a, b); - } - - /** - * Chain <code>ActionListener</code> a and b. - * - * @param a the "a" listener, may be null - * @param b the "b" listener, may be null - * @return latest entry in the chain - */ - public static ActionListener add(ActionListener a, ActionListener b) - { - return (ActionListener) addInternal(a, b); - } - - /** - * Chain <code>ItemListener</code> a and b. - * - * @param a the "a" listener, may be null - * @param b the "b" listener, may be null - * @return latest entry in the chain - */ - public static ItemListener add(ItemListener a, ItemListener b) - { - return (ItemListener) addInternal(a, b); - } - - /** - * Chain <code>AdjustmentListener</code> a and b. - * - * @param a the "a" listener, may be null - * @param b the "b" listener, may be null - * @return latest entry in the chain - */ - public static AdjustmentListener add(AdjustmentListener a, - AdjustmentListener b) - { - return (AdjustmentListener) addInternal(a, b); - } - - /** - * Chain <code>AdjustmentListener</code> a and b. - * - * @param a the "a" listener, may be null - * @param b the "b" listener, may be null - * @return latest entry in the chain - */ - public static TextListener add(TextListener a, TextListener b) - { - return (TextListener) addInternal(a, b); - } - - /** - * Chain <code>InputMethodListener</code> a and b. - * - * @param a the "a" listener, may be null - * @param b the "b" listener, may be null - * @return latest entry in the chain - * @since 1.2 - */ - public static InputMethodListener add(InputMethodListener a, - InputMethodListener b) - { - return (InputMethodListener) addInternal(a, b); - } - - /** - * Chain <code>HierarchyListener</code> a and b. - * - * @param a the "a" listener, may be null - * @param b the "b" listener, may be null - * @return latest entry in the chain - * @since 1.3 - */ - public static HierarchyListener add(HierarchyListener a, HierarchyListener b) - { - return (HierarchyListener) addInternal(a, b); - } - - /** - * Chain <code>HierarchyBoundsListener</code> a and b. - * - * @param a the "a" listener, may be null - * @param b the "b" listener, may be null - * @return latest entry in the chain - * @since 1.3 - */ - public static HierarchyBoundsListener add(HierarchyBoundsListener a, - HierarchyBoundsListener b) - { - return (HierarchyBoundsListener) addInternal(a, b); - } - - /** - * Chain <code>MouseWheelListener</code> a and b. - * - * @param a the "a" listener, may be null - * @param b the "b" listener, may be null - * @return latest entry in the chain - * @since 1.4 - */ - public static MouseWheelListener add(MouseWheelListener a, - MouseWheelListener b) - { - return (MouseWheelListener) addInternal(a, b); - } - - /** - * Removes the listener <code>oldl</code> from the listener <code>l</code>. - * - * @param l the listener chain to reduce - * @param oldl the listener to remove - * @return the resulting listener chain - */ - public static ComponentListener remove(ComponentListener l, - ComponentListener oldl) - { - return (ComponentListener) removeInternal(l, oldl); - } - - /** - * Removes the listener <code>oldl</code> from the listener <code>l</code>. - * - * @param l the listener chain to reduce - * @param oldl the listener to remove - * @return the resulting listener chain - */ - public static ContainerListener remove(ContainerListener l, - ContainerListener oldl) - { - return (ContainerListener) removeInternal(l, oldl); - } - - /** - * Removes the listener <code>oldl</code> from the listener <code>l</code>. - * - * @param l the listener chain to reduce - * @param oldl the listener to remove - * @return the resulting listener chain - */ - public static FocusListener remove(FocusListener l, FocusListener oldl) - { - return (FocusListener) removeInternal(l, oldl); - } - - /** - * Removes the listener <code>oldl</code> from the listener <code>l</code>. - * - * @param l the listener chain to reduce - * @param oldl the listener to remove - * @return the resulting listener chain - */ - public static KeyListener remove(KeyListener l, KeyListener oldl) - { - return (KeyListener) removeInternal(l, oldl); - } - - /** - * Removes the listener <code>oldl</code> from the listener <code>l</code>. - * - * @param l the listener chain to reduce - * @param oldl the listener to remove - * @return the resulting listener chain - */ - public static MouseListener remove(MouseListener l, MouseListener oldl) - { - return (MouseListener) removeInternal(l, oldl); - } - - /** - * Removes the listener <code>oldl</code> from the listener <code>l</code>. - * - * @param l the listener chain to reduce - * @param oldl the listener to remove - * @return the resulting listener chain - */ - public static MouseMotionListener remove(MouseMotionListener l, - MouseMotionListener oldl) - { - return (MouseMotionListener) removeInternal(l, oldl); - } - - /** - * Removes the listener <code>oldl</code> from the listener <code>l</code>. - * - * @param l the listener chain to reduce - * @param oldl the listener to remove - * @return the resulting listener chain - */ - public static WindowListener remove(WindowListener l, WindowListener oldl) - { - return (WindowListener) removeInternal(l, oldl); - } - - /** - * Removes the listener <code>oldl</code> from the listener <code>l</code>. - * - * @param l the listener chain to reduce - * @param oldl the listener to remove - * @return the resulting listener chain - * @since 1.4 - */ - public static WindowStateListener remove(WindowStateListener l, - WindowStateListener oldl) - { - return (WindowStateListener) removeInternal(l, oldl); - } - - /** - * Removes the listener <code>oldl</code> from the listener <code>l</code>. - * - * @param l the listener chain to reduce - * @param oldl the listener to remove - * @return the resulting listener chain - * @since 1.4 - */ - public static WindowFocusListener remove(WindowFocusListener l, - WindowFocusListener oldl) - { - return (WindowFocusListener) removeInternal(l, oldl); - } - - /** - * Removes the listener <code>oldl</code> from the listener <code>l</code>. - * - * @param l the listener chain to reduce - * @param oldl the listener to remove - * @return the resulting listener chain - */ - public static ActionListener remove(ActionListener l, ActionListener oldl) - { - return (ActionListener) removeInternal(l, oldl); - } - - /** - * Removes the listener <code>oldl</code> from the listener <code>l</code>. - * - * @param l the listener chain to reduce - * @param oldl the listener to remove - * @return the resulting listener chain - */ - public static ItemListener remove(ItemListener l, ItemListener oldl) - { - return (ItemListener) removeInternal(l, oldl); - } - - /** - * Removes the listener <code>oldl</code> from the listener <code>l</code>. - * - * @param l the listener chain to reduce - * @param oldl the listener to remove - * @return the resulting listener chain - */ - public static AdjustmentListener remove(AdjustmentListener l, - AdjustmentListener oldl) - { - return (AdjustmentListener) removeInternal(l, oldl); - } - - /** - * Removes the listener <code>oldl</code> from the listener <code>l</code>. - * - * @param l the listener chain to reduce - * @param oldl the listener to remove - * @return the resulting listener chain - */ - public static TextListener remove(TextListener l, TextListener oldl) - { - return (TextListener) removeInternal(l, oldl); - } - - /** - * Removes the listener <code>oldl</code> from the listener <code>l</code>. - * - * @param l the listener chain to reduce - * @param oldl the listener to remove - * @return the resulting listener chain - * @since 1.2 - */ - public static InputMethodListener remove(InputMethodListener l, - InputMethodListener oldl) - { - return (InputMethodListener) removeInternal(l, oldl); - } - - /** - * Removes the listener <code>oldl</code> from the listener <code>l</code>. - * - * @param l the listener chain to reduce - * @param oldl the listener to remove - * @return the resulting listener chain - * @since 1.3 - */ - public static HierarchyListener remove(HierarchyListener l, - HierarchyListener oldl) - { - return (HierarchyListener) removeInternal(l, oldl); - } - - /** - * Removes the listener <code>oldl</code> from the listener <code>l</code>. - * - * @param l the listener chain to reduce - * @param oldl the listener to remove - * @return the resulting listener chain - * @since 1.3 - */ - public static HierarchyBoundsListener remove(HierarchyBoundsListener l, - HierarchyBoundsListener oldl) - { - return (HierarchyBoundsListener) removeInternal(l, oldl); - } - - /** - * Removes the listener <code>oldl</code> from the listener <code>l</code>. - * - * @param l the listener chain to reduce - * @param oldl the listener to remove - * @return the resulting listener chain - * @since 1.4 - */ - public static MouseWheelListener remove(MouseWheelListener l, - MouseWheelListener oldl) - { - return (MouseWheelListener) removeInternal(l, oldl); - } - - /** - * Chain <code>EventListener</code> a and b. - * - * @param a the "a" listener, may be null - * @param b the "b" listener, may be null - * @return latest entry in the chain - */ - protected static EventListener addInternal(EventListener a, EventListener b) - { - if (a == null) - return b; - if (b == null) - return a; - return new AWTEventMulticaster(a, b); - } - - /** - * Removes the listener <code>oldl</code> from the listener <code>l</code>. - * - * @param l the listener chain to reduce - * @param oldl the listener to remove - * @return the resulting listener chain - */ - protected static EventListener removeInternal(EventListener l, - EventListener oldl) - { - if (l == oldl) - return null; - if (l instanceof AWTEventMulticaster) - return ((AWTEventMulticaster) l).remove(oldl); - return l; - } - - /** - * Saves all Serializable listeners to a serialization stream. - * - * @param s the stream to save to - * @param k a prefix stream put before each serializable listener - * @throws IOException if serialization fails - */ - protected void saveInternal(ObjectOutputStream s, String k) - throws IOException - { - // This is not documented by Sun, but I think it is correct. - if (a instanceof AWTEventMulticaster) - ((AWTEventMulticaster) a).saveInternal(s, k); - else if (a instanceof Serializable) - { - s.writeObject(k); - s.writeObject(a); - } - if (b instanceof AWTEventMulticaster) - ((AWTEventMulticaster) b).saveInternal(s, k); - else if (b instanceof Serializable) - { - s.writeObject(k); - s.writeObject(b); - } - } - - /** - * Saves a Serializable listener chain to a serialization stream. - * - * @param s the stream to save to - * @param k a prefix stream put before each serializable listener - * @param l the listener chain to save - * @throws IOException if serialization fails - */ - protected static void save(ObjectOutputStream s, String k, EventListener l) - throws IOException - { - // This is not documented by Sun, but I think it is correct. - if (l instanceof AWTEventMulticaster) - ((AWTEventMulticaster) l).saveInternal(s, k); - else if (l instanceof Serializable) - { - s.writeObject(k); - s.writeObject(l); - } - } - - /** - * Returns an array of all chained listeners of the specified type in the - * given chain. A null listener returns an empty array, and a listener - * which is not an AWTEventMulticaster returns an array of one element. If - * no listeners in the chain are of the specified type, an empty array is - * returned. - * - * @param l the listener chain to convert to an array - * @param type the type of listeners to collect - * @return an array of the listeners of that type in the chain - * @throws ClassCastException if type is not assignable from EventListener - * @throws NullPointerException if type is null - * @throws IllegalArgumentException if type is Void.TYPE - * @since 1.4 - */ - public static EventListener[] getListeners(EventListener l, Class type) - { - ArrayList list = new ArrayList(); - if (l instanceof AWTEventMulticaster) - ((AWTEventMulticaster) l).getListeners(list, type); - else if (type.isInstance(l)) - list.add(l); - EventListener[] r = (EventListener[]) Array.newInstance(type, list.size()); - list.toArray(r); - return r; - } - - /** - * Collects all instances of the given type in the chain into the list. - * - * @param l the list to collect into - * @param type the type of listeners to collect - * @throws NullPointerException if type is null - * @see #getListeners(EventListener, Class) - */ - private void getListeners(ArrayList l, Class type) - { - if (a instanceof AWTEventMulticaster) - ((AWTEventMulticaster) a).getListeners(l, type); - else if (type.isInstance(a)) - l.add(a); - if (b instanceof AWTEventMulticaster) - ((AWTEventMulticaster) b).getListeners(l, type); - else if (type.isInstance(b)) - l.add(b); - } -} // class AWTEventMulticaster diff --git a/libjava/java/awt/AWTException.java b/libjava/java/awt/AWTException.java deleted file mode 100644 index 2df3dd80102..00000000000 --- a/libjava/java/awt/AWTException.java +++ /dev/null @@ -1,64 +0,0 @@ -/* AWTException.java -- Generic AWT exception - Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -/** - * This is a generic exception that indicates an exception occurred in the - * Abstract Window Toolkit (AWT) system. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @status updated to 1.4 - */ -public class AWTException extends Exception -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = -1900414231151323879L; - - /** - * Create a new instance with the specified detailed error message. - * - * @param message the detailed error message - */ - public AWTException(String message) - { - super(message); - } -} // class AWTException diff --git a/libjava/java/awt/AWTKeyStroke.java b/libjava/java/awt/AWTKeyStroke.java deleted file mode 100644 index 01d169366e0..00000000000 --- a/libjava/java/awt/AWTKeyStroke.java +++ /dev/null @@ -1,659 +0,0 @@ -/* AWTKeyStroke.java -- an immutable key stroke - Copyright (C) 2002, 2004, 2005 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.awt.event.KeyEvent; -import java.io.ObjectStreamException; -import java.io.Serializable; -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.security.PrivilegedActionException; -import java.security.PrivilegedExceptionAction; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.StringTokenizer; - -/** - * This class mirrors KeyEvents, representing both low-level key presses and - * key releases, and high level key typed inputs. However, this class forms - * immutable strokes, and can be efficiently reused via the factory methods - * for creating them. - * - * <p>For backwards compatibility with Swing, this supports a way to build - * instances of a subclass, using reflection, provided the subclass has a - * no-arg constructor (of any accessibility). - * - * @author Eric Blake (ebb9@email.byu.edu) - * @see #getAWTKeyStroke(char) - * @since 1.4 - * @status updated to 1.4 - */ -public class AWTKeyStroke implements Serializable -{ - /** - * Compatible with JDK 1.4+. - */ - private static final long serialVersionUID = -6430539691155161871L; - - /** The mask for modifiers. */ - private static final int MODIFIERS_MASK = 0x3fef; - - /** - * The cache of recently created keystrokes. This maps KeyStrokes to - * KeyStrokes in a cache which removes the least recently accessed entry, - * under the assumption that garbage collection of a new keystroke is - * easy when we find the old one that it matches in the cache. - */ - private static final LinkedHashMap cache = new LinkedHashMap(11, 0.75f, true) - { - /** The largest the keystroke cache can grow. */ - private static final int MAX_CACHE_SIZE = 2048; - - /** Prune stale entries. */ - protected boolean removeEldestEntry(Map.Entry eldest) - { // XXX - FIXME Use Map.Entry, not just Entry as gcj 3.1 workaround. - return size() > MAX_CACHE_SIZE; - } - }; - - /** The most recently generated keystroke, or null. */ - private static AWTKeyStroke recent; - - /** - * The no-arg constructor of a subclass, or null to use AWTKeyStroke. Note - * that this will be left accessible, to get around private access; but - * it should not be a security risk as it is highly unlikely that creating - * protected instances of the subclass via reflection will do much damage. - */ - private static Constructor ctor; - - /** - * A table of keyCode names to values. This is package-private to - * avoid an accessor method. - * - * @see #getAWTKeyStroke(String) - */ - static final HashMap vktable = new HashMap(); - static - { - // Using reflection saves the hassle of keeping this in sync with KeyEvent, - // at the price of an expensive initialization. - AccessController.doPrivileged(new PrivilegedAction() - { - public Object run() - { - Field[] fields = KeyEvent.class.getFields(); - int i = fields.length; - try - { - while (--i >= 0) - { - Field f = fields[i]; - String name = f.getName(); - if (name.startsWith("VK_")) - vktable.put(name.substring(3), f.get(null)); - } - } - catch (Exception e) - { - throw (Error) new InternalError().initCause(e); - } - return null; - } - }); - } - - /** - * The typed character, or CHAR_UNDEFINED for key presses and releases. - * - * @serial the keyChar - */ - private char keyChar; - - /** - * The virtual key code, or VK_UNDEFINED for key typed. Package visible for - * use by Component. - * - * @serial the keyCode - */ - int keyCode; - - /** - * The modifiers in effect. To match Sun, this stores the old style masks - * for shift, control, alt, meta, and alt-graph (but not button1); as well - * as the new style of extended modifiers for all modifiers. - * - * @serial bitwise or of the *_DOWN_MASK modifiers - */ - private int modifiers; - - /** - * True if this is a key release; should only be true if keyChar is - * CHAR_UNDEFINED. - * - * @serial true to distinguish key pressed from key released - */ - private boolean onKeyRelease; - - /** - * Construct a keystroke with default values: it will be interpreted as a - * key typed event with an invalid character and no modifiers. Client code - * should use the factory methods instead. - * - * @see #getAWTKeyStroke(char) - * @see #getAWTKeyStroke(Character, int) - * @see #getAWTKeyStroke(int, int, boolean) - * @see #getAWTKeyStroke(int, int) - * @see #getAWTKeyStrokeForEvent(KeyEvent) - * @see #getAWTKeyStroke(String) - */ - protected AWTKeyStroke() - { - keyChar = KeyEvent.CHAR_UNDEFINED; - } - - /** - * Construct a keystroke with the given values. Client code should use the - * factory methods instead. - * - * @param keyChar the character entered, if this is a key typed - * @param keyCode the key pressed or released, or VK_UNDEFINED for key typed - * @param modifiers the modifier keys for the keystroke, in old or new style - * @param onKeyRelease true if this is a key release instead of a press - * @see #getAWTKeyStroke(char) - * @see #getAWTKeyStroke(Character, int) - * @see #getAWTKeyStroke(int, int, boolean) - * @see #getAWTKeyStroke(int, int) - * @see #getAWTKeyStrokeForEvent(KeyEvent) - * @see #getAWTKeyStroke(String) - */ - protected AWTKeyStroke(char keyChar, int keyCode, int modifiers, - boolean onKeyRelease) - { - this.keyChar = keyChar; - this.keyCode = keyCode; - // No need to call extend(), as only trusted code calls this constructor. - this.modifiers = modifiers; - this.onKeyRelease = onKeyRelease; - } - - /** - * Registers a new subclass as being the type of keystrokes to generate in - * the factory methods. This operation flushes the cache of stored keystrokes - * if the class differs from the current one. The new class must be - * AWTKeyStroke or a subclass, and must have a no-arg constructor (which may - * be private). - * - * @param subclass the new runtime type of generated keystrokes - * @throws IllegalArgumentException subclass doesn't have no-arg constructor - * @throws ClassCastException subclass doesn't extend AWTKeyStroke - */ - protected static void registerSubclass(final Class subclass) - { - if (subclass == null) - throw new IllegalArgumentException(); - if (subclass.equals(ctor == null ? AWTKeyStroke.class - : ctor.getDeclaringClass())) - return; - if (subclass.equals(AWTKeyStroke.class)) - { - cache.clear(); - recent = null; - ctor = null; - return; - } - try - { - ctor = (Constructor) AccessController.doPrivileged - (new PrivilegedExceptionAction() - { - public Object run() - throws NoSuchMethodException, InstantiationException, - IllegalAccessException, InvocationTargetException - { - Constructor c = subclass.getDeclaredConstructor(null); - c.setAccessible(true); - // Create a new instance, to make sure that we can, and - // to cause any ClassCastException. - AWTKeyStroke dummy = (AWTKeyStroke) c.newInstance(null); - return c; - } - }); - } - catch (PrivilegedActionException e) - { - // e.getCause() will not ever be ClassCastException; that should - // escape on its own. - throw (RuntimeException) - new IllegalArgumentException().initCause(e.getCause()); - } - cache.clear(); - recent = null; - } - - /** - * Returns a keystroke representing a typed character. - * - * @param keyChar the typed character - * @return the specified keystroke - */ - public static AWTKeyStroke getAWTKeyStroke(char keyChar) - { - return getAWTKeyStroke(keyChar, KeyEvent.VK_UNDEFINED, 0, false); - } - - /** - * Returns a keystroke representing a typed character with the given - * modifiers. Note that keyChar is a <code>Character</code> instead of a - * <code>char</code> to avoid accidental ambiguity with - * <code>getAWTKeyStroke(int, int)</code>. The modifiers are the bitwise - * or of the masks found in {@link InputEvent}; the new style (*_DOWN_MASK) - * is preferred, but the old style will work. - * - * @param keyChar the typed character - * @param modifiers the modifiers, or 0 - * @return the specified keystroke - * @throws IllegalArgumentException if keyChar is null - */ - public static AWTKeyStroke getAWTKeyStroke(Character keyChar, int modifiers) - { - if (keyChar == null) - throw new IllegalArgumentException(); - return getAWTKeyStroke(keyChar.charValue(), KeyEvent.VK_UNDEFINED, - extend(modifiers), false); - } - - /** - * Returns a keystroke representing a pressed or released key event, with - * the given modifiers. The "virtual key" should be one of the VK_* - * constants in {@link KeyEvent}. The modifiers are the bitwise or of the - * masks found in {@link InputEvent}; the new style (*_DOWN_MASK) is - * preferred, but the old style will work. - * - * @param keyCode the virtual key - * @param modifiers the modifiers, or 0 - * @param release true if this is a key release instead of a key press - * @return the specified keystroke - */ - public static AWTKeyStroke getAWTKeyStroke(int keyCode, int modifiers, - boolean release) - { - return getAWTKeyStroke(KeyEvent.CHAR_UNDEFINED, keyCode, - extend(modifiers), release); - } - - /** - * Returns a keystroke representing a pressed key event, with the given - * modifiers. The "virtual key" should be one of the VK_* constants in - * {@link KeyEvent}. The modifiers are the bitwise or of the masks found - * in {@link InputEvent}; the new style (*_DOWN_MASK) is preferred, but the - * old style will work. - * - * @param keyCode the virtual key - * @param modifiers the modifiers, or 0 - * @return the specified keystroke - */ - public static AWTKeyStroke getAWTKeyStroke(int keyCode, int modifiers) - { - return getAWTKeyStroke(KeyEvent.CHAR_UNDEFINED, keyCode, - extend(modifiers), false); - } - - /** - * Returns a keystroke representing what caused the key event. - * - * @param event the key event to convert - * @return the specified keystroke, or null if the event is invalid - * @throws NullPointerException if event is null - */ - public static AWTKeyStroke getAWTKeyStrokeForEvent(KeyEvent event) - { - switch (event.id) - { - case KeyEvent.KEY_TYPED: - return getAWTKeyStroke(event.getKeyChar(), KeyEvent.VK_UNDEFINED, - extend(event.getModifiersEx()), false); - case KeyEvent.KEY_PRESSED: - return getAWTKeyStroke(KeyEvent.CHAR_UNDEFINED, event.getKeyCode(), - extend(event.getModifiersEx()), false); - case KeyEvent.KEY_RELEASED: - return getAWTKeyStroke(KeyEvent.CHAR_UNDEFINED, event.getKeyCode(), - extend(event.getModifiersEx()), true); - default: - return null; - } - } - - /** - * Parses a string and returns the keystroke that it represents. The syntax - * for keystrokes is listed below, with tokens separated by an arbitrary - * number of spaces: - * <pre> - * keyStroke := <modifiers>* ( <typedID> | <codeID> ) - * modifiers := ( shift | control | ctrl | meta | alt - * | button1 | button2 | button3 ) - * typedID := typed <single Unicode character> - * codeID := ( pressed | released )? <name> - * name := <the KeyEvent field name less the leading "VK_"> - * </pre> - * - * <p>Note that the grammar is rather weak, and not all valid keystrokes - * can be generated in this manner (for example, a typed space, or anything - * with the alt-graph modifier!). The output of AWTKeyStroke.toString() - * will not meet the grammar. If pressed or released is not specified, - * pressed is assumed. Examples:<br> - * <code> - * "INSERT" => getAWTKeyStroke(KeyEvent.VK_INSERT, 0);<br> - * "control DELETE" => - * getAWTKeyStroke(KeyEvent.VK_DELETE, InputEvent.CTRL_MASK);<br> - * "alt shift X" => getAWTKeyStroke(KeyEvent.VK_X, - * InputEvent.ALT_MASK | InputEvent.SHIFT_MASK);<br> - * "alt shift released X" => getAWTKeyStroke(KeyEvent.VK_X, - * InputEvent.ALT_MASK | InputEvent.SHIFT_MASK, true);<br> - * "typed a" => getAWTKeyStroke('a'); - * </code> - * - * @param s the string to parse - * @throws IllegalArgumentException if s is null or cannot be parsed - * @return the specified keystroke - */ - public static AWTKeyStroke getAWTKeyStroke(String s) - { - if (s == null) - throw new IllegalArgumentException("null argument"); - StringTokenizer t = new StringTokenizer(s, " "); - if (! t.hasMoreTokens()) - throw new IllegalArgumentException("no tokens '" + s + "'"); - int modifiers = 0; - boolean released = false; - String token = null; - do - { - token = t.nextToken(); - if ("shift".equals(token)) - modifiers |= KeyEvent.SHIFT_DOWN_MASK; - else if ("ctrl".equals(token) || "control".equals(token)) - modifiers |= KeyEvent.CTRL_DOWN_MASK; - else if ("meta".equals(token)) - modifiers |= KeyEvent.META_DOWN_MASK; - else if ("alt".equals(token)) - modifiers |= KeyEvent.ALT_DOWN_MASK; - else if ("button1".equals(token)) - modifiers |= KeyEvent.BUTTON1_DOWN_MASK; - else if ("button2".equals(token)) - modifiers |= KeyEvent.BUTTON2_DOWN_MASK; - else if ("button3".equals(token)) - modifiers |= KeyEvent.BUTTON3_DOWN_MASK; - else if ("typed".equals(token)) - { - if (t.hasMoreTokens()) - { - token = t.nextToken(); - if (! t.hasMoreTokens() && token.length() == 1) - return getAWTKeyStroke(token.charAt(0), - KeyEvent.VK_UNDEFINED, modifiers, - false); - } - throw new IllegalArgumentException("Invalid 'typed' argument '" - + s + "'"); - } - else if ("pressed".equals(token)) - { - if (t.hasMoreTokens()) - token = t.nextToken(); - break; - } - else if ("released".equals(token)) - { - released = true; - if (t.hasMoreTokens()) - token = t.nextToken(); - break; - } - else - break; - } - while (t.hasMoreTokens()); - // Now token contains the VK name we must parse. - Integer code = (Integer) vktable.get(token); - if (code == null) - throw new IllegalArgumentException("Unknown token '" + token - + "' in '" + s + "'"); - if (t.hasMoreTokens()) - throw new IllegalArgumentException("Too many tokens: " + s); - return getAWTKeyStroke(KeyEvent.CHAR_UNDEFINED, code.intValue(), - modifiers, released); - } - - /** - * Returns the character of this keystroke, if it was typed. - * - * @return the character value, or CHAR_UNDEFINED - * @see #getAWTKeyStroke(char) - */ - public final char getKeyChar() - { - return keyChar; - } - - /** - * Returns the virtual key code of this keystroke, if it was pressed or - * released. This will be a VK_* constant from KeyEvent. - * - * @return the virtual key code value, or VK_UNDEFINED - * @see #getAWTKeyStroke(int, int) - */ - public final int getKeyCode() - { - return keyCode; - } - - /** - * Returns the modifiers for this keystroke. This will be a bitwise or of - * constants from InputEvent; it includes the old style masks for shift, - * control, alt, meta, and alt-graph (but not button1); as well as the new - * style of extended modifiers for all modifiers. - * - * @return the modifiers - * @see #getAWTKeyStroke(Character, int) - * @see #getAWTKeyStroke(int, int) - */ - public final int getModifiers() - { - return modifiers; - } - - /** - * Tests if this keystroke is a key release. - * - * @return true if this is a key release - * @see #getAWTKeyStroke(int, int, boolean) - */ - public final boolean isOnKeyRelease() - { - return onKeyRelease; - } - - /** - * Returns the AWT event type of this keystroke. This is one of - * {@link KeyEvent#KEY_TYPED}, {@link KeyEvent#KEY_PRESSED}, or - * {@link KeyEvent#KEY_RELEASED}. - * - * @return the key event type - */ - public final int getKeyEventType() - { - return keyCode == KeyEvent.VK_UNDEFINED ? KeyEvent.KEY_TYPED - : onKeyRelease ? KeyEvent.KEY_RELEASED : KeyEvent.KEY_PRESSED; - } - - /** - * Returns a hashcode for this key event. It is not documented, but appears - * to be: <code>(getKeyChar() + 1) * (getKeyCode() + 1) - * * (getModifiers() + 1) * 2 + (isOnKeyRelease() ? 1 : 2)</code>. - * - * @return the hashcode - */ - public int hashCode() - { - return (keyChar + 1) * (keyCode + 1) * (modifiers + 1) * 2 - + (onKeyRelease ? 1 : 2); - } - - /** - * Tests two keystrokes for equality. - * - * @param o the object to test - * @return true if it is equal - */ - public final boolean equals(Object o) - { - if (! (o instanceof AWTKeyStroke)) - return false; - AWTKeyStroke s = (AWTKeyStroke) o; - return this == o || (keyChar == s.keyChar && keyCode == s.keyCode - && modifiers == s.modifiers - && onKeyRelease == s.onKeyRelease); - } - - /** - * Returns a string representation of this keystroke. For typed keystrokes, - * this is <code>"keyChar " + KeyEvent.getKeyModifiersText(getModifiers()) - + getKeyChar()</code>; for pressed and released keystrokes, this is - * <code>"keyCode " + KeyEvent.getKeyModifiersText(getModifiers()) - * + KeyEvent.getKeyText(getKeyCode()) - * + (isOnKeyRelease() ? "-R" : "-P")</code>. - * - * @return a string representation - */ - public String toString() - { - if (keyCode == KeyEvent.VK_UNDEFINED) - return "keyChar " + KeyEvent.getKeyModifiersText(modifiers) + keyChar; - return "keyCode " + KeyEvent.getKeyModifiersText(modifiers) - + KeyEvent.getKeyText(keyCode) + (onKeyRelease ? "-R" : "-P"); - } - - /** - * Returns a cached version of the deserialized keystroke, if available. - * - * @return a cached replacement - * @throws ObjectStreamException if something goes wrong - */ - protected Object readResolve() throws ObjectStreamException - { - AWTKeyStroke s = (AWTKeyStroke) cache.get(this); - if (s != null) - return s; - cache.put(this, this); - return this; - } - - /** - * Gets the appropriate keystroke, creating one if necessary. - * - * @param keyChar the keyChar - * @param keyCode the keyCode - * @param modifiers the modifiers - * @param release true for key release - * @return the specified keystroke - */ - private static AWTKeyStroke getAWTKeyStroke(char keyChar, int keyCode, - int modifiers, boolean release) - { - // Check level 0 cache. - AWTKeyStroke stroke = recent; // Avoid thread races. - if (stroke != null && stroke.keyChar == keyChar - && stroke.keyCode == keyCode && stroke.modifiers == modifiers - && stroke.onKeyRelease == release) - return stroke; - // Create a new object, on the assumption that if it has a match in the - // cache, the VM can easily garbage collect it as it is temporary. - Constructor c = ctor; // Avoid thread races. - if (c == null) - stroke = new AWTKeyStroke(keyChar, keyCode, modifiers, release); - else - try - { - stroke = (AWTKeyStroke) c.newInstance(null); - stroke.keyChar = keyChar; - stroke.keyCode = keyCode; - stroke.modifiers = modifiers; - stroke.onKeyRelease = release; - } - catch (Exception e) - { - throw (Error) new InternalError().initCause(e); - } - // Check level 1 cache. - AWTKeyStroke cached = (AWTKeyStroke) cache.get(stroke); - if (cached == null) - cache.put(stroke, stroke); - else - stroke = cached; - return recent = stroke; - } - - /** - * Converts the modifiers to the appropriate format. - * - * @param mod the modifiers to convert - * @return the adjusted modifiers - */ - private static int extend(int mod) - { - if ((mod & (KeyEvent.SHIFT_MASK | KeyEvent.SHIFT_DOWN_MASK)) != 0) - mod |= KeyEvent.SHIFT_MASK | KeyEvent.SHIFT_DOWN_MASK; - if ((mod & (KeyEvent.CTRL_MASK | KeyEvent.CTRL_DOWN_MASK)) != 0) - mod |= KeyEvent.CTRL_MASK | KeyEvent.CTRL_DOWN_MASK; - if ((mod & (KeyEvent.META_MASK | KeyEvent.META_DOWN_MASK)) != 0) - mod |= KeyEvent.META_MASK | KeyEvent.META_DOWN_MASK; - if ((mod & (KeyEvent.ALT_MASK | KeyEvent.ALT_DOWN_MASK)) != 0) - mod |= KeyEvent.ALT_MASK | KeyEvent.ALT_DOWN_MASK; - if ((mod & (KeyEvent.ALT_GRAPH_MASK | KeyEvent.ALT_GRAPH_DOWN_MASK)) != 0) - mod |= KeyEvent.ALT_GRAPH_MASK | KeyEvent.ALT_GRAPH_DOWN_MASK; - if ((mod & KeyEvent.BUTTON1_MASK) != 0) - mod |= KeyEvent.BUTTON1_DOWN_MASK; - return mod & MODIFIERS_MASK; - } -} // class AWTKeyStroke diff --git a/libjava/java/awt/AWTPermission.java b/libjava/java/awt/AWTPermission.java deleted file mode 100644 index 3e50c059f88..00000000000 --- a/libjava/java/awt/AWTPermission.java +++ /dev/null @@ -1,121 +0,0 @@ -/* AWTPermission.java -- AWT related permissions - Copyright (C) 2000, 2002 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.security.BasicPermission; - -/** - * This class implements permissions for AWT. This is a named - * permission. No actions are defined. - * - * <p>The following table provides a list of all the possible AWTPermission - * permission names with a description of what that permission allows.<br> - * <table border=1> - * <tr><th>Permission Name</th><th>Permission Allows</th><th>Risks</th</tr> - * <tr> - * <td><code>accessClipboard</code></td> - * <td>posting and reading the AWT clipboard</td> - * <td>the clipboard may contain sensitive data</td></tr> - * <tr> - * <td><code>accessEventQueue</code></td> - * <td>access to the AWT event queue</td> - * <td>malicious code could remove real events and replace them with bogus - * ones, including simulating the user granting permission</td></tr> - * <tr> - * <td><code>listenToAllAWTEvents</code></td> - * <td>listen to system-wide AWT events</td> - * <td>malicious code can read passwords entered in an AWT event, and in - * combination with accessEventQueue, could fake system events</td></tr> - * <tr> - * <td><code>showWindowWithoutWarningBanner</code></td> - * <td>display a window without a banner notification of insecurity</td> - * <td>malicious code could install a Trojan horse applet that looks like - * a normal window, and thus steal data like passwords</td></tr> - * <tr> - * <td><code>readDisplayPixels</code></td> - * <td>read back pixels from the display screen</td> - * <td>malicious code could snoop on the user's actions</td></tr> - * <tr> - * <td><code>createRobot</code></td> - * <td>create an instance of java.awt.Robot</td> - * <td>these objects can generate events as though they were the user; so - * malicious code could control the system</td></tr> - * <tr> - * <td><code>fullScreenExclusive</code></td> - * <td>enter full-screen exclusive mode</td> - * <td>malicious code could masquerade as a trusted program</td></tr> - * </table> - * - * @author Tom Tromey (tromey@redhat.com) - * @since 1.2 - * @status updated to 1.4 - */ -public final class AWTPermission extends BasicPermission -{ - /** - * Compatible with JDK 1.2+. - */ - private static final long serialVersionUID = 8890392402588814465L; - - /** - * Construct a AWTPermission with the given name. - * - * @param name the permission name - * @throws NullPointerException if name is null - * @throws IllegalArgumentException if name is invalid - */ - public AWTPermission(String name) - { - super(name); - } - - /** - * Create a new permission with the specified name. The actions argument - * is ignored, as AWT permissions have no actions. - * - * @param name the permission name - * @param actions ignored - * @throws NullPointerException if name is null - * @throws IllegalArgumentException if name is invalid - */ - public AWTPermission(String name, String actions) - { - super(name); - } -} // class AWTPermission diff --git a/libjava/java/awt/ActiveEvent.java b/libjava/java/awt/ActiveEvent.java deleted file mode 100644 index e42959fe3d6..00000000000 --- a/libjava/java/awt/ActiveEvent.java +++ /dev/null @@ -1,61 +0,0 @@ -/* ActiveEvent.java -- a self-dispatching event - Copyright (C) 2000, 2002 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -/** - * An interface for events which can dispatch themselves in another thread. - * This has two uses: first, if your code is in a critical section, calling a - * synchronized method might deadlock. But by using an ActiveEvent to call - * the second section, it will not obtain the lock until you have left the - * critical section, avoiding deadlock. The second use is for calling - * untrusted code. For example, system code should use an ActiveEvent to - * invoke user code securely. - * - * @author Tom Tromey (tromey@cygnus.com) - * @since 1.2 - * @status updated to 1.4 - */ -public interface ActiveEvent -{ - /** - * Dispatch the event, according to what the event needs done. Invoked - * automatically if this is placed on the <code>EventDispatchQueue</code>. - */ - void dispatch(); -} // interface ActiveEvent diff --git a/libjava/java/awt/Adjustable.java b/libjava/java/awt/Adjustable.java deleted file mode 100644 index 8f633e91a62..00000000000 --- a/libjava/java/awt/Adjustable.java +++ /dev/null @@ -1,171 +0,0 @@ -/* Adjustable.java -- Objects with a numeric adjustment scale - Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.awt.event.AdjustmentListener; - -/** - * This interface is for objects that take a numeric value that can be - * adjusted within a bounded range. For example, a scroll bar. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @since 1.0 - * @status updated to 1.4 - */ -public interface Adjustable -{ - /** Constant for an adjustable object with horizontal orientation. */ - int HORIZONTAL = 0; - - /** Constant for an adjustable object with vertical orientation. */ - int VERTICAL = 1; - - /** Constant for an adjustable object with no orientation. */ - int NO_ORIENTATION = 2; - - /** - * Returns a constant representing the orientation of the object. - * - * @return the orientation of this object - * @see #HORIZONTAL - * @see #VERTICAL - * @see #NO_ORIENTATION - */ - int getOrientation(); - - /** - * Sets the minimum value this object can have. - * - * @param minimum the new minimum value - */ - void setMinimum(int minimum); - - /** - * Returns the minimum value this object can have. - * - * @return the minimum value - */ - int getMinimum(); - - /** - * Sets the maximum value this object can have. - * - * @param maximum the new maximum value - */ - void setMaximum(int maximum); - - /** - * Returns the maximum value this object can have. - * - * @return the maximum value - */ - int getMaximum(); - - /** - * Sets the increment value for incrementing the value by units. - * - * @param increment the unit increment value - */ - void setUnitIncrement(int increment); - - /** - * Returns the increment value for incrementing the value by units. - * - * @return the unit increment value - */ - int getUnitIncrement(); - - /** - * Sets the increment value for incrementing the value by blocks. - * - * @param increment the block increment value - */ - void setBlockIncrement(int increment); - - /** - * Returns the increment value for incrementing the value by blocks. - * - * @return the block increment value - */ - int getBlockIncrement(); - - /** - * Sets the length of the indicator for this object to the specified value. - * - * @param length the indicator length - */ - void setVisibleAmount(int length); - - /** - * Returns the length of the indicator for this object. - * - * @return the indicator length - */ - int getVisibleAmount(); - - /** - * Sets the current value of the object. - * - * @param value the new value - */ - void setValue(int value); - - /** - * Returns the current value of the object. - * - * @return the current value - */ - int getValue(); - - /** - * Adds a listener that will receive adjustment events for this object. - * - * @param listener the adjustment listener to add - * @see java.awt.event.AdjustmentEvent - */ - void addAdjustmentListener(AdjustmentListener listener); - - /** - * Removes an adjustment listener from this object. - * - * @param listener the adjustment listener to remove - * @see java.awt.event.AdjustmentEvent - */ - void removeAdjustmentListener(AdjustmentListener listener); -} // interface Adjustable diff --git a/libjava/java/awt/AlphaComposite.java b/libjava/java/awt/AlphaComposite.java deleted file mode 100644 index 435cfd054c3..00000000000 --- a/libjava/java/awt/AlphaComposite.java +++ /dev/null @@ -1,167 +0,0 @@ -/* AlphaComposite.java -- provides a context for performing alpha compositing - Copyright (C) 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.awt.image.ColorModel; -import java.util.LinkedHashMap; -import java.util.Map; - -/** - * - * @author Eric Blake (ebb9@email.byu.edu) - * @see Composite - * @see CompositeContext - * @since 1.3 - * @status updated to 1.4 except for createContext, needs documentation - */ -public final class AlphaComposite implements Composite -{ - /** Map Long to AlphaComposites. See getInstance for details. */ - private static final LinkedHashMap cache = new LinkedHashMap(11, 0.75f, true) - { - /** The largest the alpha composite cache can grow. */ - private static final int MAX_CACHE_SIZE = 2048; - - /** Prune stale entries. */ - protected boolean removeEldestEntry(Map.Entry eldest) - { // XXX - FIXME Use Map.Entry, not just Entry as gcj 3.1 workaround. - return size() > MAX_CACHE_SIZE; - } - }; - - public static final int CLEAR = 1; - public static final int SRC = 2; - public static final int DST = 9; - public static final int SRC_OVER = 3; - public static final int DST_OVER = 4; - public static final int SRC_IN = 5; - public static final int DST_IN = 6; - public static final int SRC_OUT = 7; - public static final int DST_OUT = 8; - public static final int SRC_ATOP = 10; - public static final int DST_ATOP = 11; - public static final int XOR = 12; - public static final AlphaComposite Clear = getInstance(CLEAR); - public static final AlphaComposite Src = getInstance(SRC); - public static final AlphaComposite Dst = getInstance(DST); - public static final AlphaComposite SrcOver = getInstance(SRC_OVER); - public static final AlphaComposite DstOver = getInstance(DST_OVER); - public static final AlphaComposite SrcIn = getInstance(SRC_IN); - public static final AlphaComposite DstIn = getInstance(DST_IN); - public static final AlphaComposite SrcOut = getInstance(SRC_OUT); - public static final AlphaComposite DstOut = getInstance(DST_OUT); - public static final AlphaComposite SrcAtop = getInstance(SRC_ATOP); - public static final AlphaComposite DstAtop = getInstance(DST_ATOP); - public static final AlphaComposite Xor = getInstance(XOR); - - private final int rule; - private final float alpha; - private AlphaComposite(int rule, float alpha) - { - this.rule = rule; - this.alpha = alpha; - } - - /** - * Creates an AlphaComposite object with the specified rule. - * - * @param rule The compositing rule. - * - * @exception IllegalArgumentException If rule is not one of the following: - * CLEAR, SRC, DST, SRC_OVER, DST_OVER, SRC_IN, DST_IN, SRC_OUT, DST_OUT, - * SRC_ATOP, DST_ATOP, or XOR. - */ - public static AlphaComposite getInstance(int rule) - { - return getInstance(rule, 1); - } - - /** - * Creates an AlphaComposite object with the specified rule and the constant - * alpha to multiply with the alpha of the source. The source is multiplied - * with the specified alpha before being composited with the destination. - * - * @param rule The compositing rule. - * - * @exception IllegalArgumentException If rule is not one of the following: - * CLEAR, SRC, DST, SRC_OVER, DST_OVER, SRC_IN, DST_IN, SRC_OUT, DST_OUT, - * SRC_ATOP, DST_ATOP, or XOR. - */ - public static AlphaComposite getInstance(int rule, float alpha) - { - if (rule < CLEAR || rule > XOR || ! (alpha >= 0 && alpha <= 1)) - throw new IllegalArgumentException(); - // This long is guaranteed unique for all valid alpha composites. - Long l = new Long(rule + Double.doubleToLongBits(alpha)); - AlphaComposite a = (AlphaComposite) cache.get(l); - if (a == null) - { - a = new AlphaComposite(rule, alpha); - cache.put(l, a); - } - return a; - } - public CompositeContext createContext(ColorModel srcColorModel, - ColorModel dstColorModel, - RenderingHints hints) - { - // XXX Implement. Sun uses undocumented implementation class - // sun.java2d.SunCompositeContext. - throw new Error("not implemented"); - } - public float getAlpha() - { - return alpha; - } - public int getRule() - { - return rule; - } - public int hashCode() - { - return 31 * Float.floatToIntBits(alpha) + rule; - } - public boolean equals(Object o) - { - if (! (o instanceof AlphaComposite)) - return false; - AlphaComposite a = (AlphaComposite) o; - return rule == a.rule && alpha == a.alpha; - } -} // class AlphaComposite diff --git a/libjava/java/awt/AttributeValue.java b/libjava/java/awt/AttributeValue.java deleted file mode 100644 index 080e92e221f..00000000000 --- a/libjava/java/awt/AttributeValue.java +++ /dev/null @@ -1,98 +0,0 @@ -/* AttributeValue.java -- parent of type-safe enums of attributes - Copyright (C) 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -/** - * This class is undocumented by Sun, but it is the parent of several other - * classes, all of which are type-safe enumerations. This takes care of - * <code>equals</code>, <code>toString</code>, and <code>hashCode</code>, so - * that you don't have to (although hashCode is commonly overridden). - * - * @author Eric Blake (ebb9@email.byu.edu) - */ -class AttributeValue -{ - /** The value of the enumeration. Package visible for speed. */ - final int value; - - /** The list of enumeration names for the given subclass. */ - private final String[] names; - - /** - * Construct a type-safe enumeration element. For example,<br> - * <pre> - * class Foo extends AttributeValue - * { - * private static final String[] names = { "one", "two" } - * public static final Foo ONE = new Foo(0); - * public static final Foo TWO = new Foo(1); - * private Foo(int value) { super(value, names); } - * } - * </pre> - * - * @param value the position of this enumeration element, consecutive from 0 - * @param names the constant list of enumeration names for the subclass - */ - AttributeValue(int value, String[] names) - { - this.value = value; - this.names = names; - } - - /** - * Returns the hashcode of this element. This is the index of the element - * in the enumeration. Note that equals defaults to the == relation. - * - * @return the hashcode - */ - public int hashCode() - { - return value; - } - - /** - * Returns the name of this enumeration element. - * - * @return the element name - */ - public String toString() - { - return names[value]; - } -} // class AttributeValue diff --git a/libjava/java/awt/BasicStroke.java b/libjava/java/awt/BasicStroke.java deleted file mode 100644 index bb008e4c791..00000000000 --- a/libjava/java/awt/BasicStroke.java +++ /dev/null @@ -1,248 +0,0 @@ -/* BasicStroke.java -- - Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.util.Arrays; - -/** - * STUB CLASS ONLY - */ -public class BasicStroke implements Stroke -{ - public static final int JOIN_MITER = 0; - public static final int JOIN_ROUND = 1; - public static final int JOIN_BEVEL = 2; - - public static final int CAP_BUTT = 0; - public static final int CAP_ROUND = 1; - public static final int CAP_SQUARE = 2; - - private final float width; - private final int cap; - private final int join; - private final float limit; - private final float[] dash; - private final float phase; - - /** - * Creates a basic stroke. - * - * @param width May not be negative . - * @param cap May be either CAP_BUTT, CAP_ROUND or CAP_SQUARE. - * @param join May be either JOIN_ROUND, JOIN_BEVEL, or JOIN_MITER. - * @param miterlimit the limit to trim the miter join. The miterlimit must be - * greater than or equal to 1.0f. - * @param dash The array representing the dashing pattern. There must be at - * least one non-zero entry. - * @param dashPhase is negative and dash is not null. - * - * @exception IllegalArgumentException If one input parameter doesn't meet - * its needs. - */ - public BasicStroke(float width, int cap, int join, float miterlimit, - float[] dash, float dashPhase) - { - if (width < 0.0f ) - throw new IllegalArgumentException("width " + width + " < 0"); - else if (cap < CAP_BUTT || cap > CAP_SQUARE) - throw new IllegalArgumentException("cap " + cap + " out of range [" - + CAP_BUTT + ".." + CAP_SQUARE + "]"); - else if (miterlimit < 1.0f && join == JOIN_MITER) - throw new IllegalArgumentException("miterlimit " + miterlimit - + " < 1.0f while join == JOIN_MITER"); - else if (join < JOIN_MITER || join > JOIN_BEVEL) - throw new IllegalArgumentException("join " + join + " out of range [" - + JOIN_MITER + ".." + JOIN_BEVEL - + "]"); - else if (dashPhase < 0.0f && dash != null) - throw new IllegalArgumentException("dashPhase " + dashPhase - + " < 0.0f while dash != null"); - else if (dash != null) - if (dash.length == 0) - throw new IllegalArgumentException("dash.length is 0"); - else - { - boolean allZero = true; - - for ( int i = 0; i < dash.length; ++i) - { - if (dash[i] != 0.0f) - { - allZero = false; - break; - } - } - - if (allZero) - throw new IllegalArgumentException("all dashes are 0.0f"); - } - - this.width = width; - this.cap = cap; - this.join = join; - limit = miterlimit; - this.dash = dash == null ? null : (float[]) dash.clone(); - phase = dashPhase; - } - - /** - * Creates a basic stroke. - * - * @param width The width of the BasicStroke. May not be negative . - * @param cap May be either CAP_BUTT, CAP_ROUND or CAP_SQUARE. - * @param join May be either JOIN_ROUND, JOIN_BEVEL, or JOIN_MITER. - * @param miterlimit the limit to trim the miter join. The miterlimit must be - * greater than or equal to 1.0f. - * - * @exception IllegalArgumentException If one input parameter doesn't meet - * its needs. - */ - public BasicStroke(float width, int cap, int join, float miterlimit) - { - this(width, cap, join, miterlimit, null, 0); - } - - /** - * Creates a basic stroke. - * - * @param width The width of the BasicStroke. May not be nehative. - * @param cap May be either CAP_BUTT, CAP_ROUND or CAP_SQUARE. - * @param join May be either JOIN_ROUND, JOIN_BEVEL, or JOIN_MITER. - * - * @exception IllegalArgumentException If one input parameter doesn't meet - * its needs. - * @exception IllegalArgumentException FIXME - */ - public BasicStroke(float width, int cap, int join) - { - this(width, cap, join, 10, null, 0); - } - - /** - * Creates a basic stroke. - * - * @param width The width of the BasicStroke. - * - * @exception IllegalArgumentException If width is negative. - */ - public BasicStroke(float width) - { - this(width, CAP_SQUARE, JOIN_MITER, 10, null, 0); - } - - /** - * Creates a basic stroke. - */ - public BasicStroke() - { - this(1, CAP_SQUARE, JOIN_MITER, 10, null, 0); - } - - public Shape createStrokedShape(Shape s) - { - throw new Error("not implemented"); - } - - public float getLineWidth() - { - return width; - } - - public int getEndCap() - { - return cap; - } - - public int getLineJoin() - { - return join; - } - - public float getMiterLimit() - { - return limit; - } - - public float[] getDashArray() - { - return dash; - } - - public float getDashPhase() - { - return phase; - } - - /** - * Returns the hash code for this object. The hash is calculated by - * xoring the hash, cap, join, limit, dash array and phase values - * (converted to <code>int</code> first with - * <code>Float.floatToIntBits()</code> if the value is a - * <code>float</code>). - */ - public int hashCode() - { - int hash = Float.floatToIntBits(width); - hash ^= cap; - hash ^= join; - hash ^= Float.floatToIntBits(limit); - - if (dash != null) - for (int i = 0; i < dash.length; i++) - hash ^= Float.floatToIntBits(dash[i]); - - hash ^= Float.floatToIntBits(phase); - - return hash; - } - - /** - * Returns true if the given Object is an instance of BasicStroke - * and the width, cap, join, limit, dash array and phase are all - * equal. - */ - public boolean equals(Object o) - { - if (! (o instanceof BasicStroke)) - return false; - BasicStroke s = (BasicStroke) o; - return width == s.width && cap == s.cap && join == s.join - && limit == s.limit && Arrays.equals(dash, s.dash) && phase == s.phase; - } -} // class BasicStroke diff --git a/libjava/java/awt/BorderLayout.java b/libjava/java/awt/BorderLayout.java deleted file mode 100644 index c9eb5dd8c37..00000000000 --- a/libjava/java/awt/BorderLayout.java +++ /dev/null @@ -1,731 +0,0 @@ -/* BorderLayout.java -- A layout manager class - Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -/** - * This class implements a layout manager that positions components - * in certain sectors of the parent container. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Rolf W. Rasmussen (rolfwr@ii.uib.no) - */ -public class BorderLayout implements LayoutManager2, java.io.Serializable -{ - -/* - * Static Variables - */ - -/** - * Constant indicating the top of the container - */ -public static final String NORTH = "North"; - -/** - * Constant indicating the bottom of the container - */ -public static final String SOUTH = "South"; - -/** - * Constant indicating the right side of the container - */ -public static final String EAST = "East"; - -/** - * Constant indicating the left side of the container - */ -public static final String WEST = "West"; - -/** - * Constant indicating the center of the container - */ -public static final String CENTER = "Center"; - - - /** - * The constant indicating the position before the first line of the - * layout. The exact position depends on the writing system: For a - * top-to-bottom orientation, it is the same as {@link #NORTH}, for - * a bottom-to-top orientation, it is the same as {@link #SOUTH}. - * - * <p>This constant is an older name for {@link #PAGE_START} which - * has exactly the same value. - * - * @since 1.2 - */ - public static final String BEFORE_FIRST_LINE = "First"; - - - /** - * The constant indicating the position after the last line of the - * layout. The exact position depends on the writing system: For a - * top-to-bottom orientation, it is the same as {@link #SOUTH}, for - * a bottom-to-top orientation, it is the same as {@link #NORTH}. - * - * <p>This constant is an older name for {@link #PAGE_END} which - * has exactly the same value. - * - * @since 1.2 - */ - public static final String AFTER_LAST_LINE = "Last"; - - - /** - * The constant indicating the position before the first item of the - * layout. The exact position depends on the writing system: For a - * left-to-right orientation, it is the same as {@link #WEST}, for - * a right-to-left orientation, it is the same as {@link #EAST}. - * - * <p>This constant is an older name for {@link #LINE_START} which - * has exactly the same value. - * - * @since 1.2 - */ - public static final String BEFORE_LINE_BEGINS = "Before"; - - - /** - * The constant indicating the position after the last item of the - * layout. The exact position depends on the writing system: For a - * left-to-right orientation, it is the same as {@link #EAST}, for - * a right-to-left orientation, it is the same as {@link #WEST}. - * - * <p>This constant is an older name for {@link #LINE_END} which - * has exactly the same value. - * - * @since 1.2 - */ - public static final String AFTER_LINE_ENDS = "After"; - - - /** - * The constant indicating the position before the first line of the - * layout. The exact position depends on the writing system: For a - * top-to-bottom orientation, it is the same as {@link #NORTH}, for - * a bottom-to-top orientation, it is the same as {@link #SOUTH}. - * - * @since 1.4 - */ - public static final String PAGE_START = BEFORE_FIRST_LINE; - - - /** - * The constant indicating the position after the last line of the - * layout. The exact position depends on the writing system: For a - * top-to-bottom orientation, it is the same as {@link #SOUTH}, for - * a bottom-to-top orientation, it is the same as {@link #NORTH}. - * - * @since 1.4 - */ - public static final String PAGE_END = AFTER_LAST_LINE; - - - /** - * The constant indicating the position before the first item of the - * layout. The exact position depends on the writing system: For a - * left-to-right orientation, it is the same as {@link #WEST}, for - * a right-to-left orientation, it is the same as {@link #EAST}. - * - * @since 1.4 - */ - public static final String LINE_START = BEFORE_LINE_BEGINS; - - - /** - * The constant indicating the position after the last item of the - * layout. The exact position depends on the writing system: For a - * left-to-right orientation, it is the same as {@link #EAST}, for - * a right-to-left orientation, it is the same as {@link #WEST}. - * - * @since 1.4 - */ - public static final String LINE_END = AFTER_LINE_ENDS; - - - -// Serialization constant -private static final long serialVersionUID = -8658291919501921765L; - -/*************************************************************************/ - -/* - * Instance Variables - */ - -/** - * @serial - */ -private Component north; - -/** - * @serial - */ -private Component south; - -/** - * @serial - */ -private Component east; - -/** - * @serial - */ -private Component west; - -/** - * @serial - */ -private Component center; - -/** - * @serial - */ -private Component firstLine; - -/** - * @serial - */ -private Component lastLine; - -/** - * @serial - */ -private Component firstItem; - -/** - * @serial - */ -private Component lastItem; - -/** - * @serial The horizontal gap between components - */ -private int hgap; - -/** - * @serial The vertical gap between components - */ -private int vgap; - -/*************************************************************************/ - -/* - * Constructors - */ - -/** - * Initializes a new instance of <code>BorderLayout</code> with no - * horiztonal or vertical gaps between components. - */ -public -BorderLayout() -{ - this(0,0); -} - -/*************************************************************************/ - -/** - * Initializes a new instance of <code>BorderLayout</code> with the - * specified horiztonal and vertical gaps between components. - * - * @param hgap The horizontal gap between components. - * @param vgap The vertical gap between components. - */ -public -BorderLayout(int hgap, int vgap) -{ - this.hgap = hgap; - this.vgap = vgap; -} - -/*************************************************************************/ - -/* - * Instance Variables - */ - -/** - * Returns the horitzontal gap value. - * - * @return The horitzontal gap value. - */ -public int -getHgap() -{ - return(hgap); -} - -/*************************************************************************/ - -/** - * Sets the horizontal gap to the specified value. - * - * @param hgap The new horizontal gap. - */ -public void -setHgap(int hgap) -{ - this.hgap = hgap; -} - -/*************************************************************************/ - -/** - * Returns the vertical gap value. - * - * @return The vertical gap value. - */ -public int -getVgap() -{ - return(vgap); -} - -/*************************************************************************/ - -/** - * Sets the vertical gap to the specified value. - * - * @param vgap The new vertical gap value. - */ -public void -setVgap(int vgap) -{ - this.vgap = vgap; -} - -/*************************************************************************/ - -/** - * Adds a component to the layout in the specified constraint position, - * which must be one of the string constants defined in this class. - * - * @param component The component to add. - * @param constraints The constraint string. - * - * @exception IllegalArgumentException If the constraint object is not - * a string, or is not one of the specified constants in this class. - */ -public void -addLayoutComponent(Component component, Object constraints) -{ - if (constraints != null && ! (constraints instanceof String)) - throw new IllegalArgumentException("Constraint must be a string"); - - addLayoutComponent((String) constraints, component); -} - -/*************************************************************************/ - -/** - * Adds a component to the layout in the specified constraint position, - * which must be one of the string constants defined in this class. - * - * @param constraints The constraint string. - * @param component The component to add. - * - * @exception IllegalArgumentException If the constraint object is not - * one of the specified constants in this class. - * - * @deprecated This method is deprecated in favor of - * <code>addLayoutComponent(Component, Object)</code>. - */ -public void -addLayoutComponent(String constraints, Component component) -{ - String str = constraints; - - if (str == null || str.equals(CENTER)) - center = component; - else if (str.equals(NORTH)) - north = component; - else if (str.equals(SOUTH)) - south = component; - else if (str.equals(EAST)) - east = component; - else if (str.equals(WEST)) - west = component; - else if (str.equals(BEFORE_FIRST_LINE)) - firstLine = component; - else if (str.equals(AFTER_LAST_LINE)) - lastLine = component; - else if (str.equals(BEFORE_LINE_BEGINS)) - firstItem = component; - else if (str.equals(AFTER_LINE_ENDS)) - lastItem = component; - else - throw new IllegalArgumentException("Constraint value not valid: " + str); -} - -/*************************************************************************/ - -/** - * Removes the specified component from the layout. - * - * @param component The component to remove from the layout. - */ -public void -removeLayoutComponent(Component component) -{ - if (north == component) - north = null; - if (south == component) - south = null; - if (east == component) - east = null; - if (west == component) - west = null; - if (center == component) - center = null; - if (firstItem == component) - firstItem = null; - if (lastItem == component) - lastItem = null; - if (firstLine == component) - firstLine = null; - if (lastLine == component) - lastLine = null; -} - -/*************************************************************************/ - -/** - * Returns the minimum size of the specified container using this layout. - * - * @param target The container to calculate the minimum size for. - * - * @return The minimum size of the container - */ -public Dimension -minimumLayoutSize(Container target) -{ - return calcSize(target, MIN); -} - -/*************************************************************************/ - -/** - * Returns the preferred size of the specified container using this layout. - * - * @param target The container to calculate the preferred size for. - * - * @return The preferred size of the container - */ -public Dimension -preferredLayoutSize(Container target) -{ - return calcSize(target, PREF); -} - -/*************************************************************************/ - -/** - * Returns the maximum size of the specified container using this layout. - * - * @param target The container to calculate the maximum size for. - * - * @return The maximum size of the container - */ -public Dimension -maximumLayoutSize(Container target) -{ - return calcSize(target, MAX); -} - -/*************************************************************************/ - -/** - * Returns the X axis alignment, which is a <code>float</code> indicating - * where along the X axis this container wishs to position its layout. - * 0 indicates align to the left, 1 indicates align to the right, and 0.5 - * indicates align to the center. - * - * @param parent The parent container. - * - * @return The X alignment value. - */ -public float -getLayoutAlignmentX(Container parent) -{ - return(parent.getAlignmentX()); -} - -/*************************************************************************/ - -/** - * Returns the Y axis alignment, which is a <code>float</code> indicating - * where along the Y axis this container wishs to position its layout. - * 0 indicates align to the top, 1 indicates align to the bottom, and 0.5 - * indicates align to the center. - * - * @param parent The parent container. - * - * @return The Y alignment value. - */ -public float -getLayoutAlignmentY(Container parent) -{ - return(parent.getAlignmentY()); -} - -/*************************************************************************/ - -/** - * Instructs this object to discard any layout information it might - * have cached. - * - * @param parent The parent container. - */ -public void -invalidateLayout(Container parent) -{ -} - -/*************************************************************************/ - -/** - * Lays out the specified container according to the constraints - * in this object. - * - * @param target The container to lay out. - */ -public void -layoutContainer(Container target) -{ - synchronized (target.getTreeLock ()) - { - Insets i = target.getInsets(); - - ComponentOrientation orient = target.getComponentOrientation (); - boolean left_to_right = orient.isLeftToRight (); - - Component my_north = north; - Component my_east = east; - Component my_south = south; - Component my_west = west; - - // Note that we currently don't handle vertical layouts. Neither - // does JDK 1.3. - if (firstLine != null) - my_north = firstLine; - if (lastLine != null) - my_south = lastLine; - if (firstItem != null) - { - if (left_to_right) - my_west = firstItem; - else - my_east = firstItem; - } - if (lastItem != null) - { - if (left_to_right) - my_east = lastItem; - else - my_west = lastItem; - } - - Dimension c = calcCompSize(center, PREF); - Dimension n = calcCompSize(my_north, PREF); - Dimension s = calcCompSize(my_south, PREF); - Dimension e = calcCompSize(my_east, PREF); - Dimension w = calcCompSize(my_west, PREF); - Dimension t = target.getSize(); - - /* - <-> hgap <-> hgap - +----------------------------+ } - |t | } i.top - | +----------------------+ | --- y1 } - | |n | | - | +----------------------+ | } vgap - | +---+ +----------+ +---+ | --- y2 } } - | |w | |c | |e | | } hh - | +---+ +----------+ +---+ | } vgap } - | +----------------------+ | --- y3 } - | |s | | - | +----------------------+ | } - | | } i.bottom - +----------------------------+ } - |x1 |x2 |x3 - <----------------------> - <--> ww <--> - i.left i.right - */ - - int x1 = i.left; - int x2 = x1 + w.width + hgap; - int x3; - if (t.width <= i.right + e.width) - x3 = x2 + w.width + hgap; - else - x3 = t.width - i.right - e.width; - int ww = t.width - i.right - i.left; - - int y1 = i.top; - int y2 = y1 + n.height + vgap; - int midh = Math.max(e.height, Math.max(w.height, c.height)); - int y3; - if (t.height <= i.bottom + s.height) - y3 = y2 + midh + vgap; - else - y3 = t.height - i.bottom - s.height; - int hh = y3-y2-vgap; - - setBounds(center, x2, y2, x3-x2-hgap, hh); - setBounds(my_north, x1, y1, ww, n.height); - setBounds(my_south, x1, y3, ww, s.height); - setBounds(my_west, x1, y2, w.width, hh); - setBounds(my_east, x3, y2, e.width, hh); - } -} - -/*************************************************************************/ - -/** - * Returns a string representation of this layout manager. - * - * @return A string representation of this object. - */ -public String -toString() -{ - return getClass().getName() + "[hgap=" + hgap + ",vgap=" + vgap + "]"; -} - -private void -setBounds(Component comp, int x, int y, int w, int h) -{ - if (comp == null) - return; - comp.setBounds(x, y, w, h); -} - -// Some constants for use with calcSize(). -private static final int MIN = 0; -private static final int MAX = 1; -private static final int PREF = 2; - -private Dimension -calcCompSize(Component comp, int what) -{ - if (comp == null || !comp.isVisible()) - return new Dimension(0, 0); - if (what == MIN) - return comp.getMinimumSize(); - else if (what == MAX) - return comp.getMaximumSize(); - return comp.getPreferredSize(); -} - -// This is a helper function used to compute the various sizes for -// this layout. -private Dimension -calcSize(Container target, int what) -{ - synchronized (target.getTreeLock ()) - { - Insets ins = target.getInsets(); - - ComponentOrientation orient = target.getComponentOrientation (); - boolean left_to_right = orient.isLeftToRight (); - - Component my_north = north; - Component my_east = east; - Component my_south = south; - Component my_west = west; - - // Note that we currently don't handle vertical layouts. Neither - // does JDK 1.3. - if (firstLine != null) - my_north = firstLine; - if (lastLine != null) - my_south = lastLine; - if (firstItem != null) - { - if (left_to_right) - my_west = firstItem; - else - my_east = firstItem; - } - if (lastItem != null) - { - if (left_to_right) - my_east = lastItem; - else - my_west = lastItem; - } - - Dimension ndim = calcCompSize(my_north, what); - Dimension sdim = calcCompSize(my_south, what); - Dimension edim = calcCompSize(my_east, what); - Dimension wdim = calcCompSize(my_west, what); - Dimension cdim = calcCompSize(center, what); - - int width = edim.width + cdim.width + wdim.width + (hgap * 2); - // check for overflow - if (width < edim.width || width < cdim.width || width < cdim.width) - width = Integer.MAX_VALUE; - - if (ndim.width > width) - width = ndim.width; - if (sdim.width > width) - width = sdim.width; - - width += (ins.left + ins.right); - - int height = edim.height; - if (cdim.height > height) - height = cdim.height; - if (wdim.height > height) - height = wdim.height; - - int addedHeight = height + (ndim.height + sdim.height + (vgap * 2) - + ins.top + ins.bottom); - // check for overflow - if (addedHeight < height) - height = Integer.MAX_VALUE; - else - height = addedHeight; - - return(new Dimension(width, height)); - } -} -} // class BorderLayout diff --git a/libjava/java/awt/BufferCapabilities.java b/libjava/java/awt/BufferCapabilities.java deleted file mode 100644 index 7cc49730cdc..00000000000 --- a/libjava/java/awt/BufferCapabilities.java +++ /dev/null @@ -1,251 +0,0 @@ -/* BufferCapabilities.java -- double-buffering capabilities descriptor - Copyright (C) 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -/** - * A double-buffering capability descriptor. This class exposes - * details about the double-buffering algorithms used by image - * buffers. - * - * BufferCapabilities represents algorithms that involve at least two - * buffers but it can also specify so-called "multi-buffer" schemes - * involving more than two buffers. This class describes the - * capabilities of the front and back buffers as well as the results - * of "flipping" -- that is, what happens when an image is transferred - * from the back buffer to the front buffer. - * - * Flipping may or may not be supported or may be supported only in - * fullscreen mode. If it is not supported then "blitting" is implied - * -- that is, the contents of the back buffer are copied using a fast - * block transfer operation from the back buffer to the front buffer. - * - * The front buffer is the one that is displayed. - * - * @author Eric Blake (ebb9@email.byu.edu) - * - * @see BufferStrategy#getCapabilities() - * @see GraphicsConfiguration#getCapabilities() - * - * @since 1.4 - */ -public class BufferCapabilities implements Cloneable -{ - /** - * A type-safe enumeration of buffer flipping results. - * - * @see AttributeValue - */ - public static final class FlipContents extends AttributeValue - { - /** - * The names of the different flipping results. - */ - private static final String[] NAMES - = { "undefined", "background", "prior", "copied" }; - - /** - * The contents of the back buffer are undefined after flipping. - */ - public static final FlipContents UNDEFINED = new FlipContents(0); - - /** - * The back buffer is cleared with the background color after - * flipping. - */ - public static final FlipContents BACKGROUND = new FlipContents(1); - - /** - * The back buffer contains the pre-flipping contents of the front - * buffer after flipping. In other words a true "flip" has been - * performed. - */ - public static final FlipContents PRIOR = new FlipContents(2); - - /** - * The back buffer has the same contents as the front buffer after - * flipping. - */ - public static final FlipContents COPIED = new FlipContents(3); - - /** - * Create a new flipping result descriptor. - * - * @param value the enumeration value - */ - private FlipContents(int value) - { - super(value, NAMES); - } - } - - /** - * Front buffer capabilities descriptor. - */ - private final ImageCapabilities front; - - /** - * Back buffer capabilities descriptor. - */ - private final ImageCapabilities back; - - /** - * Describes the results of a "flip" operation. - */ - private final FlipContents flip; - - /** - * Creates a buffer capabilities object. - * - * @param frontCaps front buffer capabilities descriptor - * @param backCaps back buffer capabilities descriptor - * @param flip the results of a flip operation or null if - * flipping is not supported - * - * @exception IllegalArgumentException if frontCaps or backCaps is - * null - */ - public BufferCapabilities(ImageCapabilities frontCaps, - ImageCapabilities backCaps, - FlipContents flip) - { - if (frontCaps == null || backCaps == null) - throw new IllegalArgumentException(); - this.front = frontCaps; - this.back = backCaps; - this.flip = flip; - } - - /** - * Retrieve the front buffer's image capabilities. - * - * @return the front buffer's image capabilities - */ - public ImageCapabilities getFrontBufferCapabilities() - { - return front; - } - - /** - * Retrieve the back buffer's image capabilities. - * - * @return the back buffer's image capabilities - */ - public ImageCapabilities getBackBufferCapabilities() - { - return back; - } - - /** - * Return whether or not flipping is supported. - * - * @return true if flipping is supported, false otherwise - */ - public boolean isPageFlipping() - { - return flip != null; - } - - /** - * Retrieve the result of a flipping operation. If this method - * returns null then flipping is not supported. This implies that - * "blitting", a fast block transfer, is used to copy the contents - * of the back buffer to the front buffer. Other possible return - * values are: - * <ul> - * <li><code>FlipContents.UNDEFINED</code> the contents of the - * back buffer are undefined after flipping.</li> - * <li><code>FlipContents.BACKGROUND</code> the contents of the - * back buffer are cleared to the background color after - * flipping.</li> - * <li><code>FlipContents.PRIOR</code> the back buffer contains - * the pre-flipping contents of the front * buffer after - * flipping.</li> - * <li><code>FlipContents.COPIED</code> the back buffer has the - * same contents as the front buffer after flipping.</li> - * </ul> - * - * @return the result of a flipping operation or null if flipping is - * not supported - */ - public FlipContents getFlipContents() - { - return flip; - } - - /** - * Returns true if flipping is only supported in fullscreen mode. - * - * @return true if flipping is only supported in fullscreen mode, - * false otherwise - */ - public boolean isFullScreenRequired() - { - return true; - } - - /** - * Returns true if flipping can involve more than two buffers. One - * or more intermediate buffers may be available in addition to the - * front and back buffers. - * - * @return true if there are more than two buffers available for - * flipping, false otherwise - */ - public boolean isMultiBufferAvailable() - { - return false; - } - - /** - * Clone this buffering capability descriptor. - * - * @return a clone of this buffer capability descriptor - */ - public Object clone() - { - try - { - return super.clone(); - } - catch (CloneNotSupportedException e) - { - throw (Error) new InternalError().initCause(e); - } - } -} diff --git a/libjava/java/awt/Button.java b/libjava/java/awt/Button.java deleted file mode 100644 index 90be1e5b111..00000000000 --- a/libjava/java/awt/Button.java +++ /dev/null @@ -1,466 +0,0 @@ -/* Button.java -- AWT button widget - Copyright (C) 1999, 2002, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.peer.ButtonPeer; -import java.lang.reflect.Array; -import java.util.EventListener; - -import javax.accessibility.Accessible; -import javax.accessibility.AccessibleAction; -import javax.accessibility.AccessibleContext; -import javax.accessibility.AccessibleRole; -import javax.accessibility.AccessibleValue; - -/** - * This class provides a button widget for the AWT. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Tom Tromey (tromey@cygnus.com) - */ -public class Button extends Component - implements java.io.Serializable, Accessible -{ - -/* - * Static Variables - */ - -// FIXME: Need readObject/writeObject for serialization - -// Serialization version constant -private static final long serialVersionUID = -8774683716313001058L; - -/*************************************************************************/ - -/* - * Instance Variables - */ - -/** - * @serial The action command name for this button. - * This is package-private to avoid an accessor method. - */ -String actionCommand; - -/** - * @serial The label for this button. - * This is package-private to avoid an accessor method. - */ -String label; - -// List of ActionListeners for this class. -private transient ActionListener action_listeners; - - /* - * The number used to generate the name returned by getName. - */ - private static transient long next_button_number; - - protected class AccessibleAWTButton extends AccessibleAWTComponent - implements AccessibleAction, AccessibleValue - { - protected AccessibleAWTButton() - { - // Do nothing here. - } - - /* (non-Javadoc) - * @see javax.accessibility.AccessibleAction#getAccessibleActionCount() - */ - public int getAccessibleActionCount() - { - // Only 1 action possible - return 1; - } - - /* (non-Javadoc) - * @see javax.accessibility.AccessibleAction#getAccessibleActionDescription(int) - */ - public String getAccessibleActionDescription(int i) - { - // JDK 1.4.2 returns the string "click" for action 0. However, the API - // docs don't say what the string to be returned is, beyond being a - // description of the action. So we return the same thing for - // compatibility with 1.4.2. - if (i == 0) - return "click"; - return null; - } - - /* (non-Javadoc) - * @see javax.accessibility.AccessibleAction#doAccessibleAction(int) - */ - public boolean doAccessibleAction(int i) - { - if (i != 0) - return false; - processActionEvent(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, actionCommand)); - return true; - } - - public String getAccessibleName() - { - return label; - } - - public AccessibleAction getAccessibleAction() - { - return this; - } - - public AccessibleValue getAccessibleValue() - { - return this; - } - - /* (non-Javadoc) - * @see javax.accessibility.AccessibleValue#getCurrentAccessibleValue() - */ - public Number getCurrentAccessibleValue() - { - // Docs say return 1 if selected, but buttons can't be selected, right? - return new Integer(0); - } - - /* (non-Javadoc) - * @see javax.accessibility.AccessibleValue#setCurrentAccessibleValue(java.lang.Number) - */ - public boolean setCurrentAccessibleValue(Number number) - { - // Since there's no selection with buttons, we're ignoring this. - // TODO someone who knows shoulw check this. - return false; - } - - /* (non-Javadoc) - * @see javax.accessibility.AccessibleValue#getMinimumAccessibleValue() - */ - public Number getMinimumAccessibleValue() - { - return new Integer(0); - } - - /* (non-Javadoc) - * @see javax.accessibility.AccessibleValue#getMaximumAccessibleValue() - */ - public Number getMaximumAccessibleValue() - { - return new Integer(0); - } - - public AccessibleRole getAccessibleRole() - { - return AccessibleRole.PUSH_BUTTON; - } - } - -/*************************************************************************/ - -/* - * Constructors - */ - -/** - * Initializes a new instance of <code>Button</code> with no label. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() - * returns true - */ -public -Button() -{ - this(""); -} - -/*************************************************************************/ - -/** - * Initializes a new instance of <code>Button</code> with the specified - * label. The action command name is also initialized to this value. - * - * @param label The label to display on the button. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() - * returns true - */ -public -Button(String label) -{ - this.label = label; - actionCommand = label; - - if (GraphicsEnvironment.isHeadless ()) - throw new HeadlessException (); -} - -/*************************************************************************/ - -/* - * Instance Variables - */ - -/** - * Returns the label for this button. - * - * @return The label for this button. - */ -public String -getLabel() -{ - return(label); -} - -/*************************************************************************/ - -/** - * Sets the label for this button to the specified value. - * - * @param label The new label for this button. - */ -public synchronized void -setLabel(String label) -{ - this.label = label; - actionCommand = label; - if (peer != null) - { - ButtonPeer bp = (ButtonPeer) peer; - bp.setLabel (label); - } -} - -/*************************************************************************/ - -/** - * Returns the action command name for this button. - * - * @return The action command name for this button. - */ -public String -getActionCommand() -{ - return(actionCommand); -} - -/*************************************************************************/ - -/** - * Sets the action command name for this button to the specified value. - * - * @param actionCommand The new action command name. - */ -public void -setActionCommand(String actionCommand) -{ - this.actionCommand = actionCommand == null ? label : actionCommand; -} - -/*************************************************************************/ - -/** - * Adds a new entry to the list of listeners that will receive - * action events from this button. - * - * @param listener The listener to add. - */ -public synchronized void -addActionListener(ActionListener listener) -{ - action_listeners = AWTEventMulticaster.add(action_listeners, listener); -} - -/*************************************************************************/ - -/** - * Removes the specified listener from the list of listeners that will - * receive action events from this button. - * - * @param listener The listener to remove. - */ -public synchronized void -removeActionListener(ActionListener listener) -{ - action_listeners = AWTEventMulticaster.remove(action_listeners, listener); -} - - /** - * Returns all added <code>ActionListener</code> objects. - * - * @return an array of listeners - * - * @since 1.4 - */ - public synchronized ActionListener[] getActionListeners() - { - return (ActionListener[]) - AWTEventMulticaster.getListeners(action_listeners, - ActionListener.class); - } - -/** - * Returns all registered EventListers of the given listenerType. - * listenerType must be a subclass of EventListener, or a - * ClassClassException is thrown. - * - * @param listenerType the listener type to return - * - * @return an array of listeners - * - * @exception ClassCastException If listenerType doesn't specify a class or - * interface that implements @see java.util.EventListener. - * - * @since 1.3 - */ - public EventListener[] getListeners(Class listenerType) - { - if (listenerType == ActionListener.class) - return getActionListeners(); - return (EventListener[]) Array.newInstance(listenerType, 0); - } - -/*************************************************************************/ - -/** - * Notifies this button that it should create its native peer object. - */ -public void -addNotify() -{ - if (peer == null) - peer = getToolkit ().createButton (this); - super.addNotify(); -} - -/*************************************************************************/ - -/** - * Processes an event for this button. If the specified event is an - * instance of <code>ActionEvent</code>, then the - * <code>processActionEvent()</code> method is called to dispatch it - * to any registered listeners. Otherwise, the superclass method - * will be invoked. Note that this method will not be called at all - * unless <code>ActionEvent</code>'s are enabled. This will be done - * implicitly if any listeners are added. - * - * @param event The event to process. - */ -protected void -processEvent(AWTEvent event) -{ - if (event instanceof ActionEvent) - processActionEvent((ActionEvent)event); - else - super.processEvent(event); -} - -/*************************************************************************/ - -/** - * This method dispatches an action event for this button to any - * registered listeners. - * - * @param event The event to process. - */ -protected void -processActionEvent(ActionEvent event) -{ - if (action_listeners != null) - action_listeners.actionPerformed(event); -} - -void -dispatchEventImpl(AWTEvent e) -{ - if (e.id <= ActionEvent.ACTION_LAST - && e.id >= ActionEvent.ACTION_FIRST - && (action_listeners != null - || (eventMask & AWTEvent.ACTION_EVENT_MASK) != 0)) - processEvent(e); - else - super.dispatchEventImpl(e); -} - -/*************************************************************************/ - -/** - * Returns a debugging string for this button. - * - * @return A debugging string for this button. - */ -protected String -paramString() -{ - return getName () + "," + getX () + "," + getY () + "," - + getWidth () + "x" + getHeight () + ",label=" + getLabel (); -} - -/** - * Gets the AccessibleContext associated with this <code>Button</code>. - * The context is created, if necessary. - * - * @return the associated context - */ -public AccessibleContext getAccessibleContext() -{ - /* Create the context if this is the first request */ - if (accessibleContext == null) - accessibleContext = new AccessibleAWTButton(); - return accessibleContext; -} - - /** - * Generate a unique name for this button. - * - * @return A unique name for this button. - */ - String generateName () - { - return "button" + getUniqueLong (); - } - - private static synchronized long getUniqueLong () - { - return next_button_number++; - } - -} // class Button - diff --git a/libjava/java/awt/Canvas.java b/libjava/java/awt/Canvas.java deleted file mode 100644 index 79f836edca3..00000000000 --- a/libjava/java/awt/Canvas.java +++ /dev/null @@ -1,365 +0,0 @@ -/* Canvas.java -- - Copyright (C) 1999, 2000, 2002, 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.awt.image.BufferStrategy; -import java.awt.peer.ComponentPeer; -import java.io.Serializable; - -import javax.accessibility.Accessible; -import javax.accessibility.AccessibleContext; -import javax.accessibility.AccessibleRole; - -/** - * The <code>Canvas</code> component provides a blank rectangular - * area, which the client application can use for drawing and for - * capturing events. By overriding the <code>paint()</code> method, - * the canvas can be used for anything from simple line drawings to - * full-scale custom components. - * - * @author Original author unknown - * @author Tom Tromey (tromey@redhat.com) - * @author Andrew John Hughes (gnu_andrew@member.fsf.org) - * @since 1.0 - */ - -public class Canvas - extends Component - implements Serializable, Accessible -{ - - /** - * Compatible with Sun's JDK. - */ - private static final long serialVersionUID = -2284879212465893870L; - - /** - * The graphics configuration associated with the canvas. - */ - transient GraphicsConfiguration graphicsConfiguration; - - /** - * The buffer strategy associated with this canvas. - */ - transient BufferStrategy bufferStrategy; - - /** - * Initializes a new instance of <code>Canvas</code>. - */ - public Canvas() - { - } - - /** - * Initializes a new instance of <code>Canvas</code> - * with the supplied graphics configuration. - * - * @param graphicsConfiguration the graphics configuration to use - * for this particular canvas. - */ - public Canvas(GraphicsConfiguration graphicsConfiguration) - { - this.graphicsConfiguration = graphicsConfiguration; - } - - GraphicsConfiguration getGraphicsConfigurationImpl() - { - if (graphicsConfiguration != null) - return graphicsConfiguration; - return super.getGraphicsConfigurationImpl(); - } - - /** - * Creates the native peer for this object. - */ - public void addNotify() - { - if (peer == null) - peer = (ComponentPeer) getToolkit().createCanvas(this); - super.addNotify(); - } - - /** - * Repaints the canvas window. This method should be overridden by - * a subclass to do something useful, as this method simply paints - * the window with the background color. - * - * @param gfx the <code>Graphics</code> to use for painting - */ - public void paint(Graphics gfx) - { - /* This implementation doesn't make much sense since the filling - of background color is guaranteed for heavyweight components - such as this. But there's no need to worry, since paint() is - usually overridden anyway. */ - gfx.setColor(getBackground()); - Dimension size = getSize(); - gfx.fillRect(0, 0, size.width, size.height); - } - - /** - * This class provides accessibility support for the canvas. - */ - protected class AccessibleAWTCanvas - extends AccessibleAWTComponent - { - /** - * For compatability with Sun's JDK - */ - private static final long serialVersionUID = -6325592262103146699L; - - /** - * Constructor for the accessible canvas. - */ - protected AccessibleAWTCanvas() - { - } - - /** - * Returns the accessible role for the canvas. - * - * @return an instance of <code>AccessibleRole</code>, describing - * the role of the canvas. - */ - public AccessibleRole getAccessibleRole() - { - return AccessibleRole.CANVAS; - } - - } - - /** - * Gets the AccessibleContext associated with this <code>Canvas</code>. - * The context is created, if necessary. - * - * @return the associated context - */ - public AccessibleContext getAccessibleContext() - { - /* Create the context if this is the first request */ - if (accessibleContext == null) - accessibleContext = new AccessibleAWTCanvas(); - return accessibleContext; - } - - /** - * A BltBufferStrategy for canvases. - */ - private class CanvasBltBufferStrategy extends BltBufferStrategy - { - /** - * Creates a block transfer strategy for this canvas. - * - * @param numBuffers the number of buffers in this strategy - * @param accelerated true if the buffer should be accelerated, - * false otherwise - */ - CanvasBltBufferStrategy(int numBuffers, boolean accelerated) - { - super(numBuffers, - new BufferCapabilities(new ImageCapabilities(accelerated), - new ImageCapabilities(accelerated), - BufferCapabilities.FlipContents.COPIED)); - } - } - - /** - * A FlipBufferStrategy for canvases. - */ - private class CanvasFlipBufferStrategy extends FlipBufferStrategy - { - /** - * Creates a flip buffer strategy for this canvas. - * - * @param numBuffers the number of buffers in this strategy - * - * @throws AWTException if the requested number of buffers is not - * supported - */ - CanvasFlipBufferStrategy(int numBuffers) - throws AWTException - { - super(numBuffers, - new BufferCapabilities(new ImageCapabilities(true), - new ImageCapabilities(true), - BufferCapabilities.FlipContents.COPIED)); - } - } - - /** - * Creates a buffering strategy that manages how this canvas is - * repainted. This method attempts to create the optimum strategy - * based on the desired number of buffers. Hardware or software - * acceleration may be used. - * - * createBufferStrategy attempts different levels of optimization, - * but guarantees that some strategy with the requested number of - * buffers will be created even if it is not optimal. First it - * attempts to create a page flipping strategy, then an accelerated - * blitting strategy, then an unaccelerated blitting strategy. - * - * Calling this method causes any existing buffer strategy to be - * destroyed. - * - * @param numBuffers the number of buffers in this strategy - * - * @throws IllegalArgumentException if requested number of buffers - * is less than one - * @throws IllegalStateException if this canvas is not displayable - * - * @since 1.4 - */ - public void createBufferStrategy(int numBuffers) - { - if (numBuffers < 1) - throw new IllegalArgumentException("Canvas.createBufferStrategy: number" - + " of buffers is less than one"); - - if (!isDisplayable()) - throw new IllegalStateException("Canvas.createBufferStrategy: canvas is" - + " not displayable"); - - // try a flipping strategy - try - { - bufferStrategy = new CanvasFlipBufferStrategy(numBuffers); - return; - } - catch (AWTException e) - { - } - - // try an accelerated blitting strategy - try - { - bufferStrategy = new CanvasBltBufferStrategy(numBuffers, true); - } - catch (AWTException e) - { - } - - // fall back to an unaccelerated blitting strategy - try - { - bufferStrategy = new CanvasBltBufferStrategy(numBuffers, false); - } - catch (AWTException e) - { - } - } - - /** - * Creates a buffering strategy that manages how this canvas is - * repainted. This method attempts to create a strategy based on - * the specified capabilities and throws an exception if the - * requested strategy is not supported. - * - * Calling this method causes any existing buffer strategy to be - * destroyed. - * - * @param numBuffers the number of buffers in this strategy - * @param caps the requested buffering capabilities - * - * @throws AWTException if the requested capabilities are not - * supported - * @throws IllegalArgumentException if requested number of buffers - * is less than one or if caps is null - * - * @since 1.4 - */ - public void createBufferStrategy(int numBuffers, - BufferCapabilities caps) - { - if (numBuffers < 1) - throw new IllegalArgumentException("Canvas.createBufferStrategy: number" - + " of buffers is less than one"); - - if (caps == null) - throw new IllegalArgumentException("Canvas.createBufferStrategy:" - + " capabilities object is null"); - - // a flipping strategy was requested - if (caps.isPageFlipping()) - { - try - { - bufferStrategy = new CanvasFlipBufferStrategy(numBuffers); - } - catch (AWTException e) - { - } - } - else - bufferStrategy = new CanvasBltBufferStrategy(numBuffers, true); - } - - /** - * Returns the buffer strategy used by the canvas. - * - * @return the buffer strategy. - * @since 1.4 - */ - public BufferStrategy getBufferStrategy() - { - return bufferStrategy; - } - - /** - * Updates the canvas in response to a request to - * <code>repaint()</code> it. The canvas is cleared - * with the current background colour, before <code>paint()</code> - * is called to add the new contents. Subclasses - * which override this method should either call this - * method via <code>super.update(graphics)</code> or re-implement - * this behaviour, so as to ensure that the canvas is - * clear before painting takes place. - * - * @param graphics the graphics context. - */ - public void update(Graphics graphics) - { - Dimension size; - - /* Clear the canvas */ - size = getSize(); - graphics.clearRect(0, 0, size.width, size.height); - /* Call the paint method */ - paint(graphics); - } -} diff --git a/libjava/java/awt/CardLayout.java b/libjava/java/awt/CardLayout.java deleted file mode 100644 index 8582c5f099b..00000000000 --- a/libjava/java/awt/CardLayout.java +++ /dev/null @@ -1,483 +0,0 @@ -/* CardLayout.java -- Card-based layout engine - Copyright (C) 1999, 2000, 2002, 2003, 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.io.Serializable; -import java.util.Enumeration; -import java.util.Hashtable; - -/** - * This class implements a card-based layout scheme. Each included - * component is treated as a card. Only one card can be shown at a - * time. This class includes methods for changing which card is - * shown. - * - * @author Tom Tromey (tromey@redhat.com) - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public class CardLayout implements LayoutManager2, Serializable -{ - private static final long serialVersionUID = -4328196481005934313L; - - /** - * Initializes a new instance of <code>CardLayout</code> with horizontal - * and vertical gaps of 0. - */ - public CardLayout () - { - this (0, 0); - } - - /** - * Create a new <code>CardLayout</code> object with the specified - * horizontal and vertical gaps. - * - * @param hgap The horizontal gap - * @param vgap The vertical gap - */ - public CardLayout (int hgap, int vgap) - { - this.hgap = hgap; - this.vgap = vgap; - this.tab = new Hashtable (); - } - - /** - * Add a new component to the layout. The constraint must be a - * string which is used to name the component. This string can - * later be used to refer to the particular component. - * - * @param comp The component to add - * @param constraints The name by which the component can later be called - * - * @exception IllegalArgumentException If `constraints' is not a - * <code>String</code> - */ - public void addLayoutComponent (Component comp, Object constraints) - { - if (! (constraints instanceof String)) - throw new IllegalArgumentException ("Object " + constraints - + " is not a string"); - addLayoutComponent ((String) constraints, comp); - } - - /** - * Add a new component to the layout. The name can be used later - * to refer to the component. - * - * @param name The name by which the component can later be called - * @param comp The component to add - * - * @deprecated This method is deprecated in favor of - * <code>addLayoutComponent(Component, Object)</code>. - */ - public void addLayoutComponent (String name, Component comp) - { - tab.put (name, comp); - // First component added is the default component. - comp.setVisible(tab.size() == 1); - } - - /** - * Cause the first component in the container to be displayed. - * - * @param parent The parent container - */ - public void first (Container parent) - { - gotoComponent (parent, FIRST); - } - - /** - * Return this layout manager's horizontal gap. - * - * @return the horizontal gap - */ - public int getHgap () - { - return hgap; - } - - /** - * Return this layout manager's x alignment. This method always - * returns Component.CENTER_ALIGNMENT. - * - * @param parent Container using this layout manager instance - * - * @return the x-axis alignment - */ - public float getLayoutAlignmentX (Container parent) - { - return Component.CENTER_ALIGNMENT; - } - - /** - * Returns this layout manager's y alignment. This method always - * returns Component.CENTER_ALIGNMENT. - * - * @param parent Container using this layout manager instance - * - * @return the y-axis alignment - */ - public float getLayoutAlignmentY (Container parent) - { - return Component.CENTER_ALIGNMENT; - } - - /** - * Return this layout manager's vertical gap. - * - * @return the vertical gap - */ - public int getVgap () - { - return vgap; - } - - /** - * Invalidate this layout manager's state. - */ - public void invalidateLayout (Container target) - { - // Do nothing. - } - - /** - * Cause the last component in the container to be displayed. - * - * @param parent The parent container - */ - public void last (Container parent) - { - gotoComponent (parent, LAST); - } - - /** - * Lays out the container. This is done by resizing the child components - * to be the same size as the parent, less insets and gaps. - * - * @param parent The parent container. - */ - public void layoutContainer (Container parent) - { - synchronized (parent.getTreeLock ()) - { - int width = parent.width; - int height = parent.height; - - Insets ins = parent.getInsets (); - - int num = parent.ncomponents; - Component[] comps = parent.component; - - int x = ins.left + hgap; - int y = ins.top + vgap; - width = width - 2 * hgap - ins.left - ins.right; - height = height - 2 * vgap - ins.top - ins.bottom; - - for (int i = 0; i < num; ++i) - comps[i].setBounds (x, y, width, height); - } - } - - /** - * Get the maximum layout size of the container. - * - * @param target The parent container - * - * @return the maximum layout size - */ - public Dimension maximumLayoutSize (Container target) - { - // The JCL says that this returns Integer.MAX_VALUE for both - // dimensions. But that just seems wrong to me. - return getSize (target, MAX); - } - - /** - * Get the minimum layout size of the container. - * - * @param target The parent container - * - * @return the minimum layout size - */ - public Dimension minimumLayoutSize (Container target) - { - return getSize (target, MIN); - } - - /** - * Cause the next component in the container to be displayed. If - * this current card is the last one in the deck, the first - * component is displayed. - * - * @param parent The parent container - */ - public void next (Container parent) - { - gotoComponent (parent, NEXT); - } - - /** - * Get the preferred layout size of the container. - * - * @param parent The parent container - * - * @return the preferred layout size - */ - public Dimension preferredLayoutSize (Container parent) - { - return getSize (parent, PREF); - } - - /** - * Cause the previous component in the container to be displayed. - * If this current card is the first one in the deck, the last - * component is displayed. - * - * @param parent The parent container - */ - public void previous (Container parent) - { - gotoComponent (parent, PREV); - } - - /** - * Remove the indicated component from this layout manager. - * - * @param comp The component to remove - */ - public void removeLayoutComponent (Component comp) - { - Enumeration e = tab.keys (); - while (e.hasMoreElements ()) - { - Object key = e.nextElement (); - if (tab.get (key) == comp) - { - tab.remove (key); - Container parent = comp.getParent(); - next(parent); - break; - } - } - } - - /** - * Set this layout manager's horizontal gap. - * - * @param hgap The new gap - */ - public void setHgap (int hgap) - { - this.hgap = hgap; - } - - /** - * Set this layout manager's vertical gap. - * - * @param vgap The new gap - */ - public void setVgap (int vgap) - { - this.vgap = vgap; - } - - /** - * Cause the named component to be shown. If the component name is - * unknown, this method does nothing. - * - * @param parent The parent container - * @param name The name of the component to show - */ - public void show (Container parent, String name) - { - Object target = tab.get (name); - if (target != null) - { - int num = parent.ncomponents; - // This is more efficient than calling getComponents(). - Component[] comps = parent.component; - for (int i = 0; i < num; ++i) - { - if (comps[i].isVisible()) - { - if (target == comps[i]) - return; - comps[i].setVisible (false); - } - } - ((Component) target).setVisible (true); - } - } - - /** - * Returns a string representation of this layout manager. - * - * @return A string representation of this object. - */ - public String toString () - { - return getClass ().getName () + "[" + hgap + "," + vgap + "]"; - } - - /** - * This implements first(), last(), next(), and previous(). - * - * @param parent The parent container - * @param what The type of goto: FIRST, LAST, NEXT or PREV - */ - private void gotoComponent (Container parent, int what) - { - synchronized (parent.getTreeLock ()) - { - int num = parent.ncomponents; - // This is more efficient than calling getComponents(). - Component[] comps = parent.component; - - if (num == 1) - { - comps[0].setVisible(true); - return; - } - - int choice = -1; - - if (what == FIRST) - choice = 0; - else if (what == LAST) - choice = num - 1; - - for (int i = 0; i < num; ++i) - { - if (comps[i].isVisible ()) - { - if (what == NEXT) - { - choice = i + 1; - if (choice == num) - choice = 0; - } - else if (what == PREV) - { - choice = i - 1; - if (choice < 0) - choice = num - 1; - } - else if (choice == i) - { - // Do nothing if we're already looking at the right - // component. - return; - } - comps[i].setVisible (false); - - if (choice >= 0) - break; - } - } - - if (choice >= 0 && choice < num) - comps[choice].setVisible (true); - } - } - - // Compute the size according to WHAT. - private Dimension getSize (Container parent, int what) - { - synchronized (parent.getTreeLock ()) - { - int w = 0, h = 0, num = parent.ncomponents; - Component[] comps = parent.component; - - for (int i = 0; i < num; ++i) - { - Dimension d; - - if (what == MIN) - d = comps[i].getMinimumSize (); - else if (what == MAX) - d = comps[i].getMaximumSize (); - else - d = comps[i].getPreferredSize (); - - w = Math.max (d.width, w); - h = Math.max (d.height, h); - } - - Insets i = parent.getInsets (); - w += 2 * hgap + i.right + i.left; - h += 2 * vgap + i.bottom + i.top; - - // Handle overflow. - if (w < 0) - w = Integer.MAX_VALUE; - if (h < 0) - h = Integer.MAX_VALUE; - - return new Dimension (w, h); - } - } - - /** - * @serial Horizontal gap value. - */ - private int hgap; - - /** - * @serial Vertical gap value. - */ - private int vgap; - - /** - * @serial Table of named components. - */ - private Hashtable tab; - - // These constants are used by the private gotoComponent method. - private static final int FIRST = 0; - private static final int LAST = 1; - private static final int NEXT = 2; - private static final int PREV = 3; - - // These constants are used by the private getSize method. - private static final int MIN = 0; - private static final int MAX = 1; - private static final int PREF = 2; -} diff --git a/libjava/java/awt/Checkbox.java b/libjava/java/awt/Checkbox.java deleted file mode 100644 index cd39ad43617..00000000000 --- a/libjava/java/awt/Checkbox.java +++ /dev/null @@ -1,649 +0,0 @@ -/* Checkbox.java -- An AWT checkbox widget - Copyright (C) 1999, 2000, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.awt.event.ItemEvent; -import java.awt.event.ItemListener; -import java.awt.peer.CheckboxPeer; -import java.io.Serializable; - -import javax.accessibility.Accessible; -import javax.accessibility.AccessibleAction; -import javax.accessibility.AccessibleContext; -import javax.accessibility.AccessibleRole; -import javax.accessibility.AccessibleState; -import javax.accessibility.AccessibleStateSet; -import javax.accessibility.AccessibleValue; - -/** - * This class implements a component which has an on/off state. Two - * or more Checkboxes can be grouped by a CheckboxGroup. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Tom Tromey (tromey@redhat.com) - */ -public class Checkbox extends Component - implements ItemSelectable, Accessible, Serializable -{ - -// FIXME: Need readObject/writeObject for this. - -/* - * Static Variables - */ - -// Serialization Constant -private static final long serialVersionUID = 7270714317450821763L; - -/*************************************************************************/ - -/* - * Instance Variables - */ - -/** - * @serial The checkbox group for this checkbox. - */ -private CheckboxGroup group; - -/** - * @serial The label on this checkbox. - */ -private String label; - -/** - * @serial The state of this checkbox. - * This is package-private to avoid an accessor method. - */ -boolean state; - -// The list of listeners for this object. -private transient ItemListener item_listeners; - - /* - * The number used to generate the name returned by getName. - */ - private static transient long next_checkbox_number; - -/** - * This class provides accessibility support for the - * checkbox. - * - * @author Jerry Quinn (jlquinn@optonline.net) - * @author Andrew John Hughes (gnu_andrew@member.fsf.org) - */ -protected class AccessibleAWTCheckbox - extends AccessibleAWTComponent - implements ItemListener, AccessibleAction, AccessibleValue -{ - /** - * Serialization constant to match JDK 1.5 - */ - private static final long serialVersionUID = 7881579233144754107L; - - /** - * Default constructor which simply calls the - * super class for generic component accessibility - * handling. - */ - public AccessibleAWTCheckbox() - { - super(); - } - - /** - * Captures changes to the state of the checkbox and - * fires appropriate accessible property change events. - * - * @param event the event fired. - * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent) - */ - public void itemStateChanged(ItemEvent event) - { - firePropertyChange(ACCESSIBLE_STATE_PROPERTY, - state ? null : AccessibleState.CHECKED, - state ? AccessibleState.CHECKED : null); - } - - /** - * Returns an implementation of the <code>AccessibleAction</code> - * interface for this accessible object. In this case, the - * current instance is simply returned (with a more appropriate - * type), as it also implements the accessible action as well as - * the context. - * - * @return the accessible action associated with this context. - * @see javax.accessibility.AccessibleAction - */ - public AccessibleAction getAccessibleAction() - { - return this; - } - - /** - * Returns an implementation of the <code>AccessibleValue</code> - * interface for this accessible object. In this case, the - * current instance is simply returned (with a more appropriate - * type), as it also implements the accessible value as well as - * the context. - * - * @return the accessible value associated with this context. - * @see javax.accessibility.AccessibleValue - */ - public AccessibleValue getAccessibleValue() - { - return this; - } - - /* - * The following methods are implemented in the JDK (up to - * 1.5) as stubs. We do likewise here. - */ - - /** - * Returns the number of actions associated with this accessible - * object. This default implementation returns 0. - * - * @return the number of accessible actions available. - * @see javax.accessibility.AccessibleAction#getAccessibleActionCount() - */ - public int getAccessibleActionCount() - { - // 1.4.1 and 1.5 do this - return 0; - } - - /** - * Returns a description of the action with the supplied id. - * This default implementation always returns null. - * - * @param i the id of the action whose description should be - * retrieved. - * @return a <code>String</code> describing the action. - * @see javax.accessibility.AccessibleAction#getAccessibleActionDescription(int) - */ - public String getAccessibleActionDescription(int i) - { - // 1.5 does this - return null; - } - - /** - * Executes the action with the specified id. This - * default implementation simply returns false. - * - * @param i the id of the action to perform. - * @return true if the action was performed. - * @see javax.accessibility.AccessibleAction#doAccessibleAction(int) - */ - public boolean doAccessibleAction(int i) - { - // 1.5 does this - return false; - } - - /** - * Returns the current value of this accessible object. - * If no value has been set, null is returned. This - * default implementation always returns null, regardless. - * - * @return the numeric value of this object, or null if - * no value has been set. - * @see javax.accessibility.AccessibleValue#getCurrentAccessibleValue() - */ - public Number getCurrentAccessibleValue() - { - // 1.5 does this - return null; - } - - /** - * Sets the current value of this accessible object - * to that supplied. In this default implementation, - * the value is never set and the method always returns - * false. - * - * @param number the new accessible value. - * @return true if the value was set. - * @see javax.accessibility.AccessibleValue#setCurrentAccessibleValue(java.lang.Number) - */ - public boolean setCurrentAccessibleValue(Number number) - { - // 1.5 does this - return false; - } - - /** - * Returns the minimum acceptable accessible value used - * by this object, or null if no minimum value exists. - * This default implementation always returns null. - * - * @return the minimum acceptable accessible value, or null - * if there is no minimum. - * @see javax.accessibility.AccessibleValue#getMinimumAccessibleValue() - */ - public Number getMinimumAccessibleValue() - { - return null; - } - - /** - * Returns the maximum acceptable accessible value used - * by this object, or null if no maximum value exists. - * This default implementation always returns null. - * - * @return the maximum acceptable accessible value, or null - * if there is no maximum. - * @see javax.accessibility.AccessibleValue#getMaximumAccessibleValue() - */ - public Number getMaximumAccessibleValue() - { - return null; - } - - /** - * Returns the role of this accessible object. - * - * @return the instance of <code>AccessibleRole</code>, - * which describes this object. - * @see javax.accessibility.AccessibleRole - */ - public AccessibleRole getAccessibleRole() - { - return AccessibleRole.CHECK_BOX; - } - - /** - * Returns the state set of this accessible object. - * - * @return a set of <code>AccessibleState</code>s - * which represent the current state of the - * accessible object. - * @see javax.accessibility.AccessibleState - * @see javax.accessibility.AccessibleStateSet - */ - public AccessibleStateSet getAccessibleStateSet() - { - AccessibleStateSet set = super.getAccessibleStateSet(); - if (state) - set.add(AccessibleState.CHECKED); - return set; - } - -} - -/*************************************************************************/ - -/* - * Constructors - */ - -/** - * Initializes a new instance of <code>Checkbox</code> with no label, - * an initial state of off, and that is not part of any checkbox group. - */ -public -Checkbox() -{ - this("", false, null); -} - -/*************************************************************************/ - -/** - * Initializes a new instance of <code>Checkbox</code> with the specified - * label, an initial state of off, and that is not part of any checkbox - * group. - * - * @param label The label for this checkbox. - */ -public -Checkbox(String label) -{ - this(label, false, null); -} - -/*************************************************************************/ - -/** - * Initializes a new instance of <code>Checkbox</code> with the specified - * label and initial state, and that is not part of any checkbox - * group. - * - * @param label The label for this checkbox. - * @param state The initial state of the checkbox, <code>true</code> for - * on, <code>false</code> for off. - */ -public -Checkbox(String label, boolean state) -{ - this(label, state, null); -} - -/*************************************************************************/ - -/** - * Initializes a new instance of <code>Checkbox</code> with the specified - * label, initial state, and checkbox group. - * - * @param label The label for this checkbox. - * @param group The checkbox group for this box, or <code>null</code> - * if there is no checkbox group. - * @param state The initial state of the checkbox, <code>true</code> for - * on, <code>false</code> for off. - */ -public -Checkbox(String label, CheckboxGroup group, boolean state) -{ - this(label, state, group); -} - -/*************************************************************************/ - -/** - * Initializes a new instance of <code>Checkbox</code> with the specified - * label, initial state, and checkbox group. - * - * @param label The label for this checkbox. - * @param state The initial state of the checkbox, <code>true</code> for - * on, <code>false</code> for off. - * @param group The checkbox group for this box, or <code>null</code> - * if there is no checkbox group. - */ -public -Checkbox(String label, boolean state, CheckboxGroup group) -{ - this.label = label; - this.state = state; - this.group = group; -} - -/*************************************************************************/ - -/* - * Instance Variables - */ - -/** - * Returns the label for this checkbox. - * - * @return The label for this checkbox. - */ -public String -getLabel() -{ - return(label); -} - -/*************************************************************************/ - -/** - * Sets the label for this checkbox to the specified value. - * - * @param label The new checkbox label. - */ -public synchronized void -setLabel(String label) -{ - this.label = label; - if (peer != null) - { - CheckboxPeer cp = (CheckboxPeer) peer; - cp.setLabel(label); - } -} - -/*************************************************************************/ - -/** - * Returns the state of this checkbox. - * - * @return The state of this checkbox, which will be <code>true</code> for - * on and <code>false</code> for off. - */ -public boolean -getState() -{ - return(state); -} - -/*************************************************************************/ - -/** - * Sets the state of this checkbox to the specified value. - * - * @param state The new state of the checkbox, which will be <code>true</code> - * for on or <code>false</code> for off. - */ -public synchronized void -setState(boolean state) -{ - this.state = state; - if (peer != null) - { - CheckboxPeer cp = (CheckboxPeer) peer; - cp.setState (state); - } -} - -/*************************************************************************/ - -/** - * Returns an array of length one containing the checkbox label if this - * checkbox is selected. Otherwise <code>null</code> is returned. - * - * @return The selection state of this checkbox. - */ -public Object[] -getSelectedObjects() -{ - if (state == false) - return(null); - - Object[] objs = new Object[1]; - objs[0] = label; - - return(objs); -} - -/*************************************************************************/ - -/** - * Returns the checkbox group this object is a member of, if any. - * - * @return This object's checkbox group, of <code>null</code> if it is - * not a member of any group. - */ -public CheckboxGroup -getCheckboxGroup() -{ - return(group); -} - -/*************************************************************************/ - -/** - * Sets this object's checkbox group to the specified group. - * - * @param group The new checkbox group, or <code>null</code> to make this - * object part of no checkbox group. - */ -public synchronized void -setCheckboxGroup(CheckboxGroup group) -{ - this.group = group; - if (peer != null) - { - CheckboxPeer cp = (CheckboxPeer) peer; - cp.setCheckboxGroup (group); - } -} - -/*************************************************************************/ - -/** - * Creates this object's native peer. - */ -public void -addNotify() -{ - if (peer == null) - peer = getToolkit ().createCheckbox (this); - super.addNotify (); -} - - public ItemListener[] getItemListeners () - { - return (ItemListener[]) - AWTEventMulticaster.getListeners (item_listeners, ItemListener.class); - } - -/** - * Adds a new listeners to the list of registered listeners for this object. - * - * @param listener The new listener to add. - */ -public synchronized void -addItemListener(ItemListener listener) -{ - item_listeners = AWTEventMulticaster.add(item_listeners, listener); -} - -/*************************************************************************/ - -/** - * Removes a listener from the list of registered listeners for this object. - * - * @param listener The listener to remove. - */ -public synchronized void -removeItemListener(ItemListener listener) -{ - item_listeners = AWTEventMulticaster.remove(item_listeners, listener); -} - -/*************************************************************************/ - -/** - * Processes this event by calling <code>processItemEvent()</code> if it - * is any instance of <code>ItemEvent</code>. Otherwise it is passed to - * the superclass for processing. - * - * @param event The event to process. - */ -protected void -processEvent(AWTEvent event) -{ - if (event instanceof ItemEvent) - processItemEvent((ItemEvent)event); - else - super.processEvent(event); -} - -/*************************************************************************/ - -/** - * Processes this event by dispatching it to any registered listeners. - * - * @param event The <code>ItemEvent</code> to process. - */ -protected void -processItemEvent(ItemEvent event) -{ - if (item_listeners != null) - item_listeners.itemStateChanged(event); -} - -void -dispatchEventImpl(AWTEvent e) -{ - if (e.id <= ItemEvent.ITEM_LAST - && e.id >= ItemEvent.ITEM_FIRST - && (item_listeners != null - || (eventMask & AWTEvent.ITEM_EVENT_MASK) != 0)) - processEvent(e); - else - super.dispatchEventImpl(e); -} - -/*************************************************************************/ - -/** - * Returns a debugging string for this object. - */ -protected String -paramString() -{ - return ("label=" + label + ",state=" + state + ",group=" + group - + "," + super.paramString()); -} - -/** - * Gets the AccessibleContext associated with this <code>Checkbox</code>. - * The context is created, if necessary. - * - * @return the associated context - */ -public AccessibleContext getAccessibleContext() -{ - /* Create the context if this is the first request */ - if (accessibleContext == null) - { - AccessibleAWTCheckbox ac = new AccessibleAWTCheckbox(); - accessibleContext = ac; - addItemListener(ac); - } - return accessibleContext; -} - - /** - * Generate a unique name for this checkbox. - * - * @return A unique name for this checkbox. - */ - String generateName() - { - return "checkbox" + getUniqueLong(); - } - - private static synchronized long getUniqueLong() - { - return next_checkbox_number++; - } -} diff --git a/libjava/java/awt/CheckboxGroup.java b/libjava/java/awt/CheckboxGroup.java deleted file mode 100644 index 31b573e654d..00000000000 --- a/libjava/java/awt/CheckboxGroup.java +++ /dev/null @@ -1,173 +0,0 @@ -/* CheckboxGroup.java -- A grouping class for checkboxes. - Copyright (C) 1999, 2000, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -/** - * This class if for combining checkboxes into groups so that only - * one checkbox in the group can be selected at any one time. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Tom Tromey (tromey@redhat.com) - */ -public class CheckboxGroup implements java.io.Serializable -{ - -/* - * Static Variables - */ - -// Serialization constant -private static final long serialVersionUID = 3729780091441768983L; - -/*************************************************************************/ - -/* - * Instance Variables - */ - -/** - * @serial The currently selected checkbox. - */ -private Checkbox selectedCheckbox; - -/*************************************************************************/ - -/* - * Constructors - */ - -/** - * Initializes a new instance of <code>CheckboxGroup</code>. - */ -public -CheckboxGroup() -{ -} - -/*************************************************************************/ - -/* - * Instance Methods - */ - -/** - * Returns the currently selected checkbox, or <code>null</code> if none - * of the checkboxes in this group are selected. - * - * @return The selected checkbox. - */ -public Checkbox -getSelectedCheckbox() -{ - return getCurrent (); -} - -/*************************************************************************/ - -/** - * Returns the currently selected checkbox, or <code>null</code> if none - * of the checkboxes in this group are selected. - * - * @return The selected checkbox. - * - * @deprecated This method is deprecated in favor of - * <code>getSelectedCheckbox()</code>. - */ -public Checkbox -getCurrent() -{ - return(selectedCheckbox); -} - -/*************************************************************************/ - -/** - * This method sets the specified checkbox to be the selected on in this - * group, and unsets all others. - * - * @param selectedCheckbox The new selected checkbox. - */ -public void -setSelectedCheckbox(Checkbox selectedCheckbox) -{ - setCurrent (selectedCheckbox); -} - -/*************************************************************************/ - -/** - * This method sets the specified checkbox to be the selected on in this - * group, and unsets all others. - * - * @param selectedCheckbox The new selected checkbox. - * - * @deprecated This method is deprecated in favor of - * <code>setSelectedCheckbox()</code>. - */ -public void -setCurrent(Checkbox selectedCheckbox) -{ - if (this.selectedCheckbox != null) - { - if (this.selectedCheckbox.getCheckboxGroup() != this) - return; - - this.selectedCheckbox.setState(false); - } - - this.selectedCheckbox = selectedCheckbox; - if (selectedCheckbox != null) - selectedCheckbox.setState(true); -} - -/*************************************************************************/ - -/** - * Returns a string representation of this checkbox group. - * - * @return A string representation of this checkbox group. - */ -public String -toString() -{ - return(getClass().getName() + "[selectedCheckbox=" + selectedCheckbox + "]"); -} - -} // class CheckboxGroup - diff --git a/libjava/java/awt/CheckboxMenuItem.java b/libjava/java/awt/CheckboxMenuItem.java deleted file mode 100644 index 5e446b84c8b..00000000000 --- a/libjava/java/awt/CheckboxMenuItem.java +++ /dev/null @@ -1,355 +0,0 @@ -/* CheckboxMenuItem.java -- A menu option with a checkbox on it. - Copyright (C) 1999, 2000, 2001, 2002, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.awt.event.ItemEvent; -import java.awt.event.ItemListener; -import java.awt.peer.CheckboxMenuItemPeer; -import java.util.EventListener; - -import javax.accessibility.Accessible; -import javax.accessibility.AccessibleAction; -import javax.accessibility.AccessibleContext; -import javax.accessibility.AccessibleValue; - -/** - * This class implements a menu item that has a checkbox on it indicating - * the selected state of some option. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Tom Tromey (tromey@redhat.com) - */ -public class CheckboxMenuItem extends MenuItem - implements ItemSelectable, Accessible -{ - -/* - * Static Variables - */ - -// Serialization constant -private static final long serialVersionUID = 6190621106981774043L; - -/* - * Instance Variables - */ - -/** - * @serial The state of the checkbox, with <code>true</code> being on and - * <code>false</code> being off. - */ -private boolean state; - -// List of registered ItemListeners -private transient ItemListener item_listeners; - -/*************************************************************************/ - -/* - * Constructors - */ - -/** - * Initializes a new instance of <code>CheckboxMenuItem</code> with no - * label and an initial state of off. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() - * returns true. - */ -public -CheckboxMenuItem() -{ - this("", false); -} - -/*************************************************************************/ - -/** - * Initializes a new instance of <code>CheckboxMenuItem</code> with the - * specified label and an initial state of off. - * - * @param label The label of the menu item. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() - * returns true. - */ -public -CheckboxMenuItem(String label) -{ - this(label, false); -} - -/*************************************************************************/ - -/** - * Initializes a new instance of <code>CheckboxMenuItem</code> with the - * specified label and initial state. - * - * @param label The label of the menu item. - * @param state The initial state of the menu item, where <code>true</code> - * is on, and <code>false</code> is off. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() - * returns true. - */ -public -CheckboxMenuItem(String label, boolean state) -{ - super(label); - this.state = state; - - if (GraphicsEnvironment.isHeadless()) - throw new HeadlessException (); -} - -/*************************************************************************/ - -/* - * Instance Methods - */ - -/** - * Returns the state of this menu item. - * - * @return The state of this menu item. - */ -public boolean -getState() -{ - return(state); -} - -/*************************************************************************/ - -/** - * Sets the state of this menu item. - * - * @param state The initial state of the menu item, where <code>true</code> - * is on, and <code>false</code> is off. - */ -public synchronized void -setState(boolean state) -{ - this.state = state; - if (peer != null) - { - CheckboxMenuItemPeer cp = (CheckboxMenuItemPeer) peer; - cp.setState (state); - } -} - -/*************************************************************************/ - -/** - * Returns an array of length 1 with the menu item label for this object - * if the state is on. Otherwise <code>null</code> is returned. - * - * @return An array with this menu item's label if it has a state of on, - * or <code>null</code> otherwise. - */ -public Object[] -getSelectedObjects() -{ - if (state == false) - return(null); - - Object[] obj = new Object[1]; - obj[0] = getLabel(); - - return(obj); -} - -/*************************************************************************/ - -/** - * Create's this object's native peer - */ -public synchronized void -addNotify() -{ - if (peer == null) - peer = getToolkit().createCheckboxMenuItem(this); - - super.addNotify (); -} - -/*************************************************************************/ - -/** - * Adds the specified listener to the list of registered item listeners - * for this object. - * - * @param listener The listener to add. - */ -public synchronized void -addItemListener(ItemListener listener) -{ - item_listeners = AWTEventMulticaster.add(item_listeners, listener); - - enableEvents(AWTEvent.ITEM_EVENT_MASK); -} - -/*************************************************************************/ - -/** - * Removes the specified listener from the list of registered item - * listeners for this object. - * - * @param listener The listener to remove. - */ -public synchronized void -removeItemListener(ItemListener listener) -{ - item_listeners = AWTEventMulticaster.remove(item_listeners, listener); -} - -/*************************************************************************/ - -/** - * Processes the specified event by calling <code>processItemEvent()</code> - * if it is an instance of <code>ItemEvent</code> or calling the superclass - * method otherwise. - * - * @param event The event to process. - */ -protected void -processEvent(AWTEvent event) -{ - if (event instanceof ItemEvent) - processItemEvent((ItemEvent)event); - else - super.processEvent(event); -} - -/*************************************************************************/ - -/** - * Processes the specified event by dispatching it to any registered listeners. - * - * @param event The event to process. - */ -protected void -processItemEvent(ItemEvent event) -{ - if (item_listeners != null) - item_listeners.itemStateChanged(event); -} - -void -dispatchEventImpl(AWTEvent e) -{ - if (e instanceof ItemEvent) - { - synchronized (this) - { - state = (((ItemEvent) e).getStateChange() == ItemEvent.SELECTED); - } - } - - if (e.id <= ItemEvent.ITEM_LAST - && e.id >= ItemEvent.ITEM_FIRST - && (item_listeners != null - || (eventMask & AWTEvent.ITEM_EVENT_MASK) != 0)) - processEvent(e); - else - super.dispatchEventImpl(e); -} - -/*************************************************************************/ - -/** - * Returns a debugging string for this object. - * - * @return A debugging string for this object. - */ -public String -paramString() -{ - return ("label=" + getLabel() + ",state=" + state - + "," + super.paramString()); -} - - /** - * Returns an array of all the objects currently registered as FooListeners - * upon this <code>CheckboxMenuItem</code>. FooListeners are registered using - * the addFooListener method. - * - * @exception ClassCastException If listenerType doesn't specify a class or - * interface that implements java.util.EventListener. - */ - public EventListener[] getListeners (Class listenerType) - { - if (listenerType == ItemListener.class) - return AWTEventMulticaster.getListeners (item_listeners, listenerType); - - return super.getListeners (listenerType); - } - - /** - * Returns an aray of all item listeners currently registered to this - * <code>CheckBoxMenuItem</code>. - */ - public ItemListener[] getItemListeners () - { - return (ItemListener[]) getListeners (ItemListener.class); - } - - - protected class AccessibleAWTCheckboxMenuItem extends AccessibleAWTMenuItem - implements AccessibleAction, AccessibleValue - { - // I think the base class provides the necessary implementation - } - - /** - * Gets the AccessibleContext associated with this <code>CheckboxMenuItem</code>. - * The context is created, if necessary. - * - * @return the associated context - */ - public AccessibleContext getAccessibleContext() - { - /* Create the context if this is the first request */ - if (accessibleContext == null) - accessibleContext = new AccessibleAWTCheckboxMenuItem(); - return accessibleContext; - } - -} // class CheckboxMenuItem - diff --git a/libjava/java/awt/Choice.java b/libjava/java/awt/Choice.java deleted file mode 100644 index 5075ea92d83..00000000000 --- a/libjava/java/awt/Choice.java +++ /dev/null @@ -1,638 +0,0 @@ -/* Choice.java -- Java choice button widget. - Copyright (C) 1999, 2000, 2001, 2002, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.awt.event.ItemEvent; -import java.awt.event.ItemListener; -import java.awt.peer.ChoicePeer; -import java.io.Serializable; -import java.util.EventListener; -import java.util.Vector; - -import javax.accessibility.Accessible; -import javax.accessibility.AccessibleAction; -import javax.accessibility.AccessibleContext; -import javax.accessibility.AccessibleRole; - -/** - * This class implements a drop down choice list. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public class Choice extends Component - implements ItemSelectable, Serializable, Accessible -{ - -/* - * Static Variables - */ - -// Serialization constant -private static final long serialVersionUID = -4075310674757313071L; - -/*************************************************************************/ - -/* - * Instance Variables - */ - -/** - * @serial A list of items for the choice box, which can be <code>null</code>. - * This is package-private to avoid an accessor method. - */ -Vector pItems = new Vector(); - -/** - * @serial The index of the selected item in the choice box. - */ -private int selectedIndex = -1; - -// Listener chain -private ItemListener item_listeners; - -/** - * This class provides accessibility support for the - * combo box. - * - * @author Jerry Quinn (jlquinn@optonline.net) - * @author Andrew John Hughes (gnu_andrew@member.fsf.org) - */ - protected class AccessibleAWTChoice - extends AccessibleAWTComponent - implements AccessibleAction - { - - /** - * Serialization constant to match JDK 1.5 - */ - private static final long serialVersionUID = 7175603582428509322L; - - /** - * Default constructor which simply calls the - * super class for generic component accessibility - * handling. - */ - public AccessibleAWTChoice() - { - super(); - } - - /** - * Returns an implementation of the <code>AccessibleAction</code> - * interface for this accessible object. In this case, the - * current instance is simply returned (with a more appropriate - * type), as it also implements the accessible action as well as - * the context. - * - * @return the accessible action associated with this context. - * @see javax.accessibility.AccessibleAction - */ - public AccessibleAction getAccessibleAction() - { - return this; - } - - /** - * Returns the role of this accessible object. - * - * @return the instance of <code>AccessibleRole</code>, - * which describes this object. - * @see javax.accessibility.AccessibleRole - */ - public AccessibleRole getAccessibleRole() - { - return AccessibleRole.COMBO_BOX; - } - - /** - * Returns the number of actions associated with this accessible - * object. In this case, it is the number of choices available. - * - * @return the number of choices available. - * @see javax.accessibility.AccessibleAction#getAccessibleActionCount() - */ - public int getAccessibleActionCount() - { - return pItems.size(); - } - - /** - * Returns a description of the action with the supplied id. - * In this case, it is the text used in displaying the particular - * choice on-screen. - * - * @param i the id of the choice whose description should be - * retrieved. - * @return the <code>String</code> used to describe the choice. - * @see javax.accessibility.AccessibleAction#getAccessibleActionDescription(int) - */ - public String getAccessibleActionDescription(int i) - { - return (String) pItems.get(i); - } - - /** - * Executes the action with the specified id. In this case, - * calling this method provides the same behaviour as would - * choosing a choice from the list in a visual manner. - * - * @param i the id of the choice to select. - * @return true if a valid choice was specified. - * @see javax.accessibility.AccessibleAction#doAccessibleAction(int) - */ - public boolean doAccessibleAction(int i) - { - if (i < 0 || i >= pItems.size()) - return false; - - Choice.this.processItemEvent(new ItemEvent(Choice.this, - ItemEvent.ITEM_STATE_CHANGED, - this, ItemEvent.SELECTED)); - return true; - } - } - -/*************************************************************************/ - -/* - * Constructors - */ - - /** - * Initializes a new instance of <code>Choice</code>. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() - * returns true - */ - public Choice() - { - if (GraphicsEnvironment.isHeadless()) - throw new HeadlessException (); - } - -/*************************************************************************/ - -/* - * Instance Methods - */ - -/** - * Returns the number of items in the list. - * - * @return The number of items in the list. - */ -public int -getItemCount() -{ - return countItems (); -} - -/*************************************************************************/ - -/** - * Returns the number of items in the list. - * - * @return The number of items in the list. - * - * @deprecated This method is deprecated in favor of <code>getItemCount</code>. - */ -public int -countItems() -{ - return(pItems.size()); -} - -/*************************************************************************/ - -/** - * Returns the item at the specified index in the list. - * - * @param index The index into the list to return the item from. - * - * @exception ArrayIndexOutOfBoundsException If the index is invalid. - */ -public String -getItem(int index) -{ - return((String)pItems.elementAt(index)); -} - -/*************************************************************************/ - -/** - * Adds the specified item to this choice box. - * - * @param item The item to add. - * - * @exception NullPointerException If the item's value is null - * - * @since 1.1 - */ -public synchronized void -add(String item) -{ - if (item == null) - throw new NullPointerException ("item must be non-null"); - - pItems.addElement(item); - - int i = pItems.size () - 1; - if (peer != null) - { - ChoicePeer cp = (ChoicePeer) peer; - cp.add (item, i); - } - else if (selectedIndex == -1) - select(0); -} - -/*************************************************************************/ - -/** - * Adds the specified item to this choice box. - * - * This method is oboslete since Java 2 platform 1.1. Please use @see add - * instead. - * - * @param item The item to add. - * - * @exception NullPointerException If the item's value is equal to null - */ -public synchronized void -addItem(String item) -{ - add(item); -} - -/*************************************************************************/ - -/** Inserts an item into this Choice. Existing items are shifted - * upwards. If the new item is the only item, then it is selected. - * If the currently selected item is shifted, then the first item is - * selected. If the currently selected item is not shifted, then it - * remains selected. - * - * @param item The item to add. - * @param index The index at which the item should be inserted. - * - * @exception IllegalArgumentException If index is less than 0 - */ -public synchronized void -insert(String item, int index) -{ - if (index < 0) - throw new IllegalArgumentException ("index may not be less then 0"); - - if (index > getItemCount ()) - index = getItemCount (); - - pItems.insertElementAt(item, index); - - if (peer != null) - { - ChoicePeer cp = (ChoicePeer) peer; - cp.add (item, index); - } - else if (selectedIndex == -1 || selectedIndex >= index) - select(0); -} - -/*************************************************************************/ - -/** - * Removes the specified item from the choice box. - * - * @param item The item to remove. - * - * @exception IllegalArgumentException If the specified item doesn't exist. - */ -public synchronized void -remove(String item) -{ - int index = pItems.indexOf(item); - if (index == -1) - throw new IllegalArgumentException ("item \"" - + item + "\" not found in Choice"); - remove(index); -} - -/*************************************************************************/ - -/** - * Removes the item at the specified index from the choice box. - * - * @param index The index of the item to remove. - * - * @exception IndexOutOfBoundsException If the index is not valid. - */ -public synchronized void -remove(int index) -{ - if ((index < 0) || (index > getItemCount())) - throw new IllegalArgumentException("Bad index: " + index); - - pItems.removeElementAt(index); - - if (peer != null) - { - ChoicePeer cp = (ChoicePeer) peer; - cp.remove (index); - } - else - { - if (getItemCount() == 0) - selectedIndex = -1; - else if (index == selectedIndex) - select(0); - } - - if (selectedIndex > index) - --selectedIndex; -} - -/*************************************************************************/ - -/** - * Removes all of the objects from this choice box. - */ -public synchronized void -removeAll() -{ - if (getItemCount() <= 0) - return; - - pItems.removeAllElements (); - - if (peer != null) - { - ChoicePeer cp = (ChoicePeer) peer; - cp.removeAll (); - } - - selectedIndex = -1; -} - -/*************************************************************************/ - -/** - * Returns the currently selected item, or null if no item is - * selected. - * - * @return The currently selected item. - */ -public synchronized String -getSelectedItem() -{ - return (selectedIndex == -1 - ? null - : ((String)pItems.elementAt(selectedIndex))); -} - -/*************************************************************************/ - -/** - * Returns an array with one row containing the selected item. - * - * @return An array containing the selected item. - */ -public synchronized Object[] -getSelectedObjects() -{ - if (selectedIndex == -1) - return null; - - Object[] objs = new Object[1]; - objs[0] = pItems.elementAt(selectedIndex); - - return(objs); -} - -/*************************************************************************/ - -/** - * Returns the index of the selected item. - * - * @return The index of the selected item. - */ -public int -getSelectedIndex() -{ - return(selectedIndex); -} - -/*************************************************************************/ - -/** - * Forces the item at the specified index to be selected. - * - * @param index The index of the row to make selected. - * - * @exception IllegalArgumentException If the specified index is invalid. - */ -public synchronized void -select(int index) -{ - if ((index < 0) || (index > getItemCount())) - throw new IllegalArgumentException("Bad index: " + index); - - this.selectedIndex = index; - if (peer != null) - { - ChoicePeer cp = (ChoicePeer) peer; - cp.select (index); - } -} - -/*************************************************************************/ - -/** - * Forces the named item to be selected. - * - * @param item The item to be selected. - * - * @exception IllegalArgumentException If the specified item does not exist. - */ -public synchronized void -select(String item) -{ - int index = pItems.indexOf(item); - if (index >= 0) - select(index); -} - -/*************************************************************************/ - -/** - * Creates the native peer for this object. - */ -public void -addNotify() -{ - if (peer == null) - peer = getToolkit ().createChoice (this); - super.addNotify (); -} - -/*************************************************************************/ - -/** - * Adds the specified listener to the list of registered listeners for - * this object. - * - * @param listener The listener to add. - */ -public synchronized void -addItemListener(ItemListener listener) -{ - item_listeners = AWTEventMulticaster.add(item_listeners, listener); -} - -/*************************************************************************/ - -/** - * Removes the specified listener from the list of registered listeners for - * this object. - * - * @param listener The listener to remove. - */ -public synchronized void -removeItemListener(ItemListener listener) -{ - item_listeners = AWTEventMulticaster.remove(item_listeners, listener); -} - -/*************************************************************************/ - -/** - * Processes this event by invoking <code>processItemEvent()</code> if the - * event is an instance of <code>ItemEvent</code>, otherwise the event - * is passed to the superclass. - * - * @param event The event to process. - */ -protected void -processEvent(AWTEvent event) -{ - if (event instanceof ItemEvent) - processItemEvent((ItemEvent)event); - else - super.processEvent(event); -} - -/*************************************************************************/ - -/** - * Processes item event by dispatching to any registered listeners. - * - * @param event The event to process. - */ -protected void -processItemEvent(ItemEvent event) -{ - if (item_listeners != null) - item_listeners.itemStateChanged(event); -} - -void -dispatchEventImpl(AWTEvent e) -{ - if (e.id <= ItemEvent.ITEM_LAST - && e.id >= ItemEvent.ITEM_FIRST - && (item_listeners != null - || (eventMask & AWTEvent.ITEM_EVENT_MASK) != 0)) - processEvent(e); - else - super.dispatchEventImpl(e); -} - -/*************************************************************************/ - -/** - * Returns a debugging string for this object. - * - * @return A debugging string for this object. - */ -protected String -paramString() -{ - return ("selectedIndex=" + selectedIndex + "," + super.paramString()); -} - - /** - * Returns an array of all the objects currently registered as FooListeners - * upon this Choice. FooListeners are registered using the addFooListener - * method. - * - * @exception ClassCastException If listenerType doesn't specify a class or - * interface that implements java.util.EventListener. - * - * @since 1.3 - */ - public EventListener[] getListeners (Class listenerType) - { - if (listenerType == ItemListener.class) - return AWTEventMulticaster.getListeners (item_listeners, listenerType); - - return super.getListeners (listenerType); - } - - /** - * Returns all registered item listeners. - * - * @since 1.4 - */ - public ItemListener[] getItemListeners () - { - return (ItemListener[]) getListeners (ItemListener.class); - } - - /** - * Gets the AccessibleContext associated with this <code>Choice</code>. - * The context is created, if necessary. - * - * @return the associated context - */ - public AccessibleContext getAccessibleContext() - { - /* Create the context if this is the first request */ - if (accessibleContext == null) - accessibleContext = new AccessibleAWTChoice(); - return accessibleContext; - } -} // class Choice diff --git a/libjava/java/awt/Color.java b/libjava/java/awt/Color.java deleted file mode 100644 index 4ad46d0c07c..00000000000 --- a/libjava/java/awt/Color.java +++ /dev/null @@ -1,1008 +0,0 @@ -/* Color.java -- represents a color in Java - Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.awt.color.ColorSpace; -import java.awt.geom.AffineTransform; -import java.awt.geom.Rectangle2D; -import java.awt.image.ColorModel; -import java.io.Serializable; - -/** - * This class represents a color value in the AWT system. It uses the sRGB - * (standard Red-Green-Blue) system, along with an alpha value ranging from - * transparent (0.0f or 0) and opaque (1.0f or 255). The color is not - * pre-multiplied by the alpha value an any of the accessor methods. Further - * information about sRGB can be found at - * <a href="http://www.w3.org/pub/WWW/Graphics/Color/sRGB.html"> - * http://www.w3.org/pub/WWW/Graphics/Color/sRGB.html</a>. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @see ColorSpace - * @see AlphaComposite - * @since 1.0 - * @status updated to 1.4 - */ -public class Color implements Paint, Serializable -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = 118526816881161077L; - - /** Constant for the color white: R=255, G=255, B=255. */ - public static final Color white = new Color(0xffffff, false); - - /** - * Constant for the color white: R=255, G=255, B=255. - * - * @since 1.4 - */ - public static final Color WHITE = white; - - /** Constant for the color light gray: R=192, G=192, B=192. */ - public static final Color lightGray = new Color(0xc0c0c0, false); - - /** - * Constant for the color light gray: R=192, G=192, B=192. - * - * @since 1.4 - */ - public static final Color LIGHT_GRAY = lightGray; - - /** Constant for the color gray: R=128, G=128, B=128. */ - public static final Color gray = new Color(0x808080, false); - - /** - * Constant for the color gray: R=128, G=128, B=128. - * - * @since 1.4 - */ - public static final Color GRAY = gray; - - /** Constant for the color dark gray: R=64, G=64, B=64. */ - public static final Color darkGray = new Color(0x404040, false); - - /** - * Constant for the color dark gray: R=64, G=64, B=64. - * - * @since 1.4 - */ - public static final Color DARK_GRAY = darkGray; - - /** Constant for the color black: R=0, G=0, B=0. */ - public static final Color black = new Color(0x000000, false); - - /** - * Constant for the color black: R=0, G=0, B=0. - * - * @since 1.4 - */ - public static final Color BLACK = black; - - /** Constant for the color red: R=255, G=0, B=0. */ - public static final Color red = new Color(0xff0000, false); - - /** - * Constant for the color red: R=255, G=0, B=0. - * - * @since 1.4 - */ - public static final Color RED = red; - - /** Constant for the color pink: R=255, G=175, B=175. */ - public static final Color pink = new Color(0xffafaf, false); - - /** - * Constant for the color pink: R=255, G=175, B=175. - * - * @since 1.4 - */ - public static final Color PINK = pink; - - /** Constant for the color orange: R=255, G=200, B=0. */ - public static final Color orange = new Color(0xffc800, false); - - /** - * Constant for the color orange: R=255, G=200, B=0. - * - * @since 1.4 - */ - public static final Color ORANGE = orange; - - /** Constant for the color yellow: R=255, G=255, B=0. */ - public static final Color yellow = new Color(0xffff00, false); - - /** - * Constant for the color yellow: R=255, G=255, B=0. - * - * @since 1.4 - */ - public static final Color YELLOW = yellow; - - /** Constant for the color green: R=0, G=255, B=0. */ - public static final Color green = new Color(0x00ff00, false); - - /** - * Constant for the color green: R=0, G=255, B=0. - * - * @since 1.4 - */ - public static final Color GREEN = green; - - /** Constant for the color magenta: R=255, G=0, B=255. */ - public static final Color magenta = new Color(0xff00ff, false); - - /** - * Constant for the color magenta: R=255, G=0, B=255. - * - * @since 1.4 - */ - public static final Color MAGENTA = magenta; - - /** Constant for the color cyan: R=0, G=255, B=255. */ - public static final Color cyan = new Color(0x00ffff, false); - - /** - * Constant for the color cyan: R=0, G=255, B=255. - * - * @since 1.4 - */ - public static final Color CYAN = cyan; - - /** Constant for the color blue: R=0, G=0, B=255. */ - public static final Color blue = new Color(0x0000ff, false); - - /** - * Constant for the color blue: R=0, G=0, B=255. - * - * @since 1.4 - */ - public static final Color BLUE = blue; - - /** Internal mask for red. */ - private static final int RED_MASK = 255 << 16; - - /** Internal mask for green. */ - private static final int GREEN_MASK = 255 << 8; - - /** Internal mask for blue. */ - private static final int BLUE_MASK = 255; - - /** Internal mask for alpha. Package visible for use in subclass. */ - static final int ALPHA_MASK = 255 << 24; - - /** Amount to scale a color by when brightening or darkening. */ - private static final float BRIGHT_SCALE = 0.7f; - - /** - * The color value, in sRGB. Note that the actual color may be more - * precise if frgbvalue or fvalue is non-null. This class stores alpha, red, - * green, and blue, each 0-255, packed in an int. However, the subclass - * SystemColor stores an index into an array. Therefore, for serial - * compatibility (and because of poor design on Sun's part), this value - * cannot be used directly; instead you must use <code>getRGB()</code>. - * - * @see #getRGB() - * @serial the value of the color, whether an RGB literal or array index - */ - final int value; - - /** - * The color value, in sRGB. This may be null if the color was constructed - * with ints; and it does not include alpha. This stores red, green, and - * blue, in the range 0.0f - 1.0f. - * - * @see #getRGBColorComponents(float[]) - * @see #getRGBComponents(float[]) - * @serial the rgb components of the value - * @since 1.2 - */ - private float[] frgbvalue; - - /** - * The color value, in the native ColorSpace components. This may be null - * if the color was constructed with ints or in the sRGB color space; and - * it does not include alpha. - * - * @see #getRGBColorComponents(float[]) - * @see #getRGBComponents(float[]) - * @serial the original color space components of the color - * @since 1.2 - */ - private float[] fvalue; - - /** - * The alpha value. This is in the range 0.0f - 1.0f, but is invalid if - * deserialized as 0.0 when frgbvalue is null. - * - * @see #getRGBComponents(float[]) - * @see #getComponents(float[]) - * @serial the alpha component of this color - * @since 1.2 - */ - private final float falpha; - - /** - * The ColorSpace. Null means the default sRGB space. - * - * @see #getColor(String) - * @see #getColorSpace() - * @see #getColorComponents(float[]) - * @serial the color space for this color - * @since 1.2 - */ - private final ColorSpace cs; - - /** - * The paint context for this solid color. Package visible for use in - * subclass. - */ - transient ColorPaintContext context; - - /** - * Initializes a new instance of <code>Color</code> using the specified - * red, green, and blue values, which must be given as integers in the - * range of 0-255. Alpha will default to 255 (opaque). When drawing to - * screen, the actual color may be adjusted to the best match of hardware - * capabilities. - * - * @param red the red component of the RGB value - * @param green the green component of the RGB value - * @param blue the blue component of the RGB value - * @throws IllegalArgumentException if the values are out of range 0-255 - * @see #getRed() - * @see #getGreen() - * @see #getBlue() - * @see #getRGB() - * @see #Color(int, int, int, int) - */ - public Color(int red, int green, int blue) - { - this(red, green, blue, 255); - } - - /** - * Initializes a new instance of <code>Color</code> using the specified - * red, green, blue, and alpha values, which must be given as integers in - * the range of 0-255. When drawing to screen, the actual color may be - * adjusted to the best match of hardware capabilities. - * - * @param red the red component of the RGB value - * @param green the green component of the RGB value - * @param blue the blue component of the RGB value - * @param alpha the alpha value of the color - * @throws IllegalArgumentException if the values are out of range 0-255 - * @see #getRed() - * @see #getGreen() - * @see #getBlue() - * @see #getAlpha() - * @see #getRGB() - */ - public Color(int red, int green, int blue, int alpha) - { - if ((red & 255) != red || (green & 255) != green || (blue & 255) != blue - || (alpha & 255) != alpha) - throw new IllegalArgumentException("Bad RGB values" - +" red=0x"+Integer.toHexString(red) - +" green=0x"+Integer.toHexString(green) - +" blue=0x"+Integer.toHexString(blue) - +" alpha=0x"+Integer.toHexString(alpha) ); - - value = (alpha << 24) | (red << 16) | (green << 8) | blue; - falpha = 1; - cs = null; - } - - /** - * Initializes a new instance of <code>Color</code> using the specified - * RGB value. The blue value is in bits 0-7, green in bits 8-15, and - * red in bits 16-23. The other bits are ignored. The alpha value is set - * to 255 (opaque). When drawing to screen, the actual color may be - * adjusted to the best match of hardware capabilities. - * - * @param value the RGB value - * @see ColorModel#getRGBdefault() - * @see #getRed() - * @see #getGreen() - * @see #getBlue() - * @see #getRGB() - * @see #Color(int, boolean) - */ - public Color(int value) - { - this(value, false); - } - - /** - * Initializes a new instance of <code>Color</code> using the specified - * RGB value. The blue value is in bits 0-7, green in bits 8-15, and - * red in bits 16-23. The alpha value is in bits 24-31, unless hasalpha - * is false, in which case alpha is set to 255. When drawing to screen, the - * actual color may be adjusted to the best match of hardware capabilities. - * - * @param value the RGB value - * @param hasalpha true if value includes the alpha - * @see ColorModel#getRGBdefault() - * @see #getRed() - * @see #getGreen() - * @see #getBlue() - * @see #getAlpha() - * @see #getRGB() - */ - public Color(int value, boolean hasalpha) - { - // Note: SystemColor calls this constructor, setting falpha to 0; but - // code in getRGBComponents correctly reports falpha as 1.0 to the user - // for all instances of SystemColor since frgbvalue is left null here. - if (hasalpha) - falpha = ((value & ALPHA_MASK) >> 24) / 255f; - else - { - value |= ALPHA_MASK; - falpha = 1; - } - this.value = value; - cs = null; - } - - /** - * Initializes a new instance of <code>Color</code> using the specified - * RGB values. These must be in the range of 0.0-1.0. Alpha is assigned - * the value of 1.0 (opaque). When drawing to screen, the actual color may - * be adjusted to the best match of hardware capabilities. - * - * @param red the red component of the RGB value - * @param green the green component of the RGB value - * @param blue the blue component of the RGB value - * @throws IllegalArgumentException tf the values are out of range 0.0f-1.0f - * @see #getRed() - * @see #getGreen() - * @see #getBlue() - * @see #getRGB() - * @see #Color(float, float, float, float) - */ - public Color(float red, float green, float blue) - { - this(red, green, blue, 1.0f); - } - - /** - * Initializes a new instance of <code>Color</code> using the specified - * RGB and alpha values. These must be in the range of 0.0-1.0. When drawing - * to screen, the actual color may be adjusted to the best match of - * hardware capabilities. - * - * @param red the red component of the RGB value - * @param green the green component of the RGB value - * @param blue the blue component of the RGB value - * @param alpha the alpha value of the color - * @throws IllegalArgumentException tf the values are out of range 0.0f-1.0f - * @see #getRed() - * @see #getGreen() - * @see #getBlue() - * @see #getAlpha() - * @see #getRGB() - */ - public Color(float red, float green, float blue, float alpha) - { - value = convert(red, green, blue, alpha); - frgbvalue = new float[] {red, green, blue}; - falpha = alpha; - cs = null; - } - - /** - * Creates a color in the given ColorSpace with the specified alpha. The - * array must be non-null and have enough elements for the color space - * (for example, RGB requires 3 elements, CMYK requires 4). When drawing - * to screen, the actual color may be adjusted to the best match of - * hardware capabilities. - * - * @param space the color space of components - * @param components the color components, except alpha - * @param alpha the alpha value of the color - * @throws NullPointerException if cpsace or components is null - * @throws ArrayIndexOutOfBoundsException if components is too small - * @throws IllegalArgumentException if alpha or any component is out of range - * @see #getComponents(float[]) - * @see #getColorComponents(float[]) - */ - public Color(ColorSpace space, float[] components, float alpha) - { - frgbvalue = space.toRGB(components); - fvalue = components; - falpha = alpha; - cs = space; - value = convert(frgbvalue[0], frgbvalue[1], frgbvalue[2], alpha); - } - - /** - * Returns the red value for this color, as an integer in the range 0-255 - * in the sRGB color space. - * - * @return the red value for this color - * @see #getRGB() - */ - public int getRed() - { - // Do not inline getRGB() to value, because of SystemColor. - return (getRGB() & RED_MASK) >> 16; - } - - /** - * Returns the green value for this color, as an integer in the range 0-255 - * in the sRGB color space. - * - * @return the green value for this color - * @see #getRGB() - */ - public int getGreen() - { - // Do not inline getRGB() to value, because of SystemColor. - return (getRGB() & GREEN_MASK) >> 8; - } - - /** - * Returns the blue value for this color, as an integer in the range 0-255 - * in the sRGB color space. - * - * @return the blue value for this color - * @see #getRGB() - */ - public int getBlue() - { - // Do not inline getRGB() to value, because of SystemColor. - return getRGB() & BLUE_MASK; - } - - /** - * Returns the alpha value for this color, as an integer in the range 0-255. - * - * @return the alpha value for this color - * @see #getRGB() - */ - public int getAlpha() - { - // Do not inline getRGB() to value, because of SystemColor. - return (getRGB() & ALPHA_MASK) >>> 24; - } - - /** - * Returns the RGB value for this color, in the sRGB color space. The blue - * value will be in bits 0-7, green in 8-15, red in 16-23, and alpha value in - * 24-31. - * - * @return the RGB value for this color - * @see ColorModel#getRGBdefault() - * @see #getRed() - * @see #getGreen() - * @see #getBlue() - * @see #getAlpha() - */ - public int getRGB() - { - return value; - } - - /** - * Returns a brighter version of this color. This is done by increasing the - * RGB values by an arbitrary scale factor. The new color is opaque (an - * alpha of 255). Note that this method and the <code>darker()</code> - * method are not necessarily inverses. - * - * @return a brighter version of this color - * @see #darker() - */ - public Color brighter() - { - // Do not inline getRGB() to this.value, because of SystemColor. - int value = getRGB(); - int red = (value & RED_MASK) >> 16; - int green = (value & GREEN_MASK) >> 8; - int blue = value & BLUE_MASK; - // We have to special case 0-2 because they won't scale by division. - red = red < 3 ? 3 : (int) Math.min(255, red / BRIGHT_SCALE); - green = green < 3 ? 3 : (int) Math.min(255, green / BRIGHT_SCALE); - blue = blue < 3 ? 3 : (int) Math.min(255, blue / BRIGHT_SCALE); - return new Color(red, green, blue, 255); - } - - /** - * Returns a darker version of this color. This is done by decreasing the - * RGB values by an arbitrary scale factor. The new color is opaque (an - * alpha of 255). Note that this method and the <code>brighter()</code> - * method are not necessarily inverses. - * - * @return a darker version of this color - * @see #brighter() - */ - public Color darker() - { - // Do not inline getRGB() to this.value, because of SystemColor. - int value = getRGB(); - return new Color((int) (((value & RED_MASK) >> 16) * BRIGHT_SCALE), - (int) (((value & GREEN_MASK) >> 8) * BRIGHT_SCALE), - (int) ((value & BLUE_MASK) * BRIGHT_SCALE), 255); - } - - /** - * Returns a hash value for this color. This is simply the color in 8-bit - * precision, in the format 0xAARRGGBB (alpha, red, green, blue). - * - * @return a hash value for this color - */ - public int hashCode() - { - return value; - } - - /** - * Tests this object for equality against the specified object. This will - * be true if and only if the specified object is an instance of - * <code>Color</code> and has the same 8-bit integer red, green, and blue - * values as this object. Note that two colors may be slightly different - * as float values, but round to the same integer values. Also note that - * this does not accurately compare SystemColors, since that class does - * not store its internal data in RGB format like regular colors. - * - * @param obj the object to compare to - * @return true if the specified object is semantically equal to this one - */ - public boolean equals(Object obj) - { - return obj instanceof Color && ((Color) obj).value == value; - } - - /** - * Returns a string representation of this object. Subclasses may return - * any desired format, except for null, but this implementation returns - * <code>getClass().getName() + "[r=" + getRed() + ",g=" + getGreen() - * + ",b=" + getBlue() + ']'</code>. - * - * @return a string representation of this object - */ - public String toString() - { - return getClass().getName() + "[r=" + ((value & RED_MASK) >> 16) - + ",g=" + ((value & GREEN_MASK) >> 8) + ",b=" + (value & BLUE_MASK) - + ']'; - } - - /** - * Converts the specified string to a number, using Integer.decode, and - * creates a new instance of <code>Color</code> from the value. The alpha - * value will be 255 (opaque). - * - * @param str the numeric color string - * @return a new instance of <code>Color</code> for the string - * @throws NumberFormatException if the string cannot be parsed - * @throws NullPointerException if the string is null - * @see Integer#decode(String) - * @see #Color(int) - * @since 1.1 - */ - public static Color decode(String str) - { - return new Color(Integer.decode(str).intValue(), false); - } - - /** - * Returns a new instance of <code>Color</code> from the value of the - * system property named by the specified string. If the property does not - * exist, or cannot be parsed, then <code>null</code> will be returned. - * - * @param prop the system property to retrieve - * @throws SecurityException if getting the property is denied - * @see #getColor(String, Color) - * @see Integer#getInteger(String) - */ - public static Color getColor(String prop) - { - return getColor(prop, null); - } - - /** - * Returns a new instance of <code>Color</code> from the value of the - * system property named by the specified string. If the property does - * not exist, or cannot be parsed, then the default color value will be - * returned. - * - * @param prop the system property to retrieve - * @param defcolor the default color - * @throws SecurityException if getting the property is denied - * @see Integer#getInteger(String) - */ - public static Color getColor(String prop, Color defcolor) - { - Integer val = Integer.getInteger(prop, null); - return val == null ? defcolor - : new Color(val.intValue(), false); - } - - /** - * Returns a new instance of <code>Color</code> from the value of the - * system property named by the specified string. If the property does - * not exist, or cannot be parsed, then the default RGB value will be - * used to create a return value. - * - * @param prop the system property to retrieve - * @param defrgb the default RGB value - * @throws SecurityException if getting the property is denied - * @see #getColor(String, Color) - * @see Integer#getInteger(String, int) - */ - public static Color getColor(String prop, int defrgb) - { - Color c = getColor(prop, null); - return c == null ? new Color(defrgb, false) : c; - } - - /** - * Converts from the HSB (hue, saturation, brightness) color model to the - * RGB (red, green, blue) color model. The hue may be any floating point; - * it's fractional portion is used to select the angle in the HSB model. - * The saturation and brightness must be between 0 and 1. The result is - * suitable for creating an RGB color with the one-argument constructor. - * - * @param hue the hue of the HSB value - * @param saturation the saturation of the HSB value - * @param brightness the brightness of the HSB value - * @return the RGB value - * @see #getRGB() - * @see #Color(int) - * @see ColorModel#getRGBdefault() - */ - public static int HSBtoRGB(float hue, float saturation, float brightness) - { - if (saturation == 0) - return convert(brightness, brightness, brightness, 0); - if (saturation < 0 || saturation > 1 || brightness < 0 || brightness > 1) - throw new IllegalArgumentException(); - hue = hue - (float) Math.floor(hue); - int i = (int) (6 * hue); - float f = 6 * hue - i; - float p = brightness * (1 - saturation); - float q = brightness * (1 - saturation * f); - float t = brightness * (1 - saturation * (1 - f)); - switch (i) - { - case 0: - return convert(brightness, t, p, 0); - case 1: - return convert(q, brightness, p, 0); - case 2: - return convert(p, brightness, t, 0); - case 3: - return convert(p, q, brightness, 0); - case 4: - return convert(t, p, brightness, 0); - case 5: - return convert(brightness, p, q, 0); - default: - throw new InternalError("impossible"); - } - } - - /** - * Converts from the RGB (red, green, blue) color model to the HSB (hue, - * saturation, brightness) color model. If the array is null, a new one - * is created, otherwise it is recycled. The results will be in the range - * 0.0-1.0 if the inputs are in the range 0-255. - * - * @param red the red part of the RGB value - * @param green the green part of the RGB value - * @param blue the blue part of the RGB value - * @param array an array for the result (at least 3 elements), or null - * @return the array containing HSB value - * @throws ArrayIndexOutOfBoundsException of array is too small - * @see #getRGB() - * @see #Color(int) - * @see ColorModel#getRGBdefault() - */ - public static float[] RGBtoHSB(int red, int green, int blue, float array[]) - { - if (array == null) - array = new float[3]; - // Calculate brightness. - int min; - int max; - if (red < green) - { - min = red; - max = green; - } - else - { - min = green; - max = red; - } - if (blue > max) - max = blue; - else if (blue < min) - min = blue; - array[2] = max / 255f; - // Calculate saturation. - if (max == 0) - array[1] = 0; - else - array[1] = (max - min) / max; - // Calculate hue. - if (array[1] == 0) - array[0] = 0; - else - { - float delta = (max - min) * 6; - if (red == max) - array[0] = (green - blue) / delta; - else if (green == max) - array[0] = 1f / 3 + (blue - red) / delta; - else - array[0] = 2f / 3 + (red - green) / delta; - if (array[0] < 0) - array[0]++; - } - return array; - } - - /** - * Returns a new instance of <code>Color</code> based on the specified - * HSB values. The hue may be any floating point; it's fractional portion - * is used to select the angle in the HSB model. The saturation and - * brightness must be between 0 and 1. - * - * @param hue the hue of the HSB value - * @param saturation the saturation of the HSB value - * @param brightness the brightness of the HSB value - * @return the new <code>Color</code> object - */ - public static Color getHSBColor(float hue, float saturation, - float brightness) - { - return new Color(HSBtoRGB(hue, saturation, brightness), false); - } - - /** - * Returns a float array with the red, green, and blue components, and the - * alpha value, in the default sRGB space, with values in the range 0.0-1.0. - * If the array is null, a new one is created, otherwise it is recycled. - * - * @param array the array to put results into (at least 4 elements), or null - * @return the RGB components and alpha value - * @throws ArrayIndexOutOfBoundsException if array is too small - */ - public float[] getRGBComponents(float[] array) - { - if (array == null) - array = new float[4]; - getRGBColorComponents(array); - // Stupid serialization issues require this check. - array[3] = (falpha == 0 && frgbvalue == null - ? ((getRGB() & ALPHA_MASK) >> 24) / 255f : falpha); - return array; - } - - /** - * Returns a float array with the red, green, and blue components, in the - * default sRGB space, with values in the range 0.0-1.0. If the array is - * null, a new one is created, otherwise it is recycled. - * - * @param array the array to put results into (at least 3 elements), or null - * @return the RGB components - * @throws ArrayIndexOutOfBoundsException if array is too small - */ - public float[] getRGBColorComponents(float[] array) - { - if (array == null) - array = new float[3]; - else if (array == frgbvalue) - return array; // Optimization for getColorComponents(float[]). - if (frgbvalue == null) - { - // Do not inline getRGB() to this.value, because of SystemColor. - int value = getRGB(); - frgbvalue = new float[] { ((value & RED_MASK) >> 16) / 255f, - ((value & GREEN_MASK) >> 8) / 255f, - (value & BLUE_MASK) / 255f }; - } - array[0] = frgbvalue[0]; - array[1] = frgbvalue[1]; - array[2] = frgbvalue[2]; - return array; - } - - /** - * Returns a float array containing the color and alpha components of this - * color in the ColorSpace it was created with (the constructors which do - * not take a ColorSpace parameter use a default sRGB ColorSpace). If the - * array is null, a new one is created, otherwise it is recycled, and must - * have at least one more position than components used in the color space. - * - * @param array the array to put results into, or null - * @return the original color space components and alpha value - * @throws ArrayIndexOutOfBoundsException if array is too small - */ - public float[] getComponents(float[] array) - { - int numComponents = cs == null ? 3 : cs.getNumComponents(); - if (array == null) - array = new float[1 + numComponents]; - getColorComponents(array); - // Stupid serialization issues require this check. - array[numComponents] = (falpha == 0 && frgbvalue == null - ? ((getRGB() & ALPHA_MASK) >> 24) / 255f : falpha); - return array; - } - - /** - * Returns a float array containing the color components of this color in - * the ColorSpace it was created with (the constructors which do not take - * a ColorSpace parameter use a default sRGB ColorSpace). If the array is - * null, a new one is created, otherwise it is recycled, and must have at - * least as many positions as used in the color space. - * - * @param array the array to put results into, or null - * @return the original color space components - * @throws ArrayIndexOutOfBoundsException if array is too small - */ - public float[] getColorComponents(float[] array) - { - int numComponents = cs == null ? 3 : cs.getNumComponents(); - if (array == null) - array = new float[numComponents]; - if (fvalue == null) // If fvalue is null, cs should be null too. - fvalue = getRGBColorComponents(frgbvalue); - System.arraycopy(fvalue, 0, array, 0, numComponents); - return array; - } - - /** - * Returns a float array containing the color and alpha components of this - * color in the given ColorSpace. If the array is null, a new one is - * created, otherwise it is recycled, and must have at least one more - * position than components used in the color space. - * - * @param space the color space to translate to - * @param array the array to put results into, or null - * @return the color space components and alpha value - * @throws ArrayIndexOutOfBoundsException if array is too small - * @throws NullPointerException if space is null - */ - public float[] getComponents(ColorSpace space, float[] array) - { - int numComponents = space.getNumComponents(); - if (array == null) - array = new float[1 + numComponents]; - getColorComponents(space, array); - // Stupid serialization issues require this check. - array[numComponents] = (falpha == 0 && frgbvalue == null - ? ((getRGB() & ALPHA_MASK) >> 24) / 255f : falpha); - return array; - } - - /** - * Returns a float array containing the color components of this color in - * the given ColorSpace. If the array is null, a new one is created, - * otherwise it is recycled, and must have at least as many positions as - * used in the color space. - * - * @param space the color space to translate to - * @return the color space components - * @throws ArrayIndexOutOfBoundsException if array is too small - * @throws NullPointerException if space is null - */ - public float[] getColorComponents(ColorSpace space, float[] array) - { - float[] components = space.fromRGB(getRGBColorComponents(frgbvalue)); - if (array == null) - return components; - System.arraycopy(components, 0, array, 0, components.length); - return array; - } - - /** - * Returns the color space of this color. Except for the constructor which - * takes a ColorSpace argument, this will be an implementation of - * ColorSpace.CS_sRGB. - * - * @return the color space - */ - public ColorSpace getColorSpace() - { - return cs == null ? ColorSpace.getInstance(ColorSpace.CS_sRGB) : cs; - } - - /** - * Returns a paint context, used for filling areas of a raster scan with - * this color. Since the color is constant across the entire rectangle, and - * since it is always in sRGB space, this implementation returns the same - * object, regardless of the parameters. Subclasses, however, may have a - * mutable result. - * - * @param cm the requested color model - * @param deviceBounds the bounding box in device coordinates, ignored - * @param userBounds the bounding box in user coordinates, ignored - * @param xform the bounds transformation, ignored - * @param hints any rendering hints, ignored - * @return a context for painting this solid color - */ - public PaintContext createContext(ColorModel cm, Rectangle deviceBounds, - Rectangle2D userBounds, - AffineTransform xform, - RenderingHints hints) - { - if (context == null || !context.getColorModel().equals(cm)) - context = new ColorPaintContext(cm,value); - return context; - } - - /** - * Returns the transparency level of this color. - * - * @return one of {@link #OPAQUE}, {@link #BITMASK}, or {@link #TRANSLUCENT} - */ - public int getTransparency() - { - // Do not inline getRGB() to this.value, because of SystemColor. - int alpha = getRGB() & ALPHA_MASK; - return alpha == (255 << 24) ? OPAQUE : alpha == 0 ? BITMASK : TRANSLUCENT; - } - - /** - * Converts float values to integer value. - * - * @param red the red value - * @param green the green value - * @param blue the blue value - * @param alpha the alpha value - * @return the integer value made of 8-bit sections - * @throws IllegalArgumentException if parameters are out of range 0.0-1.0 - */ - private static int convert(float red, float green, float blue, float alpha) - { - if (red < 0 || red > 1 || green < 0 || green > 1 || blue < 0 || blue > 1 - || alpha < 0 || alpha > 1) - throw new IllegalArgumentException("Bad RGB values"); - int redval = Math.round(255 * red); - int greenval = Math.round(255 * green); - int blueval = Math.round(255 * blue); - int alphaval = Math.round(255 * alpha); - return (alphaval << 24) | (redval << 16) | (greenval << 8) | blueval; - } -} // class Color diff --git a/libjava/java/awt/ColorPaintContext.java b/libjava/java/awt/ColorPaintContext.java deleted file mode 100644 index 8396fcd6317..00000000000 --- a/libjava/java/awt/ColorPaintContext.java +++ /dev/null @@ -1,195 +0,0 @@ -/* ColorPaintContext.java -- context for painting solid colors - Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.awt.image.ColorModel; -import java.awt.image.Raster; - -/** - * This class provides a paint context which will fill a rectanglar region of - * a raster scan with the given color. However, it is not yet completely - * implemented. - * - * @author Eric Blake (ebb9@email.byu.edu) - */ -class ColorPaintContext implements PaintContext -{ - /** - * The color to fill any raster with. Package visible for use in - * SystemColor. - */ - final int color; - final ColorModel colorModel; - - private ColorRaster cachedRaster; - - - /** - * Create the context for a given color. - * - * @param c The solid color to use. - */ - ColorPaintContext(int colorRGB) - { - this(ColorModel.getRGBdefault(), colorRGB); - } - - /** - * Create the context for a given color. - * - * @param cm The color model of this context. - * @param c The solid color to use. - */ - ColorPaintContext(ColorModel cm,int colorRGB) - { - color = colorRGB; - colorModel = cm; - } - - /** - * Release the resources allocated for the paint. As the color is constant, - * there aren't any resources. - */ - public void dispose() - { - } - - /** - * Return the color model of this context. - * - * @return the context color model - */ - public ColorModel getColorModel() - { - return colorModel; - } - - /** - * Return a raster containing the colors for the graphics operation. - * - * @param x the x-coordinate, in device space - * @param y the y-coordinate, in device space - * @param w the width, in device space - * @param h the height, in device space - * @return a raster for the given area and color - */ - public Raster getRaster(int x, int y, int width, int height) - { - if( cachedRaster == null - || cachedRaster.getWidth() < width - || cachedRaster.getHeight() < height) - { - cachedRaster = new ColorRaster(colorModel, 0, 0, width, height, color); - } - return cachedRaster.createChild(0 ,0 ,width ,height ,x ,y , null); - } - - /** - * A ColorRaster is a raster that is completely filled with one color. The - * data layout is taken from the color model given to the constructor. - */ - private class ColorRaster extends Raster - { - - /** - * Create a raster that is compaltible with the given color model and - * filled with the given color. - * @param cm The color model for this raster. - * @param x The smallest horizontal corrdinate in the raster. - * @param y The smallest vertical coordinate in the raster. - * @param width The width of the raster. - * @param height The height of the raster. - * @param rgbPixel The RGB value of the color for this raster. - */ - ColorRaster(ColorModel cm,int x, int y, int width, int height, int rgbPixel) - { - super(cm.createCompatibleSampleModel(width,height),new Point(x,y)); - Object pixel = cm.getDataElements(rgbPixel,null); - getSampleModel().setDataElements(0, 0, - width, height, - multiplyData(pixel,null,width*height), - dataBuffer); - } - - - - private Object multiplyData(Object src, Object dest, int factor) - { - Object from; - int srcLength = 0; - if (src instanceof byte[]) - { - srcLength = ((byte[])src).length; - - if (dest == null) dest = new byte[factor * srcLength]; - } - else if (src instanceof short[]) - { - srcLength = ((short[])src).length; - if (dest == null) dest = new short[factor * srcLength]; - } - else if (src instanceof int[]) - { - srcLength = ((int[]) src).length; - if (dest == null) dest = new int[factor * srcLength]; - } - else - { - throw new ClassCastException("Unknown data buffer type"); - } - - System.arraycopy(src,0,dest,0,srcLength); - - int count = 1; - while(count*2 < factor) - { - System.arraycopy(dest, 0, dest, count * srcLength, count*srcLength); - count *= 2; - } - - if(factor > count) - System.arraycopy(dest,0, dest, count * srcLength, - (factor - count) * srcLength ); - - return dest; - } - - } - -} // class ColorPaintContext diff --git a/libjava/java/awt/Component.java b/libjava/java/awt/Component.java deleted file mode 100644 index 8b99321a64d..00000000000 --- a/libjava/java/awt/Component.java +++ /dev/null @@ -1,6005 +0,0 @@ -/* Component.java -- a graphics component - Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.awt.dnd.DropTarget; -import java.awt.event.ActionEvent; -import java.awt.event.ComponentEvent; -import java.awt.event.ComponentListener; -import java.awt.event.FocusEvent; -import java.awt.event.FocusListener; -import java.awt.event.HierarchyBoundsListener; -import java.awt.event.HierarchyEvent; -import java.awt.event.HierarchyListener; -import java.awt.event.InputEvent; -import java.awt.event.InputMethodEvent; -import java.awt.event.InputMethodListener; -import java.awt.event.KeyEvent; -import java.awt.event.KeyListener; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; -import java.awt.event.MouseMotionListener; -import java.awt.event.MouseWheelEvent; -import java.awt.event.MouseWheelListener; -import java.awt.event.PaintEvent; -import java.awt.event.WindowEvent; -import java.awt.im.InputContext; -import java.awt.im.InputMethodRequests; -import java.awt.image.BufferStrategy; -import java.awt.image.ColorModel; -import java.awt.image.ImageObserver; -import java.awt.image.ImageProducer; -import java.awt.image.VolatileImage; -import java.awt.peer.ComponentPeer; -import java.awt.peer.LightweightPeer; -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.PrintStream; -import java.io.PrintWriter; -import java.io.Serializable; -import java.lang.reflect.Array; -import java.util.Collections; -import java.util.EventListener; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Locale; -import java.util.Set; -import java.util.Vector; - -import javax.accessibility.Accessible; -import javax.accessibility.AccessibleComponent; -import javax.accessibility.AccessibleContext; -import javax.accessibility.AccessibleRole; -import javax.accessibility.AccessibleState; -import javax.accessibility.AccessibleStateSet; - -/** - * The root of all evil. All graphical representations are subclasses of this - * giant class, which is designed for screen display and user interaction. - * This class can be extended directly to build a lightweight component (one - * not associated with a native window); lightweight components must reside - * inside a heavyweight window. - * - * <p>This class is Serializable, which has some big implications. A user can - * save the state of all graphical components in one VM, and reload them in - * another. Note that this class will only save Serializable listeners, and - * ignore the rest, without causing any serialization exceptions. However, by - * making a listener serializable, and adding it to another element, you link - * in that entire element to the state of this component. To get around this, - * use the idiom shown in the example below - make listeners non-serializable - * in inner classes, rather than using this object itself as the listener, if - * external objects do not need to save the state of this object. - * - * <pre> - * import java.awt.*; - * import java.awt.event.*; - * import java.io.Serializable; - * class MyApp implements Serializable - * { - * BigObjectThatShouldNotBeSerializedWithAButton bigOne; - * // Serializing aButton will not suck in an instance of MyApp, with its - * // accompanying field bigOne. - * Button aButton = new Button(); - * class MyActionListener implements ActionListener - * { - * public void actionPerformed(ActionEvent e) - * { - * System.out.println("Hello There"); - * } - * } - * MyApp() - * { - * aButton.addActionListener(new MyActionListener()); - * } - * } - * </pre> - * - * <p>Status: Incomplete. The event dispatch mechanism is implemented. All - * other methods defined in the J2SE 1.3 API javadoc exist, but are mostly - * incomplete or only stubs; except for methods relating to the Drag and - * Drop, Input Method, and Accessibility frameworks: These methods are - * present but commented out. - * - * @author original author unknown - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.0 - * @status still missing 1.4 support - */ -public abstract class Component - implements ImageObserver, MenuContainer, Serializable -{ - // Word to the wise - this file is huge. Search for '\f' (^L) for logical - // sectioning by fields, public API, private API, and nested classes. - - - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = -7644114512714619750L; - - /** - * Constant returned by the <code>getAlignmentY</code> method to indicate - * that the component wishes to be aligned to the top relative to - * other components. - * - * @see #getAlignmentY() - */ - public static final float TOP_ALIGNMENT = 0; - - /** - * Constant returned by the <code>getAlignmentY</code> and - * <code>getAlignmentX</code> methods to indicate - * that the component wishes to be aligned to the center relative to - * other components. - * - * @see #getAlignmentX() - * @see #getAlignmentY() - */ - public static final float CENTER_ALIGNMENT = 0.5f; - - /** - * Constant returned by the <code>getAlignmentY</code> method to indicate - * that the component wishes to be aligned to the bottom relative to - * other components. - * - * @see #getAlignmentY() - */ - public static final float BOTTOM_ALIGNMENT = 1; - - /** - * Constant returned by the <code>getAlignmentX</code> method to indicate - * that the component wishes to be aligned to the right relative to - * other components. - * - * @see #getAlignmentX() - */ - public static final float RIGHT_ALIGNMENT = 1; - - /** - * Constant returned by the <code>getAlignmentX</code> method to indicate - * that the component wishes to be aligned to the left relative to - * other components. - * - * @see #getAlignmentX() - */ - public static final float LEFT_ALIGNMENT = 0; - - /** - * Make the treelock a String so that it can easily be identified - * in debug dumps. We clone the String in order to avoid a conflict in - * the unlikely event that some other package uses exactly the same string - * as a lock object. - */ - static final Object treeLock = new String("AWT_TREE_LOCK"); - - // Serialized fields from the serialization spec. - - /** - * The x position of the component in the parent's coordinate system. - * - * @see #getLocation() - * @serial the x position - */ - int x; - - /** - * The y position of the component in the parent's coordinate system. - * - * @see #getLocation() - * @serial the y position - */ - int y; - - /** - * The component width. - * - * @see #getSize() - * @serial the width - */ - int width; - - /** - * The component height. - * - * @see #getSize() - * @serial the height - */ - int height; - - /** - * The foreground color for the component. This may be null. - * - * @see #getForeground() - * @see #setForeground(Color) - * @serial the foreground color - */ - Color foreground; - - /** - * The background color for the component. This may be null. - * - * @see #getBackground() - * @see #setBackground(Color) - * @serial the background color - */ - Color background; - - /** - * The default font used in the component. This may be null. - * - * @see #getFont() - * @see #setFont(Font) - * @serial the font - */ - Font font; - - /** - * The font in use by the peer, or null if there is no peer. - * - * @serial the peer's font - */ - Font peerFont; - - /** - * The cursor displayed when the pointer is over this component. This may - * be null. - * - * @see #getCursor() - * @see #setCursor(Cursor) - */ - Cursor cursor; - - /** - * The locale for the component. - * - * @see #getLocale() - * @see #setLocale(Locale) - */ - Locale locale = Locale.getDefault (); - - /** - * True if the object should ignore repaint events (usually because it is - * not showing). - * - * @see #getIgnoreRepaint() - * @see #setIgnoreRepaint(boolean) - * @serial true to ignore repaints - * @since 1.4 - */ - boolean ignoreRepaint; - - /** - * True when the object is visible (although it is only showing if all - * ancestors are likewise visible). For component, this defaults to true. - * - * @see #isVisible() - * @see #setVisible(boolean) - * @serial true if visible - */ - boolean visible = true; - - /** - * True if the object is enabled, meaning it can interact with the user. - * For component, this defaults to true. - * - * @see #isEnabled() - * @see #setEnabled(boolean) - * @serial true if enabled - */ - boolean enabled = true; - - /** - * True if the object is valid. This is set to false any time a size - * adjustment means the component need to be layed out again. - * - * @see #isValid() - * @see #validate() - * @see #invalidate() - * @serial true if layout is valid - */ - boolean valid; - - /** - * The DropTarget for drag-and-drop operations. - * - * @see #getDropTarget() - * @see #setDropTarget(DropTarget) - * @serial the drop target, or null - * @since 1.2 - */ - DropTarget dropTarget; - - /** - * The list of popup menus for this component. - * - * @see #add(PopupMenu) - * @serial the list of popups - */ - Vector popups; - - /** - * The component's name. May be null, in which case a default name is - * generated on the first use. - * - * @see #getName() - * @see #setName(String) - * @serial the name - */ - String name; - - /** - * True once the user has set the name. Note that the user may set the name - * to null. - * - * @see #name - * @see #getName() - * @see #setName(String) - * @serial true if the name has been explicitly set - */ - boolean nameExplicitlySet; - - /** - * Indicates if the object can be focused. Defaults to true for components. - * - * @see #isFocusable() - * @see #setFocusable(boolean) - * @since 1.4 - */ - boolean focusable = true; - - /** - * Tracks whether this component's {@link #isFocusTraversable} - * method has been overridden. - * - * @since 1.4 - */ - int isFocusTraversableOverridden; - - /** - * The focus traversal keys, if not inherited from the parent or - * default keyboard focus manager. These sets will contain only - * AWTKeyStrokes that represent press and release events to use as - * focus control. - * - * @see #getFocusTraversalKeys(int) - * @see #setFocusTraversalKeys(int, Set) - * @since 1.4 - */ - Set[] focusTraversalKeys; - - /** - * True if focus traversal keys are enabled. This defaults to true for - * Component. If this is true, keystrokes in focusTraversalKeys are trapped - * and processed automatically rather than being passed on to the component. - * - * @see #getFocusTraversalKeysEnabled() - * @see #setFocusTraversalKeysEnabled(boolean) - * @since 1.4 - */ - boolean focusTraversalKeysEnabled = true; - - /** - * Cached information on the minimum size. Should have been transient. - * - * @serial ignore - */ - Dimension minSize; - - /** - * Cached information on the preferred size. Should have been transient. - * - * @serial ignore - */ - Dimension prefSize; - - /** - * Set to true if an event is to be handled by this component, false if - * it is to be passed up the hierarcy. - * - * @see #dispatchEvent(AWTEvent) - * @serial true to process event locally - */ - boolean newEventsOnly; - - /** - * Set by subclasses to enable event handling of particular events, and - * left alone when modifying listeners. For component, this defaults to - * enabling only input methods. - * - * @see #enableInputMethods(boolean) - * @see AWTEvent - * @serial the mask of events to process - */ - long eventMask = AWTEvent.INPUT_ENABLED_EVENT_MASK; - - /** - * Describes all registered PropertyChangeListeners. - * - * @see #addPropertyChangeListener(PropertyChangeListener) - * @see #removePropertyChangeListener(PropertyChangeListener) - * @see #firePropertyChange(String, Object, Object) - * @serial the property change listeners - * @since 1.2 - */ - PropertyChangeSupport changeSupport; - - /** - * True if the component has been packed (layed out). - * - * @serial true if this is packed - */ - boolean isPacked; - - /** - * The serialization version for this class. Currently at version 4. - * - * XXX How do we handle prior versions? - * - * @serial the serialization version - */ - int componentSerializedDataVersion = 4; - - /** - * The accessible context associated with this component. This is only set - * by subclasses. - * - * @see #getAccessibleContext() - * @serial the accessibility context - * @since 1.2 - */ - AccessibleContext accessibleContext; - - - // Guess what - listeners are special cased in serialization. See - // readObject and writeObject. - - /** Component listener chain. */ - transient ComponentListener componentListener; - - /** Focus listener chain. */ - transient FocusListener focusListener; - - /** Key listener chain. */ - transient KeyListener keyListener; - - /** Mouse listener chain. */ - transient MouseListener mouseListener; - - /** Mouse motion listener chain. */ - transient MouseMotionListener mouseMotionListener; - - /** - * Mouse wheel listener chain. - * - * @since 1.4 - */ - transient MouseWheelListener mouseWheelListener; - - /** - * Input method listener chain. - * - * @since 1.2 - */ - transient InputMethodListener inputMethodListener; - - /** - * Hierarcy listener chain. - * - * @since 1.3 - */ - transient HierarchyListener hierarchyListener; - - /** - * Hierarcy bounds listener chain. - * - * @since 1.3 - */ - transient HierarchyBoundsListener hierarchyBoundsListener; - - // Anything else is non-serializable, and should be declared "transient". - - /** The parent. */ - transient Container parent; - - /** The associated native peer. */ - transient ComponentPeer peer; - - /** The preferred component orientation. */ - transient ComponentOrientation orientation = ComponentOrientation.UNKNOWN; - - /** - * The associated graphics configuration. - * - * @since 1.4 - */ - transient GraphicsConfiguration graphicsConfig; - - /** - * The buffer strategy for repainting. - * - * @since 1.4 - */ - transient BufferStrategy bufferStrategy; - - /** - * true if requestFocus was called on this component when its - * top-level ancestor was not focusable. - */ - private transient FocusEvent pendingFocusRequest = null; - - /** - * The system properties that affect image updating. - */ - private static transient boolean incrementalDraw; - private static transient Long redrawRate; - - static - { - incrementalDraw = Boolean.getBoolean ("awt.image.incrementalDraw"); - redrawRate = Long.getLong ("awt.image.redrawrate"); - } - - // Public and protected API. - - /** - * Default constructor for subclasses. When Component is extended directly, - * it forms a lightweight component that must be hosted in an opaque native - * container higher in the tree. - */ - protected Component() - { - } - - /** - * Returns the name of this component. - * - * @return the name of this component - * @see #setName(String) - * @since 1.1 - */ - public String getName() - { - if (name == null && ! nameExplicitlySet) - name = generateName(); - return name; - } - - /** - * Sets the name of this component to the specified name. - * - * @param name the new name of this component - * @see #getName() - * @since 1.1 - */ - public void setName(String name) - { - nameExplicitlySet = true; - this.name = name; - } - - /** - * Returns the parent of this component. - * - * @return the parent of this component - */ - public Container getParent() - { - return parent; - } - - /** - * Returns the native windowing system peer for this component. Only the - * platform specific implementation code should call this method. - * - * @return the peer for this component - * @deprecated user programs should not directly manipulate peers; use - * {@link #isDisplayable()} instead - */ - // Classpath's Gtk peers rely on this. - public ComponentPeer getPeer() - { - return peer; - } - - /** - * Set the associated drag-and-drop target, which receives events when this - * is enabled. - * - * @param dt the new drop target - * @see #isEnabled() - */ - public void setDropTarget(DropTarget dt) - { - this.dropTarget = dt; - } - - /** - * Gets the associated drag-and-drop target, if there is one. - * - * @return the drop target - */ - public DropTarget getDropTarget() - { - return dropTarget; - } - - /** - * Returns the graphics configuration of this component, if there is one. - * If it has not been set, it is inherited from the parent. - * - * @return the graphics configuration, or null - * @since 1.3 - */ - public GraphicsConfiguration getGraphicsConfiguration() - { - return getGraphicsConfigurationImpl(); - } - - /** - * Returns the object used for synchronization locks on this component - * when performing tree and layout functions. - * - * @return the synchronization lock for this component - */ - public final Object getTreeLock() - { - return treeLock; - } - - /** - * Returns the toolkit in use for this component. The toolkit is associated - * with the frame this component belongs to. - * - * @return the toolkit for this component - */ - public Toolkit getToolkit() - { - if (peer != null) - { - Toolkit tk = peer.getToolkit(); - if (tk != null) - return tk; - } - // Get toolkit for lightweight component. - if (parent != null) - return parent.getToolkit(); - return Toolkit.getDefaultToolkit(); - } - - /** - * Tests whether or not this component is valid. A invalid component needs - * to have its layout redone. - * - * @return true if this component is valid - * @see #validate() - * @see #invalidate() - */ - public boolean isValid() - { - return valid; - } - - /** - * Tests if the component is displayable. It must be connected to a native - * screen resource, and all its ancestors must be displayable. A containment - * hierarchy is made displayable when a window is packed or made visible. - * - * @return true if the component is displayable - * @see Container#add(Component) - * @see Container#remove(Component) - * @see Window#pack() - * @see Window#show() - * @see Window#dispose() - * @since 1.2 - */ - public boolean isDisplayable() - { - if (parent != null) - return parent.isDisplayable(); - return false; - } - - /** - * Tests whether or not this component is visible. Except for top-level - * frames, components are initially visible. - * - * @return true if the component is visible - * @see #setVisible(boolean) - */ - public boolean isVisible() - { - return visible; - } - - /** - * Tests whether or not this component is actually being shown on - * the screen. This will be true if and only if it this component is - * visible and its parent components are all visible. - * - * @return true if the component is showing on the screen - * @see #setVisible(boolean) - */ - public boolean isShowing() - { - if (! visible || peer == null) - return false; - - return parent == null ? true : parent.isShowing(); - } - - /** - * Tests whether or not this component is enabled. Components are enabled - * by default, and must be enabled to receive user input or generate events. - * - * @return true if the component is enabled - * @see #setEnabled(boolean) - */ - public boolean isEnabled() - { - return enabled; - } - - /** - * Enables or disables this component. The component must be enabled to - * receive events (except that lightweight components always receive mouse - * events). - * - * @param enabled true to enable this component - * - * @see #isEnabled() - * @see #isLightweight() - * - * @since 1.1 - */ - public void setEnabled(boolean enabled) - { - enable(enabled); - } - - /** - * Enables this component. - * - * @deprecated use {@link #setEnabled(boolean)} instead - */ - public void enable() - { - this.enabled = true; - if (peer != null) - peer.setEnabled (true); - } - - /** - * Enables or disables this component. - * - * @param enabled true to enable this component - * - * @deprecated use {@link #setEnabled(boolean)} instead - */ - public void enable(boolean enabled) - { - if (enabled) - enable(); - else - disable(); - } - - /** - * Disables this component. - * - * @deprecated use {@link #setEnabled(boolean)} instead - */ - public void disable() - { - this.enabled = false; - if (peer != null) - peer.setEnabled (false); - } - - /** - * Checks if this image is painted to an offscreen image buffer that is - * later copied to screen (double buffering reduces flicker). This version - * returns false, so subclasses must override it if they provide double - * buffering. - * - * @return true if this is double buffered; defaults to false - */ - public boolean isDoubleBuffered() - { - return false; - } - - /** - * Enables or disables input method support for this component. By default, - * components have this enabled. Input methods are given the opportunity - * to process key events before this component and its listeners. - * - * @param enable true to enable input method processing - * @see #processKeyEvent(KeyEvent) - * @since 1.2 - */ - public void enableInputMethods(boolean enable) - { - // XXX Implement. - throw new Error("not implemented"); - } - - /** - * Makes this component visible or invisible. Note that it wtill might - * not show the component, if a parent is invisible. - * - * @param visible true to make this component visible - * - * @see #isVisible() - * - * @since 1.1 - */ - public void setVisible(boolean visible) - { - // Inspection by subclassing shows that Sun's implementation calls - // show(boolean) which then calls show() or hide(). It is the show() - // method that is overriden in subclasses like Window. - show(visible); - } - - /** - * Makes this component visible on the screen. - * - * @deprecated use {@link #setVisible(boolean)} instead - */ - public void show() - { - // We must set visible before showing the peer. Otherwise the - // peer could post paint events before visible is true, in which - // case lightweight components are not initially painted -- - // Container.paint first calls isShowing () before painting itself - // and its children. - if(!isVisible()) - { - this.visible = true; - if (peer != null) - peer.setVisible(true); - invalidate(); - ComponentEvent ce = - new ComponentEvent(this,ComponentEvent.COMPONENT_SHOWN); - getToolkit().getSystemEventQueue().postEvent(ce); - } - } - - /** - * Makes this component visible or invisible. - * - * @param visible true to make this component visible - * - * @deprecated use {@link #setVisible(boolean)} instead - */ - public void show(boolean visible) - { - if (visible) - show(); - else - hide(); - } - - /** - * Hides this component so that it is no longer shown on the screen. - * - * @deprecated use {@link #setVisible(boolean)} instead - */ - public void hide() - { - if (isVisible()) - { - if (peer != null) - peer.setVisible(false); - this.visible = false; - invalidate(); - ComponentEvent ce = - new ComponentEvent(this,ComponentEvent.COMPONENT_HIDDEN); - getToolkit().getSystemEventQueue().postEvent(ce); - } - } - - /** - * Returns this component's foreground color. If not set, this is inherited - * from the parent. - * - * @return this component's foreground color, or null - * @see #setForeground(Color) - */ - public Color getForeground() - { - if (foreground != null) - return foreground; - return parent == null ? SystemColor.windowText : parent.getForeground(); - } - - /** - * Sets this component's foreground color to the specified color. This is a - * bound property. - * - * @param c the new foreground color - * @see #getForeground() - */ - public void setForeground(Color c) - { - firePropertyChange("foreground", foreground, c); - if (peer != null) - peer.setForeground(c); - foreground = c; - } - - /** - * Tests if the foreground was explicitly set, or just inherited from the - * parent. - * - * @return true if the foreground has been set - * @since 1.4 - */ - public boolean isForegroundSet() - { - return foreground != null; - } - - /** - * Returns this component's background color. If not set, this is inherited - * from the parent. - * - * @return the background color of the component, or null - * @see #setBackground(Color) - */ - public Color getBackground() - { - if (background != null) - return background; - return parent == null ? SystemColor.window : parent.getBackground(); - } - - /** - * Sets this component's background color to the specified color. The parts - * of the component affected by the background color may by system dependent. - * This is a bound property. - * - * @param c the new background color - * @see #getBackground() - */ - public void setBackground(Color c) - { - // If c is null, inherit from closest ancestor whose bg is set. - if (c == null && parent != null) - c = parent.getBackground(); - firePropertyChange("background", background, c); - if (peer != null && c != null) - peer.setBackground(c); - background = c; - } - - /** - * Tests if the background was explicitly set, or just inherited from the - * parent. - * - * @return true if the background has been set - * @since 1.4 - */ - public boolean isBackgroundSet() - { - return background != null; - } - - /** - * Returns the font in use for this component. If not set, this is inherited - * from the parent. - * - * @return the font for this component - * @see #setFont(Font) - */ - public Font getFont() - { - if (font != null) - return font; - - if (parent != null) - return parent.getFont (); - else - return new Font ("Dialog", Font.PLAIN, 12); - } - - /** - * Sets the font for this component to the specified font. This is a bound - * property. - * - * @param newFont the new font for this component - * - * @see #getFont() - */ - public void setFont(Font newFont) - { - if (font == newFont) - return; - - Font oldFont = font; - font = newFont; - if (peer != null) - peer.setFont(font); - firePropertyChange("font", oldFont, newFont); - invalidate(); - } - - /** - * Tests if the font was explicitly set, or just inherited from the parent. - * - * @return true if the font has been set - * @since 1.4 - */ - public boolean isFontSet() - { - return font != null; - } - - /** - * Returns the locale for this component. If this component does not - * have a locale, the locale of the parent component is returned. - * - * @return the locale for this component - * @throws IllegalComponentStateException if it has no locale or parent - * @see #setLocale(Locale) - * @since 1.1 - */ - public Locale getLocale() - { - if (locale != null) - return locale; - if (parent == null) - throw new IllegalComponentStateException - ("Component has no parent: can't determine Locale"); - return parent.getLocale(); - } - - /** - * Sets the locale for this component to the specified locale. This is a - * bound property. - * - * @param newLocale the new locale for this component - */ - public void setLocale(Locale newLocale) - { - if (locale == newLocale) - return; - - Locale oldLocale = locale; - locale = newLocale; - firePropertyChange("locale", oldLocale, newLocale); - // New writing/layout direction or more/less room for localized labels. - invalidate(); - } - - /** - * Returns the color model of the device this componet is displayed on. - * - * @return this object's color model - * @see Toolkit#getColorModel() - */ - public ColorModel getColorModel() - { - GraphicsConfiguration config = getGraphicsConfiguration(); - return config != null ? config.getColorModel() - : getToolkit().getColorModel(); - } - - /** - * Returns the location of this component's top left corner relative to - * its parent component. This may be outdated, so for synchronous behavior, - * you should use a component listner. - * - * @return the location of this component - * @see #setLocation(int, int) - * @see #getLocationOnScreen() - * @since 1.1 - */ - public Point getLocation() - { - return location (); - } - - /** - * Returns the location of this component's top left corner in screen - * coordinates. - * - * @return the location of this component in screen coordinates - * @throws IllegalComponentStateException if the component is not showing - */ - public Point getLocationOnScreen() - { - if (! isShowing()) - throw new IllegalComponentStateException("component not showing"); - // We know peer != null here. - return peer.getLocationOnScreen(); - } - - /** - * Returns the location of this component's top left corner relative to - * its parent component. - * - * @return the location of this component - * @deprecated use {@link #getLocation()} instead - */ - public Point location() - { - return new Point (x, y); - } - - /** - * Moves this component to the specified location, relative to the parent's - * coordinates. The coordinates are the new upper left corner of this - * component. - * - * @param x the new X coordinate of this component - * @param y the new Y coordinate of this component - * @see #getLocation() - * @see #setBounds(int, int, int, int) - */ - public void setLocation(int x, int y) - { - move (x, y); - } - - /** - * Moves this component to the specified location, relative to the parent's - * coordinates. The coordinates are the new upper left corner of this - * component. - * - * @param x the new X coordinate of this component - * @param y the new Y coordinate of this component - * @deprecated use {@link #setLocation(int, int)} instead - */ - public void move(int x, int y) - { - setBounds(x, y, this.width, this.height); - } - - /** - * Moves this component to the specified location, relative to the parent's - * coordinates. The coordinates are the new upper left corner of this - * component. - * - * @param p new coordinates for this component - * @throws NullPointerException if p is null - * @see #getLocation() - * @see #setBounds(int, int, int, int) - * @since 1.1 - */ - public void setLocation(Point p) - { - setLocation(p.x, p.y); - } - - /** - * Returns the size of this object. - * - * @return the size of this object - * @see #setSize(int, int) - * @since 1.1 - */ - public Dimension getSize() - { - return size (); - } - - /** - * Returns the size of this object. - * - * @return the size of this object - * @deprecated use {@link #getSize()} instead - */ - public Dimension size() - { - return new Dimension (width, height); - } - - /** - * Sets the size of this component to the specified width and height. - * - * @param width the new width of this component - * @param height the new height of this component - * @see #getSize() - * @see #setBounds(int, int, int, int) - */ - public void setSize(int width, int height) - { - resize (width, height); - } - - /** - * Sets the size of this component to the specified value. - * - * @param width the new width of the component - * @param height the new height of the component - * @deprecated use {@link #setSize(int, int)} instead - */ - public void resize(int width, int height) - { - setBounds(this.x, this.y, width, height); - } - - /** - * Sets the size of this component to the specified value. - * - * @param d the new size of this component - * @throws NullPointerException if d is null - * @see #setSize(int, int) - * @see #setBounds(int, int, int, int) - * @since 1.1 - */ - public void setSize(Dimension d) - { - resize (d); - } - - /** - * Sets the size of this component to the specified value. - * - * @param d the new size of this component - * @throws NullPointerException if d is null - * @deprecated use {@link #setSize(Dimension)} instead - */ - public void resize(Dimension d) - { - resize (d.width, d.height); - } - - /** - * Returns a bounding rectangle for this component. Note that the - * returned rectange is relative to this component's parent, not to - * the screen. - * - * @return the bounding rectangle for this component - * @see #setBounds(int, int, int, int) - * @see #getLocation() - * @see #getSize() - */ - public Rectangle getBounds() - { - return bounds (); - } - - /** - * Returns a bounding rectangle for this component. Note that the - * returned rectange is relative to this component's parent, not to - * the screen. - * - * @return the bounding rectangle for this component - * @deprecated use {@link #getBounds()} instead - */ - public Rectangle bounds() - { - return new Rectangle (x, y, width, height); - } - - /** - * Sets the bounding rectangle for this component to the specified values. - * Note that these coordinates are relative to the parent, not to the screen. - * - * @param x the X coordinate of the upper left corner of the rectangle - * @param y the Y coordinate of the upper left corner of the rectangle - * @param w the width of the rectangle - * @param h the height of the rectangle - * @see #getBounds() - * @see #setLocation(int, int) - * @see #setLocation(Point) - * @see #setSize(int, int) - * @see #setSize(Dimension) - * @since 1.1 - */ - public void setBounds(int x, int y, int w, int h) - { - reshape (x, y, w, h); - } - - /** - * Sets the bounding rectangle for this component to the specified values. - * Note that these coordinates are relative to the parent, not to the screen. - * - * @param x the X coordinate of the upper left corner of the rectangle - * @param y the Y coordinate of the upper left corner of the rectangle - * @param width the width of the rectangle - * @param height the height of the rectangle - * @deprecated use {@link #setBounds(int, int, int, int)} instead - */ - public void reshape(int x, int y, int width, int height) - { - int oldx = this.x; - int oldy = this.y; - int oldwidth = this.width; - int oldheight = this.height; - - if (this.x == x && this.y == y - && this.width == width && this.height == height) - return; - invalidate (); - this.x = x; - this.y = y; - this.width = width; - this.height = height; - if (peer != null) - peer.setBounds (x, y, width, height); - - // Erase old bounds and repaint new bounds for lightweights. - if (isLightweight() && isShowing ()) - { - boolean shouldRepaintParent = false; - boolean shouldRepaintSelf = false; - - if (parent != null) - { - Rectangle parentBounds = parent.getBounds(); - Rectangle oldBounds = new Rectangle(parent.getX() + oldx, - parent.getY() + oldy, - oldwidth, oldheight); - Rectangle newBounds = new Rectangle(parent.getX() + x, - parent.getY() + y, - width, height); - shouldRepaintParent = parentBounds.intersects(oldBounds); - shouldRepaintSelf = parentBounds.intersects(newBounds); - } - - if (shouldRepaintParent && parent != null) - parent.repaint(oldx, oldy, oldwidth, oldheight); - if (shouldRepaintSelf) - repaint(); - } - - // Only post event if this component is visible and has changed size. - if (isShowing () - && (oldx != x || oldy != y)) - { - ComponentEvent ce = new ComponentEvent(this, - ComponentEvent.COMPONENT_MOVED); - getToolkit().getSystemEventQueue().postEvent(ce); - } - if (isShowing () - && (oldwidth != width || oldheight != height)) - { - ComponentEvent ce = new ComponentEvent(this, - ComponentEvent.COMPONENT_RESIZED); - getToolkit().getSystemEventQueue().postEvent(ce); - } - } - - /** - * Sets the bounding rectangle for this component to the specified - * rectangle. Note that these coordinates are relative to the parent, not - * to the screen. - * - * @param r the new bounding rectangle - * @throws NullPointerException if r is null - * @see #getBounds() - * @see #setLocation(Point) - * @see #setSize(Dimension) - * @since 1.1 - */ - public void setBounds(Rectangle r) - { - setBounds (r.x, r.y, r.width, r.height); - } - - /** - * Gets the x coordinate of the upper left corner. This is more efficient - * than getBounds().x or getLocation().x. - * - * @return the current x coordinate - * @since 1.2 - */ - public int getX() - { - return x; - } - - /** - * Gets the y coordinate of the upper left corner. This is more efficient - * than getBounds().y or getLocation().y. - * - * @return the current y coordinate - * @since 1.2 - */ - public int getY() - { - return y; - } - - /** - * Gets the width of the component. This is more efficient than - * getBounds().width or getSize().width. - * - * @return the current width - * @since 1.2 - */ - public int getWidth() - { - return width; - } - - /** - * Gets the height of the component. This is more efficient than - * getBounds().height or getSize().height. - * - * @return the current width - * @since 1.2 - */ - public int getHeight() - { - return height; - } - - /** - * Returns the bounds of this component. This allows reuse of an existing - * rectangle, if r is non-null. - * - * @param r the rectangle to use, or null - * @return the bounds - */ - public Rectangle getBounds(Rectangle r) - { - if (r == null) - r = new Rectangle(); - r.x = x; - r.y = y; - r.width = width; - r.height = height; - return r; - } - - /** - * Returns the size of this component. This allows reuse of an existing - * dimension, if d is non-null. - * - * @param d the dimension to use, or null - * @return the size - */ - public Dimension getSize(Dimension d) - { - if (d == null) - d = new Dimension(); - d.width = width; - d.height = height; - return d; - } - - /** - * Returns the location of this component. This allows reuse of an existing - * point, if p is non-null. - * - * @param p the point to use, or null - * @return the location - */ - public Point getLocation(Point p) - { - if (p == null) - p = new Point(); - p.x = x; - p.y = y; - return p; - } - - /** - * Tests if this component is opaque. All "heavyweight" (natively-drawn) - * components are opaque. A component is opaque if it draws all pixels in - * the bounds; a lightweight component is partially transparent if it lets - * pixels underneath show through. Subclasses that guarantee that all pixels - * will be drawn should override this. - * - * @return true if this is opaque - * @see #isLightweight() - * @since 1.2 - */ - public boolean isOpaque() - { - return ! isLightweight(); - } - - /** - * Return whether the component is lightweight. That means the component has - * no native peer, but is displayable. This applies to subclasses of - * Component not in this package, such as javax.swing. - * - * @return true if the component has a lightweight peer - * @see #isDisplayable() - * @since 1.2 - */ - public boolean isLightweight() - { - return peer instanceof LightweightPeer; - } - - /** - * Returns the component's preferred size. - * - * @return the component's preferred size - * @see #getMinimumSize() - * @see LayoutManager - */ - public Dimension getPreferredSize() - { - return preferredSize(); - } - - /** - * Returns the component's preferred size. - * - * @return the component's preferred size - * @deprecated use {@link #getPreferredSize()} instead - */ - public Dimension preferredSize() - { - if (prefSize == null) - if (peer == null) - return new Dimension(width, height); - else - prefSize = peer.getPreferredSize(); - return prefSize; - } - - /** - * Returns the component's minimum size. - * - * @return the component's minimum size - * @see #getPreferredSize() - * @see LayoutManager - */ - public Dimension getMinimumSize() - { - return minimumSize(); - } - - /** - * Returns the component's minimum size. - * - * @return the component's minimum size - * @deprecated use {@link #getMinimumSize()} instead - */ - public Dimension minimumSize() - { - if (minSize == null) - minSize = (peer != null ? peer.getMinimumSize() - : new Dimension(width, height)); - return minSize; - } - - /** - * Returns the component's maximum size. - * - * @return the component's maximum size - * @see #getMinimumSize() - * @see #getPreferredSize() - * @see LayoutManager - */ - public Dimension getMaximumSize() - { - return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE); - } - - /** - * Returns the preferred horizontal alignment of this component. The value - * returned will be between {@link #LEFT_ALIGNMENT} and - * {@link #RIGHT_ALIGNMENT}, inclusive. - * - * @return the preferred horizontal alignment of this component - */ - public float getAlignmentX() - { - return CENTER_ALIGNMENT; - } - - /** - * Returns the preferred vertical alignment of this component. The value - * returned will be between {@link #TOP_ALIGNMENT} and - * {@link #BOTTOM_ALIGNMENT}, inclusive. - * - * @return the preferred vertical alignment of this component - */ - public float getAlignmentY() - { - return CENTER_ALIGNMENT; - } - - /** - * Calls the layout manager to re-layout the component. This is called - * during validation of a container in most cases. - * - * @see #validate() - * @see LayoutManager - */ - public void doLayout() - { - layout (); - } - - /** - * Calls the layout manager to re-layout the component. This is called - * during validation of a container in most cases. - * - * @deprecated use {@link #doLayout()} instead - */ - public void layout() - { - // Nothing to do unless we're a container. - } - - /** - * Called to ensure that the layout for this component is valid. This is - * usually called on containers. - * - * @see #invalidate() - * @see #doLayout() - * @see LayoutManager - * @see Container#validate() - */ - public void validate() - { - valid = true; - } - - /** - * Invalidates this component and all of its parent components. This will - * cause them to have their layout redone. This is called frequently, so - * make it fast. - */ - public void invalidate() - { - valid = false; - prefSize = null; - minSize = null; - if (parent != null && parent.valid) - parent.invalidate(); - } - - /** - * Returns a graphics object for this component. Returns <code>null</code> - * if this component is not currently displayed on the screen. - * - * @return a graphics object for this component - * @see #paint(Graphics) - */ - public Graphics getGraphics() - { - if (peer != null) - { - Graphics gfx = peer.getGraphics(); - if (gfx != null) - return gfx; - // create graphics for lightweight: - Container parent = getParent(); - if (parent != null) - { - gfx = parent.getGraphics(); - Rectangle bounds = getBounds(); - gfx.setClip(bounds); - gfx.translate(bounds.x, bounds.y); - return gfx; - } - } - return null; - } - - /** - * Returns the font metrics for the specified font in this component. - * - * @param font the font to retrieve metrics for - * @return the font metrics for the specified font - * @throws NullPointerException if font is null - * @see #getFont() - * @see Toolkit#getFontMetrics(Font) - */ - public FontMetrics getFontMetrics(Font font) - { - return peer == null ? getToolkit().getFontMetrics(font) - : peer.getFontMetrics(font); - } - - /** - * Sets the cursor for this component to the specified cursor. The cursor - * is displayed when the point is contained by the component, and the - * component is visible, displayable, and enabled. This is inherited by - * subcomponents unless they set their own cursor. - * - * @param cursor the new cursor for this component - * @see #isEnabled() - * @see #isShowing() - * @see #getCursor() - * @see #contains(int, int) - * @see Toolkit#createCustomCursor(Image, Point, String) - */ - public void setCursor(Cursor cursor) - { - this.cursor = cursor; - if (peer != null) - peer.setCursor(cursor); - } - - /** - * Returns the cursor for this component. If not set, this is inherited - * from the parent, or from Cursor.getDefaultCursor(). - * - * @return the cursor for this component - */ - public Cursor getCursor() - { - if (cursor != null) - return cursor; - return parent != null ? parent.getCursor() : Cursor.getDefaultCursor(); - } - - /** - * Tests if the cursor was explicitly set, or just inherited from the parent. - * - * @return true if the cursor has been set - * @since 1.4 - */ - public boolean isCursorSet() - { - return cursor != null; - } - - /** - * Paints this component on the screen. The clipping region in the graphics - * context will indicate the region that requires painting. This is called - * whenever the component first shows, or needs to be repaired because - * something was temporarily drawn on top. It is not necessary for - * subclasses to call <code>super.paint(g)</code>. Components with no area - * are not painted. - * - * @param g the graphics context for this paint job - * @see #update(Graphics) - */ - public void paint(Graphics g) - { - // Paint the heavyweight peer - if (!isLightweight() && peer != null) - peer.paint(g); - } - - /** - * Updates this component. This is called in response to - * <code>repaint</code>. This method fills the component with the - * background color, then sets the foreground color of the specified - * graphics context to the foreground color of this component and calls - * the <code>paint()</code> method. The coordinates of the graphics are - * relative to this component. Subclasses should call either - * <code>super.update(g)</code> or <code>paint(g)</code>. - * - * @param g the graphics context for this update - * - * @see #paint(Graphics) - * @see #repaint() - */ - public void update(Graphics g) - { - if (!isLightweight()) - { - Rectangle clip = g.getClipBounds(); - if (clip == null) - g.clearRect(0, 0, width, height); - else - g.clearRect(clip.x, clip.y, clip.width, clip.height); - } - - paint(g); - } - - /** - * Paints this entire component, including any sub-components. - * - * @param g the graphics context for this paint job - * - * @see #paint(Graphics) - */ - public void paintAll(Graphics g) - { - if (! visible) - return; - paint(g); - } - - /** - * Repaint this entire component. The <code>update()</code> method - * on this component will be called as soon as possible. - * - * @see #update(Graphics) - * @see #repaint(long, int, int, int, int) - */ - public void repaint() - { - repaint(0, 0, 0, width, height); - } - - /** - * Repaint this entire component. The <code>update()</code> method on this - * component will be called in approximate the specified number of - * milliseconds. - * - * @param tm milliseconds before this component should be repainted - * @see #paint(Graphics) - * @see #repaint(long, int, int, int, int) - */ - public void repaint(long tm) - { - repaint(tm, 0, 0, width, height); - } - - /** - * Repaints the specified rectangular region within this component. The - * <code>update</code> method on this component will be called as soon as - * possible. The coordinates are relative to this component. - * - * @param x the X coordinate of the upper left of the region to repaint - * @param y the Y coordinate of the upper left of the region to repaint - * @param w the width of the region to repaint - * @param h the height of the region to repaint - * @see #update(Graphics) - * @see #repaint(long, int, int, int, int) - */ - public void repaint(int x, int y, int w, int h) - { - repaint(0, x, y, w, h); - } - - /** - * Repaints the specified rectangular region within this component. The - * <code>update</code> method on this component will be called in - * approximately the specified number of milliseconds. The coordinates - * are relative to this component. - * - * @param tm milliseconds before this component should be repainted - * @param x the X coordinate of the upper left of the region to repaint - * @param y the Y coordinate of the upper left of the region to repaint - * @param width the width of the region to repaint - * @param height the height of the region to repaint - * @see #update(Graphics) - */ - public void repaint(long tm, int x, int y, int width, int height) - { - // Handle lightweight repainting by forwarding to native parent - if (isLightweight() && parent != null) - { - if (parent != null) - parent.repaint(tm, x + getX(), y + getY(), width, height); - } - else if (peer != null) - peer.repaint(tm, x, y, width, height); - } - - /** - * Prints this component. This method is provided so that printing can be - * done in a different manner from painting. However, the implementation - * in this class simply calls the <code>paint()</code> method. - * - * @param g the graphics context of the print device - * - * @see #paint(Graphics) - */ - public void print(Graphics g) - { - paint(g); - } - - /** - * Prints this component, including all sub-components. This method is - * provided so that printing can be done in a different manner from - * painting. However, the implementation in this class simply calls the - * <code>paintAll()</code> method. - * - * @param g the graphics context of the print device - * - * @see #paintAll(Graphics) - */ - public void printAll(Graphics g) - { - paintAll(g); - } - - /** - * Called when an image has changed so that this component is repainted. - * This incrementally draws an image as more bits are available, when - * possible. Incremental drawing is enabled if the system property - * <code>awt.image.incrementalDraw</code> is not present or is true, in which - * case the redraw rate is set to 100ms or the value of the system property - * <code>awt.image.redrawrate</code>. - * - * <p>The coordinate system used depends on the particular flags. - * - * @param img the image that has been updated - * @param flags tlags as specified in <code>ImageObserver</code> - * @param x the X coordinate - * @param y the Y coordinate - * @param w the width - * @param h the height - * @return false if the image is completely loaded, loading has been - * aborted, or an error has occurred. true if more updates are - * required. - * @see ImageObserver - * @see Graphics#drawImage(Image, int, int, Color, ImageObserver) - * @see Graphics#drawImage(Image, int, int, ImageObserver) - * @see Graphics#drawImage(Image, int, int, int, int, Color, ImageObserver) - * @see Graphics#drawImage(Image, int, int, int, int, ImageObserver) - * @see ImageObserver#imageUpdate(Image, int, int, int, int, int) - */ - public boolean imageUpdate(Image img, int flags, int x, int y, int w, int h) - { - if ((flags & (FRAMEBITS | ALLBITS)) != 0) - repaint (); - else if ((flags & SOMEBITS) != 0) - { - if (incrementalDraw) - { - if (redrawRate != null) - { - long tm = redrawRate.longValue(); - if (tm < 0) - tm = 0; - repaint (tm); - } - else - repaint (100); - } - } - return (flags & (ALLBITS | ABORT | ERROR)) == 0; - } - - /** - * Creates an image from the specified producer. - * - * @param producer the image procedure to create the image from - * @return the resulting image - */ - public Image createImage(ImageProducer producer) - { - // Sun allows producer to be null. - if (peer != null) - return peer.createImage(producer); - else - return getToolkit().createImage(producer); - } - - /** - * Creates an image with the specified width and height for use in - * double buffering. Headless environments do not support images. - * - * @param width the width of the image - * @param height the height of the image - * @return the requested image, or null if it is not supported - */ - public Image createImage (int width, int height) - { - Image returnValue = null; - if (!GraphicsEnvironment.isHeadless ()) - { - if (isLightweight () && parent != null) - returnValue = parent.createImage (width, height); - else if (peer != null) - returnValue = peer.createImage (width, height); - } - return returnValue; - } - - /** - * Creates an image with the specified width and height for use in - * double buffering. Headless environments do not support images. - * - * @param width the width of the image - * @param height the height of the image - * @return the requested image, or null if it is not supported - * @since 1.4 - */ - public VolatileImage createVolatileImage(int width, int height) - { - if (GraphicsEnvironment.isHeadless()) - return null; - GraphicsConfiguration config = getGraphicsConfiguration(); - return config == null ? null - : config.createCompatibleVolatileImage(width, height); - } - - /** - * Creates an image with the specified width and height for use in - * double buffering. Headless environments do not support images. The image - * will support the specified capabilities. - * - * @param width the width of the image - * @param height the height of the image - * @param caps the requested capabilities - * @return the requested image, or null if it is not supported - * @throws AWTException if a buffer with the capabilities cannot be created - * @since 1.4 - */ - public VolatileImage createVolatileImage(int width, int height, - ImageCapabilities caps) - throws AWTException - { - if (GraphicsEnvironment.isHeadless()) - return null; - GraphicsConfiguration config = getGraphicsConfiguration(); - return config == null ? null - : config.createCompatibleVolatileImage(width, height, caps); - } - - /** - * Prepares the specified image for rendering on this component. - * - * @param image the image to prepare for rendering - * @param observer the observer to notify of image preparation status - * @return true if the image is already fully prepared - * @throws NullPointerException if image is null - */ - public boolean prepareImage(Image image, ImageObserver observer) - { - return prepareImage(image, image.getWidth(observer), - image.getHeight(observer), observer); - } - - /** - * Prepares the specified image for rendering on this component at the - * specified scaled width and height - * - * @param image the image to prepare for rendering - * @param width the scaled width of the image - * @param height the scaled height of the image - * @param observer the observer to notify of image preparation status - * @return true if the image is already fully prepared - */ - public boolean prepareImage(Image image, int width, int height, - ImageObserver observer) - { - if (peer != null) - return peer.prepareImage(image, width, height, observer); - else - return getToolkit().prepareImage(image, width, height, observer); - } - - /** - * Returns the status of the loading of the specified image. The value - * returned will be those flags defined in <code>ImageObserver</code>. - * - * @param image the image to check on - * @param observer the observer to notify of image loading progress - * @return the image observer flags indicating the status of the load - * @see #prepareImage(Image, int, int, ImageObserver) - * @see Toolkit#checkImage(Image, int, int, ImageObserver) - * @throws NullPointerException if image is null - */ - public int checkImage(Image image, ImageObserver observer) - { - return checkImage(image, -1, -1, observer); - } - - /** - * Returns the status of the loading of the specified image. The value - * returned will be those flags defined in <code>ImageObserver</code>. - * - * @param image the image to check on - * @param width the scaled image width - * @param height the scaled image height - * @param observer the observer to notify of image loading progress - * @return the image observer flags indicating the status of the load - * @see #prepareImage(Image, int, int, ImageObserver) - * @see Toolkit#checkImage(Image, int, int, ImageObserver) - */ - public int checkImage(Image image, int width, int height, - ImageObserver observer) - { - if (peer != null) - return peer.checkImage(image, width, height, observer); - return getToolkit().checkImage(image, width, height, observer); - } - - /** - * Sets whether paint messages delivered by the operating system should be - * ignored. This does not affect messages from AWT, except for those - * triggered by OS messages. Setting this to true can allow faster - * performance in full-screen mode or page-flipping. - * - * @param ignoreRepaint the new setting for ignoring repaint events - * @see #getIgnoreRepaint() - * @see BufferStrategy - * @see GraphicsDevice#setFullScreenWindow(Window) - * @since 1.4 - */ - public void setIgnoreRepaint(boolean ignoreRepaint) - { - this.ignoreRepaint = ignoreRepaint; - } - - /** - * Test whether paint events from the operating system are ignored. - * - * @return the status of ignoring paint events - * @see #setIgnoreRepaint(boolean) - * @since 1.4 - */ - public boolean getIgnoreRepaint() - { - return ignoreRepaint; - } - - /** - * Tests whether or not the specified point is contained within this - * component. Coordinates are relative to this component. - * - * @param x the X coordinate of the point to test - * @param y the Y coordinate of the point to test - * @return true if the point is within this component - * @see #getComponentAt(int, int) - */ - public boolean contains(int x, int y) - { - return inside (x, y); - } - - /** - * Tests whether or not the specified point is contained within this - * component. Coordinates are relative to this component. - * - * @param x the X coordinate of the point to test - * @param y the Y coordinate of the point to test - * @return true if the point is within this component - * @deprecated use {@link #contains(int, int)} instead - */ - public boolean inside(int x, int y) - { - return x >= 0 && y >= 0 && x < width && y < height; - } - - /** - * Tests whether or not the specified point is contained within this - * component. Coordinates are relative to this component. - * - * @param p the point to test - * @return true if the point is within this component - * @throws NullPointerException if p is null - * @see #getComponentAt(Point) - * @since 1.1 - */ - public boolean contains(Point p) - { - return contains (p.x, p.y); - } - - /** - * Returns the component occupying the position (x,y). This will either - * be this component, an immediate child component, or <code>null</code> - * if neither of the first two occupies the specified location. - * - * @param x the X coordinate to search for components at - * @param y the Y coordinate to search for components at - * @return the component at the specified location, or null - * @see #contains(int, int) - */ - public Component getComponentAt(int x, int y) - { - return locate (x, y); - } - - /** - * Returns the component occupying the position (x,y). This will either - * be this component, an immediate child component, or <code>null</code> - * if neither of the first two occupies the specified location. - * - * @param x the X coordinate to search for components at - * @param y the Y coordinate to search for components at - * @return the component at the specified location, or null - * @deprecated use {@link #getComponentAt(int, int)} instead - */ - public Component locate(int x, int y) - { - return contains (x, y) ? this : null; - } - - /** - * Returns the component occupying the position (x,y). This will either - * be this component, an immediate child component, or <code>null</code> - * if neither of the first two occupies the specified location. - * - * @param p the point to search for components at - * @return the component at the specified location, or null - * @throws NullPointerException if p is null - * @see #contains(Point) - * @since 1.1 - */ - public Component getComponentAt(Point p) - { - return getComponentAt (p.x, p.y); - } - - /** - * AWT 1.0 event delivery. - * - * Deliver an AWT 1.0 event to this Component. This method simply - * calls {@link #postEvent}. - * - * @param e the event to deliver - * @deprecated use {@link #dispatchEvent (AWTEvent)} instead - */ - public void deliverEvent (Event e) - { - postEvent (e); - } - - /** - * Forwards AWT events to processEvent() if:<ul> - * <li>Events have been enabled for this type of event via - * <code>enableEvents()</code></li>, - * <li>There is at least one registered listener for this type of event</li> - * </ul> - * - * @param e the event to dispatch - */ - public final void dispatchEvent(AWTEvent e) - { - // Some subclasses in the AWT package need to override this behavior, - // hence the use of dispatchEventImpl(). - dispatchEventImpl(e); - if (peer != null && ! e.consumed) - peer.handleEvent(e); - } - - /** - * AWT 1.0 event handler. - * - * This method simply calls handleEvent and returns the result. - * - * @param e the event to handle - * @return true if the event was handled, false otherwise - * @deprecated use {@link #dispatchEvent(AWTEvent)} instead - */ - public boolean postEvent (Event e) - { - boolean handled = handleEvent (e); - - if (!handled && getParent() != null) - // FIXME: need to translate event coordinates to parent's - // coordinate space. - handled = getParent ().postEvent (e); - - return handled; - } - - /** - * Adds the specified listener to this component. This is harmless if the - * listener is null, but if the listener has already been registered, it - * will now be registered twice. - * - * @param listener the new listener to add - * @see ComponentEvent - * @see #removeComponentListener(ComponentListener) - * @see #getComponentListeners() - * @since 1.1 - */ - public synchronized void addComponentListener(ComponentListener listener) - { - componentListener = AWTEventMulticaster.add(componentListener, listener); - if (componentListener != null) - enableEvents(AWTEvent.COMPONENT_EVENT_MASK); - } - - /** - * Removes the specified listener from the component. This is harmless if - * the listener was not previously registered. - * - * @param listener the listener to remove - * @see ComponentEvent - * @see #addComponentListener(ComponentListener) - * @see #getComponentListeners() - * @since 1.1 - */ - public synchronized void removeComponentListener(ComponentListener listener) - { - componentListener = AWTEventMulticaster.remove(componentListener, listener); - } - - /** - * Returns an array of all specified listeners registered on this component. - * - * @return an array of listeners - * @see #addComponentListener(ComponentListener) - * @see #removeComponentListener(ComponentListener) - * @since 1.4 - */ - public synchronized ComponentListener[] getComponentListeners() - { - return (ComponentListener[]) - AWTEventMulticaster.getListeners(componentListener, - ComponentListener.class); - } - - /** - * Adds the specified listener to this component. This is harmless if the - * listener is null, but if the listener has already been registered, it - * will now be registered twice. - * - * @param listener the new listener to add - * @see FocusEvent - * @see #removeFocusListener(FocusListener) - * @see #getFocusListeners() - * @since 1.1 - */ - public synchronized void addFocusListener(FocusListener listener) - { - focusListener = AWTEventMulticaster.add(focusListener, listener); - if (focusListener != null) - enableEvents(AWTEvent.FOCUS_EVENT_MASK); - } - - /** - * Removes the specified listener from the component. This is harmless if - * the listener was not previously registered. - * - * @param listener the listener to remove - * @see FocusEvent - * @see #addFocusListener(FocusListener) - * @see #getFocusListeners() - * @since 1.1 - */ - public synchronized void removeFocusListener(FocusListener listener) - { - focusListener = AWTEventMulticaster.remove(focusListener, listener); - } - - /** - * Returns an array of all specified listeners registered on this component. - * - * @return an array of listeners - * @see #addFocusListener(FocusListener) - * @see #removeFocusListener(FocusListener) - * @since 1.4 - */ - public synchronized FocusListener[] getFocusListeners() - { - return (FocusListener[]) - AWTEventMulticaster.getListeners(focusListener, FocusListener.class); - } - - /** - * Adds the specified listener to this component. This is harmless if the - * listener is null, but if the listener has already been registered, it - * will now be registered twice. - * - * @param listener the new listener to add - * @see HierarchyEvent - * @see #removeHierarchyListener(HierarchyListener) - * @see #getHierarchyListeners() - * @since 1.3 - */ - public synchronized void addHierarchyListener(HierarchyListener listener) - { - hierarchyListener = AWTEventMulticaster.add(hierarchyListener, listener); - if (hierarchyListener != null) - enableEvents(AWTEvent.HIERARCHY_EVENT_MASK); - } - - /** - * Removes the specified listener from the component. This is harmless if - * the listener was not previously registered. - * - * @param listener the listener to remove - * @see HierarchyEvent - * @see #addHierarchyListener(HierarchyListener) - * @see #getHierarchyListeners() - * @since 1.3 - */ - public synchronized void removeHierarchyListener(HierarchyListener listener) - { - hierarchyListener = AWTEventMulticaster.remove(hierarchyListener, listener); - } - - /** - * Returns an array of all specified listeners registered on this component. - * - * @return an array of listeners - * @see #addHierarchyListener(HierarchyListener) - * @see #removeHierarchyListener(HierarchyListener) - * @since 1.4 - */ - public synchronized HierarchyListener[] getHierarchyListeners() - { - return (HierarchyListener[]) - AWTEventMulticaster.getListeners(hierarchyListener, - HierarchyListener.class); - } - - /** - * Adds the specified listener to this component. This is harmless if the - * listener is null, but if the listener has already been registered, it - * will now be registered twice. - * - * @param listener the new listener to add - * @see HierarchyEvent - * @see #removeHierarchyBoundsListener(HierarchyBoundsListener) - * @see #getHierarchyBoundsListeners() - * @since 1.3 - */ - public synchronized void - addHierarchyBoundsListener(HierarchyBoundsListener listener) - { - hierarchyBoundsListener = - AWTEventMulticaster.add(hierarchyBoundsListener, listener); - if (hierarchyBoundsListener != null) - enableEvents(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK); - } - - /** - * Removes the specified listener from the component. This is harmless if - * the listener was not previously registered. - * - * @param listener the listener to remove - * @see HierarchyEvent - * @see #addHierarchyBoundsListener(HierarchyBoundsListener) - * @see #getHierarchyBoundsListeners() - * @since 1.3 - */ - public synchronized void - removeHierarchyBoundsListener(HierarchyBoundsListener listener) - { - hierarchyBoundsListener = - AWTEventMulticaster.remove(hierarchyBoundsListener, listener); - } - - /** - * Returns an array of all specified listeners registered on this component. - * - * @return an array of listeners - * @see #addHierarchyBoundsListener(HierarchyBoundsListener) - * @see #removeHierarchyBoundsListener(HierarchyBoundsListener) - * @since 1.4 - */ - public synchronized HierarchyBoundsListener[] getHierarchyBoundsListeners() - { - return (HierarchyBoundsListener[]) - AWTEventMulticaster.getListeners(hierarchyBoundsListener, - HierarchyBoundsListener.class); - } - - /** - * Adds the specified listener to this component. This is harmless if the - * listener is null, but if the listener has already been registered, it - * will now be registered twice. - * - * @param listener the new listener to add - * @see KeyEvent - * @see #removeKeyListener(KeyListener) - * @see #getKeyListeners() - * @since 1.1 - */ - public synchronized void addKeyListener(KeyListener listener) - { - keyListener = AWTEventMulticaster.add(keyListener, listener); - if (keyListener != null) - enableEvents(AWTEvent.KEY_EVENT_MASK); - } - - /** - * Removes the specified listener from the component. This is harmless if - * the listener was not previously registered. - * - * @param listener the listener to remove - * @see KeyEvent - * @see #addKeyListener(KeyListener) - * @see #getKeyListeners() - * @since 1.1 - */ - public synchronized void removeKeyListener(KeyListener listener) - { - keyListener = AWTEventMulticaster.remove(keyListener, listener); - } - - /** - * Returns an array of all specified listeners registered on this component. - * - * @return an array of listeners - * @see #addKeyListener(KeyListener) - * @see #removeKeyListener(KeyListener) - * @since 1.4 - */ - public synchronized KeyListener[] getKeyListeners() - { - return (KeyListener[]) - AWTEventMulticaster.getListeners(keyListener, KeyListener.class); - } - - /** - * Adds the specified listener to this component. This is harmless if the - * listener is null, but if the listener has already been registered, it - * will now be registered twice. - * - * @param listener the new listener to add - * @see MouseEvent - * @see #removeMouseListener(MouseListener) - * @see #getMouseListeners() - * @since 1.1 - */ - public synchronized void addMouseListener(MouseListener listener) - { - mouseListener = AWTEventMulticaster.add(mouseListener, listener); - if (mouseListener != null) - enableEvents(AWTEvent.MOUSE_EVENT_MASK); - } - - /** - * Removes the specified listener from the component. This is harmless if - * the listener was not previously registered. - * - * @param listener the listener to remove - * @see MouseEvent - * @see #addMouseListener(MouseListener) - * @see #getMouseListeners() - * @since 1.1 - */ - public synchronized void removeMouseListener(MouseListener listener) - { - mouseListener = AWTEventMulticaster.remove(mouseListener, listener); - } - - /** - * Returns an array of all specified listeners registered on this component. - * - * @return an array of listeners - * @see #addMouseListener(MouseListener) - * @see #removeMouseListener(MouseListener) - * @since 1.4 - */ - public synchronized MouseListener[] getMouseListeners() - { - return (MouseListener[]) - AWTEventMulticaster.getListeners(mouseListener, MouseListener.class); - } - - /** - * Adds the specified listener to this component. This is harmless if the - * listener is null, but if the listener has already been registered, it - * will now be registered twice. - * - * @param listener the new listener to add - * @see MouseEvent - * @see #removeMouseMotionListener(MouseMotionListener) - * @see #getMouseMotionListeners() - * @since 1.1 - */ - public synchronized void addMouseMotionListener(MouseMotionListener listener) - { - mouseMotionListener = AWTEventMulticaster.add(mouseMotionListener, listener); - if (mouseMotionListener != null) - enableEvents(AWTEvent.MOUSE_EVENT_MASK); - } - - /** - * Removes the specified listener from the component. This is harmless if - * the listener was not previously registered. - * - * @param listener the listener to remove - * @see MouseEvent - * @see #addMouseMotionListener(MouseMotionListener) - * @see #getMouseMotionListeners() - * @since 1.1 - */ - public synchronized void removeMouseMotionListener(MouseMotionListener listener) - { - mouseMotionListener = AWTEventMulticaster.remove(mouseMotionListener, listener); - } - - /** - * Returns an array of all specified listeners registered on this component. - * - * @return an array of listeners - * @see #addMouseMotionListener(MouseMotionListener) - * @see #removeMouseMotionListener(MouseMotionListener) - * @since 1.4 - */ - public synchronized MouseMotionListener[] getMouseMotionListeners() - { - return (MouseMotionListener[]) - AWTEventMulticaster.getListeners(mouseMotionListener, - MouseMotionListener.class); - } - - /** - * Adds the specified listener to this component. This is harmless if the - * listener is null, but if the listener has already been registered, it - * will now be registered twice. - * - * @param listener the new listener to add - * @see MouseEvent - * @see MouseWheelEvent - * @see #removeMouseWheelListener(MouseWheelListener) - * @see #getMouseWheelListeners() - * @since 1.4 - */ - public synchronized void addMouseWheelListener(MouseWheelListener listener) - { - mouseWheelListener = AWTEventMulticaster.add(mouseWheelListener, listener); - if (mouseWheelListener != null) - enableEvents(AWTEvent.MOUSE_WHEEL_EVENT_MASK); - } - - /** - * Removes the specified listener from the component. This is harmless if - * the listener was not previously registered. - * - * @param listener the listener to remove - * @see MouseEvent - * @see MouseWheelEvent - * @see #addMouseWheelListener(MouseWheelListener) - * @see #getMouseWheelListeners() - * @since 1.4 - */ - public synchronized void removeMouseWheelListener(MouseWheelListener listener) - { - mouseWheelListener = AWTEventMulticaster.remove(mouseWheelListener, listener); - } - - /** - * Returns an array of all specified listeners registered on this component. - * - * @return an array of listeners - * @see #addMouseWheelListener(MouseWheelListener) - * @see #removeMouseWheelListener(MouseWheelListener) - * @since 1.4 - */ - public synchronized MouseWheelListener[] getMouseWheelListeners() - { - return (MouseWheelListener[]) - AWTEventMulticaster.getListeners(mouseWheelListener, - MouseWheelListener.class); - } - - /** - * Adds the specified listener to this component. This is harmless if the - * listener is null, but if the listener has already been registered, it - * will now be registered twice. - * - * @param listener the new listener to add - * @see InputMethodEvent - * @see #removeInputMethodListener(InputMethodListener) - * @see #getInputMethodListeners() - * @see #getInputMethodRequests() - * @since 1.2 - */ - public synchronized void addInputMethodListener(InputMethodListener listener) - { - inputMethodListener = AWTEventMulticaster.add(inputMethodListener, listener); - if (inputMethodListener != null) - enableEvents(AWTEvent.INPUT_METHOD_EVENT_MASK); - } - - /** - * Removes the specified listener from the component. This is harmless if - * the listener was not previously registered. - * - * @param listener the listener to remove - * @see InputMethodEvent - * @see #addInputMethodListener(InputMethodListener) - * @see #getInputMethodRequests() - * @since 1.2 - */ - public synchronized void removeInputMethodListener(InputMethodListener listener) - { - inputMethodListener = AWTEventMulticaster.remove(inputMethodListener, listener); - } - - /** - * Returns an array of all specified listeners registered on this component. - * - * @return an array of listeners - * @see #addInputMethodListener(InputMethodListener) - * @see #removeInputMethodListener(InputMethodListener) - * @since 1.4 - */ - public synchronized InputMethodListener[] getInputMethodListeners() - { - return (InputMethodListener[]) - AWTEventMulticaster.getListeners(inputMethodListener, - InputMethodListener.class); - } - - /** - * Returns all registered EventListers of the given listenerType. - * - * @param listenerType the class of listeners to filter - * @return an array of registered listeners - * @see #getComponentListeners() - * @see #getFocusListeners() - * @see #getHierarchyListeners() - * @see #getHierarchyBoundsListeners() - * @see #getKeyListeners() - * @see #getMouseListeners() - * @see #getMouseMotionListeners() - * @see #getMouseWheelListeners() - * @see #getInputMethodListeners() - * @see #getPropertyChangeListeners() - * @since 1.3 - */ - public EventListener[] getListeners(Class listenerType) - { - if (listenerType == ComponentListener.class) - return getComponentListeners(); - if (listenerType == FocusListener.class) - return getFocusListeners(); - if (listenerType == HierarchyListener.class) - return getHierarchyListeners(); - if (listenerType == HierarchyBoundsListener.class) - return getHierarchyBoundsListeners(); - if (listenerType == KeyListener.class) - return getKeyListeners(); - if (listenerType == MouseListener.class) - return getMouseListeners(); - if (listenerType == MouseMotionListener.class) - return getMouseMotionListeners(); - if (listenerType == MouseWheelListener.class) - return getMouseWheelListeners(); - if (listenerType == InputMethodListener.class) - return getInputMethodListeners(); - if (listenerType == PropertyChangeListener.class) - return getPropertyChangeListeners(); - return (EventListener[]) Array.newInstance(listenerType, 0); - } - - /** - * Returns the input method request handler, for subclasses which support - * on-the-spot text input. By default, input methods are handled by AWT, - * and this returns null. - * - * @return the input method handler, null by default - * @since 1.2 - */ - public InputMethodRequests getInputMethodRequests() - { - return null; - } - - /** - * Gets the input context of this component, which is inherited from the - * parent unless this is overridden. - * - * @return the text input context - * @since 1.2 - */ - public InputContext getInputContext() - { - return parent == null ? null : parent.getInputContext(); - } - - /** - * Enables the specified events. The events to enable are specified - * by OR-ing together the desired masks from <code>AWTEvent</code>. - * - * <p>Events are enabled by default when a listener is attached to the - * component for that event type. This method can be used by subclasses - * to ensure the delivery of a specified event regardless of whether - * or not a listener is attached. - * - * @param eventsToEnable the desired events to enable - * @see #processEvent(AWTEvent) - * @see #disableEvents(long) - * @see AWTEvent - * @since 1.1 - */ - protected final void enableEvents(long eventsToEnable) - { - eventMask |= eventsToEnable; - // TODO: Unlike Sun's implementation, I think we should try and - // enable/disable events at the peer (gtk/X) level. This will avoid - // clogging the event pipeline with useless mousemove events that - // we arn't interested in, etc. This will involve extending the peer - // interface, but thats okay because the peer interfaces have been - // deprecated for a long time, and no longer feature in the - // API specification at all. - if (isLightweight() && parent != null) - parent.enableEvents(eventsToEnable); - else if (peer != null) - peer.setEventMask(eventMask); - } - - /** - * Disables the specified events. The events to disable are specified - * by OR-ing together the desired masks from <code>AWTEvent</code>. - * - * @param eventsToDisable the desired events to disable - * @see #enableEvents(long) - * @since 1.1 - */ - protected final void disableEvents(long eventsToDisable) - { - eventMask &= ~eventsToDisable; - // forward new event mask to peer? - } - - /** - * This is called by the EventQueue if two events with the same event id - * and owner component are queued. Returns a new combined event, or null if - * no combining is done. The coelesced events are currently mouse moves - * (intermediate ones are discarded) and paint events (a merged paint is - * created in place of the two events). - * - * @param existingEvent the event on the queue - * @param newEvent the new event that might be entered on the queue - * @return null if both events are kept, or the replacement coelesced event - */ - protected AWTEvent coalesceEvents(AWTEvent existingEvent, AWTEvent newEvent) - { - switch (existingEvent.id) - { - case MouseEvent.MOUSE_MOVED: - case MouseEvent.MOUSE_DRAGGED: - // Just drop the old (intermediate) event and return the new one. - return newEvent; - case PaintEvent.PAINT: - case PaintEvent.UPDATE: - return coalescePaintEvents((PaintEvent) existingEvent, - (PaintEvent) newEvent); - default: - return null; - } - } - - /** - * Processes the specified event. In this class, this method simply - * calls one of the more specific event handlers. - * - * @param e the event to process - * @throws NullPointerException if e is null - * @see #processComponentEvent(ComponentEvent) - * @see #processFocusEvent(FocusEvent) - * @see #processKeyEvent(KeyEvent) - * @see #processMouseEvent(MouseEvent) - * @see #processMouseMotionEvent(MouseEvent) - * @see #processInputMethodEvent(InputMethodEvent) - * @see #processHierarchyEvent(HierarchyEvent) - * @see #processMouseWheelEvent(MouseWheelEvent) - * @since 1.1 - */ - protected void processEvent(AWTEvent e) - { - /* Note: the order of these if statements are - important. Subclasses must be checked first. Eg. MouseEvent - must be checked before ComponentEvent, since a MouseEvent - object is also an instance of a ComponentEvent. */ - - if (e instanceof FocusEvent) - processFocusEvent((FocusEvent) e); - else if (e instanceof MouseWheelEvent) - processMouseWheelEvent((MouseWheelEvent) e); - else if (e instanceof MouseEvent) - { - if (e.id == MouseEvent.MOUSE_MOVED - || e.id == MouseEvent.MOUSE_DRAGGED) - processMouseMotionEvent((MouseEvent) e); - else - processMouseEvent((MouseEvent) e); - } - else if (e instanceof KeyEvent) - processKeyEvent((KeyEvent) e); - else if (e instanceof InputMethodEvent) - processInputMethodEvent((InputMethodEvent) e); - else if (e instanceof ComponentEvent) - processComponentEvent((ComponentEvent) e); - else if (e instanceof HierarchyEvent) - { - if (e.id == HierarchyEvent.HIERARCHY_CHANGED) - processHierarchyEvent((HierarchyEvent) e); - else - processHierarchyBoundsEvent((HierarchyEvent) e); - } - } - - /** - * Called when a component event is dispatched and component events are - * enabled. This method passes the event along to any listeners - * that are attached. - * - * @param e the <code>ComponentEvent</code> to process - * @throws NullPointerException if e is null - * @see ComponentListener - * @see #addComponentListener(ComponentListener) - * @see #enableEvents(long) - * @since 1.1 - */ - protected void processComponentEvent(ComponentEvent e) - { - if (componentListener == null) - return; - switch (e.id) - { - case ComponentEvent.COMPONENT_HIDDEN: - componentListener.componentHidden(e); - break; - case ComponentEvent.COMPONENT_MOVED: - componentListener.componentMoved(e); - break; - case ComponentEvent.COMPONENT_RESIZED: - componentListener.componentResized(e); - break; - case ComponentEvent.COMPONENT_SHOWN: - componentListener.componentShown(e); - break; - } - } - - /** - * Called when a focus event is dispatched and component events are - * enabled. This method passes the event along to any listeners - * that are attached. - * - * @param e the <code>FocusEvent</code> to process - * @throws NullPointerException if e is null - * @see FocusListener - * @see #addFocusListener(FocusListener) - * @see #enableEvents(long) - * @since 1.1 - */ - protected void processFocusEvent(FocusEvent e) - { - if (focusListener == null) - return; - - switch (e.id) - { - case FocusEvent.FOCUS_GAINED: - focusListener.focusGained(e); - break; - case FocusEvent.FOCUS_LOST: - focusListener.focusLost(e); - break; - } - } - - /** - * Called when a key event is dispatched and component events are - * enabled. This method passes the event along to any listeners - * that are attached. - * - * @param e the <code>KeyEvent</code> to process - * @throws NullPointerException if e is null - * @see KeyListener - * @see #addKeyListener(KeyListener) - * @see #enableEvents(long) - * @since 1.1 - */ - protected void processKeyEvent(KeyEvent e) - { - if (keyListener == null) - return; - switch (e.id) - { - case KeyEvent.KEY_PRESSED: - keyListener.keyPressed(e); - break; - case KeyEvent.KEY_RELEASED: - keyListener.keyReleased(e); - break; - case KeyEvent.KEY_TYPED: - keyListener.keyTyped(e); - break; - } - } - - /** - * Called when a regular mouse event is dispatched and component events are - * enabled. This method passes the event along to any listeners - * that are attached. - * - * @param e the <code>MouseEvent</code> to process - * @throws NullPointerException if e is null - * @see MouseListener - * @see #addMouseListener(MouseListener) - * @see #enableEvents(long) - * @since 1.1 - */ - protected void processMouseEvent(MouseEvent e) - { - if (mouseListener == null) - return; - switch (e.id) - { - case MouseEvent.MOUSE_CLICKED: - mouseListener.mouseClicked(e); - break; - case MouseEvent.MOUSE_ENTERED: - mouseListener.mouseEntered(e); - break; - case MouseEvent.MOUSE_EXITED: - mouseListener.mouseExited(e); - break; - case MouseEvent.MOUSE_PRESSED: - mouseListener.mousePressed(e); - break; - case MouseEvent.MOUSE_RELEASED: - mouseListener.mouseReleased(e); - break; - } - e.consume(); - } - - /** - * Called when a mouse motion event is dispatched and component events are - * enabled. This method passes the event along to any listeners - * that are attached. - * - * @param e the <code>MouseMotionEvent</code> to process - * @throws NullPointerException if e is null - * @see MouseMotionListener - * @see #addMouseMotionListener(MouseMotionListener) - * @see #enableEvents(long) - * @since 1.1 - */ - protected void processMouseMotionEvent(MouseEvent e) - { - if (mouseMotionListener == null) - return; - switch (e.id) - { - case MouseEvent.MOUSE_DRAGGED: - mouseMotionListener.mouseDragged(e); - break; - case MouseEvent.MOUSE_MOVED: - mouseMotionListener.mouseMoved(e); - break; - } - e.consume(); - } - - /** - * Called when a mouse wheel event is dispatched and component events are - * enabled. This method passes the event along to any listeners that are - * attached. - * - * @param e the <code>MouseWheelEvent</code> to process - * @throws NullPointerException if e is null - * @see MouseWheelListener - * @see #addMouseWheelListener(MouseWheelListener) - * @see #enableEvents(long) - * @since 1.4 - */ - protected void processMouseWheelEvent(MouseWheelEvent e) - { - if (mouseWheelListener != null - && e.id == MouseEvent.MOUSE_WHEEL) - { - mouseWheelListener.mouseWheelMoved(e); - e.consume(); - } - } - - /** - * Called when an input method event is dispatched and component events are - * enabled. This method passes the event along to any listeners that are - * attached. - * - * @param e the <code>InputMethodEvent</code> to process - * @throws NullPointerException if e is null - * @see InputMethodListener - * @see #addInputMethodListener(InputMethodListener) - * @see #enableEvents(long) - * @since 1.2 - */ - protected void processInputMethodEvent(InputMethodEvent e) - { - if (inputMethodListener == null) - return; - switch (e.id) - { - case InputMethodEvent.CARET_POSITION_CHANGED: - inputMethodListener.caretPositionChanged(e); - break; - case InputMethodEvent.INPUT_METHOD_TEXT_CHANGED: - inputMethodListener.inputMethodTextChanged(e); - break; - } - } - - /** - * Called when a hierarchy change event is dispatched and component events - * are enabled. This method passes the event along to any listeners that are - * attached. - * - * @param e the <code>HierarchyEvent</code> to process - * @throws NullPointerException if e is null - * @see HierarchyListener - * @see #addHierarchyListener(HierarchyListener) - * @see #enableEvents(long) - * @since 1.3 - */ - protected void processHierarchyEvent(HierarchyEvent e) - { - if (hierarchyListener == null) - return; - if (e.id == HierarchyEvent.HIERARCHY_CHANGED) - hierarchyListener.hierarchyChanged(e); - } - - /** - * Called when a hierarchy bounds event is dispatched and component events - * are enabled. This method passes the event along to any listeners that are - * attached. - * - * @param e the <code>HierarchyEvent</code> to process - * @throws NullPointerException if e is null - * @see HierarchyBoundsListener - * @see #addHierarchyBoundsListener(HierarchyBoundsListener) - * @see #enableEvents(long) - * @since 1.3 - */ - protected void processHierarchyBoundsEvent(HierarchyEvent e) - { - if (hierarchyBoundsListener == null) - return; - switch (e.id) - { - case HierarchyEvent.ANCESTOR_MOVED: - hierarchyBoundsListener.ancestorMoved(e); - break; - case HierarchyEvent.ANCESTOR_RESIZED: - hierarchyBoundsListener.ancestorResized(e); - break; - } - } - - /** - * AWT 1.0 event handler. - * - * This method calls one of the event-specific handler methods. For - * example for key events, either {@link #keyDown(Event,int)} - * or {@link #keyUp(Event,int)} is called. A derived - * component can override one of these event-specific methods if it - * only needs to handle certain event types. Otherwise it can - * override handleEvent itself and handle any event. - * - * @param evt the event to handle - * @return true if the event was handled, false otherwise - * @deprecated use {@link #processEvent(AWTEvent)} instead - */ - public boolean handleEvent (Event evt) - { - switch (evt.id) - { - // Handle key events. - case Event.KEY_ACTION: - case Event.KEY_PRESS: - return keyDown (evt, evt.key); - case Event.KEY_ACTION_RELEASE: - case Event.KEY_RELEASE: - return keyUp (evt, evt.key); - - // Handle mouse events. - case Event.MOUSE_DOWN: - return mouseDown (evt, evt.x, evt.y); - case Event.MOUSE_UP: - return mouseUp (evt, evt.x, evt.y); - case Event.MOUSE_MOVE: - return mouseMove (evt, evt.x, evt.y); - case Event.MOUSE_DRAG: - return mouseDrag (evt, evt.x, evt.y); - case Event.MOUSE_ENTER: - return mouseEnter (evt, evt.x, evt.y); - case Event.MOUSE_EXIT: - return mouseExit (evt, evt.x, evt.y); - - // Handle focus events. - case Event.GOT_FOCUS: - return gotFocus (evt, evt.arg); - case Event.LOST_FOCUS: - return lostFocus (evt, evt.arg); - - // Handle action event. - case Event.ACTION_EVENT: - return action (evt, evt.arg); - } - // Unknown event. - return false; - } - - /** - * AWT 1.0 MOUSE_DOWN event handler. This method is meant to be - * overridden by components providing their own MOUSE_DOWN handler. - * The default implementation simply returns false. - * - * @param evt the event to handle - * @param x the x coordinate, ignored - * @param y the y coordinate, ignored - * @return false - * @deprecated use {@link #processMouseEvent(MouseEvent)} instead - */ - public boolean mouseDown(Event evt, int x, int y) - { - return false; - } - - /** - * AWT 1.0 MOUSE_DRAG event handler. This method is meant to be - * overridden by components providing their own MOUSE_DRAG handler. - * The default implementation simply returns false. - * - * @param evt the event to handle - * @param x the x coordinate, ignored - * @param y the y coordinate, ignored - * @return false - * @deprecated use {@link #processMouseMotionEvent(MouseEvent)} instead - */ - public boolean mouseDrag(Event evt, int x, int y) - { - return false; - } - - /** - * AWT 1.0 MOUSE_UP event handler. This method is meant to be - * overridden by components providing their own MOUSE_UP handler. - * The default implementation simply returns false. - * - * @param evt the event to handle - * @param x the x coordinate, ignored - * @param y the y coordinate, ignored - * @return false - * @deprecated use {@link #processMouseEvent(MouseEvent)} instead - */ - public boolean mouseUp(Event evt, int x, int y) - { - return false; - } - - /** - * AWT 1.0 MOUSE_MOVE event handler. This method is meant to be - * overridden by components providing their own MOUSE_MOVE handler. - * The default implementation simply returns false. - * - * @param evt the event to handle - * @param x the x coordinate, ignored - * @param y the y coordinate, ignored - * @return false - * @deprecated use {@link #processMouseMotionEvent(MouseEvent)} instead - */ - public boolean mouseMove(Event evt, int x, int y) - { - return false; - } - - /** - * AWT 1.0 MOUSE_ENTER event handler. This method is meant to be - * overridden by components providing their own MOUSE_ENTER handler. - * The default implementation simply returns false. - * - * @param evt the event to handle - * @param x the x coordinate, ignored - * @param y the y coordinate, ignored - * @return false - * @deprecated use {@link #processMouseEvent(MouseEvent)} instead - */ - public boolean mouseEnter(Event evt, int x, int y) - { - return false; - } - - /** - * AWT 1.0 MOUSE_EXIT event handler. This method is meant to be - * overridden by components providing their own MOUSE_EXIT handler. - * The default implementation simply returns false. - * - * @param evt the event to handle - * @param x the x coordinate, ignored - * @param y the y coordinate, ignored - * @return false - * @deprecated use {@link #processMouseEvent(MouseEvent)} instead - */ - public boolean mouseExit(Event evt, int x, int y) - { - return false; - } - - /** - * AWT 1.0 KEY_PRESS and KEY_ACTION event handler. This method is - * meant to be overridden by components providing their own key - * press handler. The default implementation simply returns false. - * - * @param evt the event to handle - * @param key the key pressed, ignored - * @return false - * @deprecated use {@link #processKeyEvent(KeyEvent)} instead - */ - public boolean keyDown(Event evt, int key) - { - return false; - } - - /** - * AWT 1.0 KEY_RELEASE and KEY_ACTION_RELEASE event handler. This - * method is meant to be overridden by components providing their - * own key release handler. The default implementation simply - * returns false. - * - * @param evt the event to handle - * @param key the key pressed, ignored - * @return false - * @deprecated use {@link #processKeyEvent(KeyEvent)} instead - */ - public boolean keyUp(Event evt, int key) - { - return false; - } - - /** - * AWT 1.0 ACTION_EVENT event handler. This method is meant to be - * overridden by components providing their own action event - * handler. The default implementation simply returns false. - * - * @param evt the event to handle - * @param what the object acted on, ignored - * @return false - * @deprecated in classes which support actions, use - * <code>processActionEvent(ActionEvent)</code> instead - */ - public boolean action(Event evt, Object what) - { - return false; - } - - /** - * Called to inform this component it has been added to a container. - * A native peer - if any - is created at this time. This method is - * called automatically by the AWT system and should not be called by - * user level code. - * - * @see #isDisplayable() - * @see #removeNotify() - */ - public void addNotify() - { - if (peer == null) - peer = getToolkit().createComponent(this); - /* Now that all the children has gotten their peers, we should - have the event mask needed for this component and its - lightweight subcomponents. */ - peer.setEventMask(eventMask); - /* We do not invalidate here, but rather leave that job up to - the peer. For efficiency, the peer can choose not to - invalidate if it is happy with the current dimensions, - etc. */ - } - - /** - * Called to inform this component is has been removed from its - * container. Its native peer - if any - is destroyed at this time. - * This method is called automatically by the AWT system and should - * not be called by user level code. - * - * @see #isDisplayable() - * @see #addNotify() - */ - public void removeNotify() - { - // We null our peer field before disposing of it, such that if we're - // not the event dispatch thread and the dispatch thread is awoken by - // the dispose call, there will be no race checking the peer's null - // status. - - ComponentPeer tmp = peer; - peer = null; - if (tmp != null) - tmp.dispose(); - } - - /** - * AWT 1.0 GOT_FOCUS event handler. This method is meant to be - * overridden by components providing their own GOT_FOCUS handler. - * The default implementation simply returns false. - * - * @param evt the event to handle - * @param what the Object focused, ignored - * @return false - * @deprecated use {@link #processFocusEvent(FocusEvent)} instead - */ - public boolean gotFocus(Event evt, Object what) - { - return false; - } - - /** - * AWT 1.0 LOST_FOCUS event handler. This method is meant to be - * overridden by components providing their own LOST_FOCUS handler. - * The default implementation simply returns false. - * - * @param evt the event to handle - * @param what the Object focused, ignored - * @return false - * @deprecated use {@link #processFocusEvent(FocusEvent)} instead - */ - public boolean lostFocus(Event evt, Object what) - { - return false; - } - - /** - * Tests whether or not this component is in the group that can be - * traversed using the keyboard traversal mechanism (such as the TAB key). - * - * @return true if the component is traversed via the TAB key - * @see #setFocusable(boolean) - * @since 1.1 - * @deprecated use {@link #isFocusable()} instead - */ - public boolean isFocusTraversable() - { - return enabled && visible && (peer == null || isLightweight() || peer.isFocusTraversable()); - } - - /** - * Tests if this component can receive focus. - * - * @return true if this component can receive focus - * @since 1.4 - */ - public boolean isFocusable() - { - return focusable; - } - - /** - * Specify whether this component can receive focus. This method also - * sets the {@link #isFocusTraversableOverridden} field to 1, which - * appears to be the undocumented way {@link - * DefaultFocusTraversalPolicy#accept(Component)} determines whether to - * respect the {@link #isFocusable()} method of the component. - * - * @param focusable the new focusable status - * @since 1.4 - */ - public void setFocusable(boolean focusable) - { - firePropertyChange("focusable", this.focusable, focusable); - this.focusable = focusable; - this.isFocusTraversableOverridden = 1; - } - - /** - * Sets the focus traversal keys for one of the three focus - * traversal directions supported by Components: - * {@link #KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS}, - * {@link #KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS}, or - * {@link #KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS}. Normally, the - * default values should match the operating system's native - * choices. To disable a given traversal, use - * <code>Collections.EMPTY_SET</code>. The event dispatcher will - * consume PRESSED, RELEASED, and TYPED events for the specified - * key, although focus can only transfer on PRESSED or RELEASED. - * - * <p>The defaults are: - * <table> - * <th><td>Identifier</td><td>Meaning</td><td>Default</td></th> - * <tr><td>KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS</td> - * <td>Normal forward traversal</td> - * <td>TAB on KEY_PRESSED, Ctrl-TAB on KEY_PRESSED</td></tr> - * <tr><td>KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS</td> - * <td>Normal backward traversal</td> - * <td>Shift-TAB on KEY_PRESSED, Ctrl-Shift-TAB on KEY_PRESSED</td></tr> - * <tr><td>KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS</td> - * <td>Go up a traversal cycle</td><td>None</td></tr> - * </table> - * - * If keystrokes is null, this component's focus traversal key set - * is inherited from one of its ancestors. If none of its ancestors - * has its own set of focus traversal keys, the focus traversal keys - * are set to the defaults retrieved from the current - * KeyboardFocusManager. If not null, the set must contain only - * AWTKeyStrokes that are not already focus keys and are not - * KEY_TYPED events. - * - * @param id one of FORWARD_TRAVERSAL_KEYS, BACKWARD_TRAVERSAL_KEYS, or - * UP_CYCLE_TRAVERSAL_KEYS - * @param keystrokes a set of keys, or null - * @throws IllegalArgumentException if id or keystrokes is invalid - * @see #getFocusTraversalKeys(int) - * @see KeyboardFocusManager#FORWARD_TRAVERSAL_KEYS - * @see KeyboardFocusManager#BACKWARD_TRAVERSAL_KEYS - * @see KeyboardFocusManager#UP_CYCLE_TRAVERSAL_KEYS - * @since 1.4 - */ - public void setFocusTraversalKeys(int id, Set keystrokes) - { - if (keystrokes == null) - { - Container parent = getParent (); - - while (parent != null) - { - if (parent.areFocusTraversalKeysSet (id)) - { - keystrokes = parent.getFocusTraversalKeys (id); - break; - } - parent = parent.getParent (); - } - - if (keystrokes == null) - keystrokes = KeyboardFocusManager.getCurrentKeyboardFocusManager (). - getDefaultFocusTraversalKeys (id); - } - - Set sa; - Set sb; - String name; - switch (id) - { - case KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS: - sa = getFocusTraversalKeys - (KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS); - sb = getFocusTraversalKeys - (KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS); - name = "forwardFocusTraversalKeys"; - break; - case KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS: - sa = getFocusTraversalKeys - (KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS); - sb = getFocusTraversalKeys - (KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS); - name = "backwardFocusTraversalKeys"; - break; - case KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS: - sa = getFocusTraversalKeys - (KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS); - sb = getFocusTraversalKeys - (KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS); - name = "upCycleFocusTraversalKeys"; - break; - default: - throw new IllegalArgumentException (); - } - - int i = keystrokes.size (); - Iterator iter = keystrokes.iterator (); - - while (--i >= 0) - { - Object o = iter.next (); - if (!(o instanceof AWTKeyStroke) - || sa.contains (o) || sb.contains (o) - || ((AWTKeyStroke) o).keyCode == KeyEvent.VK_UNDEFINED) - throw new IllegalArgumentException (); - } - - if (focusTraversalKeys == null) - focusTraversalKeys = new Set[3]; - - keystrokes = Collections.unmodifiableSet (new HashSet (keystrokes)); - firePropertyChange (name, focusTraversalKeys[id], keystrokes); - - focusTraversalKeys[id] = keystrokes; - } - - /** - * Returns the set of keys for a given focus traversal action, as - * defined in <code>setFocusTraversalKeys</code>. If not set, this - * is inherited from the parent component, which may have gotten it - * from the KeyboardFocusManager. - * - * @param id one of FORWARD_TRAVERSAL_KEYS, BACKWARD_TRAVERSAL_KEYS, - * or UP_CYCLE_TRAVERSAL_KEYS - * - * @return set of traversal keys - * - * @throws IllegalArgumentException if id is invalid - * - * @see #setFocusTraversalKeys (int, Set) - * @see KeyboardFocusManager#FORWARD_TRAVERSAL_KEYS - * @see KeyboardFocusManager#BACKWARD_TRAVERSAL_KEYS - * @see KeyboardFocusManager#UP_CYCLE_TRAVERSAL_KEYS - * - * @since 1.4 - */ - public Set getFocusTraversalKeys (int id) - { - if (id != KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS && - id != KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS && - id != KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS) - throw new IllegalArgumentException(); - - Set s = null; - - if (focusTraversalKeys != null) - s = focusTraversalKeys[id]; - - if (s == null && parent != null) - s = parent.getFocusTraversalKeys (id); - - return s == null ? (KeyboardFocusManager.getCurrentKeyboardFocusManager() - .getDefaultFocusTraversalKeys(id)) : s; - } - - /** - * Tests whether the focus traversal keys for a given action are explicitly - * set or inherited. - * - * @param id one of FORWARD_TRAVERSAL_KEYS, BACKWARD_TRAVERSAL_KEYS, - * or UP_CYCLE_TRAVERSAL_KEYS - * @return true if that set is explicitly specified - * @throws IllegalArgumentException if id is invalid - * @see #getFocusTraversalKeys (int) - * @see KeyboardFocusManager#FORWARD_TRAVERSAL_KEYS - * @see KeyboardFocusManager#BACKWARD_TRAVERSAL_KEYS - * @see KeyboardFocusManager#UP_CYCLE_TRAVERSAL_KEYS - * @since 1.4 - */ - public boolean areFocusTraversalKeysSet (int id) - { - if (id != KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS && - id != KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS && - id != KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS) - throw new IllegalArgumentException (); - - return focusTraversalKeys != null && focusTraversalKeys[id] != null; - } - - /** - * Enable or disable focus traversal keys on this Component. If - * they are, then the keyboard focus manager consumes and acts on - * key press and release events that trigger focus traversal, and - * discards the corresponding key typed events. If focus traversal - * keys are disabled, then all key events that would otherwise - * trigger focus traversal are sent to this Component. - * - * @param focusTraversalKeysEnabled the new value of the flag - * @see #getFocusTraversalKeysEnabled () - * @see #setFocusTraversalKeys (int, Set) - * @see #getFocusTraversalKeys (int) - * @since 1.4 - */ - public void setFocusTraversalKeysEnabled (boolean focusTraversalKeysEnabled) - { - firePropertyChange ("focusTraversalKeysEnabled", - this.focusTraversalKeysEnabled, - focusTraversalKeysEnabled); - this.focusTraversalKeysEnabled = focusTraversalKeysEnabled; - } - - /** - * Check whether or not focus traversal keys are enabled on this - * Component. If they are, then the keyboard focus manager consumes - * and acts on key press and release events that trigger focus - * traversal, and discards the corresponding key typed events. If - * focus traversal keys are disabled, then all key events that would - * otherwise trigger focus traversal are sent to this Component. - * - * @return true if focus traversal keys are enabled - * @see #setFocusTraversalKeysEnabled (boolean) - * @see #setFocusTraversalKeys (int, Set) - * @see #getFocusTraversalKeys (int) - * @since 1.4 - */ - public boolean getFocusTraversalKeysEnabled () - { - return focusTraversalKeysEnabled; - } - - /** - * Request that this Component be given the keyboard input focus and - * that its top-level ancestor become the focused Window. - * - * For the request to be granted, the Component must be focusable, - * displayable and showing and the top-level Window to which it - * belongs must be focusable. If the request is initially denied on - * the basis that the top-level Window is not focusable, the request - * will be remembered and granted when the Window does become - * focused. - * - * Never assume that this Component is the focus owner until it - * receives a FOCUS_GAINED event. - * - * The behaviour of this method is platform-dependent. - * {@link #requestFocusInWindow()} should be used instead. - * - * @see #requestFocusInWindow () - * @see FocusEvent - * @see #addFocusListener (FocusListener) - * @see #isFocusable () - * @see #isDisplayable () - * @see KeyboardFocusManager#clearGlobalFocusOwner () - */ - public void requestFocus () - { - if (isDisplayable () - && isShowing () - && isFocusable ()) - { - synchronized (getTreeLock ()) - { - // Find this Component's top-level ancestor. - Container parent = getParent (); - - while (parent != null - && !(parent instanceof Window)) - parent = parent.getParent (); - - Window toplevel = (Window) parent; - if (toplevel.isFocusableWindow ()) - { - if (peer != null && !isLightweight()) - // This call will cause a FOCUS_GAINED event to be - // posted to the system event queue if the native - // windowing system grants the focus request. - peer.requestFocus (); - else - { - // Either our peer hasn't been created yet or we're a - // lightweight component. In either case we want to - // post a FOCUS_GAINED event. - EventQueue eq = Toolkit.getDefaultToolkit ().getSystemEventQueue (); - synchronized (eq) - { - KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager (); - Component currentFocusOwner = manager.getGlobalPermanentFocusOwner (); - if (currentFocusOwner != null) - { - eq.postEvent (new FocusEvent(currentFocusOwner, FocusEvent.FOCUS_LOST, - false, this)); - eq.postEvent (new FocusEvent(this, FocusEvent.FOCUS_GAINED, false, - currentFocusOwner)); - } - else - eq.postEvent (new FocusEvent(this, FocusEvent.FOCUS_GAINED, false)); - } - } - } - else - pendingFocusRequest = new FocusEvent(this, FocusEvent.FOCUS_GAINED); - } - } - } - - /** - * Request that this Component be given the keyboard input focus and - * that its top-level ancestor become the focused Window. - * - * For the request to be granted, the Component must be focusable, - * displayable and showing and the top-level Window to which it - * belongs must be focusable. If the request is initially denied on - * the basis that the top-level Window is not focusable, the request - * will be remembered and granted when the Window does become - * focused. - * - * Never assume that this Component is the focus owner until it - * receives a FOCUS_GAINED event. - * - * The behaviour of this method is platform-dependent. - * {@link #requestFocusInWindow()} should be used instead. - * - * If the return value is false, the request is guaranteed to fail. - * If the return value is true, the request will succeed unless it - * is vetoed or something in the native windowing system intervenes, - * preventing this Component's top-level ancestor from becoming - * focused. This method is meant to be called by derived - * lightweight Components that want to avoid unnecessary repainting - * when they know a given focus transfer need only be temporary. - * - * @param temporary true if the focus request is temporary - * @return true if the request has a chance of success - * @see #requestFocusInWindow () - * @see FocusEvent - * @see #addFocusListener (FocusListener) - * @see #isFocusable () - * @see #isDisplayable () - * @see KeyboardFocusManager#clearGlobalFocusOwner () - * @since 1.4 - */ - protected boolean requestFocus (boolean temporary) - { - if (isDisplayable () - && isShowing () - && isFocusable ()) - { - synchronized (getTreeLock ()) - { - // Find this Component's top-level ancestor. - Container parent = getParent (); - - while (parent != null - && !(parent instanceof Window)) - parent = parent.getParent (); - - Window toplevel = (Window) parent; - if (toplevel.isFocusableWindow ()) - { - if (peer != null && !isLightweight()) - // This call will cause a FOCUS_GAINED event to be - // posted to the system event queue if the native - // windowing system grants the focus request. - peer.requestFocus (); - else - { - // Either our peer hasn't been created yet or we're a - // lightweight component. In either case we want to - // post a FOCUS_GAINED event. - EventQueue eq = Toolkit.getDefaultToolkit ().getSystemEventQueue (); - synchronized (eq) - { - KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager (); - Component currentFocusOwner = manager.getGlobalPermanentFocusOwner (); - if (currentFocusOwner != null) - { - eq.postEvent (new FocusEvent(currentFocusOwner, - FocusEvent.FOCUS_LOST, - temporary, this)); - eq.postEvent (new FocusEvent(this, - FocusEvent.FOCUS_GAINED, - temporary, - currentFocusOwner)); - } - else - eq.postEvent (new FocusEvent(this, FocusEvent.FOCUS_GAINED, temporary)); - } - } - } - else - // FIXME: need to add a focus listener to our top-level - // ancestor, so that we can post this event when it becomes - // the focused window. - pendingFocusRequest = new FocusEvent(this, FocusEvent.FOCUS_GAINED, temporary); - } - } - // Always return true. - return true; - } - - /** - * Request that this component be given the keyboard input focus, if - * its top-level ancestor is the currently focused Window. A - * <code>FOCUS_GAINED</code> event will be fired if and only if this - * request is successful. To be successful, the component must be - * displayable, showing, and focusable, and its ancestor top-level - * Window must be focused. - * - * If the return value is false, the request is guaranteed to fail. - * If the return value is true, the request will succeed unless it - * is vetoed or something in the native windowing system intervenes, - * preventing this Component's top-level ancestor from becoming - * focused. - * - * @return true if the request has a chance of success - * @see #requestFocus () - * @see FocusEvent - * @see #addFocusListener (FocusListener) - * @see #isFocusable () - * @see #isDisplayable () - * @see KeyboardFocusManager#clearGlobalFocusOwner () - * @since 1.4 - */ - public boolean requestFocusInWindow () - { - return requestFocusInWindow (false); - } - - /** - * Request that this component be given the keyboard input focus, if - * its top-level ancestor is the currently focused Window. A - * <code>FOCUS_GAINED</code> event will be fired if and only if this - * request is successful. To be successful, the component must be - * displayable, showing, and focusable, and its ancestor top-level - * Window must be focused. - * - * If the return value is false, the request is guaranteed to fail. - * If the return value is true, the request will succeed unless it - * is vetoed or something in the native windowing system intervenes, - * preventing this Component's top-level ancestor from becoming - * focused. This method is meant to be called by derived - * lightweight Components that want to avoid unnecessary repainting - * when they know a given focus transfer need only be temporary. - * - * @param temporary true if the focus request is temporary - * @return true if the request has a chance of success - * @see #requestFocus () - * @see FocusEvent - * @see #addFocusListener (FocusListener) - * @see #isFocusable () - * @see #isDisplayable () - * @see KeyboardFocusManager#clearGlobalFocusOwner () - * @since 1.4 - */ - protected boolean requestFocusInWindow (boolean temporary) - { - KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager (); - - Window focusedWindow = manager.getFocusedWindow (); - - if (isDisplayable () - && isShowing () - && isFocusable ()) - { - if (focusedWindow != null) - { - synchronized (getTreeLock ()) - { - Container parent = getParent (); - - while (parent != null - && !(parent instanceof Window)) - parent = parent.getParent (); - - Window toplevel = (Window) parent; - - // Check if top-level ancestor is currently focused window. - if (focusedWindow == toplevel) - { - if (peer != null - && !isLightweight() - && !(this instanceof Window)) - // This call will cause a FOCUS_GAINED event to be - // posted to the system event queue if the native - // windowing system grants the focus request. - peer.requestFocus (); - else - { - // Either our peer hasn't been created yet or we're a - // lightweight component. In either case we want to - // post a FOCUS_GAINED event. - EventQueue eq = Toolkit.getDefaultToolkit ().getSystemEventQueue (); - synchronized (eq) - { - Component currentFocusOwner = manager.getGlobalPermanentFocusOwner (); - if (currentFocusOwner != null) - { - eq.postEvent (new FocusEvent(currentFocusOwner, FocusEvent.FOCUS_LOST, - temporary, this)); - eq.postEvent (new FocusEvent(this, FocusEvent.FOCUS_GAINED, temporary, - currentFocusOwner)); - } - else - eq.postEvent (new FocusEvent(this, FocusEvent.FOCUS_GAINED, temporary)); - } - } - } - else - return false; - } - } - - return true; - } - return false; - } - - /** - * Transfers focus to the next component in the focus traversal - * order, as though this were the current focus owner. - * - * @see #requestFocus() - * @since 1.1 - */ - public void transferFocus () - { - nextFocus (); - } - - /** - * Returns the root container that owns the focus cycle where this - * component resides. A focus cycle root is in two cycles, one as - * the ancestor, and one as the focusable element; this call always - * returns the ancestor. - * - * @return the ancestor container that owns the focus cycle - * @since 1.4 - */ - public Container getFocusCycleRootAncestor () - { - if (this instanceof Window - && ((Container) this).isFocusCycleRoot ()) - return (Container) this; - - Container parent = getParent (); - - while (parent != null - && !parent.isFocusCycleRoot ()) - parent = parent.getParent (); - - return parent; - } - - /** - * Tests if the container is the ancestor of the focus cycle that - * this component belongs to. - * - * @param c the container to test - * @return true if c is the focus cycle root - * @since 1.4 - */ - public boolean isFocusCycleRoot (Container c) - { - return c == getFocusCycleRootAncestor (); - } - - /** - * AWT 1.0 focus event processor. Transfers focus to the next - * component in the focus traversal order, as though this were the - * current focus owner. - * - * @deprecated use {@link #transferFocus ()} instead - */ - public void nextFocus () - { - KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager (); - - manager.focusNextComponent (this); - } - - /** - * Transfers focus to the previous component in the focus traversal - * order, as though this were the current focus owner. - * - * @see #requestFocus () - * @since 1.4 - */ - public void transferFocusBackward () - { - KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager (); - - manager.focusPreviousComponent (this); - } - - /** - * Transfers focus to the focus cycle root of this component. - * However, if this is a Window, the default focus owner in the - * window in the current focus cycle is focused instead. - * - * @see #requestFocus() - * @see #isFocusCycleRoot(Container) - * @since 1.4 - */ - public void transferFocusUpCycle () - { - KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager (); - - manager.upFocusCycle (this); - } - - /** - * Tests if this component is the focus owner. Use {@link - * #isFocusOwner ()} instead. - * - * @return true if this component owns focus - * @since 1.2 - */ - public boolean hasFocus () - { - KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager (); - - Component focusOwner = manager.getFocusOwner (); - - return this == focusOwner; - } - - /** - * Tests if this component is the focus owner. - * - * @return true if this component owns focus - * @since 1.4 - */ - public boolean isFocusOwner() - { - return hasFocus (); - } - - /** - * Adds the specified popup menu to this component. - * - * @param popup the popup menu to be added - * - * @see #remove(MenuComponent) - * - * @since 1.1 - */ - public synchronized void add(PopupMenu popup) - { - if (popups == null) - popups = new Vector(); - popups.add(popup); - - if (popup.parent != null) - popup.parent.remove(popup); - popup.parent = this; - if (peer != null) - popup.addNotify(); - } - - /** - * Removes the specified popup menu from this component. - * - * @param popup the popup menu to remove - * @see #add(PopupMenu) - * @since 1.1 - */ - public synchronized void remove(MenuComponent popup) - { - if (popups != null) - popups.remove(popup); - } - - /** - * Returns a debugging string representing this component. The string may - * be empty but not null. - * - * @return a string representing this component - */ - protected String paramString() - { - StringBuffer param = new StringBuffer(); - String name = getName(); - if (name != null) - param.append(name).append(","); - param.append(x).append(",").append(y).append(",").append(width) - .append("x").append(height); - if (! isValid()) - param.append(",invalid"); - if (! isVisible()) - param.append(",invisible"); - if (! isEnabled()) - param.append(",disabled"); - if (! isOpaque()) - param.append(",translucent"); - if (isDoubleBuffered()) - param.append(",doublebuffered"); - return param.toString(); - } - - /** - * Returns a string representation of this component. This is implemented - * as <code>getClass().getName() + '[' + paramString() + ']'</code>. - * - * @return a string representation of this component - */ - public String toString() - { - return getClass().getName() + '[' + paramString() + ']'; - } - - /** - * Prints a listing of this component to <code>System.out</code>. - * - * @see #list(PrintStream) - */ - public void list() - { - list(System.out, 0); - } - - /** - * Prints a listing of this component to the specified print stream. - * - * @param out the <code>PrintStream</code> to print to - */ - public void list(PrintStream out) - { - list(out, 0); - } - - /** - * Prints a listing of this component to the specified print stream, - * starting at the specified indentation point. - * - * @param out the <code>PrintStream</code> to print to - * @param indent the indentation point - */ - public void list(PrintStream out, int indent) - { - for (int i = 0; i < indent; ++i) - out.print(' '); - out.println(toString()); - } - - /** - * Prints a listing of this component to the specified print writer. - * - * @param out the <code>PrintWrinter</code> to print to - * @since 1.1 - */ - public void list(PrintWriter out) - { - list(out, 0); - } - - /** - * Prints a listing of this component to the specified print writer, - * starting at the specified indentation point. - * - * @param out the <code>PrintWriter</code> to print to - * @param indent the indentation point - * @since 1.1 - */ - public void list(PrintWriter out, int indent) - { - for (int i = 0; i < indent; ++i) - out.print(' '); - out.println(toString()); - } - - /** - * Adds the specified property listener to this component. This is harmless - * if the listener is null, but if the listener has already been registered, - * it will now be registered twice. The property listener ignores inherited - * properties. Recognized properties include:<br> - * <ul> - * <li>the font (<code>"font"</code>)</li> - * <li>the background color (<code>"background"</code>)</li> - * <li>the foreground color (<code>"foreground"</code>)</li> - * <li>the focusability (<code>"focusable"</code>)</li> - * <li>the focus key traversal enabled state - * (<code>"focusTraversalKeysEnabled"</code>)</li> - * <li>the set of forward traversal keys - * (<code>"forwardFocusTraversalKeys"</code>)</li> - * <li>the set of backward traversal keys - * (<code>"backwardFocusTraversalKeys"</code>)</li> - * <li>the set of up-cycle traversal keys - * (<code>"upCycleFocusTraversalKeys"</code>)</li> - * </ul> - * - * @param listener the new listener to add - * @see #removePropertyChangeListener(PropertyChangeListener) - * @see #getPropertyChangeListeners() - * @see #addPropertyChangeListener(String, PropertyChangeListener) - * @since 1.1 - */ - public void addPropertyChangeListener(PropertyChangeListener listener) - { - if (changeSupport == null) - changeSupport = new PropertyChangeSupport(this); - changeSupport.addPropertyChangeListener(listener); - } - - /** - * Removes the specified property listener from the component. This is - * harmless if the listener was not previously registered. - * - * @param listener the listener to remove - * @see #addPropertyChangeListener(PropertyChangeListener) - * @see #getPropertyChangeListeners() - * @see #removePropertyChangeListener(String, PropertyChangeListener) - * @since 1.1 - */ - public void removePropertyChangeListener(PropertyChangeListener listener) - { - if (changeSupport != null) - changeSupport.removePropertyChangeListener(listener); - } - - /** - * Returns an array of all specified listeners registered on this component. - * - * @return an array of listeners - * @see #addPropertyChangeListener(PropertyChangeListener) - * @see #removePropertyChangeListener(PropertyChangeListener) - * @see #getPropertyChangeListeners(String) - * @since 1.4 - */ - public PropertyChangeListener[] getPropertyChangeListeners() - { - return changeSupport == null ? new PropertyChangeListener[0] - : changeSupport.getPropertyChangeListeners(); - } - - /** - * Adds the specified property listener to this component. This is harmless - * if the listener is null, but if the listener has already been registered, - * it will now be registered twice. The property listener ignores inherited - * properties. The listener is keyed to a single property. Recognized - * properties include:<br> - * <ul> - * <li>the font (<code>"font"</code>)</li> - * <li>the background color (<code>"background"</code>)</li> - * <li>the foreground color (<code>"foreground"</code>)</li> - * <li>the focusability (<code>"focusable"</code>)</li> - * <li>the focus key traversal enabled state - * (<code>"focusTraversalKeysEnabled"</code>)</li> - * <li>the set of forward traversal keys - * (<code>"forwardFocusTraversalKeys"</code>)</li> -p * <li>the set of backward traversal keys - * (<code>"backwardFocusTraversalKeys"</code>)</li> - * <li>the set of up-cycle traversal keys - * (<code>"upCycleFocusTraversalKeys"</code>)</li> - * </ul> - * - * @param propertyName the property name to filter on - * @param listener the new listener to add - * @see #removePropertyChangeListener(String, PropertyChangeListener) - * @see #getPropertyChangeListeners(String) - * @see #addPropertyChangeListener(PropertyChangeListener) - * @since 1.1 - */ - public void addPropertyChangeListener(String propertyName, - PropertyChangeListener listener) - { - if (changeSupport == null) - changeSupport = new PropertyChangeSupport(this); - changeSupport.addPropertyChangeListener(propertyName, listener); - } - - /** - * Removes the specified property listener on a particular property from - * the component. This is harmless if the listener was not previously - * registered. - * - * @param propertyName the property name to filter on - * @param listener the listener to remove - * @see #addPropertyChangeListener(String, PropertyChangeListener) - * @see #getPropertyChangeListeners(String) - * @see #removePropertyChangeListener(PropertyChangeListener) - * @since 1.1 - */ - public void removePropertyChangeListener(String propertyName, - PropertyChangeListener listener) - { - if (changeSupport != null) - changeSupport.removePropertyChangeListener(propertyName, listener); - } - - /** - * Returns an array of all specified listeners on the named property that - * are registered on this component. - * - * @return an array of listeners - * @see #addPropertyChangeListener(String, PropertyChangeListener) - * @see #removePropertyChangeListener(String, PropertyChangeListener) - * @see #getPropertyChangeListeners() - * @since 1.4 - */ - public PropertyChangeListener[] getPropertyChangeListeners(String property) - { - return changeSupport == null ? new PropertyChangeListener[0] - : changeSupport.getPropertyChangeListeners(property); - } - - /** - * Report a change in a bound property to any registered property listeners. - * - * @param propertyName the property that changed - * @param oldValue the old property value - * @param newValue the new property value - */ - protected void firePropertyChange(String propertyName, Object oldValue, - Object newValue) - { - if (changeSupport != null) - changeSupport.firePropertyChange(propertyName, oldValue, newValue); - } - - /** - * Report a change in a bound property to any registered property listeners. - * - * @param propertyName the property that changed - * @param oldValue the old property value - * @param newValue the new property value - */ - protected void firePropertyChange(String propertyName, boolean oldValue, - boolean newValue) - { - if (changeSupport != null) - changeSupport.firePropertyChange(propertyName, oldValue, newValue); - } - - /** - * Report a change in a bound property to any registered property listeners. - * - * @param propertyName the property that changed - * @param oldValue the old property value - * @param newValue the new property value - */ - protected void firePropertyChange(String propertyName, int oldValue, - int newValue) - { - if (changeSupport != null) - changeSupport.firePropertyChange(propertyName, oldValue, newValue); - } - - /** - * Sets the text layout orientation of this component. New components default - * to UNKNOWN (which behaves like LEFT_TO_RIGHT). This method affects only - * the current component, while - * {@link #applyComponentOrientation(ComponentOrientation)} affects the - * entire hierarchy. - * - * @param o the new orientation - * @throws NullPointerException if o is null - * @see #getComponentOrientation() - */ - public void setComponentOrientation(ComponentOrientation o) - { - if (o == null) - throw new NullPointerException(); - ComponentOrientation oldOrientation = orientation; - orientation = o; - firePropertyChange("componentOrientation", oldOrientation, o); - } - - /** - * Determines the text layout orientation used by this component. - * - * @return the component orientation - * @see #setComponentOrientation(ComponentOrientation) - */ - public ComponentOrientation getComponentOrientation() - { - return orientation; - } - - /** - * Sets the text layout orientation of this component. New components default - * to UNKNOWN (which behaves like LEFT_TO_RIGHT). This method affects the - * entire hierarchy, while - * {@link #setComponentOrientation(ComponentOrientation)} affects only the - * current component. - * - * @param o the new orientation - * @throws NullPointerException if o is null - * @see #getComponentOrientation() - * @since 1.4 - */ - public void applyComponentOrientation(ComponentOrientation o) - { - setComponentOrientation(o); - } - - /** - * Returns the accessibility framework context of this class. Component is - * not accessible, so the default implementation returns null. Subclasses - * must override this behavior, and return an appropriate subclass of - * {@link AccessibleAWTComponent}. - * - * @return the accessibility context - */ - public AccessibleContext getAccessibleContext() - { - return null; - } - - - // Helper methods; some are package visible for use by subclasses. - - /** - * Subclasses should override this to return unique component names like - * "menuitem0". - * - * @return the generated name for this component - */ - String generateName() - { - // Component is abstract. - return null; - } - - /** - * Sets the peer for this component. - * - * @param peer the new peer - */ - final void setPeer(ComponentPeer peer) - { - this.peer = peer; - } - - /** - * Implementation method that allows classes such as Canvas and Window to - * override the graphics configuration without violating the published API. - * - * @return the graphics configuration - */ - GraphicsConfiguration getGraphicsConfigurationImpl() - { - if (peer != null) - { - GraphicsConfiguration config = peer.getGraphicsConfiguration(); - if (config != null) - return config; - } - - if (parent != null) - return parent.getGraphicsConfiguration(); - - return null; - } - - /** - * Translate an AWT 1.1 event ({@link AWTEvent}) into an AWT 1.0 - * event ({@link Event}). - * - * @param e an AWT 1.1 event to translate - * - * @return an AWT 1.0 event representing e - */ - static Event translateEvent (AWTEvent e) - { - Component target = (Component) e.getSource (); - Event translated = null; - - if (e instanceof InputEvent) - { - InputEvent ie = (InputEvent) e; - long when = ie.getWhen (); - - int oldID = 0; - int id = e.getID (); - - int oldMods = 0; - int mods = ie.getModifiersEx (); - - if ((mods & InputEvent.BUTTON2_DOWN_MASK) != 0) - oldMods |= Event.META_MASK; - else if ((mods & InputEvent.BUTTON3_DOWN_MASK) != 0) - oldMods |= Event.ALT_MASK; - - if ((mods & InputEvent.SHIFT_DOWN_MASK) != 0) - oldMods |= Event.SHIFT_MASK; - - if ((mods & InputEvent.CTRL_DOWN_MASK) != 0) - oldMods |= Event.CTRL_MASK; - - if ((mods & InputEvent.META_DOWN_MASK) != 0) - oldMods |= Event.META_MASK; - - if ((mods & InputEvent.ALT_DOWN_MASK) != 0) - oldMods |= Event.ALT_MASK; - - if (e instanceof MouseEvent) - { - if (id == MouseEvent.MOUSE_PRESSED) - oldID = Event.MOUSE_DOWN; - else if (id == MouseEvent.MOUSE_RELEASED) - oldID = Event.MOUSE_UP; - else if (id == MouseEvent.MOUSE_MOVED) - oldID = Event.MOUSE_MOVE; - else if (id == MouseEvent.MOUSE_DRAGGED) - oldID = Event.MOUSE_DRAG; - else if (id == MouseEvent.MOUSE_ENTERED) - oldID = Event.MOUSE_ENTER; - else if (id == MouseEvent.MOUSE_EXITED) - oldID = Event.MOUSE_EXIT; - else - // No analogous AWT 1.0 mouse event. - return null; - - MouseEvent me = (MouseEvent) e; - - translated = new Event (target, when, oldID, - me.getX (), me.getY (), 0, oldMods); - } - else if (e instanceof KeyEvent) - { - if (id == KeyEvent.KEY_PRESSED) - oldID = Event.KEY_PRESS; - else if (e.getID () == KeyEvent.KEY_RELEASED) - oldID = Event.KEY_RELEASE; - else - // No analogous AWT 1.0 key event. - return null; - - int oldKey = 0; - int newKey = ((KeyEvent) e).getKeyCode (); - switch (newKey) - { - case KeyEvent.VK_BACK_SPACE: - oldKey = Event.BACK_SPACE; - break; - case KeyEvent.VK_CAPS_LOCK: - oldKey = Event.CAPS_LOCK; - break; - case KeyEvent.VK_DELETE: - oldKey = Event.DELETE; - break; - case KeyEvent.VK_DOWN: - case KeyEvent.VK_KP_DOWN: - oldKey = Event.DOWN; - break; - case KeyEvent.VK_END: - oldKey = Event.END; - break; - case KeyEvent.VK_ENTER: - oldKey = Event.ENTER; - break; - case KeyEvent.VK_ESCAPE: - oldKey = Event.ESCAPE; - break; - case KeyEvent.VK_F1: - oldKey = Event.F1; - break; - case KeyEvent.VK_F10: - oldKey = Event.F10; - break; - case KeyEvent.VK_F11: - oldKey = Event.F11; - break; - case KeyEvent.VK_F12: - oldKey = Event.F12; - break; - case KeyEvent.VK_F2: - oldKey = Event.F2; - break; - case KeyEvent.VK_F3: - oldKey = Event.F3; - break; - case KeyEvent.VK_F4: - oldKey = Event.F4; - break; - case KeyEvent.VK_F5: - oldKey = Event.F5; - break; - case KeyEvent.VK_F6: - oldKey = Event.F6; - break; - case KeyEvent.VK_F7: - oldKey = Event.F7; - break; - case KeyEvent.VK_F8: - oldKey = Event.F8; - break; - case KeyEvent.VK_F9: - oldKey = Event.F9; - break; - case KeyEvent.VK_HOME: - oldKey = Event.HOME; - break; - case KeyEvent.VK_INSERT: - oldKey = Event.INSERT; - break; - case KeyEvent.VK_LEFT: - case KeyEvent.VK_KP_LEFT: - oldKey = Event.LEFT; - break; - case KeyEvent.VK_NUM_LOCK: - oldKey = Event.NUM_LOCK; - break; - case KeyEvent.VK_PAUSE: - oldKey = Event.PAUSE; - break; - case KeyEvent.VK_PAGE_DOWN: - oldKey = Event.PGDN; - break; - case KeyEvent.VK_PAGE_UP: - oldKey = Event.PGUP; - break; - case KeyEvent.VK_PRINTSCREEN: - oldKey = Event.PRINT_SCREEN; - break; - case KeyEvent.VK_RIGHT: - case KeyEvent.VK_KP_RIGHT: - oldKey = Event.RIGHT; - break; - case KeyEvent.VK_SCROLL_LOCK: - oldKey = Event.SCROLL_LOCK; - break; - case KeyEvent.VK_TAB: - oldKey = Event.TAB; - break; - case KeyEvent.VK_UP: - case KeyEvent.VK_KP_UP: - oldKey = Event.UP; - break; - default: - oldKey = newKey; - } - - translated = new Event (target, when, oldID, - 0, 0, oldKey, oldMods); - } - } - else if (e instanceof ActionEvent) - translated = new Event (target, Event.ACTION_EVENT, - ((ActionEvent) e).getActionCommand ()); - - return translated; - } - - /** - * Implementation of dispatchEvent. Allows trusted package classes - * to dispatch additional events first. This implementation first - * translates <code>e</code> to an AWT 1.0 event and sends the - * result to {@link #postEvent}. If the AWT 1.0 event is not - * handled, and events of type <code>e</code> are enabled for this - * component, e is passed on to {@link #processEvent}. - * - * @param e the event to dispatch - */ - - void dispatchEventImpl (AWTEvent e) - { - Event oldEvent = translateEvent (e); - - if (oldEvent != null) - postEvent (oldEvent); - - if (eventTypeEnabled (e.id)) - { - // the trick we use to communicate between dispatch and redispatch - // is to have KeyboardFocusManager.redispatch synchronize on the - // object itself. we then do not redispatch to KeyboardFocusManager - // if we are already holding the lock. - if (! Thread.holdsLock(e)) - { - switch (e.id) - { - case WindowEvent.WINDOW_GAINED_FOCUS: - case WindowEvent.WINDOW_LOST_FOCUS: - case KeyEvent.KEY_PRESSED: - case KeyEvent.KEY_RELEASED: - case KeyEvent.KEY_TYPED: - case FocusEvent.FOCUS_GAINED: - case FocusEvent.FOCUS_LOST: - if (KeyboardFocusManager - .getCurrentKeyboardFocusManager() - .dispatchEvent(e)) - return; - } - } - processEvent (e); - } - } - - /** - * Tells whether or not an event type is enabled. - */ - boolean eventTypeEnabled (int type) - { - if (type > AWTEvent.RESERVED_ID_MAX) - return true; - - switch (type) - { - case ComponentEvent.COMPONENT_HIDDEN: - case ComponentEvent.COMPONENT_MOVED: - case ComponentEvent.COMPONENT_RESIZED: - case ComponentEvent.COMPONENT_SHOWN: - return (componentListener != null - || (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0); - - case KeyEvent.KEY_PRESSED: - case KeyEvent.KEY_RELEASED: - case KeyEvent.KEY_TYPED: - return (keyListener != null - || (eventMask & AWTEvent.KEY_EVENT_MASK) != 0); - - case MouseEvent.MOUSE_CLICKED: - case MouseEvent.MOUSE_ENTERED: - case MouseEvent.MOUSE_EXITED: - case MouseEvent.MOUSE_PRESSED: - case MouseEvent.MOUSE_RELEASED: - case MouseEvent.MOUSE_MOVED: - case MouseEvent.MOUSE_DRAGGED: - return (mouseListener != null - || mouseMotionListener != null - || (eventMask & AWTEvent.MOUSE_EVENT_MASK) != 0); - - case FocusEvent.FOCUS_GAINED: - case FocusEvent.FOCUS_LOST: - return (focusListener != null - || (eventMask & AWTEvent.FOCUS_EVENT_MASK) != 0); - - case InputMethodEvent.INPUT_METHOD_TEXT_CHANGED: - case InputMethodEvent.CARET_POSITION_CHANGED: - return (inputMethodListener != null - || (eventMask & AWTEvent.INPUT_METHOD_EVENT_MASK) != 0); - - case PaintEvent.PAINT: - case PaintEvent.UPDATE: - return (eventMask & AWTEvent.PAINT_EVENT_MASK) != 0; - - default: - return false; - } - } - - /** - * Coalesce paint events. Current heuristic is: Merge if the union of - * areas is less than twice that of the sum of the areas. The X server - * tend to create a lot of paint events that are adjacent but not - * overlapping. - * - * <pre> - * +------+ - * | +-----+ ...will be merged - * | | | - * | | | - * +------+ | - * +-----+ - * - * +---------------+--+ - * | | | ...will not be merged - * +---------------+ | - * | | - * | | - * | | - * | | - * | | - * +--+ - * </pre> - * - * @param queuedEvent the first paint event - * @param newEvent the second paint event - * @return the combined paint event, or null - */ - private PaintEvent coalescePaintEvents(PaintEvent queuedEvent, - PaintEvent newEvent) - { - Rectangle r1 = queuedEvent.getUpdateRect(); - Rectangle r2 = newEvent.getUpdateRect(); - Rectangle union = r1.union(r2); - - int r1a = r1.width * r1.height; - int r2a = r2.width * r2.height; - int ua = union.width * union.height; - - if (ua > (r1a+r2a)*2) - return null; - /* The 2 factor should maybe be reconsidered. Perhaps 3/2 - would be better? */ - - newEvent.setUpdateRect(union); - return newEvent; - } - - /** - * This method is used to implement transferFocus(). CHILD is the child - * making the request. This is overridden by Container; when called for an - * ordinary component there is no child and so we always return null. - * - * FIXME: is this still needed, in light of focus traversal policies? - * - * @param child the component making the request - * @return the next component to focus on - */ - Component findNextFocusComponent(Component child) - { - return null; - } - - /** - * Deserializes this component. This regenerates all serializable listeners - * which were registered originally. - * - * @param s the stream to read from - * @throws ClassNotFoundException if deserialization fails - * @throws IOException if the stream fails - */ - private void readObject(ObjectInputStream s) - throws ClassNotFoundException, IOException - { - s.defaultReadObject(); - String key = (String) s.readObject(); - while (key != null) - { - Object listener = s.readObject(); - if ("componentL".equals(key)) - addComponentListener((ComponentListener) listener); - else if ("focusL".equals(key)) - addFocusListener((FocusListener) listener); - else if ("keyL".equals(key)) - addKeyListener((KeyListener) listener); - else if ("mouseL".equals(key)) - addMouseListener((MouseListener) listener); - else if ("mouseMotionL".equals(key)) - addMouseMotionListener((MouseMotionListener) listener); - else if ("inputMethodL".equals(key)) - addInputMethodListener((InputMethodListener) listener); - else if ("hierarchyL".equals(key)) - addHierarchyListener((HierarchyListener) listener); - else if ("hierarchyBoundsL".equals(key)) - addHierarchyBoundsListener((HierarchyBoundsListener) listener); - else if ("mouseWheelL".equals(key)) - addMouseWheelListener((MouseWheelListener) listener); - key = (String) s.readObject(); - } - } - - /** - * Serializes this component. This ignores all listeners which do not - * implement Serializable, but includes those that do. - * - * @param s the stream to write to - * @throws IOException if the stream fails - */ - private void writeObject(ObjectOutputStream s) throws IOException - { - s.defaultWriteObject(); - AWTEventMulticaster.save(s, "componentL", componentListener); - AWTEventMulticaster.save(s, "focusL", focusListener); - AWTEventMulticaster.save(s, "keyL", keyListener); - AWTEventMulticaster.save(s, "mouseL", mouseListener); - AWTEventMulticaster.save(s, "mouseMotionL", mouseMotionListener); - AWTEventMulticaster.save(s, "inputMethodL", inputMethodListener); - AWTEventMulticaster.save(s, "hierarchyL", hierarchyListener); - AWTEventMulticaster.save(s, "hierarchyBoundsL", hierarchyBoundsListener); - AWTEventMulticaster.save(s, "mouseWheelL", mouseWheelListener); - s.writeObject(null); - } - - - // Nested classes. - - /** - * This class provides accessibility support for subclasses of container. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.3 - * @status updated to 1.4 - */ - protected abstract class AccessibleAWTComponent extends AccessibleContext - implements Serializable, AccessibleComponent - { - /** - * Compatible with JDK 1.3+. - */ - private static final long serialVersionUID = 642321655757800191L; - - /** - * Converts show/hide events to PropertyChange events, and is registered - * as a component listener on this component. - * - * @serial the component handler - */ - protected ComponentListener accessibleAWTComponentHandler - = new AccessibleAWTComponentHandler(); - - /** - * Converts focus events to PropertyChange events, and is registered - * as a focus listener on this component. - * - * @serial the focus handler - */ - protected FocusListener accessibleAWTFocusHandler - = new AccessibleAWTFocusHandler(); - - /** - * The default constructor. - */ - protected AccessibleAWTComponent() - { - Component.this.addComponentListener(accessibleAWTComponentHandler); - Component.this.addFocusListener(accessibleAWTFocusHandler); - } - - /** - * Adds a global property change listener to the accessible component. - * - * @param l the listener to add - * @see #ACCESSIBLE_NAME_PROPERTY - * @see #ACCESSIBLE_DESCRIPTION_PROPERTY - * @see #ACCESSIBLE_STATE_PROPERTY - * @see #ACCESSIBLE_VALUE_PROPERTY - * @see #ACCESSIBLE_SELECTION_PROPERTY - * @see #ACCESSIBLE_TEXT_PROPERTY - * @see #ACCESSIBLE_VISIBLE_DATA_PROPERTY - */ - public void addPropertyChangeListener(PropertyChangeListener l) - { - Component.this.addPropertyChangeListener(l); - super.addPropertyChangeListener(l); - } - - /** - * Removes a global property change listener from this accessible - * component. - * - * @param l the listener to remove - */ - public void removePropertyChangeListener(PropertyChangeListener l) - { - Component.this.removePropertyChangeListener(l); - super.removePropertyChangeListener(l); - } - - /** - * Returns the accessible name of this component. It is almost always - * wrong to return getName(), since it is not localized. In fact, for - * things like buttons, this should be the text of the button, not the - * name of the object. The tooltip text might also be appropriate. - * - * @return the name - * @see #setAccessibleName(String) - */ - public String getAccessibleName() - { - return accessibleName == null ? getName() : accessibleName; - } - - /** - * Returns a brief description of this accessible context. This should - * be localized. - * - * @return a description of this component - * @see #setAccessibleDescription(String) - */ - public String getAccessibleDescription() - { - return accessibleDescription; - } - - /** - * Returns the role of this component. - * - * @return the accessible role - */ - public AccessibleRole getAccessibleRole() - { - return AccessibleRole.AWT_COMPONENT; - } - - /** - * Returns a state set describing this component's state. - * - * @return a new state set - * @see AccessibleState - */ - public AccessibleStateSet getAccessibleStateSet() - { - AccessibleStateSet s = new AccessibleStateSet(); - if (Component.this.isEnabled()) - s.add(AccessibleState.ENABLED); - if (isFocusable()) - s.add(AccessibleState.FOCUSABLE); - if (isFocusOwner()) - s.add(AccessibleState.FOCUSED); - if (isOpaque()) - s.add(AccessibleState.OPAQUE); - if (Component.this.isShowing()) - s.add(AccessibleState.SHOWING); - if (Component.this.isVisible()) - s.add(AccessibleState.VISIBLE); - return s; - } - - /** - * Returns the parent of this component, if it is accessible. - * - * @return the accessible parent - */ - public Accessible getAccessibleParent() - { - if (accessibleParent == null) - { - Container parent = getParent(); - accessibleParent = parent instanceof Accessible - ? (Accessible) parent : null; - } - return accessibleParent; - } - - /** - * Returns the index of this component in its accessible parent. - * - * @return the index, or -1 if the parent is not accessible - * @see #getAccessibleParent() - */ - public int getAccessibleIndexInParent() - { - if (getAccessibleParent() == null) - return -1; - AccessibleContext context - = ((Component) accessibleParent).getAccessibleContext(); - if (context == null) - return -1; - for (int i = context.getAccessibleChildrenCount(); --i >= 0; ) - if (context.getAccessibleChild(i) == Component.this) - return i; - return -1; - } - - /** - * Returns the number of children of this component which implement - * Accessible. Subclasses must override this if they can have children. - * - * @return the number of accessible children, default 0 - */ - public int getAccessibleChildrenCount() - { - return 0; - } - - /** - * Returns the ith accessible child. Subclasses must override this if - * they can have children. - * - * @return the ith accessible child, or null - * @see #getAccessibleChildrenCount() - */ - public Accessible getAccessibleChild(int i) - { - return null; - } - - /** - * Returns the locale of this component. - * - * @return the locale - * @throws IllegalComponentStateException if the locale is unknown - */ - public Locale getLocale() - { - return Component.this.getLocale(); - } - - /** - * Returns this, since it is an accessible component. - * - * @return the accessible component - */ - public AccessibleComponent getAccessibleComponent() - { - return this; - } - - /** - * Gets the background color. - * - * @return the background color - * @see #setBackground(Color) - */ - public Color getBackground() - { - return Component.this.getBackground(); - } - - /** - * Sets the background color. - * - * @param c the background color - * @see #getBackground() - * @see #isOpaque() - */ - public void setBackground(Color c) - { - Component.this.setBackground(c); - } - - /** - * Gets the foreground color. - * - * @return the foreground color - * @see #setForeground(Color) - */ - public Color getForeground() - { - return Component.this.getForeground(); - } - - /** - * Sets the foreground color. - * - * @param c the foreground color - * @see #getForeground() - */ - public void setForeground(Color c) - { - Component.this.setForeground(c); - } - - /** - * Gets the cursor. - * - * @return the cursor - * @see #setCursor(Cursor) - */ - public Cursor getCursor() - { - return Component.this.getCursor(); - } - - /** - * Sets the cursor. - * - * @param cursor the cursor - * @see #getCursor() - */ - public void setCursor(Cursor cursor) - { - Component.this.setCursor(cursor); - } - - /** - * Gets the font. - * - * @return the font - * @see #setFont(Font) - */ - public Font getFont() - { - return Component.this.getFont(); - } - - /** - * Sets the font. - * - * @param f the font - * @see #getFont() - */ - public void setFont(Font f) - { - Component.this.setFont(f); - } - - /** - * Gets the font metrics for a font. - * - * @param f the font to look up - * @return its metrics - * @throws NullPointerException if f is null - * @see #getFont() - */ - public FontMetrics getFontMetrics(Font f) - { - return Component.this.getFontMetrics(f); - } - - /** - * Tests if the component is enabled. - * - * @return true if the component is enabled - * @see #setEnabled(boolean) - * @see #getAccessibleStateSet() - * @see AccessibleState#ENABLED - */ - public boolean isEnabled() - { - return Component.this.isEnabled(); - } - - /** - * Set whether the component is enabled. - * - * @param b the new enabled status - * @see #isEnabled() - */ - public void setEnabled(boolean b) - { - Component.this.setEnabled(b); - } - - /** - * Test whether the component is visible (not necesarily showing). - * - * @return true if it is visible - * @see #setVisible(boolean) - * @see #getAccessibleStateSet() - * @see AccessibleState#VISIBLE - */ - public boolean isVisible() - { - return Component.this.isVisible(); - } - - /** - * Sets the visibility of this component. - * - * @param b the desired visibility - * @see #isVisible() - */ - public void setVisible(boolean b) - { - Component.this.setVisible(b); - } - - /** - * Tests if the component is showing. - * - * @return true if this is showing - */ - public boolean isShowing() - { - return Component.this.isShowing(); - } - - /** - * Tests if the point is contained in this component. - * - * @param p the point to check - * @return true if it is contained - * @throws NullPointerException if p is null - */ - public boolean contains(Point p) - { - return Component.this.contains(p.x, p.y); - } - - /** - * Returns the location of this object on the screen, or null if it is - * not showing. - * - * @return the location relative to screen coordinates, if showing - * @see #getBounds() - * @see #getLocation() - */ - public Point getLocationOnScreen() - { - return Component.this.isShowing() ? Component.this.getLocationOnScreen() - : null; - } - - /** - * Returns the location of this object relative to its parent's coordinate - * system, or null if it is not showing. - * - * @return the location - * @see #getBounds() - * @see #getLocationOnScreen() - */ - public Point getLocation() - { - return Component.this.isShowing() ? Component.this.getLocation() : null; - } - - /** - * Sets the location of this relative to its parent's coordinate system. - * - * @param p the location - * @throws NullPointerException if p is null - * @see #getLocation() - */ - public void setLocation(Point p) - { - Component.this.setLocation(p.x, p.y); - } - - /** - * Gets the bounds of this component, or null if it is not on screen. - * - * @return the bounds - * @see #contains(Point) - * @see #setBounds(Rectangle) - */ - public Rectangle getBounds() - { - return Component.this.isShowing() ? Component.this.getBounds() : null; - } - - /** - * Sets the bounds of this component. - * - * @param r the bounds - * @throws NullPointerException if r is null - * @see #getBounds() - */ - public void setBounds(Rectangle r) - { - Component.this.setBounds(r.x, r.y, r.width, r.height); - } - - /** - * Gets the size of this component, or null if it is not showing. - * - * @return the size - * @see #setSize(Dimension) - */ - public Dimension getSize() - { - return Component.this.isShowing() ? Component.this.getSize() : null; - } - - /** - * Sets the size of this component. - * - * @param d the size - * @throws NullPointerException if d is null - * @see #getSize() - */ - public void setSize(Dimension d) - { - Component.this.setSize(d.width, d.height); - } - - /** - * Returns the Accessible child at a point relative to the coordinate - * system of this component, if one exists, or null. Since components - * have no children, subclasses must override this to get anything besides - * null. - * - * @param p the point to check - * @return the accessible child at that point - * @throws NullPointerException if p is null - */ - public Accessible getAccessibleAt(Point p) - { - return null; - } - - /** - * Tests whether this component can accept focus. - * - * @return true if this is focus traversable - * @see #getAccessibleStateSet () - * @see AccessibleState#FOCUSABLE - * @see AccessibleState#FOCUSED - */ - public boolean isFocusTraversable () - { - return Component.this.isFocusTraversable (); - } - - /** - * Requests focus for this component. - * - * @see #isFocusTraversable () - */ - public void requestFocus () - { - Component.this.requestFocus (); - } - - /** - * Adds a focus listener. - * - * @param l the listener to add - */ - public void addFocusListener(FocusListener l) - { - Component.this.addFocusListener(l); - } - - /** - * Removes a focus listener. - * - * @param l the listener to remove - */ - public void removeFocusListener(FocusListener l) - { - Component.this.removeFocusListener(l); - } - - /** - * Converts component changes into property changes. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.3 - * @status updated to 1.4 - */ - protected class AccessibleAWTComponentHandler implements ComponentListener - { - /** - * Default constructor. - */ - protected AccessibleAWTComponentHandler() - { - } - - /** - * Convert a component hidden to a property change. - * - * @param e the event to convert - */ - public void componentHidden(ComponentEvent e) - { - AccessibleAWTComponent.this.firePropertyChange - (ACCESSIBLE_STATE_PROPERTY, AccessibleState.VISIBLE, null); - } - - /** - * Convert a component shown to a property change. - * - * @param e the event to convert - */ - public void componentShown(ComponentEvent e) - { - AccessibleAWTComponent.this.firePropertyChange - (ACCESSIBLE_STATE_PROPERTY, null, AccessibleState.VISIBLE); - } - - /** - * Moving a component does not affect properties. - * - * @param e ignored - */ - public void componentMoved(ComponentEvent e) - { - } - - /** - * Resizing a component does not affect properties. - * - * @param e ignored - */ - public void componentResized(ComponentEvent e) - { - } - } // class AccessibleAWTComponentHandler - - /** - * Converts focus changes into property changes. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.3 - * @status updated to 1.4 - */ - protected class AccessibleAWTFocusHandler implements FocusListener - { - /** - * Default constructor. - */ - protected AccessibleAWTFocusHandler() - { - } - - /** - * Convert a focus gained to a property change. - * - * @param e the event to convert - */ - public void focusGained(FocusEvent e) - { - AccessibleAWTComponent.this.firePropertyChange - (ACCESSIBLE_STATE_PROPERTY, null, AccessibleState.FOCUSED); - } - - /** - * Convert a focus lost to a property change. - * - * @param e the event to convert - */ - public void focusLost(FocusEvent e) - { - AccessibleAWTComponent.this.firePropertyChange - (ACCESSIBLE_STATE_PROPERTY, AccessibleState.FOCUSED, null); - } - } // class AccessibleAWTComponentHandler - } // class AccessibleAWTComponent - - /** - * This class provides support for blitting offscreen surfaces to a - * component. - * - * @see BufferStrategy - * - * @since 1.4 - */ - protected class BltBufferStrategy extends BufferStrategy - { - /** - * The capabilities of the image buffer. - */ - protected BufferCapabilities caps; - - /** - * The back buffers used in this strategy. - */ - protected VolatileImage[] backBuffers; - - /** - * Whether or not the image buffer resources are allocated and - * ready to be drawn into. - */ - protected boolean validatedContents; - - /** - * The width of the back buffers. - */ - protected int width; - - /** - * The height of the back buffers. - */ - protected int height; - - /** - * The front buffer. - */ - private VolatileImage frontBuffer; - - /** - * Creates a blitting buffer strategy. - * - * @param numBuffers the number of buffers, including the front - * buffer - * @param caps the capabilities of this strategy - */ - protected BltBufferStrategy(int numBuffers, BufferCapabilities caps) - { - this.caps = caps; - createBackBuffers(numBuffers - 1); - width = getWidth(); - height = getHeight(); - } - - /** - * Initializes the backBuffers field with an array of numBuffers - * VolatileImages. - * - * @param numBuffers the number of backbuffers to create - */ - protected void createBackBuffers(int numBuffers) - { - GraphicsConfiguration c = - GraphicsEnvironment.getLocalGraphicsEnvironment() - .getDefaultScreenDevice().getDefaultConfiguration(); - - backBuffers = new VolatileImage[numBuffers]; - - for (int i = 0; i < numBuffers; i++) - backBuffers[i] = c.createCompatibleVolatileImage(width, height); - } - - /** - * Retrieves the capabilities of this buffer strategy. - * - * @return the capabilities of this buffer strategy - */ - public BufferCapabilities getCapabilities() - { - return caps; - } - - /** - * Retrieves a graphics object that can be used to draw into this - * strategy's image buffer. - * - * @return a graphics object - */ - public Graphics getDrawGraphics() - { - // Return the backmost buffer's graphics. - return backBuffers[0].getGraphics(); - } - - /** - * Bring the contents of the back buffer to the front buffer. - */ - public void show() - { - GraphicsConfiguration c = - GraphicsEnvironment.getLocalGraphicsEnvironment() - .getDefaultScreenDevice().getDefaultConfiguration(); - - // draw the front buffer. - getGraphics().drawImage(backBuffers[backBuffers.length - 1], - width, height, null); - - BufferCapabilities.FlipContents f = getCapabilities().getFlipContents(); - - // blit the back buffers. - for (int i = backBuffers.length - 1; i > 0 ; i--) - backBuffers[i] = backBuffers[i - 1]; - - // create new backmost buffer. - if (f == BufferCapabilities.FlipContents.UNDEFINED) - backBuffers[0] = c.createCompatibleVolatileImage(width, height); - - // create new backmost buffer and clear it to the background - // color. - if (f == BufferCapabilities.FlipContents.BACKGROUND) - { - backBuffers[0] = c.createCompatibleVolatileImage(width, height); - backBuffers[0].getGraphics().clearRect(0, 0, width, height); - } - - // FIXME: set the backmost buffer to the prior contents of the - // front buffer. How do we retrieve the contents of the front - // buffer? - // - // if (f == BufferCapabilities.FlipContents.PRIOR) - - // set the backmost buffer to a copy of the new front buffer. - if (f == BufferCapabilities.FlipContents.COPIED) - backBuffers[0] = backBuffers[backBuffers.length - 1]; - } - - /** - * Re-create the image buffer resources if they've been lost. - */ - protected void revalidate() - { - GraphicsConfiguration c = - GraphicsEnvironment.getLocalGraphicsEnvironment() - .getDefaultScreenDevice().getDefaultConfiguration(); - - for (int i = 0; i < backBuffers.length; i++) - { - int result = backBuffers[i].validate(c); - if (result == VolatileImage.IMAGE_INCOMPATIBLE) - backBuffers[i] = c.createCompatibleVolatileImage(width, height); - } - validatedContents = true; - } - - /** - * Returns whether or not the image buffer resources have been - * lost. - * - * @return true if the resources have been lost, false otherwise - */ - public boolean contentsLost() - { - for (int i = 0; i < backBuffers.length; i++) - { - if (backBuffers[i].contentsLost()) - { - validatedContents = false; - return true; - } - } - // we know that the buffer resources are valid now because we - // just checked them - validatedContents = true; - return false; - } - - /** - * Returns whether or not the image buffer resources have been - * restored. - * - * @return true if the resources have been restored, false - * otherwise - */ - public boolean contentsRestored() - { - GraphicsConfiguration c = - GraphicsEnvironment.getLocalGraphicsEnvironment() - .getDefaultScreenDevice().getDefaultConfiguration(); - - boolean imageRestored = false; - - for (int i = 0; i < backBuffers.length; i++) - { - int result = backBuffers[i].validate(c); - if (result == VolatileImage.IMAGE_RESTORED) - imageRestored = true; - else if (result == VolatileImage.IMAGE_INCOMPATIBLE) - return false; - } - // we know that the buffer resources are valid now because we - // just checked them - validatedContents = true; - return imageRestored; - } - } - - /** - * This class provides support for flipping component buffers. It - * can only be used on Canvases and Windows. - * - * @since 1.4 - */ - protected class FlipBufferStrategy extends BufferStrategy - { - /** - * The number of buffers. - */ - protected int numBuffers; - - /** - * The capabilities of this buffering strategy. - */ - protected BufferCapabilities caps; - - /** - * An Image reference to the drawing buffer. - */ - protected Image drawBuffer; - - /** - * A VolatileImage reference to the drawing buffer. - */ - protected VolatileImage drawVBuffer; - - /** - * Whether or not the image buffer resources are allocated and - * ready to be drawn into. - */ - protected boolean validatedContents; - - /** - * The width of the back buffer. - */ - private int width; - - /** - * The height of the back buffer. - */ - private int height; - - /** - * Creates a flipping buffer strategy. The only supported - * strategy for FlipBufferStrategy itself is a double-buffer page - * flipping strategy. It forms the basis for more complex derived - * strategies. - * - * @param numBuffers the number of buffers - * @param caps the capabilities of this buffering strategy - * - * @throws AWTException if the requested - * number-of-buffers/capabilities combination is not supported - */ - protected FlipBufferStrategy(int numBuffers, BufferCapabilities caps) - throws AWTException - { - this.caps = caps; - width = getWidth(); - height = getHeight(); - - if (numBuffers > 1) - createBuffers(numBuffers, caps); - else - { - drawVBuffer = peer.createVolatileImage(width, height); - drawBuffer = drawVBuffer; - } - } - - /** - * Creates a multi-buffer flipping strategy. The number of - * buffers must be greater than one and the buffer capabilities - * must specify page flipping. - * - * @param numBuffers the number of flipping buffers; must be - * greater than one - * @param caps the buffering capabilities; caps.isPageFlipping() - * must return true - * - * @throws IllegalArgumentException if numBuffers is not greater - * than one or if the page flipping capability is not requested - * - * @throws AWTException if the requested flipping strategy is not - * supported - */ - protected void createBuffers(int numBuffers, BufferCapabilities caps) - throws AWTException - { - if (numBuffers <= 1) - throw new IllegalArgumentException("FlipBufferStrategy.createBuffers:" - + " numBuffers must be greater than" - + " one."); - - if (!caps.isPageFlipping()) - throw new IllegalArgumentException("FlipBufferStrategy.createBuffers:" - + " flipping must be a specified" - + " capability."); - - peer.createBuffers(numBuffers, caps); - } - - /** - * Return a direct reference to the back buffer image. - * - * @return a direct reference to the back buffer image. - */ - protected Image getBackBuffer() - { - return peer.getBackBuffer(); - } - - /** - * Perform a flip operation to transfer the contents of the back - * buffer to the front buffer. - */ - protected void flip(BufferCapabilities.FlipContents flipAction) - { - peer.flip(flipAction); - } - - /** - * Release the back buffer's resources. - */ - protected void destroyBuffers() - { - peer.destroyBuffers(); - } - - /** - * Retrieves the capabilities of this buffer strategy. - * - * @return the capabilities of this buffer strategy - */ - public BufferCapabilities getCapabilities() - { - return caps; - } - - /** - * Retrieves a graphics object that can be used to draw into this - * strategy's image buffer. - * - * @return a graphics object - */ - public Graphics getDrawGraphics() - { - return drawVBuffer.getGraphics(); - } - - /** - * Re-create the image buffer resources if they've been lost. - */ - protected void revalidate() - { - GraphicsConfiguration c = - GraphicsEnvironment.getLocalGraphicsEnvironment() - .getDefaultScreenDevice().getDefaultConfiguration(); - - if (drawVBuffer.validate(c) == VolatileImage.IMAGE_INCOMPATIBLE) - drawVBuffer = peer.createVolatileImage(width, height); - validatedContents = true; - } - - /** - * Returns whether or not the image buffer resources have been - * lost. - * - * @return true if the resources have been lost, false otherwise - */ - public boolean contentsLost() - { - if (drawVBuffer.contentsLost()) - { - validatedContents = false; - return true; - } - // we know that the buffer resources are valid now because we - // just checked them - validatedContents = true; - return false; - } - - /** - * Returns whether or not the image buffer resources have been - * restored. - * - * @return true if the resources have been restored, false - * otherwise - */ - public boolean contentsRestored() - { - GraphicsConfiguration c = - GraphicsEnvironment.getLocalGraphicsEnvironment() - .getDefaultScreenDevice().getDefaultConfiguration(); - - int result = drawVBuffer.validate(c); - - boolean imageRestored = false; - - if (result == VolatileImage.IMAGE_RESTORED) - imageRestored = true; - else if (result == VolatileImage.IMAGE_INCOMPATIBLE) - return false; - - // we know that the buffer resources are valid now because we - // just checked them - validatedContents = true; - return imageRestored; - } - - /** - * Bring the contents of the back buffer to the front buffer. - */ - public void show() - { - flip(caps.getFlipContents()); - } - } -} diff --git a/libjava/java/awt/ComponentOrientation.java b/libjava/java/awt/ComponentOrientation.java deleted file mode 100644 index 69b14c7553f..00000000000 --- a/libjava/java/awt/ComponentOrientation.java +++ /dev/null @@ -1,215 +0,0 @@ -/* ComponentOrientation.java -- describes a component's orientation - Copyright (C) 2000, 2001, 2002 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.io.Serializable; -import java.util.Locale; -import java.util.MissingResourceException; -import java.util.ResourceBundle; - -/** - * This class is used to differentiate different orientations for text layout. - * It controls whether text flows left-to-right or right-to-left, and whether - * lines are horizontal or vertical, as in this table:<br> - * <pre> - * LT RT TL TR - * A B C C B A A D G G D A - * D E F F E D B E H H E B - * G H I I H G C F I I F C - * </pre> - * <b>LT</b> languages are most common (left-to-right lines, top-to-bottom). - * This includes Western European languages, and optionally includes Japanese, - * Chinese, and Korean. <b>RT</b> languages (right-to-left lines, - * top-to-bottom) are mainly middle eastern, such as Hebrew and Arabic. - * <b>TR</b> languages flow top-to-bottom in a line, right-to-left, and are - * the basis of Japanese, Chinese, and Korean. Finally, <b>TL</b> languages - * flow top-to-bottom in a line, left-to-right, as in Mongolian. - * - * <p>This is a pretty poor excuse for a type-safe enum, since it is not - * guaranteed that orientation objects are unique (thanks to serialization), - * yet there is no equals() method. You would be wise to compare the output - * of isHorizontal() and isLeftToRight() rather than comparing objects with - * ==, especially since more constants may be added in the future. - * - * @author Bryce McKinlay (bryce@albatross.co.nz) - * @since 1.0 - * @status updated to 1.4 - */ -public final class ComponentOrientation implements Serializable -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = -4113291392143563828L; - - /** Constant for unknown orientation. */ - private static final int UNKNOWN_ID = 1; - - /** Constant for horizontal line orientation. */ - private static final int HORIZONTAL_ID = 2; - - /** Constant for left-to-right orientation. */ - private static final int LEFT_TO_RIGHT_ID = 4; - - /** - * Items run left to right, and lines flow top to bottom. Examples: English, - * French. - */ - public static final ComponentOrientation LEFT_TO_RIGHT - = new ComponentOrientation(HORIZONTAL_ID | LEFT_TO_RIGHT_ID); - - /** - * Items run right to left, and lines flow top to bottom. Examples: Arabic, - * Hebrew. - */ - public static final ComponentOrientation RIGHT_TO_LEFT - = new ComponentOrientation(HORIZONTAL_ID); - - /** - * The orientation is unknown for the locale. For backwards compatibility, - * this behaves like LEFT_TO_RIGHT in the instance methods. - */ - public static final ComponentOrientation UNKNOWN - = new ComponentOrientation(UNKNOWN_ID | HORIZONTAL_ID | LEFT_TO_RIGHT_ID); - - /** - * The orientation of this object; bitwise-or of unknown (1), horizontal (2), - * and left-to-right (4). - * - * @serial the orientation - */ - private final int orientation; - - /** - * Construct a given orientation. - * - * @param orientation the orientation - */ - private ComponentOrientation(int orientation) - { - this.orientation = orientation; - } - - /** - * Returns true if the lines are horizontal, in which case lines flow - * top-to-bottom. For example, English, Hebrew. Counterexamples: Japanese, - * Chinese, Korean, Mongolian. - * - * @return true if this orientation has horizontal lines - */ - public boolean isHorizontal() - { - return (orientation & HORIZONTAL_ID) != 0; - } - - /** - * If isHorizontal() returns true, then this determines whether items in - * the line flow left-to-right. If isHorizontal() returns false, items in - * a line flow top-to-bottom, and this determines if lines flow - * left-to-right. - * - * @return true if this orientation flows left-to-right - */ - public boolean isLeftToRight() - { - return (orientation & LEFT_TO_RIGHT_ID) != 0; - } - - /** - * Gets an orientation appropriate for the locale. - * - * @param locale the locale - * @return the orientation for that locale - * @throws NullPointerException if locale is null - */ - public static ComponentOrientation getOrientation(Locale locale) - { - // Based on iterating over all languages defined in JDK 1.4, this behavior - // matches Sun's. However, it makes me wonder if any non-horizontal - // orientations even exist, as it sure contradicts their documentation. - String language = locale.getLanguage(); - if ("ar".equals(language) || "fa".equals(language) || "iw".equals(language) - || "ur".equals(language)) - return RIGHT_TO_LEFT; - return LEFT_TO_RIGHT; - } - - /** - * Gets an orientation from a resource bundle. This tries the following: - * - * <ul> - * <li>Use the key "Orientation" to find an instance of ComponentOrientation - * in the bundle.</li> - * <li>Get the locale of the resource bundle, and get the orientation of - * that locale.</li> - * <li>Give up and get the orientation of the default locale.</li> - * </ul> - * - * @param bdl the bundle to use - * @return the orientation - * @throws NullPointerException if bdl is null - * @deprecated use {@link #getOrientation(Locale)} instead - */ - public static ComponentOrientation getOrientation(ResourceBundle bdl) - { - ComponentOrientation r; - try - { - r = (ComponentOrientation) bdl.getObject("Orientation"); - if (r != null) - return r; - } - catch (MissingResourceException ignored) - { - } - catch (ClassCastException ignored) - { - } - try - { - r = getOrientation(bdl.getLocale()); - if (r != null) - return r; - } - catch (Exception ignored) - { - } - return getOrientation(Locale.getDefault()); - } -} // class ComponentOrientation diff --git a/libjava/java/awt/Composite.java b/libjava/java/awt/Composite.java deleted file mode 100644 index ca3abe4d1ee..00000000000 --- a/libjava/java/awt/Composite.java +++ /dev/null @@ -1,73 +0,0 @@ -/* Composite.java -- graphics formed from composite layers - Copyright (C) 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.awt.image.ColorModel; - -/** - * This interface is for graphics which are formed as composites of others. - * It combines {@link Graphics2D} shapes according to defined rules to form - * the new image. Implementations of this interface must be immutable, because - * they are not cloned when a Graphics2D container is cloned. - * - * <p>Since this can expose pixels to untrusted code, there is a security - * check on custom objects, <code>readDisplayPixels</code>, to prevent leaking - * restricted information graphically. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @see AlphaComposite - * @see CompositeContext - * @see Graphics2D#setComposite(Composite) - * @since 1.2 - * @status updated to 1.4 - */ -public interface Composite -{ - /** - * Create a context state for performing the compositing operation. Several - * contexts may exist for this object, in a multi-threaded environment. - * - * @param srcColorModel the color model of the source - * @param dstColorModel the color model of the destination - * @param hints hints for choosing between rendering alternatives - */ - CompositeContext createContext(ColorModel srcColorModel, - ColorModel dstColorModel, - RenderingHints hints); -} // interface Composite diff --git a/libjava/java/awt/CompositeContext.java b/libjava/java/awt/CompositeContext.java deleted file mode 100644 index 018a27071dd..00000000000 --- a/libjava/java/awt/CompositeContext.java +++ /dev/null @@ -1,71 +0,0 @@ -/* Composite.java -- the context for compositing graphics layers - Copyright (C) 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.awt.image.Raster; -import java.awt.image.WritableRaster; - -/** - * This interface provides an optimized environment for compositing graphics. - * Several such contexts may exist for a given <code>Composite</code> object. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @see Composite - * @since 1.2 - * @status updated to 1.4 - */ -public interface CompositeContext -{ - /** - * Release resources allocated for the compositing. - */ - void dispose(); - - /** - * Compose the two source images into the composite image. The destination - * can be the same as one of the two inputs, and the destination must be - * compatible with the ColorModel chosen in {@link Composite#createContext}. - * - * @param src the lower image source in compositing - * @param dstIn the upper image source in compositing - * @param dstOut the destination for the composite - * @see Composite - */ - void compose(Raster src, Raster dstIn, WritableRaster dstOut); -} // interface CompositeContext diff --git a/libjava/java/awt/Container.java b/libjava/java/awt/Container.java deleted file mode 100644 index e68adf492be..00000000000 --- a/libjava/java/awt/Container.java +++ /dev/null @@ -1,2023 +0,0 @@ -/* Container.java -- parent container class in AWT - Copyright (C) 1999, 2000, 2002, 2003, 2004, 2005 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.awt.event.ContainerEvent; -import java.awt.event.ContainerListener; -import java.awt.event.KeyEvent; -import java.awt.event.MouseEvent; -import java.awt.peer.ContainerPeer; -import java.awt.peer.LightweightPeer; -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.PrintStream; -import java.io.PrintWriter; -import java.io.Serializable; -import java.util.Collections; -import java.util.EventListener; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - -import javax.accessibility.Accessible; -import javax.swing.SwingUtilities; - -/** - * A generic window toolkit object that acts as a container for other objects. - * Components are tracked in a list, and new elements are at the end of the - * list or bottom of the stacking order. - * - * @author original author unknown - * @author Eric Blake (ebb9@email.byu.edu) - * - * @since 1.0 - * - * @status still missing 1.4 support - */ -public class Container extends Component -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = 4613797578919906343L; - - /* Serialized fields from the serialization spec. */ - int ncomponents; - Component[] component; - LayoutManager layoutMgr; - - LightweightDispatcher dispatcher; - - Dimension maxSize; - - /** - * @since 1.4 - */ - boolean focusCycleRoot; - - int containerSerializedDataVersion; - - /* Anything else is non-serializable, and should be declared "transient". */ - transient ContainerListener containerListener; - transient PropertyChangeSupport changeSupport; - - /** The focus traversal policy that determines how focus is - transferred between this Container and its children. */ - private FocusTraversalPolicy focusTraversalPolicy; - - /** - * The focus traversal keys, if not inherited from the parent or default - * keyboard manager. These sets will contain only AWTKeyStrokes that - * represent press and release events to use as focus control. - * - * @see #getFocusTraversalKeys(int) - * @see #setFocusTraversalKeys(int, Set) - * @since 1.4 - */ - transient Set[] focusTraversalKeys; - - /** - * Default constructor for subclasses. - */ - public Container() - { - } - - /** - * Returns the number of components in this container. - * - * @return The number of components in this container. - */ - public int getComponentCount() - { - return countComponents (); - } - - /** - * Returns the number of components in this container. - * - * @return The number of components in this container. - * - * @deprecated use {@link #getComponentCount()} instead - */ - public int countComponents() - { - return ncomponents; - } - - /** - * Returns the component at the specified index. - * - * @param n The index of the component to retrieve. - * - * @return The requested component. - * - * @throws ArrayIndexOutOfBoundsException If the specified index is invalid - */ - public Component getComponent(int n) - { - synchronized (getTreeLock ()) - { - if (n < 0 || n >= ncomponents) - throw new ArrayIndexOutOfBoundsException("no such component"); - - return component[n]; - } - } - - /** - * Returns an array of the components in this container. - * - * @return The components in this container. - */ - public Component[] getComponents() - { - synchronized (getTreeLock ()) - { - Component[] result = new Component[ncomponents]; - - if (ncomponents > 0) - System.arraycopy(component, 0, result, 0, ncomponents); - - return result; - } - } - - /** - * Swaps the components at position i and j, in the container. - */ - - protected void swapComponents (int i, int j) - { - synchronized (getTreeLock ()) - { - if (i < 0 - || i >= component.length - || j < 0 - || j >= component.length) - throw new ArrayIndexOutOfBoundsException (); - Component tmp = component[i]; - component[i] = component[j]; - component[j] = tmp; - } - } - - /** - * Returns the insets for this container, which is the space used for - * borders, the margin, etc. - * - * @return The insets for this container. - */ - public Insets getInsets() - { - return insets (); - } - - /** - * Returns the insets for this container, which is the space used for - * borders, the margin, etc. - * - * @return The insets for this container. - * @deprecated use {@link #getInsets()} instead - */ - public Insets insets() - { - if (peer == null) - return new Insets (0, 0, 0, 0); - - return ((ContainerPeer) peer).getInsets (); - } - - /** - * Adds the specified component to this container at the end of the - * component list. - * - * @param comp The component to add to the container. - * - * @return The same component that was added. - */ - public Component add(Component comp) - { - addImpl(comp, null, -1); - return comp; - } - - /** - * Adds the specified component to the container at the end of the - * component list. This method should not be used. Instead, use - * <code>add(Component, Object)</code>. - * - * @param name The name of the component to be added. - * @param comp The component to be added. - * - * @return The same component that was added. - * - * @see #add(Component,Object) - */ - public Component add(String name, Component comp) - { - addImpl(comp, name, -1); - return comp; - } - - /** - * Adds the specified component to this container at the specified index - * in the component list. - * - * @param comp The component to be added. - * @param index The index in the component list to insert this child - * at, or -1 to add at the end of the list. - * - * @return The same component that was added. - * - * @throws ArrayIndexOutOfBounds If the specified index is invalid. - */ - public Component add(Component comp, int index) - { - addImpl(comp, null, index); - return comp; - } - - /** - * Adds the specified component to this container at the end of the - * component list. The layout manager will use the specified constraints - * when laying out this component. - * - * @param comp The component to be added to this container. - * @param constraints The layout constraints for this component. - */ - public void add(Component comp, Object constraints) - { - addImpl(comp, constraints, -1); - } - - /** - * Adds the specified component to this container at the specified index - * in the component list. The layout manager will use the specified - * constraints when layout out this component. - * - * @param comp The component to be added. - * @param constraints The layout constraints for this component. - * @param index The index in the component list to insert this child - * at, or -1 to add at the end of the list. - * - * @throws ArrayIndexOutOfBounds If the specified index is invalid. - */ - public void add(Component comp, Object constraints, int index) - { - addImpl(comp, constraints, index); - } - - /** - * This method is called by all the <code>add()</code> methods to perform - * the actual adding of the component. Subclasses who wish to perform - * their own processing when a component is added should override this - * method. Any subclass doing this must call the superclass version of - * this method in order to ensure proper functioning of the container. - * - * @param comp The component to be added. - * @param constraints The layout constraints for this component, or - * <code>null</code> if there are no constraints. - * @param index The index in the component list to insert this child - * at, or -1 to add at the end of the list. - * - * @throws ArrayIndexOutOfBounds If the specified index is invalid. - */ - protected void addImpl(Component comp, Object constraints, int index) - { - synchronized (getTreeLock ()) - { - if (index > ncomponents - || (index < 0 && index != -1) - || comp instanceof Window - || (comp instanceof Container - && ((Container) comp).isAncestorOf(this))) - throw new IllegalArgumentException(); - - // Reparent component, and make sure component is instantiated if - // we are. - if (comp.parent != null) - comp.parent.remove(comp); - comp.parent = this; - if (peer != null) - { - if (comp.isLightweight ()) - { - enableEvents (comp.eventMask); - if (!isLightweight ()) - enableEvents (AWTEvent.PAINT_EVENT_MASK); - } - } - - invalidate(); - - if (component == null) - component = new Component[4]; // FIXME, better initial size? - - // This isn't the most efficient implementation. We could do less - // copying when growing the array. It probably doesn't matter. - if (ncomponents >= component.length) - { - int nl = component.length * 2; - Component[] c = new Component[nl]; - System.arraycopy(component, 0, c, 0, ncomponents); - component = c; - } - - if (index == -1) - component[ncomponents++] = comp; - else - { - System.arraycopy(component, index, component, index + 1, - ncomponents - index); - component[index] = comp; - ++ncomponents; - } - - // Notify the layout manager. - if (layoutMgr != null) - { - if (layoutMgr instanceof LayoutManager2) - { - LayoutManager2 lm2 = (LayoutManager2) layoutMgr; - lm2.addLayoutComponent(comp, constraints); - } - else if (constraints instanceof String) - layoutMgr.addLayoutComponent((String) constraints, comp); - else - layoutMgr.addLayoutComponent(null, comp); - } - - if (isShowing ()) - { - // Post event to notify of adding the component. - ContainerEvent ce = new ContainerEvent(this, - ContainerEvent.COMPONENT_ADDED, - comp); - getToolkit().getSystemEventQueue().postEvent(ce); - } - } - } - - /** - * Removes the component at the specified index from this container. - * - * @param index The index of the component to remove. - */ - public void remove(int index) - { - synchronized (getTreeLock ()) - { - Component r = component[index]; - - r.removeNotify(); - - System.arraycopy(component, index + 1, component, index, - ncomponents - index - 1); - component[--ncomponents] = null; - - invalidate(); - - if (layoutMgr != null) - layoutMgr.removeLayoutComponent(r); - - r.parent = null; - - if (isShowing ()) - { - // Post event to notify of removing the component. - ContainerEvent ce = new ContainerEvent(this, - ContainerEvent.COMPONENT_REMOVED, - r); - getToolkit().getSystemEventQueue().postEvent(ce); - } - } - } - - /** - * Removes the specified component from this container. - * - * @return component The component to remove from this container. - */ - public void remove(Component comp) - { - synchronized (getTreeLock ()) - { - for (int i = 0; i < ncomponents; ++i) - { - if (component[i] == comp) - { - remove(i); - break; - } - } - } - } - - /** - * Removes all components from this container. - */ - public void removeAll() - { - synchronized (getTreeLock ()) - { - while (ncomponents > 0) - remove(0); - } - } - - /** - * Returns the current layout manager for this container. - * - * @return The layout manager for this container. - */ - public LayoutManager getLayout() - { - return layoutMgr; - } - - /** - * Sets the layout manager for this container to the specified layout - * manager. - * - * @param mgr The new layout manager for this container. - */ - public void setLayout(LayoutManager mgr) - { - layoutMgr = mgr; - invalidate(); - } - - /** - * Layout the components in this container. - */ - public void doLayout() - { - layout (); - } - - /** - * Layout the components in this container. - * - * @deprecated use {@link #doLayout()} instead - */ - public void layout() - { - if (layoutMgr != null) - layoutMgr.layoutContainer (this); - } - - /** - * Invalidates this container to indicate that it (and all parent - * containers) need to be laid out. - */ - public void invalidate() - { - super.invalidate(); - } - - /** - * Re-lays out the components in this container. - */ - public void validate() - { - synchronized (getTreeLock ()) - { - if (! isValid() && peer != null) - { - validateTree(); - } - } - } - - /** - * Recursively invalidates the container tree. - */ - void invalidateTree() - { - for (int i = 0; i < ncomponents; i++) - { - Component comp = component[i]; - comp.invalidate(); - if (comp instanceof Container) - ((Container) comp).invalidateTree(); - } - } - - /** - * Recursively validates the container tree, recomputing any invalid - * layouts. - */ - protected void validateTree() - { - if (valid) - return; - - ContainerPeer cPeer = null; - if (peer != null && ! (peer instanceof LightweightPeer)) - { - cPeer = (ContainerPeer) peer; - cPeer.beginValidate(); - } - - for (int i = 0; i < ncomponents; ++i) - { - Component comp = component[i]; - - if (comp.getPeer () == null) - comp.addNotify(); - } - - doLayout (); - for (int i = 0; i < ncomponents; ++i) - { - Component comp = component[i]; - - if (! comp.isValid()) - { - if (comp instanceof Container) - { - ((Container) comp).validateTree(); - } - else - { - component[i].validate(); - } - } - } - - /* children will call invalidate() when they are layed out. It - is therefore important that valid is not set to true - until after the children have been layed out. */ - valid = true; - - if (cPeer != null) - cPeer.endValidate(); - } - - public void setFont(Font f) - { - super.setFont(f); - // FIXME: Although it might make more sense to invalidate only - // those children whose font == null, Sun invalidates all children. - // So we'll do the same. - invalidateTree(); - } - - /** - * Returns the preferred size of this container. - * - * @return The preferred size of this container. - */ - public Dimension getPreferredSize() - { - return preferredSize (); - } - - /** - * Returns the preferred size of this container. - * - * @return The preferred size of this container. - * - * @deprecated use {@link #getPreferredSize()} instead - */ - public Dimension preferredSize() - { - if (layoutMgr != null) - return layoutMgr.preferredLayoutSize (this); - else - return super.preferredSize (); - } - - /** - * Returns the minimum size of this container. - * - * @return The minimum size of this container. - */ - public Dimension getMinimumSize() - { - return minimumSize (); - } - - /** - * Returns the minimum size of this container. - * - * @return The minimum size of this container. - * - * @deprecated use {@link #getMinimumSize()} instead - */ - public Dimension minimumSize() - { - if (layoutMgr != null) - return layoutMgr.minimumLayoutSize (this); - else - return super.minimumSize (); - } - - /** - * Returns the maximum size of this container. - * - * @return The maximum size of this container. - */ - public Dimension getMaximumSize() - { - if (layoutMgr != null && layoutMgr instanceof LayoutManager2) - { - LayoutManager2 lm2 = (LayoutManager2) layoutMgr; - return lm2.maximumLayoutSize(this); - } - else - return super.getMaximumSize(); - } - - /** - * Returns the preferred alignment along the X axis. This is a value - * between 0 and 1 where 0 represents alignment flush left and - * 1 means alignment flush right, and 0.5 means centered. - * - * @return The preferred alignment along the X axis. - */ - public float getAlignmentX() - { - if (layoutMgr instanceof LayoutManager2) - { - LayoutManager2 lm2 = (LayoutManager2) layoutMgr; - return lm2.getLayoutAlignmentX(this); - } - else - return super.getAlignmentX(); - } - - /** - * Returns the preferred alignment along the Y axis. This is a value - * between 0 and 1 where 0 represents alignment flush top and - * 1 means alignment flush bottom, and 0.5 means centered. - * - * @return The preferred alignment along the Y axis. - */ - public float getAlignmentY() - { - if (layoutMgr instanceof LayoutManager2) - { - LayoutManager2 lm2 = (LayoutManager2) layoutMgr; - return lm2.getLayoutAlignmentY(this); - } - else - return super.getAlignmentY(); - } - - /** - * Paints this container. The implementation of this method in this - * class forwards to any lightweight components in this container. If - * this method is subclassed, this method should still be invoked as - * a superclass method so that lightweight components are properly - * drawn. - * - * @param g The graphics context for this paint job. - */ - public void paint(Graphics g) - { - if (!isShowing()) - return; - // Paint self first. - super.paint(g); - // Visit heavyweights as well, in case they were - // erased when we cleared the background for this container. - visitChildren(g, GfxPaintVisitor.INSTANCE, false); - } - - /** - * Updates this container. The implementation of this method in this - * class forwards to any lightweight components in this container. If - * this method is subclassed, this method should still be invoked as - * a superclass method so that lightweight components are properly - * drawn. - * - * @param g The graphics context for this update. - */ - public void update(Graphics g) - { - super.update(g); - } - - /** - * Prints this container. The implementation of this method in this - * class forwards to any lightweight components in this container. If - * this method is subclassed, this method should still be invoked as - * a superclass method so that lightweight components are properly - * drawn. - * - * @param g The graphics context for this print job. - */ - public void print(Graphics g) - { - super.print(g); - visitChildren(g, GfxPrintVisitor.INSTANCE, true); - } - - /** - * Paints all of the components in this container. - * - * @param g The graphics context for this paint job. - */ - public void paintComponents(Graphics g) - { - super.paint(g); - visitChildren(g, GfxPaintAllVisitor.INSTANCE, true); - } - - /** - * Prints all of the components in this container. - * - * @param g The graphics context for this print job. - */ - public void printComponents(Graphics g) - { - super.paint(g); - visitChildren(g, GfxPrintAllVisitor.INSTANCE, true); - } - - /** - * Adds the specified container listener to this object's list of - * container listeners. - * - * @param listener The listener to add. - */ - public synchronized void addContainerListener(ContainerListener listener) - { - containerListener = AWTEventMulticaster.add(containerListener, listener); - } - - /** - * Removes the specified container listener from this object's list of - * container listeners. - * - * @param listener The listener to remove. - */ - public synchronized void removeContainerListener(ContainerListener listener) - { - containerListener = AWTEventMulticaster.remove(containerListener, listener); - } - - /** - * @since 1.4 - */ - public synchronized ContainerListener[] getContainerListeners() - { - return (ContainerListener[]) - AWTEventMulticaster.getListeners(containerListener, - ContainerListener.class); - } - - /** - * Returns an array of all the objects currently registered as FooListeners - * upon this Container. FooListeners are registered using the addFooListener - * method. - * - * @exception ClassCastException If listenerType doesn't specify a class or - * interface that implements @see java.util.EventListener. - * - * @since 1.3 - */ - public EventListener[] getListeners(Class listenerType) - { - if (listenerType == ContainerListener.class) - return getContainerListeners(); - return super.getListeners(listenerType); - } - - /** - * Processes the specified event. This method calls - * <code>processContainerEvent()</code> if this method is a - * <code>ContainerEvent</code>, otherwise it calls the superclass - * method. - * - * @param e The event to be processed. - */ - protected void processEvent(AWTEvent e) - { - if (e instanceof ContainerEvent) - processContainerEvent((ContainerEvent) e); - else - super.processEvent(e); - } - - /** - * Called when a container event occurs if container events are enabled. - * This method calls any registered listeners. - * - * @param e The event that occurred. - */ - protected void processContainerEvent(ContainerEvent e) - { - if (containerListener == null) - return; - switch (e.id) - { - case ContainerEvent.COMPONENT_ADDED: - containerListener.componentAdded(e); - break; - - case ContainerEvent.COMPONENT_REMOVED: - containerListener.componentRemoved(e); - break; - } - } - - /** - * AWT 1.0 event processor. - * - * @param e The event that occurred. - * - * @deprecated use {@link #dispatchEvent(AWTEvent)} instead - */ - public void deliverEvent(Event e) - { - if (!handleEvent (e)) - { - synchronized (getTreeLock ()) - { - Component parent = getParent (); - - if (parent != null) - parent.deliverEvent (e); - } - } - } - - /** - * Returns the component located at the specified point. This is done - * by checking whether or not a child component claims to contain this - * point. The first child component that does is returned. If no - * child component claims the point, the container itself is returned, - * unless the point does not exist within this container, in which - * case <code>null</code> is returned. - * - * @param x The X coordinate of the point. - * @param y The Y coordinate of the point. - * - * @return The component containing the specified point, or - * <code>null</code> if there is no such point. - */ - public Component getComponentAt(int x, int y) - { - return locate (x, y); - } - - /** - * Returns the component located at the specified point. This is done - * by checking whether or not a child component claims to contain this - * point. The first child component that does is returned. If no - * child component claims the point, the container itself is returned, - * unless the point does not exist within this container, in which - * case <code>null</code> is returned. - * - * @param x The x position of the point to return the component at. - * @param y The y position of the point to return the component at. - * - * @return The component containing the specified point, or <code>null</code> - * if there is no such point. - * - * @deprecated use {@link #getComponentAt(int, int)} instead - */ - public Component locate(int x, int y) - { - synchronized (getTreeLock ()) - { - if (!contains (x, y)) - return null; - for (int i = 0; i < ncomponents; ++i) - { - // Ignore invisible children... - if (!component[i].isVisible ()) - continue; - - int x2 = x - component[i].x; - int y2 = y - component[i].y; - if (component[i].contains (x2, y2)) - return component[i]; - } - return this; - } - } - - /** - * Returns the component located at the specified point. This is done - * by checking whether or not a child component claims to contain this - * point. The first child component that does is returned. If no - * child component claims the point, the container itself is returned, - * unless the point does not exist within this container, in which - * case <code>null</code> is returned. - * - * @param p The point to return the component at. - * @return The component containing the specified point, or <code>null</code> - * if there is no such point. - */ - public Component getComponentAt(Point p) - { - return getComponentAt (p.x, p.y); - } - - public Component findComponentAt(int x, int y) - { - synchronized (getTreeLock ()) - { - if (! contains(x, y)) - return null; - - for (int i = 0; i < ncomponents; ++i) - { - // Ignore invisible children... - if (!component[i].isVisible()) - continue; - - int x2 = x - component[i].x; - int y2 = y - component[i].y; - // We don't do the contains() check right away because - // findComponentAt would redundantly do it first thing. - if (component[i] instanceof Container) - { - Container k = (Container) component[i]; - Component r = k.findComponentAt(x2, y2); - if (r != null) - return r; - } - else if (component[i].contains(x2, y2)) - return component[i]; - } - - return this; - } - } - - public Component findComponentAt(Point p) - { - return findComponentAt(p.x, p.y); - } - - /** - * Called when this container is added to another container to inform it - * to create its peer. Peers for any child components will also be - * created. - */ - public void addNotify() - { - super.addNotify(); - addNotifyContainerChildren(); - } - - /** - * Called when this container is removed from its parent container to - * inform it to destroy its peer. This causes the peers of all child - * component to be destroyed as well. - */ - public void removeNotify() - { - synchronized (getTreeLock ()) - { - for (int i = 0; i < ncomponents; ++i) - component[i].removeNotify(); - super.removeNotify(); - } - } - - /** - * Tests whether or not the specified component is contained within - * this components subtree. - * - * @param comp The component to test. - * - * @return <code>true</code> if this container is an ancestor of the - * specified component, <code>false</code> otherwise. - */ - public boolean isAncestorOf(Component comp) - { - synchronized (getTreeLock ()) - { - while (true) - { - if (comp == null) - return false; - if (comp == this) - return true; - comp = comp.getParent(); - } - } - } - - /** - * Returns a string representing the state of this container for - * debugging purposes. - * - * @return A string representing the state of this container. - */ - protected String paramString() - { - if (layoutMgr == null) - return super.paramString(); - - StringBuffer sb = new StringBuffer(); - sb.append(super.paramString()); - sb.append(",layout="); - sb.append(layoutMgr.getClass().getName()); - return sb.toString(); - } - - /** - * Writes a listing of this container to the specified stream starting - * at the specified indentation point. - * - * @param out The <code>PrintStream</code> to write to. - * @param indent The indentation point. - */ - public void list(PrintStream out, int indent) - { - synchronized (getTreeLock ()) - { - super.list(out, indent); - for (int i = 0; i < ncomponents; ++i) - component[i].list(out, indent + 2); - } - } - - /** - * Writes a listing of this container to the specified stream starting - * at the specified indentation point. - * - * @param out The <code>PrintWriter</code> to write to. - * @param indent The indentation point. - */ - public void list(PrintWriter out, int indent) - { - synchronized (getTreeLock ()) - { - super.list(out, indent); - for (int i = 0; i < ncomponents; ++i) - component[i].list(out, indent + 2); - } - } - - /** - * Sets the focus traversal keys for a given traversal operation for this - * Container. - * - * @exception IllegalArgumentException If id is not one of - * KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, - * KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, - * KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, - * or KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS, - * or if keystrokes contains null, or if any Object in keystrokes is not an - * AWTKeyStroke, or if any keystroke represents a KEY_TYPED event, or if any - * keystroke already maps to another focus traversal operation for this - * Container. - * - * @since 1.4 - */ - public void setFocusTraversalKeys(int id, Set keystrokes) - { - if (id != KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS && - id != KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS && - id != KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS && - id != KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS) - throw new IllegalArgumentException (); - - if (keystrokes == null) - { - Container parent = getParent (); - - while (parent != null) - { - if (parent.areFocusTraversalKeysSet (id)) - { - keystrokes = parent.getFocusTraversalKeys (id); - break; - } - parent = parent.getParent (); - } - - if (keystrokes == null) - keystrokes = KeyboardFocusManager.getCurrentKeyboardFocusManager (). - getDefaultFocusTraversalKeys (id); - } - - Set sa; - Set sb; - Set sc; - String name; - switch (id) - { - case KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS: - sa = getFocusTraversalKeys - (KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS); - sb = getFocusTraversalKeys - (KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS); - sc = getFocusTraversalKeys - (KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS); - name = "forwardFocusTraversalKeys"; - break; - case KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS: - sa = getFocusTraversalKeys - (KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS); - sb = getFocusTraversalKeys - (KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS); - sc = getFocusTraversalKeys - (KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS); - name = "backwardFocusTraversalKeys"; - break; - case KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS: - sa = getFocusTraversalKeys - (KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS); - sb = getFocusTraversalKeys - (KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS); - sc = getFocusTraversalKeys - (KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS); - name = "upCycleFocusTraversalKeys"; - break; - case KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS: - sa = getFocusTraversalKeys - (KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS); - sb = getFocusTraversalKeys - (KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS); - sc = getFocusTraversalKeys - (KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS); - name = "downCycleFocusTraversalKeys"; - break; - default: - throw new IllegalArgumentException (); - } - - int i = keystrokes.size (); - Iterator iter = keystrokes.iterator (); - - while (--i >= 0) - { - Object o = iter.next (); - if (!(o instanceof AWTKeyStroke) - || sa.contains (o) || sb.contains (o) || sc.contains (o) - || ((AWTKeyStroke) o).keyCode == KeyEvent.VK_UNDEFINED) - throw new IllegalArgumentException (); - } - - if (focusTraversalKeys == null) - focusTraversalKeys = new Set[3]; - - keystrokes = Collections.unmodifiableSet (new HashSet (keystrokes)); - firePropertyChange (name, focusTraversalKeys[id], keystrokes); - - focusTraversalKeys[id] = keystrokes; - } - - /** - * Returns the Set of focus traversal keys for a given traversal operation for - * this Container. - * - * @exception IllegalArgumentException If id is not one of - * KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, - * KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, - * KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, - * or KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS. - * - * @since 1.4 - */ - public Set getFocusTraversalKeys (int id) - { - if (id != KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS && - id != KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS && - id != KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS && - id != KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS) - throw new IllegalArgumentException (); - - Set s = null; - - if (focusTraversalKeys != null) - s = focusTraversalKeys[id]; - - if (s == null && parent != null) - s = parent.getFocusTraversalKeys (id); - - return s == null ? (KeyboardFocusManager.getCurrentKeyboardFocusManager() - .getDefaultFocusTraversalKeys(id)) : s; - } - - /** - * Returns whether the Set of focus traversal keys for the given focus - * traversal operation has been explicitly defined for this Container. - * If this method returns false, this Container is inheriting the Set from - * an ancestor, or from the current KeyboardFocusManager. - * - * @exception IllegalArgumentException If id is not one of - * KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, - * KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, - * KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, - * or KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS. - * - * @since 1.4 - */ - public boolean areFocusTraversalKeysSet (int id) - { - if (id != KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS && - id != KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS && - id != KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS && - id != KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS) - throw new IllegalArgumentException (); - - return focusTraversalKeys != null && focusTraversalKeys[id] != null; - } - - /** - * Check whether the given Container is the focus cycle root of this - * Container's focus traversal cycle. If this Container is a focus - * cycle root itself, then it will be in two different focus cycles - * -- it's own, and that of its ancestor focus cycle root's. In - * that case, if <code>c</code> is either of those containers, this - * method will return true. - * - * @param c the candidate Container - * - * @return true if c is the focus cycle root of the focus traversal - * cycle to which this Container belongs, false otherwise - * - * @since 1.4 - */ - public boolean isFocusCycleRoot (Container c) - { - if (this == c - && isFocusCycleRoot ()) - return true; - - Container ancestor = getFocusCycleRootAncestor (); - - if (c == ancestor) - return true; - - return false; - } - - /** - * If this Container is a focus cycle root, set the focus traversal - * policy that determines the focus traversal order for its - * children. If non-null, this policy will be inherited by all - * inferior focus cycle roots. If <code>policy</code> is null, this - * Container will inherit its policy from the closest ancestor focus - * cycle root that's had its policy set. - * - * @param policy the new focus traversal policy for this Container or null - * - * @since 1.4 - */ - public void setFocusTraversalPolicy (FocusTraversalPolicy policy) - { - focusTraversalPolicy = policy; - } - - /** - * Return the focus traversal policy that determines the focus - * traversal order for this Container's children. This method - * returns null if this Container is not a focus cycle root. If the - * focus traversal policy has not been set explicitly, then this - * method will return an ancestor focus cycle root's policy instead. - * - * @return this Container's focus traversal policy or null - * - * @since 1.4 - */ - public FocusTraversalPolicy getFocusTraversalPolicy () - { - if (!isFocusCycleRoot ()) - return null; - - if (focusTraversalPolicy == null) - { - Container ancestor = getFocusCycleRootAncestor (); - - if (ancestor != this) - return ancestor.getFocusTraversalPolicy (); - else - { - KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager (); - - return manager.getDefaultFocusTraversalPolicy (); - } - } - else - return focusTraversalPolicy; - } - - /** - * Check whether this Container's focus traversal policy has been - * explicitly set. If it has not, then this Container will inherit - * its focus traversal policy from one of its ancestor focus cycle - * roots. - * - * @return true if focus traversal policy is set, false otherwise - */ - public boolean isFocusTraversalPolicySet () - { - return focusTraversalPolicy == null; - } - - /** - * Set whether or not this Container is the root of a focus - * traversal cycle. This Container's focus traversal policy - * determines the order of focus traversal. Some policies prevent - * the focus from being transferred between two traversal cycles - * until an up or down traversal operation is performed. In that - * case, normal traversal (not up or down) is limited to this - * Container and all of this Container's descendents that are not - * descendents of inferior focus cycle roots. In the default case - * however, ContainerOrderFocusTraversalPolicy is in effect, and it - * supports implicit down-cycle traversal operations. - * - * @return true if this is a focus cycle root, false otherwise - * - * @since 1.4 - */ - public void setFocusCycleRoot (boolean focusCycleRoot) - { - this.focusCycleRoot = focusCycleRoot; - } - - /** - * Check whether this Container is a focus cycle root. - * - * @return true if this is a focus cycle root, false otherwise - * - * @since 1.4 - */ - public boolean isFocusCycleRoot () - { - return focusCycleRoot; - } - - /** - * Transfer focus down one focus traversal cycle. If this Container - * is a focus cycle root, then its default component becomes the - * focus owner, and this Container becomes the current focus cycle - * root. No traversal will occur if this Container is not a focus - * cycle root. - * - * @since 1.4 - */ - public void transferFocusDownCycle () - { - KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager (); - - manager.downFocusCycle (this); - } - - /** - * Sets the ComponentOrientation property of this container and all components - * contained within it. - * - * @exception NullPointerException If orientation is null - * - * @since 1.4 - */ - public void applyComponentOrientation (ComponentOrientation orientation) - { - if (orientation == null) - throw new NullPointerException (); - } - - public void addPropertyChangeListener (PropertyChangeListener listener) - { - if (listener == null) - return; - - if (changeSupport == null) - changeSupport = new PropertyChangeSupport (this); - - changeSupport.addPropertyChangeListener (listener); - } - - public void addPropertyChangeListener (String name, - PropertyChangeListener listener) - { - if (listener == null) - return; - - if (changeSupport == null) - changeSupport = new PropertyChangeSupport (this); - - changeSupport.addPropertyChangeListener (name, listener); - } - - // Hidden helper methods. - - /** - * Perform a graphics operation on the children of this container. - * For each applicable child, the visitChild() method will be called - * to perform the graphics operation. - * - * @param gfx The graphics object that will be used to derive new - * graphics objects for the children. - * - * @param visitor Object encapsulating the graphics operation that - * should be performed. - * - * @param lightweightOnly If true, only lightweight components will - * be visited. - */ - private void visitChildren(Graphics gfx, GfxVisitor visitor, - boolean lightweightOnly) - { - synchronized (getTreeLock ()) - { - for (int i = ncomponents - 1; i >= 0; --i) - { - Component comp = component[i]; - // If we're visiting heavyweights as well, - // don't recurse into Containers here. This avoids - // painting the same nested child multiple times. - boolean applicable = comp.isVisible() - && (comp.isLightweight() - || !lightweightOnly && ! (comp instanceof Container)); - - if (applicable) - visitChild(gfx, visitor, comp); - } - } - } - - /** - * Perform a graphics operation on a child. A translated and clipped - * graphics object will be created, and the visit() method of the - * visitor will be called to perform the operation. - * - * @param gfx The graphics object that will be used to derive new - * graphics objects for the child. - * - * @param visitor Object encapsulating the graphics operation that - * should be performed. - * - * @param comp The child component that should be visited. - */ - private void visitChild(Graphics gfx, GfxVisitor visitor, - Component comp) - { - Rectangle bounds = comp.getBounds(); - Rectangle oldClip = gfx.getClipBounds(); - if (oldClip == null) - oldClip = bounds; - - Rectangle clip = oldClip.intersection(bounds); - - if (clip.isEmpty()) return; - - boolean clipped = false; - boolean translated = false; - try - { - gfx.setClip(clip.x, clip.y, clip.width, clip.height); - clipped = true; - gfx.translate(bounds.x, bounds.y); - translated = true; - visitor.visit(comp, gfx); - } - finally - { - if (translated) - gfx.translate (-bounds.x, -bounds.y); - if (clipped) - gfx.setClip (oldClip.x, oldClip.y, oldClip.width, oldClip.height); - } - } - - void dispatchEventImpl(AWTEvent e) - { - // Give lightweight dispatcher a chance to handle it. - if (eventTypeEnabled (e.id) - && dispatcher != null - && dispatcher.handleEvent (e)) - return; - - if ((e.id <= ContainerEvent.CONTAINER_LAST - && e.id >= ContainerEvent.CONTAINER_FIRST) - && (containerListener != null - || (eventMask & AWTEvent.CONTAINER_EVENT_MASK) != 0)) - processEvent(e); - else - super.dispatchEventImpl(e); - } - - // This is used to implement Component.transferFocus. - Component findNextFocusComponent(Component child) - { - synchronized (getTreeLock ()) - { - int start, end; - if (child != null) - { - for (start = 0; start < ncomponents; ++start) - { - if (component[start] == child) - break; - } - end = start; - // This special case lets us be sure to terminate. - if (end == 0) - end = ncomponents; - ++start; - } - else - { - start = 0; - end = ncomponents; - } - - for (int j = start; j != end; ++j) - { - if (j >= ncomponents) - { - // The JCL says that we should wrap here. However, that - // seems wrong. To me it seems that focus order should be - // global within in given window. So instead if we reach - // the end we try to look in our parent, if we have one. - if (parent != null) - return parent.findNextFocusComponent(this); - j -= ncomponents; - } - if (component[j] instanceof Container) - { - Component c = component[j]; - c = c.findNextFocusComponent(null); - if (c != null) - return c; - } - else if (component[j].isFocusTraversable()) - return component[j]; - } - - return null; - } - } - - private void addNotifyContainerChildren() - { - synchronized (getTreeLock ()) - { - for (int i = ncomponents; --i >= 0; ) - { - component[i].addNotify(); - if (component[i].isLightweight ()) - { - - // If we're not lightweight, and we just got a lightweight - // child, we need a lightweight dispatcher to feed it events. - if (! this.isLightweight()) - { - if (dispatcher == null) - dispatcher = new LightweightDispatcher (this); - } - - - enableEvents(component[i].eventMask); - if (peer != null && !isLightweight ()) - enableEvents (AWTEvent.PAINT_EVENT_MASK); - } - } - } - } - - /** - * Deserialize this Container: - * <ol> - * <li>Read from the stream the default serializable fields.</li> - * <li>Read a list of serializable ContainerListeners as optional - * data. If the list is null, no listeners will be registered.</li> - * <li>Read this Container's FocusTraversalPolicy as optional data. - * If this is null, then this Container will use a - * DefaultFocusTraversalPolicy.</li> - * </ol> - * - * @param s the stream to read from - * @throws ClassNotFoundException if deserialization fails - * @throws IOException if the stream fails - */ - private void readObject (ObjectInputStream s) - throws ClassNotFoundException, IOException - { - s.defaultReadObject (); - String key = (String) s.readObject (); - while (key != null) - { - Object object = s.readObject (); - if ("containerL".equals (key)) - addContainerListener((ContainerListener) object); - // FIXME: under what key is the focus traversal policy stored? - else if ("focusTraversalPolicy".equals (key)) - setFocusTraversalPolicy ((FocusTraversalPolicy) object); - - key = (String) s.readObject(); - } - } - - /** - * Serialize this Container: - * <ol> - * <li>Write to the stream the default serializable fields.</li> - * <li>Write the list of serializable ContainerListeners as optional - * data.</li> - * <li>Write this Container's FocusTraversalPolicy as optional data.</li> - * </ol> - * - * @param s the stream to write to - * @throws IOException if the stream fails - */ - private void writeObject (ObjectOutputStream s) throws IOException - { - s.defaultWriteObject (); - AWTEventMulticaster.save (s, "containerL", containerListener); - if (focusTraversalPolicy instanceof Serializable) - s.writeObject (focusTraversalPolicy); - else - s.writeObject (null); - } - - // Nested classes. - - /* The following classes are used in concert with the - visitChildren() method to implement all the graphics operations - that requires traversal of the containment hierarchy. */ - - abstract static class GfxVisitor - { - public abstract void visit(Component c, Graphics gfx); - } - - static class GfxPaintVisitor extends GfxVisitor - { - public static final GfxVisitor INSTANCE = new GfxPaintVisitor(); - - public void visit(Component c, Graphics gfx) - { - c.paint(gfx); - } - } - - static class GfxPrintVisitor extends GfxVisitor - { - public static final GfxVisitor INSTANCE = new GfxPrintVisitor(); - - public void visit(Component c, Graphics gfx) - { - c.print(gfx); - } - } - - static class GfxPaintAllVisitor extends GfxVisitor - { - public static final GfxVisitor INSTANCE = new GfxPaintAllVisitor(); - - public void visit(Component c, Graphics gfx) - { - c.paintAll(gfx); - } - } - - static class GfxPrintAllVisitor extends GfxVisitor - { - public static final GfxVisitor INSTANCE = new GfxPrintAllVisitor(); - - public void visit(Component c, Graphics gfx) - { - c.printAll(gfx); - } - } - - /** - * This class provides accessibility support for subclasses of container. - * - * @author Eric Blake (ebb9@email.byu.edu) - * - * @since 1.3 - */ - protected class AccessibleAWTContainer extends AccessibleAWTComponent - { - /** - * Compatible with JDK 1.4+. - */ - private static final long serialVersionUID = 5081320404842566097L; - - /** - * The handler to fire PropertyChange when children are added or removed. - * - * @serial the handler for property changes - */ - protected ContainerListener accessibleContainerHandler - = new AccessibleContainerHandler(); - - /** - * The default constructor. - */ - protected AccessibleAWTContainer() - { - Container.this.addContainerListener(accessibleContainerHandler); - } - - /** - * Return the number of accessible children of the containing accessible - * object (at most the total number of its children). - * - * @return the number of accessible children - */ - public int getAccessibleChildrenCount() - { - synchronized (getTreeLock ()) - { - int count = 0; - int i = component == null ? 0 : component.length; - while (--i >= 0) - if (component[i] instanceof Accessible) - count++; - return count; - } - } - - /** - * Return the nth accessible child of the containing accessible object. - * - * @param i the child to grab, zero-based - * @return the accessible child, or null - */ - public Accessible getAccessibleChild(int i) - { - synchronized (getTreeLock ()) - { - if (component == null) - return null; - int index = -1; - while (i >= 0 && ++index < component.length) - if (component[index] instanceof Accessible) - i--; - if (i < 0) - return (Accessible) component[index]; - return null; - } - } - - /** - * Return the accessible child located at point (in the parent's - * coordinates), if one exists. - * - * @param p the point to look at - * - * @return an accessible object at that point, or null - * - * @throws NullPointerException if p is null - */ - public Accessible getAccessibleAt(Point p) - { - Component c = getComponentAt(p.x, p.y); - return c != Container.this && c instanceof Accessible ? (Accessible) c - : null; - } - - /** - * This class fires a <code>PropertyChange</code> listener, if registered, - * when children are added or removed from the enclosing accessible object. - * - * @author Eric Blake (ebb9@email.byu.edu) - * - * @since 1.3 - */ - protected class AccessibleContainerHandler implements ContainerListener - { - /** - * Default constructor. - */ - protected AccessibleContainerHandler() - { - } - - /** - * Fired when a component is added; forwards to the PropertyChange - * listener. - * - * @param e the container event for adding - */ - public void componentAdded(ContainerEvent e) - { - AccessibleAWTContainer.this.firePropertyChange - (ACCESSIBLE_CHILD_PROPERTY, null, e.getChild()); - } - - /** - * Fired when a component is removed; forwards to the PropertyChange - * listener. - * - * @param e the container event for removing - */ - public void componentRemoved(ContainerEvent e) - { - AccessibleAWTContainer.this.firePropertyChange - (ACCESSIBLE_CHILD_PROPERTY, e.getChild(), null); - } - } // class AccessibleContainerHandler - } // class AccessibleAWTContainer -} // class Container - -/** - * There is a helper class implied from stack traces called - * LightweightDispatcher, but since it is not part of the public API, - * rather than mimic it exactly we write something which does "roughly - * the same thing". - */ - -class LightweightDispatcher implements Serializable -{ - private static final long serialVersionUID = 5184291520170872969L; - private Container nativeContainer; - private Cursor nativeCursor; - private long eventMask; - - private transient Component mouseEventTarget; - private transient Component pressedComponent; - private transient Component lastComponentEntered; - private transient int pressCount; - - LightweightDispatcher(Container c) - { - nativeContainer = c; - } - - void acquireComponentForMouseEvent(MouseEvent me) - { - int x = me.getX (); - int y = me.getY (); - - // Find the candidate which should receive this event. - Component parent = nativeContainer; - Component candidate = null; - Point p = me.getPoint(); - while (candidate == null && parent != null) - { - candidate = - SwingUtilities.getDeepestComponentAt(parent, p.x, p.y); - if (candidate == null || (candidate.eventMask & me.getID()) == 0) - { - candidate = null; - p = SwingUtilities.convertPoint(parent, p.x, p.y, parent.parent); - parent = parent.parent; - } - } - - // If the only candidate we found was the native container itself, - // don't dispatch any event at all. We only care about the lightweight - // children here. - if (candidate == nativeContainer) - candidate = null; - - // If our candidate is new, inform the old target we're leaving. - if (lastComponentEntered != null - && lastComponentEntered.isShowing() - && lastComponentEntered != candidate) - { - // Old candidate could have been removed from - // the nativeContainer so we check first. - if (SwingUtilities.isDescendingFrom(lastComponentEntered, nativeContainer)) - { - Point tp = - SwingUtilities.convertPoint(nativeContainer, - x, y, lastComponentEntered); - MouseEvent exited = new MouseEvent (lastComponentEntered, - MouseEvent.MOUSE_EXITED, - me.getWhen (), - me.getModifiersEx (), - tp.x, tp.y, - me.getClickCount (), - me.isPopupTrigger (), - me.getButton ()); - lastComponentEntered.dispatchEvent (exited); - } - lastComponentEntered = null; - } - // If we have a candidate, maybe enter it. - if (candidate != null) - { - mouseEventTarget = candidate; - if (candidate.isLightweight() - && candidate.isShowing() - && candidate != nativeContainer - && candidate != lastComponentEntered) - { - lastComponentEntered = mouseEventTarget; - Point cp = SwingUtilities.convertPoint(nativeContainer, - x, y, lastComponentEntered); - MouseEvent entered = new MouseEvent (lastComponentEntered, - MouseEvent.MOUSE_ENTERED, - me.getWhen (), - me.getModifiersEx (), - cp.x, cp.y, - me.getClickCount (), - me.isPopupTrigger (), - me.getButton ()); - lastComponentEntered.dispatchEvent (entered); - } - } - - if (me.getID() == MouseEvent.MOUSE_RELEASED - || me.getID() == MouseEvent.MOUSE_PRESSED && pressCount > 0 - || me.getID() == MouseEvent.MOUSE_DRAGGED) - // If any of the following events occur while a button is held down, - // they should be dispatched to the same component to which the - // original MOUSE_PRESSED event was dispatched: - // - MOUSE_RELEASED - // - MOUSE_PRESSED: another button pressed while the first is held down - // - MOUSE_DRAGGED - if (SwingUtilities.isDescendingFrom(pressedComponent, nativeContainer)) - mouseEventTarget = pressedComponent; - else if (me.getID() == MouseEvent.MOUSE_CLICKED) - { - // Don't dispatch CLICKED events whose target is not the same as the - // target for the original PRESSED event. - if (candidate != pressedComponent) - mouseEventTarget = null; - else if (pressCount == 0) - pressedComponent = null; - } - } - - boolean handleEvent(AWTEvent e) - { - if (e instanceof MouseEvent) - { - MouseEvent me = (MouseEvent) e; - - acquireComponentForMouseEvent(me); - - // Avoid dispatching ENTERED and EXITED events twice. - if (mouseEventTarget != null - && mouseEventTarget.isShowing() - && e.getID() != MouseEvent.MOUSE_ENTERED - && e.getID() != MouseEvent.MOUSE_EXITED) - { - MouseEvent newEvt = - SwingUtilities.convertMouseEvent(nativeContainer, me, - mouseEventTarget); - mouseEventTarget.dispatchEvent(newEvt); - - switch (e.getID()) - { - case MouseEvent.MOUSE_PRESSED: - if (pressCount++ == 0) - pressedComponent = mouseEventTarget; - break; - - case MouseEvent.MOUSE_RELEASED: - // Clear our memory of the original PRESSED event, only if - // we're not expecting a CLICKED event after this. If - // there is a CLICKED event after this, it will do clean up. - if (--pressCount == 0 - && mouseEventTarget != pressedComponent) - pressedComponent = null; - break; - } - if (newEvt.isConsumed()) - e.consume(); - } - } - - return e.isConsumed(); - } - -} // class LightweightDispatcher diff --git a/libjava/java/awt/ContainerOrderFocusTraversalPolicy.java b/libjava/java/awt/ContainerOrderFocusTraversalPolicy.java deleted file mode 100644 index 152482c887b..00000000000 --- a/libjava/java/awt/ContainerOrderFocusTraversalPolicy.java +++ /dev/null @@ -1,413 +0,0 @@ -/* ContainerOrderFocusTraversalPolicy.java -- - Copyright (C) 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.io.Serializable; - -/** - * ContainerOrderFocusTraversalPolicy defines a focus traversal order - * based on the order in which Components were packed in a Container. - * This policy performs a pre-order traversal of the Component - * hierarchy starting from a given focus cycle root. Portions of the - * hierarchy that are not visible and displayable are skipped. - * - * By default, this policy transfers focus down-cycle implicitly. - * That is, if a forward traversal is requested on a focus cycle root - * and the focus cycle root has focusable children, the focus will - * automatically be transfered down to the lower focus cycle. - * - * The default implementation of accept accepts only Components that - * are visible, displayable, enabled and focusable. Derived classes - * can override these acceptance criteria by overriding accept. - * - * @author Michael Koch - * @author Thomas Fitzsimmons (fitzsim@redhat.com) - * @since 1.4 - */ -public class ContainerOrderFocusTraversalPolicy extends FocusTraversalPolicy - implements Serializable -{ - /** - * Compatible to JDK 1.4+ - */ - static final long serialVersionUID = 486933713763926351L; - - /** - * True if implicit down cycling is enabled. - */ - private boolean implicitDownCycleTraversal = true; - - /** - * Creates the <code>ContainerOrderFocusTraversalPolicy</code> object. - */ - public ContainerOrderFocusTraversalPolicy () - { - // Nothing to do here - } - - /** - * Returns the Component that should receive the focus after current. - * root must be a focus cycle root of current. - * - * @param root a focus cycle root of current - * @param current a (possibly indirect) child of root, or root itself - * - * @return the next Component in the focus traversal order for root, - * or null if no acceptable Component exists. - * - * @exception IllegalArgumentException If root is not a focus cycle - * root of current, or if either root or current is null. - */ - public Component getComponentAfter (Container root, Component current) - { - if (root == null) - throw new IllegalArgumentException ("focus cycle root is null"); - if (current == null) - throw new IllegalArgumentException ("current component is null"); - - if (!root.isFocusCycleRoot ()) - throw new IllegalArgumentException ("root is not a focus cycle root"); - - Container ancestor = current.getFocusCycleRootAncestor (); - Container prevAncestor = ancestor; - while (ancestor != root) - { - ancestor = current.getFocusCycleRootAncestor (); - if (ancestor == prevAncestor) - { - // We've reached the top focus cycle root ancestor. Check - // if it is root. - if (ancestor != root) - throw new IllegalArgumentException ("the given container is not" - + " a focus cycle root of the" - + " current component"); - else - break; - } - prevAncestor = ancestor; - } - - // FIXME: is this the right thing to do here? It moves the context - // for traversal up one focus traversal cycle. We'll need a test - // for this. - if ((Component) root == current) - root = current.getFocusCycleRootAncestor (); - - // Check if we've reached the top of the component hierarchy. If - // so then we want to loop around to the first component in the - // focus traversal cycle. - if (current instanceof Window) - return getFirstComponent ((Container) current); - - Container parent = current.getParent (); - - synchronized (parent.getTreeLock ()) - { - Component[] components = parent.getComponents (); - int componentIndex = 0; - int numComponents = parent.getComponentCount (); - - // Find component's index. - for (int i = 0; i < numComponents; i++) - { - if (components[i] == current) - componentIndex = i; - } - - // Search forward for the next acceptable component. - for (int i = componentIndex + 1; i < numComponents; i++) - { - if (accept (components[i])) - return components[i]; - - if (components[i] instanceof Container) - { - Component result = getFirstComponent ((Container) components[i]); - - if (result != null - && implicitDownCycleTraversal) - return result; - } - } - - // No focusable components after current in its Container. So go - // to the next Component after current's Container (parent). - Component result = getComponentAfter (root, parent); - - return result; - } - } - - /** - * Returns the Component that should receive the focus before - * <code>current</code>. <code>root</code> must be a focus cycle - * root of current. - * - * @param root a focus cycle root of current - * @param current a (possibly indirect) child of root, or root itself - * - * @return the previous Component in the focus traversal order for - * root, or null if no acceptable Component exists. - * - * @exception IllegalArgumentException If root is not a focus cycle - * root of current, or if either root or current is null. - */ - public Component getComponentBefore (Container root, Component current) - { - if (root == null) - throw new IllegalArgumentException ("focus cycle root is null"); - if (current == null) - throw new IllegalArgumentException ("current component is null"); - - if (!root.isFocusCycleRoot ()) - throw new IllegalArgumentException ("root is not a focus cycle root"); - - Container ancestor = current.getFocusCycleRootAncestor (); - Container prevAncestor = ancestor; - while (ancestor != root) - { - ancestor = current.getFocusCycleRootAncestor (); - if (ancestor == prevAncestor) - { - // We've reached the top focus cycle root ancestor. Check - // if it is root. - if (ancestor != root) - throw new IllegalArgumentException ("the given container is not" - + " a focus cycle root of the" - + " current component"); - else - break; - } - prevAncestor = ancestor; - } - - // FIXME: is this the right thing to do here? It moves the context - // for traversal up one focus traversal cycle. We'll need a test - // for this. - if ((Component) root == current) - root = current.getFocusCycleRootAncestor (); - - // Check if we've reached the top of the component hierarchy. If - // so then we want to loop around to the last component in the - // focus traversal cycle. - if (current instanceof Window) - return getLastComponent ((Container) current); - - Container parent = current.getParent (); - - synchronized (parent.getTreeLock ()) - { - Component[] components = parent.getComponents (); - int componentIndex = 0; - int numComponents = parent.getComponentCount (); - - // Find component's index. - for (int i = 0; i < numComponents; i++) - { - if (components[i] == current) - componentIndex = i; - } - - // Search backward for the next acceptable component. - for (int i = componentIndex - 1; i >= 0; i--) - { - if (accept (components[i])) - return components[i]; - - if (components[i] instanceof Container) - { - Component result = getLastComponent ((Container) components[i]); - - if (result != null) - return result; - } - } - - // No focusable components before current in its Container. So go - // to the previous Component before current's Container (parent). - Component result = getComponentBefore (root, parent); - - return result; - } - } - - /** - * Returns the first Component of root that should receive the focus. - * - * @param root a focus cycle root - * - * @return the first Component in the focus traversal order for - * root, or null if no acceptable Component exists. - * - * @exception IllegalArgumentException If root is null. - */ - public Component getFirstComponent(Container root) - { - if (root == null) - throw new IllegalArgumentException (); - - if (!root.isVisible () - || !root.isDisplayable ()) - return null; - - if (accept (root)) - return root; - - Component[] componentArray = root.getComponents (); - - for (int i = 0; i < componentArray.length; i++) - { - Component component = componentArray [i]; - - if (accept (component)) - return component; - - if (component instanceof Container) - { - Component result = getFirstComponent ((Container) component); - - if (result != null) - return result; - } - } - - return null; - } - - /** - * Returns the last Component of root that should receive the focus. - * - * @param root a focus cycle root - * - * @return the last Component in the focus traversal order for - * root, or null if no acceptable Component exists. - * - * @exception IllegalArgumentException If root is null. - */ - public Component getLastComponent (Container root) - { - if (root == null) - throw new IllegalArgumentException (); - - if (!root.isVisible () - || !root.isDisplayable ()) - return null; - - if (accept (root)) - return root; - - Component[] componentArray = root.getComponents (); - - for (int i = componentArray.length - 1; i >= 0; i--) - { - Component component = componentArray [i]; - - if (accept (component)) - return component; - - if (component instanceof Container) - { - Component result = getLastComponent ((Container) component); - - if (result != null) - return result; - } - } - - return null; - } - - /** - * Returns the default Component of root that should receive the focus. - * - * @param root a focus cycle root - * - * @return the default Component in the focus traversal order for - * root, or null if no acceptable Component exists. - * - * @exception IllegalArgumentException If root is null. - */ - public Component getDefaultComponent (Container root) - { - return getFirstComponent (root); - } - - /** - * Set whether or not implicit down cycling is enabled. If it is, - * then initiating a forward focus traversal operation onto a focus - * cycle root, the focus will be implicitly transferred into the - * root container's focus cycle. - * - * @param value the setting for implicit down cycling - */ - public void setImplicitDownCycleTraversal (boolean value) - { - implicitDownCycleTraversal = value; - } - - /** - * Check whether or not implicit down cycling is enabled. If it is, - * then initiating a forward focus traversal operation onto a focus - * cycle root, the focus will be implicitly transferred into the - * root container's focus cycle. - * - * @return true if the focus will be transferred down-cycle - * implicitly - */ - public boolean getImplicitDownCycleTraversal () - { - return implicitDownCycleTraversal; - } - - /** - * Check whether the given Component is an acceptable target for the - * keyboard input focus. - * - * @param current the Component to check - * - * @return true if current is acceptable, false otherwise - */ - protected boolean accept (Component current) - { - return (current.visible - && current.isDisplayable () - && current.enabled - && current.focusable); - } -} diff --git a/libjava/java/awt/Cursor.java b/libjava/java/awt/Cursor.java deleted file mode 100644 index 48a63f06f4f..00000000000 --- a/libjava/java/awt/Cursor.java +++ /dev/null @@ -1,224 +0,0 @@ -/* Copyright (C) 1999, 2000, 2002 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -/** - * This class represents various predefined cursor types. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public class Cursor implements java.io.Serializable -{ - static final long serialVersionUID = 8028237497568985504L; - - /** - * Constant for the system default cursor type - */ - public static final int DEFAULT_CURSOR = 0; - - /** - * Constant for a cross-hair cursor. - */ - public static final int CROSSHAIR_CURSOR = 1; - - /** - * Constant for a cursor over a text field. - */ - public static final int TEXT_CURSOR = 2; - - /** - * Constant for a cursor to display while waiting for an action to complete. - */ - public static final int WAIT_CURSOR = 3; - - /** - * Cursor used over SW corner of window decorations. - */ - public static final int SW_RESIZE_CURSOR = 4; - - /** - * Cursor used over SE corner of window decorations. - */ - public static final int SE_RESIZE_CURSOR = 5; - - /** - * Cursor used over NW corner of window decorations. - */ - public static final int NW_RESIZE_CURSOR = 6; - - /** - * Cursor used over NE corner of window decorations. - */ - public static final int NE_RESIZE_CURSOR = 7; - - /** - * Cursor used over N edge of window decorations. - */ - public static final int N_RESIZE_CURSOR = 8; - - /** - * Cursor used over S edge of window decorations. - */ - public static final int S_RESIZE_CURSOR = 9; - - /** - * Cursor used over W edge of window decorations. - */ - public static final int W_RESIZE_CURSOR = 10; - - /** - * Cursor used over E edge of window decorations. - */ - public static final int E_RESIZE_CURSOR = 11; - - /** - * Constant for a hand cursor. - */ - public static final int HAND_CURSOR = 12; - - /** - * Constant for a cursor used during window move operations. - */ - public static final int MOVE_CURSOR = 13; - - public static final int CUSTOM_CURSOR = 0xFFFFFFFF; - - private static final int PREDEFINED_COUNT = 14; - - protected static Cursor[] predefined = new Cursor[PREDEFINED_COUNT]; - protected String name; - - /** - * @serial The numeric id of this cursor. - */ - int type; - - /** - * Initializes a new instance of <code>Cursor</code> with the specified - * type. - * - * @param type The cursor type. - * - * @exception IllegalArgumentException If the specified cursor type is invalid - */ - public Cursor(int type) - { - if (type < 0 || type >= PREDEFINED_COUNT) - throw new IllegalArgumentException ("invalid cursor " + type); - - this.type = type; - // FIXME: lookup and set name? - } - - /** This constructor is used internally only. - * Application code should call Toolkit.createCustomCursor(). - */ - protected Cursor(String name) - { - this.name = name; - this.type = CUSTOM_CURSOR; - } - - /** - * Returns an instance of <code>Cursor</code> for one of the specified - * predetermined types. - * - * @param type The type contant from this class. - * - * @return The requested predefined cursor. - * - * @exception IllegalArgumentException If the constant is not one of the - * predefined cursor type constants from this class. - */ - public static Cursor getPredefinedCursor(int type) - { - if (type < 0 || type >= PREDEFINED_COUNT) - throw new IllegalArgumentException ("invalid cursor " + type); - if (predefined[type] == null) - predefined[type] = new Cursor(type); - return predefined[type]; - } - - /** - * Retrieves the system specific custom Cursor named Cursor names are, - * for example: "Invalid.16x16". - * - * @exception AWTException - * @exception HeadlessException If GraphicsEnvironment.isHeadless() - * returns true. - */ - public static Cursor getSystemCustomCursor(String name) - throws AWTException - { - if (GraphicsEnvironment.isHeadless()) - throw new HeadlessException (); - - // FIXME - return null; - } - - /** - * Returns an instance of the system default cursor type. - * - * @return The system default cursor. - */ - public static Cursor getDefaultCursor() - { - return getPredefinedCursor(DEFAULT_CURSOR); - } - - /** - * Returns the numeric type identifier for this cursor. - * - * @return The cursor id. - */ - public int getType() - { - return type; - } - - public String getName() - { - return name; - } - - public String toString() - { - return (this.getClass() + "[" + getName() + "]"); - } -} diff --git a/libjava/java/awt/DefaultFocusTraversalPolicy.java b/libjava/java/awt/DefaultFocusTraversalPolicy.java deleted file mode 100644 index 46b56d3fc29..00000000000 --- a/libjava/java/awt/DefaultFocusTraversalPolicy.java +++ /dev/null @@ -1,109 +0,0 @@ -/* DefaultFocusTraversalPolicy.java -- - Copyright (C) 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -/** - * DefaultFocusTraversalPolicy is the default focus traversal policy - * used by Containers. - * - * This policy sharpens ContainerOrderFocusTraversalPolicy's - * acceptance criteria, to reject those Components that have - * unfocusable peers. Despite this extra strictness, this policy will - * always accept a Component that has explicitly been set focusable by - * any means. - * - * This AWT implementation assumes that the peers of the following - * Components are not focusable: Canvas, Panel, Label, ScrollPane, - * Scrollbar, Window, and any lightweight Component. - * - * A Component's focusability is independent of the focusability of - * its peer. - * - * @author Thomas Fitzsimmons (fitzsim@redhat.com) - * @since 1.4 - */ -public class DefaultFocusTraversalPolicy - extends ContainerOrderFocusTraversalPolicy -{ - /** - * Construct a default focus traversal policy. - */ - public DefaultFocusTraversalPolicy () - { - } - - /** - * Check whether a given Component would be acceptable as a focus - * owner. The Component must be displayable, visible and enabled to - * be acceptable. If the Component's focus traversability has been - * overridden, by overriding Component.isFocusTraversable or - * Component.isFocusable, or by calling Component.setFocusable, then - * the Component will be accepted if it is focusable. If the - * Component uses the default focus traversable behaviour, then - * <code>comp</code> will always be rejected if it is a Canvas, - * Panel, Label, ScrollPane, Scrollbar, Window or lightweight - * Component. - * - * @param comp the Component to check - * - * @return true if the Component is an acceptable target for - * keyboard input focus, false otherwise - */ - protected boolean accept (Component comp) - { - if (comp.visible - && comp.isDisplayable () - && comp.enabled) - { - if (comp.isFocusTraversableOverridden != 0 - && (comp.isFocusTraversable () || comp.isFocusable())) - return true; - - if (!(comp instanceof Canvas - || comp instanceof Panel - || comp instanceof Label - || comp instanceof ScrollPane - || comp instanceof Scrollbar - || comp instanceof Window - || comp.isLightweight ())) - return true; - } - return false; - } -} diff --git a/libjava/java/awt/DefaultKeyboardFocusManager.java b/libjava/java/awt/DefaultKeyboardFocusManager.java deleted file mode 100644 index 8362a97481b..00000000000 --- a/libjava/java/awt/DefaultKeyboardFocusManager.java +++ /dev/null @@ -1,503 +0,0 @@ -/* DefaultKeyboardFocusManager.java -- - Copyright (C) 2002, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.awt.event.ActionEvent; -import java.awt.event.FocusEvent; -import java.awt.event.KeyEvent; -import java.awt.event.WindowEvent; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.Set; -import java.util.SortedSet; -import java.util.TreeSet; - -// FIXME: finish documentation -public class DefaultKeyboardFocusManager extends KeyboardFocusManager -{ - /** - * This class models a request to delay the dispatch of events that - * arrive after a certain time, until a certain component becomes - * the focus owner. - */ - private class EventDelayRequest implements Comparable - { - /** A {@link java.util.List} of {@link java.awt.event.KeyEvent}s - that are being delayed, pending this request's {@link - Component} receiving the keyboard focus. */ - private LinkedList enqueuedKeyEvents = new LinkedList (); - - /** An event timestamp. All events that arrive after this time - should be queued in the {@link #enqueuedKeyEvents} {@link - java.util.List}. */ - public long timestamp; - /** When this {@link Component} becomes focused, all events - between this EventDelayRequest and the next one in will be - dispatched from {@link #enqueuedKeyEvents}. */ - public Component focusedComp; - - /** - * Construct a new EventDelayRequest. - * - * @param timestamp events that arrive after this time will be - * delayed - * @param focusedComp the Component that needs to receive focus - * before events are dispatched - */ - public EventDelayRequest (long timestamp, Component focusedComp) - { - this.timestamp = timestamp; - this.focusedComp = focusedComp; - } - - public int compareTo (Object o) - { - if (!(o instanceof EventDelayRequest)) - throw new ClassCastException (); - - EventDelayRequest request = (EventDelayRequest) o; - - if (request.timestamp < timestamp) - return -1; - else if (request.timestamp == timestamp) - return 0; - else - return 1; - } - - public boolean equals (Object o) - { - if (!(o instanceof EventDelayRequest) || o == null) - return false; - - EventDelayRequest request = (EventDelayRequest) o; - - return (request.timestamp == timestamp - && request.focusedComp == focusedComp); - } - - public void enqueueEvent (KeyEvent e) - { - KeyEvent last = (KeyEvent) enqueuedKeyEvents.getLast (); - if (last != null && e.getWhen () < last.getWhen ()) - throw new RuntimeException ("KeyEvents enqueued out-of-order"); - - if (e.getWhen () <= timestamp) - throw new RuntimeException ("KeyEvents enqueued before starting timestamp"); - - enqueuedKeyEvents.add (e); - } - - public void dispatchEvents () - { - int size = enqueuedKeyEvents.size (); - for (int i = 0; i < size; i++) - { - KeyEvent e = (KeyEvent) enqueuedKeyEvents.remove (0); - dispatchKeyEvent (e); - } - } - - public void discardEvents () - { - enqueuedKeyEvents.clear (); - } - } - - /** The {@link java.util.SortedSet} of current {@link - #EventDelayRequest}s. */ - private SortedSet delayRequests = new TreeSet (); - - public DefaultKeyboardFocusManager () - { - } - - public boolean dispatchEvent (AWTEvent e) - { - if (e instanceof WindowEvent) - { - Window target = (Window) e.getSource (); - - if (e.id == WindowEvent.WINDOW_ACTIVATED) - setGlobalActiveWindow (target); - else if (e.id == WindowEvent.WINDOW_GAINED_FOCUS) - setGlobalFocusedWindow (target); - else if (e.id != WindowEvent.WINDOW_LOST_FOCUS - && e.id != WindowEvent.WINDOW_DEACTIVATED) - return false; - - redispatchEvent(target, e); - return true; - } - else if (e instanceof FocusEvent) - { - Component target = (Component) e.getSource (); - - if (e.id == FocusEvent.FOCUS_GAINED) - { - if (! (target instanceof Window)) - { - if (((FocusEvent) e).isTemporary ()) - setGlobalFocusOwner (target); - else - setGlobalPermanentFocusOwner (target); - } - - // Keep track of this window's focus owner. - - // Find the target Component's top-level ancestor. - Container parent = target.getParent (); - - while (parent != null - && !(parent instanceof Window)) - parent = parent.getParent (); - - Window toplevel = parent == null ? - (Window) target : (Window) parent; - - Component focusOwner = getFocusOwner (); - if (focusOwner != null - && ! (focusOwner instanceof Window)) - toplevel.setFocusOwner (focusOwner); - } - else if (e.id == FocusEvent.FOCUS_LOST) - { - if (((FocusEvent) e).isTemporary ()) - setGlobalFocusOwner (null); - else - setGlobalPermanentFocusOwner (null); - } - - redispatchEvent(target, e); - - return true; - } - else if (e instanceof KeyEvent) - { - // Loop through all registered KeyEventDispatchers, giving - // each a chance to handle this event. - Iterator i = getKeyEventDispatchers().iterator(); - - while (i.hasNext ()) - { - KeyEventDispatcher dispatcher = (KeyEventDispatcher) i.next (); - if (dispatcher.dispatchKeyEvent ((KeyEvent) e)) - return true; - } - - // processKeyEvent checks if this event represents a focus - // traversal key stroke. - Component focusOwner = getGlobalPermanentFocusOwner (); - - if (focusOwner != null) - processKeyEvent (focusOwner, (KeyEvent) e); - - if (e.isConsumed ()) - return true; - - if (enqueueKeyEvent ((KeyEvent) e)) - // This event was enqueued for dispatch at a later time. - return true; - else - // This event wasn't handled by any of the registered - // KeyEventDispatchers, and wasn't enqueued for dispatch - // later, so send it to the default dispatcher. - return dispatchKeyEvent ((KeyEvent) e); - } - - return false; - } - - private boolean enqueueKeyEvent (KeyEvent e) - { - Iterator i = delayRequests.iterator (); - boolean oneEnqueued = false; - while (i.hasNext ()) - { - EventDelayRequest request = (EventDelayRequest) i.next (); - if (e.getWhen () > request.timestamp) - { - request.enqueueEvent (e); - oneEnqueued = true; - } - } - return oneEnqueued; - } - - public boolean dispatchKeyEvent (KeyEvent e) - { - Component focusOwner = getGlobalPermanentFocusOwner (); - - if (focusOwner != null) - redispatchEvent(focusOwner, e); - - // Loop through all registered KeyEventPostProcessors, giving - // each a chance to process this event. - Iterator i = getKeyEventPostProcessors().iterator(); - - while (i.hasNext ()) - { - KeyEventPostProcessor processor = (KeyEventPostProcessor) i.next (); - if (processor.postProcessKeyEvent ((KeyEvent) e)) - return true; - } - - // The event hasn't been consumed yet. Check if it is an - // MenuShortcut. - if (postProcessKeyEvent (e)) - return true; - - // Always return true. - return true; - } - - public boolean postProcessKeyEvent (KeyEvent e) - { - // Check if this event represents a menu shortcut. - - // MenuShortcuts are activated by Ctrl- KeyEvents, only on KEY_PRESSED. - int modifiers = e.getModifiersEx (); - if (e.getID() == KeyEvent.KEY_PRESSED - && (modifiers & KeyEvent.CTRL_DOWN_MASK) != 0) - { - Window focusedWindow = getGlobalFocusedWindow (); - if (focusedWindow instanceof Frame) - { - MenuBar menubar = ((Frame) focusedWindow).getMenuBar (); - - if (menubar != null) - { - // If there's a menubar, loop through all menu items, - // checking whether each one has a shortcut, and if - // so, whether this key event should activate it. - int numMenus = menubar.getMenuCount (); - - for (int i = 0; i < numMenus; i++) - { - Menu menu = menubar.getMenu (i); - int numItems = menu.getItemCount (); - - for (int j = 0; j < numItems; j++) - { - MenuItem item = menu.getItem (j); - MenuShortcut shortcut = item.getShortcut (); - - if (item.isEnabled() && shortcut != null) - { - // Dispatch a new ActionEvent if: - // - // a) this is a Shift- KeyEvent, and the - // shortcut requires the Shift modifier - // - // or, b) this is not a Shift- KeyEvent, and the - // shortcut does not require the Shift - // modifier. - if (shortcut.getKey () == e.getKeyCode () - && ((shortcut.usesShiftModifier () - && (modifiers & KeyEvent.SHIFT_DOWN_MASK) != 0) - || (! shortcut.usesShiftModifier () - && (modifiers & KeyEvent.SHIFT_DOWN_MASK) == 0))) - { - item.dispatchEvent (new ActionEvent (item, - ActionEvent.ACTION_PERFORMED, - item.getActionCommand (), - modifiers)); - // The event was dispatched. - return true; - } - } - } - } - } - } - } - return false; - } - - public void processKeyEvent (Component comp, KeyEvent e) - { - AWTKeyStroke eventKeystroke = AWTKeyStroke.getAWTKeyStrokeForEvent (e); - // For every focus traversal keystroke, we need to also consume - // the other two key event types for the same key (e.g. if - // KEY_PRESSED TAB is a focus traversal keystroke, we also need to - // consume KEY_RELEASED and KEY_TYPED TAB key events). - AWTKeyStroke oppositeKeystroke = AWTKeyStroke.getAWTKeyStroke (e.getKeyCode (), - e.getModifiersEx (), - !(e.id == KeyEvent.KEY_RELEASED)); - - Set forwardKeystrokes = comp.getFocusTraversalKeys (KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS); - Set backwardKeystrokes = comp.getFocusTraversalKeys (KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS); - Set upKeystrokes = comp.getFocusTraversalKeys (KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS); - Set downKeystrokes = null; - if (comp instanceof Container) - downKeystrokes = comp.getFocusTraversalKeys (KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS); - - if (forwardKeystrokes.contains (eventKeystroke)) - { - focusNextComponent (comp); - e.consume (); - } - else if (backwardKeystrokes.contains (eventKeystroke)) - { - focusPreviousComponent (comp); - e.consume (); - } - else if (upKeystrokes.contains (eventKeystroke)) - { - upFocusCycle (comp); - e.consume (); - } - else if (comp instanceof Container - && downKeystrokes.contains (eventKeystroke)) - { - downFocusCycle ((Container) comp); - e.consume (); - } - else if (forwardKeystrokes.contains (oppositeKeystroke) - || backwardKeystrokes.contains (oppositeKeystroke) - || upKeystrokes.contains (oppositeKeystroke) - || (comp instanceof Container && - downKeystrokes.contains (oppositeKeystroke))) - e.consume (); - } - - protected void enqueueKeyEvents (long after, Component untilFocused) - { - delayRequests.add (new EventDelayRequest (after, untilFocused)); - } - - protected void dequeueKeyEvents (long after, Component untilFocused) - { - // FIXME: need synchronization on delayRequests and enqueuedKeyEvents. - - // Remove the KeyEvent with the oldest timestamp, which should be - // the first element in the SortedSet. - if (after < 0) - { - int size = delayRequests.size (); - if (size > 0) - delayRequests.remove (delayRequests.first ()); - } - else - { - EventDelayRequest template = new EventDelayRequest (after, untilFocused); - if (delayRequests.contains (template)) - { - EventDelayRequest actual = (EventDelayRequest) delayRequests.tailSet (template).first (); - delayRequests.remove (actual); - actual.dispatchEvents (); - } - } - } - - protected void discardKeyEvents (Component comp) - { - // FIXME: need synchronization on delayRequests and enqueuedKeyEvents. - - Iterator i = delayRequests.iterator (); - - while (i.hasNext ()) - { - EventDelayRequest request = (EventDelayRequest) i.next (); - - if (request.focusedComp == comp - || (comp instanceof Container - && ((Container) comp).isAncestorOf (request.focusedComp))) - request.discardEvents (); - } - } - - public void focusPreviousComponent (Component comp) - { - Component focusComp = (comp == null) ? getGlobalFocusOwner () : comp; - Container focusCycleRoot = focusComp.getFocusCycleRootAncestor (); - FocusTraversalPolicy policy = focusCycleRoot.getFocusTraversalPolicy (); - - Component previous = policy.getComponentBefore (focusCycleRoot, focusComp); - if (previous != null) - previous.requestFocusInWindow (); - } - - public void focusNextComponent (Component comp) - { - Component focusComp = (comp == null) ? getGlobalFocusOwner () : comp; - Container focusCycleRoot = focusComp.getFocusCycleRootAncestor (); - FocusTraversalPolicy policy = focusCycleRoot.getFocusTraversalPolicy (); - - Component next = policy.getComponentAfter (focusCycleRoot, focusComp); - if (next != null) - next.requestFocusInWindow (); - } - - public void upFocusCycle (Component comp) - { - Component focusComp = (comp == null) ? getGlobalFocusOwner () : comp; - Container focusCycleRoot = focusComp.getFocusCycleRootAncestor (); - - if (focusCycleRoot instanceof Window) - { - FocusTraversalPolicy policy = focusCycleRoot.getFocusTraversalPolicy (); - Component defaultComponent = policy.getDefaultComponent (focusCycleRoot); - if (defaultComponent != null) - defaultComponent.requestFocusInWindow (); - } - else - { - Container parentFocusCycleRoot = focusCycleRoot.getFocusCycleRootAncestor (); - - focusCycleRoot.requestFocusInWindow (); - setGlobalCurrentFocusCycleRoot (parentFocusCycleRoot); - } - } - - public void downFocusCycle (Container cont) - { - if (cont == null) - return; - - if (cont.isFocusCycleRoot (cont)) - { - FocusTraversalPolicy policy = cont.getFocusTraversalPolicy (); - Component defaultComponent = policy.getDefaultComponent (cont); - if (defaultComponent != null) - defaultComponent.requestFocusInWindow (); - setGlobalCurrentFocusCycleRoot (cont); - } - } -} // class DefaultKeyboardFocusManager diff --git a/libjava/java/awt/Dialog.java b/libjava/java/awt/Dialog.java deleted file mode 100644 index d3eb975a86d..00000000000 --- a/libjava/java/awt/Dialog.java +++ /dev/null @@ -1,553 +0,0 @@ -/* Dialog.java -- An AWT dialog box - Copyright (C) 1999, 2000, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.awt.peer.DialogPeer; - -import javax.accessibility.AccessibleContext; -import javax.accessibility.AccessibleRole; -import javax.accessibility.AccessibleState; -import javax.accessibility.AccessibleStateSet; - -/** - * A dialog box widget class. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Tom Tromey (tromey@redhat.com) - */ -public class Dialog extends Window -{ - -/* - * Static Variables - */ - -// Serialization constant -private static final long serialVersionUID = 5920926903803293709L; - -/*************************************************************************/ - -/* - * Instance Variables - */ - -/** - * @serial Indicates whether or not this dialog box is modal. - */ -private boolean modal; - -/** - * @serial Indicates whether or not this dialog box is resizable. - */ -private boolean resizable = true; - -/** - * @serial The title string for this dialog box, which can be - * <code>null</code>. - */ -private String title; - -/** - * This field indicates whether the dialog is undecorated or not. - */ -private boolean undecorated = false; - -/** - * Indicates that we are blocked for modality in show - */ -private boolean blocked = false; - -/** - * Secondary EventQueue to handle AWT events while - * we are blocked for modality in show - */ -private EventQueue eq2 = null; - -/*************************************************************************/ - -/* - * Constructors - */ - -/** - * Initializes a new instance of <code>Dialog</code> with the specified - * parent, that is resizable and not modal, and which has no title. - * - * @param parent The parent frame of this dialog box. - * - * @exception IllegalArgumentException If the owner's GraphicsConfiguration - * is not from a screen device, or if owner is null. This exception is always - * thrown when GraphicsEnvironment.isHeadless() returns true. - */ -public -Dialog(Frame parent) -{ - this(parent, "", false); -} - -/*************************************************************************/ - -/** - * Initializes a new instance of <code>Dialog</code> with the specified - * parent and modality, that is resizable and which has no title. - * - * @param parent The parent frame of this dialog box. - * @param modal <code>true</code> if this dialog box is modal, - * <code>false</code> otherwise. - * - * @exception IllegalArgumentException If the owner's GraphicsConfiguration - * is not from a screen device, or if owner is null. This exception is always - * thrown when GraphicsEnvironment.isHeadless() returns true. - */ -public -Dialog(Frame parent, boolean modal) -{ - this(parent, "", modal); -} - -/*************************************************************************/ - -/** - * Initializes a new instance of <code>Dialog</code> with the specified - * parent, that is resizable and not modal, and which has the specified - * title. - * - * @param parent The parent frame of this dialog box. - * @param title The title string for this dialog box. - * - * @exception IllegalArgumentException If the owner's GraphicsConfiguration - * is not from a screen device, or if owner is null. This exception is always - * thrown when GraphicsEnvironment.isHeadless() returns true. - */ -public -Dialog(Frame parent, String title) -{ - this(parent, title, false); -} - -/*************************************************************************/ - -/** - * Initializes a new instance of <code>Dialog</code> with the specified, - * parent, title, and modality, that is resizable. - * - * @param parent The parent frame of this dialog box. - * @param title The title string for this dialog box. - * @param modal <code>true</code> if this dialog box is modal, - * <code>false</code> otherwise. - * - * @exception IllegalArgumentException If owner is null or - * GraphicsEnvironment.isHeadless() returns true. - */ -public -Dialog(Frame parent, String title, boolean modal) -{ - this (parent, title, modal, parent.getGraphicsConfiguration ()); -} - -/** - * Initializes a new instance of <code>Dialog</code> with the specified, - * parent, title, modality and <code>GraphicsConfiguration</code>, - * that is resizable. - * - * @param parent The parent frame of this dialog box. - * @param title The title string for this dialog box. - * @param modal <code>true</code> if this dialog box is modal, - * <code>false</code> otherwise. - * @param gc The <code>GraphicsConfiguration</code> object to use. - * - * @exception IllegalArgumentException If owner is null, the - * GraphicsConfiguration is not a screen device or - * GraphicsEnvironment.isHeadless() returns true. - * - * @since 1.4 - */ -public -Dialog (Frame parent, String title, boolean modal, GraphicsConfiguration gc) -{ - super (parent, gc); - - // A null title is equivalent to an empty title - this.title = (title != null) ? title : ""; - this.modal = modal; - visible = false; - - setLayout(new BorderLayout()); -} - -/** - * Initializes a new instance of <code>Dialog</code> with the specified, - * parent, that is resizable. - * - * @exception IllegalArgumentException If parent is null. This exception is - * always thrown when GraphicsEnvironment.isHeadless() returns true. - * - * @since 1.2 - */ -public -Dialog (Dialog owner) -{ - this (owner, "", false, owner.getGraphicsConfiguration ()); -} - -/** - * Initializes a new instance of <code>Dialog</code> with the specified, - * parent and title, that is resizable. - * - * @exception IllegalArgumentException If parent is null. This exception is - * always thrown when GraphicsEnvironment.isHeadless() returns true. - * - * @since 1.2 - */ -public -Dialog (Dialog owner, String title) -{ - this (owner, title, false, owner.getGraphicsConfiguration ()); -} - -/** - * Initializes a new instance of <code>Dialog</code> with the specified, - * parent, title and modality, that is resizable. - * - * @exception IllegalArgumentException If parent is null. This exception is - * always thrown when GraphicsEnvironment.isHeadless() returns true. - * - * @since 1.2 - */ -public -Dialog (Dialog owner, String title, boolean modal) -{ - this (owner, title, modal, owner.getGraphicsConfiguration ()); -} - -/** - * Initializes a new instance of <code>Dialog</code> with the specified, - * parent, title, modality and <code>GraphicsConfiguration</code>, - * that is resizable. - * - * @exception IllegalArgumentException If parent is null, the - * GraphicsConfiguration is not a screen device or - * GraphicsEnvironment.isHeadless() returns true. - * - * @since 1.4 - */ -public -Dialog (Dialog parent, String title, boolean modal, GraphicsConfiguration gc) -{ - super (parent, parent.getGraphicsConfiguration ()); - - // A null title is equivalent to an empty title - this.title = (title != null) ? title : ""; - this.modal = modal; - visible = false; - - setLayout (new BorderLayout ()); -} - -/*************************************************************************/ - -/* - * Instance Variables - */ - -/** - * Returns the title of this dialog box. - * - * @return The title of this dialog box. - */ -public String -getTitle() -{ - return(title); -} - -/*************************************************************************/ - -/** - * Sets the title of this dialog box to the specified string. - * - * @param title The new title. - */ -public synchronized void -setTitle(String title) -{ - // A null title is equivalent to an empty title - this.title = (title != null) ? title : ""; - - if (peer != null) - { - DialogPeer d = (DialogPeer) peer; - d.setTitle (title); - } -} - -/*************************************************************************/ - -/** - * Tests whether or not this dialog box is modal. - * - * @return <code>true</code> if this dialog box is modal, - * <code>false</code> otherwise. - */ -public boolean -isModal() -{ - return(modal); -} - -/*************************************************************************/ - -/** - * Changes the modality of this dialog box. This can only be done before - * the peer is created. - * - * @param modal <code>true</code> to make this dialog box modal, - * <code>false</code> to make it non-modal. - */ -public void -setModal(boolean modal) -{ - this.modal = modal; -} - -/*************************************************************************/ - -/** - * Tests whether or not this dialog box is resizable. - * - * @return <code>true</code> if this dialog is resizable, <code>false</code>, - * otherwise. - */ -public boolean -isResizable() -{ - return(resizable); -} - -/*************************************************************************/ - -/** - * Changes the resizability of this dialog box. - * - * @param resizable <code>true</code> to make this dialog resizable, - * <code>false</code> to make it non-resizable. - */ -public synchronized void -setResizable(boolean resizable) -{ - this.resizable = resizable; - if (peer != null) - { - DialogPeer d = (DialogPeer) peer; - d.setResizable (resizable); - } -} - -/*************************************************************************/ - -/** - * Creates this object's native peer. - */ -public synchronized void -addNotify() -{ - if (peer == null) - peer = getToolkit ().createDialog (this); - super.addNotify (); -} - -/*************************************************************************/ - -/** - * Makes this dialog visible and brings it to the front. - * If the dialog is modal and is not already visible, this call will not - * return until the dialog is hidden by someone calling hide or dispose. - * If this is the event dispatching thread we must ensure that another event - * thread runs while the one which invoked this method is blocked. - */ -public synchronized void -show() -{ - super.show(); - - if (isModal()) - { - // If already shown (and blocked) just return - if (blocked) - return; - - /* If show is called in the dispatch thread for a modal dialog it will - block so we must run another thread so the events keep being - dispatched.*/ - if (EventQueue.isDispatchThread ()) - { - EventQueue eq = Toolkit.getDefaultToolkit().getSystemEventQueue(); - eq2 = new EventQueue (); - eq.push (eq2); - } - - try - { - blocked = true; - wait (); - blocked = false; - } - catch (InterruptedException e) - { - blocked = false; - } - - if (eq2 != null) - { - eq2.pop (); - eq2 = null; - } - } -} - -/*************************************************************************/ - -/** - * Hides the Dialog and then - * causes show() to return if it is currently blocked. - */ - -public synchronized void -hide () -{ - if (blocked) - { - notifyAll (); - } - - super.hide(); -} - -/*************************************************************************/ - -/** - * Disposes the Dialog and then causes show() to return - * if it is currently blocked. - */ - -public synchronized void -dispose () -{ - if (blocked) - { - notifyAll (); - } - - super.dispose(); -} - -/*************************************************************************/ - -/** - * Returns a debugging string for this component. - * - * @return A debugging string for this component. - */ -protected String -paramString() -{ - return ("title+" + title + ",modal=" + modal + - ",resizable=" + resizable + "," + super.paramString()); -} - - /** - * Returns whether this frame is undecorated or not. - * - * @since 1.4 - */ - public boolean isUndecorated () - { - return undecorated; - } - - /** - * Disables or enables decorations for this frame. This method can only be - * called while the frame is not displayable. - * - * @exception IllegalComponentStateException If this frame is displayable. - * - * @since 1.4 - */ - public void setUndecorated (boolean undecorated) - { - if (isDisplayable ()) - throw new IllegalComponentStateException (); - - this.undecorated = undecorated; - } - - protected class AccessibleAWTDialog extends AccessibleAWTWindow - { - public AccessibleRole getAccessibleRole() - { - return AccessibleRole.DIALOG; - } - - public AccessibleStateSet getAccessibleState() - { - AccessibleStateSet states = super.getAccessibleStateSet(); - if (isResizable()) - states.add(AccessibleState.RESIZABLE); - if (isModal()) - states.add(AccessibleState.MODAL); - return states; - } - } - - /** - * Gets the AccessibleContext associated with this <code>Dialog</code>. - * The context is created, if necessary. - * - * @return the associated context - */ - public AccessibleContext getAccessibleContext() - { - /* Create the context if this is the first request */ - if (accessibleContext == null) - accessibleContext = new AccessibleAWTDialog(); - return accessibleContext; - } - -} // class Dialog - diff --git a/libjava/java/awt/Dimension.java b/libjava/java/awt/Dimension.java deleted file mode 100644 index 4c1a07bf920..00000000000 --- a/libjava/java/awt/Dimension.java +++ /dev/null @@ -1,234 +0,0 @@ -/* Dimension.java -- represents a 2-dimensional span - Copyright (C) 1999, 2000, 2002 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.awt.geom.Dimension2D; -import java.io.Serializable; - -/** - * This class holds a width and height value pair. This is used in plenty - * of windowing classes, but also has geometric meaning. - * - * <p>It is valid for a dimension to have negative width or height; but it - * is considered to have no area. Therefore, the behavior in various methods - * is undefined in such a case. - * - * <p>There are some public fields; if you mess with them in an inconsistent - * manner, it is your own fault when you get invalid results. Also, this - * class is not threadsafe. - * - * @author Per Bothner (bothner@cygnus.com) - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Eric Blake (ebb9@email.byu.edu) - * @see Component - * @see LayoutManager - * @since 1.0 - * @status updated to 1.14 - */ -public class Dimension extends Dimension2D implements Serializable -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = 4723952579491349524L; - - /** - * The width of this object. - * - * @see #getSize() - * @see #setSize(double, double) - * @serial the width - */ - public int width; - - /** - * The height of this object. - * - * @see #getSize() - * @see #setSize(double, double) - * @serial the height - */ - public int height; - - /** - * Create a new Dimension with a width and height of zero. - */ - public Dimension() - { - } - - /** - * Create a new Dimension with width and height identical to that of the - * specified dimension. - * - * @param d the Dimension to copy - * @throws NullPointerException if d is null - */ - public Dimension(Dimension d) - { - width = d.width; - height = d.height; - } - - /** - * Create a new Dimension with the specified width and height. - * - * @param w the width of this object - * @param h the height of this object - */ - public Dimension(int w, int h) - { - width = w; - height = h; - } - - /** - * Gets the width of this dimension. - * - * @return the width, as a double - */ - public double getWidth() - { - return width; - } - - /** - * Gets the height of this dimension. - * - * @return the height, as a double - */ - public double getHeight() - { - return height; - } - - /** - * Sets the size of this dimension. The values are rounded to int. - * - * @param w the new width - * @param h the new height - * @since 1.2 - */ - public void setSize(double w, double h) - { - width = (int) w; - height = (int) h; - } - - /** - * Returns the size of this dimension. A pretty useless method, as this is - * already a dimension. - * - * @return a copy of this dimension - * @see #setSize(Dimension) - * @since 1.1 - */ - public Dimension getSize() - { - return new Dimension(width, height); - } - - /** - * Sets the width and height of this object to match that of the - * specified object. - * - * @param d the Dimension to get the new width and height from - * @throws NullPointerException if d is null - * @see #getSize() - * @since 1.1 - */ - public void setSize(Dimension d) - { - width = d.width; - height = d.height; - } - - /** - * Sets the width and height of this object to the specified values. - * - * @param w the new width value - * @param h the new height value - */ - public void setSize(int w, int h) - { - width = w; - height = h; - } - - /** - * Tests this object for equality against the specified object. This will - * be true if and only if the specified object is an instance of - * Dimension2D, and has the same width and height. - * - * @param obj the object to test against - * @return true if the object is equal to this - */ - public boolean equals(Object obj) - { - if (! (obj instanceof Dimension)) - return false; - Dimension dim = (Dimension) obj; - return height == dim.height && width == dim.width; - } - - /** - * Return the hashcode for this object. It is not documented, but appears - * to be <code>((width + height) * (width + height + 1) / 2) + width</code>. - * - * @return the hashcode - */ - public int hashCode() - { - // Reverse engineering this was fun! - return (width + height) * (width + height + 1) / 2 + width; - } - - /** - * Returns a string representation of this object. The format is: - * <code>getClass().getName() + "[width=" + width + ",height=" + height - * + ']'</code>. - * - * @return a string representation of this object - */ - public String toString() - { - return getClass().getName() - + "[width=" + width + ",height=" + height + ']'; - } -} // class Dimension diff --git a/libjava/java/awt/DisplayMode.java b/libjava/java/awt/DisplayMode.java deleted file mode 100644 index d41d4a87f57..00000000000 --- a/libjava/java/awt/DisplayMode.java +++ /dev/null @@ -1,164 +0,0 @@ -/* DisplayMode.java -- a description of display mode configurations - Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -/** - * This encapsulates information about the display mode for a graphics - * device configuration. They are device dependent, and may not always be - * available. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @see GraphicsDevice - * @since 1.4 - * @status updated to 1.4 - */ -public final class DisplayMode -{ - /** - * Value of the bit depth if multiple depths are supported. - * - * @see #getBitDepth() - */ - public static final int BIT_DEPTH_MULTI = -1; - - /** - * Value of an unknown refresh rate. - * - * @see #getRefreshRate() - */ - public static final int REFRESH_RATE_UNKNOWN = 0; - - /** The width. */ - private final int width; - - /** The height. */ - private final int height; - - /** The bit depth. */ - private final int bitDepth; - - /** The refresh rate. */ - private final int refreshRate; - - /** - * Create a mode with the given parameters. - * - * @param width the width - * @param height the height - * @param bitDepth the bitDepth - * @param refreshRate the refreshRate - * @see #BIT_DEPTH_MULTI - * @see #REFRESH_RATE_UNKNOWN - */ - public DisplayMode(int width, int height, int bitDepth, int refreshRate) - { - this.width = width; - this.height = height; - this.bitDepth = bitDepth; - this.refreshRate = refreshRate; - } - - /** - * Returns the height, in pixels. - * - * @return the height - */ - public int getHeight() - { - return height; - } - - /** - * Returns the width, in pixels. - * - * @return the width - */ - public int getWidth() - { - return width; - } - - /** - * Returns the bit depth, in bits per pixel. This may be BIT_DEPTH_MULTI. - * - * @return the bit depth - * @see #BIT_DEPTH_MULTI - */ - public int getBitDepth() - { - return bitDepth; - } - - /** - * Returns the refresh rate, in hertz. This may be REFRESH_RATE_UNKNOWN. - * - * @return the refresh rate - * @see #REFRESH_RATE_UNKNOWN - */ - public int getRefreshRate() - { - return refreshRate; - } - - /** - * Test for equality. This returns true for two modes with identical - * parameters. - * - * @param dm The display mode to compare to - * - * @return true if it is equal - */ - public boolean equals (DisplayMode dm) - { - return (width == dm.width - && height == dm.height - && bitDepth == dm.bitDepth - && refreshRate == dm.refreshRate); - } - - /** - * Returns a hash code for the display mode. - * - * @return the hash code - */ - public int hashCode() - { - return width + height + bitDepth + refreshRate; - } -} // class DisplayMode diff --git a/libjava/java/awt/Event.java b/libjava/java/awt/Event.java deleted file mode 100644 index 648139cc850..00000000000 --- a/libjava/java/awt/Event.java +++ /dev/null @@ -1,185 +0,0 @@ -/* Copyright (C) 1999, 2000, 2002 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -/** - * Written using on-line Java Platform 1.2 API Specification, as well - * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998). - * Status: Believed complete and correct. - */ - -public class Event implements java.io.Serializable -{ - static final long serialVersionUID = 5488922509400504703L; - - public static final int SHIFT_MASK = 1; - public static final int CTRL_MASK = 2; - public static final int META_MASK = 4; - public static final int ALT_MASK = 8; - - public static final int ACTION_EVENT = 1001; - public static final int BACK_SPACE = 8; - public static final int CAPS_LOCK = 1022; - public static final int DELETE = 127; - public static final int DOWN = 1005; - public static final int END = 1001; - public static final int ENTER = 10; - public static final int ESCAPE = 27; - public static final int F1 = 1008; - public static final int F10 = 1017; - public static final int F11 = 1018; - public static final int F12 = 1019; - public static final int F2 = 1009; - public static final int F3 = 1010; - public static final int F4 = 1011; - public static final int F5 = 1012; - public static final int F6 = 1013; - public static final int F7 = 1014; - public static final int F8 = 1015; - public static final int F9 = 1016; - public static final int GOT_FOCUS = 1004; - public static final int HOME = 1000; - public static final int INSERT = 1025; - public static final int KEY_ACTION = 403; - public static final int KEY_ACTION_RELEASE = 404; - public static final int KEY_PRESS = 401; - public static final int KEY_RELEASE = 402; - public static final int LEFT = 1006; - public static final int LIST_DESELECT = 702; - public static final int LIST_SELECT = 701; - public static final int LOAD_FILE = 1002; - public static final int LOST_FOCUS = 1005; - public static final int MOUSE_DOWN = 501; - public static final int MOUSE_DRAG = 506; - public static final int MOUSE_ENTER = 504; - public static final int MOUSE_EXIT = 505; - public static final int MOUSE_MOVE = 503; - public static final int MOUSE_UP = 502; - public static final int NUM_LOCK = 1023; - public static final int PAUSE = 1024; - public static final int PGDN = 1003; - public static final int PGUP = 1002; - public static final int PRINT_SCREEN = 1020; - public static final int RIGHT = 1007; - public static final int SAVE_FILE = 1003; - public static final int SCROLL_ABSOLUTE = 605; - public static final int SCROLL_BEGIN = 606; - public static final int SCROLL_END = 607; - public static final int SCROLL_LINE_DOWN = 602; - public static final int SCROLL_LINE_UP = 601; - public static final int SCROLL_LOCK = 1021; - public static final int SCROLL_PAGE_DOWN = 604; - public static final int SCROLL_PAGE_UP = 603; - public static final int TAB = 9; - public static final int UP = 1004; - public static final int WINDOW_DEICONIFY = 204; - public static final int WINDOW_DESTROY = 201; - public static final int WINDOW_EXPOSE = 202; - public static final int WINDOW_ICONIFY = 203; - public static final int WINDOW_MOVED = 205; - - public Object arg; - public int clickCount; - boolean consumed; // Required by serialization spec. - public Event evt; - public int id; - public int key; - public int modifiers; - public Object target; - public long when; - public int x; - public int y; - - public Event (Object target, int id, Object arg) - { - this.id = id; - this.target = target; - this.arg = arg; - } - - public Event (Object target, long when, int id, int x, int y, int key, - int modifiers) - { - this.target = target; - this.when = when; - this.id = id; - this.x = x; - this.y = y; - this.key = key; - this.modifiers = modifiers; - } - - public Event (Object target, long when, int id, int x, int y, int key, - int modifiers, Object arg) - { - this (target, when, id, x, y, key, modifiers); - this.arg = arg; - } - - public boolean controlDown () - { - return ((modifiers & CTRL_MASK) == 0 ? false : true); - } - - public boolean metaDown () - { - return ((modifiers & META_MASK) == 0 ? false : true); - } - - protected String paramString () - { - return "id=" + id + ",x=" + x + ",y=" + y - + ",target=" + target + ",arg=" + arg; - } - - public boolean shiftDown() - { - return ((modifiers & SHIFT_MASK) == 0 ? false : true); - } - - public String toString() - { - return getClass().getName() + "[" + paramString() + "]"; - } - - public void translate (int x, int y) - { - this.x += x; - this.y += y; - } -} diff --git a/libjava/java/awt/EventDispatchThread.java b/libjava/java/awt/EventDispatchThread.java deleted file mode 100644 index a64cdae8567..00000000000 --- a/libjava/java/awt/EventDispatchThread.java +++ /dev/null @@ -1,94 +0,0 @@ -/* EventDispatchThread.java - - Copyright (C) 2000, 2002, 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.awt; - -/** - * @author Bryce McKinlay - * @status believed complete, but untested. - */ -class EventDispatchThread extends Thread -{ - private static int dispatchThreadNum; - - private EventQueue queue; - - EventDispatchThread(EventQueue queue) - { - super(); - setName("AWT-EventQueue-" + ++dispatchThreadNum); - this.queue = queue; - setPriority(NORM_PRIORITY + 1); - } - - public void run() - { - while (true) - { - try - { - AWTEvent evt = queue.getNextEvent(); - - KeyboardFocusManager manager; - manager = KeyboardFocusManager.getCurrentKeyboardFocusManager (); - - // Try to dispatch this event to the current keyboard focus - // manager. It will dispatch all FocusEvents, all - // WindowEvents related to focus, and all KeyEvents, - // returning true. Otherwise, it returns false and we - // dispatch the event normally. - if (!manager.dispatchEvent (evt)) - queue.dispatchEvent(evt); - } - catch (ThreadDeath death) - { - // If someone wants to kill us, let them. - return; - } - catch (InterruptedException ie) - { - // We are interrupted when we should finish executing - return; - } - catch (Throwable x) - { - System.err.println("Exception during event dispatch:"); - x.printStackTrace(System.err); - } - } - } -} diff --git a/libjava/java/awt/EventQueue.java b/libjava/java/awt/EventQueue.java deleted file mode 100644 index f5b67f3a999..00000000000 --- a/libjava/java/awt/EventQueue.java +++ /dev/null @@ -1,551 +0,0 @@ -/* EventQueue.java -- - Copyright (C) 1999, 2000, 2001, 2002, 2003, 2005 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import gnu.java.awt.ClasspathToolkit; - -import java.awt.event.ActionEvent; -import java.awt.event.InputEvent; -import java.awt.event.InvocationEvent; -import java.awt.event.WindowEvent; -import java.lang.reflect.InvocationTargetException; -import java.util.EmptyStackException; - -/* Written using on-line Java 2 Platform Standard Edition v1.3 API - * Specification, as well as "The Java Class Libraries", 2nd edition - * (Addison-Wesley, 1998). - * Status: Believed complete, but untested. - */ - -/** - * This class manages a queue of <code>AWTEvent</code> objects that - * are posted to it. The AWT system uses only one event queue for all - * events. - * - * @author Bryce McKinlay - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public class EventQueue -{ - private static final int INITIAL_QUEUE_DEPTH = 8; - private AWTEvent[] queue = new AWTEvent[INITIAL_QUEUE_DEPTH]; - - private int next_in = 0; // Index where next event will be added to queue - private int next_out = 0; // Index of next event to be removed from queue - - private EventQueue next; - private EventQueue prev; - private AWTEvent currentEvent; - private long lastWhen = System.currentTimeMillis(); - - private EventDispatchThread dispatchThread = new EventDispatchThread(this); - private boolean shutdown = false; - - private long lastNativeQueueAccess = 0; - private long humanLatencyThreshold = 100; - - synchronized void setShutdown (boolean b) - { - shutdown = b; - } - - synchronized boolean isShutdown () - { - if (shutdown) - return true; - - // This is the exact self-shutdown condition specified in J2SE: - // http://java.sun.com/j2se/1.4.2/docs/api/java/awt/doc-files/AWTThreadIssues.html - - if (peekEvent() == null - && ((ClasspathToolkit) Toolkit.getDefaultToolkit()).nativeQueueEmpty()) - { - Frame[] frames = Frame.getFrames(); - for (int i = 0; i < frames.length; ++i) - if (frames[i].isDisplayable()) - return false; - return true; - } - return false; - } - - /** - * Initializes a new instance of <code>EventQueue</code>. - */ - public EventQueue() - { - } - - /** - * Returns the next event in the queue. This method will block until - * an event is available or until the thread is interrupted. - * - * @return The next event in the queue. - * - * @exception InterruptedException If this thread is interrupted while - * waiting for an event to be posted to the queue. - */ - public synchronized AWTEvent getNextEvent() - throws InterruptedException - { - if (next != null) - return next.getNextEvent(); - - ClasspathToolkit tk = ((ClasspathToolkit) Toolkit.getDefaultToolkit()); - long curr = System.currentTimeMillis(); - - if (! tk.nativeQueueEmpty() && - (curr - lastNativeQueueAccess > humanLatencyThreshold)) - { - tk.iterateNativeQueue(this, false); - lastNativeQueueAccess = curr; - } - - while (next_in == next_out) - { - // Only the EventDispatchThread associated with the top of the stack is - // allowed to get events from the native source; everyone else just - // waits on the head of the queue. - - if (isDispatchThread()) - { - // We are not allowed to return null from this method, yet it - // is possible that we actually have run out of native events - // in the enclosing while() loop, and none of the native events - // happened to cause AWT events. We therefore ought to check - // the isShutdown() condition here, before risking a "native - // wait". If we check it before entering this function we may - // wait forever for events after the shutdown condition has - // arisen. - - if (isShutdown()) - throw new InterruptedException(); - - tk.iterateNativeQueue(this, true); - lastNativeQueueAccess = System.currentTimeMillis(); - } - else - { - try - { - wait(); - } - catch (InterruptedException ie) - { - } - } - } - - AWTEvent res = queue[next_out]; - - if (++next_out == queue.length) - next_out = 0; - return res; - } - - /** - * Returns the next event in the queue without removing it from the queue. - * This method will block until an event is available or until the thread - * is interrupted. - * - * @return The next event in the queue. - * @specnote Does not block. Returns null if there are no events on the - * queue. - */ - public synchronized AWTEvent peekEvent() - { - if (next != null) - return next.peekEvent(); - - if (next_in != next_out) - return queue[next_out]; - else - return null; - } - - /** - * Returns the next event in the queue that has the specified id - * without removing it from the queue. - * This method will block until an event is available or until the thread - * is interrupted. - * - * @param id The event id to return. - * - * @return The next event in the queue. - * - * @specnote Does not block. Returns null if there are no matching events - * on the queue. - */ - public synchronized AWTEvent peekEvent(int id) - { - if (next != null) - return next.peekEvent(id); - - int i = next_out; - while (i != next_in) - { - AWTEvent qevt = queue[i]; - if (qevt.id == id) - return qevt; - } - return null; - } - - /** - * Posts a new event to the queue. - * - * @param evt The event to post to the queue. - * - * @exception NullPointerException If event is null. - */ - public synchronized void postEvent(AWTEvent evt) - { - if (evt == null) - throw new NullPointerException(); - - if (next != null) - { - next.postEvent(evt); - return; - } - - /* Check for any events already on the queue with the same source - and ID. */ - int i = next_out; - while (i != next_in) - { - AWTEvent qevt = queue[i]; - Object src; - if (qevt.id == evt.id - && (src = qevt.getSource()) == evt.getSource() - && src instanceof Component) - { - /* If there are, call coalesceEvents on the source component - to see if they can be combined. */ - Component srccmp = (Component) src; - AWTEvent coalesced_evt = srccmp.coalesceEvents(qevt, evt); - if (coalesced_evt != null) - { - /* Yes. Replace the existing event with the combined event. */ - queue[i] = coalesced_evt; - return; - } - break; - } - if (++i == queue.length) - i = 0; - } - - queue[next_in] = evt; - if (++next_in == queue.length) - next_in = 0; - - if (next_in == next_out) - { - /* Queue is full. Extend it. */ - AWTEvent[] oldQueue = queue; - queue = new AWTEvent[queue.length * 2]; - - int len = oldQueue.length - next_out; - System.arraycopy(oldQueue, next_out, queue, 0, len); - if (next_out != 0) - System.arraycopy(oldQueue, 0, queue, len, next_out); - - next_out = 0; - next_in = oldQueue.length; - } - - if (dispatchThread == null || !dispatchThread.isAlive()) - { - dispatchThread = new EventDispatchThread(this); - dispatchThread.start(); - } - - // Window events might represent the closing of a window, which - // might cause the end of the dispatch thread's life, so we'll wake - // it up here to give it a chance to check for shutdown. - - if (!isDispatchThread() - || (evt.getID() == WindowEvent.WINDOW_CLOSED) - || (evt.getID() == WindowEvent.WINDOW_CLOSING)) - ((ClasspathToolkit) Toolkit.getDefaultToolkit()).wakeNativeQueue(); - - notify(); - } - - /** - * Causes runnable to have its run method called in the dispatch thread of the - * EventQueue. This will happen after all pending events are processed. The - * call blocks until this has happened. This method will throw an Error if - * called from the event dispatcher thread. - * - * @exception InterruptedException If another thread has interrupted - * this thread. - * @exception InvocationTargetException If an exception is thrown when running - * runnable. - * - * @since 1.2 - */ - public static void invokeAndWait(Runnable runnable) - throws InterruptedException, InvocationTargetException - { - if (isDispatchThread ()) - throw new Error("Can't call invokeAndWait from event dispatch thread"); - - EventQueue eq = Toolkit.getDefaultToolkit().getSystemEventQueue(); - Thread current = Thread.currentThread(); - - InvocationEvent ie = - new InvocationEvent(eq, runnable, current, true); - - synchronized (current) - { - eq.postEvent(ie); - current.wait(); - } - - Exception exception; - - if ((exception = ie.getException()) != null) - throw new InvocationTargetException(exception); - } - - /** - * This arranges for runnable to have its run method called in the - * dispatch thread of the EventQueue. This will happen after all - * pending events are processed. - * - * @since 1.2 - */ - public static void invokeLater(Runnable runnable) - { - EventQueue eq = Toolkit.getDefaultToolkit().getSystemEventQueue(); - - InvocationEvent ie = - new InvocationEvent(eq, runnable, null, false); - - eq.postEvent(ie); - } - - /** - * Return true if the current thread is the current AWT event dispatch - * thread. - */ - public static boolean isDispatchThread() - { - EventQueue eq = Toolkit.getDefaultToolkit().getSystemEventQueue(); - - /* Find last EventQueue in chain */ - while (eq.next != null) - eq = eq.next; - - return (Thread.currentThread() == eq.dispatchThread); - } - - /** - * Return the event currently being dispatched by the event - * dispatch thread. If the current thread is not the event - * dispatch thread, this method returns null. - * - * @since 1.4 - */ - public static AWTEvent getCurrentEvent() - { - EventQueue eq = Toolkit.getDefaultToolkit().getSystemEventQueue(); - Thread ct = Thread.currentThread(); - - /* Find out if this thread is the dispatch thread for any of the - EventQueues in the chain */ - while (ct != eq.dispatchThread) - { - // Try next EventQueue, if any - if (eq.next == null) - return null; // Not an event dispatch thread - eq = eq.next; - } - - return eq.currentEvent; - } - - /** - * Allows a custom EventQueue implementation to replace this one. - * All pending events are transferred to the new queue. Calls to postEvent, - * getNextEvent, and peekEvent and others are forwarded to the pushed queue - * until it is removed with a pop(). - * - * @exception NullPointerException if newEventQueue is null. - */ - public synchronized void push(EventQueue newEventQueue) - { - if (newEventQueue == null) - throw new NullPointerException (); - - /* Make sure we are at the top of the stack because callers can - only get a reference to the one at the bottom using - Toolkit.getDefaultToolkit().getSystemEventQueue() */ - if (next != null) - { - next.push (newEventQueue); - return; - } - - /* Make sure we have a live dispatch thread to drive the queue */ - if (dispatchThread == null) - dispatchThread = new EventDispatchThread(this); - - int i = next_out; - while (i != next_in) - { - newEventQueue.postEvent(queue[i]); - next_out = i; - if (++i == queue.length) - i = 0; - } - - next = newEventQueue; - newEventQueue.prev = this; - } - - /** Transfer any pending events from this queue back to the parent queue that - * was previously push()ed. Event dispatch from this queue is suspended. - * - * @exception EmptyStackException If no previous push was made on this - * EventQueue. - */ - protected void pop() throws EmptyStackException - { - if (prev == null) - throw new EmptyStackException(); - - /* The order is important here, we must get the prev lock first, - or deadlock could occur as callers usually get here following - prev's next pointer, and thus obtain prev's lock before trying - to get this lock. */ - synchronized (prev) - { - prev.next = next; - if (next != null) - next.prev = prev; - - synchronized (this) - { - int i = next_out; - while (i != next_in) - { - prev.postEvent(queue[i]); - next_out = i; - if (++i == queue.length) - i = 0; - } - // Empty the queue so it can be reused - next_in = 0; - next_out = 0; - - ((ClasspathToolkit) Toolkit.getDefaultToolkit()).wakeNativeQueue(); - setShutdown(true); - dispatchThread = null; - this.notifyAll(); - } - } - } - - /** - * Dispatches an event. The manner in which the event is dispatched depends - * upon the type of the event and the type of the event's source object. - * - * @exception NullPointerException If event is null. - */ - protected void dispatchEvent(AWTEvent evt) - { - currentEvent = evt; - - if (evt instanceof InputEvent) - lastWhen = ((InputEvent) evt).getWhen(); - else if (evt instanceof ActionEvent) - lastWhen = ((ActionEvent) evt).getWhen(); - else if (evt instanceof InvocationEvent) - lastWhen = ((InvocationEvent) evt).getWhen(); - - if (evt instanceof ActiveEvent) - { - ActiveEvent active_evt = (ActiveEvent) evt; - active_evt.dispatch(); - } - else - { - Object source = evt.getSource(); - - if (source instanceof Component) - { - Component srccmp = (Component) source; - srccmp.dispatchEvent(evt); - } - else if (source instanceof MenuComponent) - { - MenuComponent srccmp = (MenuComponent) source; - srccmp.dispatchEvent(evt); - } - } - } - - /** - * Returns the timestamp of the most recent event that had a timestamp, or - * the initialization time of the event queue if no events have been fired. - * At present, only <code>InputEvent</code>s, <code>ActionEvent</code>s, - * <code>InputMethodEvent</code>s, and <code>InvocationEvent</code>s have - * timestamps, but this may be added to other events in future versions. - * If this is called by the event dispatching thread, it can be any - * (sequential) value, but to other threads, the safest bet is to return - * System.currentTimeMillis(). - * - * @return the most recent timestamp - * @see InputEvent#getWhen() - * @see ActionEvent#getWhen() - * @see InvocationEvent#getWhen() - * @see InputMethodEvent#getWhen() - * @since 1.4 - */ - public static long getMostRecentEventTime() - { - EventQueue eq = Toolkit.getDefaultToolkit().getSystemEventQueue(); - if (Thread.currentThread() != eq.dispatchThread) - return System.currentTimeMillis(); - return eq.lastWhen; - } -} diff --git a/libjava/java/awt/FileDialog.java b/libjava/java/awt/FileDialog.java deleted file mode 100644 index 7f2723e7e9a..00000000000 --- a/libjava/java/awt/FileDialog.java +++ /dev/null @@ -1,318 +0,0 @@ -/* FileDialog.java -- A filename selection dialog box - Copyright (C) 1999, 2000, 2001, 2002, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.awt.peer.FileDialogPeer; -import java.io.FilenameFilter; -import java.io.Serializable; - -/** - * This class implements a file selection dialog box widget. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Tom Tromey (tromey@redhat.com) - */ -public class FileDialog extends Dialog implements Serializable -{ - -/* - * Static Variables - */ - -/** - * Indicates that the purpose of the dialog is for opening a file. - */ -public static final int LOAD = 0; - -/** - * Indicates that the purpose of the dialog is for saving a file. - */ -public static final int SAVE = 1; - -// Serialization constant -private static final long serialVersionUID = 5035145889651310422L; - -/*************************************************************************/ - -/* - * Instance Variables - */ - -/** - * @serial The directory for this file dialog. - */ -private String dir; - -/** - * @serial The filename for this file dialog - */ -private String file; - -/** - * @serial The filter for selecting filenames to display - */ -private FilenameFilter filter; - -/** - * @serial The mode of this dialog, either <code>LOAD</code> or - * <code>SAVE</code>. - */ -private int mode; - -/*************************************************************************/ - -/* - * Constructors - */ - -/** - * Initializes a new instance of <code>FileDialog</code> with the - * specified parent. This dialog will have no title and will be for - * loading a file. - * - * @param parent The parent frame for this dialog. - */ -public -FileDialog(Frame parent) -{ - this(parent, "", LOAD); -} - -/*************************************************************************/ - -/** - * Initialized a new instance of <code>FileDialog</code> with the - * specified parent and title. This dialog will be for opening a file. - * - * @param parent The parent frame for this dialog. - * @param title The title for this dialog. - */ -public -FileDialog(Frame parent, String title) -{ - this(parent, title, LOAD); -} - -/*************************************************************************/ - -/** - * Initialized a new instance of <code>FileDialog</code> with the - * specified parent, title, and mode. - * - * @param parent The parent frame for this dialog. - * @param title The title for this dialog. - * @param mode The mode of the dialog, either <code>LOAD</code> or - * <code>SAVE</code>. - * - * @exception IllegalArgumentException If an illegal file dialog mode - * is supplied. - */ -public -FileDialog(Frame parent, String title, int mode) -{ - super(parent, title, true); - - if ((mode != LOAD) && (mode != SAVE)) - throw new IllegalArgumentException ( - "Mode argument must be either LOAD or SAVE"); - - setMode (mode); -} - -/*************************************************************************/ - -/* - * Instance Methods - */ - -/** - * Returns the mode of this dialog, either <code>LOAD</code> or - * <code>SAVE</code>. - * - * @return The mode of this dialog. - */ -public int -getMode() -{ - return(mode); -} - -/*************************************************************************/ - -/** - * Sets the mode of this dialog to either <code>LOAD</code> or - * <code>SAVE</code>. This method is only effective before the native - * peer is created. - * - * @param mode The new mode of this file dialog. - * - * @exception IllegalArgumentException If an illegal file dialog mode - * is supplied. - */ -public void -setMode(int mode) -{ - if ((mode != LOAD) && (mode != SAVE)) - throw new IllegalArgumentException("Bad mode: " + mode); - - this.mode = mode; -} - -/*************************************************************************/ - -/** - * Returns the directory for this file dialog. - * - * @return The directory for this file dialog. - */ -public String -getDirectory() -{ - return(dir); -} - -/*************************************************************************/ - -/** - * Sets the directory for this file dialog. - * - * @param dir The new directory for this file dialog. - */ -public synchronized void -setDirectory(String dir) -{ - this.dir = dir; - if (peer != null) - { - FileDialogPeer f = (FileDialogPeer) peer; - f.setDirectory (dir); - } -} - -/*************************************************************************/ - -/** - * Returns the file that is selected in this dialog. - * - * @return The file that is selected in this dialog. - */ -public String -getFile() -{ - return(file); -} - -/*************************************************************************/ - -/** - * Sets the selected file for this dialog. - * - * @param file The selected file for this dialog. - */ -public synchronized void -setFile(String file) -{ - this.file = file; - if (peer != null) - { - FileDialogPeer f = (FileDialogPeer) peer; - f.setFile (file); - } -} - -/*************************************************************************/ - -/** - * Returns the filename filter being used by this dialog. - * - * @return The filename filter being used by this dialog. - */ -public FilenameFilter -getFilenameFilter() -{ - return(filter); -} - -/*************************************************************************/ - -/** - * Sets the filename filter used by this dialog. - * - * @param filter The new filename filter for this file dialog box. - */ -public synchronized void -setFilenameFilter(FilenameFilter filter) -{ - this.filter = filter; - if (peer != null) - { - FileDialogPeer f = (FileDialogPeer) peer; - f.setFilenameFilter (filter); - } -} - -/*************************************************************************/ - -/** - * Creates the native peer for this file dialog box. - */ -public void -addNotify() -{ - if (peer == null) - peer = getToolkit ().createFileDialog (this); - super.addNotify (); -} - -/*************************************************************************/ - -/** - * Returns a debugging string for this object. - * - * @return A debugging string for this object. - */ -protected String -paramString() -{ - return ("dir=" + dir + ",file=" + file + - ",mode=" + mode + "," + super.paramString()); -} - -} // class FileDialog - diff --git a/libjava/java/awt/FlowLayout.java b/libjava/java/awt/FlowLayout.java deleted file mode 100644 index 4674990ac52..00000000000 --- a/libjava/java/awt/FlowLayout.java +++ /dev/null @@ -1,364 +0,0 @@ -/* FlowLayout.java -- Grid-based layout engine - Copyright (C) 1999, 2000, 2001, 2002, 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.io.Serializable; - -/** This class implements a flow-based layout. Components are laid - * out in order from left to right. When a component cannot be placed - * without horizontal clipping, a new row is started. This class - * supports horizontal and vertical gaps. These are used for spacing - * between components. - * - * @author Tom Tromey (tromey@redhat.com) - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public class FlowLayout implements LayoutManager, Serializable -{ - /** Constant that specifies left alignment. */ - public static final int LEFT = 0; - /** Constant that specifies center alignment. */ - public static final int CENTER = 1; - /** Constant that specifies right alignment. */ - public static final int RIGHT = 2; - - /** Constant that specifies alignment to leading edge of container's - * orientation. */ - public static final int LEADING = 3; - /** Constant that specifies alignment to trailing edge of container's - * orientation. */ - public static final int TRAILING = 4; - - // Serialization constant - private static final long serialVersionUID = -7262534875583282631L; - - /** - * Add a new component to the layout. This particular implementation - * does nothing. - * - * @param name the name - * @param comp the component - */ - public void addLayoutComponent (String name, Component comp) - { - // Nothing. - } - - /** - * Returns the current justification value for this object. - * - * @return The current justification value for this object. - */ - public int getAlignment () - { - return align; - } - - /** - * Returns the horizontal gap between components. - * - * @return The horizontal gap between components. - */ - public int getHgap () - { - return hgap; - } - - /** - * Returns the vertical gap between lines of components. - * - * @return The vertical gap between lines of components. - */ - public int getVgap () - { - return vgap; - } - - /** - * Initializes a new instance of <code>FlowLayout</code> with a center - * justification and a default horizontal and vertical gap of 5. - */ - public FlowLayout () - { - this (CENTER, 5, 5); - } - - /** - * Initializes a new instance of <code>FlowLayout</code> with the specified - * justification and a default horizontal and vertical gap of 5. - * - * @param align The justification setting, which should be one of the - * contants in this class. - */ - public FlowLayout (int align) - { - this (align, 5, 5); - } - - /** - * Initializes a new instance of <code>FlowLayout</code> with the specified - * justification and gap values - * @param align Alignment - * @param hgap The horizontal gap - * @param vgap The vertical gap - * @exception IllegalArgumentException If either gap is negative - */ - public FlowLayout (int align, int hgap, int vgap) - { - // Use methods to set fields so that we can have all the checking - // in one place. - setVgap (vgap); - setHgap (hgap); - setAlignment (align); - } - - /** Lay out the container's components based on current settings. - * @param parent The parent container - */ - public void layoutContainer (Container parent) - { - synchronized (parent.getTreeLock ()) - { - int num = parent.getComponentCount (); - // This is more efficient than calling getComponents(). - Component[] comps = parent.component; - - Dimension d = parent.getSize (); - Insets ins = parent.getInsets (); - - ComponentOrientation orient = parent.getComponentOrientation (); - boolean left_to_right = orient.isLeftToRight (); - - int y = ins.top + vgap; - int i = 0; - while (i < num) - { - // Find the components which go in the current row. - int new_w = ins.left + hgap + ins.right; - int new_h = 0; - int j; - boolean found_one = false; - for (j = i; j < num; ++j) - { - // Skip invisible items. - if (! comps[j].visible) - continue; - - Dimension c = comps[j].getPreferredSize (); - - int next_w = new_w + hgap + c.width; - if (next_w <= d.width || ! found_one) - { - new_w = next_w; - new_h = Math.max (new_h, c.height); - found_one = true; - } - else - { - // Must start a new row, and we already found an item - break; - } - } - - // Set the location of each component for this row. - int x; - - int myalign = align; - if (align == LEADING) - myalign = left_to_right ? LEFT : RIGHT; - else if (align == TRAILING) - myalign = left_to_right ? RIGHT : LEFT; - - if (myalign == LEFT) - x = ins.left + hgap; - else if (myalign == CENTER) - x = ins.left + (d.width - new_w) / 2 + hgap; - else - x = ins.left + (d.width - new_w) + hgap; - - for (int k = i; k < j; ++k) - { - if (comps[k].visible) - { - Dimension c = comps[k].getPreferredSize (); - comps[k].setBounds (x, y + (new_h - c.height) / 2, - c.width, c.height); - x += c.width + hgap; - } - } - - // Advance to next row. - i = j; - y += new_h + vgap; - } - } - } - - /** - * Returns the minimum layout size for the specified container using - * this layout. - * @param cont The parent container - * @return The minimum layout size. - */ - public Dimension minimumLayoutSize (Container cont) - { - return getSize (cont, true); - } - - /** - * Returns the preferred layout size for the specified container using - * this layout. - * @param cont The parent container - * @return The preferred layout size. - */ - public Dimension preferredLayoutSize (Container cont) - { - return getSize (cont, false); - } - - /** Remove the indicated component from this layout manager. - * This particular implementation does nothing. - * @param comp The component to remove - */ - public void removeLayoutComponent (Component comp) - { - // Nothing. - } - - /** - * Sets the justification value for this object to the specified value. - * - * @param align The new justification value for this object, which must - * be one of the constants in this class. - */ - public void setAlignment (int align) - { - if (align != LEFT && align != RIGHT && align != CENTER - && align != LEADING && align != TRAILING) - throw new IllegalArgumentException ("invalid alignment: " + align); - this.align = align; - } - - /** - * Sets the horizontal gap between components to the specified value. - * - * @param hgap The new horizontal gap between components. - */ - public void setHgap (int hgap) - { - if (hgap < 0) - throw new IllegalArgumentException ("horizontal gap must be nonnegative"); - this.hgap = hgap; - } - - /** - * Sets the vertical gap between lines of components to the specified value. - * - * @param vgap The new vertical gap. - */ - public void setVgap (int vgap) - { - if (vgap < 0) - throw new IllegalArgumentException ("vertical gap must be nonnegative"); - this.vgap = vgap; - } - - /** Return String description of this object. - * @return A string representation of this object. - */ - public String toString () - { - return ("[" + getClass ().getName () + ",hgap=" + hgap + ",vgap=" + vgap - + ",align=" + align + "]"); - } - - // This method is used to compute the various sizes. - private Dimension getSize (Container parent, boolean is_min) - { - synchronized (parent.getTreeLock ()) - { - int w, h, num = parent.getComponentCount (); - // This is more efficient than calling getComponents(). - Component[] comps = parent.component; - - w = 0; - h = 0; - for (int i = 0; i < num; ++i) - { - if (! comps[i].visible) - continue; - - // FIXME: can we just directly read the fields in Component? - // Or will that not work with subclassing? - Dimension d; - - if (is_min) - d = comps[i].getMinimumSize (); - else - d = comps[i].getPreferredSize (); - - w += d.width; - h = Math.max (d.height, h); - } - - Insets ins = parent.getInsets (); - - w += (num + 1) * hgap + ins.left + ins.right; - h += 2 * vgap + ins.top + ins.bottom; - - return new Dimension (w, h); - } - } - - /** - * @serial The justification alignment of the lines of components, which - * will be one of the constants defined in this class. - */ - private int align; - - /** - * @serial The horizontal gap between components. - */ - private int hgap; - - /** - * @serial The vertical gap between lines of components. - */ - private int vgap; -} diff --git a/libjava/java/awt/FocusTraversalPolicy.java b/libjava/java/awt/FocusTraversalPolicy.java deleted file mode 100644 index a7f1558dde9..00000000000 --- a/libjava/java/awt/FocusTraversalPolicy.java +++ /dev/null @@ -1,103 +0,0 @@ -/* FocusTraversalPolicy.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -/** - * @since 1.4 - */ -public abstract class FocusTraversalPolicy -{ - /** - * Creates a <code>FocusTraversalPolicy</code> object. - */ - public FocusTraversalPolicy() - { - // Do nothing in here. - } - - /** - * Returns the Component that should receive the focus after a Component. - * - * @exception IllegalArgumentException If root or current is null, - * or if root is not a focus cycle root of current. - */ - public abstract Component getComponentAfter(Container root, - Component current); - - /** - * Returns the Component that should receive the focus before a Component. - * - * @exception IllegalArgumentException If root or current is null, - * or if root is not a focus cycle root of current. - */ - public abstract Component getComponentBefore(Container root, - Component current); - - /** - * Returns the first Component in the traversal cycle. - * - * @exception IllegalArgumentException If root is null. - */ - public abstract Component getFirstComponent(Container root); - - /** - * Returns the last Component in the traversal cycle. - * - * @exception IllegalArgumentException If root is null. - */ - public abstract Component getLastComponent(Container root); - - /** - * Returns the default Component to focus. - * - * @exception IllegalArgumentException If root is null. - */ - public abstract Component getDefaultComponent(Container root); - - /** - * Returns the Component that should receive the focus when a Window is made - * visible for the first time. - * - * @exception IllegalArgumentException If window is null. - */ - public Component getInitialComponent(Window window) - { - return getDefaultComponent(window); - } -} // class FocusTraversalPolicy diff --git a/libjava/java/awt/Font.java b/libjava/java/awt/Font.java deleted file mode 100644 index f6833484474..00000000000 --- a/libjava/java/awt/Font.java +++ /dev/null @@ -1,1335 +0,0 @@ -/* Font.java -- Font object - Copyright (C) 1999, 2002, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import gnu.java.awt.ClasspathToolkit; -import gnu.java.awt.peer.ClasspathFontPeer; - -import java.awt.font.FontRenderContext; -import java.awt.font.GlyphVector; -import java.awt.font.LineMetrics; -import java.awt.geom.AffineTransform; -import java.awt.geom.Rectangle2D; -import java.awt.peer.FontPeer; -import java.io.IOException; -import java.io.InputStream; -import java.io.Serializable; -import java.text.AttributedCharacterIterator; -import java.text.CharacterIterator; -import java.text.StringCharacterIterator; -import java.util.HashMap; -import java.util.Locale; -import java.util.Map; -import java.util.StringTokenizer; - -/** - * This class represents a windowing system font. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Warren Levy (warrenl@cygnus.com) - * @author Graydon Hoare (graydon@redhat.com) - */ -public class Font implements Serializable -{ - -/* - * Static Variables - */ - -/** - * Constant indicating a "plain" font. - */ -public static final int PLAIN = 0; - -/** - * Constant indicating a "bold" font. - */ -public static final int BOLD = 1; - -/** - * Constant indicating an "italic" font. - */ -public static final int ITALIC = 2; - -/** - * Constant indicating the baseline mode characteristic of Roman. - */ -public static final int ROMAN_BASELINE = 0; - -/** - * Constant indicating the baseline mode characteristic of Chinese. - */ -public static final int CENTER_BASELINE = 1; - -/** - * Constant indicating the baseline mode characteristic of Devanigri. - */ -public static final int HANGING_BASELINE = 2; - - - /** - * Indicates to <code>createFont</code> that the supplied font data - * is in TrueType format. - * - * <p><em>Specification Note:</em> The Sun JavaDoc for J2SE 1.4 does - * not indicate whether this value also subsumes OpenType. OpenType - * is essentially the same format as TrueType, but allows to define - * glyph shapes in the same way as PostScript, using cubic bezier - * curves. - * - * @since 1.3 - */ - public static final int TRUETYPE_FONT = 0; - - - /** - * A flag for <code>layoutGlyphVector</code>, indicating that the - * orientation of a text run is from left to right. - * - * @since 1.4 - */ - public static final int LAYOUT_LEFT_TO_RIGHT = 0; - - - /** - * A flag for <code>layoutGlyphVector</code>, indicating that the - * orientation of a text run is from right to left. - * - * @since 1.4 - */ - public static final int LAYOUT_RIGHT_TO_LEFT = 1; - - - /** - * A flag for <code>layoutGlyphVector</code>, indicating that the - * text does not contain valid characters before the - * <code>start</code> position. If this flag is set, - * <code>layoutGlyphVector</code> does not examine the text before - * <code>start</code>, even if this would be necessary to select the - * correct glyphs (e.g., for Arabic text). - * - * @since 1.4 - */ - public static final int LAYOUT_NO_START_CONTEXT = 2; - - - /** - * A flag for <code>layoutGlyphVector</code>, indicating that the - * text does not contain valid characters after the - * <code>limit</code> position. If this flag is set, - * <code>layoutGlyphVector</code> does not examine the text after - * <code>limit</code>, even if this would be necessary to select the - * correct glyphs (e.g., for Arabic text). - * - * @since 1.4 - */ - public static final int LAYOUT_NO_LIMIT_CONTEXT = 4; - - /** - * The logical name of this font. - * - * @since 1.0 - */ - protected String name; - - /** - * The size of this font in pixels. - * - * @since 1.0 - */ - protected int size; - - /** - * The style of this font -- PLAIN, BOLD, ITALIC or BOLD+ITALIC. - * - * @since 1.0 - */ - protected int style; - -// Serialization constant -private static final long serialVersionUID = -4206021311591459213L; - - - // The ClasspathToolkit-provided peer which implements this font - private ClasspathFontPeer peer; - -/*************************************************************************/ - -/* - * Static Methods - */ - -/** - * Creates a <code>Font</code> object from the specified string, which - * is in one of the following formats: - * <p> - * <ul> - * <li>fontname-style-pointsize - * <li>fontname-style - * <li>fontname-pointsize - * <li>fontname - * </ul> - * <p> - * The style should be one of BOLD, ITALIC, or BOLDITALIC. The default - * style if none is specified is PLAIN. The default size if none - * is specified is 12. - * - * @param fontspec a string specifying the required font (<code>null</code> - * permitted, interpreted as 'Dialog-PLAIN-12'). - * - * @return A font. - */ - public static Font decode (String fontspec) -{ - if (fontspec == null) - fontspec = "Dialog-PLAIN-12"; - String name = null; - int style = PLAIN; - int size = 12; - - StringTokenizer st = new StringTokenizer(fontspec, "- "); - while (st.hasMoreTokens()) - { - String token = st.nextToken(); - if (name == null) - { - name = token; - continue; - } - - if (token.toUpperCase().equals("BOLD")) - { - style = BOLD; - continue; - } - if (token.toUpperCase().equals("ITALIC")) - { - style = ITALIC; - continue; - } - if (token.toUpperCase().equals("BOLDITALIC")) - { - style = BOLD | ITALIC; - continue; - } - - int tokenval = 0; - try - { - tokenval = Integer.parseInt(token); - } - catch(NumberFormatException e) - { - // Ignored. - } - - if (tokenval != 0) - size = tokenval; - } - - HashMap attrs = new HashMap(); - ClasspathFontPeer.copyStyleToAttrs (style, attrs); - ClasspathFontPeer.copySizeToAttrs (size, attrs); - - return getFontFromToolkit (name, attrs); -} - - /* These methods delegate to the toolkit. */ - - protected static ClasspathToolkit tk () - { - return (ClasspathToolkit)(Toolkit.getDefaultToolkit ()); - } - - /* Every factory method in Font should eventually call this. */ - protected static Font getFontFromToolkit (String name, Map attribs) - { - return tk ().getFont (name, attribs); - } - - /* Every Font constructor should eventually call this. */ - protected static ClasspathFontPeer getPeerFromToolkit (String name, Map attrs) - { - return tk ().getClasspathFontPeer (name, attrs); - } - - -/*************************************************************************/ - -/** - * Returns a <code>Font</code> object from the passed property name. - * - * @param propname The name of the system property. - * @param defval Value to use if the property is not found. - * - * @return The requested font, or <code>default</code> if the property - * not exist or is malformed. - */ - public static Font getFont (String propname, Font defval) -{ - String propval = System.getProperty(propname); - if (propval != null) - return decode (propval); - return defval; -} - -/*************************************************************************/ - -/** - * Returns a <code>Font</code> object from the passed property name. - * - * @param propname The name of the system property. - * - * @return The requested font, or <code>null</code> if the property - * not exist or is malformed. - */ - public static Font getFont (String propname) -{ - return getFont (propname, (Font)null); -} - -/*************************************************************************/ - -/* - * Constructors - */ - -/** - * Initializes a new instance of <code>Font</code> with the specified - * attributes. - * - * @param name The name of the font. - * @param style The font style. - * @param size The font point size. - */ - - public Font (String name, int style, int size) - { - HashMap attrs = new HashMap(); - ClasspathFontPeer.copyStyleToAttrs (style, attrs); - ClasspathFontPeer.copySizeToAttrs (size, attrs); - this.peer = getPeerFromToolkit (name, attrs); - } - - public Font (Map attrs) - { - this(null, attrs); - } - - /* This extra constructor is here to permit ClasspathToolkit and to build - a font with a "logical name" as well as attrs. */ - public Font (String name, Map attrs) - { - // If attrs is null, setting it to an empty HashMap will give this - // Font default attributes. - if (attrs == null) - attrs = new HashMap(); - this.peer = getPeerFromToolkit (name, attrs); - } - -/*************************************************************************/ - -/* - * Instance Methods - */ - -/** - * Returns the logical name of the font. A logical name is the name the - * font was constructed with. It may be the name of a logical font (one - * of 6 required names in all java environments) or it may be a face - * name. - * - * @return The logical name of the font. - * - * @see getFamily() - * @see getFontName() - */ - public String getName () -{ - return peer.getName (this); -} - -/*************************************************************************/ - -/** - * Returns the style of the font. - * - * @return The font style. - */ - public int getSize () -{ - return (int) peer.getSize (this); -} - - public float getSize2D () -{ - return peer.getSize (this); -} - -/*************************************************************************/ - -/** - * Tests whether or not this is a plain font. This will be true if - * and only if neither the bold nor the italics style is set. - * - * @return <code>true</code> if this is a plain font, <code>false</code> - * otherwise. - */ - public boolean isPlain () -{ - return peer.isPlain (this); -} - -/*************************************************************************/ - -/** - * Tests whether or not this font is bold. - * - * @return <code>true</code> if this font is bold, <code>false</code> - * otherwise. - */ - public boolean isBold () -{ - return peer.isBold (this); -} - -/*************************************************************************/ - -/** - * Tests whether or not this font is italic. - * - * @return <code>true</code> if this font is italic, <code>false</code> - * otherwise. - */ - public boolean isItalic () -{ - return peer.isItalic (this); -} - -/*************************************************************************/ - -/** - * Returns the family name of this font. A family name describes a design - * or "brand name" (such as Helvetica or Palatino). It is less specific - * than a font face name (such as Helvetica Bold). - * - * @return A string containing the font family name. - * - * @since 1.2 - * - * @see getName() - * @see getFontName() - * @see GraphicsEnvironment.getAvailableFontFamilyNames() - */ - public String getFamily () -{ - return peer.getFamily (this); -} - -/** - * Returns integer code representing the sum of style flags of this font, a - * combination of either {@link PLAIN}, {@link BOLD}, or {@link ITALIC}. - * - * @return code representing the style of this font. - * - * @see isPlain() - * @see isBold() - * @see isItalic() - */ - public int getStyle () -{ - return peer.getStyle (this); -} - -/** - * Checks if specified character maps to a glyph in this font. - * - * @param c The character to check. - * - * @return Whether the character has a corresponding glyph in this font. - * - * @since 1.2 - */ - public boolean canDisplay (char c) -{ - return peer.canDisplay (this, c); -} - -/** - * Checks how much of a given string can be mapped to glyphs in - * this font. - * - * @param s The string to check. - * - * @return The index of the first character in <code>s</code> which cannot - * be converted to a glyph by this font, or <code>-1</code> if all - * characters can be mapped to glyphs. - * - * @since 1.2 - */ - public int canDisplayUpTo (String s) -{ - return peer.canDisplayUpTo (this, new StringCharacterIterator (s), - 0, s.length () - 1); -} - -/** - * Checks how much of a given sequence of text can be mapped to glyphs in - * this font. - * - * @param text Array containing the text to check. - * @param start Position of first character to check in <code>text</code>. - * @param limit Position of last character to check in <code>text</code>. - * - * @return The index of the first character in the indicated range which - * cannot be converted to a glyph by this font, or <code>-1</code> if all - * characters can be mapped to glyphs. - * - * @since 1.2 - * - * @throws IndexOutOfBoundsException if the range [start, limit] is - * invalid in <code>text</code>. - */ - public int canDisplayUpTo (char[] text, int start, int limit) -{ - return peer.canDisplayUpTo - (this, new StringCharacterIterator (new String (text)), start, limit); -} - -/** - * Checks how much of a given sequence of text can be mapped to glyphs in - * this font. - * - * @param i Iterator over the text to check. - * @param start Position of first character to check in <code>i</code>. - * @param limit Position of last character to check in <code>i</code>. - * - * @return The index of the first character in the indicated range which - * cannot be converted to a glyph by this font, or <code>-1</code> if all - * characters can be mapped to glyphs. - * - * @since 1.2 - * - * @throws IndexOutOfBoundsException if the range [start, limit] is - * invalid in <code>i</code>. - */ - public int canDisplayUpTo (CharacterIterator i, int start, int limit) -{ - return peer.canDisplayUpTo (this, i, start, limit); -} - -/** - * Creates a new font with point size 1 and {@link PLAIN} style, - * reading font data from the provided input stream. The resulting font - * can have further fonts derived from it using its - * <code>deriveFont</code> method. - * - * @param fontFormat Integer code indicating the format the font data is - * in.Currently this can only be {@link TRUETYPE_FONT}. - * @param is {@link InputStream} from which font data will be read. This - * stream is not closed after font data is extracted. - * - * @return A new {@link Font} of the format indicated. - * - * @throws IllegalArgumentException if <code>fontType</code> is not - * recognized. - * @throws FontFormatException if data in InputStream is not of format - * indicated. - * @throws IOException if insufficient data is present on InputStream. - * - * @since 1.3 - */ - public static Font createFont (int fontFormat, InputStream is) - throws FontFormatException, IOException -{ - return tk().createFont (fontFormat, is); -} - -/** - * Maps characters to glyphs in a one-to-one relationship, returning a new - * {@link GlyphVector} with a mapped glyph for each input character. This - * sort of mapping is often sufficient for some scripts such as Roman, but - * is inappropriate for scripts with special shaping or contextual layout - * requirements such as Arabic, Indic, Hebrew or Thai. - * - * @param ctx The rendering context used for precise glyph placement. - * @param str The string to convert to Glyphs. - * - * @return A new {@link GlyphVector} containing glyphs mapped from str, - * through the font's cmap table. - * - * @see layoutGlyphVector() - */ - public GlyphVector createGlyphVector (FontRenderContext ctx, String str) -{ - return peer.createGlyphVector (this, ctx, new StringCharacterIterator (str)); -} - -/** - * Maps characters to glyphs in a one-to-one relationship, returning a new - * {@link GlyphVector} with a mapped glyph for each input character. This - * sort of mapping is often sufficient for some scripts such as Roman, but - * is inappropriate for scripts with special shaping or contextual layout - * requirements such as Arabic, Indic, Hebrew or Thai. - * - * @param ctx The rendering context used for precise glyph placement. - * @param i Iterator over the text to convert to glyphs. - * - * @return A new {@link GlyphVector} containing glyphs mapped from str, - * through the font's cmap table. - * - * @see layoutGlyphVector() - */ - public GlyphVector createGlyphVector (FontRenderContext ctx, CharacterIterator i) -{ - return peer.createGlyphVector (this, ctx, i); -} - -/** - * Maps characters to glyphs in a one-to-one relationship, returning a new - * {@link GlyphVector} with a mapped glyph for each input character. This - * sort of mapping is often sufficient for some scripts such as Roman, but - * is inappropriate for scripts with special shaping or contextual layout - * requirements such as Arabic, Indic, Hebrew or Thai. - * - * @param ctx The rendering context used for precise glyph placement. - * @param chars Array of characters to convert to glyphs. - * - * @return A new {@link GlyphVector} containing glyphs mapped from str, - * through the font's cmap table. - * - * @see layoutGlyphVector() - */ - public GlyphVector createGlyphVector (FontRenderContext ctx, char[] chars) -{ - return peer.createGlyphVector - (this, ctx, new StringCharacterIterator (new String (chars))); -} - -/** - * Extracts a sequence of glyphs from a font, returning a new {@link - * GlyphVector} with a mapped glyph for each input glyph code. - * - * @param ctx The rendering context used for precise glyph placement. - * @param glyphCodes Array of characters to convert to glyphs. - * - * @return A new {@link GlyphVector} containing glyphs mapped from str, - * through the font's cmap table. - * - * @see layoutGlyphVector() - * - * @specnote This method is documented to perform character-to-glyph - * conversions, in the Sun documentation, but its second parameter name is - * "glyphCodes" and it is not clear to me why it would exist if its - * purpose was to transport character codes inside integers. I assume it - * is mis-documented in the Sun documentation. - */ - - public GlyphVector createGlyphVector (FontRenderContext ctx, int[] glyphCodes) -{ - return peer.createGlyphVector (this, ctx, glyphCodes); -} - -/** - * Produces a new {@link Font} based on the current font, adjusted to a - * new size and style. - * - * @param style The style of the newly created font. - * @param size The size of the newly created font. - * - * @return A clone of the current font, with the specified size and style. - * - * @since 1.2 - */ - public Font deriveFont (int style, float size) -{ - return peer.deriveFont (this, style, size); -} - -/** - * Produces a new {@link Font} based on the current font, adjusted to a - * new size. - * - * @param size The size of the newly created font. - * - * @return A clone of the current font, with the specified size. - * - * @since 1.2 - */ - public Font deriveFont (float size) -{ - return peer.deriveFont (this, size); -} - -/** - * Produces a new {@link Font} based on the current font, adjusted to a - * new style. - * - * @param style The style of the newly created font. - * - * @return A clone of the current font, with the specified style. - * - * @since 1.2 - */ - public Font deriveFont (int style) -{ - return peer.deriveFont (this, style); -} - -/** - * Produces a new {@link Font} based on the current font, adjusted to a - * new style and subjected to a new affine transformation. - * - * @param style The style of the newly created font. - * @param a The transformation to apply. - * - * @return A clone of the current font, with the specified style and - * transform. - * - * @throws IllegalArgumentException If transformation is - * <code>null</code>. - * - * @since 1.2 - */ - public Font deriveFont (int style, AffineTransform a) -{ - if (a == null) - throw new IllegalArgumentException ("Affine transformation is null"); - - return peer.deriveFont (this, style, a); -} - -/** - * Produces a new {@link Font} based on the current font, subjected - * to a new affine transformation. - * - * @param a The transformation to apply. - * - * @return A clone of the current font, with the specified transform. - * - * @throws IllegalArgumentException If transformation is - * <code>null</code>. - * - * @since 1.2 - */ - public Font deriveFont (AffineTransform a) -{ - if (a == null) - throw new IllegalArgumentException ("Affine transformation is null"); - - return peer.deriveFont (this, a); -} - -/** - * Produces a new {@link Font} based on the current font, adjusted to a - * new set of attributes. - * - * @param attributes Attributes of the newly created font. - * - * @return A clone of the current font, with the specified attributes. - * - * @since 1.2 - */ - public Font deriveFont (Map attributes) -{ - return peer.deriveFont (this, attributes); -} - -/** - * Returns a map of chracter attributes which this font currently has set. - * - * @return A map of chracter attributes which this font currently has set. - * - * @see getAvailableAttributes() - * @see java.text.AttributedCharacterIterator.Attribute - * @see java.awt.font.TextAttribute - */ - public Map getAttributes () -{ - return peer.getAttributes (this); -} - -/** - * Returns an array of chracter attribute keys which this font understands. - * - * @return An array of chracter attribute keys which this font understands. - * - * @see getAttributes() - * @see java.text.AttributedCharacterIterator.Attribute - * @see java.awt.font.TextAttribute - */ - public AttributedCharacterIterator.Attribute[] getAvailableAttributes() -{ - return peer.getAvailableAttributes (this); -} - -/** - * Returns a baseline code (one of {@link ROMAN_BASELINE}, {@link - * CENTER_BASELINE} or {@link HANGING_BASELINE}) indicating which baseline - * this font will measure baseline offsets for, when presenting glyph - * metrics for a given character. - * - * Baseline offsets describe the position of a glyph relative to an - * invisible line drawn under, through the center of, or over a line of - * rendered text, respectively. Different scripts use different baseline - * modes, so clients should not assume all baseline offsets in a glyph - * vector are from a common baseline. - * - * @param c The character code to select a baseline mode for. - * - * @return The baseline mode which would be used in a glyph associated - * with the provided character. - * - * @since 1.2 - * - * @see LineMetrics.getBaselineOffsets() - */ - public byte getBaselineFor (char c) -{ - return peer.getBaselineFor (this, c); -} - -/** - * Returns the family name of this font. A family name describes a - * typographic style (such as Helvetica or Palatino). It is more specific - * than a logical font name (such as Sans Serif) but less specific than a - * font face name (such as Helvetica Bold). - * - * @param lc The locale in which to describe the name of the font family. - * - * @return A string containing the font family name, localized for the - * provided locale. - * - * @since 1.2 - * - * @see getName() - * @see getFontName() - * @see GraphicsEnvironment.getAvailableFontFamilyNames() - * @see Locale - */ - public String getFamily (Locale lc) -{ - return peer.getFamily (this, lc); -} - -/** - * Returns a font appropriate for the given attribute set. - * - * @param attributes The attributes required for the new font. - * - * @return A new Font with the given attributes. - * - * @since 1.2 - * - * @see TextAttribure - */ - public static Font getFont (Map attributes) -{ - return getFontFromToolkit (null, attributes); -} - -/** - * Returns the font face name of the font. A font face name describes a - * specific variant of a font family (such as Helvetica Bold). It is more - * specific than both a font family name (such as Helvetica) and a logical - * font name (such as Sans Serif). - * - * @return The font face name of the font. - * - * @since 1.2 - * - * @see getName() - * @see getFamily() - */ - public String getFontName () -{ - return peer.getFontName (this); -} - -/** - * Returns the font face name of the font. A font face name describes a - * specific variant of a font family (such as Helvetica Bold). It is more - * specific than both a font family name (such as Helvetica). - * - * @param lc The locale in which to describe the name of the font face. - * - * @return A string containing the font face name, localized for the - * provided locale. - * - * @since 1.2 - * - * @see getName() - * @see getFamily() - */ - public String getFontName (Locale lc) -{ - return peer.getFontName (this, lc); -} - -/** - * Returns the italic angle of this font, a measurement of its slant when - * style is {@link ITALIC}. The precise meaning is the inverse slope of a - * caret line which "best measures" the font's italic posture. - * - * @return The italic angle. - * - * @see TextAttribute.POSTURE - */ - public float getItalicAngle () -{ - return peer.getItalicAngle (this); -} - -/** - * Returns a {@link LineMetrics} object constructed with the specified - * text and {@link FontRenderContext}. - * - * @param text The string to calculate metrics from. - * @param begin Index of first character in <code>text</code> to measure. - * @param limit Index of last character in <code>text</code> to measure. - * @param rc Context for calculating precise glyph placement and hints. - * - * @return A new {@link LineMetrics} object. - * - * @throws IndexOutOfBoundsException if the range [begin, limit] is - * invalid in <code>text</code>. - */ - public LineMetrics getLineMetrics(String text, int begin, - int limit, FontRenderContext rc) -{ - return peer.getLineMetrics (this, new StringCharacterIterator (text), - begin, limit, rc); -} - -/** - * Returns a {@link LineMetrics} object constructed with the specified - * text and {@link FontRenderContext}. - * - * @param chars The string to calculate metrics from. - * @param begin Index of first character in <code>text</code> to measure. - * @param limit Index of last character in <code>text</code> to measure. - * @param rc Context for calculating precise glyph placement and hints. - * - * @return A new {@link LineMetrics} object. - * - * @throws IndexOutOfBoundsException if the range [begin, limit] is - * invalid in <code>chars</code>. - */ - public LineMetrics getLineMetrics(char[] chars, int begin, - int limit, FontRenderContext rc) -{ - return peer.getLineMetrics (this, new StringCharacterIterator (new String(chars)), - begin, limit, rc); -} - -/** - * Returns a {@link LineMetrics} object constructed with the specified - * text and {@link FontRenderContext}. - * - * @param ci The string to calculate metrics from. - * @param begin Index of first character in <code>text</code> to measure. - * @param limit Index of last character in <code>text</code> to measure. - * @param rc Context for calculating precise glyph placement and hints. - * - * @return A new {@link LineMetrics} object. - * - * @throws IndexOutOfBoundsException if the range [begin, limit] is - * invalid in <code>ci</code>. - */ - public LineMetrics getLineMetrics (CharacterIterator ci, int begin, - int limit, FontRenderContext rc) -{ - return peer.getLineMetrics (this, ci, begin, limit, rc); -} - -/** - * Returns the maximal bounding box of all the bounding boxes in this - * font, when the font's bounding boxes are evaluated in a given {@link - * FontRenderContext} - * - * @param rc Context in which to evaluate bounding boxes. - * - * @return The maximal bounding box. - */ - public Rectangle2D getMaxCharBounds (FontRenderContext rc) -{ - return peer.getMaxCharBounds (this, rc); -} - -/** - * Returns the glyph code this font uses to represent missing glyphs. This - * code will be present in glyph vectors when the font was unable to - * locate a glyph to represent a particular character code. - * - * @return The missing glyph code. - * - * @since 1.2 - */ - public int getMissingGlyphCode () -{ - return peer.getMissingGlyphCode (this); -} - -/** - * Returns the overall number of glyphs in this font. This number is one - * more than the greatest glyph code used in any glyph vectors this font - * produces. In other words, glyph codes are taken from the range - * <code>[ 0, getNumGlyphs() - 1 ]</code>. - * - * @return The number of glyphs in this font. - * - * @since 1.2 - */ - public int getNumGlyphs () -{ - return peer.getMissingGlyphCode (this); -} - -/** - * Returns the PostScript Name of this font. - * - * @return The PostScript Name of this font. - * - * @since 1.2 - * - * @see getName() - * @see getFamily() - * @see getFontName() - */ - public String getPSName () -{ - return peer.getPostScriptName (this); -} - -/** - * Returns the logical bounds of the specified string when rendered with this - * font in the specified {@link FontRenderContext}. This box will include the - * glyph origin, ascent, advance, height, and leading, but may not include all - * diacritics or accents. To get the complete visual bounding box of all the - * glyphs in a run of text, use the {@link TextLayout#getBounds} method of - * {@link TextLayout}. - * - * @param str The string to measure. - * @param frc The context in which to make the precise glyph measurements. - * - * @return A bounding box covering the logical bounds of the specified text. - * - * @see createGlyphVector() - */ - public Rectangle2D getStringBounds (String str, FontRenderContext frc) -{ - return getStringBounds (str, 0, str.length () - 1, frc); -} - -/** - * Returns the logical bounds of the specified string when rendered with this - * font in the specified {@link FontRenderContext}. This box will include the - * glyph origin, ascent, advance, height, and leading, but may not include all - * diacritics or accents. To get the complete visual bounding box of all the - * glyphs in a run of text, use the {@link TextLayout#getBounds} method of - * {@link TextLayout}. - * - * @param str The string to measure. - * @param begin Index of the first character in <code>str</code> to measure. - * @param limit Index of the last character in <code>str</code> to measure. - * @param frc The context in which to make the precise glyph measurements. - * - * @return A bounding box covering the logical bounds of the specified text. - * - * @throws IndexOutOfBoundsException if the range [begin, limit] is - * invalid in <code>str</code>. - * - * @since 1.2 - * - * @see createGlyphVector() - */ - public Rectangle2D getStringBounds (String str, int begin, - int limit, FontRenderContext frc) -{ - return peer.getStringBounds (this, new StringCharacterIterator(str), begin, limit, frc); -} - -/** - * Returns the logical bounds of the specified string when rendered with this - * font in the specified {@link FontRenderContext}. This box will include the - * glyph origin, ascent, advance, height, and leading, but may not include all - * diacritics or accents. To get the complete visual bounding box of all the - * glyphs in a run of text, use the {@link TextLayout#getBounds} method of - * {@link TextLayout}. - * - * @param ci The text to measure. - * @param begin Index of the first character in <code>ci</code> to measure. - * @param limit Index of the last character in <code>ci</code> to measure. - * @param frc The context in which to make the precise glyph measurements. - * - * @return A bounding box covering the logical bounds of the specified text. - * - * @throws IndexOutOfBoundsException if the range [begin, limit] is - * invalid in <code>ci</code>. - * - * @since 1.2 - * - * @see createGlyphVector() - */ - public Rectangle2D getStringBounds (CharacterIterator ci, int begin, - int limit, FontRenderContext frc) -{ - return peer.getStringBounds (this, ci, begin, limit, frc); -} - -/** - * Returns the logical bounds of the specified string when rendered with this - * font in the specified {@link FontRenderContext}. This box will include the - * glyph origin, ascent, advance, height, and leading, but may not include all - * diacritics or accents. To get the complete visual bounding box of all the - * glyphs in a run of text, use the {@link TextLayout#getBounds} method of - * {@link TextLayout}. - * - * @param chars The text to measure. - * @param begin Index of the first character in <code>ci</code> to measure. - * @param limit Index of the last character in <code>ci</code> to measure. - * @param frc The context in which to make the precise glyph measurements. - * - * @return A bounding box covering the logical bounds of the specified text. - * - * @throws IndexOutOfBoundsException if the range [begin, limit] is - * invalid in <code>chars</code>. - * - * @since 1.2 - * - * @see createGlyphVector() - */ - public Rectangle2D getStringBounds (char[] chars, int begin, - int limit, FontRenderContext frc) -{ - return peer.getStringBounds (this, new StringCharacterIterator (new String (chars)), - begin, limit, frc); -} - -/** - * Returns a copy of the affine transformation this font is currently - * subject to, if any. - * - * @return The current transformation. - */ - public AffineTransform getTransform () -{ - return peer.getTransform (this); -} - -/** - * Indicates whether this font's line metrics are uniform. A font may be - * composed of several "subfonts", each covering a different code range, - * and each with their own line metrics. A font with no subfonts, or - * subfonts with identical line metrics, is said to have "uniform" line - * metrics. - * - * @return Whether this font has uniform line metrics. - * - * @see LineMetrics - * @see getLineMetrics() - */ - public boolean hasUniformLineMetrics () -{ - return peer.hasUniformLineMetrics (this); -} - -/** - * Indicates whether this font is subject to a non-identity affine - * transformation. - * - * @return <code>true</code> iff the font has a non-identity affine - * transformation applied to it. - */ - public boolean isTransformed () -{ - return peer.isTransformed (this); -} - -/** - * Produces a glyph vector representing a full layout fo the specified - * text in this font. Full layouts may include complex shaping and - * reordering operations, for scripts such as Arabic or Hindi. - * - * Bidirectional (bidi) layout is not performed in this method; text - * should have its bidi direction specified with one of the flags {@link - * LAYOUT_LEFT_TO_RIGHT} or {@link LAYOUT_RIGHT_TO_LEFT}. - * - * Some types of layout (notably Arabic glyph shaping) may examine context - * characters beyond the bounds of the indicated range, in order to select - * an appropriate shape. The flags {@link LAYOUT_NO_START_CONTEXT} and - * {@link LAYOUT_NO_LIMIT_CONTEXT} can be provided to prevent these extra - * context areas from being examined, for instance if they contain invalid - * characters. - * - * @param frc Context in which to perform the layout. - * @param chars Text to perform layout on. - * @param start Index of first character to perform layout on. - * @param limit Index of last character to perform layout on. - * @param flags Combination of flags controlling layout. - * - * @return A new {@link GlyphVector} representing the specified text. - * - * @throws IndexOutOfBoundsException if the range [begin, limit] is - * invalid in <code>chars</code>. - */ - public GlyphVector layoutGlyphVector (FontRenderContext frc, - char[] chars, int start, - int limit, int flags) -{ - return peer.layoutGlyphVector (this, frc, chars, start, limit, flags); -} - - -/** - * Returns a native peer object for this font. - * - * @return A native peer object for this font. - * - * @deprecated - */ - public FontPeer getPeer () -{ - return peer; -} - - -/** - * Returns a hash value for this font. - * - * @return A hash for this font. - */ - public int hashCode() -{ - return this.toString().hashCode(); -} - - -/** - * Tests whether or not the specified object is equal to this font. This - * will be true if and only if: - * <P> - * <ul> - * <li>The object is not <code>null</code>. - * <li>The object is an instance of <code>Font</code>. - * <li>The object has the same names, style, size, and transform as this object. - * </ul> - * - * @return <code>true</code> if the specified object is equal to this - * object, <code>false</code> otherwise. - */ -public boolean -equals(Object obj) -{ - if (obj == null) - return(false); - - if (!(obj instanceof Font)) - return(false); - - Font f = (Font)obj; - - return (f.getName ().equals (this.getName ()) && - f.getFamily ().equals (this.getFamily ()) && - f.getFontName ().equals (this.getFontName ()) && - f.getTransform ().equals (this.getTransform ()) && - f.getSize() == this.getSize() && - f.getStyle() == this.getStyle()); -} - -/*************************************************************************/ - -/** - * Returns a string representation of this font. - * - * @return A string representation of this font. - */ -public String -toString() -{ - String styleString = ""; - - switch (getStyle ()) - { - case 0: - styleString = "plain"; - break; - case 1: - styleString = "bold"; - break; - case 2: - styleString = "italic"; - break; - default: - styleString = "unknown"; - } - - return getClass ().getName () - + "[family=" + getFamily () - + ",name=" + getFontName () - + ",style=" + styleString - + ",size=" + getSize () + "]"; -} - - - /** - * Determines the line metrics for a run of text. - * - * @param str the text run to be measured. - * - * @param frc the font rendering parameters that are used for the - * measurement. The exact placement and size of text slightly - * depends on device-specific characteristics, for instance - * the device resolution or anti-aliasing. For this reason, - * the returned measurement will only be accurate if the - * passed <code>FontRenderContext</code> correctly reflects - * the relevant parameters. Hence, <code>frc</code> should be - * obtained from the same <code>Graphics2D</code> that will - * be used for drawing, and any rendering hints should be set - * to the desired values before obtaining <code>frc</code>. - * - * @see java.awt.Graphics2D#getFontRenderContext() - */ - public LineMetrics getLineMetrics(String str, FontRenderContext frc) - { - return getLineMetrics (str, 0, str.length () - 1, frc); - } - -} // class Font - diff --git a/libjava/java/awt/FontFormatException.java b/libjava/java/awt/FontFormatException.java deleted file mode 100644 index 6ec8757fb5b..00000000000 --- a/libjava/java/awt/FontFormatException.java +++ /dev/null @@ -1,65 +0,0 @@ -/* FontFormatException.java -- the specified font is bad - Copyright (C) 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -/** - * Thrown when a specified font is bad. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @see Font - * @since 1.3 - * @status updated to 1.4 - */ -public class FontFormatException extends Exception -{ - /** - * Compatible with JDK 1.4+. - */ - private static final long serialVersionUID = -4481290147811361272L; - - /** - * Create a new instance with the specified detailed error message. - * - * @param message the detailed error message - */ - public FontFormatException(String message) - { - super(message); - } -} // class FontFormatException diff --git a/libjava/java/awt/FontMetrics.java b/libjava/java/awt/FontMetrics.java deleted file mode 100644 index e702a625766..00000000000 --- a/libjava/java/awt/FontMetrics.java +++ /dev/null @@ -1,425 +0,0 @@ -/* FontMetrics.java -- Information about about a fonts display characteristics - Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.awt.font.FontRenderContext; -import java.awt.font.LineMetrics; -import java.awt.geom.Rectangle2D; -import java.text.CharacterIterator; - -// FIXME: I leave many methods basically unimplemented. This -// should be reviewed. - -/** - * This class returns information about the display characteristics of - * a font. It is abstract, and concrete subclasses should implement at - * least the following methods: - * - * <ul> - * <li>getAscent()</li> - * <li>getDescent()</li> - * <li>getLeading()</li> - * <li>getMaxAdvance()</li> - * <li>charWidth(char)</li> - * <li>charsWidth(char[], int, int)</li> - * </ul> - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public abstract class FontMetrics implements java.io.Serializable -{ - // Serialization constant. - private static final long serialVersionUID = 1681126225205050147L; - - /** - * This is the font for which metrics will be returned. - */ - protected Font font; - - /** - * Initializes a new instance of <code>FontMetrics</code> for the - * specified font. - * - * @param font The font to return metric information for. - */ - protected FontMetrics(Font font) - { - this.font = font; - } - - /** - * Returns the font that this object is creating metric information fo. - * - * @return The font for this object. - */ - public Font getFont() - { - return font; - } - - /** - * Returns the leading, or spacing between lines, for this font. - * - * @return The font leading. - */ - public int getLeading() - { - return 0; - } - - /** - * Returns the ascent of the font, which is the distance from the base - * to the top of the majority of characters in the set. Some characters - * can exceed this value however. - * - * @return The font ascent. - */ - public int getAscent() - { - return 1; - } - - /** - * Returns the descent of the font, which is the distance from the base - * to the bottom of the majority of characters in the set. Some characters - * can exceed this value however. - * - * @return The font descent. - */ - public int getDescent() - { - return 1; - } - - /** - * Returns the height of a line in this font. This will be the sum - * of the leading, the ascent, and the descent. - * - * @return The height of the font. - */ - public int getHeight() - { - return getAscent() + getDescent() + getLeading(); - } - - /** - * Returns the maximum ascent value. This is the maximum distance any - * character in the font rised above the baseline. - * - * @return The maximum ascent for this font. - */ - public int getMaxAscent() - { - return getAscent(); - } - - /** - * Returns the maximum descent value. This is the maximum distance any - * character in the font extends below the baseline. - * - * @return The maximum descent for this font. - */ - public int getMaxDescent() - { - return getMaxDecent(); - } - - /** - * Returns the maximum descent value. This is the maximum distance any - * character in the font extends below the baseline. - * - * @return The maximum descent for this font. - * - * @deprecated This method is deprecated in favor of - * <code>getMaxDescent()</code>. - */ - public int getMaxDecent() - { - return getDescent(); - } - - /** - * Returns the width of the widest character in the font. - * - * @return The width of the widest character in the font. - */ - public int getMaxAdvance() - { - return -1; - } - - /** - * Returns the width of the specified character. - * - * @param ch The character to return the width of. - * - * @return The width of the specified character. - */ - public int charWidth(int ch) - { - return charWidth((char) ch); - } - - /** - * Returns the width of the specified character. - * - * @param ch The character to return the width of. - * - * @return The width of the specified character. - */ - public int charWidth(char ch) - { - return 1; - } - - /** - * Returns the total width of the specified string - * - * @param str The string to return the width of. - * - * @return The width of the string. - */ - public int stringWidth(String str) - { - char[] buf = new char[str.length()]; - str.getChars(0, str.length(), buf, 0); - - return charsWidth(buf, 0, buf.length); - } - - /** - * Returns the total width of the specified character array. - * - * @param buf The character array containing the data. - * @param offset The offset into the array to start calculating from. - * @param len The total number of bytes to process. - * - * @return The width of the requested characters. - */ - public int charsWidth(char[] buf, int offset, int len) - { - int total_width = 0; - for (int i = offset; i < len; i++) - total_width += charWidth(buf[i]); - return total_width; - } - - /** - * Returns the total width of the specified byte array. - * - * @param buf The byte array containing the data. - * @param offset The offset into the array to start calculating from. - * @param len The total number of bytes to process. - * - * @return The width of the requested characters. - */ - public int bytesWidth(byte[] buf, int offset, int len) - { - int total_width = 0; - for (int i = offset; i < len; i++) - total_width = charWidth((char) buf[i]); - - return total_width; - } - - /** - * Returns the widths of the first 256 characters in the font. - * - * @return The widths of the first 256 characters in the font. - */ - public int[] getWidths() - { - int[] result = new int[256]; - for (char i = 0; i < 256; i++) - result[i] = charWidth(i); - return result; - } - - /** - * Returns a string representation of this object. - * - * @return A string representation of this object. - */ - public String toString() - { - return (this.getClass() + "[font=" + font + ",ascent=" + getAscent() - + ",descent=" + getDescent() + ",height=" + getHeight() + "]"); - } - - // Generic FontRenderContext used when getLineMetrics is called with a - // plain Graphics object. - private static final FontRenderContext gRC = new FontRenderContext(null, - false, - false); - - /** - * Returns a {@link LineMetrics} object constructed with the - * specified text and the {@link FontRenderContext} of the Graphics - * object when it is an instance of Graphics2D or a generic - * FontRenderContext with a null transform, not anti-aliased and not - * using fractional metrics. - * - * @param text The string to calculate metrics from. - * @param g The Graphics object that will be used. - * - * @return A new {@link LineMetrics} object. - */ - public LineMetrics getLineMetrics(String text, Graphics g) - { - return getLineMetrics(text, 0, text.length(), g); - } - - /** - * Returns a {@link LineMetrics} object constructed with the - * specified text and the {@link FontRenderContext} of the Graphics - * object when it is an instance of Graphics2D or a generic - * FontRenderContext with a null transform, not anti-aliased and not - * using fractional metrics. - * - * @param text The string to calculate metrics from. - * @param begin Index of first character in <code>text</code> to measure. - * @param limit Index of last character in <code>text</code> to measure. - * @param g The Graphics object that will be used. - * - * @return A new {@link LineMetrics} object. - * - * @throws IndexOutOfBoundsException if the range [begin, limit] is - * invalid in <code>text</code>. - */ - public LineMetrics getLineMetrics(String text, int begin, int limit, - Graphics g) - { - FontRenderContext rc; - if (g instanceof Graphics2D) - rc = ((Graphics2D) g).getFontRenderContext(); - else - rc = gRC; - return font.getLineMetrics(text, begin, limit, rc); - } - - /** - * Returns a {@link LineMetrics} object constructed with the - * specified text and the {@link FontRenderContext} of the Graphics - * object when it is an instance of Graphics2D or a generic - * FontRenderContext with a null transform, not anti-aliased and not - * using fractional metrics. - * - * @param chars The string to calculate metrics from. - * @param begin Index of first character in <code>text</code> to measure. - * @param limit Index of last character in <code>text</code> to measure. - * @param g The Graphics object that will be used. - * - * @return A new {@link LineMetrics} object. - * - * @throws IndexOutOfBoundsException if the range [begin, limit] is - * invalid in <code>text</code>. - */ - public LineMetrics getLineMetrics(char[] chars, int begin, int limit, - Graphics g) - { - FontRenderContext rc; - if (g instanceof Graphics2D) - rc = ((Graphics2D) g).getFontRenderContext(); - else - rc = gRC; - return font.getLineMetrics(chars, begin, limit, rc); - } - - /** - * Returns a {@link LineMetrics} object constructed with the - * specified text and the {@link FontRenderContext} of the Graphics - * object when it is an instance of Graphics2D or a generic - * FontRenderContext with a null transform, not anti-aliased and not - * using fractional metrics. - * - * @param ci An iterator over the string to calculate metrics from. - * @param begin Index of first character in <code>text</code> to measure. - * @param limit Index of last character in <code>text</code> to measure. - * @param g The Graphics object that will be used. - * - * @return A new {@link LineMetrics} object. - * - * @throws IndexOutOfBoundsException if the range [begin, limit] is - * invalid in <code>text</code>. - */ - public LineMetrics getLineMetrics(CharacterIterator ci, int begin, - int limit, Graphics g) - { - FontRenderContext rc; - if (g instanceof Graphics2D) - rc = ((Graphics2D) g).getFontRenderContext(); - else - rc = gRC; - return font.getLineMetrics(ci, begin, limit, rc); - } - - public Rectangle2D getStringBounds(String str, Graphics context) - { - return font.getStringBounds(str, getFontRenderContext(context)); - } - - public Rectangle2D getStringBounds(String str, int beginIndex, int limit, - Graphics context) - { - return font.getStringBounds(str, beginIndex, limit, - getFontRenderContext(context)); - } - - public Rectangle2D getStringBounds(char[] chars, int beginIndex, int limit, - Graphics context) - { - return font.getStringBounds(chars, beginIndex, limit, - getFontRenderContext(context)); - } - - public Rectangle2D getStringBounds(CharacterIterator ci, int beginIndex, - int limit, Graphics context) - { - return font.getStringBounds(ci, beginIndex, limit, - getFontRenderContext(context)); - } - - private FontRenderContext getFontRenderContext(Graphics context) - { - if (context instanceof Graphics2D) - return ((Graphics2D) context).getFontRenderContext(); - - return gRC; - } -} diff --git a/libjava/java/awt/Frame.java b/libjava/java/awt/Frame.java deleted file mode 100644 index 16c66136037..00000000000 --- a/libjava/java/awt/Frame.java +++ /dev/null @@ -1,649 +0,0 @@ -/* Frame.java -- AWT toplevel window - Copyright (C) 1999, 2000, 2002, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.awt.peer.FramePeer; -import java.lang.ref.WeakReference; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.Vector; - -import javax.accessibility.AccessibleContext; -import javax.accessibility.AccessibleRole; -import javax.accessibility.AccessibleState; -import javax.accessibility.AccessibleStateSet; - -/** - * This class is a top-level window with a title bar and window - * decorations. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public class Frame extends Window implements MenuContainer -{ -/** - * Constant for the default cursor. - * @deprecated Replaced by <code>Cursor.DEFAULT_CURSOR</code> instead. - */ -public static final int DEFAULT_CURSOR = Cursor.DEFAULT_CURSOR; - -/** - * Constant for a cross-hair cursor. - * @deprecated Use <code>Cursor.CROSSHAIR_CURSOR</code> instead. - */ -public static final int CROSSHAIR_CURSOR = Cursor.CROSSHAIR_CURSOR; - -/** - * Constant for a cursor over a text field. - * @deprecated Use <code>Cursor.TEXT_CURSOR</code> instead. - */ -public static final int TEXT_CURSOR = Cursor.TEXT_CURSOR; - -/** - * Constant for a cursor to display while waiting for an action to complete. - * @deprecated Use <code>Cursor.WAIT_CURSOR</code>. - */ -public static final int WAIT_CURSOR = Cursor.WAIT_CURSOR; - -/** - * Cursor used over SW corner of window decorations. - * @deprecated Use <code>Cursor.SW_RESIZE_CURSOR</code> instead. - */ -public static final int SW_RESIZE_CURSOR = Cursor.SW_RESIZE_CURSOR; - -/** - * Cursor used over SE corner of window decorations. - * @deprecated Use <code>Cursor.SE_RESIZE_CURSOR</code> instead. - */ -public static final int SE_RESIZE_CURSOR = Cursor.SE_RESIZE_CURSOR; - -/** - * Cursor used over NW corner of window decorations. - * @deprecated Use <code>Cursor.NW_RESIZE_CURSOR</code> instead. - */ -public static final int NW_RESIZE_CURSOR = Cursor.NW_RESIZE_CURSOR; - -/** - * Cursor used over NE corner of window decorations. - * @deprecated Use <code>Cursor.NE_RESIZE_CURSOR</code> instead. - */ -public static final int NE_RESIZE_CURSOR = Cursor.NE_RESIZE_CURSOR; - -/** - * Cursor used over N edge of window decorations. - * @deprecated Use <code>Cursor.N_RESIZE_CURSOR</code> instead. - */ -public static final int N_RESIZE_CURSOR = Cursor.N_RESIZE_CURSOR; - -/** - * Cursor used over S edge of window decorations. - * @deprecated Use <code>Cursor.S_RESIZE_CURSOR</code> instead. - */ -public static final int S_RESIZE_CURSOR = Cursor.S_RESIZE_CURSOR; - -/** - * Cursor used over E edge of window decorations. - * @deprecated Use <code>Cursor.E_RESIZE_CURSOR</code> instead. - */ -public static final int E_RESIZE_CURSOR = Cursor.E_RESIZE_CURSOR; - -/** - * Cursor used over W edge of window decorations. - * @deprecated Use <code>Cursor.W_RESIZE_CURSOR</code> instead. - */ -public static final int W_RESIZE_CURSOR = Cursor.W_RESIZE_CURSOR; - -/** - * Constant for a hand cursor. - * @deprecated Use <code>Cursor.HAND_CURSOR</code> instead. - */ -public static final int HAND_CURSOR = Cursor.HAND_CURSOR; - -/** - * Constant for a cursor used during window move operations. - * @deprecated Use <code>Cursor.MOVE_CURSOR</code> instead. - */ -public static final int MOVE_CURSOR = Cursor.MOVE_CURSOR; - -public static final int ICONIFIED = 1; -public static final int MAXIMIZED_BOTH = 6; -public static final int MAXIMIZED_HORIZ = 2; -public static final int MAXIMIZED_VERT = 4; -public static final int NORMAL = 0; - -// Serialization version constant -private static final long serialVersionUID = 2673458971256075116L; - -/** - * @serial The version of the class data being serialized - * // FIXME: what is this value? - */ -private int frameSerializedDataVersion; - -/** - * @serial Image used as the icon when this frame is minimized. - */ -private Image icon; - -/** - * @serial Constant used by the JDK Motif peer set. Not used in - * this implementation. - */ -private boolean mbManagement; - -/** - * @serial The menu bar for this frame. - */ -//private MenuBar menuBar = new MenuBar(); -private MenuBar menuBar; - -/** - * @serial A list of other top-level windows owned by this window. - */ -Vector ownedWindows = new Vector(); - -/** - * @serial Indicates whether or not this frame is resizable. - */ -private boolean resizable = true; - -/** - * @serial The state of this frame. - * // FIXME: What are the values here? - * This is package-private to avoid an accessor method. - */ -int state; - -/** - * @serial The title of the frame. - */ -private String title = ""; - - /** - * Maximized bounds for this frame. - */ - private Rectangle maximizedBounds; - - /** - * This field indicates whether the frame is undecorated or not. - */ - private boolean undecorated = false; - - /* - * The number used to generate the name returned by getName. - */ - private static transient long next_frame_number; - -/** - * Initializes a new instance of <code>Frame</code> that is not visible - * and has no title. - */ -public -Frame() -{ - this(""); - noteFrame(this); -} - -/** - * Initializes a new instance of <code>Frame</code> that is not visible - * and has the specified title. - * - * @param title The title of this frame. - */ -public -Frame(String title) -{ - super(); - this.title = title; - // Top-level frames are initially invisible. - visible = false; - noteFrame(this); -} - -public -Frame(GraphicsConfiguration gc) -{ - super(gc); - visible = false; - noteFrame(this); -} - -public -Frame(String title, GraphicsConfiguration gc) -{ - super(gc); - setTitle(title); - visible = false; - noteFrame(this); -} - -/** - * Returns this frame's title string. - * - * @return This frame's title string. - */ -public String -getTitle() -{ - return(title); -} - -/* - * Sets this frame's title to the specified value. - * - * @param title The new frame title. - */ -public synchronized void -setTitle(String title) -{ - this.title = title; - if (peer != null) - ((FramePeer) peer).setTitle(title); -} - -/** - * Returns this frame's icon. - * - * @return This frame's icon, or <code>null</code> if this frame does not - * have an icon. - */ -public Image -getIconImage() -{ - return(icon); -} - -/** - * Sets this frame's icon to the specified value. - * - * @icon The new icon for this frame. - */ -public synchronized void -setIconImage(Image icon) -{ - this.icon = icon; - if (peer != null) - ((FramePeer) peer).setIconImage(icon); -} - -/** - * Returns this frame's menu bar. - * - * @return This frame's menu bar, or <code>null</code> if this frame - * does not have a menu bar. - */ -public MenuBar -getMenuBar() -{ - return(menuBar); -} - -/** - * Sets this frame's menu bar. - * - * @param menuBar The new menu bar for this frame. - */ -public synchronized void -setMenuBar(MenuBar menuBar) -{ - if (peer != null) - { - if (this.menuBar != null) - this.menuBar.removeNotify(); - if (menuBar != null) - menuBar.addNotify(); - invalidateTree (); - ((FramePeer) peer).setMenuBar(menuBar); - } - this.menuBar = menuBar; -} - -/** - * Tests whether or not this frame is resizable. This will be - * <code>true</code> by default. - * - * @return <code>true</code> if this frame is resizable, <code>false</code> - * otherwise. - */ -public boolean -isResizable() -{ - return(resizable); -} - -/** - * Sets the resizability of this frame to the specified value. - * - * @param resizable <code>true</code> to make the frame resizable, - * <code>false</code> to make it non-resizable. - */ -public synchronized void -setResizable(boolean resizable) -{ - this.resizable = resizable; - if (peer != null) - ((FramePeer) peer).setResizable(resizable); -} - -/** - * Returns the cursor type of the cursor for this window. This will - * be one of the constants in this class. - * - * @return The cursor type for this frame. - * - * @deprecated Use <code>Component.getCursor()</code> instead. - */ -public int -getCursorType() -{ - return(getCursor().getType()); -} - -/** - * Sets the cursor for this window to the specified type. The specified - * type should be one of the constants in this class. - * - * @param type The cursor type. - * - * @deprecated Use <code>Component.setCursor(Cursor)</code> instead. - */ -public void -setCursor(int type) -{ - setCursor(new Cursor(type)); -} - -/** - * Removes the specified component from this frame's menu. - * - * @param menu The menu component to remove. - */ -public void -remove(MenuComponent menu) -{ - menuBar.remove(menu); -} - -/** - * Notifies this frame that it should create its native peer. - */ -private static void fireDummyEvent() -{ - EventQueue.invokeLater(new Runnable() - { - public void run() - { - // Do nothing here. - } - }); -} - -public void -addNotify() -{ - if (menuBar != null) - menuBar.addNotify(); - if (peer == null) - peer = getToolkit ().createFrame (this); - - // We now know there's a Frame (us) with a live peer, so we can start the - // fundamental queue and dispatch thread, by inserting a dummy event. - if (parent != null && parent.isDisplayable()) - fireDummyEvent(); - - super.addNotify(); -} - -public void removeNotify() -{ - if (menuBar != null) - menuBar.removeNotify(); - super.removeNotify(); - - // By now we've been disconnected from the peer, and the peer set to - // null. This is formally the same as saying "we just became - // un-displayable", so we wake up the event queue with a dummy event to - // see if it's time to shut down. - fireDummyEvent(); -} - - /** - * Returns a debugging string describing this window. - * - * @return A debugging string describing this window. - */ - protected String paramString () - { - String title = getTitle (); - - String resizable = ""; - if (isResizable ()) - resizable = ",resizable"; - - String state = ""; - switch (getState ()) - { - case NORMAL: - state = ",normal"; - break; - case ICONIFIED: - state = ",iconified"; - break; - case MAXIMIZED_BOTH: - state = ",maximized-both"; - break; - case MAXIMIZED_HORIZ: - state = ",maximized-horiz"; - break; - case MAXIMIZED_VERT: - state = ",maximized-vert"; - break; - } - - return super.paramString () + ",title=" + title + resizable + state; - } - -private static ArrayList weakFrames = new ArrayList(); - -private static void noteFrame(Frame f) -{ - weakFrames.add(new WeakReference(f)); -} - -public static Frame[] getFrames() -{ - int n = 0; - synchronized (weakFrames) - { - Iterator i = weakFrames.iterator(); - while (i.hasNext()) - { - WeakReference wr = (WeakReference) i.next(); - if (wr.get() != null) - ++n; - } - if (n == 0) - return new Frame[0]; - else - { - Frame[] frames = new Frame[n]; - n = 0; - i = weakFrames.iterator(); - while (i.hasNext()) - { - WeakReference wr = (WeakReference) i.next(); - if (wr.get() != null) - frames[n++] = (Frame) wr.get(); - } - return frames; - } - } -} - - public void setState (int state) - { - int current_state = getExtendedState (); - - if (state == NORMAL - && (current_state & ICONIFIED) != 0) - setExtendedState (current_state | ICONIFIED); - - if (state == ICONIFIED - && (current_state & ~ICONIFIED) == 0) - setExtendedState (current_state & ~ICONIFIED); - } - - public int getState () - { - /* FIXME: State might have changed in the peer... Must check. */ - - return (state & ICONIFIED) != 0 ? ICONIFIED : NORMAL; - } - - /** - * @since 1.4 - */ - public void setExtendedState (int state) - { - this.state = state; - } - - /** - * @since 1.4 - */ - public int getExtendedState () - { - return state; - } - - /** - * @since 1.4 - */ - public void setMaximizedBounds (Rectangle maximizedBounds) - { - this.maximizedBounds = maximizedBounds; - } - - /** - * Returns the maximized bounds of this frame. - * - * @return the maximized rectangle, may be null. - * - * @since 1.4 - */ - public Rectangle getMaximizedBounds () - { - return maximizedBounds; - } - - /** - * Returns whether this frame is undecorated or not. - * - * @since 1.4 - */ - public boolean isUndecorated () - { - return undecorated; - } - - /** - * Disables or enables decorations for this frame. This method can only be - * called while the frame is not displayable. - * - * @exception IllegalComponentStateException If this frame is displayable. - * - * @since 1.4 - */ - public void setUndecorated (boolean undecorated) - { - if (!isDisplayable ()) - throw new IllegalComponentStateException (); - - this.undecorated = undecorated; - } - - /** - * Generate a unique name for this frame. - * - * @return A unique name for this frame. - */ - String generateName () - { - return "frame" + getUniqueLong (); - } - - private static synchronized long getUniqueLong () - { - return next_frame_number++; - } - - protected class AccessibleAWTFrame extends AccessibleAWTWindow - { - public AccessibleRole getAccessibleRole() - { - return AccessibleRole.FRAME; - } - - public AccessibleStateSet getAccessibleState() - { - AccessibleStateSet states = super.getAccessibleStateSet(); - if (isResizable()) - states.add(AccessibleState.RESIZABLE); - if ((state & ICONIFIED) != 0) - states.add(AccessibleState.ICONIFIED); - return states; - } - } - - /** - * Gets the AccessibleContext associated with this <code>Frame</code>. - * The context is created, if necessary. - * - * @return the associated context - */ - public AccessibleContext getAccessibleContext() - { - /* Create the context if this is the first request */ - if (accessibleContext == null) - accessibleContext = new AccessibleAWTFrame(); - return accessibleContext; - } - -} diff --git a/libjava/java/awt/GradientPaint.java b/libjava/java/awt/GradientPaint.java deleted file mode 100644 index f730f5ebbd1..00000000000 --- a/libjava/java/awt/GradientPaint.java +++ /dev/null @@ -1,129 +0,0 @@ -/* GradientPaint.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.awt.geom.AffineTransform; -import java.awt.geom.Point2D; -import java.awt.geom.Rectangle2D; -import java.awt.image.ColorModel; - -/** - * STUB CLASS ONLY - */ -public class GradientPaint implements Paint -{ - private final float x1; - private final float y1; - private final Color c1; - private final float x2; - private final float y2; - private final Color c2; - private final boolean cyclic; - - public GradientPaint(float x1, float y1, Color c1, - float x2, float y2, Color c2) - { - this(x1, y1, c1, x2, y2, c2, false); - } - - public GradientPaint(Point2D p1, Color c1, Point2D p2, Color c2) - { - this((float) p1.getX(), (float) p1.getY(), c1, - (float) p2.getX(), (float) p2.getY(), c2, false); - } - - public GradientPaint(float x1, float y1, Color c1, - float x2, float y2, Color c2, boolean cyclic) - { - if (c1 == null || c2 == null) - throw new NullPointerException(); - this.x1 = x1; - this.y1 = y1; - this.c1 = c1; - this.x2 = x2; - this.y2 = y2; - this.c2 = c2; - this.cyclic = cyclic; - } - - public GradientPaint(Point2D p1, Color c1, Point2D p2, Color c2, - boolean cyclic) - { - this((float) p1.getX(), (float) p1.getY(), c1, - (float) p2.getX(), (float) p2.getY(), c2, cyclic); - } - - public Point2D getPoint1() - { - return new Point2D.Float(x1, y1); - } - - public Color getColor1() - { - return c1; - } - - public Point2D getPoint2() - { - return new Point2D.Float(x2, y2); - } - - public Color getColor2() - { - return c2; - } - - public boolean isCyclic() - { - return cyclic; - } - - public PaintContext createContext(ColorModel cm, Rectangle deviceBounds, - Rectangle2D userBounds, - AffineTransform xform, - RenderingHints hints) - { - throw new Error("not implemented"); - } - - public int getTransparency() - { - throw new Error("not implemented"); - } -} // class GradientPaint diff --git a/libjava/java/awt/Graphics.java b/libjava/java/awt/Graphics.java deleted file mode 100644 index ff26190e5f0..00000000000 --- a/libjava/java/awt/Graphics.java +++ /dev/null @@ -1,767 +0,0 @@ -/* Graphics.java -- Abstract Java drawing class - Copyright (C) 1999, 2000, 2002, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.awt.image.ImageObserver; -import java.text.AttributedCharacterIterator; - -/** - * This is the abstract superclass of classes for drawing to graphics - * devices such as the screen or printers. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Warren Levy (warrenl@cygnus.com) - */ -public abstract class Graphics -{ - -/* - * Instance Variables - */ - -/*************************************************************************/ - -/* - * Constructors - */ - -/** - * Default constructor for subclasses. - */ -protected -Graphics() -{ -} - -/*************************************************************************/ - -/* - * Instance Methods - */ - -/** - * Returns a copy of this <code>Graphics</code> object. - * - * @return A copy of this object. - */ -public abstract Graphics -create(); - -/*************************************************************************/ - -/** - * Returns a copy of this <code>Graphics</code> object. The origin point - * will be translated to the point (x, y) and the cliping rectangle set - * to the intersection of the clipping rectangle in this object and the - * rectangle specified by the parameters to this method. - * - * @param x The new X coordinate of the clipping region rect. - * @param y The new Y coordinate of the clipping region rect. - * @param width The width of the clipping region intersect rectangle. - * @param height The height of the clipping region intersect rectangle. - * - * @return A copy of this object, modified as specified. - */ -public Graphics -create(int x, int y, int width, int height) -{ - Graphics g = create(); - - g.translate(x, y); - // FIXME: I'm not sure if this will work. Are the old clip rect bounds - // translated above? - g.clipRect(0, 0, width, height); - - return(g); -} - -/*************************************************************************/ - -/** - * Translates this context so that its new origin point is the point - * (x, y). - * - * @param x The new X coordinate of the origin. - * @param y The new Y coordinate of the origin. - */ -public abstract void -translate(int x, int y); - -/*************************************************************************/ - -/** - * Returns the current color for this object. - * - * @return The color for this object. - */ -public abstract Color -getColor(); - -/*************************************************************************/ - -/** - * Sets the current color for this object. - * - * @param color The new color. - */ -public abstract void -setColor(Color color); - -/*************************************************************************/ - -/** - * Sets this context into "paint" mode, where the target pixels are - * completely overwritten when drawn on. - */ -public abstract void -setPaintMode(); - -/*************************************************************************/ - -/** - * Sets this context info "XOR" mode, where the targe pixles are - * XOR-ed when drawn on. - * - * @param color The color to XOR against. - */ -public abstract void -setXORMode(Color color); - -/*************************************************************************/ - -/** - * Returns the current font for this graphics context. - * - * @return The current font. - */ -public abstract Font -getFont(); - -/*************************************************************************/ - -/** - * Sets the font for this graphics context to the specified value. - * - * @param font The new font. - */ -public abstract void -setFont(Font font); - -/*************************************************************************/ - -/** - * Returns the font metrics for the current font. - * - * @return The font metrics for the current font. - */ -public FontMetrics -getFontMetrics() -{ - return(getFontMetrics(getFont())); -} - -/*************************************************************************/ - -/** - * Returns the font metrics for the specified font. - * - * @param font The font to return metrics for. - * - * @return The requested font metrics. - */ -public abstract FontMetrics -getFontMetrics(Font font); - -/*************************************************************************/ - -/** - * Returns the bounding rectangle of the clipping region for this - * graphics context. - * - * @return The bounding rectangle for the clipping region. - */ -public abstract Rectangle -getClipBounds(); - -/*************************************************************************/ - -/** - * Returns the bounding rectangle of the clipping region for this - * graphics context. - * - * @return The bounding rectangle for the clipping region. - * - * @deprecated This method is deprecated in favor of - * <code>getClipBounds()</code>. - */ -public Rectangle -getClipRect() -{ - return(getClipBounds()); -} - -/*************************************************************************/ - -/** - * Sets the clipping region to the intersection of the current clipping - * region and the rectangle determined by the specified parameters. - * - * @param x The X coordinate of the upper left corner of the intersect rect. - * @param y The Y coordinate of the upper left corner of the intersect rect. - * @param width The width of the intersect rect. - * @param height The height of the intersect rect. - */ -public abstract void -clipRect(int x, int y, int width, int height); - -/*************************************************************************/ - -/** - * Sets the clipping region to the rectangle determined by the specified - * parameters. - * - * @param x The X coordinate of the upper left corner of the rect. - * @param y The Y coordinate of the upper left corner of the rect. - * @param width The width of the rect. - * @param height The height of the rect. - */ -public abstract void -setClip(int x, int y, int width, int height); - -/*************************************************************************/ - -/** - * Returns the current clipping region as a <code>Shape</code> object. - * - * @return The clipping region as a <code>Shape</code>. - */ -public abstract Shape -getClip(); - -/*************************************************************************/ - -/** - * Sets the clipping region to the specified <code>Shape</code>. - * - * @param clip The new clipping region. - */ -public abstract void -setClip(Shape clip); - -/*************************************************************************/ - -/** - * Copies the specified rectangle to the specified offset location. - * - * @param x The X coordinate of the upper left corner of the copy rect. - * @param y The Y coordinate of the upper left corner of the copy rect. - * @param width The width of the copy rect. - * @param height The height of the copy rect. - * @param dx The offset from the X value to start drawing. - * @param dy The offset from the Y value to start drawing. - */ -public abstract void -copyArea(int x, int y, int width, int height, int dx, int dy); - -/*************************************************************************/ - -/** - * Draws a line between the two specified points. - * - * @param x1 The X coordinate of the first point. - * @param y1 The Y coordinate of the first point. - * @param x2 The X coordinate of the second point. - * @param y2 The Y coordinate of the second point. - */ -public abstract void -drawLine(int x1, int y1, int x2, int y2); - -/*************************************************************************/ - -/** - * Fills the area bounded by the specified rectangle. - * - * @param x The X coordinate of the upper left corner of the fill rect. - * @param y The Y coordinate of the upper left corner of the fill rect. - * @param width The width of the fill rect. - * @param height The height of the fill rect. - */ -public abstract void -fillRect(int x, int y, int width, int height); - -/*************************************************************************/ - -/** - * Draws the outline of the specified rectangle. - * - * @param x The X coordinate of the upper left corner of the draw rect. - * @param y The Y coordinate of the upper left corner of the draw rect. - * @param width The width of the draw rect. - * @param height The height of the draw rect. - */ -public void -drawRect(int x, int y, int width, int height) -{ - int x1 = x; - int y1 = y; - int x2 = x + width; - int y2 = y + height; - drawLine(x1, y1, x2, y1); - drawLine(x2, y1, x2, y2); - drawLine(x2, y2, x1, y2); - drawLine(x1, y2, x1, y1); -} - -/*************************************************************************/ - -/** - * Clears the specified rectangle. - * - * @param x The X coordinate of the upper left corner of the clear rect. - * @param y The Y coordinate of the upper left corner of the clear rect. - * @param width The width of the clear rect. - * @param height The height of the clear rect. - */ -public abstract void -clearRect(int x, int y, int width, int height); - -/*************************************************************************/ - -/** - * Draws the outline of the specified rectangle with rounded cornders. - * - * @param x The X coordinate of the upper left corner of the draw rect. - * @param y The Y coordinate of the upper left corner of the draw rect. - * @param width The width of the draw rect. - * @param height The height of the draw rect. - * @param arcWidth The width of the corner arcs. - * @param arcHeight The height of the corner arcs. - */ -public abstract void -drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight); - -/*************************************************************************/ - -/** - * Fills the specified rectangle with rounded cornders. - * - * @param x The X coordinate of the upper left corner of the fill rect. - * @param y The Y coordinate of the upper left corner of the fill rect. - * @param width The width of the fill rect. - * @param height The height of the fill rect. - * @param arcWidth The width of the corner arcs. - * @param arcHeight The height of the corner arcs. - */ -public abstract void -fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight); - -/*************************************************************************/ - -public void -draw3DRect(int x, int y, int width, int height, boolean raised) -{ - Color color = getColor(); - Color tl = color.brighter(); - Color br = color.darker(); - - if (!raised) - { - Color tmp = tl; - tl = br; - br = tmp; - } - - int x1 = x; - int y1 = y; - int x2 = x + width; - int y2 = y + height; - - setColor(tl); - drawLine(x1, y1, x2, y1); - drawLine(x1, y2, x1, y1); - setColor(br); - drawLine(x2, y1, x2, y2); - drawLine(x2, y2, x1, y2); - setColor(color); -} - -/** - * Fills the specified rectangle with a 3D effect - * - * @param x The X coordinate of the upper left corner of the fill rect. - * @param y The Y coordinate of the upper left corner of the fill rect. - * @param width The width of the fill rect. - * @param height The height of the fill rect. - * @param raised <code>true</code> if the rectangle appears raised, - * <code>false</code> if it should appear etched. - */ -public void -fill3DRect(int x, int y, int width, int height, boolean raised) -{ - fillRect(x, y, width, height); - draw3DRect(x, y, width-1, height-1, raised); -} - -/*************************************************************************/ - -/** - * Draws an oval that just fits within the specified rectangle. - * - * @param x The X coordinate of the upper left corner of the rect. - * @param y The Y coordinate of the upper left corner of the rect. - * @param width The width of the rect. - * @param height The height of the rect. - */ -public abstract void -drawOval(int x, int y, int width, int height); - -/*************************************************************************/ - -/** - * Fills an oval that just fits within the specified rectangle. - * - * @param x The X coordinate of the upper left corner of the rect. - * @param y The Y coordinate of the upper left corner of the rect. - * @param width The width of the rect. - * @param height The height of the rect. - */ -public abstract void -fillOval(int x, int y, int width, int height); - -/*************************************************************************/ - -/** - * Draws an arc using the specified bounding rectangle and the specified - * angle parameter. The arc is centered at the center of the rectangle. - * The arc starts at the arcAngle position and extend for arcAngle - * degrees. The degree origin is at the 3 o'clock position. - * - * @param x The X coordinate of the upper left corner of the rect. - * @param y The Y coordinate of the upper left corner of the rect. - * @param width The width of the rect. - * @param height The height of the rect. - * @param arcStart The beginning angle of the arc. - * @param arcAngle The extent of the arc. - */ -public abstract void -drawArc(int x, int y, int width, int height, int arcStart, int arcAngle); - -/*************************************************************************/ - -/** - * Fills the arc define by the specified bounding rectangle and the specified - * angle parameter. The arc is centered at the center of the rectangle. - * The arc starts at the arcAngle position and extend for arcAngle - * degrees. The degree origin is at the 3 o'clock position. - * - * @param x The X coordinate of the upper left corner of the rect. - * @param y The Y coordinate of the upper left corner of the rect. - * @param width The width of the rect. - * @param height The height of the rect. - * @param arcStart The beginning angle of the arc. - * @param arcAngle The extent of the arc. - */ -public abstract void -fillArc(int x, int y, int width, int height, int arcStart, int arcAngle); - -/*************************************************************************/ - -/** - * Draws a series of interconnected lines determined by the arrays - * of corresponding x and y coordinates. - * - * @param xPoints The X coordinate array. - * @param yPoints The Y coordinate array. - * @param npoints The number of points to draw. - */ -public abstract void -drawPolyline(int xPoints[], int yPoints[], int npoints); - -/*************************************************************************/ - -/** - * Draws a series of interconnected lines determined by the arrays - * of corresponding x and y coordinates. The figure is closed if necessary - * by connecting the first and last points. - * - * @param xPoints The X coordinate array. - * @param yPoints The Y coordinate array. - * @param npoints The number of points to draw. - */ -public abstract void -drawPolygon(int xPoints[], int yPoints[], int npoints); - -/*************************************************************************/ - -/** - * Draws the specified polygon. - * - * @param polygon The polygon to draw. - */ -public void -drawPolygon(Polygon polygon) -{ - drawPolygon(polygon.xpoints, polygon.ypoints, polygon.npoints); -} - -/*************************************************************************/ - -/** - * Fills the polygon determined by the arrays - * of corresponding x and y coordinates. - * - * @param xPoints The X coordinate array. - * @param yPoints The Y coordinate array. - * @param npoints The number of points to draw. - */ -public abstract void -fillPolygon(int xPoints[], int yPoints[], int npoints); - -/*************************************************************************/ - -/** - * Fills the specified polygon - * - * @param polygon The polygon to fill. - */ -public void -fillPolygon(Polygon polygon) -{ - fillPolygon(polygon.xpoints, polygon.ypoints, polygon.npoints); -} - -/*************************************************************************/ - -/** - * Draws the specified string starting at the specified point. - * - * @param string The string to draw. - * @param x The X coordinate of the point to draw at. - * @param y The Y coordinate of the point to draw at. - */ -public abstract void -drawString(String string, int x, int y); - -public abstract void drawString (AttributedCharacterIterator ci, int x, int y); - -/*************************************************************************/ - -/** - * Draws the specified characters starting at the specified point. - * - * @param data The array of characters to draw. - * @param offset The offset into the array to start drawing characters from. - * @param length The number of characters to draw. - * @param x The X coordinate of the point to draw at. - * @param y The Y coordinate of the point to draw at. - */ -public void -drawChars(char data[], int offset, int length, int x, int y) -{ - drawString(new String(data, offset, length), x, y); -} - -public void -drawBytes(byte[] data, int offset, int length, int x, int y) -{ - String str = new String(data, offset, length); - drawString(str, x, y); -} - -/*************************************************************************/ - -/** - * Draws all of the image that is available and returns. If the image - * is not completely loaded, <code>false</code> is returned and - * the specified iamge observer is notified as more data becomes - * available. - * - * @param image The image to draw. - * @param x The X coordinate of the point to draw at. - * @param y The Y coordinate of the point to draw at. - * @param observer The image observer to notify as data becomes available. - * - * @return <code>true</code> if all the image data is available, - * <code>false</code> otherwise. - */ -public abstract boolean -drawImage(Image image, int x, int y, ImageObserver observer); - -/*************************************************************************/ - -/** - * Draws all of the image that is available and returns. The image - * is scaled to fit in the specified rectangle. If the image - * is not completely loaded, <code>false</code> is returned and - * the specified iamge observer is notified as more data becomes - * available. - * - * @param image The image to draw. - * @param x The X coordinate of the point to draw at. - * @param y The Y coordinate of the point to draw at. - * @param width The width of the rectangle to draw in. - * @param height The height of the rectangle to draw in. - * @param observer The image observer to notify as data becomes available. - * - * @return <code>true</code> if all the image data is available, - * <code>false</code> otherwise. - */ -public abstract boolean -drawImage(Image image, int x, int y, int width, int height, - ImageObserver observer); - -/*************************************************************************/ - -/** - * Draws all of the image that is available and returns. If the image - * is not completely loaded, <code>false</code> is returned and - * the specified iamge observer is notified as more data becomes - * available. - * - * @param image The image to draw. - * @param x The X coordinate of the point to draw at. - * @param y The Y coordinate of the point to draw at. - * @param bgcolor The background color to use for the image. - * @param observer The image observer to notify as data becomes available. - * - * @return <code>true</code> if all the image data is available, - * <code>false</code> otherwise. - */ -public abstract boolean -drawImage(Image image, int x, int y, Color bgcolor, ImageObserver observer); - -/*************************************************************************/ - -/** - * Draws all of the image that is available and returns. The image - * is scaled to fit in the specified rectangle. If the image - * is not completely loaded, <code>false</code> is returned and - * the specified iamge observer is notified as more data becomes - * available. - * - * @param image The image to draw. - * @param x The X coordinate of the point to draw at. - * @param y The Y coordinate of the point to draw at. - * @param width The width of the rectangle to draw in. - * @param height The height of the rectangle to draw in. - * @param bgcolor The background color to use for the image. - * @param observer The image observer to notify as data becomes available. - * - * @return <code>true</code> if all the image data is available, - * <code>false</code> otherwise. - */ -public abstract boolean -drawImage(Image image, int x, int y, int width, int height, Color bgcolor, - ImageObserver observer); - -/*************************************************************************/ - -/** - * FIXME: Write Javadocs for this when you understand it. - */ -public abstract boolean -drawImage(Image image, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, - int sx2, int sy2, ImageObserver observer); - -/*************************************************************************/ - -/** - * FIXME: Write Javadocs for this when you understand it. - */ -public abstract boolean -drawImage(Image image, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, - int sx2, int sy2, Color bgcolor, ImageObserver observer); - -/*************************************************************************/ - -/** - * Free any resources held by this graphics context immediately instead - * of waiting for the object to be garbage collected and finalized. - */ -public abstract void -dispose(); - -/*************************************************************************/ - -/** - * Frees the resources held by this graphics context when it is - * garbage collected. - */ -public void -finalize() -{ - dispose(); -} - -/*************************************************************************/ - -/** - * Returns a string representation of this object. - * - * @return A string representation of this object. - */ -public String -toString() -{ - return getClass ().getName () + "[font=" + getFont () + ",color=" + getColor () + "]"; -} - -public boolean -hitClip(int x, int y, int width, int height) -{ - throw new UnsupportedOperationException("not implemented yet"); -} - -public Rectangle -getClipBounds(Rectangle r) -{ - Rectangle clipBounds = getClipBounds(); - - if (r == null) - return clipBounds; - - r.x = clipBounds.x; - r.y = clipBounds.y; - r.width = clipBounds.width; - r.height = clipBounds.height; - return r; -} - -} // class Graphics - diff --git a/libjava/java/awt/Graphics2D.java b/libjava/java/awt/Graphics2D.java deleted file mode 100644 index 3faa9dc0c66..00000000000 --- a/libjava/java/awt/Graphics2D.java +++ /dev/null @@ -1,158 +0,0 @@ -/* Copyright (C) 2000, 2002, 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.awt.font.FontRenderContext; -import java.awt.font.GlyphVector; -import java.awt.geom.AffineTransform; -import java.awt.image.BufferedImage; -import java.awt.image.BufferedImageOp; -import java.awt.image.ImageObserver; -import java.awt.image.RenderedImage; -import java.awt.image.renderable.RenderableImage; -import java.text.AttributedCharacterIterator; -import java.util.Map; - -/** - * @author Rolf W. Rasmussen (rolfwr@ii.uib.no) - */ -public abstract class Graphics2D extends Graphics -{ - - protected Graphics2D() - { - } - - public void draw3DRect(int x, int y, int width, int height, - boolean raised) - { - super.draw3DRect(x, y, width, height, raised); - } - - public void fill3DRect(int x, int y, int width, int height, - boolean raised) - { - super.fill3DRect(x, y, width, height, raised); - } - - public abstract void draw(Shape shape); - - public abstract boolean drawImage(Image image, AffineTransform xform, - ImageObserver obs); - - public abstract void drawImage(BufferedImage image, - BufferedImageOp op, - int x, - int y); - - public abstract void drawRenderedImage(RenderedImage image, - AffineTransform xform); - - public abstract void drawRenderableImage(RenderableImage image, - AffineTransform xform); - - public abstract void drawString(String text, int x, int y); - - public abstract void drawString(String text, float x, float y); - - public abstract void drawString(AttributedCharacterIterator iterator, - int x, int y); - - public abstract void drawString(AttributedCharacterIterator iterator, - float x, float y); - - // public abstract void drawGlyphVector(GlyphVector g, float x, float y); - - public abstract void fill(Shape shape); - - public abstract boolean hit(Rectangle rect, Shape text, - boolean onStroke); - - public abstract GraphicsConfiguration getDeviceConfiguration(); - - public abstract void setComposite(Composite comp); - - public abstract void setPaint(Paint paint); - - public abstract void setStroke(Stroke stroke); - - public abstract void setRenderingHint(RenderingHints.Key hintKey, - Object hintValue); - - public abstract Object getRenderingHint(RenderingHints.Key hintKey); - - public abstract void setRenderingHints(Map hints); - - public abstract void addRenderingHints(Map hints); - - public abstract RenderingHints getRenderingHints(); - - public abstract void translate(int x, int y); - - public abstract void translate(double tx, double ty); - - public abstract void rotate(double theta); - - public abstract void rotate(double theta, double x, double y); - - public abstract void scale(double scaleX, double scaleY); - - public abstract void shear(double shearX, double shearY); - - public abstract void transform(AffineTransform Tx); - - public abstract void setTransform(AffineTransform Tx); - - public abstract AffineTransform getTransform(); - - public abstract Paint getPaint(); - - public abstract Composite getComposite(); - - public abstract void setBackground(Color color); - - public abstract Color getBackground(); - - public abstract Stroke getStroke(); - - public abstract void clip(Shape s); - - public abstract FontRenderContext getFontRenderContext (); - - public abstract void drawGlyphVector (GlyphVector g, float x, float y); -} diff --git a/libjava/java/awt/GraphicsConfigTemplate.java b/libjava/java/awt/GraphicsConfigTemplate.java deleted file mode 100644 index e46888378fe..00000000000 --- a/libjava/java/awt/GraphicsConfigTemplate.java +++ /dev/null @@ -1,106 +0,0 @@ -/* GraphicsConfigTemplate.java -- a template for selecting configurations - Copyright (C) 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.io.Serializable; - -/** - * This allows filtering an array of GraphicsConfigurations for the best - * one based on various requirements. The resulting configuration has had - * all non-default attributes set as required to meet or exceed the request. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @see GraphicsConfiguration - * @see GraphicsDevice - * @since 1.2 - * @status updated to 1.4 - */ -public abstract class GraphicsConfigTemplate implements Serializable -{ - /** - * Compatible with JDK 1.2+. - */ - private static final long serialVersionUID = -8061369279557787079L; - - /** States that a feature is required to select a configuration. */ - public static final int REQUIRED = 1; - - /** - * States that a feature is preferred, but not required, to select a - * configuration. In the case of multiple valid configurations, the tie - * breaks in favor of the one with the feature. - */ - public static final int PREFERRED = 2; - - /** - * States that a feature is not necessary in the configuration. In the case - * of multiple valid configurations, the tie breaks in favor of the one - * without the feature, to reduce overhead. - */ - public static final int UNNECESSARY = 3; - - /** - * The default constructor. - */ - public GraphicsConfigTemplate() - { - } - - /** - * Returns the "best" match among the array of possible configurations, given - * the criteria of this template. - * - * @param array the array to choose from - * @return the best match - * @throws NullPointerException if array is null - */ - public abstract GraphicsConfiguration getBestConfiguration - (GraphicsConfiguration[] array); - - /** - * Returns true if the given configuration supports all the features required - * by this template. - * - * @param config the configuration to test - * @return true if it is a match - * @throws NullPointerException if config is null - */ - public abstract boolean isGraphicsConfigSupported - (GraphicsConfiguration config); -} // class GraphicsConfigTemplate diff --git a/libjava/java/awt/GraphicsConfiguration.java b/libjava/java/awt/GraphicsConfiguration.java deleted file mode 100644 index 6dc27793d43..00000000000 --- a/libjava/java/awt/GraphicsConfiguration.java +++ /dev/null @@ -1,218 +0,0 @@ -/* GraphicsConfiguration.java -- describes characteristics of graphics - Copyright (C) 2000, 2001, 2002 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.awt.geom.AffineTransform; -import java.awt.image.BufferedImage; -import java.awt.image.ColorModel; -import java.awt.image.VolatileImage; - -/** - * This class describes the configuration of various graphics devices, such - * as a monitor or printer. Different configurations may exist for the same - * device, according to the different native modes supported. - * - * <p>Virtual devices are supported (for example, in a multiple screen - * environment, a virtual device covers all screens simultaneously); the - * configuration will have a non-zero relative coordinate system in such - * a case. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @see Window - * @see Frame - * @see GraphicsEnvironment - * @see GraphicsDevice - * @since 1.0 - * @status updated to 1.4 - */ -public abstract class GraphicsConfiguration -{ - /** - * The default constructor. - * - * @see GraphicsDevice#getConfigurations() - * @see GraphicsDevice#getDefaultConfiguration() - * @see GraphicsDevice#getBestConfiguration(GraphicsConfigTemplate) - * @see Graphics2D#getDeviceConfiguration() - */ - protected GraphicsConfiguration () - { - } - - /** - * Gets the associated device that this configuration describes. - * - * @return the device - */ - public abstract GraphicsDevice getDevice(); - - /** - * Returns a buffered image optimized to this device, so that blitting can - * be supported in the buffered image. - * - * @param w the width of the buffer - * @param h the height of the buffer - * @return the buffered image, or null if none is supported - */ - public abstract BufferedImage createCompatibleImage(int w, int h); - - /** - * Returns a buffered volatile image optimized to this device, so that - * blitting can be supported in the buffered image. Because the buffer is - * volatile, it can be optimized by native graphics accelerators. - * - * @param w the width of the buffer - * @param h the height of the buffer - * @return the buffered image, or null if none is supported - * @see Component#createVolatileImage(int, int) - * @since 1.4 - */ - public abstract VolatileImage createCompatibleVolatileImage(int w, int h); - - /** - * Returns a buffered volatile image optimized to this device, and with the - * given capabilities, so that blitting can be supported in the buffered - * image. Because the buffer is volatile, it can be optimized by native - * graphics accelerators. - * - * @param w the width of the buffer - * @param h the height of the buffer - * @param caps the desired capabilities of the image buffer - * @return the buffered image, or null if none is supported - * @throws AWTException if the capabilities cannot be met - * @since 1.4 - */ - public VolatileImage createCompatibleVolatileImage(int w, int h, - ImageCapabilities caps) - throws AWTException - { - throw new AWTException("not implemented"); - } - - /** - * Returns a buffered image optimized to this device, and with the specified - * transparency, so that blitting can be supported in the buffered image. - * - * @param w the width of the buffer - * @param h the height of the buffer - * @param transparency the transparency of the buffer - * @return the buffered image, or null if none is supported - * @see Transparency#OPAQUE - * @see Transparency#BITMASK - * @see Transparency#TRANSLUCENT - */ - public abstract BufferedImage createCompatibleImage(int w, int h, - int transparency); - - /** - * Gets the color model of the corresponding device. - * - * @return the color model - */ - public abstract ColorModel getColorModel(); - - /** - * Gets a color model for the corresponding device which supports the desired - * transparency level. - * - * @param transparency the transparency of the model - * @return the color model, with transparency - * @see Transparency#OPAQUE - * @see Transparency#BITMASK - * @see Transparency#TRANSLUCENT - */ - public abstract ColorModel getColorModel(int transparency); - - /** - * Returns a transform that maps user coordinates to device coordinates. The - * preferred mapping is about 72 user units to 1 inch (2.54 cm) of physical - * space. This is often the identity transform. The device coordinates have - * the origin at the upper left, with increasing x to the right, and - * increasing y to the bottom. - * - * @return the transformation from user space to device space - * @see #getNormalizingTransform() - */ - public abstract AffineTransform getDefaultTransform(); - - /** - * Returns a transform that maps user coordinates to device coordinates. The - * exact mapping is 72 user units to 1 inch (2.54 cm) of physical space. - * This is often the identity transform. The device coordinates have the - * origin at the upper left, with increasing x to the right, and increasing - * y to the bottom. Note that this is more accurate (and thus, sometimes more - * costly) than the default transform. - * - * @return the normalized transformation from user space to device space - * @see #getDefaultTransform() - */ - public abstract AffineTransform getNormalizingTransform(); - - /** - * Returns the bounds of the configuration, in device coordinates. If this - * is a virtual device (for example, encompassing several screens), the - * bounds may have a non-zero origin. - * - * @return the device bounds - * @since 1.3 - */ - public abstract Rectangle getBounds(); - - /** - * Returns the buffering capabilities of this configuration. - * - * @return the buffer capabilities - * @since 1.4 - */ - public BufferCapabilities getBufferCapabilities() - { - throw new Error("not implemented"); - } - - /** - * Returns the imaging capabilities of this configuration. - * - * @return the image capabilities - * @since 1.4 - */ - public ImageCapabilities getImageCapabilities() - { - throw new Error("not implemented"); - } -} // class GraphicsConfiguration diff --git a/libjava/java/awt/GraphicsDevice.java b/libjava/java/awt/GraphicsDevice.java deleted file mode 100644 index 581d02f0d41..00000000000 --- a/libjava/java/awt/GraphicsDevice.java +++ /dev/null @@ -1,290 +0,0 @@ -/* GraphicsDevice.java -- information about a graphics device - Copyright (C) 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -/** - * This describes a graphics device available to the given environment. This - * includes screen and printer devices, and the different configurations for - * each device. Also, this allows you to create virtual devices which operate - * over a multi-screen environment. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @see GraphicsEnvironment - * @see GraphicsConfiguration - * @since 1.3 - * @status updated to 1.4 - */ -public abstract class GraphicsDevice -{ - /** Device is a raster screen. */ - public static final int TYPE_RASTER_SCREEN = 0; - - /** Device is a printer. */ - public static final int TYPE_PRINTER = 1; - - /** Device is an image buffer not visible to the user. */ - public static final int TYPE_IMAGE_BUFFER = 2; - - /** The current full-screen window, or null if there is none. */ - private Window full_screen; - - /** - * The bounds of the fullscreen window before it has been switched to full - * screen. - */ - private Rectangle fullScreenOldBounds; - - /** The current display mode, or null if unknown. */ - private DisplayMode mode; - - /** - * The default constructor. - * - * @see GraphicsEnvironment#getScreenDevices() - * @see GraphicsEnvironment#getDefaultScreenDevice() - * @see GraphicsConfiguration#getDevice() - */ - protected GraphicsDevice() - { - } - - /** - * Returns the type of the device. - * - * @return the device type - * @see #TYPE_RASTER_SCREEN - * @see #TYPE_PRINTER - * @see #TYPE_IMAGE_BUFFER - */ - public abstract int getType(); - - /** - * Returns an identification string for the device. This can be - * vendor-specific, and may be useful for debugging. - * - * @return the identification - */ - public abstract String getIDstring(); - - /** - * Return all configurations valid for this device. - * - * @return an array of configurations - */ - public abstract GraphicsConfiguration[] getConfigurations(); - - /** - * Return the default configuration for this device. - * - * @return the default configuration - */ - public abstract GraphicsConfiguration getDefaultConfiguration(); - - /** - * Return the best configuration, according to the criteria in the given - * template. - * - * @param template the template to adjust by - * @return the best configuration - * @throws NullPointerException if template is null - */ - public GraphicsConfiguration getBestConfiguration - (GraphicsConfigTemplate template) - { - return template.getBestConfiguration(getConfigurations()); - } - - /** - * Returns true if the device supports full-screen exclusive mode. The - * default implementation returns true; subclass it if this is not the case. - * - * @return true if full screen support is available - * @since 1.4 - */ - public boolean isFullScreenSupported() - { - return true; - } - - /** - * Toggle the given window between full screen and normal mode. The previous - * full-screen window, if different, is restored; if the given window is - * null, no window will be full screen. If - * <code>isFullScreenSupported()</code> returns true, full screen mode is - * considered to be exclusive, which implies:<ul> - * <li>Windows cannot overlap the full-screen window. All other application - * windows will always appear beneath the full-screen window in the - * Z-order.</li> - * <li>Input method windows are disabled. It is advisable to call - * <code>Component.enableInputMethods(false)</code> to make a component - * a non-client of the input method framework.</li> - * </ul><br> - * If <code>isFullScreenSupported()</code> returns false, full-screen - * exclusive mode is simulated by resizing the window to the size of the - * screen and positioning it at (0,0). This is also what this method does. - * If a device supports real fullscreen mode then it should override this - * method as well as #isFullScreenSupported and #getFullScreenWindow. - * - * @param w the window to toggle - * @see #isFullScreenSupported() - * @see getFullScreenWindow() - * @see setDisplayMode(DisplayMode) - * @see Component#enableInputMethods(boolean) - * @since 1.4 - */ - public synchronized void setFullScreenWindow(Window w) - { - // Restore the previous window to normal mode and release the reference. - if (full_screen != null) - { - full_screen.setBounds(fullScreenOldBounds); - } - - full_screen = null; - - // If w != null, make it full-screen. - if (w != null) - { - fullScreenOldBounds = w.getBounds(); - full_screen = w; - DisplayMode dMode = getDisplayMode(); - full_screen.setBounds(0, 0, dMode.getWidth(), dMode.getHeight()); - full_screen.requestFocus(); - full_screen.setLocationRelativeTo(null); - } - } - - /** - * Returns the current full-screen window of the device, or null if no - * window is full-screen. - * - * @return the full-screen window - * @see #setFullScreenWindow(Window) - * @since 1.4 - */ - public Window getFullScreenWindow() - { - return full_screen; - } - - /** - * Returns whether this device supports low-level display changes. This may - * depend on whether full-screen exclusive mode is available. - * - * XXX The default implementation returns false for now. - * - * @return true if display changes are supported - * @see #setDisplayMode(DisplayMode) - * @since 1.4 - */ - public boolean isDisplayChangeSupported() - { - return false; - } - - /** - * Sets the display mode. This may be dependent on the availability of - * full-screen exclusive mode. - * - * @param mode the new mode - * @throws IllegalArgumentException if the new mode is not in getDisplayModes - * @throws UnsupportedOperationException if ! isDisplayChangeSupported() - * @see #getDisplayMode() - * @see #getDisplayModes() - * @see #isDisplayChangeSupported() - * @since 1.4 - */ - public void setDisplayMode(DisplayMode mode) - { - DisplayMode[] array = getDisplayModes(); - if (! isDisplayChangeSupported()) - throw new UnsupportedOperationException(); - int i = array == null ? 0 : array.length; - while (--i >= 0) - if (array[i].equals(mode)) - break; - if (i < 0) - throw new IllegalArgumentException(); - this.mode = mode; - } - - /** - * Returns the current display mode of this device, or null if unknown. - * - * @return the current display mode - * @see #setDisplayMode(DisplayMode) - * @see #getDisplayModes() - * @since 1.4 - */ - public DisplayMode getDisplayMode() - { - return mode; - } - - /** - * Return an array of all available display modes. This implementation - * returns a 0-length array, so subclasses must override this. - * - * @return the array of available modes - * @since 1.4 - */ - public DisplayMode[] getDisplayModes() - { - return new DisplayMode[0]; - } - - /** - * Return the number of bytes available in accelerated memory on this - * device. The device may support creation or caching on a first-come, - * first-served basis, depending on the operating system and driver. - * Memory may be a finite resource, and because of multi-threading, you - * are not guaranteed that the result of this method ensures your image - * will successfully be put in accelerated memory. A negative result means - * the memory is unlimited. The default implementation assumes no special - * memory is available, and returns 0. - * - * @return the size of accelerated memory available - * @see VolatileImage#flush() - * @see ImageCapabilities#isAccelerated() - */ - public int getAvailableAcceleratedMemory() - { - return 0; - } -} // class GraphicsDevice diff --git a/libjava/java/awt/GraphicsEnvironment.java b/libjava/java/awt/GraphicsEnvironment.java deleted file mode 100644 index a82e7a357de..00000000000 --- a/libjava/java/awt/GraphicsEnvironment.java +++ /dev/null @@ -1,244 +0,0 @@ -/* GraphicsEnvironment.java -- information about the graphics environment - Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import gnu.java.awt.ClasspathToolkit; -import gnu.classpath.SystemProperties; -import java.awt.image.BufferedImage; -import java.util.Locale; - -/** - * This descibes the collection of GraphicsDevice and Font objects available - * on a given platform. The resources might be local or remote, and specify - * the valid configurations for displaying graphics. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @see GraphicsDevice - * @see GraphicsConfiguration - * @since 1.4 - * @status updated to 1.4 - */ -public abstract class GraphicsEnvironment -{ - private static GraphicsEnvironment localGraphicsEnvironment; - - /** - * The environment must be obtained from a factory or query method, hence - * this constructor is protected. - */ - protected GraphicsEnvironment() - { - } - - /** - * Returns the local graphics environment. If the java.awt.graphicsenv - * system property is set, it instantiates the specified class, - * otherwise it assume that the awt toolkit is a ClasspathToolkit - * and delegates to it to create the instance. - * - * @return the local environment - */ - public static GraphicsEnvironment getLocalGraphicsEnvironment() - { - if (localGraphicsEnvironment != null) - return localGraphicsEnvironment; - - String graphicsenv = SystemProperties.getProperty("java.awt.graphicsenv", - null); - if (graphicsenv != null) - { - try - { - // We intentionally use the bootstrap class loader. - localGraphicsEnvironment = (GraphicsEnvironment) - Class.forName(graphicsenv).newInstance(); - return localGraphicsEnvironment; - } - catch (Exception x) - { - throw (InternalError) - new InternalError("Unable to instantiate java.awt.graphicsenv") - .initCause(x); - } - } - else - { - ClasspathToolkit tk; - tk = ((ClasspathToolkit) Toolkit.getDefaultToolkit()); - localGraphicsEnvironment = tk.getLocalGraphicsEnvironment(); - return localGraphicsEnvironment; - } - } - - /** - * Check if the local environment is headless, meaning that it does not - * support a display, keyboard, or mouse. Many methods in the Abstract - * Windows Toolkit (java.awt) throw a {@link HeadlessException} if this - * returns true. - * - * This method returns true if the java.awt.headless property is set - * to "true". - * - * @return true if the environment is headless, meaning that graphics are - * unsupported - * @since 1.4 - */ - public static boolean isHeadless() - { - String headless = SystemProperties.getProperty("java.awt.headless", null); - return "true".equalsIgnoreCase(headless); - } - - /** - * Check if the given environment is headless, meaning that it does not - * support a display, keyboard, or mouse. Many methods in the Abstract - * Windows Toolkit (java.awt) throw a {@link HeadlessException} if this - * returns true. This default implementation returns isHeadless(), so - * subclasses need only override it if they differ. - * - * @return true if the environment is headless, meaning that graphics are - * unsupported - * @since 1.4 - */ - public boolean isHeadlessInstance() - { - return isHeadless(); - } - - /** - * Get an array of all the GraphicsDevice objects. - * - * @return the available graphics devices, may be 0 length - * @throws HeadlessException if the environment is headless - */ - public abstract GraphicsDevice[] getScreenDevices(); - - /** - * Get the default screen GraphicsDevice object. - * - * @return the default screen device - * @throws HeadlessException if the environment is headless - */ - public abstract GraphicsDevice getDefaultScreenDevice(); - - /** - * Return a Graphics2D object which will render into the specified image. - * - * @param image the image to render into - * @return the object that renders into the image - */ - public abstract Graphics2D createGraphics(BufferedImage image); - - /** - * Returns an array of the one-point size fonts available in this - * environment. From there, the user can select the font and derive the - * correct one of proper size and attributes, using <code>deriveFont</code>. - * Only one master version of each font appears in this array; if a font - * can be derived from another, it must be created in that way. - * - * @return the array of available fonts - * @see #getAvailableFontFamilyNames() - * @see Font#deriveFont(int, float) - * @since 1.2 - */ - public abstract Font[] getAllFonts(); - - /** - * Returns an array of the font family names available in this environment. - * This allows flexibility in choosing the style of font, while still letting - * the Font class decide its best match. - * - * @return the array of available font families - * @see #getAllFonts() - * @see Font#getFamily() - * @since 1.2 - */ - public abstract String[] getAvailableFontFamilyNames(); - - /** - * Returns an array of the font family names available in this environment, - * localized to the current Locale if l is non-null. This allows - * flexibility in choosing the style of font, while still letting the Font - * class decide its best match. - * - * @param l the locale to use - * @return the array of available font families, localized - * @see #getAllFonts() - * @see Font#getFamily() - * @since 1.2 - */ - public abstract String[] getAvailableFontFamilyNames(Locale l); - - /** - * Returns the point where a window should be centered. You should probably - * also check that the window fits within the screen bounds. The default - * simply returns the center of the maximum window bounds; subclasses should - * override this if native objects (like scrollbars) make that off-centered. - * - * @return the centering point - * @throws HeadlessException if the environment is headless - * @see #getMaximumWindowBounds() - * @since 1.4 - */ - public Point getCenterPoint() - { - Rectangle r = getMaximumWindowBounds(); - return new Point(r.x + r.width / 2, r.y + r.height / 2); - } - - /** - * Returns the maximum bounds for a centered window object. The default - * implementation simply returns the bounds of the default configuration - * of the default screen; subclasses should override this to if native - * objects (like scrollbars) reduce what is truly available. Also, - * subclasses should override this if the window should be centered across - * a multi-screen display. - * - * @return the maximum window bounds - * @throws HeadlessException if the environment is headless - * @see #getCenterPoint() - * @see GraphicsConfiguration#getBounds() - * @see Toolkit#getScreenInsets(GraphicsConfiguration) - * @since 1.4 - */ - public Rectangle getMaximumWindowBounds() - { - return getDefaultScreenDevice().getDefaultConfiguration().getBounds(); - } -} // class GraphicsEnvironment diff --git a/libjava/java/awt/GridBagConstraints.java b/libjava/java/awt/GridBagConstraints.java deleted file mode 100644 index 8d8b4fae534..00000000000 --- a/libjava/java/awt/GridBagConstraints.java +++ /dev/null @@ -1,195 +0,0 @@ -/* GridBagConstraints.java -- Constraints for GridBag layout manager - Copyright (C) 2000, 2001, 2002, 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.io.Serializable; - -/** - * This specifies the constraints for a component managed by the - * GridBagLayout layout manager. - */ -public class GridBagConstraints implements Cloneable, Serializable -{ - static final long serialVersionUID = -1000070633030801713L; - - /** Fill in both directions. */ - public static final int BOTH = 1; - /** Don't fill. */ - public static final int NONE = 0; - /** Fill horizontally. */ - public static final int HORIZONTAL = 2; - /** Fill vertically. */ - public static final int VERTICAL = 3; - - /** Position in the center. */ - public static final int CENTER = 10; - /** Position to the east. */ - public static final int EAST = 13; - /** Position to the north. */ - public static final int NORTH = 11; - /** Position to the northeast. */ - public static final int NORTHEAST = 12; - /** Position to the northwest. */ - public static final int NORTHWEST = 18; - /** Position to the south. */ - public static final int SOUTH = 15; - /** Position to the southeast. */ - public static final int SOUTHEAST = 14; - /** Position to the southwest. */ - public static final int SOUTHWEST = 16; - /** Position to the west. */ - public static final int WEST = 17; - - /** Occupy all remaining cells except last cell. */ - public static final int RELATIVE = -1; - /** Occupy all remaining cells. */ - public static final int REMAINDER = 0; - - /** - * Position to where the first text line would end. Equals to NORTHEAST for - * horizontal left-to-right orientations. - */ - public static final int FIRST_LINE_END = 24; - - /** - * Position to where the first text line would start. Equals to NORTHWEST for - * horizontal left-to-right orientations. - */ - public static final int FIRST_LINE_START = 23; - - /** - * Position to where the last text line would end. Equals to SOUTHEAST for - * horizontal left-to-right orientations. - */ - public static final int LAST_LINE_END = 26; - - /** - * Position to where the last text line would start. Equals to SOUTHWEST for - * horizontal left-to-right orientations. - */ - public static final int LAST_LINE_START = 25; - - /** - * Position to where a text line would end. Equals to EAST for - * left-to-right orientations. - */ - public static final int LINE_END = 22; - - /** - * Position to where a text line would start. Equals to WEST for - * left-to-right orientations. - */ - public static final int LINE_START = 21; - - /** - * Position to where a page ends. Equals SOUTH for horizontal orientations. - */ - public static final int PAGE_END = 20; - - /** - * Position to where a page starts. Equals NORTH for horizontal orientations. - */ - public static final int PAGE_START = 19; - - public int anchor; - public int fill; - public int gridheight; - public int gridwidth; - public int gridx; - public int gridy; - public Insets insets; - public int ipadx; - public int ipady; - public double weightx; - public double weighty; - - /** Create a copy of this object. */ - public Object clone () - { - try - { - GridBagConstraints g = (GridBagConstraints) super.clone (); - g.insets = (Insets) insets.clone (); - return g; - } - catch (CloneNotSupportedException _) - { - // Can't happen. - return null; - } - } - - /** Create a new GridBagConstraints object with the default - * parameters. */ - public GridBagConstraints () - { - this.anchor = CENTER; - this.fill = NONE; - this.gridx = RELATIVE; - this.gridy = RELATIVE; - this.gridwidth = 1; - this.gridheight = 1; - this.ipadx = 0; - this.ipady = 0; - this.insets = new Insets (0, 0, 0, 0); - this.weightx = 0; - this.weighty = 0; - } - - /** Create a new GridBagConstraints object with the indicated - * parameters. */ - public GridBagConstraints (int gridx, int gridy, - int gridwidth, int gridheight, - double weightx, double weighty, - int anchor, int fill, - Insets insets, int ipadx, int ipady) - { - this.anchor = anchor; - this.fill = fill; - this.gridx = gridx; - this.gridy = gridy; - this.gridwidth = gridwidth; - this.gridheight = gridheight; - this.ipadx = ipadx; - this.ipady = ipady; - this.insets = insets; - this.weightx = weightx; - this.weighty = weighty; - } -} diff --git a/libjava/java/awt/GridBagLayout.java b/libjava/java/awt/GridBagLayout.java deleted file mode 100644 index efa429dc327..00000000000 --- a/libjava/java/awt/GridBagLayout.java +++ /dev/null @@ -1,1067 +0,0 @@ -/* GridBagLayout - Layout manager for components according to GridBagConstraints - Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Hashtable; - -/** - * @author Michael Koch (konqueror@gmx.de) - * @author Jeroen Frijters (jeroen@frijters.net) - */ -public class GridBagLayout - implements Serializable, LayoutManager2 -{ - private static final long serialVersionUID = 8838754796412211005L; - - protected static final int MINSIZE = 1; - protected static final int PREFERREDSIZE = 2; - protected static final int MAXGRIDSIZE = 512; - - // comptable remembers the original contraints given to us. - // internalcomptable is used to keep track of modified constraint values - // that we calculate, particularly when we are given RELATIVE and - // REMAINDER constraints. - // Constraints kept in comptable are never modified, and constraints - // kept in internalcomptable can be modified internally only. - protected Hashtable comptable; - private Hashtable internalcomptable; - protected GridBagLayoutInfo layoutInfo; - protected GridBagConstraints defaultConstraints; - - public double[] columnWeights; - public int[] columnWidths; - public double[] rowWeights; - public int[] rowHeights; - - public GridBagLayout () - { - this.comptable = new Hashtable(); - this.internalcomptable = new Hashtable(); - this.defaultConstraints= new GridBagConstraints(); - } - - /** - * Helper method to calc the sum of a range of elements in an int array. - */ - private int sumIntArray (int[] array, int upto) - { - int result = 0; - - for (int i = 0; i < upto; i++) - result += array [i]; - - return result; - } - - /** - * Helper method to calc the sum of all elements in an int array. - */ - private int sumIntArray (int[] array) - { - return sumIntArray(array, array.length); - } - - /** - * Helper method to calc the sum of all elements in an double array. - */ - private double sumDoubleArray (double[] array) - { - double result = 0; - - for (int i = 0; i < array.length; i++) - result += array [i]; - - return result; - } - - public void addLayoutComponent (String name, Component component) - { - // do nothing here. - } - - public void removeLayoutComponent (Component component) - { - // do nothing here - } - - public void addLayoutComponent (Component component, Object constraints) - { - if (constraints == null) - return; - - if (!(constraints instanceof GridBagConstraints)) - throw new IllegalArgumentException(); - - setConstraints (component, (GridBagConstraints) constraints); - } - - public Dimension preferredLayoutSize (Container parent) - { - if (parent == null) - return new Dimension (0, 0); - - GridBagLayoutInfo li = getLayoutInfo (parent, PREFERREDSIZE); - return getMinSize (parent, li); - } - - public Dimension minimumLayoutSize (Container parent) - { - if (parent == null) - return new Dimension (0, 0); - - GridBagLayoutInfo li = getLayoutInfo (parent, MINSIZE); - return getMinSize (parent, li); - } - - public Dimension maximumLayoutSize (Container target) - { - return new Dimension (Integer.MAX_VALUE, Integer.MAX_VALUE); - } - - public void layoutContainer (Container parent) - { - arrangeGrid (parent); - } - - public float getLayoutAlignmentX (Container target) - { - return Component.CENTER_ALIGNMENT; - } - - public float getLayoutAlignmentY (Container target) - { - return Component.CENTER_ALIGNMENT; - } - - public void invalidateLayout (Container target) - { - this.layoutInfo = null; - } - - public void setConstraints (Component component, - GridBagConstraints constraints) - { - GridBagConstraints clone = (GridBagConstraints) constraints.clone(); - - if (clone.gridx < 0) - clone.gridx = GridBagConstraints.RELATIVE; - - if (clone.gridy < 0) - clone.gridy = GridBagConstraints.RELATIVE; - - if (clone.gridwidth == 0) - clone.gridwidth = GridBagConstraints.REMAINDER; - else if (clone.gridwidth < 0 - && clone.gridwidth != GridBagConstraints.REMAINDER - && clone.gridwidth != GridBagConstraints.RELATIVE) - clone.gridwidth = 1; - - if (clone.gridheight == 0) - clone.gridheight = GridBagConstraints.REMAINDER; - else if (clone.gridheight < 0 - && clone.gridheight != GridBagConstraints.REMAINDER - && clone.gridheight != GridBagConstraints.RELATIVE) - clone.gridheight = 1; - - comptable.put (component, clone); - } - - public GridBagConstraints getConstraints (Component component) - { - return (GridBagConstraints) (lookupConstraints (component).clone()); - } - - protected GridBagConstraints lookupConstraints (Component component) - { - GridBagConstraints result = (GridBagConstraints) comptable.get (component); - - if (result == null) - { - setConstraints (component, defaultConstraints); - result = (GridBagConstraints) comptable.get (component); - } - - return result; - } - - private GridBagConstraints lookupInternalConstraints (Component component) - { - GridBagConstraints result = - (GridBagConstraints) internalcomptable.get (component); - - if (result == null) - { - result = (GridBagConstraints) lookupConstraints(component).clone(); - internalcomptable.put (component, result); - } - - return result; - } - - /** - * @since 1.1 - */ - public Point getLayoutOrigin () - { - if (layoutInfo == null) - return new Point (0, 0); - - return new Point (layoutInfo.pos_x, layoutInfo.pos_y); - } - - /** - * @since 1.1 - */ - public int[][] getLayoutDimensions () - { - int[][] result = new int [2][]; - if (layoutInfo == null) - { - result[0] = new int[0]; - result[1] = new int[0]; - - return result; - } - - result [0] = new int [layoutInfo.cols]; - System.arraycopy (layoutInfo.colWidths, 0, result [0], 0, layoutInfo.cols); - result [1] = new int [layoutInfo.rows]; - System.arraycopy (layoutInfo.rowHeights, 0, result [1], 0, layoutInfo.rows); - return result; - } - - public double[][] getLayoutWeights () - { - double[][] result = new double [2][]; - if (layoutInfo == null) - { - result[0] = new double[0]; - result[1] = new double[0]; - - return result; - } - - result [0] = new double [layoutInfo.cols]; - System.arraycopy (layoutInfo.colWeights, 0, result [0], 0, layoutInfo.cols); - result [1] = new double [layoutInfo.rows]; - System.arraycopy (layoutInfo.rowWeights, 0, result [1], 0, layoutInfo.rows); - return result; - } - - /** - * @since 1.1 - */ - public Point location (int x, int y) - { - if (layoutInfo == null) - return new Point (0, 0); - - int col; - int row; - int pixel_x = layoutInfo.pos_x; - int pixel_y = layoutInfo.pos_y; - - for (col = 0; col < layoutInfo.cols; col++) - { - int w = layoutInfo.colWidths [col]; - if (x < pixel_x + w) - break; - - pixel_x += w; - } - - for (row = 0; row < layoutInfo.rows; row++) - { - int h = layoutInfo.rowHeights [row]; - if (y < pixel_y + h) - break; - - pixel_y += h; - } - - return new Point (col, row); - } - - /** - * Obsolete. - */ - protected void AdjustForGravity (GridBagConstraints gbc, Rectangle rect) - { - // FIXME - throw new Error ("Not implemented"); - } - - /** - * Obsolete. - */ - protected void ArrangeGrid (Container parent) - { - Component[] components = parent.getComponents(); - - if (components.length == 0) - return; - - GridBagLayoutInfo info = getLayoutInfo (parent, PREFERREDSIZE); - if (info.cols == 0 && info.rows == 0) - return; - layoutInfo = info; - - // DEBUG - //dumpLayoutInfo (layoutInfo); - - for(int i = 0; i < components.length; i++) - { - Component component = components [i]; - - // If component is not visible we dont have to care about it. - if (!component.isVisible()) - continue; - - GridBagConstraints constraints = - lookupInternalConstraints(component); - - int cellx = sumIntArray(layoutInfo.colWidths, constraints.gridx); - int celly = sumIntArray(layoutInfo.rowHeights, constraints.gridy); - int cellw = sumIntArray(layoutInfo.colWidths, - constraints.gridx + constraints.gridwidth) - cellx; - int cellh = sumIntArray(layoutInfo.rowHeights, - constraints.gridy + constraints.gridheight) - celly; - - Insets insets = constraints.insets; - if (insets != null) - { - cellx += insets.left; - celly += insets.top; - cellw -= insets.left + insets.right; - cellh -= insets.top + insets.bottom; - } - - Dimension dim = component.getPreferredSize(); - - // Note: Documentation says that padding is added on both sides, but - // visual inspection shows that the Sun implementation only adds it - // once, so we do the same. - dim.width += constraints.ipadx; - dim.height += constraints.ipady; - - switch(constraints.fill) - { - case GridBagConstraints.HORIZONTAL: - dim.width = cellw; - break; - case GridBagConstraints.VERTICAL: - dim.height = cellh; - break; - case GridBagConstraints.BOTH: - dim.width = cellw; - dim.height = cellh; - break; - } - - int x; - int y; - - switch(constraints.anchor) - { - case GridBagConstraints.NORTH: - x = cellx + (cellw - dim.width) / 2; - y = celly; - break; - case GridBagConstraints.SOUTH: - x = cellx + (cellw - dim.width) / 2; - y = celly + cellh - dim.height; - break; - case GridBagConstraints.WEST: - x = cellx; - y = celly + (cellh - dim.height) / 2; - break; - case GridBagConstraints.EAST: - x = cellx + cellw - dim.width; - y = celly + (cellh - dim.height) / 2; - break; - case GridBagConstraints.NORTHEAST: - x = cellx + cellw - dim.width; - y = celly; - break; - case GridBagConstraints.NORTHWEST: - x = cellx; - y = celly; - break; - case GridBagConstraints.SOUTHEAST: - x = cellx + cellw - dim.width; - y = celly + cellh - dim.height; - break; - case GridBagConstraints.SOUTHWEST: - x = cellx; - y = celly + cellh - dim.height; - break; - default: - x = cellx + (cellw - dim.width) / 2; - y = celly + (cellh - dim.height) / 2; - break; - } - - component.setBounds(layoutInfo.pos_x + x, layoutInfo.pos_y + y, dim.width, dim.height); - } - - // DEBUG - //dumpLayoutInfo (layoutInfo); - } - - /** - * Obsolete. - */ - protected GridBagLayoutInfo GetLayoutInfo (Container parent, int sizeflag) - { - if (sizeflag != MINSIZE && sizeflag != PREFERREDSIZE) - throw new IllegalArgumentException(); - - Dimension parentDim = parent.getSize (); - Insets parentInsets = parent.getInsets (); - parentDim.width -= parentInsets.left + parentInsets.right; - parentDim.height -= parentInsets.top + parentInsets.bottom; - - int current_y = 0; - int max_x = 0; - int max_y = 0; - - // Guaranteed to contain the last component added to the given row - // or column, whose gridwidth/height is not REMAINDER. - HashMap lastInRow = new HashMap(); - HashMap lastInCol = new HashMap(); - - Component[] components = parent.getComponents(); - - // Components sorted by gridwidths/heights, - // smallest to largest, with REMAINDER and RELATIVE at the end. - // These are useful when determining sizes and weights. - ArrayList sortedByWidth = new ArrayList(components.length); - ArrayList sortedByHeight = new ArrayList(components.length); - - // STEP 1: first we figure out how many rows/columns - for (int i = 0; i < components.length; i++) - { - Component component = components [i]; - - // If component is not visible we dont have to care about it. - if (!component.isVisible()) - continue; - - // When looking up the constraint for the first time, check the - // original unmodified constraint. After the first time, always - // refer to the internal modified constraint. - GridBagConstraints originalConstraints = lookupConstraints (component); - GridBagConstraints constraints = (GridBagConstraints) originalConstraints.clone(); - internalcomptable.put(component, constraints); - - // Cases: - // - // 1. gridy == RELATIVE, gridx == RELATIVE - // - // use y as the row number; check for the next - // available slot at row y - // - // 2. only gridx == RELATIVE - // - // check for the next available slot at row gridy - // - // 3. only gridy == RELATIVE - // - // check for the next available slot at column gridx - // - // 4. neither gridx or gridy == RELATIVE - // - // nothing to check; just add it - - - // cases 1 and 2 - if(constraints.gridx == GridBagConstraints.RELATIVE) - { - if (constraints.gridy == GridBagConstraints.RELATIVE) - constraints.gridy = current_y; - - int x; - - // Check the component that occupies the right-most spot in this - // row. We want to add this component after it. - // If this row is empty, add to the 0 position. - if (!lastInRow.containsKey(new Integer(constraints.gridy))) - x = 0; - else - { - Component lastComponent = (Component) lastInRow.get(new Integer(constraints.gridy)); - GridBagConstraints lastConstraints = lookupInternalConstraints(lastComponent); - x = lastConstraints.gridx + Math.max(1, lastConstraints.gridwidth); - } - - // Determine if this component will fit in the slot vertically. - // If not, bump it over to where it does fit. - for (int y = constraints.gridy + 1; y < constraints.gridy + Math.max(1, constraints.gridheight); y++) - { - if (lastInRow.containsKey(new Integer(y))) - { - Component lastComponent = (Component) lastInRow.get(new Integer(y)); - GridBagConstraints lastConstraints = lookupInternalConstraints(lastComponent); - x = Math.max (x, - lastConstraints.gridx + Math.max(1, lastConstraints.gridwidth)); - } - } - - constraints.gridx = x; - } - // case 3 - else if(constraints.gridy == GridBagConstraints.RELATIVE) - { - int y; - // Check the component that occupies the bottom-most spot in - // this column. We want to add this component below it. - // If this column is empty, add to the 0 position. - if (!lastInCol.containsKey(new Integer(constraints.gridx))) - y = 0; - else - { - Component lastComponent = (Component)lastInCol.get(new Integer(constraints.gridx)); - GridBagConstraints lastConstraints = lookupInternalConstraints(lastComponent); - y = lastConstraints.gridy + Math.max(1, lastConstraints.gridheight); - } - - // Determine if this component will fit in the slot horizontally. - // If not, bump it down to where it does fit. - for (int x = constraints.gridx + 1; x < constraints.gridx + Math.max(1, constraints.gridwidth); x++) - { - if (lastInCol.containsKey(new Integer(x))) - { - Component lastComponent = (Component) lastInCol.get(new Integer(x)); - GridBagConstraints lastConstraints = lookupInternalConstraints(lastComponent); - y = Math.max (y, - lastConstraints.gridy + Math.max(1, lastConstraints.gridheight)); - } - } - - constraints.gridy = y; - } - // case 4: do nothing - - max_x = Math.max(max_x, - constraints.gridx + Math.max(1, constraints.gridwidth)); - max_y = Math.max(max_y, - constraints.gridy + Math.max(1, constraints.gridheight)); - - sortBySpan(component, constraints.gridwidth, sortedByWidth, true); - sortBySpan(component, constraints.gridheight, sortedByHeight, false); - - // Update our reference points for RELATIVE gridx and gridy. - if(constraints.gridwidth == GridBagConstraints.REMAINDER) - { - current_y = constraints.gridy + Math.max(1, constraints.gridheight); - } - else if (constraints.gridwidth != GridBagConstraints.REMAINDER) - { - for (int y = constraints.gridy; y < constraints.gridy + Math.max(1, constraints.gridheight); y++) - { - if(lastInRow.containsKey(new Integer(y))) - { - Component lastComponent = (Component) lastInRow.get(new Integer(y)); - GridBagConstraints lastConstraints = lookupInternalConstraints(lastComponent); - if (constraints.gridx > lastConstraints.gridx) - { - lastInRow.put(new Integer(y), component); - } - } - else - { - lastInRow.put(new Integer(y), component); - } - } - - for (int x = constraints.gridx; x < constraints.gridx + Math.max(1, constraints.gridwidth); x++) - { - if(lastInCol.containsKey(new Integer(x))) - { - Component lastComponent = (Component) lastInCol.get(new Integer(x)); - GridBagConstraints lastConstraints = lookupInternalConstraints(lastComponent); - if (constraints.gridy > lastConstraints.gridy) - { - lastInCol.put(new Integer(x), component); - } - } - else - { - lastInCol.put(new Integer(x), component); - } - } - } - } // end of STEP 1 - - GridBagLayoutInfo info = new GridBagLayoutInfo(max_x, max_y); - - // Check if column widths and row heights are overridden. - - for (int x = 0; x < max_x; x++) - { - if(columnWidths != null && columnWidths.length > x) - info.colWidths[x] = columnWidths[x]; - if(columnWeights != null && columnWeights.length > x) - info.colWeights[x] = columnWeights[x]; - } - - for (int y = 0; y < max_y; y++) - { - if(rowHeights != null && rowHeights.length > y) - info.rowHeights[y] = rowHeights[y]; - if(rowWeights != null && rowWeights.length > y) - info.rowWeights[y] = rowWeights[y]; - } - - // STEP 2: Fix up any cells with width/height as REMAINDER/RELATIVE. - for (int i = 0; i < components.length; i++) - { - Component component = components [i]; - - // If component is not visible we dont have to care about it. - if (!component.isVisible()) - continue; - - GridBagConstraints constraints = lookupInternalConstraints (component); - - if(constraints.gridwidth == GridBagConstraints.REMAINDER || constraints.gridwidth == GridBagConstraints.RELATIVE) - { - if(constraints.gridwidth == GridBagConstraints.REMAINDER) - { - for (int y = constraints.gridy; y < constraints.gridy + Math.max(1, constraints.gridheight); y++) - { - if (lastInRow.containsKey(new Integer(y))) - { - Component lastComponent = (Component) lastInRow.get(new Integer(y)); - GridBagConstraints lastConstraints = lookupInternalConstraints(lastComponent); - - if (lastConstraints.gridwidth == GridBagConstraints.RELATIVE) - { - constraints.gridx = max_x - 1; - break; - } - else - { - constraints.gridx = Math.max (constraints.gridx, - lastConstraints.gridx + Math.max (1, lastConstraints.gridwidth)); - } - } - } - constraints.gridwidth = max_x - constraints.gridx; - } - else if (constraints.gridwidth == GridBagConstraints.RELATIVE) - { - constraints.gridwidth = max_x - constraints.gridx - 1; - } - - // Re-sort - sortedByWidth.remove(sortedByWidth.indexOf(component)); - sortBySpan(component, constraints.gridwidth, sortedByWidth, true); - } - - if(constraints.gridheight == GridBagConstraints.REMAINDER || constraints.gridheight == GridBagConstraints.RELATIVE) - { - if(constraints.gridheight == GridBagConstraints.REMAINDER) - { - for (int x = constraints.gridx; x < constraints.gridx + Math.max(1, constraints.gridwidth); x++) - { - if (lastInCol.containsKey(new Integer(x))) - { - Component lastComponent = (Component) lastInRow.get(new Integer(x)); - GridBagConstraints lastConstraints = lookupInternalConstraints(lastComponent); - - if (lastConstraints.gridheight == GridBagConstraints.RELATIVE) - { - constraints.gridy = max_y - 1; - break; - } - else - { - constraints.gridy = Math.max (constraints.gridy, - lastConstraints.gridy + Math.max (1, lastConstraints.gridheight)); - } - } - } - constraints.gridheight = max_y - constraints.gridy; - } - else if (constraints.gridheight == GridBagConstraints.RELATIVE) - { - constraints.gridheight = max_y - constraints.gridy - 1; - } - - // Re-sort - sortedByHeight.remove(sortedByHeight.indexOf(component)); - sortBySpan(component, constraints.gridheight, sortedByHeight, false); - } - } // end of STEP 2 - - // STEP 3: Determine sizes and weights for columns. - for (int i = 0; i < sortedByWidth.size(); i++) - { - Component component = (Component) sortedByWidth.get(i); - - // If component is not visible we dont have to care about it. - if (!component.isVisible()) - continue; - - GridBagConstraints constraints = lookupInternalConstraints (component); - - int width = (sizeflag == PREFERREDSIZE) ? - component.getPreferredSize().width : - component.getMinimumSize().width; - - if(constraints.insets != null) - width += constraints.insets.left + constraints.insets.right; - - width += constraints.ipadx; - - distributeSizeAndWeight(width, - constraints.weightx, - constraints.gridx, - constraints.gridwidth, - info.colWidths, - info.colWeights); - } // end of STEP 3 - - // STEP 4: Determine sizes and weights for rows. - for (int i = 0; i < sortedByHeight.size(); i++) - { - Component component = (Component) sortedByHeight.get(i); - - // If component is not visible we dont have to care about it. - if (!component.isVisible()) - continue; - - GridBagConstraints constraints = lookupInternalConstraints (component); - - int height = (sizeflag == PREFERREDSIZE) ? - component.getPreferredSize().height : - component.getMinimumSize().height; - - if(constraints.insets != null) - height += constraints.insets.top + constraints.insets.bottom; - - height += constraints.ipady; - - distributeSizeAndWeight(height, - constraints.weighty, - constraints.gridy, - constraints.gridheight, - info.rowHeights, - info.rowWeights); - } // end of STEP 4 - - // Adjust cell sizes iff parent size not zero. - if (parentDim.width > 0 && parentDim.height > 0) - { - calcCellSizes (info.colWidths, info.colWeights, parentDim.width); - calcCellSizes (info.rowHeights, info.rowWeights, parentDim.height); - } - - int totalWidth = sumIntArray(info.colWidths); - int totalHeight = sumIntArray(info.rowHeights); - - // Make sure pos_x and pos_y are never negative. - if (totalWidth >= parentDim.width) - info.pos_x = parentInsets.left; - else - info.pos_x = parentInsets.left + (parentDim.width - totalWidth) / 2; - - if (totalHeight >= parentDim.height) - info.pos_y = parentInsets.top; - else - info.pos_y = parentInsets.top + (parentDim.height - totalHeight) / 2; - - // DEBUG - //dumpLayoutInfo (info); - - return info; - } - - /** - * Obsolete. - */ - protected Dimension GetMinSize (Container parent, GridBagLayoutInfo info) - { - if (parent == null || info == null) - return new Dimension (0, 0); - - Insets insets = parent.getInsets(); - int width = sumIntArray (info.colWidths) + insets.left + insets.right; - int height = sumIntArray (info.rowHeights) + insets.top + insets.bottom; - return new Dimension (width, height); - } - - /** - * @since 1.4 - */ - protected Dimension getMinSize (Container parent, GridBagLayoutInfo info) - { - return GetMinSize (parent, info); - } - - /** - * Helper method used by GetLayoutInfo to keep components sorted, either - * by gridwidth or gridheight. - * - * @param component Component to add to the sorted list. - * @param span Either the component's gridwidth or gridheight. - * @param list <code>ArrayList</code> of components, sorted by - * their span. - * @param sortByWidth Flag indicating sorting index. If true, sort by - * width. Otherwise, sort by height. - * FIXME: Use a better sorting algorithm. - */ - private void sortBySpan (Component component, int span, ArrayList list, boolean sortByWidth) - { - if (span == GridBagConstraints.REMAINDER - || span == GridBagConstraints.RELATIVE) - { - // Put all RELATIVE and REMAINDER components at the end. - list.add(component); - } - else - { - int i = 0; - if (list.size() > 0) - { - GridBagConstraints gbc = lookupInternalConstraints((Component) list.get(i)); - int otherspan = sortByWidth ? - gbc.gridwidth : - gbc.gridheight; - while (otherspan != GridBagConstraints.REMAINDER - && otherspan != GridBagConstraints.RELATIVE - && span >= otherspan) - { - i++; - if (i < list.size()) - { - gbc = lookupInternalConstraints((Component) list.get(i)); - otherspan = sortByWidth ? - gbc.gridwidth : - gbc.gridheight; - } - else - break; - } - } - list.add(i, component); - } - } - - /** - * Helper method used by GetLayoutInfo to distribute a component's size - * and weight. - * - * @param size Preferred size of component, with inset and padding - * already added. - * @param weight Weight of component. - * @param start Starting position of component. Either - * constraints.gridx or gridy. - * @param span Span of component. either contraints.gridwidth or - * gridheight. - * @param sizes Sizes of rows or columns. - * @param weights Weights of rows or columns. - */ - private void distributeSizeAndWeight (int size, double weight, - int start, int span, - int[] sizes, double[] weights) - { - if (span == 1) - { - sizes[start] = Math.max(sizes[start], size); - weights[start] = Math.max(weights[start], weight); - } - else - { - int numOccupied = span; - int lastOccupied = -1; - - for(int i = start; i < start + span; i++) - { - if (sizes[i] == 0.0) - numOccupied--; - else - { - size -= sizes[i]; - lastOccupied = i; - } - } - - // A component needs to occupy at least one row. - if(numOccupied == 0) - sizes[start + span - 1] = size; - else if (size > 0) - sizes[lastOccupied] += size; - - calcCellWeights(weight, weights, start, span); - } - } - - /** - * Helper method used by GetLayoutInfo to calculate weight distribution. - * @param weight Weight of component. - * @param weights Weights of rows/columns. - * @param start Starting position of component in grid (gridx/gridy). - * @param span Span of component (gridwidth/gridheight). - */ - private void calcCellWeights (double weight, double[] weights, int start, int span) - { - double totalWeight = 0.0; - for(int k = start; k < start + span; k++) - totalWeight += weights[k]; - - if(weight > totalWeight) - { - if (totalWeight == 0.0) - { - weights[start + span - 1] += weight; - } - else - { - double diff = weight - totalWeight ; - double remaining = diff; - - for(int k = start; k < start + span; k++) - { - double extraWeight = diff * weights[k] / totalWeight; - weights[k] += extraWeight; - remaining -= extraWeight; - } - - if (remaining > 0.0 && weights[start + span - 1] != 0.0) - { - weights[start + span - 1] += remaining; - } - } - } - } - - /** - * Helper method used by GetLayoutInfo to distribute extra space - * based on weight distribution. - * - * @param sizes Sizes of rows/columns. - * @param weights Weights of rows/columns. - * @param range Dimension of container. - */ - private void calcCellSizes (int[] sizes, double[] weights, int range) - { - int totalSize = sumIntArray (sizes); - double totalWeight = sumDoubleArray (weights); - - int diff = range - totalSize; - - if (diff == 0) - return; - - for (int i = 0; i < sizes.length; i++) - { - int newsize = (int) (sizes[i] + (((double) diff) * weights [i] / totalWeight )); - - if (newsize > 0) - sizes[i] = newsize; - } - } - - private void dumpLayoutInfo (GridBagLayoutInfo info) - { - System.out.println ("GridBagLayoutInfo:"); - System.out.println ("cols: " + info.cols + ", rows: " + info.rows); - System.out.print ("colWidths: "); - dumpArray(info.colWidths); - System.out.print ("rowHeights: "); - dumpArray(info.rowHeights); - System.out.print ("colWeights: "); - dumpArray(info.colWeights); - System.out.print ("rowWeights: "); - dumpArray(info.rowWeights); - } - - private void dumpArray(int[] array) - { - String sep = ""; - for(int i = 0; i < array.length; i++) - { - System.out.print(sep); - System.out.print(array[i]); - sep = ", "; - } - System.out.println(); - } - - private void dumpArray(double[] array) - { - String sep = ""; - for(int i = 0; i < array.length; i++) - { - System.out.print(sep); - System.out.print(array[i]); - sep = ", "; - } - System.out.println(); - } - - /** - * @since 1.4 - */ - protected void arrangeGrid (Container parent) - { - ArrangeGrid (parent); - } - - /** - * @since 1.4 - */ - protected GridBagLayoutInfo getLayoutInfo (Container parent, int sizeflag) - { - return GetLayoutInfo (parent, sizeflag); - } - - /** - * @since 1.4 - */ - protected void adjustForGravity (GridBagConstraints gbc, Rectangle rect) - { - AdjustForGravity (gbc, rect); - } -} diff --git a/libjava/java/awt/GridBagLayoutInfo.java b/libjava/java/awt/GridBagLayoutInfo.java deleted file mode 100644 index 43ba09d72c1..00000000000 --- a/libjava/java/awt/GridBagLayoutInfo.java +++ /dev/null @@ -1,70 +0,0 @@ -/* GridBagLayoutInfo - - Copyright (C) 2003, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.io.Serializable; - -/** - * @author Michael Koch (konqueror@gmx.de) - */ -class GridBagLayoutInfo implements Serializable -{ - private static final long serialVersionUID = -4899416460737170217L; - - int pos_x; - int pos_y; - int cols; - int rows; - int colWidths[]; - int rowHeights[]; - double colWeights[]; - double rowWeights[]; - - GridBagLayoutInfo (int cols, int rows) - { - this.pos_x = 0; - this.pos_y = 0; - this.cols = cols; - this.rows = rows; - this.colWidths = new int [cols]; - this.rowHeights = new int [rows]; - this.colWeights = new double [cols]; - this.rowWeights = new double [rows]; - } -} diff --git a/libjava/java/awt/GridLayout.java b/libjava/java/awt/GridLayout.java deleted file mode 100644 index 80d96414249..00000000000 --- a/libjava/java/awt/GridLayout.java +++ /dev/null @@ -1,360 +0,0 @@ -/* GridLayout.java -- Grid-based layout engine - Copyright (C) 1999, 2000, 2002, 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.io.Serializable; - -/** This class implements a grid-based layout scheme. Components are - * all given the same size and are laid out from left to right and top - * to bottom. A GridLayout is configured with a number of rows and a - * number of columns. If both are specified, then the number of - * columns is ignored and is derived from the number of rows and the - * total number of components. If either is zero then that dimension - * is computed based on the actual size of the container. An - * exception is thrown if an attempt is made to set both the number of - * rows and the number of columns to 0. This class also supports - * horizontal and vertical gaps; these are used as spacing between - * cells. - * - * @author Tom Tromey (tromey@redhat.com) - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public class GridLayout implements LayoutManager, Serializable -{ - static final long serialVersionUID = -7411804673224730901L; - - /** Add a new component to the layout. This particular implementation - * does nothing. - * @param name The name of the component to add. - * @param comp The component to add. - */ - public void addLayoutComponent (String name, Component comp) - { - // Nothing. - } - - /** Return the number of columns in this layout. */ - public int getColumns () - { - return cols; - } - - /** Return the horizontal gap. */ - public int getHgap () - { - return hgap; - } - - /** Return the number of rows in this layout. */ - public int getRows () - { - return rows; - } - - /** Return the vertical gap. */ - public int getVgap () - { - return vgap; - } - - /** Create a new <code>GridLayout</code> with one row and any number - * of columns. Both gaps are set to 0. - */ - public GridLayout () - { - this (1, 0, 0, 0); - } - - /** Create a new <code>GridLayout</code> with the specified number - * of rows and columns. Both gaps are set to 0. Note that the row - * and column settings cannot both be zero. If both the row and - * column values are non-zero, the rows value takes precedence. - * @param rows Number of rows - * @param cols Number of columns - * @exception IllegalArgumentException If rows and columns are both - * 0, or if either are negative - */ - public GridLayout (int rows, int cols) - { - this (rows, cols, 0, 0); - } - - /** Create a new GridLayout with the specified number of rows and - * columns and the specified gaps. - * Note that the row and column settings cannot both be - * zero. If both the row and column values are non-zero, the rows value - * takes precedence. - * @param rows Number of rows - * @param cols Number of columns - * @param hgap The horizontal gap - * @param vgap The vertical gap - * @exception IllegalArgumentException If rows and columns are both - * 0, if either are negative, or if either gap is negative - */ - public GridLayout (int rows, int cols, int hgap, int vgap) - { - if (rows < 0) - throw new IllegalArgumentException ("number of rows cannot be negative"); - if (cols < 0) - throw new IllegalArgumentException ("number of columns cannot be negative"); - if (rows == 0 && cols == 0) - throw new IllegalArgumentException ("both rows and columns cannot be 0"); - if (hgap < 0) - throw new IllegalArgumentException ("horizontal gap must be nonnegative"); - if (vgap < 0) - throw new IllegalArgumentException ("vertical gap must be nonnegative"); - this.rows = rows; - this.cols = cols; - this.hgap = hgap; - this.vgap = vgap; - } - - /** Lay out the container's components based on current settings. - * The free space in the container is divided evenly into the specified - * number of rows and columns in this object. - * @param parent The container to lay out - */ - public void layoutContainer (Container parent) - { - synchronized (parent.getTreeLock ()) - { - int num = parent.ncomponents; - - // There's no point, and handling this would mean adding special - // cases. - if (num == 0) - return; - - // This is more efficient than calling getComponents(). - Component[] comps = parent.component; - - int real_rows = rows; - int real_cols = cols; - if (real_rows == 0) - real_rows = (num + real_cols - 1) / real_cols; - else - real_cols = (num + real_rows - 1) / real_rows; - - // We might have less than a single row. In this case we expand - // to fill. - if (num < real_cols) - real_cols = num; - - Dimension d = parent.getSize (); - Insets ins = parent.getInsets (); - - // Compute width and height of each cell in the grid. - int tw = d.width - ins.left - ins.right; - tw = (tw - (real_cols - 1) * hgap) / real_cols; - int th = d.height - ins.top - ins.bottom; - th = (th - (real_rows - 1) * vgap) / real_rows; - - // If the cells are too small, still try to do something. - if (tw < 0) - tw = 1; - if (th < 0) - th = 1; - - int x = ins.left; - int y = ins.top; - int i = 0; - int recount = 0; - - while (i < num) - { - comps[i].setBounds (x, y, tw, th); - - ++i; - ++recount; - if (recount == real_cols) - { - recount = 0; - y += vgap + th; - x = ins.left; - } - else - x += hgap + tw; - } - } - } - - /** Get the minimum layout size of the container. - * @param cont The parent container - */ - public Dimension minimumLayoutSize (Container cont) - { - return getSize (cont, true); - } - - /** Get the preferred layout size of the container. - * @param cont The parent container - */ - public Dimension preferredLayoutSize (Container cont) - { - return getSize (cont, false); - } - - /** Remove the indicated component from this layout manager. - * This particular implementation does nothing. - * @param comp The component to remove - */ - public void removeLayoutComponent (Component comp) - { - // Nothing. - } - - /** Set the number of columns. - * @param newCols - * @exception IllegalArgumentException If the number of columns is - * negative, or if the number of columns is zero and the number - * of rows is already 0. - */ - public void setColumns (int newCols) - { - if (newCols < 0) - throw new IllegalArgumentException ("number of columns cannot be negative"); - if (newCols == 0 && rows == 0) - throw new IllegalArgumentException ("number of rows is already 0"); - this.cols = newCols; - } - - /** Set the horizontal gap - * @param hgap The horizontal gap - * @exception IllegalArgumentException If the hgap value is less than zero. - */ - public void setHgap (int hgap) - { - if (hgap < 0) - throw new IllegalArgumentException ("horizontal gap must be nonnegative"); - this.hgap = hgap; - } - - /** Set the number of rows - * @param newRows - * @exception IllegalArgumentException If the number of rows is - * negative, or if the number of rows is zero and the number - * of columns is already 0. - */ - public void setRows (int newRows) - { - if (newRows < 0) - throw new IllegalArgumentException ("number of rows cannot be negative"); - if (newRows == 0 && cols == 0) - throw new IllegalArgumentException ("number of columns is already 0"); - this.rows = newRows; - } - - /** Set the vertical gap. - * @param vgap The vertical gap - * @exception IllegalArgumentException If the vgap value is less than zero. - */ - public void setVgap (int vgap) - { - if (vgap < 0) - throw new IllegalArgumentException ("vertical gap must be nonnegative"); - this.vgap = vgap; - } - - /** Return String description of this object. */ - public String toString () - { - return ("[" + getClass ().getName () - + ",hgap=" + hgap + ",vgap=" + vgap - + ",rows=" + rows + ",cols=" + cols - + "]"); - } - - // This method is used to compute the various sizes. - private Dimension getSize (Container parent, boolean is_min) - { - synchronized (parent.getTreeLock ()) - { - int w = 0, h = 0, num = parent.ncomponents; - // This is more efficient than calling getComponents(). - Component[] comps = parent.component; - - for (int i = 0; i < num; ++i) - { - Dimension d; - - if (is_min) - d = comps[i].getMinimumSize (); - else - d = comps[i].getPreferredSize (); - - w = Math.max (d.width, w); - h = Math.max (d.height, h); - } - - int real_rows = rows; - int real_cols = cols; - if (real_rows == 0) - real_rows = (num + real_cols - 1) / real_cols; - else - real_cols = (num + real_rows - 1) / real_rows; - - Insets ins = parent.getInsets (); - // We subtract out an extra gap here because the gaps are only - // between cells. - w = ins.left + ins.right + real_cols * (w + hgap) - hgap; - h = ins.top + ins.bottom + real_rows * (h + vgap) - vgap; - return new Dimension (w, h); - } - } - - /** - * @serial The number of columns in the grid. - */ - private int cols; - - /** - * @serial The number of rows in the grid. - */ - private int rows; - - /** - * @serial The horizontal gap between columns - */ - private int hgap; - - /** - * @serial The vertical gap between rows - */ - private int vgap; -} diff --git a/libjava/java/awt/HeadlessException.java b/libjava/java/awt/HeadlessException.java deleted file mode 100644 index b180b1d86f7..00000000000 --- a/libjava/java/awt/HeadlessException.java +++ /dev/null @@ -1,72 +0,0 @@ -/* HeadlessException.java -- operation not possible in headless environment - Copyright (C) 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -/** - * This exception is thrown when code dependent on a keyboard, mouse, or - * display is executed in a headless environment. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.4 - * @status updated to 1.4 - */ -public class HeadlessException extends UnsupportedOperationException -{ - /** - * Compatible with JDK 1.4+. - */ - private static final long serialVersionUID = 167183644944358563L; - - /** - * Create a new instance with no detailed error message. - */ - public HeadlessException() - { - } - - /** - * Create a new instance with the specified detailed error message. - * - * @param message the detailed error message - */ - public HeadlessException(String message) - { - super(message); - } -} // class HeadlessException diff --git a/libjava/java/awt/IllegalComponentStateException.java b/libjava/java/awt/IllegalComponentStateException.java deleted file mode 100644 index 4a47f1da95d..00000000000 --- a/libjava/java/awt/IllegalComponentStateException.java +++ /dev/null @@ -1,71 +0,0 @@ -/* IllegalComponentStateException.java -- bad component state - Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -/** - * This exception is thrown when the requested operation failed because - * a component was not in the proper state. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @status updated to 1.4 - */ -public class IllegalComponentStateException extends IllegalStateException -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = -1889339587208144238L; - - /** - * Create a new instance with no detailed error message. - */ - public IllegalComponentStateException() - { - } - - /** - * Create a new instance with the specified detailed error message. - * - * @param message the detailed error message - */ - public IllegalComponentStateException(String message) - { - super(message); - } -} // class IllegalComponentStateException diff --git a/libjava/java/awt/Image.java b/libjava/java/awt/Image.java deleted file mode 100644 index 32e30674cd7..00000000000 --- a/libjava/java/awt/Image.java +++ /dev/null @@ -1,203 +0,0 @@ -/* Image.java -- superclass for images - Copyright (C) 1999, 2002, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.awt.image.FilteredImageSource; -import java.awt.image.ImageObserver; -import java.awt.image.ImageProducer; -import java.awt.image.ReplicateScaleFilter; - -/** - * This is the abstract superclass of all image objects in Java. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @since 1.0 - * @status updated to 1.4 - */ -public abstract class Image -{ - /** - * This variable is returned whenever a property that is not defined - * is requested. - */ - // For debug purposes, this might as well be a unique string. - public static final Object UndefinedProperty - = new String("undefined property"); - - /** - * Constant indicating that the default scaling algorithm should be used. - * - * @since 1.1 - */ - public static final int SCALE_DEFAULT = 1; - - /** - * Constant indicating that a fast scaling algorithm should be used. - * - * @since 1.1 - */ - public static final int SCALE_FAST = 2; - - /** - * Constant indicating that a smooth scaling algorithm should be used. - * - * @since 1.1 - */ - public static final int SCALE_SMOOTH = 4; - - /** - * Constant indicating that the <code>ReplicateScaleFilter</code> class - * algorithm should be used for scaling. - * - * @see ReplicateScaleFilter - * @since 1.1 - */ - public static final int SCALE_REPLICATE = 8; - - /** - * Constant indicating that the area averaging scaling algorithm should be - * used. - * - * @see AreaAveragingScaleFilter - * @since 1.1 - */ - public static final int SCALE_AREA_AVERAGING = 16; - - /** - * A default constructor for subclasses. - */ - public Image() - { - } - - /** - * Returns the width of the image, or -1 if it is unknown. If the - * image width is unknown, the observer object will be notified when - * the value is known. - * - * @param observer the image observer for this object - * @return the width in pixels - * @see #getHeight(ImageObserver) - */ - public abstract int getWidth(ImageObserver observer); - - /** - * Returns the height of the image, or -1 if it is unknown. If the - * image height is unknown, the observer object will be notified when - * the value is known. - * - * @param observer the image observer for this object - * @return the height in pixels - * @see #getWidth(ImageObserver) - */ - public abstract int getHeight(ImageObserver observer); - - /** - * Returns the image producer object for this object. The producer is the - * object which generates pixels for this image. - * - * @return the image producer for this object - */ - public abstract ImageProducer getSource(); - - /** - * Returns a graphics context object for drawing an off-screen object. - * This method is only valid for off-screen objects. - * - * @return a graphics context object for an off-screen object - * @see Graphics#createImage(int, int) - */ - public abstract Graphics getGraphics(); - - /** - * This method requests a named property for an object. The value of the - * property is returned. The value <code>UndefinedProperty</code> is - * returned if there is no property with the specified name. The value - * <code>null</code> is returned if the properties for the object are - * not yet known. In this case, the specified image observer is notified - * when the properties are known. - * - * @param name the requested property name - * @param observer the image observer for this object - * @return the named property, if available - * @see #UndefinedProperty - */ - public abstract Object getProperty(String name, ImageObserver observer); - - /** - * Scales the image to the requested dimension. A new Image with asynchronous - * loading will be produced according to the hints of the algorithm - * requested. If either the width or height is non-positive, it is adjusted - * to preserve the original aspect ratio. - * - * @param width the width of the scaled image - * @param height the height of the scaled image - * @param flags a value indicating the algorithm to use - * @return the scaled <code>Image</code> object - * @see #SCALE_DEFAULT - * @see #SCALE_FAST - * @see #SCALE_SMOOTH - * @see #SCALE_REPLICATE - * @see #SCALE_AREA_AVERAGING - * @since 1.1 - */ - public Image getScaledInstance(int width, int height, int flags) - { - switch (flags) - { - case SCALE_DEFAULT: - case SCALE_FAST: - case SCALE_REPLICATE: - ImageProducer producer = - new FilteredImageSource(this.getSource(), - new ReplicateScaleFilter(width, height)); - return Toolkit.getDefaultToolkit().createImage(producer); - case SCALE_SMOOTH: - case SCALE_AREA_AVERAGING: - default: - throw new Error("not implemented"); - } - } - - /** - * Flushes (that is, destroys) any resources used for this image. This - * includes the actual image data. - */ - public abstract void flush(); -} // class Image diff --git a/libjava/java/awt/ImageCapabilities.java b/libjava/java/awt/ImageCapabilities.java deleted file mode 100644 index 2fe71d1e23b..00000000000 --- a/libjava/java/awt/ImageCapabilities.java +++ /dev/null @@ -1,107 +0,0 @@ -/* ImageCapabilities.java -- the capabilities of an image buffer - Copyright (C) 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -/** - * This class represents the capabilities of an image buffer. An - * image buffer may be backed by accelerated graphics resources. - * Those resources may or may not be volatile. This class is used to - * describe these image buffer characteristics. - */ -public class ImageCapabilities implements Cloneable -{ - /** - * Whether or not this the image buffer uses accelerated graphics - * resources. - */ - private final boolean accelerated; - - /** - * Create a new image capability descriptor. - * - * @param accelerated true if the image buffer uses accelerated - * graphics resources - */ - public ImageCapabilities(boolean accelerated) - { - this.accelerated = accelerated; - } - - /** - * Returns whether or not the image buffer uses accelerated graphics - * resources. - * - * @return true if the image buffer uses accelerated graphics - * resources; false otherwise - */ - public boolean isAccelerated() - { - return accelerated; - } - - /** - * Returns whether or not the image buffer's resources are volatile, - * meaning that they can be reclaimed by the graphics system at any - * time. - * - * @return true if the image buffer's resources are volatile; false - * otherwise - */ - public boolean isTrueVolatile() - { - return true; - } - - /** - * Clone this image capability descriptor. - * - * @return a clone of this image capability descriptor - */ - public Object clone() - { - try - { - return super.clone(); - } - catch (CloneNotSupportedException e) - { - throw (Error) new InternalError().initCause(e); - } - } -} diff --git a/libjava/java/awt/Insets.java b/libjava/java/awt/Insets.java deleted file mode 100644 index 7238a34e22a..00000000000 --- a/libjava/java/awt/Insets.java +++ /dev/null @@ -1,158 +0,0 @@ -/* Insets.java -- information about a container border - Copyright (C) 1999, 2000, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.io.Serializable; - -/** - * This class represents the "margin" or space around a container. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Eric Blake (ebb9@email.byu.edu) - * @status - */ -public class Insets implements Cloneable, Serializable -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = -2272572637695466749L; - - /** - * The gap from the top. - * - * @serial the top inset - */ - public int top; - - /** - * The gap from the left. - * - * @serial the left inset - */ - public int left; - - /** - * The gap from the bottom. - * - * @serial the bottom inset - */ - public int bottom; - - /** - * The gap from the right. - * - * @serial the right inset - */ - public int right; - - /** - * Initializes a new instance of <code>Inset</code> with the specified - * inset values. - * - * @param top the top inset - * @param left the left inset - * @param bottom the bottom inset - * @param right the right inset - */ - public Insets(int top, int left, int bottom, int right) - { - this.top = top; - this.left = left; - this.bottom = bottom; - this.right = right; - } - - /** - * Tests whether this object is equal to the specified object. The other - * object must be an instance of Insets with identical field values. - * - * @param obj the object to test against - * @return true if the specified object is equal to this one - */ - public boolean equals(Object obj) - { - if (! (obj instanceof Insets)) - return false; - Insets i = (Insets) obj; - return top == i.top && bottom == i.bottom - && left == i.left && right == i.right; - } - - /** - * Returns a hashcode for this instance. The formula is unspecified, but - * appears to be <code>XXX what is it? </code>. - * - * @return the hashcode - */ - public int hashCode() - { - // This can't be right... - return top + bottom + left + right; - } - - /** - * Returns a string representation of this object, which will be non-null. - * The format is unspecified, but appears to be <code>XXX what is it?</code>. - * - * @return a string representation of this object - */ - public String toString() - { - return getClass().getName() + "(top=" + top + ",bottom=" + bottom + - ",left=" + left + ",right=" + right + ')'; - } - - /** - * Returns a copy of this object. - * - * @return a copy of this object - */ - public Object clone() - { - try - { - return super.clone(); - } - catch (CloneNotSupportedException e) - { - throw (Error) new InternalError().initCause(e); // Impossible - } - } -} // class Insets diff --git a/libjava/java/awt/ItemSelectable.java b/libjava/java/awt/ItemSelectable.java deleted file mode 100644 index f155f723efe..00000000000 --- a/libjava/java/awt/ItemSelectable.java +++ /dev/null @@ -1,75 +0,0 @@ -/* ItemSelectable.java -- items that can be selected - Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.awt.event.ItemListener; - -/** - * This interface is for objects that can have one or more items selected. - * For example, radio buttons. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @since 1.0 - * @status updated to 1.4 - */ -public interface ItemSelectable -{ - /** - * Returns the list of objects that are selected in this component. - * - * @return the list of selected objects, or null - */ - Object[] getSelectedObjects(); - - /** - * Adds an item listener to this object. It will receive selection events - * for this object by the user (but not programatically). If listener is - * null, it is ignored. - * - * @param listener the item listener to add - */ - void addItemListener(ItemListener listener); - - /** - * Removes an item listener from this object. - * - * @param listener the item listener to remove - */ - void removeItemListener(ItemListener listener); -} // interface ItemSelectable diff --git a/libjava/java/awt/JobAttributes.java b/libjava/java/awt/JobAttributes.java deleted file mode 100644 index 2acb3a01ed3..00000000000 --- a/libjava/java/awt/JobAttributes.java +++ /dev/null @@ -1,500 +0,0 @@ -/* JobAttributes.java -- - Copyright (C) 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -/** - * Needs documentation... - * - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.3 - * @status updated to 1.4, lacks documentation - */ -public final class JobAttributes implements Cloneable -{ - public static final class DefaultSelectionType extends AttributeValue - { - private static final String[] NAMES = { "all", "range", "selection" }; - public static final DefaultSelectionType ALL - = new DefaultSelectionType(0); - public static final DefaultSelectionType RANGE - = new DefaultSelectionType(1); - public static final DefaultSelectionType SELECTION - = new DefaultSelectionType(2); - private DefaultSelectionType(int value) - { - super(value, NAMES); - } - } // class DefaultSelectionType - - public static final class DestinationType extends AttributeValue - { - private static final String[] NAMES = { "file", "printer" }; - public static final DestinationType FILE = new DestinationType(0); - public static final DestinationType PRINTER = new DestinationType(1); - private DestinationType(int value) - { - super(value, NAMES); - } - } // class DestinationType - - public static final class DialogType extends AttributeValue - { - private static final String[] NAMES = { "common", "native", "none" }; - public static final DialogType COMMON = new DialogType(0); - public static final DialogType NATIVE = new DialogType(1); - public static final DialogType NONE = new DialogType(2); - private DialogType(int value) - { - super(value, NAMES); - } - } // class DialogType - - public static final class MultipleDocumentHandlingType - extends AttributeValue - { - private static final String[] NAMES = { - "separate-documents-collated-copies", - "separate-documents-uncollated-copies" - }; - public static final MultipleDocumentHandlingType - SEPARATE_DOCUMENTS_COLLATED_COPIES - = new MultipleDocumentHandlingType(0); - public static final MultipleDocumentHandlingType - SEPARATE_DOCUMENTS_UNCOLLATED_COPIES - = new MultipleDocumentHandlingType(1); - private MultipleDocumentHandlingType(int value) - { - super(value, NAMES); - } - } // class MultipleDocumentHandlingType - - public static final class SidesType extends AttributeValue - { - private static final String[] NAMES - = { "one-sided", "two-sided-long-edge", "two-sided-short-edge" }; - public static final SidesType ONE_SIDED = new SidesType(0); - public static final SidesType TWO_SIDED_LONG_EDGE = new SidesType(1); - public static final SidesType TWO_SIDED_SHORT_EDGE = new SidesType(2); - private SidesType(int value) - { - super(value, NAMES); - } - } // class SidesType - - private int copies; - private DefaultSelectionType selection; - private DestinationType destination; - private DialogType dialog; - private String filename; - private int maxPage; - private int minPage; - private MultipleDocumentHandlingType multiple; - private int[][] pageRanges; // null for default value - private int fromPage; // 0 for default value - private int toPage; // 0 for default value - private String printer; - private SidesType sides; - - public JobAttributes() - { - copies = 1; - selection = DefaultSelectionType.ALL; - destination = DestinationType.PRINTER; - dialog = DialogType.NATIVE; - maxPage = Integer.MAX_VALUE; - minPage = 1; - multiple - = MultipleDocumentHandlingType.SEPARATE_DOCUMENTS_UNCOLLATED_COPIES; - sides = SidesType.ONE_SIDED; - } - - public JobAttributes(JobAttributes attr) - { - set(attr); - } - - public JobAttributes(int copies, DefaultSelectionType selection, - DestinationType destination, DialogType dialog, - String filename, int max, int min, - MultipleDocumentHandlingType multiple, - int[][] pageRanges, String printer, SidesType sides) - { - if (copies <= 0 || selection == null || destination == null - || dialog == null || max < min || min <= 0 || multiple == null - || sides == null) - throw new IllegalArgumentException(); - this.copies = copies; - this.selection = selection; - this.destination = destination; - this.dialog = dialog; - this.filename = filename; - maxPage = max; - minPage = min; - this.multiple = multiple; - setPageRanges(pageRanges); - this.printer = printer; - this.sides = sides; - } - - public Object clone() - { - return new JobAttributes(this); - } - - public void set(JobAttributes attr) - { - copies = attr.copies; - selection = attr.selection; - destination = attr.destination; - dialog = attr.dialog; - filename = attr.filename; - maxPage = attr.maxPage; - minPage = attr.minPage; - multiple = attr.multiple; - pageRanges = (int[][]) attr.pageRanges.clone(); - printer = attr.printer; - sides = attr.sides; - fromPage = attr.fromPage; - toPage = attr.toPage; - } - - public int getCopies() - { - return copies; - } - - public void setCopies(int copies) - { - if (copies <= 0) - throw new IllegalArgumentException(); - this.copies = copies; - } - - public void setCopiesToDefault() - { - copies = 1; - } - - public DefaultSelectionType getDefaultSelection() - { - return selection; - } - - public void setDefaultSelection(DefaultSelectionType selection) - { - if (selection == null) - throw new IllegalArgumentException(); - this.selection = selection; - } - - public DestinationType getDestination() - { - return destination; - } - - public void setDestination(DestinationType destination) - { - if (destination == null) - throw new IllegalArgumentException(); - this.destination = destination; - } - - public DialogType getDialog() - { - return dialog; - } - - public void setDialog(DialogType dialog) - { - if (dialog == null) - throw new IllegalArgumentException(); - this.dialog = dialog; - } - - public String getFileName() - { - return filename; - } - - public void setFileName(String filename) - { - this.filename = filename; - } - - public int getFromPage() - { - return fromPage != 0 ? fromPage - : pageRanges != null ? pageRanges[0][0] - : toPage != 0 ? toPage : minPage; - } - - public void setFromPage(int fromPage) - { - if (fromPage < minPage || (fromPage > toPage && toPage != 0) - || fromPage > maxPage) - throw new IllegalArgumentException(); - if (pageRanges == null) - this.fromPage = fromPage; - } - - public int getMaxPage() - { - return maxPage; - } - - public void setMaxPage(int maxPage) - { - if (maxPage < minPage) - throw new IllegalArgumentException(); - this.maxPage = maxPage; - if (maxPage < fromPage) - fromPage = maxPage; - if (maxPage < toPage) - toPage = maxPage; - if (pageRanges != null) - { - int i = pageRanges.length - 1; - while (i >= 0 && maxPage < pageRanges[i][1]) - i--; - if (maxPage >= pageRanges[++i][0]) - pageRanges[i++][1] = maxPage; - if (i == 0) - pageRanges = null; - else if (i < pageRanges.length) - { - int[][] tmp = new int[i][]; - System.arraycopy(pageRanges, 0, tmp, 0, i); - pageRanges = tmp; - } - } - } - - public int getMinPage() - { - return minPage; - } - - public void setMinPage(int minPage) - { - if (minPage <= 0 || minPage > maxPage) - throw new IllegalArgumentException(); - this.minPage = minPage; - if (minPage > toPage) - toPage = minPage; - if (minPage > fromPage) - fromPage = minPage; - if (pageRanges != null) - { - int size = pageRanges.length; - int i = 0; - while (i < size && minPage > pageRanges[i][0]) - i++; - if (minPage <= pageRanges[i - 1][1]) - pageRanges[--i][0] = minPage; - if (i == size) - pageRanges = null; - else if (i > 0) - { - int[][] tmp = new int[size - i][]; - System.arraycopy(pageRanges, i, tmp, 0, size - i); - pageRanges = tmp; - } - } - } - - public MultipleDocumentHandlingType getMultipleDocumentHandling() - { - return multiple; - } - - public void setMultipleDocumentHandling - (MultipleDocumentHandlingType multiple) - { - if (multiple == null) - throw new IllegalArgumentException(); - this.multiple = multiple; - } - - public void setMultipleDocumentHandlingToDefault() - { - multiple - = MultipleDocumentHandlingType.SEPARATE_DOCUMENTS_UNCOLLATED_COPIES; - } - - public int[][] getPageRanges() - { - if (pageRanges == null) - return new int[][] { { getFromPage(), getToPage() } }; - // Perform a deep clone, so user code cannot affect original arrays. - int i = pageRanges.length; - int[][] result = new int[i][]; - while (--i >= 0) - result[i] = (int[]) pageRanges[i].clone(); - return result; - } - - public void setPageRanges(int[][] pageRanges) - { - int size = pageRanges == null ? 0 : pageRanges.length; - if (size == 0) - throw new IllegalArgumentException(); - while (--size >= 0) - { - int[] range = pageRanges[size]; - if (range == null || range.length != 2 - || range[0] < minPage || range[1] < range[0] || range[1] > maxPage - || (size != 0 && range[0] <= pageRanges[size - 1][1])) - throw new IllegalArgumentException(); - } - size = pageRanges.length; - if (fromPage > 0 && pageRanges[0][0] > fromPage) - fromPage = pageRanges[0][0]; - if (toPage > 0 && pageRanges[size - 1][1] < toPage) - toPage = pageRanges[size - 1][1]; - this.pageRanges = new int[size][]; - while (--size >= 0) - this.pageRanges[size] = (int[]) pageRanges[size].clone(); - } - - public String getPrinter() - { - return printer; - } - - public void setPrinter(String printer) - { - this.printer = printer; - } - - public SidesType getSides() - { - return sides; - } - - public void setSides(SidesType sides) - { - if (sides == null) - throw new IllegalArgumentException(); - this.sides = sides; - } - - public void setSidesToDefault() - { - sides = SidesType.ONE_SIDED; - } - - public int getToPage() - { - return toPage != 0 ? toPage - : pageRanges != null ? pageRanges[pageRanges.length - 1][1] - : fromPage != 0 ? fromPage : maxPage; - } - - public void setToPage(int toPage) - { - if (toPage < minPage || (fromPage > toPage && fromPage != 0) - || toPage > maxPage) - throw new IllegalArgumentException(); - if (pageRanges == null) - this.toPage = toPage; - } - - public boolean equals(Object o) - { - if (this == o) - return true; - if (! (o instanceof JobAttributes)) - return false; - JobAttributes ja = (JobAttributes) o; - if (copies != ja.copies || selection != ja.selection - || destination != ja.destination || dialog != ja.dialog - || ! filename.equals(ja.filename) || maxPage != ja.maxPage - || minPage != ja.minPage || multiple != ja.multiple - || fromPage != ja.fromPage || toPage != ja.toPage - || ! printer.equals(ja.printer) || sides != ja.sides - || (pageRanges == null) != (ja.pageRanges == null)) - return false; - if (pageRanges != ja.pageRanges) - for (int i = pageRanges.length; --i >= 0; ) - if (pageRanges[i][0] != ja.pageRanges[i][0] - || pageRanges[i][1] != ja.pageRanges[i][1]) - return false; - return true; - } - - public int hashCode() - { - int hash = (selection.value << 6) ^ (destination.value << 5) - ^ (dialog.value << 3) ^ (multiple.value << 2) ^ sides.value - ^ (filename == null ? 0 : filename.hashCode()) - ^ (printer == null ? 0 : printer.hashCode()); - // The effect of the above fields on the hashcode match the JDK. However, - // I am unable to reverse engineer the effect of the fields listed below, - // so I am using my own implementation. Note that this still satisfies - // the general contract of hashcode, it just doesn't match the JDK. - hash ^= (copies << 27) ^ (maxPage << 22) ^ (minPage << 17); - if (pageRanges == null) - hash ^= (getFromPage() << 13) ^ (getToPage() << 8); - else - for (int i = pageRanges.length; --i >= 0; ) - hash ^= (pageRanges[i][0] << 13) ^ (pageRanges[i][1] << 8); - return hash; - } - - public String toString() - { - StringBuffer s = new StringBuffer("copies=").append(copies) - .append(",defaultSelection=").append(selection).append(",destination=") - .append(destination).append(",dialog=").append(dialog) - .append(",fileName=").append(filename).append(",fromPage=") - .append(getFromPage()).append(",maxPage=").append(maxPage) - .append(",minPage=").append(minPage) - .append(",multiple-document-handling=").append(multiple) - .append(",page-ranges=["); - if (pageRanges == null) - s.append(minPage).append(':').append(minPage).append(']'); - else - for (int i = 0; i < pageRanges.length; i++) - s.append(pageRanges[i][0]).append(':').append(pageRanges[i][1]) - .append(','); - s.setLength(s.length() - 1); - return s.append("],printer=").append(printer).append(",sides=") - .append(sides).append(",toPage=").append(getToPage()).toString(); - } -} // class JobAttributes diff --git a/libjava/java/awt/KeyEventDispatcher.java b/libjava/java/awt/KeyEventDispatcher.java deleted file mode 100644 index 30997278e1b..00000000000 --- a/libjava/java/awt/KeyEventDispatcher.java +++ /dev/null @@ -1,82 +0,0 @@ -/* KeyEventDispatcher.java -- dispatches key events - Copyright (C) 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.awt.event.KeyEvent; - -/** - * An instance of this interface coordinates with a KeyboardFocusManager to - * target and dispatch all key events. This allows retargeting, consuming, - * changing, or otherwise manipulating the key event before sending it on to - * a target. - * - * <p>By default, the KeyboardFocusManager is the sink for all key events not - * dispatched by other dispatchers. Therefore, it is unnecessary for the user - * to register the focus manager as a dispatcher. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @see KeyboardFocusManager#addKeyEventDispatcher(KeyEventDispatcher) - * @see KeyboardFocusManager#removeKeyEventDispatcher(KeyEventDispatcher) - * @since 1.4 - * @status updated to 1.4 - */ -public interface KeyEventDispatcher -{ - /** - * Called by the KeyboardFocusManager to request that a key event be - * dispatched. The dispatcher is free to retarget the event, consume it, - * dispatch it, or make other changes. This is usually done to allow - * delivery of key events to objects other than the window in focus, such - * as for navigating non-focusable components. If this dispatcher chooses - * to dispatch the event itself, it should call <code>redispatchEvent</code> - * to avoid infinite recursion. - * - * <p>If the return value is false, the KeyEvent is passed to the next - * dispatcher in the chain, ending with the KeyboardFocusManager. If the - * return value is true, the event has been consumed (although it might - * have been ignored), and no further action will be taken on the event. Be - * sure to check whether the event was consumed before dispatching it - * further. - * - * @param e the key event - * @return true if the event has been consumed - * @see KeyboardFocusManager#redispatchEvent(Component, AWTEvent) - */ - boolean dispatchKeyEvent(KeyEvent e); -} // interface KeyEventDispatcher diff --git a/libjava/java/awt/KeyEventPostProcessor.java b/libjava/java/awt/KeyEventPostProcessor.java deleted file mode 100644 index 0b39dc25075..00000000000 --- a/libjava/java/awt/KeyEventPostProcessor.java +++ /dev/null @@ -1,81 +0,0 @@ -/* KeyEventPostProcessor.java -- performs actions after a key event dispatch - Copyright (C) 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.awt.event.KeyEvent; - -/** - * An instance of this interface coordinates with a KeyboardFocusManager to - * target and dispatch all key events that are otherwise unconsumed. This - * allows events which take place when nothing has focus to still operate, - * such as menu keyboard shortcuts. - * - * <p>By default, the KeyboardFocusManager is the sink for all key events not - * post-processed elsewhere. Therefore, it is unnecessary for the user - * to register the focus manager as a dispatcher. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @see KeyboardFocusManager#addKeyEventPostProcessor(KeyEventPostProcessor) - * @see KeyboardFocusManager#removeKeyEventPostProcessor(KeyEventPostProcessor) - * @since 1.4 - * @status updated to 1.4 - */ -public interface KeyEventPostProcessor -{ - /** - * Called by the KeyboardFocusManager to request that a key event be - * post-processed. Typically, the event has already been dispatched and - * handled, unless no object has focus. Thus, this allows global event - * handling for things like menu shortcuts. If this post-processor chooses - * to dispatch the event, it should call <code>redispatchEvent</code> - * to avoid infinite recursion. - * - * <p>If the return value is false, the KeyEvent is passed to the next - * dispatcher in the chain, ending with the KeyboardFocusManager. If the - * return value is true, the event has been consumed (although it might - * have been ignored), and no further action will be taken on the event. Be - * sure to check whether the event was consumed before dispatching it - * further. - * - * @param e the key event - * @return true if the event has been consumed - * @see KeyboardFocusManager#redispatchEvent(Component, AWTEvent) - */ - boolean postProcessKeyEvent(KeyEvent e); -} // interface KeyEventPostProcessor diff --git a/libjava/java/awt/KeyboardFocusManager.java b/libjava/java/awt/KeyboardFocusManager.java deleted file mode 100644 index ab355456646..00000000000 --- a/libjava/java/awt/KeyboardFocusManager.java +++ /dev/null @@ -1,1436 +0,0 @@ -/* KeyboardFocusManager.java -- manage component focusing via the keyboard - Copyright (C) 2002, 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.awt.event.FocusEvent; -import java.awt.event.KeyEvent; -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; -import java.beans.PropertyVetoException; -import java.beans.VetoableChangeListener; -import java.beans.VetoableChangeSupport; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; - -/** - * The <code>KeyboardFocusManager</code> handles the focusing of - * windows for receiving keyboard events. The manager handles - * the dispatch of all <code>FocusEvent</code>s and - * <code>KeyEvent</code>s, along with <code>WindowEvent</code>s - * relating to the focused window. Users can use the manager - * to ascertain the current focus owner and fire events. - * <br /> - * <br /> - * The focus owner is the <code>Component</code> that receives - * key events. The focus owner is either the currently focused - * window or a component within this window. - * <br /> - * <br /> - * The underlying native windowing system may denote the active - * window or its children with special decorations (e.g. a highlighted - * title bar). The active window is always either a <code>Frame</code> - * or <code>Dialog</code>, and is either the currently focused - * window or its owner. - * <br /> - * <br /> - * Applets may be partitioned into different applet contexts, according - * to their code base. In this case, each context has its own - * <code>KeyboardFocusManager</code>, as opposed to the global - * manager maintained by applets which share the same context. - * Each context is insulated from the others, and they don't interact. - * The resulting behaviour, as with context division, depends on the browser - * supporting the applets. Regardless, there can only ever be - * one focused window, one active window and one focus owner - * per <code>ClassLoader</code>. - * <br /> - * <br /> - * To support this separation of focus managers, the manager instances - * and the internal state information is grouped by the - * <code>ThreadGroup</code> to which it pertains. With respect to - * applets, each code base has its own <code>ThreadGroup</code>, so the - * isolation of each context is enforced within the manager. - * <br /> - * <br /> - * By default, the manager defines TAB and Ctrl+TAB as the - * forward focus traversal keys and Shift+TAB and Ctrl+Shift+TAB - * as the backward focus traversal keys. No up or down cycle - * traversal keys are defined by default. Traversal takes effect - * on the firing of a relevant <code>KEY_PRESSED</code> event. - * However, all other key events related to the use of the - * defined focus traversal key sequence are consumed and not - * dispatched. - * <br /> - * <br /> - * These default traversal keys come into effect on all windows - * for which no alternative set of keys is defined. This also - * applies recursively to any child components of such a window, - * which define no traversal keys of their own. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @author Thomas Fitzsimmons (fitzsim@redhat.com) - * @author Andrew John Hughes (gnu_andrew@member.fsf.org) - * @since 1.4 - */ -public abstract class KeyboardFocusManager - implements KeyEventDispatcher, KeyEventPostProcessor -{ - /** Identifies {@link AWTKeyStroke}s that move the focus forward in - the focus cycle. */ - public static final int FORWARD_TRAVERSAL_KEYS = 0; - - /** Identifies {@link AWTKeyStroke}s that move the focus backward in - the focus cycle. */ - public static final int BACKWARD_TRAVERSAL_KEYS = 1; - - /** Identifies {@link AWTKeyStroke}s that move the focus up to the - parent focus cycle root. */ - public static final int UP_CYCLE_TRAVERSAL_KEYS = 2; - - /** Identifies {@link AWTKeyStroke}s that move the focus down to the - child focus cycle root. */ - public static final int DOWN_CYCLE_TRAVERSAL_KEYS = 3; - - /** The set of {@link AWTKeyStroke}s that cause focus to be moved to - the next focusable Component in the focus cycle. */ - private static final Set DEFAULT_FORWARD_KEYS; - - /** The set of {@link AWTKeyStroke}s that cause focus to be moved to - the previous focusable Component in the focus cycle. */ - private static final Set DEFAULT_BACKWARD_KEYS; - - /** Populate the DEFAULT_FORWARD_KEYS and DEFAULT_BACKWARD_KEYS - {@link java.util.Set}s. */ - static - { - Set s = new HashSet(); - s.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB, 0)); - s.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB, - KeyEvent.CTRL_DOWN_MASK)); - DEFAULT_FORWARD_KEYS = Collections.unmodifiableSet(s); - s = new HashSet(); - s.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB, - KeyEvent.SHIFT_DOWN_MASK)); - s.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB, - KeyEvent.SHIFT_DOWN_MASK - | KeyEvent.CTRL_DOWN_MASK)); - DEFAULT_BACKWARD_KEYS = Collections.unmodifiableSet(s); - } - - /** The global object {@link java.util.Map}s. */ - - /** For security reasons, {@link java.applet.Applet}s in different - codebases must be insulated from one another. Since {@link - KeyboardFocusManager}s have the ability to return {@link - Component}s from a given {@link java.applet.Applet}, each - codebase must have an independent {@link KeyboardFocusManager}. - Since each codebase has its own {@link ThreadGroup} in which its - {@link Applet}s run, it makes sense to partition {@link - KeyboardFocusManager}s according to {@link - java.lang.ThreadGroup}. Thus, currentKeyboardFocusManagers is a - {@link java.util.Map} keyed on {@link java.lang.ThreadGroup}. */ - private static Map currentKeyboardFocusManagers = new HashMap (); - - /** {@link java.applet.Applet}s in one codebase must not be allowed - to access {@link Component}s in {@link java.applet.Applet}s in - other codebases. To enforce this restriction, we key the - following {@link java.util.Map}s on {@link java.lang.ThreadGroup}s (which - are per-codebase). For example, if {@link - java.lang.ThreadGroup} A calls {@link #setGlobalFocusOwner}, - passing {@link Component} C, currentFocusOwners[A] is assigned - C, and all other currentFocusOwners values are nullified. Then - if {@link java.lang.ThreadGroup} A subsequently calls {@link - #getGlobalFocusOwner}, it will return currentFocusOwners[A], - that is, {@link Component} C. If another {@link - java.lang.ThreadGroup} K calls {@link #getGlobalFocusOwner}, it - will return currentFocusOwners[K], that is, null. - - Since this is a static field, we ensure that there is only one - focused {@link Component} per class loader. */ - private static Map currentFocusOwners = new HashMap (); - - /** A {@link java.util.Map} keyed on {@link java.lang.ThreadGroup}s - that stores the {@link Component} that owns the permanent - keyboard focus. @see currentFocusOwners */ - private static Map currentPermanentFocusOwners = new HashMap (); - - /** A {@link java.util.Map} keyed on {@link java.lang.ThreadGroup}s - that stores the focused {@link Window}. @see - currentFocusOwners */ - private static Map currentFocusedWindows = new HashMap (); - - /** A {@link java.util.Map} keyed on {@link java.lang.ThreadGroup}s - that stores the active {@link Window}. @see - currentFocusOwners */ - private static Map currentActiveWindows = new HashMap (); - - /** A {@link java.util.Map} keyed on {@link java.lang.ThreadGroup}s - that stores the focus cycle root {@link Container}. @see - currentFocusOwners */ - private static Map currentFocusCycleRoots = new HashMap (); - - /** The default {@link FocusTraveralPolicy} that focus-managing - {@link Container}s will use to define their initial focus - traversal policy. */ - private FocusTraversalPolicy defaultPolicy; - - /** An array that stores the {@link #FORWARD_TRAVERSAL_KEYS}, {@link - #BACKWARD_TRAVERSAL_KEYS}, {@link #UP_CYCLE_TRAVERSAL_KEYS} and - {@link #DOWN_CYCLE_TRAVERSAL_KEYS} {@link AWTKeyStroke}s {@link - java.util.Set}s. */ - private Set[] defaultFocusKeys = new Set[] - { - DEFAULT_FORWARD_KEYS, DEFAULT_BACKWARD_KEYS, - Collections.EMPTY_SET, Collections.EMPTY_SET - }; - - /** - * A utility class to support the handling of events relating to property changes. - */ - private final PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport (this); - - /** - * A utility class to support the handling of events relating to vetoable changes. - */ - private final VetoableChangeSupport vetoableChangeSupport = new VetoableChangeSupport (this); - - /** A list of {@link KeyEventDispatcher}s that process {@link - KeyEvent}s before they are processed the default keyboard focus - manager. */ - private final ArrayList keyEventDispatchers = new ArrayList(); - - /** A list of {@link KeyEventPostProcessor}s that process unconsumed - {@link KeyEvent}s. */ - private final ArrayList keyEventPostProcessors = new ArrayList(); - - /** - * Construct a KeyboardFocusManager. - */ - public KeyboardFocusManager () - { - } - - /** - * Retrieve the keyboard focus manager associated with the {@link - * java.lang.ThreadGroup} to which the calling thread belongs. - * - * @return the keyboard focus manager associated with the current - * thread group - */ - public static KeyboardFocusManager getCurrentKeyboardFocusManager () - { - ThreadGroup currentGroup = Thread.currentThread ().getThreadGroup (); - - if (currentKeyboardFocusManagers.get (currentGroup) == null) - setCurrentKeyboardFocusManager (null); - - return (KeyboardFocusManager) currentKeyboardFocusManagers.get (currentGroup); - } - - /** - * Set the keyboard focus manager associated with the {@link - * java.lang.ThreadGroup} to which the calling thread belongs. - * - * @param m the keyboard focus manager for the current thread group - */ - public static void setCurrentKeyboardFocusManager (KeyboardFocusManager m) - { - SecurityManager sm = System.getSecurityManager (); - if (sm != null) - sm.checkPermission (new AWTPermission ("replaceKeyboardFocusManager")); - - ThreadGroup currentGroup = Thread.currentThread ().getThreadGroup (); - KeyboardFocusManager manager; - - if (m == null) - manager = new DefaultKeyboardFocusManager (); - else - manager = m; - - currentKeyboardFocusManagers.put (currentGroup, manager); - } - - /** - * Retrieve the {@link Component} that has the keyboard focus, or - * null if the focus owner was not set by a thread in the current - * {@link java.lang.ThreadGroup}. - * - * @return the keyboard focus owner or null - */ - public Component getFocusOwner () - { - Component owner = (Component) getObject (currentFocusOwners); - if (owner == null) - owner = (Component) getObject (currentPermanentFocusOwners); - return owner; - } - - /** - * Retrieve the {@link Component} that has the keyboard focus, - * regardless of whether or not it was set by a thread in the - * current {@link java.lang.ThreadGroup}. If there is no temporary - * focus owner in effect then this method will return the same value - * as {@link #getGlobalPermanentFocusOwner}. - * - * @return the keyboard focus owner - * @throws SecurityException if this is not the keyboard focus - * manager associated with the current {@link java.lang.ThreadGroup} - */ - protected Component getGlobalFocusOwner () - { - // Check if there is a temporary focus owner. - Component focusOwner = (Component) getGlobalObject (currentFocusOwners); - - return (focusOwner == null) ? getGlobalPermanentFocusOwner () : focusOwner; - } - - /** - * Set the {@link Component} that will be returned by {@link - * #getFocusOwner} (when it is called from the current {@link - * java.lang.ThreadGroup}) and {@link #getGlobalFocusOwner}. This - * method does not actually transfer the keyboard focus. - * - * @param owner the Component to return from getFocusOwner and - * getGlobalFocusOwner - * - * @see Component.requestFocus () - * @see Component.requestFocusInWindow () - */ - protected void setGlobalFocusOwner (Component owner) - { - if (owner == null || owner.focusable) - setGlobalObject (currentFocusOwners, owner, "focusOwner"); - } - - /** - * Clear the global focus owner and deliver a FOCUS_LOST event to - * the previously-focused {@link Component}. Until another {@link - * Component} becomes the keyboard focus owner, key events will be - * discarded by top-level windows. - */ - public void clearGlobalFocusOwner () - { - synchronized (currentFocusOwners) - { - Component focusOwner = getGlobalFocusOwner (); - Component permanentFocusOwner = getGlobalPermanentFocusOwner (); - - setGlobalFocusOwner (null); - setGlobalPermanentFocusOwner (null); - - // Inform the old focus owner that it has lost permanent - // focus. - if (focusOwner != null) - { - // We can't cache the event queue, because of - // bootstrapping issues. We need to set the default - // KeyboardFocusManager in EventQueue before the event - // queue is started. - EventQueue q = Toolkit.getDefaultToolkit ().getSystemEventQueue (); - if (focusOwner != permanentFocusOwner) - q.postEvent (new FocusEvent (focusOwner, FocusEvent.FOCUS_LOST, true)); - else - q.postEvent (new FocusEvent (focusOwner, FocusEvent.FOCUS_LOST, false)); - } - - if (focusOwner != permanentFocusOwner) - { - EventQueue q = Toolkit.getDefaultToolkit ().getSystemEventQueue (); - q.postEvent (new FocusEvent (permanentFocusOwner, FocusEvent.FOCUS_LOST, false)); - } - } - } - - /** - * Retrieve the {@link Component} that has the permanent keyboard - * focus, or null if the focus owner was not set by a thread in the - * current {@link java.lang.ThreadGroup}. - * - * @return the keyboard focus owner or null - */ - public Component getPermanentFocusOwner () - { - return (Component) getObject (currentPermanentFocusOwners); - } - - /** - * Retrieve the {@link Component} that has the permanent keyboard - * focus, regardless of whether or not it was set by a thread in the - * current {@link java.lang.ThreadGroup}. - * - * @return the keyboard focus owner - * @throws SecurityException if this is not the keyboard focus - * manager associated with the current {@link java.lang.ThreadGroup} - */ - protected Component getGlobalPermanentFocusOwner () - { - return (Component) getGlobalObject (currentPermanentFocusOwners); - } - - /** - * Set the {@link Component} that will be returned by {@link - * #getPermanentFocusOwner} (when it is called from the current - * {@link java.lang.ThreadGroup}) and {@link - * #getGlobalPermanentFocusOwner}. This method does not actually - * transfer the keyboard focus. - * - * @param focusOwner the Component to return from - * getPermanentFocusOwner and getGlobalPermanentFocusOwner - * - * @see Component.requestFocus () - * @see Component.requestFocusInWindow () - */ - protected void setGlobalPermanentFocusOwner (Component focusOwner) - { - if (focusOwner == null || focusOwner.focusable) - setGlobalObject (currentPermanentFocusOwners, focusOwner, - "permanentFocusOwner"); - } - - /** - * Retrieve the {@link Window} that is or contains the keyboard - * focus owner, or null if the focused window was not set by a - * thread in the current {@link java.lang.ThreadGroup}. - * - * @return the focused window or null - */ - public Window getFocusedWindow () - { - return (Window) getObject (currentFocusedWindows); - } - - /** - * Retrieve the {@link Window} that is or contains the focus owner, - * regardless of whether or not the {@link Window} was set focused - * by a thread in the current {@link java.lang.ThreadGroup}. - * - * @return the focused window - * @throws SecurityException if this is not the keyboard focus - * manager associated with the current {@link java.lang.ThreadGroup} - */ - protected Window getGlobalFocusedWindow () - { - return (Window) getGlobalObject (currentFocusedWindows); - } - - /** - * Set the {@link Window} that will be returned by {@link - * #getFocusedWindow} (when it is called from the current {@link - * java.lang.ThreadGroup}) and {@link #getGlobalFocusedWindow}. - * This method does not actually cause <code>window</code> to become - * the focused {@link Window}. - * - * @param window the Window to return from getFocusedWindow and - * getGlobalFocusedWindow - */ - protected void setGlobalFocusedWindow (Window window) - { - if (window == null || window.focusable) - setGlobalObject (currentFocusedWindows, window, "focusedWindow"); - } - - /** - * Retrieve the active {@link Window}, or null if the active window - * was not set by a thread in the current {@link - * java.lang.ThreadGroup}. - * - * @return the active window or null - */ - public Window getActiveWindow() - { - return (Window) getObject (currentActiveWindows); - } - - /** - * Retrieve the active {@link Window}, regardless of whether or not - * the {@link Window} was made active by a thread in the current - * {@link java.lang.ThreadGroup}. - * - * @return the active window - * @throws SecurityException if this is not the keyboard focus - * manager associated with the current {@link java.lang.ThreadGroup} - */ - protected Window getGlobalActiveWindow() - { - return (Window) getGlobalObject (currentActiveWindows); - } - - /** - * Set the {@link Window} that will be returned by {@link - * #getActiveWindow} (when it is called from the current {@link - * java.lang.ThreadGroup}) and {@link #getGlobalActiveWindow}. This - * method does not actually cause <code>window</code> to be made - * active. - * - * @param window the Window to return from getActiveWindow and - * getGlobalActiveWindow - */ - protected void setGlobalActiveWindow(Window window) - { - setGlobalObject (currentActiveWindows, window, "activeWindow"); - } - - /** - * Retrieve the default {@link FocusTraversalPolicy}. - * Focus-managing {@link Container}s use the returned object to - * define their initial focus traversal policy. - * - * @return a non-null default FocusTraversalPolicy object - */ - public FocusTraversalPolicy getDefaultFocusTraversalPolicy () - { - if (defaultPolicy == null) - defaultPolicy = new DefaultFocusTraversalPolicy (); - return defaultPolicy; - } - - /** - * Set the {@link FocusTraversalPolicy} returned by {@link - * #getDefaultFocusTraversalPolicy}. Focus-managing {@link - * Container}s created after this call will use policy as their - * initial focus traversal policy. Existing {@link Container}s' - * focus traversal policies will not be affected by calls to this - * method. - * - * @param policy the FocusTraversalPolicy that will be returned by - * subsequent calls to getDefaultFocusTraversalPolicy - * @throws IllegalArgumentException if policy is null - */ - public void setDefaultFocusTraversalPolicy (FocusTraversalPolicy policy) - { - if (policy == null) - throw new IllegalArgumentException (); - firePropertyChange ("defaultFocusTraversalPolicy", defaultPolicy, policy); - defaultPolicy = policy; - } - - /** - * Set the default {@link java.util.Set} of focus traversal keys for - * one of the focus traversal directions. - * - * @param id focus traversal direction identifier - * @param keystrokes set of AWTKeyStrokes - * - * @see #FORWARD_TRAVERSAL_KEYS - * @see #BACKWARD_TRAVERSAL_KEYS - * @see #UP_CYCLE_TRAVERSAL_KEYS - * @see #DOWN_CYCLE_TRAVERSAL_KEYS - */ - public void setDefaultFocusTraversalKeys (int id, Set keystrokes) - { - if (id != KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS && - id != KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS && - id != KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS && - id != KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS) - throw new IllegalArgumentException (); - - if (keystrokes == null) - throw new IllegalArgumentException (); - - Set sa; - Set sb; - Set sc; - String type; - switch (id) - { - case FORWARD_TRAVERSAL_KEYS: - sa = defaultFocusKeys[BACKWARD_TRAVERSAL_KEYS]; - sb = defaultFocusKeys[UP_CYCLE_TRAVERSAL_KEYS]; - sc = defaultFocusKeys[DOWN_CYCLE_TRAVERSAL_KEYS]; - type = "forwardDefaultFocusTraversalKeys"; - break; - case BACKWARD_TRAVERSAL_KEYS: - sa = defaultFocusKeys[FORWARD_TRAVERSAL_KEYS]; - sb = defaultFocusKeys[UP_CYCLE_TRAVERSAL_KEYS]; - sc = defaultFocusKeys[DOWN_CYCLE_TRAVERSAL_KEYS]; - type = "backwardDefaultFocusTraversalKeys"; - break; - case UP_CYCLE_TRAVERSAL_KEYS: - sa = defaultFocusKeys[FORWARD_TRAVERSAL_KEYS]; - sb = defaultFocusKeys[BACKWARD_TRAVERSAL_KEYS]; - sc = defaultFocusKeys[DOWN_CYCLE_TRAVERSAL_KEYS]; - type = "upCycleDefaultFocusTraversalKeys"; - break; - case DOWN_CYCLE_TRAVERSAL_KEYS: - sa = defaultFocusKeys[FORWARD_TRAVERSAL_KEYS]; - sb = defaultFocusKeys[BACKWARD_TRAVERSAL_KEYS]; - sc = defaultFocusKeys[UP_CYCLE_TRAVERSAL_KEYS]; - type = "downCycleDefaultFocusTraversalKeys"; - break; - default: - throw new IllegalArgumentException (); - } - int i = keystrokes.size (); - Iterator iter = keystrokes.iterator (); - while (--i >= 0) - { - Object o = iter.next (); - if (!(o instanceof AWTKeyStroke) - || sa.contains (o) || sb.contains (o) || sc.contains (o) - || ((AWTKeyStroke) o).keyCode == KeyEvent.VK_UNDEFINED) - throw new IllegalArgumentException (); - } - keystrokes = Collections.unmodifiableSet (new HashSet (keystrokes)); - firePropertyChange (type, defaultFocusKeys[id], keystrokes); - defaultFocusKeys[id] = keystrokes; - } - - /** - * Retrieve the default {@link java.util.Set} of focus traversal - * keys for one of the focus traversal directions. - * - * @param id focus traversal direction identifier - * - * @return the default set of AWTKeyStrokes - * - * @see #FORWARD_TRAVERSAL_KEYS - * @see #BACKWARD_TRAVERSAL_KEYS - * @see #UP_CYCLE_TRAVERSAL_KEYS - * @see #DOWN_CYCLE_TRAVERSAL_KEYS - */ - public Set getDefaultFocusTraversalKeys (int id) - { - if (id < FORWARD_TRAVERSAL_KEYS || id > DOWN_CYCLE_TRAVERSAL_KEYS) - throw new IllegalArgumentException (); - return defaultFocusKeys[id]; - } - - /** - * Retrieve the current focus cycle root, or null if the focus owner - * was not set by a thread in the current {@link - * java.lang.ThreadGroup}. - * - * @return the current focus cycle root or null - */ - public Container getCurrentFocusCycleRoot () - { - return (Container) getObject (currentFocusCycleRoots); - } - - /** - * Retrieve the current focus cycle root, regardless of whether or - * not it was made set by a thread in the current {@link - * java.lang.ThreadGroup}. - * - * @return the current focus cycle root - * @throws SecurityException if this is not the keyboard focus - * manager associated with the current {@link java.lang.ThreadGroup} - */ - protected Container getGlobalCurrentFocusCycleRoot () - { - return (Container) getGlobalObject (currentFocusCycleRoots); - } - - /** - * Set the {@link Container} that will be returned by {@link - * #getCurrentFocusCycleRoot} (when it is called from the current - * {@link java.lang.ThreadGroup}) and {@link - * #getGlobalCurrentFocusCycleRoot}. This method does not actually - * make <code>cycleRoot</code> the current focus cycle root. - * - * @param cycleRoot the focus cycle root to return from - * getCurrentFocusCycleRoot and getGlobalCurrentFocusCycleRoot - */ - public void setGlobalCurrentFocusCycleRoot (Container cycleRoot) - { - setGlobalObject (currentFocusCycleRoots, cycleRoot, "currentFocusCycleRoot"); - } - - /** - * Registers the supplied property change listener for receiving - * events caused by the following property changes: - * - * <ul> - * <li>the current focus owner ("focusOwner")</li> - * <li>the permanent focus owner ("permanentFocusOwner")</li> - * <li>the focused window ("focusedWindow")</li> - * <li>the active window ("activeWindow")</li> - * <li>the default focus traversal policy ("defaultFocusTraversalPolicy")</li> - * <li>the default set of forward traversal keys ("forwardDefaultFocusTraversalKeys")</li> - * <li>the default set of backward traversal keys ("backwardDefaultFocusTraversalKeys")</li> - * <li>the default set of up cycle traversal keys ("upCycleDefaultFocusTraversalKeys")</li> - * <li>the default set of down cycle traversal keys ("downCycleDefaultFocusTraversalKeys")</li> - * <li>the current focus cycle root ("currentFocusCycleRoot")</li> - * </ul> - * - * If the supplied listener is null, nothing occurs. - * - * @param l the new listener to register. - * @see KeyboardFocusManager#addPropertyChangeListener(String, java.beans.PropertyChangeListener) - */ - public void addPropertyChangeListener(PropertyChangeListener l) - { - if (l != null) - propertyChangeSupport.addPropertyChangeListener(l); - } - - /** - * Removes the supplied property change listener from the list - * of registered listeners. If the supplied listener is null, - * nothing occurs. - * - * @param l the listener to remove. - */ - public void removePropertyChangeListener(PropertyChangeListener l) - { - if (l != null) - propertyChangeSupport.removePropertyChangeListener(l); - } - - /** - * Returns the currently registered property change listeners - * in array form. The returned array is empty if no listeners are - * currently registered. - * - * @return an array of registered property change listeners. - */ - public PropertyChangeListener[] getPropertyChangeListeners() - { - return propertyChangeSupport.getPropertyChangeListeners(); - } - - /** - * Registers a property change listener for receiving events relating - * to a change to a specified property. The supplied property name can be - * either user-defined or one from the following list of properties - * relevant to this class: - * - * <ul> - * <li>the current focus owner ("focusOwner")</li> - * <li>the permanent focus owner ("permanentFocusOwner")</li> - * <li>the focused window ("focusedWindow")</li> - * <li>the active window ("activeWindow")</li> - * <li>the default focus traversal policy ("defaultFocusTraversalPolicy")</li> - * <li>the default set of forward traversal keys ("forwardDefaultFocusTraversalKeys")</li> - * <li>the default set of backward traversal keys ("backwardDefaultFocusTraversalKeys")</li> - * <li>the default set of up cycle traversal keys ("upCycleDefaultFocusTraversalKeys")</li> - * <li>the default set of down cycle traversal keys ("downCycleDefaultFocusTraversalKeys")</li> - * <li>the current focus cycle root ("currentFocusCycleRoot")</li> - * </ul> - * - * Nothing occurs if a null listener is supplied. null is regarded as a valid property name. - * - * @param name the name of the property to handle change events for. - * @param l the listener to register for changes to the specified property. - * @see KeyboardFocusManager#addPropertyChangeListener(java.beans.PropertyChangeListener) - */ - public void addPropertyChangeListener(String name, PropertyChangeListener l) - { - if (l != null) - propertyChangeSupport.addPropertyChangeListener(name, l); - } - - /** - * Removes the supplied property change listener registered for the - * specified property from the list of registered listeners. If the - * supplied listener is null, nothing occurs. - * - * @param name the name of the property the listener is - * monitoring changes to. - * @param l the listener to remove. - */ - public void removePropertyChangeListener(String name, - PropertyChangeListener l) - { - if (l != null) - propertyChangeSupport.removePropertyChangeListener(name, l); - } - - /** - * Returns the currently registered property change listeners - * in array form, which listen for changes to the supplied property. - * The returned array is empty, if no listeners are currently registered - * for events pertaining to the supplied property. - * - * @param name The property the returned listeners monitor for changes. - * @return an array of registered property change listeners which - * listen for changes to the supplied property. - */ - public PropertyChangeListener[] getPropertyChangeListeners(String name) - { - return propertyChangeSupport.getPropertyChangeListeners(name); - } - - /** - * Fires a property change event as a response to a change to - * to the specified property. The event is only fired if a - * change has actually occurred (i.e. o and n are different). - * - * @param name The name of the property to which a change occurred. - * @param o The old value of the property. - * @param n The new value of the property. - */ - protected void firePropertyChange(String name, Object o, Object n) - { - propertyChangeSupport.firePropertyChange(name, o, n); - } - - /** - * Registers a vetoable property change listener for receiving events - * relating to the following properties: - * - * <ul> - * <li>the current focus owner ("focusOwner")</li> - * <li>the permanent focus owner ("permanentFocusOwner")</li> - * <li>the focused window ("focusedWindow")</li> - * <li>the active window ("activeWindow")</li> - * </ul> - * - * Nothing occurs if a null listener is supplied. - * - * @param l the listener to register. - * @see KeyboardFocusManager#addVetoableChangeListener(String, java.beans.VetoableChangeListener) - */ - public void addVetoableChangeListener(VetoableChangeListener l) - { - if (l != null) - vetoableChangeSupport.addVetoableChangeListener(l); - } - - /** - * Removes the supplied vetoable property change listener from - * the list of registered listeners. If the supplied listener - * is null, nothing occurs. - * - * @param l the listener to remove. - */ - public void removeVetoableChangeListener(VetoableChangeListener l) - { - if (l != null) - vetoableChangeSupport.removeVetoableChangeListener(l); - } - - /** - * Returns the currently registered vetoable property change listeners - * in array form. The returned array is empty if no listeners are - * currently registered. - * - * @return an array of registered vetoable property change listeners. - * @since 1.4 - */ - public VetoableChangeListener[] getVetoableChangeListeners() - { - return vetoableChangeSupport.getVetoableChangeListeners(); - } - - /** - * Registers a vetoable property change listener for receiving events relating - * to a vetoable change to a specified property. The supplied property name can be - * either user-defined or one from the following list of properties - * relevant to this class: - * - * <ul> - * <li>the current focus owner ("focusOwner")</li> - * <li>the permanent focus owner ("permanentFocusOwner")</li> - * <li>the focused window ("focusedWindow")</li> - * <li>the active window ("activeWindow")</li> - * </ul> - * - * Nothing occurs if a null listener is supplied. null is regarded as a valid property name. - * - * @param name the name of the property to handle change events for. - * @param l the listener to register for changes to the specified property. - * @see KeyboardFocusManager#addVetoableChangeListener(java.beans.VetoableChangeListener) - */ - public void addVetoableChangeListener(String name, VetoableChangeListener l) - { - if (l != null) - vetoableChangeSupport.addVetoableChangeListener(name, l); - } - - /** - * Removes the supplied vetoable property change listener registered - * for the specified property from the list of registered listeners. - * If the supplied listener is null, nothing occurs. - * - * @param name the name of the vetoable property the listener is - * monitoring changes to. - * @param l the listener to remove. - */ - public void removeVetoableChangeListener(String name, - VetoableChangeListener l) - { - if (l != null) - vetoableChangeSupport.removeVetoableChangeListener(name, l); - } - - /** - * Returns the currently registered vetoable property change listeners - * in array form, which listen for changes to the supplied property. - * The returned array is empty, if no listeners are currently registered - * for events pertaining to the supplied property. - * - * @param name The property the returned listeners monitor for changes. - * @return an array of registered property change listeners which - * listen for changes to the supplied property. - * @since 1.4 - */ - public VetoableChangeListener[] getVetoableChangeListeners(String name) - { - return vetoableChangeSupport.getVetoableChangeListeners(name); - } - - /** - * Fires a property change event as a response to a vetoable change to - * to the specified property. The event is only fired if a - * change has actually occurred (i.e. o and n are different). - * In the event that the property change is vetoed, the following - * occurs: - * - * <ol> - * <li> - * This method throws a <code>PropertyVetoException</code> to - * the proposed change. - * </li> - * <li> - * A new event is fired to reverse the previous change. - * </li> - * <li> - * This method again throws a <code>PropertyVetoException</code> - * in response to the reversion. - * </li> - * </ol> - * - * @param name The name of the property to which a change occurred. - * @param o The old value of the property. - * @param n The new value of the property. - * @throws PropertyVetoException if one of the listeners vetos - * the change by throwing this exception. - */ - protected void fireVetoableChange(String name, Object o, Object n) - throws PropertyVetoException - { - vetoableChangeSupport.fireVetoableChange(name, o, n); - } - - /** - * Adds a key event dispatcher to the list of registered dispatchers. - * When a key event is fired, each dispatcher's <code>dispatchKeyEvent</code> - * method is called in the order that they were added, prior to the manager - * dispatching the event itself. Notifications halt when one of the - * dispatchers returns true. - * <br /> - * <br /> - * The same dispatcher can exist multiple times within the list - * of registered dispatchers, and there is no limit on the length - * of this list. A null dispatcher is simply ignored. - * - * @param dispatcher The dispatcher to register. - */ - public void addKeyEventDispatcher(KeyEventDispatcher dispatcher) - { - if (dispatcher != null) - keyEventDispatchers.add(dispatcher); - } - - /** - * Removes the specified key event dispatcher from the list of - * registered dispatchers. The manager always dispatches events, - * regardless of its existence within the list. The manager - * can be added and removed from the list, as with any other - * dispatcher, but this does not affect its ability to dispatch - * key events. Non-existent and null dispatchers are simply ignored - * by this method. - * - * @param dispatcher The dispatcher to remove. - */ - public void removeKeyEventDispatcher(KeyEventDispatcher dispatcher) - { - keyEventDispatchers.remove(dispatcher); - } - - /** - * Returns the currently registered key event dispatchers in <code>List</code> - * form. At present, this only includes dispatchers explicitly registered - * via the <code>addKeyEventDispatcher()</code> method, but this behaviour - * is subject to change and should not be depended on. The manager itself - * may be a member of the list, but only if explicitly registered. If no - * dispatchers have been registered, the list will be empty. - * - * @return A list of explicitly registered key event dispatchers. - * @see KeyboardFocusManager#addKeyEventDispatcher(java.awt.KeyEventDispatcher) - */ - protected List getKeyEventDispatchers () - { - return (List) keyEventDispatchers.clone (); - } - - /** - * Adds a key event post processor to the list of registered post processors. - * Post processors work in the same way as key event dispatchers, except - * that they are invoked after the manager has dispatched the key event, - * and not prior to this. Each post processor's <code>postProcessKeyEvent</code> - * method is called to see if any post processing needs to be performed. THe - * processors are called in the order in which they were added to the list, - * and notifications continue until one returns true. As with key event - * dispatchers, the manager is implicitly called following this process, - * regardless of whether or not it is present within the list. - * <br /> - * <br /> - * The same post processor can exist multiple times within the list - * of registered post processors, and there is no limit on the length - * of this list. A null post processor is simply ignored. - * - * @param postProcessor the post processor to register. - * @see KeyboardFocusManager#addKeyEventDispatcher(java.awt.KeyEventDispatcher) - */ - public void addKeyEventPostProcessor (KeyEventPostProcessor postProcessor) - { - if (postProcessor != null) - keyEventPostProcessors.add (postProcessor); - } - - /** - * Removes the specified key event post processor from the list of - * registered post processors. The manager always post processes events, - * regardless of its existence within the list. The manager - * can be added and removed from the list, as with any other - * post processor, but this does not affect its ability to post process - * key events. Non-existent and null post processors are simply ignored - * by this method. - * - * @param postProcessor the post processor to remove. - */ - public void removeKeyEventPostProcessor (KeyEventPostProcessor postProcessor) - { - keyEventPostProcessors.remove (postProcessor); - } - - /** - * Returns the currently registered key event post processors in <code>List</code> - * form. At present, this only includes post processors explicitly registered - * via the <code>addKeyEventPostProcessor()</code> method, but this behaviour - * is subject to change and should not be depended on. The manager itself - * may be a member of the list, but only if explicitly registered. If no - * post processors have been registered, the list will be empty. - * - * @return A list of explicitly registered key event post processors. - * @see KeyboardFocusManager#addKeyEventPostProcessor(java.awt.KeyEventPostProcessor) - */ - protected List getKeyEventPostProcessors () - { - return (List) keyEventPostProcessors.clone (); - } - - /** - * The AWT event dispatcher uses this method to request that the manager - * handle a particular event. If the manager fails or refuses to - * dispatch the supplied event (this method returns false), the - * AWT event dispatcher will try to dispatch the event itself. - * <br /> - * <br /> - * The manager is expected to handle all <code>FocusEvent</code>s - * and <code>KeyEvent</code>s, and <code>WindowEvent</code>s - * relating to the focus. Dispatch is done with regard to the - * the focus owner and the currently focused and active windows. - * In handling the event, the source of the event may be overridden. - * <br /> - * <br /> - * The actual dispatching is performed by calling - * <code>redispatchEvent()</code>. This avoids the infinite recursion - * of dispatch requests which may occur if this method is called on - * the target component. - * - * @param e the event to dispatch. - * @return true if the event was dispatched. - * @see KeyboardFocusManager#redispatchEvent(java.awt.Component, java.awt.AWTEvent) - * @see KeyEvent - * @see FocusEvent - * @see WindowEvent - */ - public abstract boolean dispatchEvent (AWTEvent e); - - /** - * Handles redispatching of an event so that recursion of - * dispatch requests does not occur. Event dispatch methods - * within this manager (<code>dispatchEvent()</code>) and - * the key event dispatchers should use this method to handle - * dispatching rather than the dispatch method of the target - * component. - * <br /> - * <br /> - * <strong> - * This method is not intended for general consumption, and is - * only for the use of the aforementioned classes. - * </strong> - * - * @param target the target component to which the event is - * dispatched. - * @param e the event to dispatch. - */ - public final void redispatchEvent (Component target, AWTEvent e) - { - synchronized (e) - { - e.setSource (target); - target.dispatchEvent (e); - } - } - - /** - * Attempts to dispatch key events for which no key event dispatcher - * has so far succeeded. This method is usually called by - * <code>dispatchEvent()</code> following the sending of the key - * event to any registered key event dispatchers. If the key - * event reaches this stage, none of the dispatchers returned - * true. This is, of course, always the case if there are no - * registered dispatchers. - * <br /> - * <br /> - * If this method also fails to handle the key event, then - * false is returned to the caller. In the case of - * <code>dispatchEvent()</code>, the calling method may try - * to handle the event itself or simply forward on the - * false result to its caller. When the event is dispatched - * by this method, a true result is propogated through the - * calling methods. - * - * @param e the key event to dispatch. - * @return true if the event was dispatched successfully. - */ - public abstract boolean dispatchKeyEvent (KeyEvent e); - - /** - * Handles the post processing of key events. By default, - * this method will map unhandled key events to appropriate - * <code>MenuShortcut</code>s. The event is consumed - * in the process and the shortcut is activated. This - * method is usually called by <code>dispatchKeyEvent</code>. - * - * @param e the key event to post process. - * @return true by default, as the event was handled. - */ - public abstract boolean postProcessKeyEvent (KeyEvent e); - - /** - * Handles focus traversal operations for key events which - * represent focus traversal keys in relation to the supplied - * component. The supplied component is assumed to have the - * focus, whether it does so or not, and the operation is - * carried out as appropriate, with this in mind. - * - * @param focused the component on which to perform focus traversal, - * on the assumption that this component has the focus. - * @param e the possible focus traversal key event. - */ - public abstract void processKeyEvent (Component focused, KeyEvent e); - - /** - * Delays all key events following the specified timestamp until the - * supplied component has focus. The AWT calls this method when it is - * determined that a focus change may occur within the native windowing - * system. Any key events which occur following the time specified by - * after are delayed until a <code>FOCUS_GAINED</code> event is received - * for the untilFocused component. The manager is responsible for ensuring - * this takes place. - * - * @param after the timestamp beyond which all key events are delayed until - * the supplied component gains focus. - * @param untilFocused the component to wait on gaining focus. - */ - protected abstract void enqueueKeyEvents (long after, Component untilFocused); - - /** - * Removes the key event block specified by the supplied timestamp and component. - * All delayed key events are released for normal dispatching following its - * removal and subsequent key events that would have been blocked are now - * immediately dispatched. If the specified timestamp is below 0, then - * the request with the oldest timestamp is removed. - * - * @param after the timestamp of the key event block to be removed, or a - * value smaller than 0 if the oldest is to be removed. - * @param untilFocused the component of the key event block to be removed. - */ - protected abstract void dequeueKeyEvents (long after, Component untilFocused); - - /** - * Discards all key event blocks relating to focus requirements for - * the supplied component, regardless of timestamp. - * - * @param comp the component of the key event block(s) to be removed. - */ - protected abstract void discardKeyEvents (Component comp); - - /** - * Moves the current focus to the next component following - * comp, based on the current focus traversal policy. By - * default, only visible, displayable, accepted components - * can receive focus. <code>Canvas</code>es, <code>Panel</code>s, - * <code>Label</code>s, <code>ScrollPane</code>s, <code>Scrollbar</code>s, - * <code>Window</code>s and lightweight components are judged - * to be unacceptable by default. See the - * <code>DefaultFocusTraversalPolicy</code> for more details. - * - * @param comp the component prior to the one which will - * become the focus, following execution of this method. - * @see DefaultFocusTraversalPolicy - */ - public abstract void focusNextComponent(Component comp); - - /** - * Moves the current focus to the previous component, prior to - * comp, based on the current focus traversal policy. By - * default, only visible, displayable, accepted components - * can receive focus. <code>Canvas</code>es, <code>Panel</code>s, - * <code>Label</code>s, <code>ScrollPane</code>s, <code>Scrollbar</code>s, - * <code>Window</code>s and lightweight components are judged - * to be unacceptable by default. See the - * <code>DefaultFocusTraversalPolicy</code> for more details. - * - * @param comp the component following the one which will - * become the focus, following execution of this method. - * @see DefaultFocusTraversalPolicy - */ - public abstract void focusPreviousComponent(Component comp); - - /** - * Moves the current focus upwards by one focus cycle. - * Both the current focus owner and current focus cycle root - * become the focus cycle root of the supplied component. - * However, in the case of a <code>Window</code>, the default - * focus component becomes the focus owner and the focus cycle - * root is not changed. - * - * @param comp the component used as part of the focus traversal. - */ - public abstract void upFocusCycle(Component comp); - - /** - * Moves the current focus downwards by one focus cycle. - * If the supplied container is a focus cycle root, then this - * becomes the current focus cycle root and the focus goes - * to the default component of the specified container. - * Nothing happens for non-focus cycle root containers. - * - * @param cont the container used as part of the focus traversal. - */ - public abstract void downFocusCycle(Container cont); - - /** - * Moves the current focus to the next component, based on the - * current focus traversal policy. By default, only visible, - * displayable, accepted component can receive focus. - * <code>Canvas</code>es, <code>Panel</code>s, - * <code>Label</code>s, <code>ScrollPane</code>s, <code>Scrollbar</code>s, - * <code>Window</code>s and lightweight components are judged - * to be unacceptable by default. See the - * <code>DefaultFocusTraversalPolicy</code> for more details. - * - * @see DefaultFocusTraversalPolicy - */ - public final void focusNextComponent() - { - focusNextComponent (null); - } - - /** - * Moves the current focus to the previous component, based on the - * current focus traversal policy. By default, only visible, - * displayable, accepted component can receive focus. - * <code>Canvas</code>es, <code>Panel</code>s, - * <code>Label</code>s, <code>ScrollPane</code>s, <code>Scrollbar</code>s, - * <code>Window</code>s and lightweight components are judged - * to be unacceptable by default. See the - * <code>DefaultFocusTraversalPolicy</code> for more details. - * - * @see DefaultFocusTraversalPolicy - */ - public final void focusPreviousComponent() - { - focusPreviousComponent (null); - } - - /** - * Moves the current focus upwards by one focus cycle, - * so that the new focus owner is the focus cycle root - * of the current owner. The current focus cycle root then - * becomes the focus cycle root of the new focus owner. - * However, in the case of the focus cycle root of the - * current focus owner being a <code>Window</code>, the default - * component of this window becomes the focus owner and the - * focus cycle root is not changed. - */ - public final void upFocusCycle() - { - upFocusCycle (null); - } - - /** - * Moves the current focus downwards by one focus cycle, - * iff the current focus cycle root is a <code>Container</code>. - * Usually, the new focus owner is set to the default component - * of the container and the current focus cycle root is set - * to the current focus owner. Nothing occurs if the current - * focus cycle root is not a container. - */ - public final void downFocusCycle() - { - Component focusOwner = getGlobalFocusOwner (); - if (focusOwner instanceof Container - && ((Container) focusOwner).isFocusCycleRoot ()) - downFocusCycle ((Container) focusOwner); - } - - /** - * Retrieve an object from one of the global object {@link - * java.util.Map}s, if the object was set by the a thread in the - * current {@link java.lang.ThreadGroup}. Otherwise, return null. - * - * @param globalMap one of the global object Maps - * - * @return a global object set by the current ThreadGroup, or null - * - * @see getFocusOwner - * @see getPermanentFocusOwner - * @see getFocusedWindow - * @see getActiveWindow - * @see getCurrentFocusCycleRoot - */ - private Object getObject (Map globalMap) - { - ThreadGroup currentGroup = Thread.currentThread ().getThreadGroup (); - return globalMap.get (currentGroup); - } - - /** - * Retrieve an object from one of the global object {@link - * java.util.Map}s, regardless of whether or not the object was set - * by a thread in the current {@link java.lang.ThreadGroup}. - * - * @param globalMap one of the global object Maps - * - * @return a global object set by the current ThreadGroup, or null - * - * @throws SecurityException if this is not the keyboard focus - * manager associated with the current {@link java.lang.ThreadGroup} - * - * @see getGlobalFocusOwner - * @see getGlobalPermanentFocusOwner - * @see getGlobalFocusedWindow - * @see getGlobalActiveWindow - * @see getGlobalCurrentFocusCycleRoot - */ - private Object getGlobalObject (Map globalMap) - { - ThreadGroup currentGroup = Thread.currentThread ().getThreadGroup (); - KeyboardFocusManager managerForCallingThread - = (KeyboardFocusManager) currentKeyboardFocusManagers.get (currentGroup); - - if (this != managerForCallingThread) - throw new SecurityException ("Attempted to retrieve an object from a " - + "keyboard focus manager that isn't " - + "associated with the current thread group."); - - synchronized (globalMap) - { - Collection globalObjects = globalMap.values (); - Iterator i = globalObjects.iterator (); - Component globalObject; - - while (i.hasNext ()) - { - globalObject = (Component) i.next (); - if (globalObject != null) - return globalObject; - } - } - - // No Object was found. - return null; - } - - /** - * Set an object in one of the global object {@link java.util.Map}s, - * that will be returned by subsequent calls to getGlobalObject on - * the same {@link java.util.Map}. - * - * @param globalMap one of the global object Maps - * @param newObject the object to set - * @param property the property that will change - * - * @see setGlobalFocusOwner - * @see setGlobalPermanentFocusOwner - * @see setGlobalFocusedWindow - * @see setGlobalActiveWindow - * @see setGlobalCurrentFocusCycleRoot - */ - private void setGlobalObject (Map globalMap, - Object newObject, - String property) - { - synchronized (globalMap) - { - // Save old object. - Object oldObject = getGlobalObject (globalMap); - - // Nullify old object. - Collection threadGroups = globalMap.keySet (); - Iterator i = threadGroups.iterator (); - while (i.hasNext ()) - { - ThreadGroup oldThreadGroup = (ThreadGroup) i.next (); - if (globalMap.get (oldThreadGroup) != null) - { - globalMap.put (oldThreadGroup, null); - // There should only be one object set at a time, so - // we can short circuit. - break; - } - } - - ThreadGroup currentGroup = Thread.currentThread ().getThreadGroup (); - firePropertyChange (property, oldObject, newObject); - try - { - fireVetoableChange (property, oldObject, newObject); - // Set new object. - globalMap.put (currentGroup, newObject); - } - catch (PropertyVetoException e) - { - } - } - } -} diff --git a/libjava/java/awt/Label.java b/libjava/java/awt/Label.java deleted file mode 100644 index 8867fa12e35..00000000000 --- a/libjava/java/awt/Label.java +++ /dev/null @@ -1,314 +0,0 @@ -/* Label.java -- Java label widget - Copyright (C) 1999, 2000, 2002, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.awt.peer.LabelPeer; - -import javax.accessibility.Accessible; -import javax.accessibility.AccessibleContext; -import javax.accessibility.AccessibleRole; - -/** - * This component is used for displaying simple text strings that cannot - * be edited by the user. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Tom Tromey (tromey@cygnus.com) - * @author Andrew John Hughes (gnu_andrew@member.fsf.org) - */ -public class Label extends Component implements Accessible -{ - -/* - * Static Variables - */ - -/** - * Alignment constant aligning the text to the left of its window. - */ -public static final int LEFT = 0; - -/** - * Alignment constant aligning the text in the center of its window. - */ -public static final int CENTER = 1; - -/** - * Alignment constant aligning the text to the right of its window. - */ -public static final int RIGHT = 2; - -// Serialization version constant: -private static final long serialVersionUID = 3094126758329070636L; - -/*************************************************************************/ - -/* - * Instance Variables - */ - -/** - * @serial Indicates the alignment of the text within this label's window. - * This is one of the constants in this class. The default value is - * <code>LEFT</code>. - */ -private int alignment; - -/** - * @serial The text displayed in the label - */ -private String text; - -/*************************************************************************/ - -/* - * Constructors - */ - -/** - * Initializes a new instance of <code>Label</code> with no text. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. - */ -public -Label() -{ - this("", LEFT); -} - -/*************************************************************************/ - -/** - * Initializes a new instance of <code>Label</code> with the specified - * text that is aligned to the left. - * - * @param text The text of the label. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. - */ -public -Label(String text) -{ - this(text, LEFT); -} - -/*************************************************************************/ - -/** - * Initializes a new instance of <code>Label</code> with the specified - * text and alignment. - * - * @param text The text of the label. - * @param alignment The desired alignment for the text in this label, - * which must be one of <code>LEFT</code>, <code>CENTER</code>, or - * <code>RIGHT</code>. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. - */ -public -Label(String text, int alignment) -{ - setAlignment (alignment); - setText (text); - - if (GraphicsEnvironment.isHeadless()) - throw new HeadlessException (); -} - -/*************************************************************************/ - -/* - * Instance Variables - */ - -/** - * Returns the constant indicating the alignment of the text in this - * label. The value returned will be one of the alignment constants - * from this class. - * - * @return The alignment of the text in the label. - */ -public int -getAlignment() -{ - return(alignment); -} - -/*************************************************************************/ - -/** - * Sets the text alignment of this label to the specified value. - * - * @param alignment The desired alignment for the text in this label, - * which must be one of <code>LEFT</code>, <code>CENTER</code>, or - * <code>RIGHT</code>. - */ -public synchronized void -setAlignment(int alignment) -{ - if (alignment != CENTER && alignment != LEFT && alignment != RIGHT) - throw new IllegalArgumentException ("invalid alignment: " + alignment); - this.alignment = alignment; - if (peer != null) - { - LabelPeer lp = (LabelPeer) peer; - lp.setAlignment (alignment); - } -} - -/*************************************************************************/ - -/** - * Returns the text displayed in this label. - * - * @return The text for this label. - */ -public String -getText() -{ - return(text); -} - -/*************************************************************************/ - -/** - * Sets the text in this label to the specified value. - * - * @param text The new text for this label. - */ -public synchronized void -setText(String text) -{ - this.text = text; - - if (peer != null) - { - LabelPeer lp = (LabelPeer) peer; - lp.setText (text); - } -} - -/*************************************************************************/ - -/** - * Notifies this label that it has been added to a container, causing - * the peer to be created. This method is called internally by the AWT - * system. - */ -public void -addNotify() -{ - if (peer == null) - peer = getToolkit ().createLabel (this); - super.addNotify (); -} - -/*************************************************************************/ - -/** - * Returns a parameter string useful for debugging. - * - * @return A debugging string. - */ -protected String -paramString() -{ - return ("text=" + getText() + ",alignment=" + - getAlignment() + "," + super.paramString()); -} - -/** - * This class provides accessibility support for the label. - */ -protected class AccessibleAWTLabel - extends AccessibleAWTComponent -{ - /** - * For compatability with Sun's JDK 1.4.2 rev. 5 - */ - private static final long serialVersionUID = -3568967560160480438L; - - /** - * Constructor for the accessible label. - */ - public AccessibleAWTLabel() - { - } - - /** - * Returns the accessible name for the label. This is - * the text used in the label. - * - * @return a <code>String</code> containing the accessible - * name for this label. - */ - public String getAccessibleName() - { - return getText(); - } - - /** - * Returns the accessible role for the label. - * - * @return an instance of <code>AccessibleRole</code>, describing - * the role of the label. - */ - public AccessibleRole getAccessibleRole() - { - return AccessibleRole.LABEL; - } - -} - -/** - * Gets the AccessibleContext associated with this <code>Label</code>. - * The context is created, if necessary. - * - * @return the associated context - */ -public AccessibleContext getAccessibleContext() -{ - /* Create the context if this is the first request */ - if (accessibleContext == null) - accessibleContext = new AccessibleAWTLabel(); - return accessibleContext; -} - -} // class Label - diff --git a/libjava/java/awt/LayoutManager.java b/libjava/java/awt/LayoutManager.java deleted file mode 100644 index 62ff8087e76..00000000000 --- a/libjava/java/awt/LayoutManager.java +++ /dev/null @@ -1,92 +0,0 @@ -/* LayoutManager.java -- lay out elements in a Container - Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -/** - * This interface is for laying out containers in a particular sequence. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @see Container - * @since 1.0 - * @status updated to 1.4 - */ -public interface LayoutManager -{ - /** - * Adds the specified component to the layout group. - * - * @param name the name of the component to add - * @param component the component to add - */ - void addLayoutComponent(String name, Component component); - - /** - * Removes the specified component from the layout group. - * - * @param component the component to remove - */ - void removeLayoutComponent(Component component); - - /** - * Calculates the preferred size for this container, taking into account - * the components it contains. - * - * @param parent the parent container to lay out - * @return the preferred dimensions of this container - * @see #minimumLayoutSize(Container) - */ - Dimension preferredLayoutSize(Container parent); - - /** - * Calculates the minimum size for this container, taking into account - * the components it contains. - * - * @param parent the parent container to lay out - * @return the minimum dimensions of this container - * @see #preferredLayoutSize(Container) - */ - Dimension minimumLayoutSize(Container parent); - - /** - * Lays out the components in the given container. - * - * @param parent the container to lay out - */ - void layoutContainer(Container parent); -} // interface LayoutManager diff --git a/libjava/java/awt/LayoutManager2.java b/libjava/java/awt/LayoutManager2.java deleted file mode 100644 index 45fc5430f29..00000000000 --- a/libjava/java/awt/LayoutManager2.java +++ /dev/null @@ -1,100 +0,0 @@ -/* LayoutManager2.java -- enhanced layout manager - Copyright (C) 1999, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -/** - * Layout manager for laying out containers based on contraints. The - * constraints control how the layout will proceed. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @see LayoutManager - * @see Container - * @since 1.0 - * @status updated to 1.4 - */ -public interface LayoutManager2 extends LayoutManager -{ - /** - * Adds the specified component to the layout, with the specified - * constraints object. - * - * @param component the component to add - * @param constraints the constraints to satisfy - */ - void addLayoutComponent(Component component, Object constraints); - - /** - * Determines the maximum size of the specified target container. - * - * @param target the container to lay out - * @return the maximum size of the container - * @see Component#getMaximumSize() - */ - Dimension maximumLayoutSize(Container target); - - /** - * Returns the preferred X axis alignment for the specified target - * container. This value will range from 0 to 1 where 0 is alignment - * closest to the origin, 0.5 is centered, and 1 is aligned furthest - * from the origin. - * - * @param target the target container - * @return the x-axis alignment preference - */ - float getLayoutAlignmentX(Container target); - - /** - * Returns the preferred Y axis alignment for the specified target - * container. This value will range from 0 to 1 where 0 is alignment - * closest to the origin, 0.5 is centered, and 1 is aligned furthest - * from the origin. - * - * @param target the target container - * @return the y-axis alignment preference - */ - float getLayoutAlignmentY(Container target); - - /** - * Forces the layout manager to purge any cached information about the - * layout of the target container. This will force it to be recalculated. - * - * @param target the target container - */ - void invalidateLayout(Container target); -} // interface LayoutManager2 diff --git a/libjava/java/awt/List.java b/libjava/java/awt/List.java deleted file mode 100644 index 5fcc79bfcef..00000000000 --- a/libjava/java/awt/List.java +++ /dev/null @@ -1,1263 +0,0 @@ -/* List.java -- A listbox widget - Copyright (C) 1999, 2002, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.ItemEvent; -import java.awt.event.ItemListener; -import java.awt.peer.ListPeer; -import java.util.EventListener; -import java.util.Vector; - -import javax.accessibility.Accessible; -import javax.accessibility.AccessibleContext; -import javax.accessibility.AccessibleRole; -import javax.accessibility.AccessibleSelection; -import javax.accessibility.AccessibleState; -import javax.accessibility.AccessibleStateSet; - -/** - * Class that implements a listbox widget - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public class List extends Component - implements ItemSelectable, Accessible -{ - -/* - * Static Variables - */ - -// Serialization constant -private static final long serialVersionUID = -3304312411574666869L; - -/*************************************************************************/ - -/* - * Instance Variables - */ - -// FIXME: Need read/writeObject - -/** - * @serial The items in the list. - */ -private Vector items = new Vector(); - -/** - * @serial Indicates whether or not multiple items can be selected - * simultaneously. - */ -private boolean multipleMode; - -/** - * @serial The number of rows in the list. This is set on creation - * only and cannot be modified. - */ -private int rows; - -/** - * @serial An array of the item indices that are selected. - */ -private int[] selected; - -/** - * @serial An index value used by <code>makeVisible()</code> and - * <code>getVisibleIndex</code>. - */ -private int visibleIndex; - -// The list of ItemListeners for this object. -private ItemListener item_listeners; - -// The list of ActionListeners for this object. -private ActionListener action_listeners; - - -/*************************************************************************/ - -/* - * Constructors - */ - -/** - * Initializes a new instance of <code>List</code> with no visible lines - * and multi-select disabled. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. - */ -public -List() -{ - this(4, false); -} - -/*************************************************************************/ - -/** - * Initializes a new instance of <code>List</code> with the specified - * number of visible lines and multi-select disabled. - * - * @param rows The number of visible rows in the list. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. - */ -public -List(int rows) -{ - this(rows, false); -} - -/*************************************************************************/ - -/** - * Initializes a new instance of <code>List</code> with the specified - * number of lines and the specified multi-select setting. - * - * @param rows The number of visible rows in the list. - * @param multipleMode <code>true</code> if multiple lines can be selected - * simultaneously, <code>false</code> otherwise. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. - */ -public -List(int rows, boolean multipleMode) -{ - this.rows = rows; - this.multipleMode = multipleMode; - - if (GraphicsEnvironment.isHeadless()) - throw new HeadlessException (); -} - -/*************************************************************************/ - -/* - * Instance Variables - */ - -/** - * Returns the number of items in this list. - * - * @return The number of items in this list. - */ -public int -getItemCount() -{ - return countItems (); -} - -/*************************************************************************/ - -/** - * Returns the number of items in this list. - * - * @return The number of items in this list. - * - * @deprecated This method is deprecated in favor of - * <code>getItemCount()</code> - */ -public int -countItems() -{ - return items.size (); -} - -/*************************************************************************/ - -/** - * Returns the complete list of items. - * - * @return The complete list of items in the list. - */ -public synchronized String[] -getItems() -{ - String[] l_items = new String[getItemCount()]; - - items.copyInto(l_items); - return(l_items); -} - -/*************************************************************************/ - -/** - * Returns the item at the specified index. - * - * @param index The index of the item to retrieve. - * - * @exception IndexOutOfBoundsException If the index value is not valid. - */ -public String -getItem(int index) -{ - return((String)items.elementAt(index)); -} - -/*************************************************************************/ - -/** - * Returns the number of visible rows in the list. - * - * @return The number of visible rows in the list. - */ -public int -getRows() -{ - return(rows); -} - -/*************************************************************************/ - -/** - * Tests whether or not multi-select mode is enabled. - * - * @return <code>true</code> if multi-select mode is enabled, - * <code>false</code> otherwise. - */ -public boolean -isMultipleMode() -{ - return allowsMultipleSelections (); -} - -/*************************************************************************/ - -/** - * Tests whether or not multi-select mode is enabled. - * - * @return <code>true</code> if multi-select mode is enabled, - * <code>false</code> otherwise. - * - * @deprecated This method is deprecated in favor of - * <code>isMultipleMode()</code>. - */ -public boolean -allowsMultipleSelections() -{ - return multipleMode; -} - -/*************************************************************************/ - -/** - * This method enables or disables multiple selection mode for this - * list. - * - * @param multipleMode <code>true</code> to enable multiple mode, - * <code>false</code> otherwise. - */ -public void -setMultipleMode(boolean multipleMode) -{ - setMultipleSelections (multipleMode); -} - -/*************************************************************************/ - -/** - * This method enables or disables multiple selection mode for this - * list. - * - * @param multipleMode <code>true</code> to enable multiple mode, - * <code>false</code> otherwise. - * - * @deprecated - */ -public void -setMultipleSelections(boolean multipleMode) -{ - this.multipleMode = multipleMode; - - ListPeer peer = (ListPeer) getPeer (); - if (peer != null) - peer.setMultipleMode (multipleMode); -} - -/*************************************************************************/ - -/** - * Returns the minimum size of this component. - * - * @return The minimum size of this component. - */ -public Dimension -getMinimumSize() -{ - return getMinimumSize (getRows ()); -} - -/*************************************************************************/ - -/** - * Returns the minimum size of this component. - * - * @return The minimum size of this component. - * - * @deprecated This method is deprecated in favor of - * <code>getMinimumSize</code>. - */ -public Dimension -minimumSize() -{ - return minimumSize (getRows ()); -} - -/*************************************************************************/ - -/** - * Returns the minimum size of this component assuming it had the specified - * number of rows. - * - * @param rows The number of rows to size for. - * - * @return The minimum size of this component. - */ -public Dimension -getMinimumSize(int rows) -{ - return minimumSize (rows); -} - -/*************************************************************************/ - -/** - * Returns the minimum size of this component assuming it had the specified - * number of rows. - * - * @param rows The number of rows to size for. - * - * @return The minimum size of this component. - * - * @deprecated This method is deprecated in favor of - * <code>getMinimumSize(int)</code>> - */ -public Dimension -minimumSize(int rows) -{ - ListPeer peer = (ListPeer) getPeer (); - if (peer != null) - return peer.minimumSize (rows); - else - return new Dimension (0, 0); -} - -/*************************************************************************/ - -/** - * Returns the preferred size of this component. - * - * @return The preferred size of this component. - */ -public Dimension -getPreferredSize() -{ - return getPreferredSize (getRows ()); -} - -/*************************************************************************/ - -/** - * Returns the preferred size of this component. - * - * @return The preferred size of this component. - * - * @deprecated This method is deprecated in favor of - * <code>getPreferredSize</code>. - */ -public Dimension -preferredSize() -{ - return preferredSize (getRows ()); -} - -/*************************************************************************/ - -/** - * Returns the preferred size of this component assuming it had the specified - * number of rows. - * - * @param rows The number of rows to size for. - * - * @return The preferred size of this component. - */ -public Dimension -getPreferredSize(int rows) -{ - return preferredSize (rows); -} - -/*************************************************************************/ - -/** - * Returns the preferred size of this component assuming it had the specified - * number of rows. - * - * @param rows The number of rows to size for. - * - * @return The preferred size of this component. - * - * @deprecated This method is deprecated in favor of - * <code>getPreferredSize(int)</code>> - */ -public Dimension -preferredSize(int rows) -{ - ListPeer peer = (ListPeer) getPeer (); - if (peer != null) - return peer.preferredSize (rows); - else - return new Dimension (0, 0); -} - -/*************************************************************************/ - -/** - * This method adds the specified item to the end of the list. - * - * @param item The item to add to the list. - */ -public void -add(String item) -{ - add (item, -1); -} - -/*************************************************************************/ - -/** - * This method adds the specified item to the end of the list. - * - * @param item The item to add to the list. - * - * @deprecated Use add() instead. - */ -public void -addItem(String item) -{ - addItem (item, -1); -} - -/*************************************************************************/ - -/** - * Adds the specified item to the specified location in the list. - * If the desired index is -1 or greater than the number of rows - * in the list, then the item is added to the end. - * - * @param item The item to add to the list. - * @param index The location in the list to add the item, or -1 to add - * to the end. - */ -public void -add(String item, int index) -{ - addItem (item, index); -} - -/*************************************************************************/ - -/** - * Adds the specified item to the specified location in the list. - * If the desired index is -1 or greater than the number of rows - * in the list, then the item is added to the end. - * - * @param item The item to add to the list. - * @param index The location in the list to add the item, or -1 to add - * to the end. - * - * @deprecated Use add() instead. - */ -public void -addItem(String item, int index) -{ - if ((index == -1) || (index >= items.size ())) - items.addElement (item); - else - items.insertElementAt (item, index); - - ListPeer peer = (ListPeer) getPeer (); - if (peer != null) - peer.add (item, index); -} - -/*************************************************************************/ - -/** - * Deletes the item at the specified index. - * - * @param index The index of the item to delete. - * - * @exception IllegalArgumentException If the index is not valid - * - * @deprecated - */ -public void -delItem(int index) throws IllegalArgumentException -{ - items.removeElementAt (index); - - ListPeer peer = (ListPeer) getPeer (); - if (peer != null) - peer.delItems (index, index); -} - -/*************************************************************************/ - -/** - * Deletes the item at the specified index. - * - * @param index The index of the item to delete. - * - * @exception IllegalArgumentException If the index is not valid - */ -public void -remove(int index) throws IllegalArgumentException -{ - delItem (index); -} - -/*************************************************************************/ - -/** - * Deletes all items in the specified index range. - * - * @param start The beginning index of the range to delete. - * @param end The ending index of the range to delete. - * - * @exception IllegalArgumentException If the indexes are not valid - * - * @deprecated This method is deprecated for some unknown reason. - */ -public synchronized void -delItems(int start, int end) throws IllegalArgumentException -{ - if ((start < 0) || (start >= items.size())) - throw new IllegalArgumentException("Bad list start index value: " + start); - - if ((start < 0) || (start >= items.size())) - throw new IllegalArgumentException("Bad list start index value: " + start); - - if (start > end) - throw new IllegalArgumentException("Start is greater than end!"); - - // We must run the loop in reverse direction. - for (int i = end; i >= start; --i) - items.removeElementAt (i); - if (peer != null) - { - ListPeer l = (ListPeer) peer; - l.delItems (start, end); - } -} - -/*************************************************************************/ - -/** - * Deletes the first occurrence of the specified item from the list. - * - * @param item The item to delete. - * - * @exception IllegalArgumentException If the specified item does not exist. - */ -public synchronized void -remove(String item) throws IllegalArgumentException -{ - int index = items.indexOf(item); - if (index == -1) - throw new IllegalArgumentException("List element to delete not found"); - - remove(index); -} - -/*************************************************************************/ - -/** - * Deletes all of the items from the list. - */ -public synchronized void -removeAll() -{ - clear (); -} - -/*************************************************************************/ - -/** - * Deletes all of the items from the list. - * - * @deprecated This method is deprecated in favor of <code>removeAll()</code>. - */ -public void -clear() -{ - items.clear(); - - ListPeer peer = (ListPeer) getPeer (); - if (peer != null) - peer.removeAll (); -} - -/*************************************************************************/ - -/** - * Replaces the item at the specified index with the specified item. - * - * @param item The new item value. - * @param index The index of the item to replace. - * - * @exception IllegalArgumentException If the index is not valid. - */ -public synchronized void -replaceItem(String item, int index) throws IllegalArgumentException -{ - if ((index < 0) || (index >= items.size())) - throw new IllegalArgumentException("Bad list index: " + index); - - items.insertElementAt(item, index + 1); - items.removeElementAt (index); - - if (peer != null) - { - ListPeer l = (ListPeer) peer; - - /* We add first and then remove so that the selected - item remains the same */ - l.add (item, index + 1); - l.delItems (index, index); - } -} - -/*************************************************************************/ - -/** - * Returns the index of the currently selected item. -1 will be returned - * if there are no selected rows or if there are multiple selected rows. - * - * @return The index of the selected row. - */ -public synchronized int -getSelectedIndex() -{ - if (peer != null) - { - ListPeer l = (ListPeer) peer; - selected = l.getSelectedIndexes (); - } - - if (selected == null || selected.length != 1) - return -1; - return selected[0]; -} - -/*************************************************************************/ - -/** - * Returns an array containing the indexes of the rows that are - * currently selected. - * - * @return A list of indexes of selected rows. - */ -public synchronized int[] -getSelectedIndexes() -{ - if (peer != null) - { - ListPeer l = (ListPeer) peer; - selected = l.getSelectedIndexes (); - } - return selected; -} - -/*************************************************************************/ - -/** - * Returns the item that is currently selected, or <code>null</code> if there - * is no item selected. FIXME: What happens if multiple items selected? - * - * @return The selected item, or <code>null</code> if there is no - * selected item. - */ -public synchronized String -getSelectedItem() -{ - int index = getSelectedIndex(); - if (index == -1) - return(null); - - return((String)items.elementAt(index)); -} - -/*************************************************************************/ - -/** - * Returns the list of items that are currently selected in this list. - * - * @return The list of currently selected items. - */ -public synchronized String[] -getSelectedItems() -{ - int[] indexes = getSelectedIndexes(); - if (indexes == null) - return(new String[0]); - - String[] retvals = new String[indexes.length]; - if (retvals.length > 0) - for (int i = 0 ; i < retvals.length; i++) - retvals[i] = (String)items.elementAt(indexes[i]); - - return(retvals); -} - -/*************************************************************************/ - -/** - * Returns the list of items that are currently selected in this list as - * an array of type <code>Object[]</code> instead of <code>String[]</code>. - * - * @return The list of currently selected items. - */ -public synchronized Object[] -getSelectedObjects() -{ - int[] indexes = getSelectedIndexes(); - if (indexes == null) - return(new Object[0]); - - Object[] retvals = new Object[indexes.length]; - if (retvals.length > 0) - for (int i = 0 ; i < retvals.length; i++) - retvals[i] = items.elementAt(indexes[i]); - - return(retvals); -} - -/*************************************************************************/ - -/** - * Tests whether or not the specified index is selected. - * - * @param index The index to test. - * - * @return <code>true</code> if the index is selected, <code>false</code> - * otherwise. - */ -public boolean -isIndexSelected(int index) -{ - return isSelected (index); -} - -/*************************************************************************/ - -/** - * Tests whether or not the specified index is selected. - * - * @param index The index to test. - * - * @return <code>true</code> if the index is selected, <code>false</code> - * otherwise. - * - * @deprecated This method is deprecated in favor of - * <code>isIndexSelected(int)</code>. - */ -public boolean -isSelected(int index) -{ - int[] indexes = getSelectedIndexes (); - - for (int i = 0; i < indexes.length; i++) - if (indexes[i] == index) - return true; - - return false; -} - -/*************************************************************************/ - -/** - * This method ensures that the item at the specified index is visible. - * - * @exception IllegalArgumentException If the specified index is out of - * range. - */ -public synchronized void -makeVisible(int index) throws IllegalArgumentException -{ - if ((index < 0) || (index >= items.size())) - throw new IllegalArgumentException("Bad list index: " + index); - - visibleIndex = index; - if (peer != null) - { - ListPeer l = (ListPeer) peer; - l.makeVisible (index); - } -} - -/*************************************************************************/ - -/** - * Returns the index of the last item that was made visible via the - * <code>makeVisible()</code> method. - * - * @return The index of the last item made visible via the - * <code>makeVisible()</code> method. - */ -public int -getVisibleIndex() -{ - return(visibleIndex); -} - -/*************************************************************************/ - -/** - * Makes the item at the specified index selected. - * - * @param index The index of the item to select. - */ -public synchronized void -select(int index) -{ - ListPeer lp = (ListPeer)getPeer(); - if (lp != null) - lp.select(index); -} - -/*************************************************************************/ - -/** - * Makes the item at the specified index not selected. - * - * @param index The index of the item to unselect. - */ -public synchronized void -deselect(int index) -{ - ListPeer lp = (ListPeer)getPeer(); - if (lp != null) - lp.deselect(index); -} - -/*************************************************************************/ - -/** - * Notifies this object to create its native peer. - */ -public void -addNotify() -{ - if (peer == null) - peer = getToolkit ().createList (this); - super.addNotify (); -} - -/*************************************************************************/ - -/** - * Notifies this object to destroy its native peer. - */ -public void -removeNotify() -{ - super.removeNotify(); -} - -/*************************************************************************/ - -/** - * Adds the specified <code>ActionListener</code> to the list of - * registered listeners for this object. - * - * @param listener The listener to add. - */ -public synchronized void -addActionListener(ActionListener listener) -{ - action_listeners = AWTEventMulticaster.add(action_listeners, listener); -} - -/*************************************************************************/ - -/** - * Removes the specified <code>ActionListener</code> from the list of - * registers listeners for this object. - * - * @param listener The listener to remove. - */ -public synchronized void -removeActionListener(ActionListener listener) -{ - action_listeners = AWTEventMulticaster.remove(action_listeners, listener); -} - -/*************************************************************************/ - -/** - * Adds the specified <code>ItemListener</code> to the list of - * registered listeners for this object. - * - * @param listener The listener to add. - */ -public synchronized void -addItemListener(ItemListener listener) -{ - item_listeners = AWTEventMulticaster.add(item_listeners, listener); -} - -/*************************************************************************/ - -/** - * Removes the specified <code>ItemListener</code> from the list of - * registers listeners for this object. - * - * @param listener The listener to remove. - */ -public synchronized void -removeItemListener(ItemListener listener) -{ - item_listeners = AWTEventMulticaster.remove(item_listeners, listener); -} - -/*************************************************************************/ - -/** - * Processes the specified event for this object. If the event is an - * instance of <code>ActionEvent</code> then the - * <code>processActionEvent()</code> method is called. Similarly, if the - * even is an instance of <code>ItemEvent</code> then the - * <code>processItemEvent()</code> method is called. Otherwise the - * superclass method is called to process this event. - * - * @param event The event to process. - */ -protected void -processEvent(AWTEvent event) -{ - if (event instanceof ActionEvent) - processActionEvent((ActionEvent)event); - else if (event instanceof ItemEvent) - processItemEvent((ItemEvent)event); - else - super.processEvent(event); -} - -/*************************************************************************/ - -/** - * This method processes the specified event by dispatching it to any - * registered listeners. Note that this method will only get called if - * action events are enabled. This will happen automatically if any - * listeners are added, or it can be done "manually" by calling - * the <code>enableEvents()</code> method. - * - * @param event The event to process. - */ -protected void -processActionEvent(ActionEvent event) -{ - if (action_listeners != null) - action_listeners.actionPerformed(event); -} - -/*************************************************************************/ - -/** - * This method processes the specified event by dispatching it to any - * registered listeners. Note that this method will only get called if - * item events are enabled. This will happen automatically if any - * listeners are added, or it can be done "manually" by calling - * the <code>enableEvents()</code> method. - * - * @param event The event to process. - */ -protected void -processItemEvent(ItemEvent event) -{ - if (item_listeners != null) - item_listeners.itemStateChanged(event); -} - -void -dispatchEventImpl(AWTEvent e) -{ - if (e.id <= ItemEvent.ITEM_LAST - && e.id >= ItemEvent.ITEM_FIRST - && (item_listeners != null - || (eventMask & AWTEvent.ITEM_EVENT_MASK) != 0)) - processEvent(e); - else if (e.id <= ActionEvent.ACTION_LAST - && e.id >= ActionEvent.ACTION_FIRST - && (action_listeners != null - || (eventMask & AWTEvent.ACTION_EVENT_MASK) != 0)) - processEvent(e); - else - super.dispatchEventImpl(e); -} - -/*************************************************************************/ - -/** - * Returns a debugging string for this object. - * - * @return A debugging string for this object. - */ -protected String -paramString() -{ - return "multiple=" + multipleMode + ",rows=" + rows + super.paramString(); -} - - /** - * Returns an array of all the objects currently registered as FooListeners - * upon this <code>List</code>. FooListeners are registered using the - * addFooListener method. - * - * @exception ClassCastException If listenerType doesn't specify a class or - * interface that implements java.util.EventListener. - */ - public EventListener[] getListeners (Class listenerType) - { - if (listenerType == ActionListener.class) - return AWTEventMulticaster.getListeners (action_listeners, listenerType); - - if (listenerType == ItemListener.class) - return AWTEventMulticaster.getListeners (item_listeners, listenerType); - - return super.getListeners (listenerType); - } - - /** - * Returns all action listeners registered to this object. - */ - public ActionListener[] getActionListeners () - { - return (ActionListener[]) getListeners (ActionListener.class); - } - - /** - * Returns all action listeners registered to this object. - */ - public ItemListener[] getItemListeners () - { - return (ItemListener[]) getListeners (ItemListener.class); - } - - // Accessibility internal class - protected class AccessibleAWTList extends AccessibleAWTComponent - implements AccessibleSelection, ItemListener, ActionListener - { - protected class AccessibleAWTListChild extends AccessibleAWTComponent - implements Accessible - { - private int index; - private List parent; - - public AccessibleAWTListChild(List parent, int indexInParent) - { - this.parent = parent; - index = indexInParent; - if (parent == null) - index = -1; - } - - /* (non-Javadoc) - * @see javax.accessibility.Accessible#getAccessibleContext() - */ - public AccessibleContext getAccessibleContext() - { - return this; - } - - public AccessibleRole getAccessibleRole() - { - return AccessibleRole.LIST_ITEM; - } - - public AccessibleStateSet getAccessibleStateSet() - { - AccessibleStateSet states = super.getAccessibleStateSet(); - if (parent.isIndexSelected(index)) - states.add(AccessibleState.SELECTED); - return states; - } - - public int getAccessibleIndexInParent() - { - return index; - } - - } - - public AccessibleAWTList() - { - addItemListener(this); - addActionListener(this); - } - - public AccessibleRole getAccessibleRole() - { - return AccessibleRole.LIST; - } - - public AccessibleStateSet getAccessibleStateSet() - { - AccessibleStateSet states = super.getAccessibleStateSet(); - states.add(AccessibleState.SELECTABLE); - if (isMultipleMode()) - states.add(AccessibleState.MULTISELECTABLE); - return states; - } - - public int getAccessibleChildrenCount() - { - return getItemCount(); - } - - public Accessible getAccessibleChild(int i) - { - if (i >= getItemCount()) - return null; - return new AccessibleAWTListChild(List.this, i); - } - - /* (non-Javadoc) - * @see javax.accessibility.AccessibleSelection#getAccessibleSelectionCount() - */ - public int getAccessibleSelectionCount() - { - return getSelectedIndexes().length; - } - - /* (non-Javadoc) - * @see javax.accessibility.AccessibleSelection#getAccessibleSelection() - */ - public AccessibleSelection getAccessibleSelection() - { - return this; - } - - /* (non-Javadoc) - * @see javax.accessibility.AccessibleSelection#getAccessibleSelection(int) - */ - public Accessible getAccessibleSelection(int i) - { - int[] items = getSelectedIndexes(); - if (i >= items.length) - return null; - return new AccessibleAWTListChild(List.this, items[i]); - } - - /* (non-Javadoc) - * @see javax.accessibility.AccessibleSelection#isAccessibleChildSelected(int) - */ - public boolean isAccessibleChildSelected(int i) - { - return isIndexSelected(i); - } - - /* (non-Javadoc) - * @see javax.accessibility.AccessibleSelection#addAccessibleSelection(int) - */ - public void addAccessibleSelection(int i) - { - select(i); - } - - /* (non-Javadoc) - * @see javax.accessibility.AccessibleSelection#removeAccessibleSelection(int) - */ - public void removeAccessibleSelection(int i) - { - deselect(i); - } - - /* (non-Javadoc) - * @see javax.accessibility.AccessibleSelection#clearAccessibleSelection() - */ - public void clearAccessibleSelection() - { - for (int i = 0; i < getItemCount(); i++) - deselect(i); - } - - /* (non-Javadoc) - * @see javax.accessibility.AccessibleSelection#selectAllAccessibleSelection() - */ - public void selectAllAccessibleSelection() - { - if (isMultipleMode()) - for (int i = 0; i < getItemCount(); i++) - select(i); - } - - /* (non-Javadoc) - * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent) - */ - public void itemStateChanged(ItemEvent event) - { - } - - /* (non-Javadoc) - * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) - */ - public void actionPerformed(ActionEvent event) - { - } - - } - - /** - * Gets the AccessibleContext associated with this <code>List</code>. - * The context is created, if necessary. - * - * @return the associated context - */ - public AccessibleContext getAccessibleContext() - { - /* Create the context if this is the first request */ - if (accessibleContext == null) - accessibleContext = new AccessibleAWTList(); - return accessibleContext; - } -} // class List diff --git a/libjava/java/awt/MediaTracker.java b/libjava/java/awt/MediaTracker.java deleted file mode 100644 index 45ed7b48b42..00000000000 --- a/libjava/java/awt/MediaTracker.java +++ /dev/null @@ -1,663 +0,0 @@ -/* MediaTracker.java -- Class used for keeping track of images - Copyright (C) 1999, 2002, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.awt.image.ImageObserver; -import java.util.ArrayList; - -/** - * This class is used for keeping track of the status of various media - * objects. - * - * Media objects are tracked by assigning them an ID. It is possible - * to assign the same ID to mutliple objects, effectivly grouping them - * together. In this case the status flags ({@link #statusID}) and error flag - * (@link #isErrorID} and {@link #getErrorId}) are ORed together. This - * means that you cannot say exactly which media object has which status, - * at most you can say that there <em>are</em> certain media objects with - * some certain status. - * - * At the moment only images are supported by this class. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Bryce McKinlay - */ -public class MediaTracker implements java.io.Serializable -{ - /** Indicates that the media is still loading. */ - public static final int LOADING = 1 << 0; - - /** Indicates that the loading operation has been aborted. */ - public static final int ABORTED = 1 << 1; - - /** Indicates that an error has occured during loading of the media. */ - public static final int ERRORED = 1 << 2; - - /** Indicates that the media has been successfully and completely loaded. */ - public static final int COMPLETE = 1 << 3; - - /** The component on which the media is eventually been drawn. */ - Component target; - - /** The head of the linked list of tracked media objects. */ - MediaEntry head; - - /** Our serialVersionUID for serialization. */ - static final long serialVersionUID = -483174189758638095L; - - /** - * This represents a media object that is tracked by a MediaTracker. - * It also implements a simple linked list. - */ - // FIXME: The serialized form documentation says MediaEntry is a - // serializable field, but the serialized form of MediaEntry itself - // doesn't appear to be documented. - class MediaEntry implements ImageObserver - { - /** The ID of the media object. */ - int id; - - /** The media object. (only images are supported ATM). */ - Image image; - - /** The link to the next entry in the list. */ - MediaEntry next; - - /** The tracking status. */ - int status; - - /** The width of the image. */ - int width; - - /** The height of the image. */ - int height; - - /** - * Receives notification from an {@link java.awt.image.ImageProducer} - * that more data of the image is available. - * - * @param img the image that is updated - * @param flags flags from the ImageProducer that indicate the status - * of the loading process - * @param x the X coordinate of the upper left corner of the image - * @param y the Y coordinate of the upper left corner of the image - * @param width the width of the image - * @param height the height of the image - * - * @return <code>true</code> if more data is needed, <code>false</code> - * otherwise - * - * @see {@link java.awt.image.ImageObserver} - */ - public boolean imageUpdate(Image img, int flags, int x, int y, - int width, int height) - { - if ((flags & ABORT) != 0) - status = ABORTED; - else if ((flags & ERROR) != 0) - status = ERRORED; - else if ((flags & ALLBITS) != 0) - status = COMPLETE; - else - status = 0; - - synchronized (MediaTracker.this) - { - MediaTracker.this.notifyAll(); - } - - // If status is not COMPLETE then we need more updates. - return ((status & (COMPLETE | ERRORED | ABORTED)) == 0); - } - } - - /** - * Constructs a new MediaTracker for the component <code>c</code>. The - * component should be the component that uses the media (i.e. draws it). - * - * @param c the Component that wants to use the media - */ - public MediaTracker(Component c) - { - target = c; - } - - /** - * Adds an image to the tracker with the specified <code>ID</code>. - * - * @param image the image to be added - * @param id the ID of the tracker list to which the image is added - */ - public void addImage(Image image, int id) - { - MediaEntry e = new MediaEntry(); - e.id = id; - e.image = image; - synchronized(this) - { - e.next = head; - head = e; - } - } - - /** - * Adds an image to the tracker with the specified <code>ID</code>. - * The image is expected to be rendered with the specified width and - * height. - * - * @param image the image to be added - * @param id the ID of the tracker list to which the image is added - * @param width the width of the image - * @param height the height of the image - */ - public void addImage(Image image, int id, int width, int height) - { - MediaEntry e = new MediaEntry(); - e.id = id; - e.image = image; - e.width = width; - e.height = height; - synchronized(this) - { - e.next = head; - head = e; - } - } - - /** - * Checks if all media objects have finished loading, i.e. are - * {@link #COMPLETE}, {@link #ABORTED} or {@link #ERRORED}. - * - * If the media objects are not already loading, a call to this - * method does <em>not</em> start loading. This is equivalent to - * a call to <code>checkAll(false)</code>. - * - * @return if all media objects have finished loading either by beeing - * complete, have been aborted or errored. - */ - public boolean checkAll() - { - return checkAll(false); - } - - /** - * Checks if all media objects have finished loading, i.e. are - * {@link #COMPLETE}, {@link #ABORTED} or {@link #ERRORED}. - * - * If the media objects are not already loading, and <code>load</code> - * is <code>true</code> then a call to this - * method starts loading the media objects. - * - * @param load if <code>true</code> this method starts loading objects - * that are not already loading - * - * @return if all media objects have finished loading either by beeing - * complete, have been aborted or errored. - */ - public boolean checkAll(boolean load) - { - MediaEntry e = head; - boolean result = true; - - while (e != null) - { - if ((e.status & (COMPLETE | ERRORED | ABORTED)) == 0) - { - if (load && ((e.status & LOADING) == 0)) - { - e.status = LOADING; - result = false; - boolean complete = target.prepareImage(e.image, e); - if (complete) - { - e.status = COMPLETE; - result = true; - } - } - else - result = false; - } - e = e.next; - } - return result; - } - - /** - * Checks if any of the registered media objects has encountered an error - * during loading. - * - * @return <code>true</code> if at least one media object has encountered - * an error during loading, <code>false</code> otherwise - * - */ - public boolean isErrorAny() - { - MediaEntry e = head; - while (e != null) - { - if ((e.status & ERRORED) != 0) - return true; - e = e.next; - } - return false; - } - - /** - * Returns all media objects that have encountered errors during loading. - * - * @return an array of all media objects that have encountered errors - * or <code>null</code> if there were no errors at all - */ - public Object[] getErrorsAny() - { - MediaEntry e = head; - ArrayList result = null; - while (e != null) - { - if ((e.status & ERRORED) != 0) - { - if (result == null) - result = new ArrayList(); - result.add(e.image); - } - e = e.next; - } - if (result == null) - return null; - else - return result.toArray(); - } - - /** - * Waits for all media objects to finish loading, either by completing - * successfully or by aborting or encountering an error. - * - * @throws InterruptedException if another thread interrupted the - * current thread while waiting - */ - public void waitForAll() throws InterruptedException - { - synchronized (this) - { - while (checkAll(true) == false) - wait(); - } - } - - /** - * Waits for all media objects to finish loading, either by completing - * successfully or by aborting or encountering an error. - * - * This method waits at most <code>ms</code> milliseconds. If the - * media objects have not completed loading within this timeframe, this - * method returns <code>false</code>, otherwise <code>true</code>. - * - * @param ms timeframe in milliseconds to wait for the media objects to - * finish - * - * @return <code>true</code> if all media objects have successfully loaded - * within the timeframe, <code>false</code> otherwise - * - * @throws InterruptedException if another thread interrupted the - * current thread while waiting - */ - public boolean waitForAll(long ms) throws InterruptedException - { - long start = System.currentTimeMillis(); - boolean result = checkAll(true); - synchronized (this) - { - while (result == false) - { - wait(ms); - result = checkAll(true); - if ((System.currentTimeMillis() - start) > ms) - break; - } - } - - return result; - } - - /** - * Returns the status flags of all registered media objects ORed together. - * If <code>load</code> is <code>true</code> then media objects that - * are not already loading will be started to load. - * - * @param load if set to <code>true</code> then media objects that are - * not already loading are started - * - * @return the status flags of all tracked media objects ORed together - */ - public int statusAll(boolean load) - { - int result = 0; - MediaEntry e = head; - while (e != null) - { - if (load && e.status == 0) - { - boolean complete = target.prepareImage(e.image, e); - if (complete) - e.status = COMPLETE; - else - e.status = LOADING; - } - result |= e.status; - e = e.next; - } - return result; - } - - /** - * Checks if the media objects with <code>ID</code> have completed loading. - * - * @param id the ID of the media objects to check - * - * @return <code>true</code> if all media objects with <code>ID</code> - * have successfully finished - */ - public boolean checkID(int id) - { - return checkID(id, false); - } - - /** - * Checks if the media objects with <code>ID</code> have completed loading. - * If <code>load</code> is <code>true</code> then media objects that - * are not already loading will be started to load. - * - * @param id the ID of the media objects to check - * @param load if set to <code>true</code> then media objects that are - * not already loading are started - * - * @return <code>true</code> if all media objects with <code>ID</code> - * have successfully finished - */ - public boolean checkID(int id, boolean load) - { - MediaEntry e = head; - boolean result = true; - - while (e != null) - { - if (e.id == id && ((e.status & (COMPLETE | ABORTED | ERRORED)) == 0)) - { - if (load && ((e.status & LOADING) == 0)) - { - e.status = LOADING; - result = false; - boolean complete = target.prepareImage(e.image, e); - if (complete) - { - e.status = COMPLETE; - result = true; - } - } - else - result = false; - } - e = e.next; - } - return result; - } - - /** - * Returns <code>true</code> if any of the media objects with <code>ID</code> - * have encountered errors during loading, false otherwise. - * - * @param id the ID of the media objects to check - * - * @return <code>true</code> if any of the media objects with <code>ID</code> - * have encountered errors during loading, false otherwise - */ - public boolean isErrorID(int id) - { - MediaEntry e = head; - while (e != null) - { - if (e.id == id && ((e.status & ERRORED) != 0)) - return true; - e = e.next; - } - return false; - } - - /** - * Returns all media objects with the specified ID that have encountered - * an error. - * - * @param id the ID of the media objects to check - * - * @return an array of all media objects with the specified ID that - * have encountered an error - */ - public Object[] getErrorsID(int id) - { - MediaEntry e = head; - ArrayList result = null; - while (e != null) - { - if (e.id == id && ((e.status & ERRORED) != 0)) - { - if (result == null) - result = new ArrayList(); - result.add(e.image); - } - e = e.next; - } - if (result == null) - return null; - else - return result.toArray(); - } - - /** - * Waits for all media objects with the specified ID to finish loading, - * either by completing successfully or by aborting or encountering an error. - * - * @param id the ID of the media objects to wait for - * - * @throws InterruptedException if another thread interrupted the - * current thread while waiting - */ - public void waitForID(int id) throws InterruptedException - { - MediaEntry e = head; - synchronized (this) - { - while (checkID (id, true) == false) - wait(); - } - } - - /** - * Waits for all media objects with the specified ID to finish loading, - * either by completing successfully or by aborting or encountering an error. - * - * This method waits at most <code>ms</code> milliseconds. If the - * media objects have not completed loading within this timeframe, this - * method returns <code>false</code>, otherwise <code>true</code>. - * - * @param id the ID of the media objects to wait for - * @param ms timeframe in milliseconds to wait for the media objects to - * finish - * - * @return <code>true</code> if all media objects have successfully loaded - * within the timeframe, <code>false</code> otherwise - * - * @throws InterruptedException if another thread interrupted the - * current thread while waiting - */ - public boolean waitForID(int id, long ms) throws InterruptedException - { - MediaEntry e = head; - long start = System.currentTimeMillis(); - boolean result = checkID(id, true); - - synchronized (this) - { - while (result == false) - { - wait(ms); - result = checkID(id, true); - if ((System.currentTimeMillis() - start) > ms) - break; - } - } - - return result; - } - - /** - * Returns the status flags of the media objects with the specified ID - * ORed together. - * - * If <code>load</code> is <code>true</code> then media objects that - * are not already loading will be started to load. - * - * @param load if set to <code>true</code> then media objects that are - * not already loading are started - * - * @return the status flags of all tracked media objects ORed together - */ - public int statusID(int id, boolean load) - { - int result = 0; - MediaEntry e = head; - while (e != null) - { - if (e.id == id) - { - if (load && e.status == 0) - { - boolean complete = target.prepareImage(e.image, e); - if (complete) - e.status = COMPLETE; - else - e.status = LOADING; - } - result |= e.status; - } - e = e.next; - } - return result; - } - - /** - * Removes an image from this MediaTracker. - * - * @param image the image to be removed - */ - public void removeImage(Image image) - { - synchronized (this) - { - MediaEntry e = head; - MediaEntry prev = null; - while (e != null) - { - if (e.image == image) - { - if (prev == null) - head = e.next; - else - prev.next = e.next; - } - prev = e; - e = e.next; - } - } - } - - /** - * Removes an image with the specified ID from this MediaTracker. - * - * @param image the image to be removed - */ - public void removeImage(Image image, int id) - { - synchronized (this) - { - MediaEntry e = head; - MediaEntry prev = null; - while (e != null) - { - if (e.id == id && e.image == image) - { - if (prev == null) - head = e.next; - else - prev.next = e.next; - } - else - prev = e; - e = e.next; - } - } - } - - /** - * Removes an image with the specified ID and scale from this MediaTracker. - * - * @param image the image to be removed - */ - public void removeImage(Image image, int id, int width, int height) - { - synchronized (this) - { - MediaEntry e = head; - MediaEntry prev = null; - while (e != null) - { - if (e.id == id && e.image == image - && e.width == width && e.height == height) - { - if (prev == null) - head = e.next; - else - prev.next = e.next; - } - else - prev = e; - e = e.next; - } - } - } -} diff --git a/libjava/java/awt/Menu.java b/libjava/java/awt/Menu.java deleted file mode 100644 index 56ceccfc542..00000000000 --- a/libjava/java/awt/Menu.java +++ /dev/null @@ -1,468 +0,0 @@ -/* Menu.java -- A Java AWT Menu - Copyright (C) 1999, 2002, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.awt.peer.MenuPeer; -import java.io.Serializable; -import java.util.Enumeration; -import java.util.Vector; - -import javax.accessibility.AccessibleContext; -import javax.accessibility.AccessibleRole; - -/** - * This class represents a pull down or tear off menu in Java's AWT. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public class Menu extends MenuItem implements MenuContainer, Serializable -{ - -/* - * Static Variables - */ - -// Serialization Constant -private static final long serialVersionUID = -8809584163345499784L; - -/*************************************************************************/ - -/* - * Instance Variables - */ - -/** - * @serial The actual items in the menu - */ -private Vector items = new Vector(); - -/** - * @serial Flag indicating whether or not this menu is a tear off - */ -private boolean tearOff; - -/** - * @serial Indicates whether or not this is a help menu. - */ -private boolean isHelpMenu; - - /* - * @serial Unused in this implementation, but present in Sun's - * serialization spec. Value obtained via reflection. - */ - private int menuSerializedDataVersion = 1; - -static final transient String separatorLabel = "-"; - -/*************************************************************************/ - -/* - * Constructors - */ - -/** - * Initializes a new instance of <code>Menu</code> with no label and that - * is not a tearoff; - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. - */ -public -Menu() -{ -} - -/*************************************************************************/ - -/** - * Initializes a new instance of <code>Menu</code> that is not a tearoff and - * that has the specified label. - * - * @param label The menu label. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. - */ -public -Menu(String label) -{ - this(label, false); -} - -/*************************************************************************/ - -/** - * Initializes a new instance of <code>Menu</code> with the specified - * label and tearoff status. - * - * @param label The label for this menu - * @param isTearOff <code>true</code> if this menu is a tear off menu, - * <code>false</code> otherwise. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. - */ -public -Menu(String label, boolean isTearOff) -{ - super(label); - - tearOff = isTearOff; - - if (label.equals("Help")) - isHelpMenu = true; - - if (GraphicsEnvironment.isHeadless()) - throw new HeadlessException (); -} - -/*************************************************************************/ - -/* - * Instance Methods - */ - -/** - * Tests whether or not this menu is a tearoff. - * - * @return <code>true</code> if this menu is a tearoff, <code>false</code> - * otherwise. - */ -public boolean -isTearOff() -{ - return(tearOff); -} - -/*************************************************************************/ - -/** - * Returns the number of items in this menu. - * - * @return The number of items in this menu. - */ -public int -getItemCount() -{ - return countItems (); -} - -/** - * Returns the number of items in this menu. - * - * @return The number of items in this menu. - * - * @deprecated As of JDK 1.1, replaced by getItemCount(). - */ -public int countItems () -{ - return items.size (); -} - -/*************************************************************************/ - -/** - * Returns the item at the specified index. - * - * @return The item at the specified index. - * - * @exception ArrayIndexOutOfBoundsException If the index value is not valid. - */ -public MenuItem -getItem(int index) -{ - return((MenuItem)items.elementAt(index)); -} - -/*************************************************************************/ - -/** - * Adds the specified item to this menu. If it was previously part of - * another menu, it is first removed from that menu. - * - * @param item The new item to add. - * - * @return The item that was added. - */ -public MenuItem -add(MenuItem item) -{ - items.addElement(item); - if (item.parent != null) - { - item.parent.remove(item); - } - item.parent = this; - - if (peer != null) - { - MenuPeer mp = (MenuPeer) peer; - mp.addItem(item); - } - - return item; -} - -/*************************************************************************/ - -/** - * Add an item with the specified label to this menu. - * - * @param label The label of the menu item to add. - */ -public void -add(String label) -{ - add(new MenuItem(label)); -} - -/*************************************************************************/ - -/** - * Inserts the specified menu item into this menu at the specified index. - * - * @param item The menu item to add. - * @param index The index of the menu item. - * - * @exception IllegalArgumentException If the index is less than zero. - * @exception ArrayIndexOutOfBoundsException If the index is otherwise invalid. - */ -public void -insert(MenuItem item, int index) -{ - if (index < 0) - throw new IllegalArgumentException("Index is less than zero"); - - MenuPeer peer = (MenuPeer) getPeer(); - if (peer == null) - return; - - int count = getItemCount (); - - if (index >= count) - peer.addItem (item); - else - { - for (int i = count - 1; i >= index; i--) - peer.delItem (i); - - peer.addItem (item); - - for (int i = index; i < count; i++) - peer.addItem ((MenuItem) items.elementAt (i)); - } - - items.insertElementAt(item, index); -} - -/*************************************************************************/ - -/** - * Inserts an item with the specified label into this menu at the specified index. - * - * @param label The label of the item to add. - * @param index The index of the menu item. - * - * @exception IllegalArgumentException If the index is less than zero. - * @exception ArrayIndexOutOfBoundsException If the index is otherwise invalid. - */ -public void -insert(String label, int index) -{ - insert(new MenuItem(label), index); -} - -/*************************************************************************/ - -/** - * Adds a separator bar at the current menu location. - */ -public void -addSeparator() -{ - add(new MenuItem(separatorLabel)); -} - -/*************************************************************************/ - -/** - * Inserts a separator bar at the specified index value. - * - * @param index The index at which to insert a separator bar. - * - * @exception IllegalArgumentException If the index is less than zero. - * @exception ArrayIndexOutOfBoundsException If the index is otherwise invalid. - */ -public void -insertSeparator(int index) -{ - insert(new MenuItem(separatorLabel), index); -} - -/*************************************************************************/ - -/** - * Deletes the item at the specified index from this menu. - * - * @param index The index of the item to remove. - * - * @exception ArrayIndexOutOfBoundsException If the index is otherwise invalid. - */ -public synchronized void -remove(int index) -{ - items.removeElementAt(index); - - MenuPeer mp = (MenuPeer)getPeer(); - if (mp != null) - mp.delItem(index); -} - -/*************************************************************************/ - -/** - * Removes the specifed item from the menu. If the specified component - * does not exist, this method does nothing. - * - * @param item The component to remove. - */ -public void -remove(MenuComponent item) -{ - int index = items.indexOf(item); - if (index == -1) - return; - - remove(index); -} - -/*************************************************************************/ - -/** - * Removes all the elements from this menu. - */ -public synchronized void -removeAll() -{ - int count = getItemCount(); - for(int i = 0; i < count; i++) - { - // We must always remove item 0. - remove(0); - } -} - -/*************************************************************************/ - -/** - * Creates the native peer for this object. - */ -public void -addNotify() -{ - if (peer == null) - peer = getToolkit().createMenu(this); - Enumeration e = items.elements(); - while (e.hasMoreElements()) - { - MenuItem mi = (MenuItem)e.nextElement(); - mi.addNotify(); - } - super.addNotify (); -} - -/*************************************************************************/ - -/** - * Destroys the native peer for this object. - */ -public void -removeNotify() -{ - Enumeration e = items.elements(); - while (e.hasMoreElements()) - { - MenuItem mi = (MenuItem) e.nextElement(); - mi.removeNotify(); - } - super.removeNotify(); -} - -/*************************************************************************/ - -/** - * Returns a debugging string for this menu. - * - * @return A debugging string for this menu. - */ -public String -paramString() -{ - return (",tearOff=" + tearOff + ",isHelpMenu=" + isHelpMenu - + super.paramString()); -} - - /** - * Basic Accessibility class for Menu. Details get provided in derived - * classes. - */ - protected class AccessibleAWTMenu extends AccessibleAWTMenuItem - { - protected AccessibleAWTMenu() - { - } - - public AccessibleRole getAccessibleRole() - { - return AccessibleRole.MENU; - } - } - - /** - * Gets the AccessibleContext associated with this <code>Menu</code>. - * The context is created, if necessary. - * - * @return the associated context - */ - public AccessibleContext getAccessibleContext() - { - /* Create the context if this is the first request */ - if (accessibleContext == null) - accessibleContext = new AccessibleAWTMenu(); - return accessibleContext; - } - -} // class Menu diff --git a/libjava/java/awt/MenuBar.java b/libjava/java/awt/MenuBar.java deleted file mode 100644 index 4089fe189e0..00000000000 --- a/libjava/java/awt/MenuBar.java +++ /dev/null @@ -1,423 +0,0 @@ -/* MenuBar.java -- An AWT menu bar class - Copyright (C) 1999, 2000, 2001, 2002, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.awt.peer.MenuBarPeer; -import java.awt.peer.MenuComponentPeer; - -import java.io.Serializable; -import java.util.Enumeration; -import java.util.Vector; - -import javax.accessibility.Accessible; -import javax.accessibility.AccessibleContext; -import javax.accessibility.AccessibleRole; - -/** - * This class implements a menu bar in the AWT system. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Tom Tromey (tromey@redhat.com) - * @author Andrew John Hughes (gnu_andrew@member.fsf.org) - */ -public class MenuBar extends MenuComponent - implements MenuContainer, Serializable, Accessible -{ - -/* - * Static Variables - */ - -// Serialization Constant -private static final long serialVersionUID = -4930327919388951260L; - -/*************************************************************************/ - -/* - * Instance Variables - */ - -/** - * @serial The menu used for providing help information - */ -private Menu helpMenu; - -/** - * @serial The menus contained in this menu bar. - */ -private Vector menus = new Vector(); - - /** - * The accessible context for this component. - * - * @see #getAccessibleContext() - * @serial ignored. - */ - private transient AccessibleContext accessibleContext; - -/*************************************************************************/ - -/* - * Constructors - */ - -/** - * Initializes a new instance of <code>MenuBar</code>. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. - */ -public -MenuBar() -{ - if (GraphicsEnvironment.isHeadless()) - throw new HeadlessException (); -} - -/*************************************************************************/ - -/* - * Instance Methods - */ - -/** - * Returns the help menu for this menu bar. This may be <code>null</code>. - * - * @return The help menu for this menu bar. - */ -public Menu -getHelpMenu() -{ - return(helpMenu); -} - -/*************************************************************************/ - -/** - * Sets the help menu for this menu bar. - * - * @param menu The new help menu for this menu bar. - */ -public synchronized void -setHelpMenu(Menu menu) -{ - if (helpMenu != null) - { - helpMenu.removeNotify (); - helpMenu.parent = null; - } - helpMenu = menu; - - if (menu.parent != null) - menu.parent.remove (menu); - menu.parent = this; - - MenuBarPeer peer = (MenuBarPeer) getPeer (); - if (peer != null) - { - menu.addNotify(); - peer.addHelpMenu (menu); - } -} - -/*************************************************************************/ - -/** Add a menu to this MenuBar. If the menu has already has a - * parent, it is first removed from its old parent before being - * added. - * - * @param menu The menu to add. - * - * @return The menu that was added. - */ -public synchronized Menu -add(Menu menu) -{ - if (menu.parent != null) - menu.parent.remove (menu); - - menu.parent = this; - menus.addElement(menu); - - if (peer != null) - { - menu.addNotify(); - } - - return(menu); -} - -/*************************************************************************/ - -/** - * Removes the menu at the specified index. - * - * @param index The index of the menu to remove from the menu bar. - */ -public synchronized void -remove(int index) -{ - Menu m = (Menu) menus.get (index); - menus.remove (index); - m.removeNotify (); - m.parent = null; - - if (peer != null) - { - MenuBarPeer mp = (MenuBarPeer) peer; - mp.delMenu (index); - } -} - -/*************************************************************************/ - -/** - * Removes the specified menu from the menu bar. - * - * @param menu The menu to remove from the menu bar. - */ -public void -remove(MenuComponent menu) -{ - int index = menus.indexOf(menu); - if (index == -1) - return; - - remove(index); -} - -/*************************************************************************/ - -/** - * Returns the number of elements in this menu bar. - * - * @return The number of elements in the menu bar. - */ -public int -getMenuCount() -{ - return countMenus (); -} - -/*************************************************************************/ - -/** - * Returns the number of elements in this menu bar. - * - * @return The number of elements in the menu bar. - * - * @deprecated This method is deprecated in favor of <code>getMenuCount()</code>. - */ -public int -countMenus() -{ - return menus.size () + (getHelpMenu () == null ? 0 : 1); -} - -/*************************************************************************/ - -/** - * Returns the menu at the specified index. - * - * @param index the index of the menu - * - * @return The requested menu. - * - * @exception ArrayIndexOutOfBoundsException If the index is not valid. - */ -public Menu -getMenu(int index) -{ - return((Menu)menus.elementAt(index)); -} - -/*************************************************************************/ - -/** - * Creates this object's native peer. - */ -public void -addNotify() -{ - if (getPeer() == null) - setPeer((MenuComponentPeer)getToolkit().createMenuBar(this)); - Enumeration e = menus.elements(); - while (e.hasMoreElements()) - { - Menu mi = (Menu)e.nextElement(); - mi.addNotify(); - } - if (helpMenu != null) - { - helpMenu.addNotify(); - ((MenuBarPeer) peer).addHelpMenu(helpMenu); - } -} - -/*************************************************************************/ - -/** - * Destroys this object's native peer. - */ -public void -removeNotify() -{ - Enumeration e = menus.elements(); - while (e.hasMoreElements()) - { - Menu mi = (Menu) e.nextElement(); - mi.removeNotify(); - } - super.removeNotify(); -} - -/*************************************************************************/ - -/** - * Returns a list of all shortcuts for the menus in this menu bar. - * - * @return A list of all shortcuts for the menus in this menu bar. - */ -public synchronized Enumeration -shortcuts() -{ - Vector shortcuts = new Vector(); - Enumeration e = menus.elements(); - - while (e.hasMoreElements()) - { - Menu menu = (Menu)e.nextElement(); - if (menu.getShortcut() != null) - shortcuts.addElement(menu.getShortcut()); - } - - return(shortcuts.elements()); -} - -/*************************************************************************/ - -/** - * Returns the menu item for the specified shortcut, or <code>null</code> - * if no such item exists. - * - * @param shortcut The shortcut to return the menu item for. - * - * @return The menu item for the specified shortcut. - */ -public MenuItem -getShortcutMenuItem(MenuShortcut shortcut) -{ - Enumeration e = menus.elements(); - - while (e.hasMoreElements()) - { - Menu menu = (Menu)e.nextElement(); - MenuShortcut s = menu.getShortcut(); - if ((s != null) && (s.equals(shortcut))) - return(menu); - } - - return(null); -} - -/*************************************************************************/ - -/** - * Deletes the specified menu shortcut. - * - * @param shortcut The shortcut to delete. - */ -public void -deleteShortcut(MenuShortcut shortcut) -{ - MenuItem it; - // This is a slow implementation, but it probably doesn't matter. - while ((it = getShortcutMenuItem (shortcut)) != null) - it.deleteShortcut (); -} - -/** - * Gets the AccessibleContext associated with this <code>MenuBar</code>. - * The context is created, if necessary. - * - * @return the associated context - */ -public AccessibleContext getAccessibleContext() -{ - /* Create the context if this is the first request */ - if (accessibleContext == null) - accessibleContext = new AccessibleAWTMenuBar(); - return accessibleContext; -} - -/** - * This class provides accessibility support for AWT menu bars. - * - * @author Andrew John Hughes (gnu_andrew@member.fsf.org) - */ -protected class AccessibleAWTMenuBar - extends AccessibleAWTMenuComponent -{ - - /** - * Compatible with JDK 1.4.2 revision 5 - */ - private static final long serialVersionUID = -8577604491830083815L; - - /** - * This is the default constructor, which simply calls the default - * constructor of the superclass. - */ - protected AccessibleAWTMenuBar() - { - super(); - } - - /** - * Returns the accessible role relating to the menu bar. - * - * @return <code>AccessibleRole.MENU_BAR</code>. - */ - public AccessibleRole getAccessibleRole() - { - return AccessibleRole.MENU_BAR; - } - -} // class AccessibleAWTMenuBar - -} // class MenuBar diff --git a/libjava/java/awt/MenuComponent.java b/libjava/java/awt/MenuComponent.java deleted file mode 100644 index ec6980e10ca..00000000000 --- a/libjava/java/awt/MenuComponent.java +++ /dev/null @@ -1,1324 +0,0 @@ -/* MenuComponent.java -- Superclass of all AWT menu components - Copyright (C) 1999, 2000, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.awt.event.FocusEvent; -import java.awt.event.FocusListener; -import java.awt.peer.MenuComponentPeer; -import java.io.Serializable; -import java.util.Locale; - -import javax.accessibility.Accessible; -import javax.accessibility.AccessibleComponent; -import javax.accessibility.AccessibleContext; -import javax.accessibility.AccessibleRole; -import javax.accessibility.AccessibleSelection; -import javax.accessibility.AccessibleStateSet; - -/** - * This is the superclass of all menu AWT widgets. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Andrew John Hughes (gnu_andrew@member.fsf.org) - */ -public abstract class MenuComponent implements Serializable -{ - -/* - * Static Variables - */ - -// Serialization Constant -private static final long serialVersionUID = -4536902356223894379L; - -/*************************************************************************/ - -/* - * Instance Variables - */ - -/** - * The font for this component. - * - * @see #getFont() - * @see #setFont(java.awt.Font) - * @serial the component's font. - */ - private Font font; - - /** - * The name of the component. - * - * @see #getName() - * @see #setName(String) - * @serial the component's name. - */ - private String name; - - /** - * The parent of this component. - * - * @see #getParent() - * @see #setParent(java.awt.MenuContainer) - * @serial ignored. - */ - transient MenuContainer parent; - - /** - * The native peer for this component. - * - * @see #getPeer() - * @see #setPeer(java.awt.peer.MenuComponentPeer) - * @serial ignored. - */ - transient MenuComponentPeer peer; - - /** - * The synchronization locking object for this component. - * - * @serial ignored. - */ - private transient Object tree_lock = this; - - /** - * The toolkit for this object. - * - * @see #getToolkit() - * @serial ignored. - */ - private static transient Toolkit toolkit = Toolkit.getDefaultToolkit(); - - /** - * The accessible context for this component. - * - * @see #getAccessibleContext() - * @serial the accessibility information for this component. - */ - AccessibleContext accessibleContext; - - /** - * Was the name of the component set? This value defaults - * to false and becomes true after a call to <code>setName()</code>. - * Please note that this does not guarantee that name will then - * be non-null, as this may be the value passed to <code>setName()</code>. - * - * @see #setName(String) - * @serial true if the name value has been explicitly set by calling - * <code>setName()</code>. - */ - private boolean nameExplicitlySet; - - /** - * Does this component handle new events? Events will be handled - * by this component if this is true. Otherwise, they will be forwarded - * up the component hierarchy. This implementation does not use this - * variable; it is merely provided for serialization compatability. - * - * @see #dispatchEvent(AWTEvent) - * @serial true if events are to be processed locally. Unused. - */ - private boolean newEventsOnly; - - /** - * The focus listener chain handler which deals with focus events for - * the accessible context of this component. - * - * @see AccessibleAWTMenuComponent#addFocusListener(java.awt.event.FocusListener) - * @serial ignored. - * This is package-private to avoid an accessor method. - */ - transient FocusListener focusListener; - -/*************************************************************************/ - -/* - * Constructors - */ - -/** - * Default constructor for subclasses. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. - */ -public -MenuComponent() -{ - if (GraphicsEnvironment.isHeadless()) - throw new HeadlessException (); -} - -/*************************************************************************/ - -/* - * Instance Methods - */ - -/** - * Returns the font in use for this component. - * - * @return The font for this component. - */ -public Font -getFont() -{ - if (font != null) - return font; - - if (parent != null) - return parent.getFont (); - - return null; -} - -/*************************************************************************/ - -/** - * Sets the font for this component to the specified font. - * - * @param font The new font for this component. - */ -public void -setFont(Font font) -{ - this.font = font; -} - -/*************************************************************************/ - -/** - * Returns the name of this component. - * - * @return The name of this component. - */ -public String -getName() -{ - return(name); -} - -/*************************************************************************/ - -/** - * Sets the name of this component to the specified name. - * - * @param name The new name of this component. - */ -public void -setName(String name) -{ - this.name = name; - nameExplicitlySet = true; -} - -/*************************************************************************/ - -/** - * Returns the parent of this component. - * - * @return The parent of this component. - */ -public MenuContainer -getParent() -{ - return(parent); -} - -/*************************************************************************/ - -// Sets the parent of this component. -final void -setParent(MenuContainer parent) -{ - this.parent = parent; -} - -/*************************************************************************/ - -/** - * Returns the native windowing system peer for this component. - * - * @return The peer for this component. - * - * @deprecated - */ -public MenuComponentPeer -getPeer() -{ - return(peer); -} - -/*************************************************************************/ - -// Sets the peer for this component. -final void -setPeer(MenuComponentPeer peer) -{ - this.peer = peer; -} - -/*************************************************************************/ - -/** - * Destroys this component's native peer - */ -public void -removeNotify() -{ - if (peer != null) - peer.dispose(); - peer = null; -} - -/*************************************************************************/ - -/** - * Returns the toolkit in use for this component. - * - * @return The toolkit for this component. - */ -final Toolkit -getToolkit() -{ - return(toolkit); -} - -/*************************************************************************/ - -/** - * Returns the object used for synchronization locks on this component - * when performing tree and layout functions. - * - * @return The synchronization lock for this component. - */ -protected final Object -getTreeLock() -{ - return(tree_lock); -} - -/*************************************************************************/ - -// The sync lock object for this component. -final void -setTreeLock(Object tree_lock) -{ - this.tree_lock = tree_lock; -} - -/*************************************************************************/ - -/** - * AWT 1.0 event dispatcher. - * - * @deprecated Deprecated in favor of <code>dispatchEvent()</code>. - * @return true if the event was dispatched, false otherwise. - */ -public boolean -postEvent(Event event) -{ - // This is overridden by subclasses that support events. - return false; -} -/*************************************************************************/ - -/** - * Sends this event to this component or a subcomponent for processing. - * - * @param event The event to dispatch - */ -public final void dispatchEvent(AWTEvent event) -{ - // See comment in Component.dispatchEvent(). - dispatchEventImpl(event); -} - - -/** - * Implementation of dispatchEvent. Allows trusted package classes - * to dispatch additional events first. This implementation first - * translates <code>event</code> to an AWT 1.0 event and sends the - * result to {@link #postEvent}. The event is then - * passed on to {@link #processEvent} for local processing. - * - * @param event the event to dispatch. - */ -void dispatchEventImpl(AWTEvent event) -{ - Event oldStyleEvent; - - // This is overridden by subclasses that support events. - /* Convert AWT 1.1 event to AWT 1.0 event */ - oldStyleEvent = Component.translateEvent(event); - if (oldStyleEvent != null) - { - postEvent(oldStyleEvent); - } - /* Do local processing */ - processEvent(event); -} - -/*************************************************************************/ - -/** - * Processes the specified event. In this class, this method simply - * calls one of the more specific event handlers. - * - * @param event The event to process. - */ -protected void -processEvent(AWTEvent event) -{ - /* - Pass a focus event to the focus listener for - the accessibility context. - */ - if (event instanceof FocusEvent) - { - if (focusListener != null) - { - switch (event.id) - { - case FocusEvent.FOCUS_GAINED: - focusListener.focusGained((FocusEvent) event); - break; - case FocusEvent.FOCUS_LOST: - focusListener.focusLost((FocusEvent) event); - break; - } - } - } -} - -/*************************************************************************/ - -/** - * Returns a string representation of this component. - * - * @return A string representation of this component - */ -public String -toString() -{ - return this.getClass().getName() + "[" + paramString() + "]"; -} - -/*************************************************************************/ - -/** - * Returns a debugging string for this component - */ -protected String -paramString() -{ - return "name=" + getName(); -} - -/** - * Gets the AccessibleContext associated with this <code>MenuComponent</code>. - * As an abstract class, we return null. Concrete subclasses should return - * their implementation of the accessibility context. - * - * @return null. - */ - -public AccessibleContext getAccessibleContext() -{ - return null; -} - -/** - * This class provides a base for the accessibility support of menu - * components. - * - * @author Andrew John Hughes (gnu_andrew@member.fsf.org) - */ -protected abstract class AccessibleAWTMenuComponent - extends AccessibleContext - implements Serializable, AccessibleComponent, AccessibleSelection -{ - - /** - * Compatible with JDK 1.4.2 revision 5 - */ - private static final long serialVersionUID = -4269533416223798698L; - - /** - * This is the default constructor. It should be called by - * concrete subclasses to ensure necessary groundwork is completed. - */ - protected AccessibleAWTMenuComponent() - { - } - - /** - * Replaces or supplements the component's selection with the - * <code>Accessible</code> child at the supplied index. If - * the component supports multiple selection, the child is - * added to the current selection. Otherwise, the current - * selection becomes the specified child. If the child is - * already selected, nothing happens. - * <br /> - * <br /> - * As the existence of children can not be determined from - * this abstract class, the implementation of this method - * is left to subclasses. - * - * @param index the index of the specified child within a - * zero-based list of the component's children. - */ - public void addAccessibleSelection(int index) - { - /* Subclasses with children should implement this */ - } - - /** - * Registers the specified focus listener to receive - * focus events from this component. - * - * @param listener the new focus listener. - */ - public void addFocusListener(FocusListener listener) - { - /* - * Chain the new focus listener to the existing chain - * of focus listeners. Each new focus listener is - * coupled via multicasting to the existing chain. - */ - focusListener = AWTEventMulticaster.add(focusListener, listener); - } - - /** - * Clears the component's current selection. Following - * the calling of this method, no children of the component - * will be selected. - * <br /> - * <br /> - * As the existence of children can not be determined from - * this abstract class, the implementation of this method - * is left to subclasses. - */ - public void clearAccessibleSelection() - { - } - - /** - * Returns true if the specified point lies within the - * component. The supplied co-ordinates are assumed to - * be relative to the co-ordinate system of the component - * itself. Thus, the point (0,0) is the upper left corner - * of this component. - * <br /> - * <br /> - * Please note that this method depends on a correctly implemented - * version of the <code>getBounds()</code> method. Subclasses - * must provide the bounding rectangle via <code>getBounds()</code> - * in order for this method to work. - * - * @param point the point to check against this component. - * @return true if the point is within this component. - * @see #getBounds() - */ - public boolean contains(Point point) - { - /* - We can simply return the result of a - test for containment in the bounding rectangle - */ - return getBounds().contains(point); - } - - /** - * Returns the <code>Accessible</code> child of this component present - * at the specified point. The supplied co-ordinates are - * assumed to be relative to the co-ordinate system of this - * component (the parent of any returned accessible). Thus, - * the point (0,0) is the upper left corner of this menu - * component. - * <br /> - * <br /> - * As the existence of children can not be determined from - * this abstract class, the implementation of this method - * is left to subclasses. - * - * @param point the point at which the returned accessible - * is located. - * @return null. - */ - public Accessible getAccessibleAt(Point point) - { - return null; - } - - /** - * Returns the <code>Accessible</code> child at the supplied - * index within the list of children of this component. - * <br /> - * <br /> - * As the existence of children can not be determined from - * this abstract class, the implementation of this method - * is left to subclasses. - * - * @param index the index of the <code>Accessible</code> child - * to retrieve. - * @return null. - */ - public Accessible getAccessibleChild(int index) - { - return null; - } - - /** - * Returns the number of children of this component which - * implement the <code>Accessible</code> interface. If - * all children of this component are accessible, then - * the returned value will be the same as the number of - * children. - * <br /> - * <br /> - * - * @return 0. - */ - public int getAccessibleChildrenCount() - { - return 0; - } - - /** - * Retrieves the <code>AccessibleComponent</code> associated - * with this accessible context and its component. As the - * context itself implements <code>AccessibleComponent</code>, - * this is the return value. - * - * @return the context itself. - */ - public AccessibleComponent getAccessibleComponent() - { - return this; - } - - /** - * Returns the accessible name for this menu component. This - * is the name given to the component, which may be null if - * not set using <code>setName()</code>. - * <br /> - * <br /> - * The name is not the most appropriate description of this - * object. Subclasses should preferably provide a more - * accurate description. For example, a File menu could - * have the description `Lists commands related to the - * file system'. - * - * @return a description of the component. Currently, - * this is just the contents of the name property. - * @see MenuComponent#setName(String) - */ - public String getAccessibleDescription() - { - return MenuComponent.this.getName(); - } - - /** - * Retrieves the index of this component within its parent. - * If no parent exists, -1 is returned. - * - * @return -1 as the parent, a <code>MenuContainer</code> - * is not <code>Accessible</code>. - */ - public int getAccessibleIndexInParent() - { - return -1; - } - - /** - * Returns the accessible name of this component. This - * is the name given to the component, which may be null if - * not set using <code>setName()</code>. - * <br /> - * <br /> - * The name property is not the most suitable string to return - * for this method. The string should be localized, and - * relevant to the operation of the component. For example, - * it could be the text of a menu item. However, this can - * not be used at this level of abstraction, so it is the - * responsibility of subclasses to provide a more appropriate - * name. - * - * @return a localized name for this component. Currently, this - * is just the contents of the name property. - * @see MenuComponent#setName(String) - */ - public String getAccessibleName() - { - return MenuComponent.this.getName(); - } - - /** - * Returns the <code>Accessible</code> parent of this component. - * As the parent of a <code>MenuComponent</code> is a - * <code>MenuContainer</code>, which doesn't implement - * <code>Accessible</code>, this method returns null. - * - * @return null. - */ - public Accessible getAccessibleParent() - { - return null; - } - - /** - * Returns the accessible role of this component. - * <br /> - * <br /> - * The abstract implementation of this method returns - * <code>AccessibleRole.AWT_COMPONENT</code>, - * as the abstract component has no specific role. This - * method should be overridden by concrete subclasses, so - * as to return an appropriate role for the component. - * - * @return <code>AccessibleRole.AWT_COMPONENT</code>. - */ - public AccessibleRole getAccessibleRole() - { - return AccessibleRole.AWT_COMPONENT; - } - - /** - * Retrieves the <code>AccessibleSelection</code> associated - * with this accessible context and its component. As the - * context itself implements <code>AccessibleSelection</code>, - * this is the return value. - * - * @return the context itself. - */ - public AccessibleSelection getAccessibleSelection() - { - return this; - } - - /** - * Retrieves the <code>Accessible</code> selected child - * at the specified index. If there are no selected children - * or the index is outside the range of selected children, - * null is returned. Please note that the index refers - * to the index of the child in the list of <strong>selected - * children</strong>, and not the index of the child in - * the list of all <code>Accessible</code> children. - * <br /> - * <br /> - * As the existence of children can not be determined from - * this abstract class, the implementation of this method - * is left to subclasses. - * - * @param index the index of the selected <code>Accessible</code> - * child. - */ - public Accessible getAccessibleSelection(int index) - { - return null; - } - - /** - * Returns a count of the number of <code>Accessible</code> - * children of this component which are currently selected. - * If there are no children currently selected, 0 is returned. - * <br /> - * <br /> - * As the existence of children can not be determined from - * this abstract class, the implementation of this method - * is left to subclasses. - * - * @return 0. - */ - public int getAccessibleSelectionCount() - { - return 0; - } - - /** - * Retrieves the current state of this component - * in an accessible form. For example, a given component - * may be visible, selected, disabled, etc. - * <br /> - * <br /> - * As this class tells us virtually nothing about the component, - * except for its name and font, no state information can be - * provided. This implementation thus returns an empty - * state set, and it is left to concrete subclasses to provide - * a more acceptable and relevant state set. Changes to these - * properties also need to be handled using - * <code>PropertyChangeListener</code>s. - * - * @return an empty <code>AccessibleStateSet</code>. - */ - public AccessibleStateSet getAccessibleStateSet() - { - return new AccessibleStateSet(); - } - - /** - * Returns the background color of the component, or null - * if this property is unsupported. - * <br /> - * <br /> - * This abstract class knows nothing about how the component - * is drawn on screen, so this method simply returns the - * default system background color used for rendering menus. - * Concrete subclasses which handle the drawing of an onscreen - * menu component should override this method and provide - * the appropriate information. - * - * @return the default system background color for menus. - * @see #setBackground(java.awt.Color) - */ - public Color getBackground() - { - return SystemColor.menu; - } - - /** - * Returns a <code>Rectangle</code> which represents the - * bounds of this component. The returned rectangle has the - * height and width of the component's bounds, and is positioned - * at a location relative to this component's parent, the - * <code>MenuContainer</code>. null is returned if bounds - * are not supported by the component. - * <br /> - * <br /> - * This abstract class knows nothing about how the component - * is drawn on screen, so this method simply returns null. - * Concrete subclasses which handle the drawing of an onscreen - * menu component should override this method and provide - * the appropriate information. - * - * @return null. - * @see #setBounds(java.awt.Rectangle) - */ - public Rectangle getBounds() - { - return null; - } - - /** - * Returns the <code>Cursor</code> displayed when the pointer - * is positioned over this component. Alternatively, null - * is returned if the component doesn't support the cursor - * property. - * <br /> - * <br /> - * This abstract class knows nothing about how the component - * is drawn on screen, so this method simply returns the default - * system cursor. Concrete subclasses which handle the drawing - * of an onscreen menu component may override this method and provide - * the appropriate information. - * - * @return the default system cursor. - * @see #setCursor(java.awt.Cursor) - */ - public Cursor getCursor() - { - return Cursor.getDefaultCursor(); - } - - /** - * Returns the <code>Font</code> used for text created by this component. - * - * @return the current font. - * @see #setFont(java.awt.Font) - */ - public Font getFont() - { - return MenuComponent.this.getFont(); - } - - /** - * Retrieves information on the rendering and metrics of the supplied - * font. If font metrics are not supported by this component, null - * is returned. - * <br /> - * <br /> - * The abstract implementation of this method simply uses the toolkit - * to obtain the <code>FontMetrics</code>. Concrete subclasses may - * find it more efficient to invoke their peer class directly, if one - * is available. - * - * @param font the font about which to retrieve rendering and metric - * information. - * @return the metrics of the given font, as provided by the system - * toolkit. - * @throws NullPointerException if the supplied font was null. - */ - public FontMetrics getFontMetrics(Font font) - { - return MenuComponent.this.getToolkit().getFontMetrics(font); - } - - /** - * Returns the foreground color of the component, or null - * if this property is unsupported. - * <br /> - * <br /> - * This abstract class knows nothing about how the component - * is drawn on screen, so this method simply returns the - * default system text color used for rendering menus. - * Concrete subclasses which handle the drawing of an onscreen - * menu component should override this method and provide - * the appropriate information. - * - * @return the default system text color for menus. - * @see #setForeground(java.awt.Color) - */ - public Color getForeground() - { - return SystemColor.menuText; - } - - /** - * Returns the locale currently in use by this component. - * <br /> - * <br /> - * This abstract class has no property relating to the - * locale used by the component, so this method simply - * returns the default locale for the current instance - * of the Java Virtual Machine (JVM). Concrete subclasses - * which maintain such a property should override this method - * and provide the locale information more accurately. - * - * @return the default locale for this JVM instance. - */ - public Locale getLocale() - { - return Locale.getDefault(); - } - - /** - * Returns the location of the component, with co-ordinates - * relative to the parent component and using the co-ordinate - * space of the screen. Thus, the point (0,0) is the upper - * left corner of the parent component. - * <br /> - * <br /> - * Please note that this method depends on a correctly implemented - * version of the <code>getBounds()</code> method. Subclasses - * must provide the bounding rectangle via <code>getBounds()</code> - * in order for this method to work. - * - * @return the location of the component, relative to its parent. - * @see #setLocation(java.awt.Point) - */ - public Point getLocation() - { - /* Simply return the location of the bounding rectangle */ - return getBounds().getLocation(); - } - - /** - * Returns the location of the component, with co-ordinates - * relative to the screen. Thus, the point (0,0) is the upper - * left corner of the screen. null is returned if the component - * is either not on screen or if this property is unsupported. - * <br /> - * <br /> - * This abstract class knows nothing about how the component - * is drawn on screen, so this method simply returns null. - * Concrete subclasses which handle the drawing of an onscreen - * menu component should override this method and provide - * the appropriate information. - * - * @return the location of the component, relative to the screen. - */ - public Point getLocationOnScreen() - { - return null; - } - - /** - * Returns the size of the component. - * <br /> - * <br /> - * Please note that this method depends on a correctly implemented - * version of the <code>getBounds()</code> method. Subclasses - * must provide the bounding rectangle via <code>getBounds()</code> - * in order for this method to work. - * - * @return the size of the component. - * @see #setSize(java.awt.Dimension) - */ - public Dimension getSize() - { - /* Simply return the size of the bounding rectangle */ - return getBounds().getSize(); - } - - /** - * Returns true if the accessible child specified by the supplied index - * is currently selected. - * <br /> - * <br /> - * As the existence of children can not be determined from - * this abstract class, the implementation of this method - * is left to subclasses. - * - * @param index the index of the accessible child to check for selection. - * @return false. - */ - public boolean isAccessibleChildSelected(int index) - { - return false; - } - - /** - * Returns true if this component is currently enabled. - * <br /> - * <br /> - * As this abstract component has no properties related to - * its enabled or disabled state, the implementation of this - * method is left to subclasses. - * - * @return false. - * @see #setEnabled(boolean) - */ - public boolean isEnabled() - { - return false; - } - - /** - * Returns true if this component is included in the traversal - * of the current focus from one component to the other. - * <br /> - * <br /> - * As this abstract component has no properties related to - * its ability to accept the focus, the implementation of this - * method is left to subclasses. - * - * @return false. - */ - public boolean isFocusTraversable() - { - return false; - } - - /** - * Returns true if the component is being shown on screen. - * A component is determined to be shown if it is visible, - * and each parent component is also visible. Please note - * that, even when a component is showing, it may still be - * obscured by other components in front. This method only - * determines if the component is being drawn on the screen. - * <br /> - * <br /> - * As this abstract component and its parent have no properties - * relating to visibility, the implementation of this method is - * left to subclasses. - * - * @return false. - * @see #isVisible() - */ - public boolean isShowing() - { - return false; - } - - /** - * Returns true if the component is visible. A component may - * be visible but not drawn on the screen if one of its parent - * components is not visible. To determine if the component is - * actually drawn on screen, <code>isShowing()</code> should be - * used. - * <br /> - * <br /> - * As this abstract component has no properties relating to its - * visibility, the implementation of this method is left to subclasses. - * - * @return false. - * @see #isShowing() - * @see #setVisible(boolean) - */ - public boolean isVisible() - { - return false; - } - - /** - * Removes the accessible child specified by the supplied index from - * the list of currently selected children. If the child specified - * is not selected, nothing happens. - * <br /> - * <br /> - * As the existence of children can not be determined from - * this abstract class, the implementation of this method - * is left to subclasses. - * - * @param index the index of the <code>Accessible</code> child. - */ - public void removeAccessibleSelection(int index) - { - /* Subclasses with children should implement this */ - } - - /** - * Removes the specified focus listener from the list of registered - * focus listeners for this component. - * - * @param listener the listener to remove. - */ - public void removeFocusListener(FocusListener listener) - { - /* Remove the focus listener from the chain */ - focusListener = AWTEventMulticaster.remove(focusListener, listener); - } - - /** - * Requests that this component gains focus. This depends on the - * component being focus traversable. - * <br /> - * <br /> - * As this abstract component has no properties relating to its - * focus traversability, or access to a peer with request focusing - * abilities, the implementation of this method is left to subclasses. - */ - public void requestFocus() - { - /* Ignored */ - } - - /** - * Selects all <code>Accessible</code> children of this component which - * it is possible to select. The component needs to support multiple - * selections. - * <br /> - * <br /> - * This abstract component provides a simplistic implementation of this - * method, which ignores the ability of the component to support multiple - * selections and simply uses <code>addAccessibleSelection</code> to - * add each <code>Accessible</code> child to the selection. The last - * <code>Accessible</code> component is thus selected for components - * which don't support multiple selections. Concrete implementations should - * override this with a more appopriate and efficient implementation, which - * properly takes into account the ability of the component to support multiple - * selections. - */ - public void selectAllAccessibleSelection() - { - /* Simply call addAccessibleSelection() on all accessible children */ - for (int a = 0; a < getAccessibleChildrenCount(); ++a) - { - addAccessibleSelection(a); - } - } - - /** - * Sets the background color of the component to that specified. - * Unspecified behaviour occurs when null is given as the new - * background color. - * <br /> - * <br /> - * This abstract class knows nothing about how the component - * is drawn on screen, so this method simply ignores the supplied - * color and continues to use the default system color. - * Concrete subclasses which handle the drawing of an onscreen - * menu component should override this method and provide - * the appropriate information. - * - * @param color the new color to use for the background. - * @see getBackground() - */ - public void setBackground(Color color) - { - /* Ignored */ - } - - /** - * Sets the height and width of the component, and its position - * relative to this component's parent, to the values specified - * by the supplied rectangle. Unspecified behaviour occurs when - * null is given as the new bounds. - * <br /> - * <br /> - * This abstract class knows nothing about how the component - * is drawn on screen, so this method simply ignores the new - * rectangle and continues to return null from <code>getBounds()</code>. - * Concrete subclasses which handle the drawing of an onscreen - * menu component should override this method and provide - * the appropriate information. - * - * @param rectangle a rectangle which specifies the new bounds of - * the component. - * @see #getBounds() - */ - public void setBounds(Rectangle rectangle) - { - /* Ignored */ - } - - /** - * Sets the <code>Cursor</code> used when the pointer is positioned over the - * component. Unspecified behaviour occurs when null is given as the new - * cursor. - * <br /> - * <br /> - * This abstract class knows nothing about how the component - * is drawn on screen, so this method simply ignores the new cursor - * and continues to return the default system cursor. Concrete - * subclasses which handle the drawing of an onscreen menu component - * may override this method and provide the appropriate information. - * - * @param cursor the new cursor to use. - * @see #getCursor() - */ - public void setCursor(Cursor cursor) - { - /* Ignored */ - } - - /** - * Sets the enabled/disabled state of this component. - * <br /> - * <br /> - * As this abstract component has no properties related to - * its enabled or disabled state, the implementation of this - * method is left to subclasses. - * - * @param enabled true if the component should be enabled, - * false otherwise. - * @see #getEnabled() - */ - public void setEnabled(boolean enabled) - { - /* Ignored */ - } - - /** - * Sets the <code>Font</code> used for text created by this component. - * Unspecified behaviour occurs when null is given as the new - * font. - * - * @param font the new font to use for text. - * @see #getFont() - */ - public void setFont(Font font) - { - /* Call the method of the enclosing component */ - MenuComponent.this.setFont(font); - } - - /** - * Sets the foreground color of the component to that specified. - * Unspecified behaviour occurs when null is given as the new - * background color. - * <br /> - * <br /> - * This abstract class knows nothing about how the component - * is drawn on screen, so this method simply ignores the supplied - * color and continues to return the default system text color used - * for rendering menus. - * Concrete subclasses which handle the drawing of an onscreen - * menu component should override this method and provide - * the appropriate information. - * - * @param color the new foreground color. - * @see #getForeground() - */ - public void setForeground(Color color) - { - /* Ignored */ - } - - /** - * Sets the location of the component, with co-ordinates - * relative to the parent component and using the co-ordinate - * space of the screen. Thus, the point (0,0) is the upper - * left corner of the parent component. - * <br /> - * <br /> - * Please note that this method depends on a correctly implemented - * version of the <code>getBounds()</code> method. Subclasses - * must provide the bounding rectangle via <code>getBounds()</code> - * in order for this method to work. - * - * @param point the location of the component, relative to its parent. - * @see #getLocation() - */ - public void setLocation(Point point) - { - getBounds().setLocation(point); - } - - /** - * Sets the size of the component. - * <br /> - * <br /> - * Please note that this method depends on a correctly implemented - * version of the <code>getBounds()</code> method. Subclasses - * must provide the bounding rectangle via <code>getBounds()</code> - * in order for this method to work. - * - * @param size the new size of the component. - * @see #getSize() - */ - public void setSize(Dimension size) - { - getBounds().setSize(size); - } - - /** - * Sets the visibility state of the component. A component may - * be visible but not drawn on the screen if one of its parent - * components is not visible. To determine if the component is - * actually drawn on screen, <code>isShowing()</code> should be - * used. - * <br /> - * <br /> - * As this abstract component has no properties relating to its - * visibility, the implementation of this method is left to subclasses. - * - * @param visibility the new visibility of the component -- true if - * the component is visible, false if not. - * @see #isShowing() - * @see #isVisible() - */ - public void setVisible(boolean visibility) - { - /* Ignored */ - } - -} /* class AccessibleAWTMenuComponent */ - - -} // class MenuComponent diff --git a/libjava/java/awt/MenuContainer.java b/libjava/java/awt/MenuContainer.java deleted file mode 100644 index c76ec96c20b..00000000000 --- a/libjava/java/awt/MenuContainer.java +++ /dev/null @@ -1,71 +0,0 @@ -/* MenuContainer.java -- container for menu items - Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -/** - * This interface is a container for menu components. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @since 1.0 - * @status updated to 1.4 - */ -public interface MenuContainer -{ - /** - * Returns the font in use by this container. - * - * @return the menu font - */ - Font getFont(); - - /** - * Removes the specified menu component from the menu. - * - * @param component the menu component to remove - */ - void remove(MenuComponent component); - - /** - * Posts an event to the listeners. - * - * @param event the event to dispatch - * @deprecated use {@link MenuComponent#dispatchEvent(AWTEvent)} instead - */ - boolean postEvent(Event event); -} // interface MenuContainer diff --git a/libjava/java/awt/MenuItem.java b/libjava/java/awt/MenuItem.java deleted file mode 100644 index cea2475cda2..00000000000 --- a/libjava/java/awt/MenuItem.java +++ /dev/null @@ -1,603 +0,0 @@ -/* MenuItem.java -- An item in a menu - Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.peer.MenuItemPeer; -import java.io.Serializable; -import java.lang.reflect.Array; -import java.util.EventListener; - -import javax.accessibility.Accessible; -import javax.accessibility.AccessibleAction; -import javax.accessibility.AccessibleContext; -import javax.accessibility.AccessibleRole; -import javax.accessibility.AccessibleValue; - -/** - * This class represents an item in a menu. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public class MenuItem extends MenuComponent - implements Serializable, Accessible -{ - -/* - * Static Variables - */ - -// Serialization Constant -private static final long serialVersionUID = -21757335363267194L; - -/*************************************************************************/ - -/* - * Instance Variables - */ - -/** - * @serial The name of the action command generated by this item. - * This is package-private to avoid an accessor method. - */ -String actionCommand; - -/** - * @serial Indicates whether or not this menu item is enabled. - * This is package-private to avoid an accessor method. - */ -boolean enabled = true; - -/** - * @serial The mask of events that are enabled for this menu item. - */ -long eventMask; - -/** - * @serial This menu item's label - * This is package-private to avoid an accessor method. - */ -String label; - -/** - * @serial The shortcut for this menu item, if any - */ -private MenuShortcut shortcut; - -// The list of action listeners for this menu item. -private transient ActionListener action_listeners; - - protected class AccessibleAWTMenuItem - extends MenuComponent.AccessibleAWTMenuComponent - implements AccessibleAction, AccessibleValue - { - /** Constructor */ - public AccessibleAWTMenuItem() - { - super(); - } - - - - public String getAccessibleName() - { - return label; - } - - public AccessibleAction getAccessibleAction() - { - return this; - } - - public AccessibleRole getAccessibleRole() - { - return AccessibleRole.MENU_ITEM; - } - - /* (non-Javadoc) - * @see javax.accessibility.AccessibleAction#getAccessibleActionCount() - */ - public int getAccessibleActionCount() - { - return 1; - } - - /* (non-Javadoc) - * @see javax.accessibility.AccessibleAction#getAccessibleActionDescription(int) - */ - public String getAccessibleActionDescription(int i) - { - if (i == 0) - return label; - else - return null; - } - - /* (non-Javadoc) - * @see javax.accessibility.AccessibleAction#doAccessibleAction(int) - */ - public boolean doAccessibleAction(int i) - { - if (i != 0) - return false; - processActionEvent(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, actionCommand)); - return true; - } - - public AccessibleValue getAccessibleValue() - { - return this; - } - - /* (non-Javadoc) - * @see javax.accessibility.AccessibleValue#getCurrentAccessibleValue() - */ - public Number getCurrentAccessibleValue() - { - return (enabled) ? new Integer(1) : new Integer(0); - } - - /* (non-Javadoc) - * @see javax.accessibility.AccessibleValue#setCurrentAccessibleValue(java.lang.Number) - */ - public boolean setCurrentAccessibleValue(Number number) - { - if (number.intValue() == 0) - { - setEnabled(false); - return false; - } - - setEnabled(true); - return true; - } - - /* (non-Javadoc) - * @see javax.accessibility.AccessibleValue#getMinimumAccessibleValue() - */ - public Number getMinimumAccessibleValue() - { - return new Integer(0); - } - - /* (non-Javadoc) - * @see javax.accessibility.AccessibleValue#getMaximumAccessibleValue() - */ - public Number getMaximumAccessibleValue() - { - return new Integer(0); - } - - } - - -/*************************************************************************/ - -/* - * Constructors - */ - -/** - * Initializes a new instance of <code>MenuItem</code> with no label - * and no shortcut. - */ -public -MenuItem() -{ -} - -/*************************************************************************/ - -/** - * Initializes a new instance of <code>MenuItem</code> with the specified - * label and no shortcut. - * - * @param label The label for this menu item. - */ -public -MenuItem(String label) -{ - this.label = label; -} - -/*************************************************************************/ - -/** - * Initializes a new instance of <code>MenuItem</code> with the specified - * label and shortcut. - * - * @param label The label for this menu item. - * @param shortcut The shortcut for this menu item. - */ -public -MenuItem(String label, MenuShortcut shortcut) -{ - this.label = label; - this.shortcut = shortcut; -} - -/*************************************************************************/ - -/* - * Instance Methods - */ - -/** - * Returns the label for this menu item, which may be <code>null</code>. - * - * @return The label for this menu item. - */ -public String -getLabel() -{ - return(label); -} - -/*************************************************************************/ - -/** - * This method sets the label for this menu to the specified value. - * - * @param label The new label for this menu item. - */ -public synchronized void -setLabel(String label) -{ - this.label = label; - if (peer != null) - { - MenuItemPeer mp = (MenuItemPeer) peer; - mp.setLabel (label); - } -} - -/*************************************************************************/ - -/** - * Tests whether or not this menu item is enabled. - * - * @return <code>true</code> if this menu item is enabled, <code>false</code> - * otherwise. - */ -public boolean -isEnabled() -{ - return(enabled); -} - -/*************************************************************************/ - -/** - * Sets the enabled status of this menu item. - * - * @param enabled <code>true</code> to enable this menu item, - * <code>false</code> otherwise. - */ -public synchronized void -setEnabled(boolean enabled) -{ - enable (enabled); -} - -/*************************************************************************/ - -/** - * Sets the enabled status of this menu item. - * - * @param enabled <code>true</code> to enable this menu item, - * <code>false</code> otherwise. - * - * @deprecated This method is deprecated in favor of <code>setEnabled()</code>. - */ -public void -enable(boolean enabled) -{ - if (enabled) - enable (); - else - disable (); -} - -/*************************************************************************/ - -/** - * Enables this menu item. - * - * @deprecated This method is deprecated in favor of <code>setEnabled()</code>. - */ -public void -enable() -{ - if (enabled) - return; - - this.enabled = true; - if (peer != null) - ((MenuItemPeer) peer).setEnabled (true); -} - -/*************************************************************************/ - -/** - * Disables this menu item. - * - * @deprecated This method is deprecated in favor of <code>setEnabled()</code>. - */ -public void -disable() -{ - if (!enabled) - return; - - this.enabled = false; - if (peer != null) - ((MenuItemPeer) peer).setEnabled (false); -} - -/*************************************************************************/ - -/** - * Returns the shortcut for this menu item, which may be <code>null</code>. - * - * @return The shortcut for this menu item. - */ -public MenuShortcut -getShortcut() -{ - return(shortcut); -} - -/*************************************************************************/ - -/** - * Sets the shortcut for this menu item to the specified value. This - * must be done before the native peer is created. - * - * @param shortcut The new shortcut for this menu item. - */ -public void -setShortcut(MenuShortcut shortcut) -{ - this.shortcut = shortcut; -} - -/*************************************************************************/ - -/** - * Deletes the shortcut for this menu item if one exists. This must be - * done before the native peer is created. - */ -public void -deleteShortcut() -{ - shortcut = null; -} - -/*************************************************************************/ - -/** - * Returns the name of the action command in the action events - * generated by this menu item. - * - * @return The action command name - */ -public String -getActionCommand() -{ - if (actionCommand == null) - return label; - else - return actionCommand; -} - -/*************************************************************************/ - -/** - * Sets the name of the action command in the action events generated by - * this menu item. - * - * @param actionCommand The new action command name. - */ -public void -setActionCommand(String actionCommand) -{ - this.actionCommand = actionCommand; -} - -/*************************************************************************/ - -/** - * Enables the specified events. This is done automatically when a - * listener is added and does not normally need to be done by - * application code. - * - * @param events The events to enable, which should be the bit masks - * from <code>AWTEvent</code>. - */ -protected final void -enableEvents(long events) -{ - eventMask |= events; - // TODO: see comment in Component.enableEvents(). -} - -/*************************************************************************/ - -/** - * Disables the specified events. - * - * @param events The events to enable, which should be the bit masks - * from <code>AWTEvent</code>. - */ -protected final void -disableEvents(long events) -{ - eventMask &= ~events; -} - -/*************************************************************************/ - -/** - * Creates the native peer for this object. - */ -public void -addNotify() -{ - if (peer == null) - peer = getToolkit ().createMenuItem (this); -} - -/*************************************************************************/ - -/** - * Adds the specified listener to the list of registered action listeners - * for this component. - * - * @param listener The listener to add. - */ -public synchronized void -addActionListener(ActionListener listener) -{ - action_listeners = AWTEventMulticaster.add(action_listeners, listener); - - enableEvents(AWTEvent.ACTION_EVENT_MASK); -} - -public synchronized void -removeActionListener(ActionListener l) -{ - action_listeners = AWTEventMulticaster.remove(action_listeners, l); -} - - public synchronized ActionListener[] getActionListeners() - { - return (ActionListener[]) - AWTEventMulticaster.getListeners(action_listeners, - ActionListener.class); - } - -/** Returns all registered EventListers of the given listenerType. - * listenerType must be a subclass of EventListener, or a - * ClassClassException is thrown. - * @since 1.3 - */ - public EventListener[] getListeners(Class listenerType) - { - if (listenerType == ActionListener.class) - return getActionListeners(); - return (EventListener[]) Array.newInstance(listenerType, 0); - } - -/*************************************************************************/ - -void -dispatchEventImpl(AWTEvent e) -{ - if (e.id <= ActionEvent.ACTION_LAST - && e.id >= ActionEvent.ACTION_FIRST - && (action_listeners != null - || (eventMask & AWTEvent.ACTION_EVENT_MASK) != 0)) - processEvent(e); - - // Send the event to the parent menu if it has not yet been - // consumed. - if (!e.isConsumed ()) - ((Menu) getParent ()).processEvent (e); -} - -/** - * Processes the specified event by calling <code>processActionEvent()</code> - * if it is an instance of <code>ActionEvent</code>. - * - * @param event The event to process. - */ -protected void -processEvent(AWTEvent event) -{ - if (event instanceof ActionEvent) - processActionEvent((ActionEvent)event); -} - -/*************************************************************************/ - -/** - * Processes the specified event by dispatching it to any registered listeners. - * - * @param event The event to process. - */ -protected void -processActionEvent(ActionEvent event) -{ - if (action_listeners != null) - { - event.setSource(this); - action_listeners.actionPerformed(event); - } -} - -/*************************************************************************/ - -/** - * Returns a debugging string for this object. - * - * @return A debugging string for this object. - */ -public String -paramString() -{ - return ("label=" + label + ",enabled=" + enabled + - ",actionCommand=" + actionCommand + "," + super.paramString()); -} - -/** - * Gets the AccessibleContext associated with this <code>MenuItem</code>. - * The context is created, if necessary. - * - * @return the associated context - */ -public AccessibleContext getAccessibleContext() -{ - /* Create the context if this is the first request */ - if (accessibleContext == null) - accessibleContext = new AccessibleAWTMenuItem(); - return accessibleContext; -} - -} // class MenuItem diff --git a/libjava/java/awt/MenuShortcut.java b/libjava/java/awt/MenuShortcut.java deleted file mode 100644 index adfd1d3187a..00000000000 --- a/libjava/java/awt/MenuShortcut.java +++ /dev/null @@ -1,207 +0,0 @@ -/* MenuShortcut.java -- A class for menu accelerators - Copyright (C) 1999, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -/** - * This class implements a keyboard accelerator for a menu item. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public class MenuShortcut implements java.io.Serializable -{ - -/* - * Static Variables - */ - -// Serialization Constant -private static final long serialVersionUID = 143448358473180225L; - -/*************************************************************************/ - -/* - * Instance Variables - */ - -/** - * @serial The virtual keycode for the shortcut. - */ -private int key; - -/** - * @serial <code>true</code> if the shift key was used with this shortcut, - * or <code>false</code> otherwise. - */ -private boolean usesShift; - -/*************************************************************************/ - -/** - * Initializes a new instance of <code>MenuShortcut</code> with the - * specified virtual key value. - * - * @param key The virtual keycode for the shortcut. - */ -public -MenuShortcut(int key) -{ - this(key, false); -} - -/*************************************************************************/ - -/** - * Initializes a new instance of <code>MenuShortcut</code> with the - * specified virtual key value and shift setting. - * - * @param key The virtual keycode for the shortcut. - * @param usesShift <code>true</code> if the shift key was pressed, - * <code>false</code> otherwise. - */ -public -MenuShortcut(int key, boolean usesShift) -{ - this.key = key; - this.usesShift = usesShift; -} - -/*************************************************************************/ - -/* - * Instance Methods - */ - -/** - * Returns the virtual keycode for this shortcut. - * - * @return The virtual keycode for this shortcut. - */ -public int -getKey() -{ - return(key); -} - -/*************************************************************************/ - -/** - * Returns the shift setting for this shortcut. - * - * @return <code>true</code> if the shift key was pressed, <code>false</code> - * otherwise. - */ -public boolean -usesShiftModifier() -{ - return(usesShift); -} - -/*************************************************************************/ - -/** - * Tests this object for equality against the specified object. The two - * objects will be considered equal if and only if the specified object - * is an instance of <code>MenuShortcut</code> and has the same key value - * and shift setting as this object. - * - * @param obj The object to test for equality against. - * - * @return <code>true</code> if the two objects are equal, <code>false</code> - * otherwise. - */ -public boolean -equals(MenuShortcut obj) -{ - if (obj == null) - return(false); - - if (obj.key != this.key) - return(false); - - if (obj.usesShift != this.usesShift) - return(false); - - return(true); -} - -public boolean -equals(Object obj) -{ - if (obj instanceof MenuShortcut) - { - MenuShortcut ms = (MenuShortcut) obj; - return (ms.key == key && ms.usesShift == usesShift); - } - return false; -} - -/*************************************************************************/ - -/** - * Returns a string representation of this shortcut. - * - * @return A string representation of this shortcut. - */ -public String -toString() -{ - return(getClass().getName() + "[" + paramString () + "]"); -} - -public int -hashCode() -{ - // Arbitrary. - return key + (usesShift ? 23 : 57); -} - -/*************************************************************************/ - -/** - * Returns a debugging string for this object. - * - * @return A debugging string for this object. - */ -protected String -paramString() -{ - return "key=" + key + ",usesShift=" + usesShift; -} - -} // class MenuShortcut diff --git a/libjava/java/awt/PageAttributes.java b/libjava/java/awt/PageAttributes.java deleted file mode 100644 index 38fb696e339..00000000000 --- a/libjava/java/awt/PageAttributes.java +++ /dev/null @@ -1,482 +0,0 @@ -/* PageAttributes.java -- - Copyright (C) 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.util.Locale; - -/** - * Missing Documentation - * - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.3 - * @status updated to 1.4, but missing documentation - */ -public final class PageAttributes implements Cloneable -{ - public static final class ColorType extends AttributeValue - { - private static final String[] NAMES = { "color", "monochrome" }; - public static final ColorType COLOR = new ColorType(0); - public static final ColorType MONOCHROME = new ColorType(1); - private ColorType(int value) - { - super(value, NAMES); - } - } // class ColorType - public static final class MediaType extends AttributeValue - { - private static final String[] NAMES - = { "iso-4a0", "iso-2a0", "iso-a0", "iso-a1", "iso-a2", "iso-a3", - "iso-a4", "iso-a5", "iso-a6", "iso-a7", "iso-a8", "iso-a9", - "iso-a10", "iso-b0", "iso-b1", "iso-b2", "iso-b3", "iso-b4", - "iso-b5", "iso-b6", "iso-b7", "iso-b8", "iso-b9", "iso-b10", - "jis-b0", "jis-b1", "jis-b2", "jis-b3", "jis-b4", "jis-b5", - "jis-b6", "jis-b7", "jis-b8", "jis-b9", "jis-b10", "iso-c0", - "iso-c1", "iso-c2", "iso-c3", "iso-c4", "iso-c5", "iso-c6", - "iso-c7", "iso-c8", "iso-c9", "iso-c10", "iso-designated-long", - "executive", "folio", "invoice", "ledger", "na-letter", "na-legal", - "quarto", "a", "b", "c", "d", "e", "na-10x15-envelope", - "na-10x14-envelope", "na-10x13-envelope", "na-9x12-envelope", - "na-9x11-envelope", "na-7x9-envelope", "na-6x9-envelope", - "na-number-9-envelope", "na-number-10-envelope", - "na-number-11-envelope", "na-number-12-envelope", - "na-number-14-envelope", "invite-envelope", "italy-envelope", - "monarch-envelope", "personal-envelope" }; - public static final MediaType ISO_4A0 = new MediaType(0); - public static final MediaType ISO_2A0 = new MediaType(1); - public static final MediaType ISO_A0 = new MediaType(2); - public static final MediaType ISO_A1 = new MediaType(3); - public static final MediaType ISO_A2 = new MediaType(4); - public static final MediaType ISO_A3 = new MediaType(5); - public static final MediaType ISO_A4 = new MediaType(6); - public static final MediaType ISO_A5 = new MediaType(7); - public static final MediaType ISO_A6 = new MediaType(8); - public static final MediaType ISO_A7 = new MediaType(9); - public static final MediaType ISO_A8 = new MediaType(10); - public static final MediaType ISO_A9 = new MediaType(11); - public static final MediaType ISO_A10 = new MediaType(12); - public static final MediaType ISO_B0 = new MediaType(13); - public static final MediaType ISO_B1 = new MediaType(14); - public static final MediaType ISO_B2 = new MediaType(15); - public static final MediaType ISO_B3 = new MediaType(16); - public static final MediaType ISO_B4 = new MediaType(17); - public static final MediaType ISO_B5 = new MediaType(18); - public static final MediaType ISO_B6 = new MediaType(19); - public static final MediaType ISO_B7 = new MediaType(20); - public static final MediaType ISO_B8 = new MediaType(21); - public static final MediaType ISO_B9 = new MediaType(22); - public static final MediaType ISO_B10 = new MediaType(23); - public static final MediaType JIS_B0 = new MediaType(24); - public static final MediaType JIS_B1 = new MediaType(25); - public static final MediaType JIS_B2 = new MediaType(26); - public static final MediaType JIS_B3 = new MediaType(27); - public static final MediaType JIS_B4 = new MediaType(28); - public static final MediaType JIS_B5 = new MediaType(29); - public static final MediaType JIS_B6 = new MediaType(30); - public static final MediaType JIS_B7 = new MediaType(31); - public static final MediaType JIS_B8 = new MediaType(32); - public static final MediaType JIS_B9 = new MediaType(33); - public static final MediaType JIS_B10 = new MediaType(34); - public static final MediaType ISO_C0 = new MediaType(35); - public static final MediaType ISO_C1 = new MediaType(36); - public static final MediaType ISO_C2 = new MediaType(37); - public static final MediaType ISO_C3 = new MediaType(38); - public static final MediaType ISO_C4 = new MediaType(39); - public static final MediaType ISO_C5 = new MediaType(40); - public static final MediaType ISO_C6 = new MediaType(41); - public static final MediaType ISO_C7 = new MediaType(42); - public static final MediaType ISO_C8 = new MediaType(43); - public static final MediaType ISO_C9 = new MediaType(44); - public static final MediaType ISO_C10 = new MediaType(45); - public static final MediaType ISO_DESIGNATED_LONG = new MediaType(46); - public static final MediaType EXECUTIVE = new MediaType(47); - public static final MediaType FOLIO = new MediaType(48); - public static final MediaType INVOICE = new MediaType(49); - public static final MediaType LEDGER = new MediaType(50); - public static final MediaType NA_LETTER = new MediaType(51); - public static final MediaType NA_LEGAL = new MediaType(52); - public static final MediaType QUARTO = new MediaType(53); - public static final MediaType A = new MediaType(54); - public static final MediaType B = new MediaType(55); - public static final MediaType C = new MediaType(56); - public static final MediaType D = new MediaType(57); - public static final MediaType E = new MediaType(58); - public static final MediaType NA_10X15_ENVELOPE = new MediaType(59); - public static final MediaType NA_10X14_ENVELOPE = new MediaType(60); - public static final MediaType NA_10X13_ENVELOPE = new MediaType(61); - public static final MediaType NA_9X12_ENVELOPE = new MediaType(62); - public static final MediaType NA_9X11_ENVELOPE = new MediaType(63); - public static final MediaType NA_7X9_ENVELOPE = new MediaType(64); - public static final MediaType NA_6X9_ENVELOPE = new MediaType(65); - public static final MediaType NA_NUMBER_9_ENVELOPE = new MediaType(66); - public static final MediaType NA_NUMBER_10_ENVELOPE = new MediaType(67); - public static final MediaType NA_NUMBER_11_ENVELOPE = new MediaType(68); - public static final MediaType NA_NUMBER_12_ENVELOPE = new MediaType(69); - public static final MediaType NA_NUMBER_14_ENVELOPE = new MediaType(70); - public static final MediaType INVITE_ENVELOPE = new MediaType(71); - public static final MediaType ITALY_ENVELOPE = new MediaType(72); - public static final MediaType MONARCH_ENVELOPE = new MediaType(73); - public static final MediaType PERSONAL_ENVELOPE = new MediaType(74); - public static final MediaType A0 = ISO_A0; - public static final MediaType A1 = ISO_A1; - public static final MediaType A2 = ISO_A2; - public static final MediaType A3 = ISO_A3; - public static final MediaType A4 = ISO_A4; - public static final MediaType A5 = ISO_A5; - public static final MediaType A6 = ISO_A6; - public static final MediaType A7 = ISO_A7; - public static final MediaType A8 = ISO_A8; - public static final MediaType A9 = ISO_A9; - public static final MediaType A10 = ISO_A10; - public static final MediaType B0 = ISO_B0; - public static final MediaType B1 = ISO_B1; - public static final MediaType B2 = ISO_B2; - public static final MediaType B3 = ISO_B3; - public static final MediaType B4 = ISO_B4; - public static final MediaType ISO_B4_ENVELOPE = ISO_B4; - public static final MediaType B5 = ISO_B5; - public static final MediaType ISO_B5_ENVELOPE = ISO_B4; - public static final MediaType B6 = ISO_B6; - public static final MediaType B7 = ISO_B7; - public static final MediaType B8 = ISO_B8; - public static final MediaType B9 = ISO_B9; - public static final MediaType B10 = ISO_B10; - public static final MediaType C0 = ISO_B0; - public static final MediaType ISO_C0_ENVELOPE = ISO_C0; - public static final MediaType C1 = ISO_C1; - public static final MediaType ISO_C1_ENVELOPE = ISO_C1; - public static final MediaType C2 = ISO_C2; - public static final MediaType ISO_C2_ENVELOPE = ISO_C2; - public static final MediaType C3 = ISO_C3; - public static final MediaType ISO_C3_ENVELOPE = ISO_C3; - public static final MediaType C4 = ISO_C4; - public static final MediaType ISO_C4_ENVELOPE = ISO_C4; - public static final MediaType C5 = ISO_C5; - public static final MediaType ISO_C5_ENVELOPE = ISO_C5; - public static final MediaType C6 = ISO_C6; - public static final MediaType ISO_C6_ENVELOPE = ISO_C6; - public static final MediaType C7 = ISO_C7; - public static final MediaType ISO_C7_ENVELOPE = ISO_C7; - public static final MediaType C8 = ISO_C8; - public static final MediaType ISO_C8_ENVELOPE = ISO_C8; - public static final MediaType C9 = ISO_C9; - public static final MediaType ISO_C9_ENVELOPE = ISO_C9; - public static final MediaType C10 = ISO_C10; - public static final MediaType ISO_C10_ENVELOPE = ISO_C10; - public static final MediaType ISO_DESIGNATED_LONG_ENVELOPE - = ISO_DESIGNATED_LONG; - public static final MediaType STATEMENT = INVOICE; - public static final MediaType TABLOID = LEDGER; - public static final MediaType LETTER = NA_LETTER; - public static final MediaType NOTE = NA_LETTER; - public static final MediaType LEGAL = NA_LEGAL; - public static final MediaType ENV_10X15 = NA_10X15_ENVELOPE; - public static final MediaType ENV_10X14 = NA_10X14_ENVELOPE; - public static final MediaType ENV_10X13 = NA_10X13_ENVELOPE; - public static final MediaType ENV_9X12 = NA_9X12_ENVELOPE; - public static final MediaType ENV_9X11 = NA_9X11_ENVELOPE; - public static final MediaType ENV_7X9 = NA_7X9_ENVELOPE; - public static final MediaType ENV_6X9 = NA_6X9_ENVELOPE; - public static final MediaType ENV_9 = NA_NUMBER_9_ENVELOPE; - public static final MediaType ENV_10 = NA_NUMBER_10_ENVELOPE; - public static final MediaType ENV_11 = NA_NUMBER_11_ENVELOPE; - public static final MediaType ENV_12 = NA_NUMBER_12_ENVELOPE; - public static final MediaType ENV_14 = NA_NUMBER_14_ENVELOPE; - public static final MediaType ENV_INVITE = INVITE_ENVELOPE; - public static final MediaType ENV_ITALY = ITALY_ENVELOPE; - public static final MediaType ENV_MONARCH = MONARCH_ENVELOPE; - public static final MediaType ENV_PERSONAL = PERSONAL_ENVELOPE; - public static final MediaType INVITE = INVITE_ENVELOPE; - public static final MediaType ITALY = ITALY_ENVELOPE; - public static final MediaType MONARCH = MONARCH_ENVELOPE; - public static final MediaType PERSONAL = PERSONAL_ENVELOPE; - private MediaType(int value) - { - super(value, NAMES); - } - } // class MediaType - public static final class OrientationRequestedType extends AttributeValue - { - private static final String[] NAMES = { "portrait", "landscape" }; - public static final OrientationRequestedType PORTRAIT - = new OrientationRequestedType(0); - public static final OrientationRequestedType LANDSCAPE - = new OrientationRequestedType(1); - private OrientationRequestedType(int value) - { - super(value, NAMES); - } - } // class OrientationRequestedType - public static final class OriginType extends AttributeValue - { - private static final String[] NAMES = { "physical", "printable" }; - public static final OriginType PHYSICAL = new OriginType(0); - public static final OriginType PRINTABLE = new OriginType(1); - private OriginType(int value) - { - super(value, NAMES); - } - } // class OriginType - public static final class PrintQualityType extends AttributeValue - { - private static final String[] NAMES = { "high", "normal", "draft" }; - public static final PrintQualityType HIGH = new PrintQualityType(0); - public static final PrintQualityType NORMAL = new PrintQualityType(1); - public static final PrintQualityType DRAFT = new PrintQualityType(2); - private PrintQualityType(int value) - { - super(value, NAMES); - } - } // class PrintQualityType - - - private ColorType color; - private MediaType media; - private OrientationRequestedType orientation; - private OriginType origin; - private PrintQualityType quality; - private int resolutionX; - private int resolutionY; - private int resolutionScale; - public PageAttributes() - { - color = ColorType.MONOCHROME; - setMediaToDefault(); - orientation = OrientationRequestedType.PORTRAIT; - origin = OriginType.PHYSICAL; - quality = PrintQualityType.NORMAL; - setPrinterResolutionToDefault(); - } - - public PageAttributes(PageAttributes attr) - { - set(attr); - } - - public PageAttributes(ColorType color, MediaType media, - OrientationRequestedType orientation, - OriginType origin, PrintQualityType quality, - int[] resolution) - { - if (color == null || media == null || orientation == null - || origin == null || quality == null) - throw new IllegalArgumentException(); - setPrinterResolution(resolution); - this.color = color; - this.media = media; - this.orientation = orientation; - this.origin = origin; - this.quality = quality; - } - - public Object clone() - { - return new PageAttributes(this); - } - - public void set(PageAttributes attr) - { - color = attr.color; - media = attr.media; - orientation = attr.orientation; - origin = attr.origin; - quality = attr.quality; - resolutionX = attr.resolutionX; - resolutionY = attr.resolutionY; - resolutionScale = attr.resolutionScale; - } - - public ColorType getColor() - { - return color; - } - - public void setColor(ColorType color) - { - if (color == null) - throw new IllegalArgumentException(); - this.color = color; - } - - public MediaType getMedia() - { - return media; - } - - public void setMedia(MediaType media) - { - if (media == null) - throw new IllegalArgumentException(); - this.media = media; - } - - public void setMediaToDefault() - { - String country = Locale.getDefault().getCountry(); - media = ("US".equals(country) || "CA".equals(country)) ? MediaType.LETTER - : MediaType.A4; - } - - public OrientationRequestedType getOrientationRequested() - { - return orientation; - } - - public void setOrientationRequested(OrientationRequestedType orientation) - { - if (orientation == null) - throw new IllegalArgumentException(); - this.orientation = orientation; - } - - public void setOrientationRequested(int orientation) - { - if (orientation == 3) - this.orientation = OrientationRequestedType.PORTRAIT; - else if (orientation == 4) - this.orientation = OrientationRequestedType.LANDSCAPE; - else - throw new IllegalArgumentException(); - } - - public void setOrientationRequestedToDefault() - { - orientation = OrientationRequestedType.PORTRAIT; - } - - public OriginType getOrigin() - { - return origin; - } - - public void setOrigin(OriginType origin) - { - if (origin == null) - throw new IllegalArgumentException(); - this.origin = origin; - } - - public PrintQualityType getPrintQuality() - { - return quality; - } - - public void setPrintQuality(PrintQualityType quality) - { - if (quality == null) - throw new IllegalArgumentException(); - this.quality = quality; - } - - public void setPrintQuality(int quality) - { - if (quality == 3) - this.quality = PrintQualityType.DRAFT; - else if (quality == 4) - this.quality = PrintQualityType.NORMAL; - else if (quality == 5) - this.quality = PrintQualityType.HIGH; - else - throw new IllegalArgumentException(); - } - - public void setPrintQualityToDefault() - { - quality = PrintQualityType.NORMAL; - } - - public int[] getPrinterResolution() - { - return new int[] { resolutionX, resolutionY, resolutionScale }; - } - - public void setPrinterResolution(int[] resolution) - { - if (resolution == null || resolution.length != 3 || resolution[0] <= 0 - || resolution[1] <= 0 || resolution[2] < 3 || resolution[2] > 4) - throw new IllegalArgumentException(); - resolutionX = resolution[0]; - resolutionY = resolution[1]; - resolutionScale = resolution[2]; - } - - public void setPrinterResolution(int resolution) - { - if (resolution <= 0) - throw new IllegalArgumentException(); - resolutionX = resolution; - resolutionY = resolution; - resolutionScale = 3; - } - - public void setPrinterResolutionToDefault() - { - resolutionX = 72; - resolutionY = 72; - resolutionScale = 3; - } - - public boolean equals(Object o) - { - if (this == o) - return true; - if (! (o instanceof PageAttributes)) - return false; - PageAttributes pa = (PageAttributes) o; - return color == pa.color && media == pa.media - && orientation == pa.orientation && origin == pa.origin - && quality == pa.quality && resolutionX == pa.resolutionX - && resolutionY == pa.resolutionY - && resolutionScale == pa.resolutionScale; - } - public int hashCode() - { - return (color.value << 31) ^ (media.value << 24) - ^ (orientation.value << 23) ^ (origin.value << 22) - ^ (quality.value << 20) ^ (resolutionScale << 19) - ^ (resolutionY << 10) ^ resolutionX; - } - public String toString() - { - return "color=" + color + ",media=" + media + ",orientation-requested=" - + orientation + ",origin=" + origin + ",print-quality=" + quality - + ",printer-resolution=[" + resolutionX + ',' + resolutionY + ',' - + resolutionScale + ']'; - } -} // class PageAttributes diff --git a/libjava/java/awt/Paint.java b/libjava/java/awt/Paint.java deleted file mode 100644 index 0f099cc0b80..00000000000 --- a/libjava/java/awt/Paint.java +++ /dev/null @@ -1,79 +0,0 @@ -/* Paint.java -- generate colors for Graphics2D operations - Copyright (C) 2000, 2002 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.awt.geom.AffineTransform; -import java.awt.geom.Rectangle2D; -import java.awt.image.ColorModel; - -/** - * Defines how color patterns are generated for Graphics2D operations. This - * is used to perform the <code>draw</code> and <code>fill</code> methods - * of the graphics object. Instances must be immutable, because the graphics - * object does not clone them. - * - * @author Warren Levy (warrenl@cygnus.com) - * @see PaintContext - * @see Color - * @see GradientPaint - * @see TexturePaint - * @see Graphics2D#setPaint(Paint) - * @since 1.1 - * @status updated to 1.4 - */ -public interface Paint extends Transparency -{ - /** - * Create the context necessary for performing the color pattern generation. - * The color model is a hint, and may be null for Classpath implementations; - * however some legacy code may throw a NullPointerException when passed a - * null. Leaving the color model null provides the most efficiency and leeway - * in the generation of the color pattern. - * - * @param cm the color model, used as a hint - * @param deviceBounds the device space bounding box of the painted area - * @param userBounds the user space bounding box of the painted area - * @param xform the transformation from user space to device space - * @param hints any hints for choosing between rendering alternatives - * @return the context for performing the paint - */ - PaintContext createContext(ColorModel cm, Rectangle deviceBounds, - Rectangle2D userBounds, AffineTransform xform, - RenderingHints hints); -} // interface Paint diff --git a/libjava/java/awt/PaintContext.java b/libjava/java/awt/PaintContext.java deleted file mode 100644 index 3d5fdcdf0e4..00000000000 --- a/libjava/java/awt/PaintContext.java +++ /dev/null @@ -1,76 +0,0 @@ -/* PaintContext.java -- the environment for performing a paint operation - Copyright (C) 2000, 2002 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.awt.image.ColorModel; -import java.awt.image.Raster; - -/** - * @author Warren Levy (warrenl@cygnus.com) - * @see Paint - * @since 1.1 - * @status updated to 1.4 - */ -public interface PaintContext -{ - /** - * Release the resources allocated for the paint. - */ - void dispose(); - - /** - * Return the color model of this context. It may be different from the - * hint specified during createContext, as not all contexts can generate - * color patterns in an arbitrary model. - * - * @return the context color model - */ - ColorModel getColorModel(); - - /** - * Return a raster containing the colors for the graphics operation. - * - * @param x the x-coordinate, in device space - * @param y the y-coordinate, in device space - * @param w the width, in device space - * @param h the height, in device space - * @return a raster for the given area and color - */ - Raster getRaster(int x, int y, int w, int h); -} // interface PaintContext diff --git a/libjava/java/awt/Panel.java b/libjava/java/awt/Panel.java deleted file mode 100644 index cc17eef2285..00000000000 --- a/libjava/java/awt/Panel.java +++ /dev/null @@ -1,173 +0,0 @@ -/* Panel.java -- Simple container object - Copyright (C) 1999, 2002, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import javax.accessibility.Accessible; -import javax.accessibility.AccessibleContext; -import javax.accessibility.AccessibleRole; - -/** - * A panel is a simple container class. It's default layout is the - * <code>FlowLayout</code> manager. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Eric Blake (ebb9@email.byu.edu) - * @see FlowLayout - * @since 1.0 - * @status updated to 1.4 - */ -public class Panel extends Container implements Accessible -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = -2728009084054400034L; - - /** The cached accessible context. */ - private transient AccessibleContext context; - - /** Flag set when the first system-requested paint event is - dispatched. */ - private transient boolean initialSystemUpdateDone; - - /** Flag set when the first application-requested paint event is - consumed. */ - private transient boolean initialUpdateConsumed; - - /* - * The number used to generate the name returned by getName. - */ - private static transient long next_panel_number; - - /** - * Initializes a new instance of <code>Panel</code> that has a default - * layout manager of <code>FlowLayout</code>. - */ - public Panel() - { - this(new FlowLayout()); - } - - /** - * Initializes a new instance of <code>Panel</code> with the specified - * layout manager. - * - * @param layoutManager the layout manager for this object - * @since 1.1 - */ - public Panel(LayoutManager layoutManager) - { - setLayout(layoutManager); - } - - /** - * Notifies this object to create its native peer. - * - * @see #isDisplayable() - * @see #removeNotify() - */ - public void addNotify() - { - if (peer == null) - peer = getToolkit().createPanel(this); - super.addNotify(); - } - - /** - * Gets the AccessibleContext associated with this panel, creating one if - * necessary. This always returns an instance of {@link AccessibleAWTPanel}. - * - * @return the accessibility context of this panel - * @since 1.3 - */ - public AccessibleContext getAccessibleContext() - { - if (context == null) - context = new AccessibleAWTPanel(); - return context; - } - - /** - * This class provides accessibility support for Panels, and is the - * runtime type returned by {@link #getAccessibleContext()}. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.3 - */ - protected class AccessibleAWTPanel extends AccessibleAWTContainer - { - /** - * Compatible with JDK 1.4+. - */ - private static final long serialVersionUID = -6409552226660031050L; - - /** - * The default constructor. - */ - protected AccessibleAWTPanel() - { - } - - /** - * Get the role of this accessible object, a panel. - * - * @return the role of the object - * @see AccessibleRole#PANEL - */ - public AccessibleRole getAccessibleRole() - { - return AccessibleRole.PANEL; - } - } - - /** - * Generate a unique name for this panel. - * - * @return A unique name for this panel. - */ - String generateName () - { - return "panel" + getUniqueLong (); - } - - private static synchronized long getUniqueLong () - { - return next_panel_number++; - } -} diff --git a/libjava/java/awt/Point.java b/libjava/java/awt/Point.java deleted file mode 100644 index 492749b8dc3..00000000000 --- a/libjava/java/awt/Point.java +++ /dev/null @@ -1,245 +0,0 @@ -/* Point.java -- represents a point in 2-D space - Copyright (C) 1999, 2002 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.awt.geom.Point2D; -import java.io.Serializable; - -/** - * This class represents a point on the screen using cartesian coordinates. - * Remember that in screen coordinates, increasing x values go from left to - * right, and increasing y values go from top to bottom. - * - * <p>There are some public fields; if you mess with them in an inconsistent - * manner, it is your own fault when you get invalid results. Also, this - * class is not threadsafe. - * - * @author Per Bothner (bothner@cygnus.com) - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.0 - * @status updated to 1.4 - */ -public class Point extends Point2D implements Serializable -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = -5276940640259749850L; - - /** - * The x coordinate. - * - * @see #getLocation() - * @see #move(int, int) - * @serial the X coordinate of the point - */ - public int x; - - /** - * The y coordinate. - * - * @see #getLocation() - * @see #move(int, int) - * @serial The Y coordinate of the point - */ - public int y; - - /** - * Initializes a new instance of <code>Point</code> representing the - * coordiates (0,0). - * - * @since 1.1 - */ - public Point() - { - } - - /** - * Initializes a new instance of <code>Point</code> with coordinates - * identical to the coordinates of the specified points. - * - * @param p the point to copy the coordinates from - * @throws NullPointerException if p is null - */ - public Point(Point p) - { - x = p.x; - y = p.y; - } - - /** - * Initializes a new instance of <code>Point</code> with the specified - * coordinates. - * - * @param x the X coordinate - * @param y the Y coordinate - */ - public Point(int x, int y) - { - this.x = x; - this.y = y; - } - - /** - * Get the x coordinate. - * - * @return the value of x, as a double - */ - public double getX() - { - return x; - } - - /** - * Get the y coordinate. - * - * @return the value of y, as a double - */ - public double getY() - { - return y; - } - - /** - * Returns the location of this point. A pretty useless method, as this - * is already a point. - * - * @return a copy of this point - * @see #setLocation(Point) - * @since 1.1 - */ - public Point getLocation() - { - return new Point(x, y); - } - - /** - * Sets this object's coordinates to match those of the specified point. - * - * @param p the point to copy the coordinates from - * @throws NullPointerException if p is null - * @since 1.1 - */ - public void setLocation(Point p) - { - x = p.x; - y = p.y; - } - - /** - * Sets this object's coordinates to the specified values. This method - * is identical to the <code>move()</code> method. - * - * @param x the new X coordinate - * @param y the new Y coordinate - */ - public void setLocation(int x, int y) - { - this.x = x; - this.y = y; - } - - /** - * Sets this object's coordinates to the specified values. This method - * performs normal casting from double to int, so you may lose precision. - * - * @param x the new X coordinate - * @param y the new Y coordinate - */ - public void setLocation(double x, double y) - { - this.x = (int) x; - this.y = (int) y; - } - - /** - * Sets this object's coordinates to the specified values. This method - * is identical to the <code>setLocation(int, int)</code> method. - * - * @param x the new X coordinate - * @param y the new Y coordinate - */ - public void move(int x, int y) - { - this.x = x; - this.y = y; - } - - /** - * Changes the coordinates of this point such that the specified - * <code>dx</code> parameter is added to the existing X coordinate and - * <code>dy</code> is added to the existing Y coordinate. - * - * @param dx the amount to add to the X coordinate - * @param dy the amount to add to the Y coordinate - */ - public void translate(int dx, int dy) - { - x += dx; - y += dy; - } - - /** - * Tests whether or not this object is equal to the specified object. - * This will be true if and only if the specified object is an instance - * of Point2D and has the same X and Y coordinates. - * - * @param obj the object to test against for equality - * @return true if the specified object is equal - */ - public boolean equals(Object obj) - { - if (! (obj instanceof Point2D)) - return false; - Point2D p = (Point2D) obj; - return x == p.getX() && y == p.getY(); - } - - /** - * Returns a string representation of this object. The format is: - * <code>getClass().getName() + "[x=" + x + ",y=" + y + ']'</code>. - * - * @return a string representation of this object - */ - public String toString() - { - return getClass().getName() + "[x=" + x + ",y=" + y + ']'; - } -} // class Point diff --git a/libjava/java/awt/Polygon.java b/libjava/java/awt/Polygon.java deleted file mode 100644 index a72522cb089..00000000000 --- a/libjava/java/awt/Polygon.java +++ /dev/null @@ -1,613 +0,0 @@ -/* Polygon.java -- class representing a polygon - Copyright (C) 1999, 2002, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.awt.geom.AffineTransform; -import java.awt.geom.Line2D; -import java.awt.geom.PathIterator; -import java.awt.geom.Point2D; -import java.awt.geom.Rectangle2D; -import java.io.Serializable; - -/** - * This class represents a polygon, a closed, two-dimensional region in a - * coordinate space. The region is bounded by an arbitrary number of line - * segments, between (x,y) coordinate vertices. The polygon has even-odd - * winding, meaning that a point is inside the shape if it crosses the - * boundary an odd number of times on the way to infinity. - * - * <p>There are some public fields; if you mess with them in an inconsistent - * manner, it is your own fault when you get NullPointerException, - * ArrayIndexOutOfBoundsException, or invalid results. Also, this class is - * not threadsafe. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.0 - * @status updated to 1.4 - */ -public class Polygon implements Shape, Serializable -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = -6460061437900069969L; - - /** - * This total number of endpoints. - * - * @serial the number of endpoints, possibly less than the array sizes - */ - public int npoints; - - /** - * The array of X coordinates of endpoints. This should not be null. - * - * @see #addPoint(int, int) - * @serial the x coordinates - */ - public int[] xpoints; - - /** - * The array of Y coordinates of endpoints. This should not be null. - * - * @see #addPoint(int, int) - * @serial the y coordinates - */ - public int[] ypoints; - - /** - * The bounding box of this polygon. This is lazily created and cached, so - * it must be invalidated after changing points. - * - * @see #getBounds() - * @serial the bounding box, or null - */ - protected Rectangle bounds; - - /** A big number, but not so big it can't survive a few float operations */ - private static final double BIG_VALUE = java.lang.Double.MAX_VALUE / 10.0; - - /** - * Initializes an empty polygon. - */ - public Polygon() - { - // Leave room for growth. - xpoints = new int[4]; - ypoints = new int[4]; - } - - /** - * Create a new polygon with the specified endpoints. The arrays are copied, - * so that future modifications to the parameters do not affect the polygon. - * - * @param xpoints the array of X coordinates for this polygon - * @param ypoints the array of Y coordinates for this polygon - * @param npoints the total number of endpoints in this polygon - * @throws NegativeArraySizeException if npoints is negative - * @throws IndexOutOfBoundsException if npoints exceeds either array - * @throws NullPointerException if xpoints or ypoints is null - */ - public Polygon(int[] xpoints, int[] ypoints, int npoints) - { - this.xpoints = new int[npoints]; - this.ypoints = new int[npoints]; - System.arraycopy(xpoints, 0, this.xpoints, 0, npoints); - System.arraycopy(ypoints, 0, this.ypoints, 0, npoints); - this.npoints = npoints; - } - - /** - * Reset the polygon to be empty. The arrays are left alone, to avoid object - * allocation, but the number of points is set to 0, and all cached data - * is discarded. If you are discarding a huge number of points, it may be - * more efficient to just create a new Polygon. - * - * @see #invalidate() - * @since 1.4 - */ - public void reset() - { - npoints = 0; - invalidate(); - } - - /** - * Invalidate or flush all cached data. After direct manipulation of the - * public member fields, this is necessary to avoid inconsistent results - * in methods like <code>contains</code>. - * - * @see #getBounds() - * @since 1.4 - */ - public void invalidate() - { - bounds = null; - } - - /** - * Translates the polygon by adding the specified values to all X and Y - * coordinates. This updates the bounding box, if it has been calculated. - * - * @param dx the amount to add to all X coordinates - * @param dy the amount to add to all Y coordinates - * @since 1.1 - */ - public void translate(int dx, int dy) - { - int i = npoints; - while (--i >= 0) - { - xpoints[i] += dx; - ypoints[i] += dy; - } - if (bounds != null) - { - bounds.x += dx; - bounds.y += dy; - } - } - - /** - * Adds the specified endpoint to the polygon. This updates the bounding - * box, if it has been created. - * - * @param x the X coordinate of the point to add - * @param y the Y coordiante of the point to add - */ - public void addPoint(int x, int y) - { - if (npoints + 1 > xpoints.length) - { - int[] newx = new int[npoints + 1]; - System.arraycopy(xpoints, 0, newx, 0, npoints); - xpoints = newx; - } - if (npoints + 1 > ypoints.length) - { - int[] newy = new int[npoints + 1]; - System.arraycopy(ypoints, 0, newy, 0, npoints); - ypoints = newy; - } - xpoints[npoints] = x; - ypoints[npoints] = y; - npoints++; - if (bounds != null) - { - if (npoints == 1) - { - bounds.x = x; - bounds.y = y; - } - else - { - if (x < bounds.x) - { - bounds.width += bounds.x - x; - bounds.x = x; - } - else if (x > bounds.x + bounds.width) - bounds.width = x - bounds.x; - if (y < bounds.y) - { - bounds.height += bounds.y - y; - bounds.y = y; - } - else if (y > bounds.y + bounds.height) - bounds.height = y - bounds.y; - } - } - } - - /** - * Returns the bounding box of this polygon. This is the smallest - * rectangle with sides parallel to the X axis that will contain this - * polygon. - * - * @return the bounding box for this polygon - * @see #getBounds2D() - * @since 1.1 - */ - public Rectangle getBounds() - { - return getBoundingBox(); - } - - /** - * Returns the bounding box of this polygon. This is the smallest - * rectangle with sides parallel to the X axis that will contain this - * polygon. - * - * @return the bounding box for this polygon - * @see #getBounds2D() - * @deprecated use {@link #getBounds()} instead - */ - public Rectangle getBoundingBox() - { - if (bounds == null) - { - if (npoints == 0) - return bounds = new Rectangle(); - int i = npoints - 1; - int minx = xpoints[i]; - int maxx = minx; - int miny = ypoints[i]; - int maxy = miny; - while (--i >= 0) - { - int x = xpoints[i]; - int y = ypoints[i]; - if (x < minx) - minx = x; - else if (x > maxx) - maxx = x; - if (y < miny) - miny = y; - else if (y > maxy) - maxy = y; - } - bounds = new Rectangle(minx, miny, maxx - minx, maxy - miny); - } - return bounds; - } - - /** - * Tests whether or not the specified point is inside this polygon. - * - * @param p the point to test - * @return true if the point is inside this polygon - * @throws NullPointerException if p is null - * @see #contains(double, double) - */ - public boolean contains(Point p) - { - return contains(p.getX(), p.getY()); - } - - /** - * Tests whether or not the specified point is inside this polygon. - * - * @param x the X coordinate of the point to test - * @param y the Y coordinate of the point to test - * @return true if the point is inside this polygon - * @see #contains(double, double) - * @since 1.1 - */ - public boolean contains(int x, int y) - { - return contains((double) x, (double) y); - } - - /** - * Tests whether or not the specified point is inside this polygon. - * - * @param x the X coordinate of the point to test - * @param y the Y coordinate of the point to test - * @return true if the point is inside this polygon - * @see #contains(double, double) - * @deprecated use {@link #contains(int, int)} instead - */ - public boolean inside(int x, int y) - { - return contains((double) x, (double) y); - } - - /** - * Returns a high-precision bounding box of this polygon. This is the - * smallest rectangle with sides parallel to the X axis that will contain - * this polygon. - * - * @return the bounding box for this polygon - * @see #getBounds() - * @since 1.2 - */ - public Rectangle2D getBounds2D() - { - // For polygons, the integer version is exact! - return getBounds(); - } - - /** - * Tests whether or not the specified point is inside this polygon. - * - * @param x the X coordinate of the point to test - * @param y the Y coordinate of the point to test - * @return true if the point is inside this polygon - * @since 1.2 - */ - public boolean contains(double x, double y) - { - return ((evaluateCrossings(x, y, false, BIG_VALUE) & 1) != 0); - } - - /** - * Tests whether or not the specified point is inside this polygon. - * - * @param p the point to test - * @return true if the point is inside this polygon - * @throws NullPointerException if p is null - * @see #contains(double, double) - * @since 1.2 - */ - public boolean contains(Point2D p) - { - return contains(p.getX(), p.getY()); - } - - /** - * Test if a high-precision rectangle intersects the shape. This is true - * if any point in the rectangle is in the shape. This implementation is - * precise. - * - * @param x the x coordinate of the rectangle - * @param y the y coordinate of the rectangle - * @param w the width of the rectangle, treated as point if negative - * @param h the height of the rectangle, treated as point if negative - * @return true if the rectangle intersects this shape - * @since 1.2 - */ - public boolean intersects(double x, double y, double w, double h) - { - /* Does any edge intersect? */ - if (evaluateCrossings(x, y, false, w) != 0 /* top */ - || evaluateCrossings(x, y + h, false, w) != 0 /* bottom */ - || evaluateCrossings(x + w, y, true, h) != 0 /* right */ - || evaluateCrossings(x, y, true, h) != 0) /* left */ - return true; - - /* No intersections, is any point inside? */ - if ((evaluateCrossings(x, y, false, BIG_VALUE) & 1) != 0) - return true; - - return false; - } - - /** - * Test if a high-precision rectangle intersects the shape. This is true - * if any point in the rectangle is in the shape. This implementation is - * precise. - * - * @param r the rectangle - * @return true if the rectangle intersects this shape - * @throws NullPointerException if r is null - * @see #intersects(double, double, double, double) - * @since 1.2 - */ - public boolean intersects(Rectangle2D r) - { - return intersects(r.getX(), r.getY(), r.getWidth(), r.getHeight()); - } - - /** - * Test if a high-precision rectangle lies completely in the shape. This is - * true if all points in the rectangle are in the shape. This implementation - * is precise. - * - * @param x the x coordinate of the rectangle - * @param y the y coordinate of the rectangle - * @param w the width of the rectangle, treated as point if negative - * @param h the height of the rectangle, treated as point if negative - * @return true if the rectangle is contained in this shape - * @since 1.2 - */ - public boolean contains(double x, double y, double w, double h) - { - if (! getBounds2D().intersects(x, y, w, h)) - return false; - - /* Does any edge intersect? */ - if (evaluateCrossings(x, y, false, w) != 0 /* top */ - || evaluateCrossings(x, y + h, false, w) != 0 /* bottom */ - || evaluateCrossings(x + w, y, true, h) != 0 /* right */ - || evaluateCrossings(x, y, true, h) != 0) /* left */ - return false; - - /* No intersections, is any point inside? */ - if ((evaluateCrossings(x, y, false, BIG_VALUE) & 1) != 0) - return true; - - return false; - } - - /** - * Test if a high-precision rectangle lies completely in the shape. This is - * true if all points in the rectangle are in the shape. This implementation - * is precise. - * - * @param r the rectangle - * @return true if the rectangle is contained in this shape - * @throws NullPointerException if r is null - * @see #contains(double, double, double, double) - * @since 1.2 - */ - public boolean contains(Rectangle2D r) - { - return contains(r.getX(), r.getY(), r.getWidth(), r.getHeight()); - } - - /** - * Return an iterator along the shape boundary. If the optional transform - * is provided, the iterator is transformed accordingly. Each call returns - * a new object, independent from others in use. This class is not - * threadsafe to begin with, so the path iterator is not either. - * - * @param transform an optional transform to apply to the iterator - * @return a new iterator over the boundary - * @since 1.2 - */ - public PathIterator getPathIterator(final AffineTransform transform) - { - return new PathIterator() - { - /** The current vertex of iteration. */ - private int vertex; - - public int getWindingRule() - { - return WIND_EVEN_ODD; - } - - public boolean isDone() - { - return vertex > npoints; - } - - public void next() - { - vertex++; - } - - public int currentSegment(float[] coords) - { - if (vertex >= npoints) - return SEG_CLOSE; - coords[0] = xpoints[vertex]; - coords[1] = ypoints[vertex]; - if (transform != null) - transform.transform(coords, 0, coords, 0, 1); - return vertex == 0 ? SEG_MOVETO : SEG_LINETO; - } - - public int currentSegment(double[] coords) - { - if (vertex >= npoints) - return SEG_CLOSE; - coords[0] = xpoints[vertex]; - coords[1] = ypoints[vertex]; - if (transform != null) - transform.transform(coords, 0, coords, 0, 1); - return vertex == 0 ? SEG_MOVETO : SEG_LINETO; - } - }; - } - - /** - * Return an iterator along the flattened version of the shape boundary. - * Since polygons are already flat, the flatness parameter is ignored, and - * the resulting iterator only has SEG_MOVETO, SEG_LINETO and SEG_CLOSE - * points. If the optional transform is provided, the iterator is - * transformed accordingly. Each call returns a new object, independent - * from others in use. This class is not threadsafe to begin with, so the - * path iterator is not either. - * - * @param transform an optional transform to apply to the iterator - * @param flatness the maximum distance for deviation from the real boundary - * @return a new iterator over the boundary - * @since 1.2 - */ - public PathIterator getPathIterator(AffineTransform transform, - double flatness) - { - return getPathIterator(transform); - } - - /** - * Helper for contains, intersects, calculates the number of intersections - * between the polygon and a line extending from the point (x, y) along - * the positive X, or Y axis, within a given interval. - * - * @return the winding number. - * @see #condensed - * @see #contains(double, double) - */ - private int evaluateCrossings(double x, double y, boolean useYaxis, - double distance) - { - double x0; - double x1; - double y0; - double y1; - double epsilon = 0.0; - int crossings = 0; - int[] xp; - int[] yp; - - if (useYaxis) - { - xp = ypoints; - yp = xpoints; - double swap; - swap = y; - y = x; - x = swap; - } - else - { - xp = xpoints; - yp = ypoints; - } - - /* Get a value which is small but not insignificant relative the path. */ - epsilon = 1E-7; - - x0 = xp[0] - x; - y0 = yp[0] - y; - for (int i = 1; i < npoints; i++) - { - x1 = xp[i] - x; - y1 = yp[i] - y; - - if (y0 == 0.0) - y0 -= epsilon; - if (y1 == 0.0) - y1 -= epsilon; - if (y0 * y1 < 0) - if (Line2D.linesIntersect(x0, y0, x1, y1, epsilon, 0.0, distance, 0.0)) - ++crossings; - - x0 = xp[i] - x; - y0 = yp[i] - y; - } - - // end segment - x1 = xp[0] - x; - y1 = yp[0] - y; - if (y0 == 0.0) - y0 -= epsilon; - if (y1 == 0.0) - y1 -= epsilon; - if (y0 * y1 < 0) - if (Line2D.linesIntersect(x0, y0, x1, y1, epsilon, 0.0, distance, 0.0)) - ++crossings; - - return crossings; - } -} // class Polygon - diff --git a/libjava/java/awt/PopupMenu.java b/libjava/java/awt/PopupMenu.java deleted file mode 100644 index 90d48d903b9..00000000000 --- a/libjava/java/awt/PopupMenu.java +++ /dev/null @@ -1,169 +0,0 @@ -/* PopupMenu.java -- An AWT popup menu - Copyright (C) 1999, 2000, 2001, 2002, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.awt.peer.PopupMenuPeer; - -import javax.accessibility.AccessibleContext; -import javax.accessibility.AccessibleRole; - -/** - * This class implement an AWT popup menu widget - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public class PopupMenu extends Menu -{ - -/* - * Static Variables - */ - -// Serialization Constant -private static final long serialVersionUID = -4620452533522760060L; - -/*************************************************************************/ - -/* - * Constructors - */ - -/** - * Initializes a new instance of <code>PopupMenu</code>. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() - * returns true. - */ -public -PopupMenu() -{ -} - -/*************************************************************************/ - -/** - * Initializes a new instance of <code>PopupMenu</code> with the specified - * label. - * - * @param label The label for this popup menu. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() - * returns true. - */ -public -PopupMenu(String label) -{ - super(label); - - if (GraphicsEnvironment.isHeadless()) - throw new HeadlessException (); -} - -/*************************************************************************/ - -/* - * Instance Methods - */ - -/** - * Creates this object's native peer. - */ -public void -addNotify() -{ - if (peer == null) - peer = getToolkit ().createPopupMenu (this); - super.addNotify (); -} - -/*************************************************************************/ - -/** - * Displays this popup menu at the specified coordinates relative to - * the specified component. - * - * @param component The component to which the display coordinates are relative. - * @param x The X coordinate of the menu. - * @param y The Y coordinate of the menu. - */ -public void -show(Component component, int x, int y) -{ - if (getPeer() == null) - this.addNotify(); - PopupMenuPeer pmp = (PopupMenuPeer)getPeer(); - if (pmp != null) - { - /* XXX - Event e = new Event (component, Event.ACTION_EVENT, component); - e.x = x; - e.y = y;*/ - pmp.show (component, x, y); - } -} - - protected class AccessibleAWTPopupMenu extends AccessibleAWTMenu - { - protected AccessibleAWTPopupMenu() - { - } - - public AccessibleRole getAccessibleRole() - { - return AccessibleRole.POPUP_MENU; - } - - } - - /** - * Gets the AccessibleContext associated with this <code>PopupMenu</code>. - * The context is created, if necessary. - * - * @return the associated context - */ - public AccessibleContext getAccessibleContext() - { - /* Create the context if this is the first request */ - if (accessibleContext == null) - accessibleContext = new AccessibleAWTPopupMenu(); - return accessibleContext; - } - -} // class PopupMenu - diff --git a/libjava/java/awt/PrintGraphics.java b/libjava/java/awt/PrintGraphics.java deleted file mode 100644 index e7f857797d3..00000000000 --- a/libjava/java/awt/PrintGraphics.java +++ /dev/null @@ -1,57 +0,0 @@ -/* PrintGraphics.java -- a print graphics context - Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -/** - * This interface allows the originating print job to be obtained. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @since 1.0 - * @status updated to 1.4 - */ -public interface PrintGraphics -{ - /** - * Returns the <code>PrintJob</code> that this object is being - * managed by. - * - * @return the print job for this object - */ - PrintJob getPrintJob(); -} // interface PrintGraphics diff --git a/libjava/java/awt/PrintJob.java b/libjava/java/awt/PrintJob.java deleted file mode 100644 index 09b85acceac..00000000000 --- a/libjava/java/awt/PrintJob.java +++ /dev/null @@ -1,102 +0,0 @@ -/* PrintJob.java -- A print job class - Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -/** - * This abstract class represents a print job. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @see Toolkit#getPrintJob(Frame, String, Properties) - * @since 1.0 - * @status updated to 1.4 - */ -public abstract class PrintJob -{ - /** - * Create a new PrintJob. - */ - public PrintJob() - { - } - - /** - * Returns a graphics context suitable for rendering the next page. The - * return must also implement {@link PrintGraphics}. - * - * @return a graphics context for printing the next page - */ - public abstract Graphics getGraphics(); - - /** - * Returns the dimension of the page in pixels. The resolution will be - * chosen to be similar to the on screen image. - * - * @return the page dimensions - */ - public abstract Dimension getPageDimension(); - - /** - * Returns the resolution of the page in pixels per inch. Note that this is - * not necessarily the printer's resolution. - * - * @return the resolution of the page in pixels per inch - */ - public abstract int getPageResolution(); - - /** - * Tests whether or not the last page will be printed first. - * - * @return true if the last page prints first - */ - public abstract boolean lastPageFirst(); - - /** - * Informs the print job that printing is complete or should be aborted. - */ - public abstract void end(); - - /** - * This method explicitly ends the print job in the event the job - * becomes un-referenced without the application having done so. - */ - public void finalize() - { - end(); - } -} // class PrintJob diff --git a/libjava/java/awt/Rectangle.java b/libjava/java/awt/Rectangle.java deleted file mode 100644 index 0f21d495cd8..00000000000 --- a/libjava/java/awt/Rectangle.java +++ /dev/null @@ -1,749 +0,0 @@ -/* Rectangle.java -- represents a graphics rectangle - Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.awt.geom.Rectangle2D; -import java.io.Serializable; - -/** - * This class represents a rectangle and all the interesting things you - * might want to do with it. Note that the coordinate system uses - * the origin (0,0) as the top left of the screen, with the x and y - * values increasing as they move to the right and down respectively. - * - * <p>It is valid for a rectangle to have negative width or height; but it - * is considered to have no area or internal points. Therefore, the behavior - * in methods like <code>contains</code> or <code>intersects</code> is - * undefined unless the rectangle has positive width and height. - * - * <p>There are some public fields; if you mess with them in an inconsistent - * manner, it is your own fault when you get NullPointerException, - * ArrayIndexOutOfBoundsException, or invalid results. Also, this class is - * not threadsafe. - * - * @author Warren Levy (warrenl@cygnus.com) - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.0 - * @status updated to 1.4 - */ -public class Rectangle extends Rectangle2D implements Shape, Serializable -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = -4345857070255674764L; - - /** - * The X coordinate of the top-left corner of the rectangle. - * - * @see #setLocation(int, int) - * @see #getLocation() - * @serial the x coordinate - */ - public int x; - - /** - * The Y coordinate of the top-left corner of the rectangle. - * - * @see #setLocation(int, int) - * @see #getLocation() - * @serial the y coordinate - */ - public int y; - - /** - * The width of the rectangle. - * - * @see #setSize(int, int) - * @see #getSize() - * @serial - */ - public int width; - - /** - * The height of the rectangle. - * - * @see #setSize(int, int) - * @see #getSize() - * @serial - */ - public int height; - - /** - * Initializes a new instance of <code>Rectangle</code> with a top - * left corner at (0,0) and a width and height of 0. - */ - public Rectangle() - { - } - - /** - * Initializes a new instance of <code>Rectangle</code> from the - * coordinates of the specified rectangle. - * - * @param r the rectangle to copy from - * @throws NullPointerException if r is null - * @since 1.1 - */ - public Rectangle(Rectangle r) - { - x = r.x; - y = r.y; - width = r.width; - height = r.height; - } - - /** - * Initializes a new instance of <code>Rectangle</code> from the specified - * inputs. - * - * @param x the X coordinate of the top left corner - * @param y the Y coordinate of the top left corner - * @param width the width of the rectangle - * @param height the height of the rectangle - */ - public Rectangle(int x, int y, int width, int height) - { - this.x = x; - this.y = y; - this.width = width; - this.height = height; - } - - /** - * Initializes a new instance of <code>Rectangle</code> with the specified - * width and height. The upper left corner of the rectangle will be at - * the origin (0,0). - * - * @param width the width of the rectangle - * @param height the height of the rectange - */ - public Rectangle(int width, int height) - { - this.width = width; - this.height = height; - } - - /** - * Initializes a new instance of <code>Rectangle</code> with a top-left - * corner represented by the specified point and the width and height - * represented by the specified dimension. - * - * @param p the upper left corner of the rectangle - * @param d the width and height of the rectangle - * @throws NullPointerException if p or d is null - */ - public Rectangle(Point p, Dimension d) - { - x = p.x; - y = p.y; - width = d.width; - height = d.height; - } - - /** - * Initializes a new instance of <code>Rectangle</code> with a top left - * corner at the specified point and a width and height of zero. - * - * @param p the upper left corner of the rectangle - */ - public Rectangle(Point p) - { - x = p.x; - y = p.y; - } - - /** - * Initializes a new instance of <code>Rectangle</code> with an - * upper left corner at the origin (0,0) and a width and height represented - * by the specified dimension. - * - * @param d the width and height of the rectangle - */ - public Rectangle(Dimension d) - { - width = d.width; - height = d.height; - } - - /** - * Get the X coordinate of the upper-left corner. - * - * @return the value of x, as a double - */ - public double getX() - { - return x; - } - - /** - * Get the Y coordinate of the upper-left corner. - * - * @return the value of y, as a double - */ - public double getY() - { - return y; - } - - /** - * Get the width of the rectangle. - * - * @return the value of width, as a double - */ - public double getWidth() - { - return width; - } - - /** - * Get the height of the rectangle. - * - * @return the value of height, as a double - */ - public double getHeight() - { - return height; - } - - /** - * Returns the bounds of this rectangle. A pretty useless method, as this - * is already a rectangle; it is included to mimic the - * <code>getBounds</code> method in Component. - * - * @return a copy of this rectangle - * @see #setBounds(Rectangle) - * @since 1.1 - */ - public Rectangle getBounds() - { - return new Rectangle(this); - } - - /** - * Returns the high-precision bounds of this rectangle. A pretty useless - * method, as this is already a rectangle. - * - * @return a copy of this rectangle - * @see #setBounds(Rectangle) - * @since 1.2 - */ - public Rectangle2D getBounds2D() - { - return new Rectangle(x, y, width, height); - } - - /** - * Updates this rectangle to match the dimensions of the specified - * rectangle. - * - * @param r the rectangle to update from - * @throws NullPointerException if r is null - * @see #setBounds(int, int, int, int) - * @since 1.1 - */ - public void setBounds(Rectangle r) - { - setBounds (r.x, r.y, r.width, r.height); - } - - /** - * Updates this rectangle to have the specified dimensions. - * - * @param x the new X coordinate of the upper left hand corner - * @param y the new Y coordinate of the upper left hand corner - * @param width the new width of this rectangle - * @param height the new height of this rectangle - * @since 1.1 - */ - public void setBounds(int x, int y, int width, int height) - { - reshape (x, y, width, height); - } - - /** - * Updates this rectangle to have the specified dimensions, as rounded to - * integers. - * - * @param x the new X coordinate of the upper left hand corner - * @param y the new Y coordinate of the upper left hand corner - * @param width the new width of this rectangle - * @param height the new height of this rectangle - * @since 1.2 - */ - public void setRect(double x, double y, double width, double height) - { - this.x = (int) x; - this.y = (int) y; - this.width = (int) width; - this.height = (int) height; - } - - /** - * Updates this rectangle to have the specified dimensions. - * - * @param x the new X coordinate of the upper left hand corner - * @param y the new Y coordinate of the upper left hand corner - * @param width the new width of this rectangle - * @param height the new height of this rectangle - * @deprecated use {@link #setBounds(int, int, int, int)} instead - */ - public void reshape(int x, int y, int width, int height) - { - this.x = x; - this.y = y; - this.width = width; - this.height = height; - } - - /** - * Returns the location of this rectangle, which is the coordinates of - * its upper left corner. - * - * @return the point where this rectangle is located - * @see #setLocation(Point) - * @since 1.1 - */ - public Point getLocation() - { - return new Point(x,y); - } - - /** - * Moves the location of this rectangle by setting its upper left - * corner to the specified point. - * - * @param p the point to move the rectangle to - * @throws NullPointerException if p is null - * @see #getLocation() - * @since 1.1 - */ - public void setLocation(Point p) - { - setLocation (p.x, p.y); - } - - /** - * Moves the location of this rectangle by setting its upper left - * corner to the specified coordinates. - * - * @param x the new X coordinate for this rectangle - * @param y the new Y coordinate for this rectangle - * @since 1.1 - */ - public void setLocation(int x, int y) - { - move (x, y); - } - - /** - * Moves the location of this rectangle by setting its upper left - * corner to the specified coordinates. - * - * @param x the new X coordinate for this rectangle - * @param y the new Y coordinate for this rectangle - * @deprecated use {@link #setLocation(int, int)} instead - */ - public void move(int x, int y) - { - this.x = x; - this.y = y; - } - - /** - * Translate the location of this rectangle by the given amounts. - * - * @param dx the x distance to move by - * @param dy the y distance to move by - * @see #setLocation(int, int) - */ - public void translate(int dx, int dy) - { - x += dx; - y += dy; - } - - /** - * Returns the size of this rectangle. - * - * @return the size of this rectangle - * @see #setSize(Dimension) - * @since 1.1 - */ - public Dimension getSize() - { - return new Dimension(width, height); - } - - /** - * Sets the size of this rectangle based on the specified dimensions. - * - * @param d the new dimensions of the rectangle - * @throws NullPointerException if d is null - * @see #getSize() - * @since 1.1 - */ - public void setSize(Dimension d) - { - setSize (d.width, d.height); - } - - /** - * Sets the size of this rectangle based on the specified dimensions. - * - * @param width the new width of the rectangle - * @param height the new height of the rectangle - * @since 1.1 - */ - public void setSize(int width, int height) - { - resize (width, height); - } - - /** - * Sets the size of this rectangle based on the specified dimensions. - * - * @param width the new width of the rectangle - * @param height the new height of the rectangle - * @deprecated use {@link #setSize(int, int)} instead - */ - public void resize(int width, int height) - { - this.width = width; - this.height = height; - } - - /** - * Tests whether or not the specified point is inside this rectangle. - * According to the contract of Shape, a point on the border is in only if - * it has an adjacent point inside the rectangle in either the increasing - * x or y direction. - * - * @param p the point to test - * @return true if the point is inside the rectangle - * @throws NullPointerException if p is null - * @see #contains(int, int) - * @since 1.1 - */ - public boolean contains(Point p) - { - return contains (p.x, p.y); - } - - /** - * Tests whether or not the specified point is inside this rectangle. - * According to the contract of Shape, a point on the border is in only if - * it has an adjacent point inside the rectangle in either the increasing - * x or y direction. - * - * @param x the X coordinate of the point to test - * @param y the Y coordinate of the point to test - * @return true if the point is inside the rectangle - * @since 1.1 - */ - public boolean contains(int x, int y) - { - return inside (x, y); - } - - /** - * Checks whether all points in the given rectangle are contained in this - * rectangle. - * - * @param r the rectangle to check - * @return true if r is contained in this rectangle - * @throws NullPointerException if r is null - * @see #contains(int, int, int, int) - * @since 1.1 - */ - public boolean contains(Rectangle r) - { - return contains (r.x, r.y, r.width, r.height); - } - - /** - * Checks whether all points in the given rectangle are contained in this - * rectangle. - * - * @param x the x coordinate of the rectangle to check - * @param y the y coordinate of the rectangle to check - * @param w the width of the rectangle to check - * @param h the height of the rectangle to check - * @return true if the parameters are contained in this rectangle - * @since 1.1 - */ - public boolean contains(int x, int y, int w, int h) - { - return width > 0 && height > 0 && w > 0 && h > 0 - && x >= this.x && x + w <= this.x + this.width - && y >= this.y && y + h <= this.y + this.height; - } - - /** - * Tests whether or not the specified point is inside this rectangle. - * - * @param x the X coordinate of the point to test - * @param y the Y coordinate of the point to test - * @return true if the point is inside the rectangle - * @deprecated use {@link #contains(int, int)} instead - */ - public boolean inside(int x, int y) - { - return width > 0 && height > 0 - && x >= this.x && x < this.x + width - && y >= this.y && y < this.y + height; - } - - /** - * Tests whether or not the specified rectangle intersects this rectangle. - * This means the two rectangles share at least one internal point. - * - * @param r the rectangle to test against - * @return true if the specified rectangle intersects this one - * @throws NullPointerException if r is null - * @since 1.2 - */ - public boolean intersects(Rectangle r) - { - return r.width > 0 && r.height > 0 && width > 0 && height > 0 - && r.x < x + width && r.x + r.width > x - && r.y < y + height && r.y + r.height > y; - } - - /** - * Determines the rectangle which is formed by the intersection of this - * rectangle with the specified rectangle. If the two do not intersect, - * an empty rectangle will be returned (meaning the width and/or height - * will be non-positive). - * - * @param r the rectange to calculate the intersection with - * @return a new rectangle bounding the intersection - * @throws NullPointerException if r is null - */ - public Rectangle intersection(Rectangle r) - { - Rectangle res = new Rectangle(); - intersect(this, r, res); - return res; - } - - /** - * Returns the smallest rectangle that contains both this rectangle - * and the specified rectangle. - * - * @param r the rectangle to compute the union with - * @return the smallest rectangle containing both rectangles - * @throws NullPointerException if r is null - */ - public Rectangle union(Rectangle r) - { - Rectangle res = new Rectangle(); - union(this, r, res); - return res; - } - - /** - * Modifies this rectangle so that it represents the smallest rectangle - * that contains both the existing rectangle and the specified point. - * However, if the point falls on one of the two borders which are not - * inside the rectangle, a subsequent call to <code>contains</code> may - * return false. - * - * @param x the X coordinate of the point to add to this rectangle - * @param y the Y coordinate of the point to add to this rectangle - */ - public void add(int x, int y) - { - add((double) x, (double) y); - } - - /** - * Modifies this rectangle so that it represents the smallest rectangle - * that contains both the existing rectangle and the specified point. - * However, if the point falls on one of the two borders which are not - * inside the rectangle, a subsequent call to <code>contains</code> may - * return false. - * - * @param p the point to add to this rectangle - * @throws NullPointerException if p is null - */ - public void add(Point p) - { - add((double) p.x, (double) p.y); - } - - /** - * Modifies this rectangle so that it represents the smallest rectangle - * that contains both the existing rectangle and the specified rectangle. - * - * @param r the rectangle to add to this rectangle - * @throws NullPointerException if r is null - * @see #union(Rectangle) - */ - public void add(Rectangle r) - { - union(this, r, this); - } - - /** - * Expands the rectangle by the specified amount. The horizontal - * and vertical expansion values are applied both to the X,Y coordinate - * of this rectangle, and its width and height. Thus the width and - * height will increase by 2h and 2v accordingly. - * - * @param h the horizontal expansion value - * @param v the vertical expansion value - */ - public void grow(int h, int v) - { - x -= h; - y -= v; - width += h + h; - height += v + v; - } - - /** - * Tests whether or not this rectangle is empty. An empty rectangle - * has a non-positive width or height. - * - * @return true if the rectangle is empty - */ - public boolean isEmpty() - { - return width <= 0 || height <= 0; - } - - /** - * Determine where the point lies with respect to this rectangle. The - * result will be the binary OR of the appropriate bit masks. - * - * @param x the x coordinate to check - * @param y the y coordinate to check - * @return the binary OR of the result - * @see #OUT_LEFT - * @see #OUT_TOP - * @see #OUT_RIGHT - * @see #OUT_BOTTOM - * @since 1.2 - */ - public int outcode(double x, double y) - { - int result = 0; - if (width <= 0) - result |= OUT_LEFT | OUT_RIGHT; - else if (x < this.x) - result |= OUT_LEFT; - else if (x > this.x + width) - result |= OUT_RIGHT; - if (height <= 0) - result |= OUT_BOTTOM | OUT_TOP; - else if (y < this.y) // Remember that +y heads top-to-bottom. - result |= OUT_TOP; - else if (y > this.y + height) - result |= OUT_BOTTOM; - return result; - } - - /** - * Determines the rectangle which is formed by the intersection of this - * rectangle with the specified rectangle. If the two do not intersect, - * an empty rectangle will be returned (meaning the width and/or height - * will be non-positive). - * - * @param r the rectange to calculate the intersection with - * @return a new rectangle bounding the intersection - * @throws NullPointerException if r is null - * @since 1.2 - */ - public Rectangle2D createIntersection(Rectangle2D r) - { - // Favor runtime type of other rectangle. - Rectangle2D res = r.getBounds2D(); - intersect(this, r, res); - return res; - } - - /** - * Returns the smallest rectangle that contains both this rectangle - * and the specified rectangle. - * - * @param r the rectangle to compute the union with - * @return the smallest rectangle containing both rectangles - * @throws NullPointerException if r is null - * @since 1.2 - */ - public Rectangle2D createUnion(Rectangle2D r) - { - // Favor runtime type of other rectangle. - Rectangle2D res = r.getBounds2D(); - union(this, r, res); - return res; - } - - /** - * Tests this rectangle for equality against the specified object. This - * will be true if an only if the specified object is an instance of - * Rectangle2D with the same coordinates and dimensions. - * - * @param obj the object to test against for equality - * @return true if the specified object is equal to this one - */ - public boolean equals(Object obj) - { - if (! (obj instanceof Rectangle2D)) - return false; - Rectangle2D r = (Rectangle2D) obj; - return r.getX() == x && r.getY() == y - && r.getWidth() == width && r.getHeight() == height; - } - - /** - * Returns a string representation of this rectangle. This is in the form - * <code>getClass().getName() + "[x=" + x + ",y=" + y + ",width=" + width - * + ",height=" + height + ']'</code>. - * - * @return a string representation of this rectangle - */ - public String toString() - { - return getClass().getName() + "[x=" + x + ",y=" + y + ",width=" + width - + ",height=" + height + ']'; - } -} // class Rectangle diff --git a/libjava/java/awt/RenderingHints.java b/libjava/java/awt/RenderingHints.java deleted file mode 100644 index 61e69f6b4bb..00000000000 --- a/libjava/java/awt/RenderingHints.java +++ /dev/null @@ -1,793 +0,0 @@ -/* RenderingHints.java -- - Copyright (C) 2000, 2001, 2002, 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - -/** - * A collection of (key, value) items that provide 'hints' for the - * {@link java.awt.Graphics2D} rendering pipeline. Because these - * items are hints only, they may be ignored by a particular - * {@link java.awt.Graphics2D} implementation. - * - * @author Rolf W. Rasmussen (rolfwr@ii.uib.no) - * @author Eric Blake (ebb9@email.byu.edu) - */ -public class RenderingHints implements Map, Cloneable -{ - /** - * The base class used to represent keys. - */ - public abstract static class Key - { - private final int key; - - /** - * Creates a new key. - * - * @param privateKey the private key. - */ - protected Key(int privateKey) - { - key = privateKey; - } - - /** - * Returns <code>true</code> if the specified value is compatible with - * this key, and <code>false</code> otherwise. - * - * @param value the value (<code>null</code> permitted). - * - * @return A boolean. - */ - public abstract boolean isCompatibleValue(Object value); - - /** - * Returns the private key for this instance. - * - * @return The private key. - */ - protected final int intKey() - { - return key; - } - - /** - * Returns a hash code for the key. - * - * @return A hash code. - */ - public final int hashCode() - { - return System.identityHashCode(this); - } - - /** - * Checks this key for equality with an arbitrary object. - * - * @param other the object (<code>null</code> permitted) - * - * @return A boolean. - */ - public final boolean equals(Object other) - { - return this == other; - } - } // class Key - - private static final class KeyImpl extends Key - { - final String description; - final Object v1; - final Object v2; - final Object v3; - - KeyImpl(int privateKey, String description, - Object v1, Object v2, Object v3) - { - super(privateKey); - this.description = description; - this.v1 = v1; - this.v2 = v2; - this.v3 = v3; - } - - /** - * Returns <code>true</code> if the specified value is compatible with - * this key, and <code>false</code> otherwise. - * - * @param value the value (<code>null</code> permitted). - * - * @return A boolean. - */ - public boolean isCompatibleValue(Object value) - { - return value == v1 || value == v2 || value == v3; - } - - /** - * Returns a string representation of the key. - * - * @return A string. - */ - public String toString() - { - return description; - } - } // class KeyImpl - - private HashMap hintMap = new HashMap(); - - /** - * A key for the 'antialiasing' hint. Permitted values are: - * <p> - * <table> - * <tr> - * <td>{@link #VALUE_ANTIALIAS_OFF}</td> - * <td>Render without antialiasing (better speed).</td> - * </tr> - * <tr> - * <td>{@link #VALUE_ANTIALIAS_ON}</td> - * <td>Render with antialiasing (better quality).</td> - * </tr> - * <tr> - * <td>{@link #VALUE_ANTIALIAS_DEFAULT}</td> - * <td>Use the default value for antialiasing.</td> - * </tr> - * </table> - */ - public static final Key KEY_ANTIALIASING; - - /** - * This value is for use with the {@link #KEY_ANTIALIASING} key. - */ - public static final Object VALUE_ANTIALIAS_ON - = "Antialiased rendering mode"; - - /** - * This value is for use with the {@link #KEY_ANTIALIASING} key. - */ - public static final Object VALUE_ANTIALIAS_OFF - = "Nonantialiased rendering mode"; - - /** - * This value is for use with the {@link #KEY_ANTIALIASING} key. - */ - public static final Object VALUE_ANTIALIAS_DEFAULT - = "Default antialiasing rendering mode"; - - /** - * A key for the 'rendering' hint. Permitted values are: - * <p> - * <table> - * <tr> - * <td>{@link #VALUE_RENDER_SPEED}</td> - * <td>Prefer speed over quality when rendering.</td> - * </tr> - * <tr> - * <td>{@link #VALUE_RENDER_QUALITY}</td> - * <td>Prefer quality over speed when rendering.</td> - * </tr> - * <tr> - * <td>{@link #VALUE_RENDER_DEFAULT}</td> - * <td>Use the default value for quality vs. speed when rendering.</td> - * </tr> - * </table> - */ - public static final Key KEY_RENDERING; - - /** - * This value is for use with the {@link #KEY_RENDERING} key. - */ - public static final Object VALUE_RENDER_SPEED - = "Fastest rendering methods"; - - /** - * This value is for use with the {@link #KEY_RENDERING} key. - */ - public static final Object VALUE_RENDER_QUALITY - = "Highest quality rendering methods"; - - /** - * This value is for use with the {@link #KEY_RENDERING} key. - */ - public static final Object VALUE_RENDER_DEFAULT - = "Default rendering methods"; - - /** - * A key for the 'dithering' hint. Permitted values are: - * <p> - * <table> - * <tr> - * <td>{@link #VALUE_DITHER_DISABLE}</td> - * <td>Disable dithering.</td> - * </tr> - * <tr> - * <td>{@link #VALUE_DITHER_ENABLE}</td> - * <td>Enable dithering.</td> - * </tr> - * <tr> - * <td>{@link #VALUE_DITHER_DEFAULT}</td> - * <td>Use the default value for dithering.</td> - * </tr> - * </table> - */ - public static final Key KEY_DITHERING; - - /** - * This value is for use with the {@link #KEY_DITHERING} key. - */ - public static final Object VALUE_DITHER_DISABLE - = "Nondithered rendering mode"; - - /** - * This value is for use with the {@link #KEY_DITHERING} key. - */ - public static final Object VALUE_DITHER_ENABLE - = "Dithered rendering mode"; - - /** - * This value is for use with the {@link #KEY_DITHERING} key. - */ - public static final Object VALUE_DITHER_DEFAULT - = "Default dithering mode"; - - /** - * A key for the 'text antialiasing' hint. Permitted values are: - * <p> - * <table> - * <tr> - * <td>{@link #VALUE_TEXT_ANTIALIAS_ON}</td> - * <td>Render text with antialiasing (better quality usually).</td> - * </tr> - * <tr> - * <td>{@link #VALUE_TEXT_ANTIALIAS_OFF}</td> - * <td>Render test without antialiasing (better speed).</td> - * </tr> - * <tr> - * <td>{@link #VALUE_TEXT_ANTIALIAS_DEFAULT}</td> - * <td>Use the default value for text antialiasing.</td> - * </tr> - * </table> - */ - public static final Key KEY_TEXT_ANTIALIASING; - - /** - * This value is for use with the {@link #KEY_TEXT_ANTIALIASING} key. - */ - public static final Object VALUE_TEXT_ANTIALIAS_ON - = "Antialiased text mode"; - - /** - * This value is for use with the {@link #KEY_TEXT_ANTIALIASING} key. - */ - public static final Object VALUE_TEXT_ANTIALIAS_OFF - = "Nonantialiased text mode"; - - /** - * This value is for use with the {@link #KEY_TEXT_ANTIALIASING} key. - */ - public static final Object VALUE_TEXT_ANTIALIAS_DEFAULT - = "Default antialiasing text mode"; - - /** - * A key for the 'fractional metrics' hint. Permitted values are: - * <p> - * <table> - * <tr> - * <td>{@link #VALUE_FRACTIONALMETRICS_OFF}</td> - * <td>Render text with fractional metrics off.</td> - * </tr> - * <tr> - * <td>{@link #VALUE_FRACTIONALMETRICS_ON}</td> - * <td>Render text with fractional metrics on.</td> - * </tr> - * <tr> - * <td>{@link #VALUE_FRACTIONALMETRICS_DEFAULT}</td> - * <td>Use the default value for fractional metrics.</td> - * </tr> - * </table> - */ - public static final Key KEY_FRACTIONALMETRICS; - - /** - * This value is for use with the {@link #KEY_FRACTIONALMETRICS} key. - */ - public static final Object VALUE_FRACTIONALMETRICS_OFF - = "Integer text metrics mode"; - - /** - * This value is for use with the {@link #KEY_FRACTIONALMETRICS} key. - */ - public static final Object VALUE_FRACTIONALMETRICS_ON - = "Fractional text metrics mode"; - - /** - * This value is for use with the {@link #KEY_FRACTIONALMETRICS} key. - */ - public static final Object VALUE_FRACTIONALMETRICS_DEFAULT - = "Default fractional text metrics mode"; - - /** - * A key for the 'interpolation' hint. Permitted values are: - * <p> - * <table> - * <tr> - * <td>{@link #VALUE_INTERPOLATION_NEAREST_NEIGHBOR}</td> - * <td>Use nearest neighbour interpolation.</td> - * </tr> - * <tr> - * <td>{@link #VALUE_INTERPOLATION_BILINEAR}</td> - * <td>Use bilinear interpolation.</td> - * </tr> - * <tr> - * <td>{@link #VALUE_INTERPOLATION_BICUBIC}</td> - * <td>Use bicubic interpolation.</td> - * </tr> - * </table> - */ - public static final Key KEY_INTERPOLATION; - - /** - * This value is for use with the {@link #KEY_INTERPOLATION} key. - */ - public static final Object VALUE_INTERPOLATION_NEAREST_NEIGHBOR - = "Nearest Neighbor image interpolation mode"; - - /** - * This value is for use with the {@link #KEY_INTERPOLATION} key. - */ - public static final Object VALUE_INTERPOLATION_BILINEAR - = "Bilinear image interpolation mode"; - - /** - * This value is for use with the {@link #KEY_INTERPOLATION} key. - */ - public static final Object VALUE_INTERPOLATION_BICUBIC - = "Bicubic image interpolation mode"; - - /** - * A key for the 'alpha interpolation' hint. Permitted values are: - * <p> - * <table> - * <tr> - * <td>{@link #VALUE_ALPHA_INTERPOLATION_SPEED}</td> - * <td>Prefer speed over quality.</td> - * </tr> - * <tr> - * <td>{@link #VALUE_ALPHA_INTERPOLATION_QUALITY}</td> - * <td>Prefer quality over speed.</td> - * </tr> - * <tr> - * <td>{@link #VALUE_ALPHA_INTERPOLATION_DEFAULT}</td> - * <td>Use the default setting.</td> - * </tr> - * </table> - */ - public static final Key KEY_ALPHA_INTERPOLATION; - - /** - * This value is for use with the {@link #KEY_ALPHA_INTERPOLATION} key. - */ - public static final Object VALUE_ALPHA_INTERPOLATION_SPEED - = "Fastest alpha blending methods"; - - /** - * This value is for use with the {@link #KEY_ALPHA_INTERPOLATION} key. - */ - public static final Object VALUE_ALPHA_INTERPOLATION_QUALITY - = "Highest quality alpha blending methods"; - - /** - * This value is for use with the {@link #KEY_ALPHA_INTERPOLATION} key. - */ - public static final Object VALUE_ALPHA_INTERPOLATION_DEFAULT - = "Default alpha blending methods"; - - /** - * A key for the 'color rendering' hint. Permitted values are: - * <p> - * <table> - * <tr> - * <td>{@link #VALUE_COLOR_RENDER_SPEED}</td> - * <td>Prefer speed over quality.</td> - * </tr> - * <tr> - * <td>{@link #VALUE_COLOR_RENDER_QUALITY}</td> - * <td>Prefer quality over speed.</td> - * </tr> - * <tr> - * <td>{@link #VALUE_COLOR_RENDER_DEFAULT}</td> - * <td>Use the default setting.</td> - * </tr> - * </table> - */ - public static final Key KEY_COLOR_RENDERING; - - /** - * This value is for use with the {@link #KEY_COLOR_RENDERING} key. - */ - public static final Object VALUE_COLOR_RENDER_SPEED - = "Fastest color rendering mode"; - - /** - * This value is for use with the {@link #KEY_COLOR_RENDERING} key. - */ - public static final Object VALUE_COLOR_RENDER_QUALITY - = "Highest quality color rendering mode"; - - /** - * This value is for use with the {@link #KEY_COLOR_RENDERING} key. - */ - public static final Object VALUE_COLOR_RENDER_DEFAULT - = "Default color rendering mode"; - - /** - * A key for the 'stroke control' hint. Permitted values are: - * <p> - * <table> - * <tr> - * <td>{@link #VALUE_STROKE_DEFAULT}</td> - * <td>Use the default setting.</td> - * </tr> - * <tr> - * <td>{@link #VALUE_STROKE_NORMALIZE}</td> - * <td>XXX</td> - * </tr> - * <tr> - * <td>{@link #VALUE_STROKE_PURE}</td> - * <td>XXX</td> - * </tr> - * </table> - */ - public static final Key KEY_STROKE_CONTROL; - - /** - * This value is for use with the {@link #KEY_STROKE_CONTROL} key. - */ - public static final Object VALUE_STROKE_DEFAULT - = "Default stroke normalization"; - - /** - * This value is for use with the {@link #KEY_STROKE_CONTROL} key. - */ - public static final Object VALUE_STROKE_NORMALIZE - = "Normalize strokes for consistent rendering"; - - /** - * This value is for use with the {@link #KEY_STROKE_CONTROL} key. - */ - public static final Object VALUE_STROKE_PURE - = "Pure stroke conversion for accurate paths"; - - static - { - KEY_ANTIALIASING = new KeyImpl(1, "Global antialiasing enable key", - VALUE_ANTIALIAS_ON, - VALUE_ANTIALIAS_OFF, - VALUE_ANTIALIAS_DEFAULT); - KEY_RENDERING = new KeyImpl(2, "Global rendering quality key", - VALUE_RENDER_SPEED, - VALUE_RENDER_QUALITY, - VALUE_RENDER_DEFAULT); - KEY_DITHERING = new KeyImpl(3, "Dithering quality key", - VALUE_DITHER_DISABLE, - VALUE_DITHER_ENABLE, - VALUE_DITHER_DEFAULT); - KEY_TEXT_ANTIALIASING - = new KeyImpl(4, "Text-specific antialiasing enable key", - VALUE_TEXT_ANTIALIAS_ON, - VALUE_TEXT_ANTIALIAS_OFF, - VALUE_TEXT_ANTIALIAS_DEFAULT); - KEY_FRACTIONALMETRICS = new KeyImpl(5, "Fractional metrics enable key", - VALUE_FRACTIONALMETRICS_OFF, - VALUE_FRACTIONALMETRICS_ON, - VALUE_FRACTIONALMETRICS_DEFAULT); - KEY_INTERPOLATION = new KeyImpl(6, "Image interpolation method key", - VALUE_INTERPOLATION_NEAREST_NEIGHBOR, - VALUE_INTERPOLATION_BILINEAR, - VALUE_INTERPOLATION_BICUBIC); - KEY_ALPHA_INTERPOLATION - = new KeyImpl(7, "Alpha blending interpolation method key", - VALUE_ALPHA_INTERPOLATION_SPEED, - VALUE_ALPHA_INTERPOLATION_QUALITY, - VALUE_ALPHA_INTERPOLATION_DEFAULT); - KEY_COLOR_RENDERING = new KeyImpl(8, "Color rendering quality key", - VALUE_COLOR_RENDER_SPEED, - VALUE_COLOR_RENDER_QUALITY, - VALUE_COLOR_RENDER_DEFAULT); - KEY_STROKE_CONTROL = new KeyImpl(9, "Stroke normalization control key", - VALUE_STROKE_DEFAULT, - VALUE_STROKE_NORMALIZE, - VALUE_STROKE_PURE); - } - - /** - * Creates a new collection of hints containing all the (key, value) pairs - * in the specified map. - * - * @param init a map containing a collection of hints (<code>null</code> - * permitted). - */ - public RenderingHints(Map init) - { - if (init != null) - putAll(init); - } - - /** - * Creates a new collection containing a single (key, value) pair. - * - * @param key the key. - * @param value the value. - */ - public RenderingHints(Key key, Object value) - { - put(key, value); - } - - /** - * Returns the number of hints in the collection. - * - * @return The number of hints. - */ - public int size() - { - return hintMap.size(); - } - - /** - * Returns <code>true</code> if there are no hints in the collection, - * and <code>false</code> otherwise. - * - * @return A boolean. - */ - public boolean isEmpty() - { - return hintMap.isEmpty(); - } - - /** - * Returns <code>true</code> if the collection of hints contains the - * specified key, and <code>false</code> otherwise. - * - * @param key the key. - * - * @return A boolean. - */ - public boolean containsKey(Object key) - { - if (key == null) - throw new NullPointerException(); - return hintMap.containsKey((Key) key); - } - - /** - * Returns <code>true</code> if the collection of hints contains the - * specified value, and <code>false</code> otherwise. - * - * @param value the value. - * - * @return A boolean. - */ - public boolean containsValue(Object value) - { - return hintMap.containsValue(value); - } - - /** - * Returns the value associated with the specified key. - * - * @param key the key. - * - * @return The value. - */ - public Object get(Object key) - { - return hintMap.get((Key) key); - } - - /** - * Adds a (key, value) pair to the collection of hints (if the - * collection already contains the specified key, then the - * value is updated). - * - * @param key the key. - * @param value the value. - * - * @return the previous value of the key or <code>null</code> if the key - * didn't have a value yet. - */ - public Object put(Object key, Object value) - { - if (key == null || value == null) - throw new NullPointerException(); - if (! ((Key) key).isCompatibleValue(value)) - throw new IllegalArgumentException(); - return hintMap.put(key, value); - } - - /** - * Adds all the hints from a collection to this collection. - * - * @param hints the hint collection. - */ - public void add(RenderingHints hints) - { - hintMap.putAll(hints); - } - - /** - * Clears all the hints from this collection. - */ - public void clear() - { - hintMap.clear(); - } - - /** - * Removes a hint from the collection. - * - * @param key the key. - * - * @return The value that was associated with the key, or <code>null</code> if - * the key was not part of the collection - * - * @throws ClassCastException if the key is not a subclass of - * {@link RenderingHints.Key}. - */ - public Object remove(Object key) - { - // don't remove the (Key) cast, it is necessary to throw the exception - // required by the spec - return hintMap.remove((Key) key); - } - - /** - * Adds a collection of (key, value) pairs to the collection. - * - * @param m a map containing (key, value) items. - * - * @throws ClassCastException if the map contains a key that is not - * a subclass of {@link RenderingHints.Key}. - * @throws IllegalArgumentException if the map contains a value that is - * not compatible with its key. - */ - public void putAll(Map m) - { - // preprocess map to generate appropriate exceptions - Iterator iterator = m.keySet().iterator(); - while (iterator.hasNext()) - { - Key key = (Key) iterator.next(); - if (!key.isCompatibleValue(m.get(key))) - throw new IllegalArgumentException(); - } - // map is OK, update - hintMap.putAll(m); - } - - /** - * Returns a set containing the keys from this collection. - * - * @return A set of keys. - */ - public Set keySet() - { - return hintMap.keySet(); - } - - /** - * Returns a collection of the values from this hint collection. The - * collection is backed by the <code>RenderingHints</code> instance, - * so updates to one will affect the other. - * - * @return A collection of values. - */ - public Collection values() - { - return hintMap.values(); - } - - /** - * Returns a set of entries from the collection. - * - * @return A set of entries. - */ - public Set entrySet() - { - return Collections.unmodifiableSet(hintMap.entrySet()); - } - - /** - * Checks this collection for equality with an arbitrary object. - * - * @param o the object (<code>null</code> permitted) - * - * @return A boolean. - */ - public boolean equals(Object o) - { - return hintMap.equals(o); - } - - /** - * Returns a hash code for the collection of hints. - * - * @return A hash code. - */ - public int hashCode() - { - return hintMap.hashCode(); - } - - /** - * Creates a clone of this instance. - * - * @return A clone. - */ - public Object clone() - { - try - { - RenderingHints copy = (RenderingHints) super.clone(); - copy.hintMap = (HashMap) hintMap.clone(); - return copy; - } - catch (CloneNotSupportedException e) - { - throw (Error) new InternalError().initCause(e); // Impossible - } - } - - /** - * Returns a string representation of this instance. - * - * @return A string. - */ - public String toString() - { - return hintMap.toString(); - } -} // class RenderingHints diff --git a/libjava/java/awt/Robot.java b/libjava/java/awt/Robot.java deleted file mode 100644 index 72daa9b94fb..00000000000 --- a/libjava/java/awt/Robot.java +++ /dev/null @@ -1,422 +0,0 @@ -/* Robot.java -- a native input event generator - Copyright (C) 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import gnu.java.awt.ClasspathToolkit; - -import java.lang.reflect.InvocationTargetException; -import java.awt.event.InputEvent; -import java.awt.image.BufferedImage; -import java.awt.peer.RobotPeer; - -/** - * The Robot class is used to simulate user interaction with graphical - * programs. It can generate native windowing system input events and - * retrieve image data from the current screen. Robot is used to test - * the AWT and Swing library implementations; it can also be used to - * create self-running demo programs. - * - * Since Robot generates native windowing system events, rather than - * simply inserting {@link AWTEvents} on the AWT event queue, its use - * is not restricted to Java programs. It can be used to - * programatically drive any graphical application. - * - * This implementation requires an X server that supports the XTest - * extension. - * - * @author Thomas Fitzsimmons (fitzsim@redhat.com) - * - * @since 1.3 - */ -public class Robot -{ - private boolean waitForIdle; - private int autoDelay; - private RobotPeer peer; - - /** - * Construct a Robot object that operates on the default screen. - * - * @exception AWTException if GraphicsEnvironment.isHeadless() - * returns true or if the X server does not support the XTest - * extension - * @exception SecurityException if createRobot permission is not - * granted - */ - public Robot () throws AWTException - { - if (GraphicsEnvironment.isHeadless ()) - throw new AWTException ("Robot: headless graphics environment"); - - SecurityManager sm = System.getSecurityManager (); - if (sm != null) - sm.checkPermission (new AWTPermission ("createRobot")); - - ClasspathToolkit tk = (ClasspathToolkit) Toolkit.getDefaultToolkit (); - - // createRobot will throw AWTException if XTest is not supported. - peer = tk.createRobot (GraphicsEnvironment.getLocalGraphicsEnvironment () - .getDefaultScreenDevice ()); - } - - /** - * Construct a Robot object that operates on the specified screen. - * - * @exception AWTException if GraphicsEnvironment.isHeadless() - * returns true or if the X server does not support the XTest - * extension - * @exception IllegalArgumentException if screen is not a screen - * GraphicsDevice - * @exception SecurityException if createRobot permission is not - * granted - */ - public Robot (GraphicsDevice screen) throws AWTException - { - if (GraphicsEnvironment.isHeadless ()) - throw new AWTException ("Robot: headless graphics environment"); - - if (screen.getType () != GraphicsDevice.TYPE_RASTER_SCREEN) - throw new IllegalArgumentException ("Robot: graphics" - + " device is not a screen"); - - SecurityManager sm = System.getSecurityManager (); - if (sm != null) - sm.checkPermission (new AWTPermission ("createRobot")); - - ClasspathToolkit tk = (ClasspathToolkit) Toolkit.getDefaultToolkit (); - - // createRobot will throw AWTException if XTest is not supported. - peer = tk.createRobot (screen); - } - - /** - * Move the mouse pointer to absolute coordinates (x, y). - * - * @param x the destination x coordinate - * @param y the destination y coordinate - */ - public void mouseMove(int x, int y) - { - peer.mouseMove (x, y); - - if (waitForIdle) - waitForIdle (); - - if (autoDelay > 0) - delay (autoDelay); - } - - /** - * Press one or more mouse buttons. - * - * @param buttons the buttons to press; a bitmask of one or more of - * these {@link InputEvent} fields: - * - * <ul> - * <li>BUTTON1_MASK</li> - * <li>BUTTON2_MASK</li> - * <li>BUTTON3_MASK</li> - * </ul> - * - * @exception IllegalArgumentException if the button mask is invalid - */ - public void mousePress (int buttons) - { - if ((buttons & InputEvent.BUTTON1_MASK) == 0 - && (buttons & InputEvent.BUTTON2_MASK) == 0 - && (buttons & InputEvent.BUTTON3_MASK) == 0) - throw new IllegalArgumentException ("Robot: mousePress:" - + " invalid button mask"); - - peer.mousePress (buttons); - - if (waitForIdle) - waitForIdle (); - - if (autoDelay > 0) - delay (autoDelay); - } - - /** - * Release one or more mouse buttons. - * - * @param buttons the buttons to release; a bitmask of one or more - * of these {@link InputEvent} fields: - * - * <ul> - * <li>BUTTON1_MASK</li> - * <li>BUTTON2_MASK</li> - * <li>BUTTON3_MASK</li> - * </ul> - * - * @exception IllegalArgumentException if the button mask is invalid - */ - public void mouseRelease(int buttons) - { - if ((buttons & InputEvent.BUTTON1_MASK) == 0 - && (buttons & InputEvent.BUTTON2_MASK) == 0 - && (buttons & InputEvent.BUTTON3_MASK) == 0) - throw new IllegalArgumentException ("Robot: mouseRelease:" - + " invalid button mask"); - - peer.mouseRelease (buttons); - - if (waitForIdle) - waitForIdle (); - - if (autoDelay > 0) - delay (autoDelay); - } - - /** - * Rotate the mouse scroll wheel. - * - * @param wheelAmt number of steps to rotate mouse wheel. negative - * to rotate wheel up (away from the user), positive to rotate wheel - * down (toward the user). - * - * @since 1.4 - */ - public void mouseWheel (int wheelAmt) - { - peer.mouseWheel (wheelAmt); - - if (waitForIdle) - waitForIdle (); - - if (autoDelay > 0) - delay (autoDelay); - } - - /** - * Press a key. - * - * @param keycode key to press, a {@link KeyEvent} VK_ constant - * - * @exception IllegalArgumentException if keycode is not a valid key - */ - public void keyPress (int keycode) - { - peer.keyPress (keycode); - - if (waitForIdle) - waitForIdle (); - - if (autoDelay > 0) - delay (autoDelay); - } - - /** - * Release a key. - * - * @param keycode key to release, a {@link KeyEvent} VK_ constant - * - * @exception IllegalArgumentException if keycode is not a valid key - */ - public void keyRelease (int keycode) - { - peer.keyRelease (keycode); - - if (waitForIdle) - waitForIdle (); - - if (autoDelay > 0) - delay (autoDelay); - } - - /** - * Return the color of the pixel at the given screen coordinates. - * - * @param x the x coordinate of the pixel - * @param y the y coordinate of the pixel - * - * @return the Color of the pixel at screen coodinates <code>(x, y)</code> - */ - public Color getPixelColor (int x, int y) - { - return new Color (peer.getRGBPixel (x, y)); - } - - /** - * Create an image containing pixels read from the screen. The - * image does not include the mouse pointer. - * - * @param screenRect the rectangle of pixels to capture, in screen - * coordinates - * - * @return a BufferedImage containing the requested pixels - * - * @exception IllegalArgumentException if requested width and height - * are not both greater than zero - * @exception SecurityException if readDisplayPixels permission is - * not granted - */ - public BufferedImage createScreenCapture (Rectangle screenRect) - { - if (screenRect.width <= 0) - throw new IllegalArgumentException ("Robot: capture width is <= 0"); - - if (screenRect.height <= 0) - throw new IllegalArgumentException ("Robot: capture height is <= 0"); - - SecurityManager sm = System.getSecurityManager (); - if (sm != null) - sm.checkPermission (new AWTPermission ("readDisplayPixels")); - - int[] pixels = peer.getRGBPixels (screenRect); - - BufferedImage bufferedImage = - new BufferedImage (screenRect.width, screenRect.height, - BufferedImage.TYPE_INT_ARGB); - - bufferedImage.setRGB (0, 0, screenRect.width, screenRect.height, - pixels, 0, screenRect.width); - - return bufferedImage; - } - - /** - * Check if this Robot automatically calls {@link waitForIdle} after - * generating an event. - * - * @return true if waitForIdle is automatically called - */ - public boolean isAutoWaitForIdle () - { - return waitForIdle; - } - - /** - * Set whether or not this Robot automatically calls {@link - * waitForIdle} after generating an event. - * - * @param isOn true if waitForIdle should be called automatically - */ - public void setAutoWaitForIdle (boolean isOn) - { - waitForIdle = isOn; - } - - /** - * Retrieve the length of time this Robot sleeps after generating an - * event. - * - * @return the length of time in milliseconds - */ - public int getAutoDelay () - { - return autoDelay; - } - - /** - * Set the length of time this Robot sleeps after generating an - * event. - * - * @param ms the length of time in milliseconds - * - * @exception IllegalArgumentException if ms is not between 0 and - * 60,000 milliseconds inclusive - */ - public void setAutoDelay (int ms) - { - if (ms <= 0 || ms >= 60000) - throw new IllegalArgumentException ("Robot: delay length out-of-bounds"); - - autoDelay = ms; - } - - /** - * Sleep for a specified length of time. - * - * @param ms the length of time in milliseconds - * - * @exception IllegalArgumentException if ms is not between 0 and - * 60,000 milliseconds inclusive - */ - public void delay (int ms) - { - if (ms < 0 || ms > 60000) - throw new IllegalArgumentException ("Robot: delay length out-of-bounds"); - - try - { - Thread.sleep (ms); - } - catch (InterruptedException e) - { - System.err.println ("Robot: delay interrupted"); - } - } - - /** - * Wait until all events currently on the event queue have been - * dispatched. - */ - public void waitForIdle () - { - if (EventQueue.isDispatchThread ()) - throw new IllegalThreadStateException ("Robot: waitForIdle called from " - + "the event dispatch thread"); - - try - { - EventQueue.invokeAndWait (new Runnable () { public void run () { } }); - } - catch (InterruptedException e) - { - System.err.println ("Robot: waitForIdle interrupted"); - } - catch (InvocationTargetException e) - { - System.err.println ("Robot: waitForIdle cannot invoke target"); - } - } - - /** - * Return a string representation of this Robot. - * - * @return a string representation - */ - public String toString () - { - return getClass ().getName () - + "[ autoDelay = " + autoDelay + ", autoWaitForIdle = " - + waitForIdle + " ]"; - } -} diff --git a/libjava/java/awt/ScrollPane.java b/libjava/java/awt/ScrollPane.java deleted file mode 100644 index b3ecc59fcd5..00000000000 --- a/libjava/java/awt/ScrollPane.java +++ /dev/null @@ -1,615 +0,0 @@ -/* ScrollPane.java -- Scrolling window - Copyright (C) 1999, 2002, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.awt.event.MouseEvent; -import java.awt.peer.ComponentPeer; -import java.awt.peer.ScrollPanePeer; - -import javax.accessibility.Accessible; -import javax.accessibility.AccessibleContext; -import javax.accessibility.AccessibleRole; - -/** - * This widget provides a scrollable region that allows a single - * subcomponent to be viewed through a smaller window. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public class ScrollPane extends Container implements Accessible -{ - -/* - * Static Variables - */ - -/** - * Constant indicating that scrollbars are created as needed in this - * windows. - */ -public static final int SCROLLBARS_AS_NEEDED = 0; - -/** - * Constant indicating that scrollbars are always displayed in this - * window. - */ -public static final int SCROLLBARS_ALWAYS = 1; - -/** - * Constant indicating that scrollbars are never displayed in this window. - */ -public static final int SCROLLBARS_NEVER = 2; - -// Serialization constant -private static final long serialVersionUID = 7956609840827222915L; - -/*************************************************************************/ - -/* - * Instance Variables - */ - -/** - * @serial The horizontal scrollbar for this window. The methods - * <code>setMinimum()</code>, <code>setMaximum</code>, and - * <code>setVisibleAmount</code> must not be called on this scrollbar. - */ -private ScrollPaneAdjustable hAdjustable; - -/** - * @serial The vertical scrollbar for this window. The methods - * <code>setMinimum()</code>, <code>setMaximum</code>, and - * <code>setVisibleAmount</code> must not be called on this scrollbar. - */ -private ScrollPaneAdjustable vAdjustable; - -/** - * @serial Indicates when scrollbars are displayed in this window, will - * be one of the constants from this class. - */ -private int scrollbarDisplayPolicy; - -// Current scroll position -private Point scrollPosition = new Point(0, 0); - -private boolean wheelScrollingEnabled; - -/*************************************************************************/ - -/* - * Constructors - */ - -/** - * Initializes a new instance of <code>ScrollPane</code> with a default - * scrollbar policy of <code>SCROLLBARS_AS_NEEDED</code>. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. - */ -public -ScrollPane() -{ - this(SCROLLBARS_AS_NEEDED); -} - -/*************************************************************************/ - -/** - * Initializes a new instance of <code>ScrollPane</code> with the - * specified scrollbar policy. - * - * @param scrollbarDisplayPolicy When to display scrollbars, which must - * be one of the constants defined in this class. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. - */ -public -ScrollPane(int scrollbarDisplayPolicy) -{ - if (GraphicsEnvironment.isHeadless ()) - throw new HeadlessException (); - - this.scrollbarDisplayPolicy = scrollbarDisplayPolicy; - - if (scrollbarDisplayPolicy != SCROLLBARS_ALWAYS - && scrollbarDisplayPolicy != SCROLLBARS_AS_NEEDED - && scrollbarDisplayPolicy != SCROLLBARS_NEVER) - throw new IllegalArgumentException("Bad scrollbarDisplayPolicy: " + - scrollbarDisplayPolicy); - - if (scrollbarDisplayPolicy != SCROLLBARS_NEVER) - { - hAdjustable = new ScrollPaneAdjustable (this, Scrollbar.HORIZONTAL); - vAdjustable = new ScrollPaneAdjustable (this, Scrollbar.VERTICAL); - } - - wheelScrollingEnabled = true; - - // Default size. - setSize(100,100); -} - -/*************************************************************************/ - -/* - * Instance Variables - */ - -/** - * Returns the current scrollbar display policy. - * - * @return The current scrollbar display policy. - */ -public int -getScrollbarDisplayPolicy() -{ - return(scrollbarDisplayPolicy); -} - -/*************************************************************************/ - -/** - * Returns the horizontal scrollbar for this object. If the scrollbar - * display policy is set to <code>SCROLLBARS_NEVER</code> then this - * will be <code>null</code>. - * - * @return The horizontal scrollbar for this window. - */ -public Adjustable -getHAdjustable() -{ - return(hAdjustable); -} - -/*************************************************************************/ - -/** - * Returns the vertical scrollbar for this object. If the scrollbar - * display policy is set to <code>SCROLLBARS_NEVER</code> then this - * will be <code>null</code>. - * - * @return The horizontal scrollbar for this window. - */ -public Adjustable -getVAdjustable() -{ - return(vAdjustable); -} - -/*************************************************************************/ - -/** - * Returns the current viewport size. The viewport is the region of - * this object's window where the child is actually displayed. - * - * @return The viewport size. - */ -public Dimension getViewportSize () -{ - Dimension viewsize = getSize (); - Insets insets = getInsets (); - - viewsize.width -= (insets.left + insets.right); - viewsize.height -= (insets.top + insets.bottom); - - Component[] list = getComponents(); - if ((list == null) || (list.length <= 0)) - return viewsize; - - Dimension dim = list[0].getPreferredSize(); - - if (dim.width <= 0 && dim.height <= 0) - return viewsize; - - int vScrollbarWidth = getVScrollbarWidth (); - int hScrollbarHeight = getHScrollbarHeight (); - - if (scrollbarDisplayPolicy == SCROLLBARS_ALWAYS) - { - viewsize.width -= vScrollbarWidth; - viewsize.height -= hScrollbarHeight; - return viewsize; - } - - if (scrollbarDisplayPolicy == SCROLLBARS_NEVER) - return viewsize; - - // The scroll policy is SCROLLBARS_AS_NEEDED, so we need to see if - // either scrollbar is needed. - - // Assume we don't need either scrollbar. - boolean mayNeedVertical = false; - boolean mayNeedHorizontal = false; - - boolean needVertical = false; - boolean needHorizontal = false; - - // Check if we need vertical scrollbars. If we do, then we need to - // subtract the width of the vertical scrollbar from the viewport's - // width. - if (dim.height > viewsize.height) - needVertical = true; - else if (dim.height > (viewsize.height - hScrollbarHeight)) - // This is tricky. In this case the child is tall enough that its - // bottom edge would be covered by a horizontal scrollbar, if one - // were present. This means that if there's a horizontal - // scrollbar then we need a vertical scrollbar. - mayNeedVertical = true; - - if (dim.width > viewsize.width) - needHorizontal = true; - else if (dim.width > (viewsize.width - vScrollbarWidth)) - mayNeedHorizontal = true; - - if (needVertical && mayNeedHorizontal) - needHorizontal = true; - - if (needHorizontal && mayNeedVertical) - needVertical = true; - - if (needHorizontal) - viewsize.height -= hScrollbarHeight; - - if (needVertical) - viewsize.width -= vScrollbarWidth; - - return viewsize; -} - -/*************************************************************************/ - -/** - * Returns the height of a horizontal scrollbar. - * - * @return The height of a horizontal scrollbar. - */ -public int -getHScrollbarHeight() -{ - ScrollPanePeer spp = (ScrollPanePeer)getPeer(); - if (spp != null) - return(spp.getHScrollbarHeight()); - else - return(0); // FIXME: What to do here? -} - -/*************************************************************************/ - -/** - * Returns the width of a vertical scrollbar. - * - * @return The width of a vertical scrollbar. - */ -public int -getVScrollbarWidth() -{ - ScrollPanePeer spp = (ScrollPanePeer)getPeer(); - if (spp != null) - return(spp.getVScrollbarWidth()); - else - return(0); // FIXME: What to do here? -} - -/*************************************************************************/ - -/** - * Returns the current scroll position of the viewport. - * - * @return The current scroll position of the viewport. - */ -public Point -getScrollPosition() -{ - int x = 0; - int y = 0; - - Adjustable v = getVAdjustable(); - Adjustable h = getHAdjustable(); - - if (v != null) - y = v.getValue(); - if (h != null) - x = h.getValue(); - - return(new Point(x, y)); -} - -/*************************************************************************/ - -/** - * Sets the scroll position to the specified value. - * - * @param scrollPosition The new scrollPosition. - * - * @exception IllegalArgumentException If the specified value is outside - * the legal scrolling range. - */ -public void -setScrollPosition(Point scrollPosition) throws IllegalArgumentException -{ - setScrollPosition(scrollPosition.x, scrollPosition.y); -} - -/*************************************************************************/ - -/** - * Sets the scroll position to the specified value. - * - * @param x The new X coordinate of the scroll position. - * @param y The new Y coordinate of the scroll position. - * - * @exception IllegalArgumentException If the specified value is outside - * the legal scrolling range. - */ -public void -setScrollPosition(int x, int y) -{ - Adjustable h = getHAdjustable(); - Adjustable v = getVAdjustable(); - - if (h != null) - h.setValue(x); - if (v != null) - v.setValue(y); - - ScrollPanePeer spp = (ScrollPanePeer)getPeer(); - if (spp != null) - spp.setScrollPosition(x, y); -} - -/*************************************************************************/ - -/** - * Notifies this object that it should create its native peer. - */ -public void -addNotify() -{ - if (!isDisplayable ()) - return; - - setPeer((ComponentPeer)getToolkit().createScrollPane(this)); - super.addNotify(); - - Component[] list = getComponents(); - if (list != null && list.length > 0 && ! (list[0] instanceof Panel)) - { - Panel panel = new Panel(); - panel.setLayout(new BorderLayout()); - panel.add(list[0], BorderLayout.CENTER); - add(panel); - } -} - -/*************************************************************************/ - -/** - * Notifies this object that it should destroy its native peers. - */ -public void -removeNotify() -{ - super.removeNotify(); -} - -/*************************************************************************/ - -/** - * Adds the specified child component to this container. A - * <code>ScrollPane</code> can have at most one child, so if a second - * one is added, then first one is removed. - * - * @param component The component to add to this container. - * @param constraints A list of layout constraints for this object. - * @param index The index at which to add the child, which is ignored - * in this implementation. - */ - protected final void addImpl (Component component, Object constraints, - int index) -{ - Component[] list = getComponents(); - if ((list != null) && (list.length > 0)) - remove(list[0]); - - super.addImpl(component, constraints, -1); - - doLayout(); -} - -/*************************************************************************/ - -/** - * Lays out this component. This consists of resizing the sole child - * component to its perferred size. - */ -public void -doLayout() -{ - layout (); -} - -/*************************************************************************/ - -/** - * Lays out this component. This consists of resizing the sole child - * component to its perferred size. - * - * @deprecated This method is deprecated in favor of - * <code>doLayout()</code>. - */ -public void -layout() -{ - Component[] list = getComponents (); - if ((list != null) && (list.length > 0)) - { - Dimension dim = list[0].getPreferredSize (); - Dimension vp = getViewportSize (); - - if (dim.width < vp.width) - dim.width = vp.width; - - if (dim.height < vp.height) - dim.height = vp.height; - - ScrollPanePeer peer = (ScrollPanePeer) getPeer (); - if (peer != null) - peer.childResized (dim.width, dim.height); - - list[0].setSize (dim); - - Point p = getScrollPosition (); - if (p.x > dim.width) - p.x = dim.width; - if (p.y > dim.height) - p.y = dim.height; - - setScrollPosition (p); - } -} - -/*************************************************************************/ - -/** - * This method overrides its superclass method to ensure no layout - * manager is set for this container. <code>ScrollPane</code>'s do - * not have layout managers. - * - * @param layoutManager Ignored - */ -public final void -setLayout(LayoutManager layoutManager) -{ - return; -} - -/*************************************************************************/ - -/** - * Prints all of the components in this container. - * - * @param graphics The desired graphics context for printing. - */ -public void -printComponents(Graphics graphics) -{ - super.printComponents(graphics); -} - -/*************************************************************************/ - -/** - * Returns a debug string for this object. - * - * @return A debug string for this object. - */ -public String -paramString() -{ - Insets insets = getInsets(); - return getName() + "," - + getX() + "," - + getY() + "," - + getWidth() + "x" + getHeight() + "," - + "ScrollPosition=(" + scrollPosition.getX() + "," - + scrollPosition.getY() + ")," - + "Insets=(" + insets.top + "," - + insets.left + "," - + insets.bottom + "," - + insets.right + ")," - + "ScrollbarDisplayPolicy=" + getScrollbarDisplayPolicy() + "," - + "wheelScrollingEnabled=" + isWheelScrollingEnabled(); -} - - /** - * Tells whether or not an event is enabled. - * - * @since 1.4 - */ - protected boolean eventTypeEnabled (int type) - { - if (type == MouseEvent.MOUSE_WHEEL) - return wheelScrollingEnabled; - - return super.eventTypeEnabled (type); - } - - /** - * Tells whether or not wheel scrolling is enabled. - * - * @since 1.4 - */ - public boolean isWheelScrollingEnabled () - { - return wheelScrollingEnabled; - } - - /** - * Enables/disables wheel scrolling. - * - * @since 1.4 - */ - public void setWheelScrollingEnabled (boolean enable) - { - wheelScrollingEnabled = enable; - } - - protected class AccessibleAWTScrollPane extends AccessibleAWTContainer - { - public AccessibleRole getAccessibleRole() - { - return AccessibleRole.SCROLL_PANE; - } - } - - /** - * Gets the AccessibleContext associated with this <code>ScrollPane</code>. - * The context is created, if necessary. - * - * @return the associated context - */ - public AccessibleContext getAccessibleContext() - { - /* Create the context if this is the first request */ - if (accessibleContext == null) - accessibleContext = new AccessibleAWTScrollPane(); - return accessibleContext; - } -} // class ScrollPane - diff --git a/libjava/java/awt/ScrollPaneAdjustable.java b/libjava/java/awt/ScrollPaneAdjustable.java deleted file mode 100644 index cfca19b4423..00000000000 --- a/libjava/java/awt/ScrollPaneAdjustable.java +++ /dev/null @@ -1,200 +0,0 @@ -/* ScrollPaneAdjustable.java -- Scrollbars for a ScrollPane - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.awt.event.AdjustmentListener; -import java.io.Serializable; - -/** - * Need this class since the serialization spec for ScrollPane - * uses it. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @since 1.4 - */ -public class ScrollPaneAdjustable - implements Adjustable, Serializable -{ - private static final long serialVersionUID = -3359745691033257079L; - - ScrollPane sp; - int orientation; - int value; - int minimum; - int maximum; - int visibleAmount; - int unitIncrement = 1; - int blockIncrement = 1; - AdjustmentListener adjustmentListener; - - private transient boolean valueIsAdjusting = false; - - ScrollPaneAdjustable (ScrollPane sp, int orientation) - { - this.sp = sp; - this.orientation = orientation; - } - - ScrollPaneAdjustable (ScrollPane sp, int orientation, int value, int minimum, - int maximum, int visibleAmount, int unitIncrement, - int blockIncrement) - { - this.sp = sp; - this.orientation = orientation; - this.value = value; - this.minimum = minimum; - this.maximum = maximum; - this.visibleAmount = visibleAmount; - this.unitIncrement = unitIncrement; - this.blockIncrement = blockIncrement; - } - - public void addAdjustmentListener (AdjustmentListener listener) - { - AWTEventMulticaster.add (adjustmentListener, listener); - } - - public void removeAdjustmentListener (AdjustmentListener listener) - { - AWTEventMulticaster.remove (adjustmentListener, listener); - } - - public AdjustmentListener[] getAdjustmentListeners () - { - return (AdjustmentListener[]) AWTEventMulticaster.getListeners - (adjustmentListener, AdjustmentListener.class); - } - - public int getBlockIncrement () - { - return blockIncrement; - } - - public int getMaximum () - { - return maximum; - } - - public int getMinimum () - { - return minimum; - } - - public int getOrientation () - { - return orientation; - } - - public int getUnitIncrement () - { - return unitIncrement; - } - - public int getValue () - { - return value; - } - - public int getVisibleAmount () - { - return visibleAmount; - } - - public void setBlockIncrement (int blockIncrement) - { - this.blockIncrement = blockIncrement; - } - - public void setMaximum (int maximum) - { - this.maximum = maximum; - } - - public void setMinimum (int minimum) - { - this.minimum = minimum; - } - - public void setUnitIncrement (int unitIncrement) - { - this.unitIncrement = unitIncrement; - } - - public void setValue (int value) - { - this.value = value; - - if (value < minimum) - minimum = value; - - if (value > maximum) - maximum = value; - } - - public void setVisibleAmount (int visibleAmount) - { - this.visibleAmount = visibleAmount; - } - - public String paramString () - { - throw new Error ("not implemented"); - } - - /** - * Returns true if the value is in the process of changing. - * - * @since 1.4 - */ - public boolean getValueIsAdjusting () - { - return valueIsAdjusting; - } - - /** - * Sets the value of valueIsAdjusting. - * - * @since 1.4 - */ - public void setValueIsAdjusting (boolean valueIsAdjusting) - { - this.valueIsAdjusting = valueIsAdjusting; - } -} // class ScrollPaneAdjustable - diff --git a/libjava/java/awt/Scrollbar.java b/libjava/java/awt/Scrollbar.java deleted file mode 100644 index 6e506c78584..00000000000 --- a/libjava/java/awt/Scrollbar.java +++ /dev/null @@ -1,825 +0,0 @@ -/* Scrollbar.java -- AWT Scrollbar widget - Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005 - Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.awt.event.AdjustmentEvent; -import java.awt.event.AdjustmentListener; -import java.awt.peer.ScrollbarPeer; -import java.util.EventListener; - -import javax.accessibility.Accessible; -import javax.accessibility.AccessibleContext; -import javax.accessibility.AccessibleRole; -import javax.accessibility.AccessibleState; -import javax.accessibility.AccessibleStateSet; -import javax.accessibility.AccessibleValue; - -/** - * This class implements a scrollbar widget. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Tom Tromey (tromey@cygnus.com) - * @author Andrew John Hughes (gnu_andrew@member.fsf.org) - */ -public class Scrollbar extends Component implements Accessible, Adjustable -{ - // FIXME: Serialization readObject/writeObject - - /** - * Constant indicating that a scrollbar is horizontal. - */ - public static final int HORIZONTAL = 0; - - /** - * Constant indicating that a scrollbar is vertical. - */ - public static final int VERTICAL = 1; - - /** - * Serialization Constant. - */ - private static final long serialVersionUID = 8451667562882310543L; - - /** - * @serial The amount by which the value of the scrollbar is changed - * when incrementing in line mode. - */ - private int lineIncrement; - - /** - * @serial The amount by which the value of the scrollbar is changed - * when incrementing in page mode. - */ - private int pageIncrement; - - /** - * @serial The maximum value for this scrollbar - */ - private int maximum; - - /** - * @serial The minimum value for this scrollbar - */ - private int minimum; - - /** - * @serial The orientation of this scrollbar, which will be either - * the <code>HORIZONTAL</code> or <code>VERTICAL</code> constant - * from this class. - */ - private int orientation; - - /** - * @serial The current value of this scrollbar. - */ - private int value; - - /** - * @serial The width of the scrollbar's thumb, which is relative - * to the minimum and maximum value of the scrollbar. - */ - private int visibleAmount; - - /** - * List of AdjustmentListener's. - */ - private AdjustmentListener adjustment_listeners; - - /** - * true if the scrollbar is adjusting, false otherwise. - */ - private transient boolean valueIsAdjusting = false; - - /** - * The number used to generate the name returned by getName. - */ - private static transient long next_scrollbar_number; - - /** - * Initializes a new instance of <code>Scrollbar</code> with a - * vertical orientation and default values for all other parameters. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true, - */ - public Scrollbar() - { - this(VERTICAL); - } - - /** - * Initializes a new instance of <code>Scrollbar</code> with the - * specified orientation and default values for all other parameters. - * The orientation must be either the constant <code>HORIZONTAL</code> or - * <code>VERTICAL</code> from this class. An incorrect value will throw - * an exception. - * - * @param orientation The orientation of this scrollbar. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true, - * @exception IllegalArgumentException If the orientation value is not valid. - */ - public Scrollbar(int orientation) throws IllegalArgumentException - { - this(orientation, 0, 10, 0, 100); - } - - /** - * Initializes a new instance of <code>Scrollbar</code> with the - * specified parameters. The orientation must be either the constant - * <code>HORIZONTAL</code> or <code>VERTICAL</code>. An incorrect value - * will throw an exception. Inconsistent values for other parameters - * are silently corrected to valid values. - * - * @param orientation The orientation of this scrollbar. - * @param value The initial value of the scrollbar. - * @param visibleAmount The width of the scrollbar thumb. - * @param minimum The minimum value of the scrollbar. - * @param maximum The maximum value of the scrollbar. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true, - * @exception IllegalArgumentException If the orientation value is not valid. - */ - public Scrollbar(int orientation, int value, int visibleAmount, int minimum, - int maximum) throws IllegalArgumentException - { - if (GraphicsEnvironment.isHeadless()) - throw new HeadlessException(); - - if ((orientation != HORIZONTAL) && (orientation != VERTICAL)) - throw new IllegalArgumentException("Bad orientation value: " - + orientation); - - this.orientation = orientation; - - setValues(value, visibleAmount, minimum, maximum); - - // Default is 1 according to online docs. - lineIncrement = 1; - - // Default is 10 according to javadocs. - pageIncrement = 10; - } - - /** - * Returns the orientation constant for this object. - * - * @return The orientation constant for this object. - */ - public int getOrientation() - { - return orientation; - } - - /** - * Sets the orientation of this scrollbar to the specified value. This - * value must be either the constant <code>HORIZONTAL</code> or - * <code>VERTICAL</code> from this class or an exception will be thrown. - * - * @param orientation The new orientation value. - * - * @exception IllegalArgumentException If the orientation value is not valid. - */ - public void setOrientation(int orientation) - { - if ((orientation != HORIZONTAL) && (orientation != VERTICAL)) - throw new IllegalArgumentException("Bad orientation value: " - + orientation); - - // FIXME: Communicate to peer? Or must this be called before peer creation? - this.orientation = orientation; - } - - /** - * Returns the current value for this scrollbar. - * - * @return The current value for this scrollbar. - */ - public int getValue() - { - return value; - } - - /** - * Sets the current value for this scrollbar to the specified value. - * If this is inconsistent with the minimum and maximum values for this - * scrollbar, the value is silently adjusted. - * - * @param value The new value for this scrollbar. - */ - public void setValue(int value) - { - setValues(value, visibleAmount, minimum, maximum); - } - - /** - * Returns the maximum value for this scrollbar. - * - * @return The maximum value for this scrollbar. - */ - public int getMaximum() - { - return maximum; - } - - /** - * Sets the maximum value for this scrollbar to the specified value. - * If the value is less than the current minimum value, it is silent - * set to equal the minimum value. - * - * @param maximum The new maximum value for this scrollbar. - */ - public void setMaximum(int maximum) - { - setValues(value, visibleAmount, minimum, maximum); - } - - /** - * Returns the minimum value for this scrollbar. - * - * @return The minimum value for this scrollbar. - */ - public int getMinimum() - { - return minimum; - } - - /** - * Sets the minimum value for this scrollbar to the specified value. If - * this is not consistent with the current value and maximum, it is - * silently adjusted to be consistent. - * - * @param minimum The new minimum value for this scrollbar. - */ - public void setMinimum(int minimum) - { - setValues(value, visibleAmount, minimum, maximum); - } - - /** - * Returns the width of the scrollbar's thumb, in units relative to the - * maximum and minimum value of the scrollbar. - * - * @return The width of the scrollbar's thumb. - */ - public int getVisibleAmount() - { - return getVisible(); - } - - /** - * Returns the width of the scrollbar's thumb, in units relative to the - * maximum and minimum value of the scrollbar. - * - * @return The width of the scrollbar's thumb. - * - * @deprecated This method is deprecated in favor of - * <code>getVisibleAmount()</code>. - */ - public int getVisible() - { - return visibleAmount; - } - - /** - * Sets the width of the scrollbar's thumb, in units relative to the - * maximum and minimum value of the scrollbar. - * - * @param visibleAmount The new visible amount value of the scrollbar. - */ - public void setVisibleAmount(int visibleAmount) - { - setValues(value, visibleAmount, minimum, maximum); - } - - /** - * Sets the current value, visible amount, minimum, and maximum for this - * scrollbar. These values are adjusted to be internally consistent - * if necessary. - * - * @param value The new value for this scrollbar. - * @param visibleAmount The new visible amount for this scrollbar. - * @param minimum The new minimum value for this scrollbar. - * @param maximum The new maximum value for this scrollbar. - */ - public synchronized void setValues(int value, int visibleAmount, - int minimum, int maximum) - { - if (maximum < minimum) - maximum = minimum; - - if (value < minimum) - value = minimum; - - if (value > maximum) - value = maximum; - - if (visibleAmount > maximum - minimum) - visibleAmount = maximum - minimum; - - ScrollbarPeer peer = (ScrollbarPeer) getPeer(); - if (peer != null - && (this.value != value || this.visibleAmount != visibleAmount - || this.minimum != minimum || this.maximum != maximum)) - peer.setValues(value, visibleAmount, minimum, maximum); - - this.value = value; - this.visibleAmount = visibleAmount; - this.minimum = minimum; - this.maximum = maximum; - - int range = maximum - minimum; - if (lineIncrement > range) - { - if (range == 0) - lineIncrement = 1; - else - lineIncrement = range; - - if (peer != null) - peer.setLineIncrement(lineIncrement); - } - - if (pageIncrement > range) - { - if (range == 0) - pageIncrement = 1; - else - pageIncrement = range; - - if (peer != null) - peer.setPageIncrement(pageIncrement); - } - } - - /** - * Returns the value added or subtracted when the user activates the scrollbar - * scroll by a "unit" amount. - * - * @return The unit increment value. - */ - public int getUnitIncrement() - { - return getLineIncrement(); - } - - /** - * Returns the value added or subtracted when the user selects the scrollbar - * scroll by a "unit" amount control. - * - * @return The unit increment value. - * - * @deprecated This method is deprecated in favor of - * <code>getUnitIncrement()</code>. - */ - public int getLineIncrement() - { - return lineIncrement; - } - - /** - * Sets the value added or subtracted to the scrollbar value when the - * user selects the scroll by a "unit" amount control. - * - * @param unitIncrement The new unit increment amount. - */ - public synchronized void setUnitIncrement(int unitIncrement) - { - setLineIncrement(unitIncrement); - } - - /** - * Sets the value added or subtracted to the scrollbar value when the - * user selects the scroll by a "unit" amount control. - * - * @param lineIncrement The new unit increment amount. - * - * @deprecated This method is deprecated in favor of - * <code>setUnitIncrement()</code>. - */ - public void setLineIncrement(int lineIncrement) - { - if (lineIncrement < 0) - throw new IllegalArgumentException("Unit increment less than zero."); - - int range = maximum - minimum; - if (lineIncrement > range) - { - if (range == 0) - lineIncrement = 1; - else - lineIncrement = range; - } - - if (lineIncrement == this.lineIncrement) - return; - - this.lineIncrement = lineIncrement; - - ScrollbarPeer peer = (ScrollbarPeer) getPeer(); - if (peer != null) - peer.setLineIncrement(this.lineIncrement); - } - - /** - * Returns the value added or subtracted when the user activates the scrollbar - * scroll by a "block" amount. - * - * @return The block increment value. - */ - public int getBlockIncrement() - { - return getPageIncrement(); - } - - /** - * Returns the value added or subtracted when the user selects the scrollbar - * scroll by a "block" amount control. - * - * @return The block increment value. - * - * @deprecated This method is deprecated in favor of - * <code>getBlockIncrement()</code>. - */ - public int getPageIncrement() - { - return pageIncrement; - } - - /** - * Sets the value added or subtracted to the scrollbar value when the - * user selects the scroll by a "block" amount control. - * - * @param blockIncrement The new block increment amount. - */ - public synchronized void setBlockIncrement(int blockIncrement) - { - setPageIncrement(blockIncrement); - } - - /** - * Sets the value added or subtracted to the scrollbar value when the - * user selects the scroll by a "block" amount control. - * - * @param pageIncrement The new block increment amount. - * - * @deprecated This method is deprecated in favor of - * <code>setBlockIncrement()</code>. - */ - public void setPageIncrement(int pageIncrement) - { - if (pageIncrement < 0) - throw new IllegalArgumentException("Block increment less than zero."); - - int range = maximum - minimum; - if (pageIncrement > range) - { - if (range == 0) - pageIncrement = 1; - else - pageIncrement = range; - } - - if (pageIncrement == this.pageIncrement) - return; - - this.pageIncrement = pageIncrement; - - ScrollbarPeer peer = (ScrollbarPeer) getPeer(); - if (peer != null) - peer.setPageIncrement(this.pageIncrement); - } - - /** - * Notifies this object to create its native peer. - */ - public synchronized void addNotify() - { - if (peer == null) - peer = getToolkit().createScrollbar(this); - super.addNotify(); - } - - /** - * Adds a new adjustment listener to the list of registered listeners - * for this object. - * - * @param listener The listener to add. - */ - public synchronized void addAdjustmentListener(AdjustmentListener listener) - { - adjustment_listeners = AWTEventMulticaster.add(adjustment_listeners, - listener); - enableEvents(AWTEvent.ADJUSTMENT_EVENT_MASK); - } - - /** - * Removes the specified listener from the list of registered listeners - * for this object. - * - * @param listener The listener to remove. - */ - public synchronized void removeAdjustmentListener(AdjustmentListener listener) - { - adjustment_listeners = AWTEventMulticaster.remove(adjustment_listeners, - listener); - } - - /** - * Processes events for this scrollbar. It does this by calling - * <code>processAdjustmentEvent()</code> if the event is an instance of - * <code>AdjustmentEvent</code>, otherwise it calls the superclass to - * process the event. - * - * @param event The event to process. - */ - protected void processEvent(AWTEvent event) - { - if (event instanceof AdjustmentEvent) - processAdjustmentEvent((AdjustmentEvent) event); - else - super.processEvent(event); - } - - /** - * Processes adjustment events for this object by dispatching them to - * any registered listeners. Note that this method will only be called - * if adjustment events are enabled. This will happen automatically if - * any listeners are registered. Otherwise, it can be enabled by a - * call to <code>enableEvents()</code>. - * - * @param event The event to process. - */ - protected void processAdjustmentEvent(AdjustmentEvent event) - { - value = event.getValue(); - if (adjustment_listeners != null) - adjustment_listeners.adjustmentValueChanged(event); - } - - void dispatchEventImpl(AWTEvent e) - { - if (e.id <= AdjustmentEvent.ADJUSTMENT_LAST - && e.id >= AdjustmentEvent.ADJUSTMENT_FIRST - && (adjustment_listeners != null - || (eventMask & AWTEvent.ADJUSTMENT_EVENT_MASK) != 0)) - processEvent(e); - else - super.dispatchEventImpl(e); - } - - /** - * Returns a debugging string for this object. - * - * @return A debugging string for this object. - */ - protected String paramString() - { - return ("value=" + getValue() + ",visibleAmount=" + getVisibleAmount() - + ",minimum=" + getMinimum() + ",maximum=" + getMaximum() - + ",pageIncrement=" + pageIncrement + ",lineIncrement=" - + lineIncrement + ",orientation=" - + (orientation == HORIZONTAL ? "HORIZONTAL" : "VERTICAL") - + super.paramString()); - } - - /** - * Returns an array of all the objects currently registered as FooListeners - * upon this <code>Scrollbar</code>. FooListeners are registered using the - * addFooListener method. - * - * @exception ClassCastException If listenerType doesn't specify a class or - * interface that implements java.util.EventListener. - */ - public EventListener[] getListeners(Class listenerType) - { - if (listenerType == AdjustmentListener.class) - return AWTEventMulticaster.getListeners(adjustment_listeners, - listenerType); - - return super.getListeners(listenerType); - } - - /** - * Returns an array of all registered adjustment listeners. - */ - public AdjustmentListener[] getAdjustmentListeners() - { - return (AdjustmentListener[]) getListeners(AdjustmentListener.class); - } - - /** - * Returns true if the value is in the process of changing. - * - * @since 1.4 - */ - public boolean getValueIsAdjusting() - { - return valueIsAdjusting; - } - - /** - * Sets the value of valueIsAdjusting. - * - * @since 1.4 - */ - public void setValueIsAdjusting(boolean valueIsAdjusting) - { - this.valueIsAdjusting = valueIsAdjusting; - } - - /** - * Generate a unique name for this scroll bar. - * - * @return A unique name for this scroll bar. - */ - String generateName() - { - return "scrollbar" + getUniqueLong(); - } - - private static synchronized long getUniqueLong() - { - return next_scrollbar_number++; - } - - /** - * This class provides accessibility support for the - * scrollbar. - * - * @author Jerry Quinn (jlquinn@optonline.net) - * @author Andrew John Hughes (gnu_andrew@member.fsf.org) - */ - protected class AccessibleAWTScrollBar extends AccessibleAWTComponent - implements AccessibleValue - { - /** - * Serialization constant to match JDK 1.5 - */ - private static final long serialVersionUID = -344337268523697807L; - - /** - * Returns the role of this accessible object. - * - * @return the instance of <code>AccessibleRole</code>, - * which describes this object. - * - * @see javax.accessibility.AccessibleRole - */ - public AccessibleRole getAccessibleRole() - { - return AccessibleRole.SCROLL_BAR; - } - - /** - * Returns the state set of this accessible object. - * - * @return a set of <code>AccessibleState</code>s which - * represent the current state of the accessible object. - * - * @see javax.accessibility.AccessibleState - * @see javax.accessibility.AccessibleStateSet - */ - public AccessibleStateSet getAccessibleStateSet() - { - AccessibleStateSet states = super.getAccessibleStateSet(); - if (getOrientation() == HORIZONTAL) - states.add(AccessibleState.HORIZONTAL); - else - states.add(AccessibleState.VERTICAL); - if (getValueIsAdjusting()) - states.add(AccessibleState.BUSY); - return states; - } - - /** - * Returns an implementation of the <code>AccessibleValue</code> - * interface for this accessible object. In this case, the - * current instance is simply returned (with a more appropriate - * type), as it also implements the accessible value as well as - * the context. - * - * @return the accessible value associated with this context. - * - * @see javax.accessibility.AccessibleValue - */ - public AccessibleValue getAccessibleValue() - { - return this; - } - - /** - * Returns the current value of this accessible object. - * In this case, this is the same as the value for - * the scrollbar, wrapped in an <code>Integer</code> - * object. - * - * @return the numeric value of this scrollbar. - * - * @see javax.accessibility.AccessibleValue#getCurrentAccessibleValue() - */ - public Number getCurrentAccessibleValue() - { - return new Integer(getValue()); - } - - /** - * Sets the current value of this accessible object - * to that supplied. In this case, the value of the - * scrollbar is set, and this method always returns - * true. - * - * @param number the new accessible value. - * - * @return true if the value was set. - * - * @see javax.accessibility.AccessibleValue#setCurrentAccessibleValue(java.lang.Number) - */ - public boolean setCurrentAccessibleValue(Number number) - { - setValue(number.intValue()); - return true; - } - - /** - * Returns the minimum acceptable accessible value used - * by this object. In this case, this is the same as - * the minimum value of the scrollbar, wrapped in an - * object. - * - * @return the minimum value of this scrollbar. - * - * @see javax.accessibility.AccessibleValue#getMinimumAccessibleValue() - */ - public Number getMinimumAccessibleValue() - { - return new Integer(getMinimum()); - } - - /** - * Returns the maximum acceptable accessible value used - * by this object. In this case, this is the same as - * the maximum value of the scrollbar, wrapped in an - * object. - * - * @return the maximum value of this scrollbar. - * - * @see javax.accessibility.AccessibleValue#getMaximumAccessibleValue() - */ - public Number getMaximumAccessibleValue() - { - return new Integer(getMaximum()); - } - } - - /** - * Gets the AccessibleContext associated with this <code>Scrollbar</code>. - * The context is created, if necessary. - * - * @return the associated context - */ - public AccessibleContext getAccessibleContext() - { - /* Create the context if this is the first request */ - if (accessibleContext == null) - accessibleContext = new AccessibleAWTScrollBar(); - - return accessibleContext; - } -} diff --git a/libjava/java/awt/Shape.java b/libjava/java/awt/Shape.java deleted file mode 100644 index bd8a4343528..00000000000 --- a/libjava/java/awt/Shape.java +++ /dev/null @@ -1,203 +0,0 @@ -/* Shape.java -- the classic Object-Oriented shape interface - Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.awt.geom.AffineTransform; -import java.awt.geom.PathIterator; -import java.awt.geom.Point2D; -import java.awt.geom.Rectangle2D; - -/** - * This interface represents an abstract shape. The shape is described by - * a {@link PathIterator}, and has callbacks for determining bounding box, - * where points and rectangles lie in relation to the shape, and tracing - * the trajectory. - * - * <p>A point is inside if it is completely inside, or on the boundary and - * adjacent points in the increasing x or y direction are completely inside. - * Unclosed shapes are considered as implicitly closed when performing - * <code>contains</code> or <code>intersects</code>. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @see PathIterator - * @see AffineTransform - * @see java.awt.geom.FlatteningPathIterator - * @see java.awt.geom.GeneralPath - * @since 1.0 - * @status updated to 1.4 - */ -public interface Shape -{ - /** - * Returns a <code>Rectange</code> that bounds the shape. There is no - * guarantee that this is the minimum bounding box, particularly if - * the shape overflows the finite integer range of a bound. Generally, - * <code>getBounds2D</code> returns a tighter bound. - * - * @return the shape's bounding box - * @see #getBounds2D() - */ - Rectangle getBounds(); - - /** - * Returns a high precision bounding box of the shape. There is no guarantee - * that this is the minimum bounding box, but at least it never overflows. - * - * @return the shape's bounding box - * @see #getBounds() - * @since 1.2 - */ - Rectangle2D getBounds2D(); - - /** - * Test if the coordinates lie in the shape. - * - * @param x the x coordinate - * @param y the y coordinate - * @return true if (x,y) lies inside the shape - * @since 1.2 - */ - boolean contains(double x, double y); - - /** - * Test if the point lie in the shape. - * - * @param p the high-precision point - * @return true if p lies inside the shape - * @throws NullPointerException if p is null - * @since 1.2 - */ - boolean contains(Point2D p); - - /** - * Test if a high-precision rectangle intersects the shape. This is true - * if any point in the rectangle is in the shape, with the caveat that the - * operation may include high probability estimates when the actual - * calculation is prohibitively expensive. The {@link java.awt.geom.Area} - * class can be used for more precise answers. - * - * @param x the x coordinate of the rectangle - * @param y the y coordinate of the rectangle - * @param w the width of the rectangle, undefined results if negative - * @param h the height of the rectangle, undefined results if negative - * @return true if the rectangle intersects this shape - * @see java.awt.geom.Area - * @since 1.2 - */ - boolean intersects(double x, double y, double w, double h); - - /** - * Test if a high-precision rectangle intersects the shape. This is true - * if any point in the rectangle is in the shape, with the caveat that the - * operation may include high probability estimates when the actual - * calculation is prohibitively expensive. The {@link java.awt.geom.Area} - * class can be used for more precise answers. - * - * @param r the rectangle - * @return true if the rectangle intersects this shape - * @throws NullPointerException if r is null - * @see #intersects(double, double, double, double) - * @since 1.2 - */ - boolean intersects(Rectangle2D r); - - /** - * Test if a high-precision rectangle lies completely in the shape. This is - * true if all points in the rectangle are in the shape, with the caveat - * that the operation may include high probability estimates when the actual - * calculation is prohibitively expensive. The {@link java.awt.geom.Area} - * class can be used for more precise answers. - * - * @param x the x coordinate of the rectangle - * @param y the y coordinate of the rectangle - * @param w the width of the rectangle, undefined results if negative - * @param h the height of the rectangle, undefined results if negative - * @return true if the rectangle is contained in this shape - * @see java.awt.geom.Area - * @since 1.2 - */ - boolean contains(double x, double y, double w, double h); - - /** - * Test if a high-precision rectangle lies completely in the shape. This is - * true if all points in the rectangle are in the shape, with the caveat - * that the operation may include high probability estimates when the actual - * calculation is prohibitively expensive. The {@link java.awt.geom.Area} - * class can be used for more precise answers. - * - * @param r the rectangle - * @return true if the rectangle is contained in this shape - * @throws NullPointerException if r is null - * @see #contains(double, double, double, double) - * @since 1.2 - */ - boolean contains(Rectangle2D r); - - /** - * Return an iterator along the shape boundary. If the optional transform - * is provided, the iterator is transformed accordingly. Each call returns - * a new object, independent from others in use. It is recommended, but - * not required, that the Shape isolate iterations from future changes to - * the boundary, and document this fact. - * - * @param transform an optional transform to apply to the iterator - * @return a new iterator over the boundary - * @since 1.2 - */ - PathIterator getPathIterator(AffineTransform transform); - - /** - * Return an iterator along the flattened version of the shape boundary. - * Only SEG_MOVETO, SEG_LINETO, and SEG_CLOSE points are returned in the - * iterator. The flatness paramter controls how far points are allowed to - * differ from the real curve; although a limit on accuracy may cause this - * parameter to be enlarged if needed. - * - * <p>If the optional transform is provided, the iterator is transformed - * accordingly. Each call returns a new object, independent from others in - * use. It is recommended, but not required, that the Shape isolate - * iterations from future changes to the boundary, and document this fact. - * - * @param transform an optional transform to apply to the iterator - * @param flatness the maximum distance for deviation from the real boundary - * @return a new iterator over the boundary - * @since 1.2 - */ - PathIterator getPathIterator(AffineTransform transform, double flatness); -} // interface Shape diff --git a/libjava/java/awt/Stroke.java b/libjava/java/awt/Stroke.java deleted file mode 100644 index 1a4c61cfb1f..00000000000 --- a/libjava/java/awt/Stroke.java +++ /dev/null @@ -1,65 +0,0 @@ -/* Stroke.java -- a stroked outline of a shape - Copyright (C) 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -/** - * This interface allows a Graphics2D to grab the outline of a shape, as if - * stroked by a marking pen of appropriate size and shape. The area inked - * by the pen is the area of this stroke. Anything in the graphic which - * traces an outline will use this stroke, such as <code>drawLine</code>. - * Strokes must be immutable, because the graphics object does not clone - * them. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @see BasicStroke - * @see Graphics2D#setStroke(Stroke) - * @since 1.1 - * @status updated to 1.4 - */ -public interface Stroke -{ - /** - * Returns a shape which outlines the boundary of the given shape, in - * effect converting the infinitely thin line into a new shape. - * - * @param s the shape to stroke - * @return the stroked outline shape - */ - Shape createStrokedShape(Shape s); -} // interface Stroke diff --git a/libjava/java/awt/SystemColor.java b/libjava/java/awt/SystemColor.java deleted file mode 100644 index 2ead74a0dbd..00000000000 --- a/libjava/java/awt/SystemColor.java +++ /dev/null @@ -1,462 +0,0 @@ -/* SystemColor.java -- access dynamic system color values - Copyright (C) 1999, 2002, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.awt.geom.AffineTransform; -import java.awt.geom.Rectangle2D; -import java.awt.image.ColorModel; -import java.io.Serializable; - -/** - * This class contains the various "system colors" in use by the native - * windowing system. The <code>getRGB()</code> method is dynamic on systems - * which support dynamic system color changes, and most methods in the - * superclass are written to use this dynamic value when reporting colors. - * However, the <code>equals()</code> method is not dynamic, and does not - * track the actual color of instances in this class. This means that equals - * may give surprising results; you are better off relying on getRGB. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.1 - * @status updated to 1.4 - */ -public final class SystemColor extends Color implements Serializable -{ - // Implementation note: To be serial compatible with JDK, this class must - // violate the semantic meaning of super.value to be one of the - // NUM_COLORS constants instead of the actual RGB value. Hence there are - // a lot of ugly workarounds in Color and in this class. I would have - // designed it MUCH differently, making a separate id field in this class. - - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = 4503142729533789064L; - - /** - * Array index of the desktop color. Used by - * {@link Toolkit#loadSystemColors(int[])}. - * - * @see #desktop - */ - public static final int DESKTOP = 0; - - /** - * Array index of the active caption color. Used by - * {@link Toolkit#loadSystemColors(int[])}. - * - * @see #activeCaption - */ - public static final int ACTIVE_CAPTION = 1; - - /** - * Array index of the active caption text color. Used by - * {@link Toolkit#loadSystemColors(int[])}. - * - * @see #activeCaptionText - */ - public static final int ACTIVE_CAPTION_TEXT = 2; - - /** - * Array index of the active caption border color. Used by - * {@link Toolkit#loadSystemColors(int[])}. - * - * @see #activeCaptionBorder - */ - public static final int ACTIVE_CAPTION_BORDER = 3; - - /** - * Array index of the inactive caption color. Used by - * {@link Toolkit#loadSystemColors(int[])}. - * - * @see #inactiveCaption - */ - public static final int INACTIVE_CAPTION = 4; - - /** - * Array index of the inactive caption text color. Used by - * {@link Toolkit#loadSystemColors(int[])}. - * - * @see #inactiveCaptionText - */ - public static final int INACTIVE_CAPTION_TEXT = 5; - - /** - * Array index of the inactive caption border color. Used by - * {@link Toolkit#loadSystemColors(int[])}. - * - * @see #inactiveCaptionBorder - */ - public static final int INACTIVE_CAPTION_BORDER = 6; - - /** - * Array index of the window background color. Used by - * {@link Toolkit#loadSystemColors(int[])}. - * - * @see #window - */ - public static final int WINDOW = 7; - - /** - * Array index of the window border color. Used by - * {@link Toolkit#loadSystemColors(int[])}. - * - * @see #windowBorder - */ - public static final int WINDOW_BORDER = 8; - - /** - * Array index of the window text color. Used by - * {@link Toolkit#loadSystemColors(int[])}. - * - * @see #windowText - */ - public static final int WINDOW_TEXT = 9; - - /** - * Array index of the menu background color. Used by - * {@link Toolkit#loadSystemColors(int[])}. - * - * @see #menu - */ - public static final int MENU = 10; - - /** - * Array index of the menu text color. Used by - * {@link Toolkit#loadSystemColors(int[])}. - * - * @see #menuText - */ - public static final int MENU_TEXT = 11; - - /** - * Array index of the text background color. Used by - * {@link Toolkit#loadSystemColors(int[])}. - * - * @see #text - */ - public static final int TEXT = 12; - - /** - * Array index of the text foreground color. Used by - * {@link Toolkit#loadSystemColors(int[])}. - * - * @see #textText - */ - public static final int TEXT_TEXT = 13; - - /** - * Array index of the highlighted text background color. Used by - * {@link Toolkit#loadSystemColors(int[])}. - * - * @see #textHighlight - */ - public static final int TEXT_HIGHLIGHT = 14; - - /** - * Array index of the highlighted text foreground color. Used by - * {@link Toolkit#loadSystemColors(int[])}. - * - * @see #textHighlightText - */ - public static final int TEXT_HIGHLIGHT_TEXT = 15; - - /** - * Array index of the inactive text foreground color. Used by - * {@link Toolkit#loadSystemColors(int[])}. - * - * @see #textInactiveText - */ - public static final int TEXT_INACTIVE_TEXT = 16; - - /** - * Array index of the control background color. Used by - * {@link Toolkit#loadSystemColors(int[])}. - * - * @see #control - */ - public static final int CONTROL = 17; - - /** - * Array index of the control text color. Used by - * {@link Toolkit#loadSystemColors(int[])}. - * - * @see #controlText - */ - public static final int CONTROL_TEXT = 18; - - /** - * Array index of the highlighted control background color. Used by - * {@link Toolkit#loadSystemColors(int[])}. - * - * @see #controlHighlight - */ - public static final int CONTROL_HIGHLIGHT = 19; - - /** - * Array index of the lightly highlighted control background color. Used by - * {@link Toolkit#loadSystemColors(int[])}. - * - * @see #controlLtHighlight - */ - public static final int CONTROL_LT_HIGHLIGHT = 20; - - /** - * Array index of the shadowed control background color. Used by - * {@link Toolkit#loadSystemColors(int[])}. - * - * @see #controlShadow - */ - public static final int CONTROL_SHADOW = 21; - - /** - * Array index of the darkly shadowed control background color. Used by - * {@link Toolkit#loadSystemColors(int[])}. - * - * @see #controlDkShadow - */ - public static final int CONTROL_DK_SHADOW = 22; - - /** - * Array index of the scrollbar background color. Used by - * {@link Toolkit#loadSystemColors(int[])}. - * - * @see #scrollbar - */ - public static final int SCROLLBAR = 23; - - /** - * Array index of the info background color. Used by - * {@link Toolkit#loadSystemColors(int[])}. - * - * @see #info - */ - public static final int INFO = 24; - - /** - * Array index of the info text color. Used by - * {@link Toolkit#loadSystemColors(int[])}. - * - * @see #infoText - */ - public static final int INFO_TEXT = 25; - - /** - * The number of system colors. Used by - * {@link Toolkit#loadSystemColors(int[])}. - */ - public static final int NUM_COLORS = 26; - - /** - * The internal array used to dynamically update <code>getRGB()</code>. - */ - private static final int[] colors = new int[NUM_COLORS]; - - /** The desktop color. */ - public static final SystemColor desktop - = new SystemColor(DESKTOP); - - /** The active caption background color. */ - public static final SystemColor activeCaption - = new SystemColor(ACTIVE_CAPTION); - - /** The active caption text color. */ - public static final SystemColor activeCaptionText - = new SystemColor(ACTIVE_CAPTION_TEXT); - - /** The active caption border color. */ - public static final SystemColor activeCaptionBorder - = new SystemColor(ACTIVE_CAPTION_BORDER); - - /** The inactive caption background color. */ - public static final SystemColor inactiveCaption - = new SystemColor(INACTIVE_CAPTION); - - /** The inactive caption text color. */ - public static final SystemColor inactiveCaptionText - = new SystemColor(INACTIVE_CAPTION_TEXT); - - /** The inactive caption border color. */ - public static final SystemColor inactiveCaptionBorder - = new SystemColor(INACTIVE_CAPTION_BORDER); - - /** The window background color. */ - public static final SystemColor window - = new SystemColor(WINDOW); - - /** The window border color. */ - public static final SystemColor windowBorder - = new SystemColor(WINDOW_BORDER); - - /** The window text color. */ - public static final SystemColor windowText - = new SystemColor(WINDOW_TEXT); - - /** The menu background color. */ - public static final SystemColor menu - = new SystemColor(MENU); - - /** The menu text color. */ - public static final SystemColor menuText - = new SystemColor(MENU_TEXT); - - /** The text background color. */ - public static final SystemColor text - = new SystemColor(TEXT); - - /** The text foreground color. */ - public static final SystemColor textText - = new SystemColor(TEXT_TEXT); - - /** The highlighted text background color. */ - public static final SystemColor textHighlight - = new SystemColor(TEXT_HIGHLIGHT); - - /** The highlighted text foreground color. */ - public static final SystemColor textHighlightText - = new SystemColor(TEXT_HIGHLIGHT_TEXT); - - /** The inactive text color. */ - public static final SystemColor textInactiveText - = new SystemColor(TEXT_INACTIVE_TEXT); - - /** The control background color. */ - public static final SystemColor control - = new SystemColor(CONTROL); - - /** The control text color. */ - public static final SystemColor controlText - = new SystemColor(CONTROL_TEXT); - - /** The control highlight color. */ - public static final SystemColor controlHighlight - = new SystemColor(CONTROL_HIGHLIGHT); - - /** The control light highlight color. */ - public static final SystemColor controlLtHighlight - = new SystemColor(CONTROL_LT_HIGHLIGHT); - - /** The control shadow color. */ - public static final SystemColor controlShadow - = new SystemColor(CONTROL_SHADOW); - - /** The control dark shadow color. */ - public static final SystemColor controlDkShadow - = new SystemColor(CONTROL_DK_SHADOW); - - /** The scrollbar color. */ - public static final SystemColor scrollbar - = new SystemColor(SCROLLBAR); - - /** The info text background color. */ - public static final SystemColor info - = new SystemColor(INFO); - - /** The info text foreground color. */ - public static final SystemColor infoText - = new SystemColor(INFO_TEXT); - - /** - * Construct a system color which is dynamically updated. - * - * @param id the color id - */ - private SystemColor(int id) - { - // Note: See Color#Color(int, boolean) to explain why we use this - // particular constructor. - super(id, true); - } - - /** - * Returns the RGB value for this color, in the sRGB color space. The blue - * value will be in bits 0-7, green in 8-15, red in 6-23, and the alpha - * value (bits 24-31) is 0xff. This is dynamically updated, so it may not - * match the results of <code>getRed()</code>, <code>getGreen()</code>, or - * <code>getBlue()</code>. - * - * @return the current RGB value - */ - public int getRGB() - { - Toolkit.getDefaultToolkit().loadSystemColors(colors); - return colors[value] | ALPHA_MASK; - } - - /** - * Returns a paint context, used for filling areas of a raster scan with - * the current value of this system color. Since the system colors may be - * dynamically updated, the returned value may not always be the same; but - * as the system color is solid, the context does not need any of the - * passed parameters to do its job. - * - * @param cm the requested color model - * @param deviceBounds the bounding box in device coordinates, ignored - * @param userBounds the bounding box in user coordinates, ignored - * @param xform the bounds transformation, ignored - * @param hints any rendering hints, ignored - * @return a context for painting this solid color - */ - public PaintContext createContext(ColorModel cm, Rectangle deviceBounds, - Rectangle2D userBounds, - AffineTransform xform, - RenderingHints hints) - { - Toolkit.getDefaultToolkit().loadSystemColors(colors); - int color = colors[value] | ALPHA_MASK; - if (context == null || color != context.color || !context.getColorModel().equals(cm)) - context = new ColorPaintContext(cm,color); - return context; - } - - /** - * Returns a string describing this color. This is in the format - * "java.awt.SystemColor[i=" + index + ']', where index is one of the - * integer constants of this class. Unfortunately, this description - * does not describe the current value of the color; for that you should - * use <code>new Color(syscolor.getRGB()).toString()</code>. - * - * @return a string describing this color - */ - public String toString() - { - return "java.awt.SystemColor[i=" + value + ']'; - } -} // class SystemColor diff --git a/libjava/java/awt/TextArea.java b/libjava/java/awt/TextArea.java deleted file mode 100644 index d422d3306d2..00000000000 --- a/libjava/java/awt/TextArea.java +++ /dev/null @@ -1,629 +0,0 @@ -/* TextArea.java -- A multi-line text entry component - Copyright (C) 1999, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.awt.event.KeyEvent; -import java.awt.peer.ComponentPeer; -import java.awt.peer.TextAreaPeer; -import java.util.HashSet; -import java.util.Set; - -import javax.accessibility.AccessibleContext; -import javax.accessibility.AccessibleStateSet; - - -/** - * A TextArea is a text component capable of displaying multiple lines - * of user-editable text. A TextArea handles its own scrolling and - * can display vertical and horizontal scrollbars as navigation aids. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public class TextArea extends TextComponent implements java.io.Serializable -{ - /** - * Display both horiztonal and vertical scroll bars. - */ - public static final int SCROLLBARS_BOTH = 0; - - /** - * Display vertical scroll bar only. - */ - public static final int SCROLLBARS_VERTICAL_ONLY = 1; - - /** - * Display horizatonal scroll bar only. - */ - public static final int SCROLLBARS_HORIZONTAL_ONLY = 2; - - /** - * Do not display scrollbars. - */ - public static final int SCROLLBARS_NONE = 3; - - /** - * Serialization constant. - */ - private static final long serialVersionUID = 3692302836626095722L; - - /** - * @serial The number of columns used in this text area's preferred - * and minimum size calculations. - */ - private int columns; - - /** - * @serial The number of rows used in this text area's preferred and - * minimum size calculations. - */ - private int rows; - - /** - * @serial The scrollbar display policy. One of SCROLLBARS_BOTH, - * SCROLLBARS_VERTICAL_ONLY, SCROLLBARS_HORIZONTAL_ONLY, - * SCROLLBARS_NONE. - */ - private int scrollbarVisibility; - - /* - * The number used to generate the name returned by getName. - */ - private static transient long next_text_number; - - /** - * Initialize a new instance of <code>TextArea</code> that is empty. - * Conceptually the <code>TextArea</code> has 0 rows and 0 columns - * but its initial bounds are defined by its peer or by the - * container in which it is packed. Both horizontal and vertical - * scrollbars will be displayed. - * - * @exception HeadlessException if GraphicsEnvironment.isHeadless () is true - */ - public TextArea () - { - this ("", 0, 0, SCROLLBARS_BOTH); - } - - /** - * Initialize a new instance of <code>TextArea</code> that contains - * the specified text. Conceptually the <code>TextArea</code> has 0 - * rows and 0 columns but its initial bounds are defined by its peer - * or by the container in which it is packed. Both horizontal and - * veritcal scrollbars will be displayed. - * - * @param text The text to display in this text area. - * - * @exception HeadlessException if GraphicsEnvironment.isHeadless () is true - */ - public TextArea (String text) - { - this (text, 0, 0, SCROLLBARS_BOTH); - } - - /** - * Initialize a new instance of <code>TextArea</code> that is empty - * and can display the specified number of rows and columns of text, - * without the need to scroll. Both horizontal and vertical - * scrollbars will be displayed. - * - * @param rows The number of rows in this text area. - * @param columns The number of columns in this text area. - * - * @exception HeadlessException if GraphicsEnvironment.isHeadless () is true - */ - public TextArea (int rows, int columns) - { - this ("", rows, columns, SCROLLBARS_BOTH); - } - - /** - * Initialize a new instance of <code>TextArea</code> that can - * display the specified number of rows and columns of text, without - * the need to scroll. The TextArea initially contains the - * specified text. - * - * @param text The text to display in this text area. - * @param rows The number of rows in this text area. - * @param columns The number of columns in this text area. - * - * @exception HeadlessException if GraphicsEnvironment.isHeadless () is true - */ - public TextArea (String text, int rows, int columns) - { - this (text, rows, columns, SCROLLBARS_BOTH); - } - - /** - * Initialize a new instance of <code>TextArea</code> that initially - * contains the specified text. The TextArea can display the - * specified number of rows and columns of text, without the need to - * scroll. This constructor allows specification of the scroll bar - * display policy. - * - * @param text The text to display in this text area. - * @param rows The number of rows in this text area. - * @param columns The number of columns in this text area. - * @param scrollbarVisibility The scroll bar display policy. One of - * SCROLLBARS_BOTH, SCROLLBARS_VERTICAL_ONLY, - * SCROLLBARS_HORIZONTAL_ONLY, SCROLLBARS_NONE. - * - * @exception HeadlessException if GraphicsEnvironment.isHeadless () is true - */ - public TextArea (String text, int rows, int columns, int scrollbarVisibility) - { - super (text); - - if (GraphicsEnvironment.isHeadless ()) - throw new HeadlessException (); - - if (rows < 0 || columns < 0) - throw new IllegalArgumentException ("Bad row or column value"); - - if (scrollbarVisibility != SCROLLBARS_BOTH - && scrollbarVisibility != SCROLLBARS_VERTICAL_ONLY - && scrollbarVisibility != SCROLLBARS_HORIZONTAL_ONLY - && scrollbarVisibility != SCROLLBARS_NONE) - throw new IllegalArgumentException ("Bad scrollbar visibility value"); - - this.rows = rows; - this.columns = columns; - this.scrollbarVisibility = scrollbarVisibility; - - // TextAreas need to receive tab key events so we override the - // default forward and backward traversal key sets. - Set s = new HashSet (); - s.add (AWTKeyStroke.getAWTKeyStroke (KeyEvent.VK_TAB, - KeyEvent.CTRL_DOWN_MASK)); - setFocusTraversalKeys (KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, s); - s = new HashSet (); - s.add (AWTKeyStroke.getAWTKeyStroke (KeyEvent.VK_TAB, - KeyEvent.SHIFT_DOWN_MASK - | KeyEvent.CTRL_DOWN_MASK)); - setFocusTraversalKeys (KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, s); - } - - /** - * Retrieve the number of columns that this text area would prefer - * to display. This value may or may not correspond to the number - * of columns that are actually displayed. - * - * @return The preferred number of columns. - */ - public int getColumns () - { - return columns; - } - - /** - * Set the preferred number of columns for this text area. This - * method does not cause the number of columns displayed by the text - * area to be updated, if the text area is currently visible. - * - * @param columns The preferred number of columns. - * - * @exception IllegalArgumentException If columns is less than zero. - */ - public synchronized void setColumns (int columns) - { - if (columns < 0) - throw new IllegalArgumentException ("Value is less than zero: " - + columns); - - this.columns = columns; - } - - /** - * Retrieve the number of rows that this text area would prefer to - * display. This value may or may not correspond to the number of - * rows that are actually displayed. - * - * @return The preferred number of rows. - */ - public int getRows () - { - return rows; - } - - /** - * Set the preferred number of rows for this text area. This method - * does not cause the number of columns displayed by the text area - * to be updated, if the text area is currently visible. - * - * @param rows The preferred number of rows. - * - * @exception IllegalArgumentException If rows is less than zero. - */ - public synchronized void setRows (int rows) - { - if (rows < 1) - throw new IllegalArgumentException ("Value is less than one: " + rows); - - this.rows = rows; - } - - /** - * Retrieve the minimum size for this text area, considering the - * text area's current row and column values. A text area's minimum - * size depends on the number of rows and columns of text it would - * prefer to display, and on the size of the font in which the text - * would be displayed. - * - * @return The minimum size for this text field. - */ - public Dimension getMinimumSize () - { - return getMinimumSize (getRows (), getColumns ()); - } - - /** - * Retrieve the minimum size that this text area would have if its - * row and column values were equal to those specified. A text - * area's minimum size depends on the number of rows and columns of - * text it would prefer to display, and on the size of the font in - * which the text would be displayed. - * - * @param rows The number of rows to use in the minimum size - * calculation. - * @param columns The number of columns to use in the minimum size - * calculation. - * - * @return The minimum size for this text area. - */ - public Dimension getMinimumSize (int rows, int columns) - { - return minimumSize (rows, columns); - } - - /** - * Retrieve the minimum size for this text area, considering the - * text area's current row and column values. A text area's minimum - * size depends on the number of rows and columns of text it would - * prefer to display, and on the size of the font in which the text - * would be displayed. - * - * @return The minimum size for this text area. - * - * @deprecated This method is deprecated in favor of - * <code>getMinimumSize ()</code>. - */ - public Dimension minimumSize () - { - return minimumSize (getRows (), getColumns ()); - } - - /** - * Retrieve the minimum size that this text area would have if its - * row and column values were equal to those specified. A text - * area's minimum size depends on the number of rows and columns of - * text it would prefer to display, and on the size of the font in - * which the text would be displayed. - * - * @param rows The number of rows to use in the minimum size - * calculation. - * @param columns The number of columns to use in the minimum size - * calculation. - * - * @return The minimum size for this text area. - * - * @deprecated This method is deprecated in favor of - * <code>getMinimumSize (int, int)</code>. - */ - public Dimension minimumSize (int rows, int columns) - { - TextAreaPeer peer = (TextAreaPeer) getPeer (); - - // Sun returns Dimension (0,0) in this case. - if (peer == null) - return new Dimension (0, 0); - - return peer.getMinimumSize (rows, columns); - } - - /** - * Retrieve the preferred size for this text area, considering the - * text area's current row and column values. A text area's preferred - * size depends on the number of rows and columns of text it would - * prefer to display, and on the size of the font in which the text - * would be displayed. - * - * @return The preferred size for this text field. - */ - public Dimension getPreferredSize () - { - return getPreferredSize (getRows (), getColumns ()); - } - - /** - * Retrieve the preferred size that this text area would have if its - * row and column values were equal to those specified. A text - * area's preferred size depends on the number of rows and columns - * of text it would prefer to display, and on the size of the font - * in which the text would be displayed. - * - * @param rows The number of rows to use in the preferred size - * calculation. - * @param columns The number of columns to use in the preferred size - * calculation. - * - * @return The preferred size for this text area. - */ - public Dimension getPreferredSize (int rows, int columns) - { - return preferredSize (rows, columns); - } - - /** - * Retrieve the preferred size for this text area, considering the - * text area's current row and column values. A text area's preferred - * size depends on the number of rows and columns of text it would - * prefer to display, and on the size of the font in which the text - * would be displayed. - * - * @return The preferred size for this text field. - * - * @deprecated This method is deprecated in favor of - * <code>getPreferredSize ()</code>. - */ - public Dimension preferredSize () - { - return preferredSize (getRows (), getColumns ()); - } - - /** - * Retrieve the preferred size that this text area would have if its - * row and column values were equal to those specified. A text - * area's preferred size depends on the number of rows and columns - * of text it would prefer to display, and on the size of the font - * in which the text would be displayed. - * - * @param rows The number of rows to use in the preferred size - * calculation. - * @param columns The number of columns to use in the preferred size - * calculation. - * - * @return The preferred size for this text area. - * - * @deprecated This method is deprecated in favor of - * <code>getPreferredSize (int, int)</code>. - */ - public Dimension preferredSize (int rows, int columns) - { - TextAreaPeer peer = (TextAreaPeer) getPeer (); - - // Sun returns Dimension (0,0) in this case. - if (peer == null) - return new Dimension (0, 0); - - return peer.getPreferredSize (rows, columns); - } - - /** - * Retrieve the scroll bar display policy -- one of SCROLLBARS_BOTH, - * SCROLLBARS_VERTICAL_ONLY, SCROLLBARS_HORIZONTAL_ONLY, - * SCROLLBARS_NONE. - * - * @return The current scroll bar display policy. - */ - public int getScrollbarVisibility () - { - return scrollbarVisibility; - } - - /** - * Notify this object that it should create its native peer. - */ - public void addNotify () - { - if (getPeer () == null) - setPeer ((ComponentPeer) getToolkit().createTextArea (this)); - } - - /** - * Append the specified text to the end of the current text. - * - * @param str The text to append. - */ - public void append (String str) - { - appendText (str); - } - - /** - * Append the specified text to the end of the current text. - * - * @param str The text to append. - * - * @deprecated This method is deprecated in favor of - * <code>append ()</code>. - */ - public void appendText (String str) - { - TextAreaPeer peer = (TextAreaPeer) getPeer (); - - if (peer != null) - peer.insert (str, peer.getText().length ()); - } - - /** - * Insert the specified text at the specified position. The first - * character in the text area is at position zero. - * - * @param str The text to insert. - * @param pos The position at which to insert text. - */ - public void insert (String str, int pos) - { - insertText (str, pos); - } - - /** - * Insert the specified text at the specified position. The first - * character in the text area is at position zero. - * - * @param str The text to insert. - * @param pos The position at which to insert text. - * - * @deprecated This method is deprecated in favor of - * <code>insert ()</code>. - */ - public void insertText (String str, int pos) - { - TextAreaPeer peer = (TextAreaPeer) getPeer (); - - if (peer != null) - peer.insert (str, pos); - } - - /** - * Replace a range of characters with the specified text. The - * character at the start position will be replaced, unless start == - * end. The character at the end posistion will not be replaced. - * The first character in the text area is at position zero. The - * length of the replacement text may differ from the length of the - * text that is replaced. - * - * @param str The new text for the range. - * @param start The start position of the replacement range. - * @param end The end position of the replacement range. - */ - public void replaceRange (String str, int start, int end) - { - replaceText (str, start, end); - } - - /** - * Replace a range of characters with the specified text. The - * character at the start position will be replaced, unless start == - * end. The character at the end posistion will not be replaced. - * The first character in the text area is at position zero. The - * length of the replacement text may differ from the length of the - * text that is replaced. - * - * @param str The new text for the range. - * @param start The start position of the replacement range. - * @param end The end position of the replacement range. - * - * @deprecated This method is deprecated in favor of - * <code>replaceRange ()</code>. - */ - public void replaceText (String str, int start, int end) - { - TextAreaPeer peer = (TextAreaPeer) getPeer (); - - if (peer != null) - peer.replaceRange (str, start, end); - } - - /** - * Retrieve a debugging string for this text area. - * - * @return A debugging string for this text area. - */ - protected String paramString () - { - String sbVisibility = ""; - - switch (scrollbarVisibility) - { - case SCROLLBARS_BOTH: - sbVisibility = "both"; - break; - case SCROLLBARS_VERTICAL_ONLY: - sbVisibility = "vertical-only"; - break; - case SCROLLBARS_HORIZONTAL_ONLY: - sbVisibility = "horizontal-only"; - break; - case SCROLLBARS_NONE: - sbVisibility = "none"; - break; - } - - String editable = ""; - if (isEditable ()) - editable = "editable,"; - - return getName () + "," + getX () + "," + getY () + "," + getWidth () - + "x" + getHeight () + "," + "text=" + getText () + "," + editable - + "selection=" + getSelectionStart () + "-" + getSelectionEnd () - + ",rows=" + rows + ",columns=" + columns + ",scrollbarVisibility=" - + sbVisibility; - } - - /** - * Generate a unique name for this text area. - * - * @return A unique name for this text area. - */ - String generateName () - { - return "text" + getUniqueLong (); - } - - private static synchronized long getUniqueLong () - { - return next_text_number++; - } - - protected class AccessibleAWTTextArea extends AccessibleAWTTextComponent - { - protected AccessibleAWTTextArea() - { - } - - public AccessibleStateSet getAccessibleStateSet() - { - return super.getAccessibleStateSet(); - } - } - - /** - * Gets the AccessibleContext associated with this <code>TextArea</code>. - * The context is created, if necessary. - * - * @return the associated context - */ - public AccessibleContext getAccessibleContext() - { - /* Create the context if this is the first request */ - if (accessibleContext == null) - accessibleContext = new AccessibleAWTTextArea(); - return accessibleContext; - } -} diff --git a/libjava/java/awt/TextComponent.java b/libjava/java/awt/TextComponent.java deleted file mode 100644 index 9edbd88fe33..00000000000 --- a/libjava/java/awt/TextComponent.java +++ /dev/null @@ -1,739 +0,0 @@ -/* TextComponent.java -- Widgets for entering text - Copyright (C) 1999, 2002, 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.awt.event.TextEvent; -import java.awt.event.TextListener; -import java.awt.peer.TextComponentPeer; -import java.io.Serializable; -import java.text.BreakIterator; -import java.util.EventListener; - -import javax.accessibility.Accessible; -import javax.accessibility.AccessibleContext; -import javax.accessibility.AccessibleRole; -import javax.accessibility.AccessibleState; -import javax.accessibility.AccessibleStateSet; -import javax.accessibility.AccessibleText; -import javax.swing.text.AttributeSet; - -/** - * This class provides common functionality for widgets than - * contain text. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public class TextComponent extends Component - implements Serializable, Accessible -{ - -/* - * Static Variables - */ - -// Constant for serialization -private static final long serialVersionUID = -2214773872412987419L; - -/* - * Instance Variables - */ - -/** - * @serial Indicates whether or not this component is editable. - * This is package-private to avoid an accessor method. - */ -boolean editable; - -/** - * @serial The starting position of the selected text region. - * This is package-private to avoid an accessor method. - */ -int selectionStart; - -/** - * @serial The ending position of the selected text region. - * This is package-private to avoid an accessor method. - */ -int selectionEnd; - -/** - * @serial The text in the component - * This is package-private to avoid an accessor method. - */ -String text; - -/** - * A list of listeners that will receive events from this object. - */ -protected transient TextListener textListener; - - protected class AccessibleAWTTextComponent - extends AccessibleAWTComponent - implements AccessibleText, TextListener - { - // Constructor - // Adds a listener for tracking caret changes - public AccessibleAWTTextComponent() - { - TextComponent.this.addTextListener(this); - } - - public AccessibleRole getAccessibleRole() - { - return AccessibleRole.TEXT; - } - - public AccessibleStateSet getAccessibleStateSet() - { - // TODO: Docs say PropertyChangeEvent will fire if this state changes. - // That means that the event has to fire when editable changes. - AccessibleStateSet ss = super.getAccessibleStateSet(); - if (editable) - ss.add(AccessibleState.EDITABLE); - return ss; - } - - public AccessibleText getAccessibleText() - { - return this; - } - - /* (non-Javadoc) - * @see javax.accessibility.AccessibleText#getIndexAtPoint(java.awt.Point) - */ - public int getIndexAtPoint(Point point) - { - return TextComponent.this.getIndexAtPoint(point); - } - - /* (non-Javadoc) - * @see javax.accessibility.AccessibleText#getCharacterBounds(int) - */ - public Rectangle getCharacterBounds(int index) - { - return TextComponent.this.getCharacterBounds(index); - } - - /* (non-Javadoc) - * @see javax.accessibility.AccessibleText#getCharCount() - */ - public int getCharCount() - { - return text.length(); - } - - /* (non-Javadoc) - * @see javax.accessibility.AccessibleText#getCaretPosition() - */ - public int getCaretPosition() - { - return TextComponent.this.getCaretPosition(); - } - - /* (non-Javadoc) - * @see javax.accessibility.AccessibleText#getAtIndex(int, int) - */ - public String getAtIndex(int part, int index) - { - if (index < 0 || index >= text.length()) - return null; - BreakIterator it = null; - switch (part) - { - case CHARACTER: - return text.substring(index, index + 1); - case WORD: - it = BreakIterator.getWordInstance(); - break; - case SENTENCE: - it = BreakIterator.getSentenceInstance(); - break; - default: - return null; - } - it.setText(text); - int start = index; - if (!it.isBoundary(index)) - start = it.preceding(index); - int end = it.following(index); - if (end == -1) - return text.substring(index); - else - return text.substring(index, end); - } - - /* (non-Javadoc) - * @see javax.accessibility.AccessibleText#getAfterIndex(int, int) - */ - public String getAfterIndex(int part, int index) { - if (index < 0 || index >= text.length()) - return null; - BreakIterator it = null; - switch (part) - { - case CHARACTER: - return text.substring(index, index + 1); - case WORD: - it = BreakIterator.getWordInstance(); - break; - case SENTENCE: - it = BreakIterator.getSentenceInstance(); - break; - default: - return null; - } - it.setText(text); - int start = index; - if (!it.isBoundary(index)) - start = it.following(index); - // Make sure there was a complete unit. I.e. if index is in the middle - // of a word, return null if there is no word after the that one. - if (start == -1) - return null; - int end = it.following(start); - if (end == -1) - return text.substring(index); - else - return text.substring(index, end); - } - - /* (non-Javadoc) - * @see javax.accessibility.AccessibleText#getBeforeIndex(int, int) - */ - public String getBeforeIndex(int part, int index) - { - if (index < 1 || index >= text.length()) - return null; - BreakIterator it = null; - switch (part) - { - case CHARACTER: - return text.substring(index - 1, index); - case WORD: - it = BreakIterator.getWordInstance(); - break; - case SENTENCE: - it = BreakIterator.getSentenceInstance(); - break; - default: - return null; - } - it.setText(text); - int end = index; - if (!it.isBoundary(index)) - end = it.preceding(index); - // Make sure there was a complete unit. I.e. if index is in the middle - // of a word, return null if there is no word before that one. - if (end == -1) - return null; - int start = it.preceding(end); - if (start == -1) - return text.substring(0, end); - else - return text.substring(start, end); - } - - /* (non-Javadoc) - * @see javax.accessibility.AccessibleText#getCharacterAttribute(int) - */ - public AttributeSet getCharacterAttribute(int index) - { - // FIXME: I suspect this really gets filled in by subclasses. - return null; - } - - /* (non-Javadoc) - * @see javax.accessibility.AccessibleText#getSelectionStart() - */ - public int getSelectionStart() { - // TODO Auto-generated method stub - return selectionStart; - } - - /* (non-Javadoc) - * @see javax.accessibility.AccessibleText#getSelectionEnd() - */ - public int getSelectionEnd() - { - return selectionEnd; - } - - /* (non-Javadoc) - * @see javax.accessibility.AccessibleText#getSelectedText() - */ - public String getSelectedText() - { - if (selectionEnd - selectionStart > 0) - return text.substring(selectionStart, selectionEnd); - else - return null; - } - - /* (non-Javadoc) - * @see java.awt.event.TextListener#textValueChanged(java.awt.event.TextEvent) - */ - public void textValueChanged(TextEvent event) - { - // TODO Auto-generated method stub - - } - - } - -/*************************************************************************/ - -/* - * Constructors - */ - -TextComponent(String text) -{ - this.text = text; - this.editable = true; -} - -/*************************************************************************/ - -/* - * Instance Methods - */ - -/** - * Returns the text in this component - * - * @return The text in this component. - */ -public synchronized String -getText() -{ - TextComponentPeer tcp = (TextComponentPeer)getPeer(); - if (tcp != null) - text = tcp.getText(); - - return(text); -} - -/*************************************************************************/ - -/** - * Sets the text in this component to the specified string. - * - * @param text The new text for this component. - */ -public synchronized void -setText(String text) -{ - if (text == null) - text = ""; - - this.text = text; - - TextComponentPeer tcp = (TextComponentPeer)getPeer(); - if (tcp != null) - tcp.setText(text); - setCaretPosition(0); -} - -/*************************************************************************/ - -/** - * Returns a string that contains the text that is currently selected. - * - * @return The currently selected text region. - */ -public synchronized String -getSelectedText() -{ - String alltext = getText(); - int start = getSelectionStart(); - int end = getSelectionEnd(); - - return(alltext.substring(start, end)); -} - -/*************************************************************************/ - -/** - * Returns the starting position of the selected text region. - * If the text is not selected then caret position is returned. - * - * @return The starting position of the selected text region. - */ -public synchronized int -getSelectionStart() -{ - TextComponentPeer tcp = (TextComponentPeer)getPeer(); - if (tcp != null) - selectionStart = tcp.getSelectionStart(); - - return(selectionStart); -} - -/*************************************************************************/ - -/** - * Sets the starting position of the selected region to the - * specified value. If the specified value is out of range, then it - * will be silently changed to the nearest legal value. - * - * @param selectionStart The new start position for selected text. - */ -public synchronized void -setSelectionStart(int selectionStart) -{ - select(selectionStart, getSelectionEnd()); -} - -/*************************************************************************/ - -/** - * Returns the ending position of the selected text region. - * If the text is not selected, then caret position is returned - * - * @return The ending position of the selected text region. - */ -public synchronized int -getSelectionEnd() -{ - TextComponentPeer tcp = (TextComponentPeer)getPeer(); - if (tcp != null) - selectionEnd = tcp.getSelectionEnd(); - - return(selectionEnd); -} - -/*************************************************************************/ - -/** - * Sets the ending position of the selected region to the - * specified value. If the specified value is out of range, then it - * will be silently changed to the nearest legal value. - * - * @param selectionEnd The new start position for selected text. - */ -public synchronized void -setSelectionEnd(int selectionEnd) -{ - select(getSelectionStart(), selectionEnd); -} - -/*************************************************************************/ - -/** - * This method sets the selected text range to the text between the - * specified start and end positions. Illegal values for these - * positions are silently fixed. - * - * @param selectionStart The new start position for the selected text. - * @param selectionEnd The new end position for the selected text. - */ -public synchronized void -select(int selectionStart, int selectionEnd) -{ - if (selectionStart < 0) - selectionStart = 0; - - if (selectionStart > getText().length()) - selectionStart = text.length(); - - if (selectionEnd > text.length()) - selectionEnd = text.length(); - - if (selectionStart > getSelectionEnd()) - selectionStart = selectionEnd; - - this.selectionStart = selectionStart; - this.selectionEnd = selectionEnd; - - TextComponentPeer tcp = (TextComponentPeer)getPeer(); - if (tcp != null) - tcp.select(selectionStart, selectionEnd); -} - -/*************************************************************************/ - -/** - * Selects all of the text in the component. - */ -public synchronized void -selectAll() -{ - select(0, getText().length()); -} - -/*************************************************************************/ - -/** - * Returns the current caret position in the text. - * - * @return The caret position in the text. - */ -public synchronized int -getCaretPosition() -{ - TextComponentPeer tcp = (TextComponentPeer)getPeer(); - if (tcp != null) - return(tcp.getCaretPosition()); - else - return(0); -} - -/*************************************************************************/ - -/** - * Sets the caret position to the specified value. - * - * @param caretPosition The new caret position. - * - * @exception IllegalArgumentException If the value supplied for position - * is less than zero. - * - * @since 1.1 - */ -public synchronized void -setCaretPosition(int caretPosition) -{ - if (caretPosition < 0) - throw new IllegalArgumentException (); - - TextComponentPeer tcp = (TextComponentPeer)getPeer(); - if (tcp != null) - tcp.setCaretPosition(caretPosition); -} - -/*************************************************************************/ - -/** - * Tests whether or not this component's text can be edited. - * - * @return <code>true</code> if the text can be edited, <code>false</code> - * otherwise. - */ -public boolean -isEditable() -{ - return(editable); -} - -/*************************************************************************/ - -/** - * Sets whether or not this component's text can be edited. - * - * @param editable <code>true</code> to enable editing of the text, - * <code>false</code> to disable it. - */ -public synchronized void -setEditable(boolean editable) -{ - this.editable = editable; - - TextComponentPeer tcp = (TextComponentPeer)getPeer(); - if (tcp != null) - tcp.setEditable(editable); -} - -/*************************************************************************/ - -/** - * Notifies the component that it should destroy its native peer. - */ -public void -removeNotify() -{ - super.removeNotify(); -} - -/*************************************************************************/ - -/** - * Adds a new listener to the list of text listeners for this - * component. - * - * @param listener The listener to be added. - */ -public synchronized void -addTextListener(TextListener listener) -{ - textListener = AWTEventMulticaster.add(textListener, listener); - - enableEvents(AWTEvent.TEXT_EVENT_MASK); -} - -/*************************************************************************/ - -/** - * Removes the specified listener from the list of listeners - * for this component. - * - * @param listener The listener to remove. - */ -public synchronized void -removeTextListener(TextListener listener) -{ - textListener = AWTEventMulticaster.remove(textListener, listener); -} - -/*************************************************************************/ - -/** - * Processes the specified event for this component. Text events are - * processed by calling the <code>processTextEvent()</code> method. - * All other events are passed to the superclass method. - * - * @param event The event to process. - */ -protected void -processEvent(AWTEvent event) -{ - if (event instanceof TextEvent) - processTextEvent((TextEvent)event); - else - super.processEvent(event); -} - -/*************************************************************************/ - -/** - * Processes the specified text event by dispatching it to any listeners - * that are registered. Note that this method will only be called - * if text event's are enabled. This will be true if there are any - * registered listeners, or if the event has been specifically - * enabled using <code>enableEvents()</code>. - * - * @param event The text event to process. - */ -protected void -processTextEvent(TextEvent event) -{ - if (textListener != null) - textListener.textValueChanged(event); -} - -void -dispatchEventImpl(AWTEvent e) -{ - if (e.id <= TextEvent.TEXT_LAST - && e.id >= TextEvent.TEXT_FIRST - && (textListener != null - || (eventMask & AWTEvent.TEXT_EVENT_MASK) != 0)) - processEvent(e); - else - super.dispatchEventImpl(e); -} - -/*************************************************************************/ - -/** - * Returns a debugging string. - * - * @return A debugging string. - */ -protected String -paramString() -{ - return(getClass().getName() + "(text=" + getText() + ")"); -} - - /** - * Returns an array of all the objects currently registered as FooListeners - * upon this <code>TextComponent</code>. FooListeners are registered using - * the addFooListener method. - * - * @exception ClassCastException If listenerType doesn't specify a class or - * interface that implements java.util.EventListener. - */ - public EventListener[] getListeners (Class listenerType) - { - if (listenerType == TextListener.class) - return AWTEventMulticaster.getListeners (textListener, listenerType); - - return super.getListeners (listenerType); - } - - /** - * Returns all text listeners registered to this object. - */ - public TextListener[] getTextListeners () - { - return (TextListener[]) getListeners (TextListener.class); - } - - /** - * Gets the AccessibleContext associated with this <code>TextComponent</code>. - * The context is created, if necessary. - * - * @return the associated context - */ - public AccessibleContext getAccessibleContext() - { - /* Create the context if this is the first request */ - if (accessibleContext == null) - accessibleContext = new AccessibleAWTTextComponent(); - return accessibleContext; - } - - - /*******************************/ - // Provide AccessibleAWTTextComponent access to several peer functions that - // aren't publicly exposed. This is package-private to avoid an accessor - // method. - synchronized int - getIndexAtPoint(Point p) - { - TextComponentPeer tcp = (TextComponentPeer)getPeer(); - if (tcp != null) - return tcp.getIndexAtPoint(p.x, p.y); - return -1; - } - - synchronized Rectangle - getCharacterBounds(int i) - { - TextComponentPeer tcp = (TextComponentPeer)getPeer(); - if (tcp != null) - return tcp.getCharacterBounds(i); - return null; - } - - - - -} // class TextComponent - diff --git a/libjava/java/awt/TextField.java b/libjava/java/awt/TextField.java deleted file mode 100644 index 4d62d024aad..00000000000 --- a/libjava/java/awt/TextField.java +++ /dev/null @@ -1,541 +0,0 @@ -/* TextField.java -- A one line text entry field - Copyright (C) 1999, 2002, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.peer.ComponentPeer; -import java.awt.peer.TextFieldPeer; -import java.util.EventListener; - -import javax.accessibility.AccessibleContext; -import javax.accessibility.AccessibleStateSet; - -/** - * This class implements a single line text entry field widget - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public class TextField extends TextComponent -{ - -/* - * Static Variables - */ - -// Serialization constant -private static final long serialVersionUID = -2966288784432217853L; - -/*************************************************************************/ - -/* - * Instance Variables - */ - -/** - * @serial The number of columns in the text entry field. - */ -private int columns; - -/** - * @serial The character that is echoed when doing protected input - */ -private char echoChar; - -// List of registered ActionListener's for this object. -private ActionListener action_listeners; - -/*************************************************************************/ - -/* - * Constructors - */ - -/** - * Initializes a new instance of <code>TextField</code> that is empty - * and has one column. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true, - */ -public -TextField() -{ - this("", 1); -} - -/*************************************************************************/ - -/** - * Initializes a new instance of <code>TextField</code> containing - * the specified text. The number of columns will be equal to the - * length of the text string. - * - * @param text The text to display in the field. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true, - */ -public -TextField(String text) -{ - this(text, text.length()); -} - -/*************************************************************************/ - -/** - * Initializes a new instance of <code>TextField</code> that is empty - * and has the specified number of columns. - * - * @param columns The number of columns in the text field. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true, - */ -public -TextField(int columns) -{ - this("", columns); -} - -/*************************************************************************/ - -/** - * Initializes a new instance of <code>TextField</code> with the - * specified text and number of columns. - * - * @param text The text to display in the field. - * @param columns The number of columns in the field. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true, - */ -public -TextField(String text, int columns) -{ - super(text); - this.columns = columns; - - if (GraphicsEnvironment.isHeadless()) - throw new HeadlessException (); -} - -/*************************************************************************/ - -/* - * Instance Methods - */ - -/** - * Returns the number of columns in the field. - * - * @return The number of columns in the field. - */ -public int -getColumns() -{ - return(columns); -} - -/*************************************************************************/ - -/** - * Sets the number of columns in this field to the specified value. - * - * @param columns The new number of columns in the field. - * - * @exception IllegalArgumentException If columns is less than zero. - */ -public synchronized void -setColumns(int columns) -{ - if (columns < 0) - throw new IllegalArgumentException("Value is less than zero: " + - columns); - - this.columns = columns; - // FIXME: How to we communicate this to our peer? -} - -/*************************************************************************/ - -/** - * Returns the character that is echoed to the screen when a text - * field is protected (such as when a password is being entered). - * - * @return The echo character for this text field. - */ -public char -getEchoChar() -{ - return(echoChar); -} - -/*************************************************************************/ - -/** - * Sets the character that is echoed when protected input such as - * a password is displayed. - * - * @param echoChar The new echo character. - */ -public void -setEchoChar(char echoChar) -{ - setEchoCharacter (echoChar); -} - -/*************************************************************************/ - -/** - * Sets the character that is echoed when protected input such as - * a password is displayed. - * - * @param echoChar The new echo character. - * - * @deprecated This method is deprecated in favor of - * <code>setEchoChar()</code> - */ -public void -setEchoCharacter(char echoChar) -{ - this.echoChar = echoChar; - - TextFieldPeer peer = (TextFieldPeer) getPeer (); - if (peer != null) - peer.setEchoChar (echoChar); -} - -/*************************************************************************/ - -/** - * Tests whether or not this text field has an echo character set - * so that characters the user type are not echoed to the screen. - * - * @return <code>true</code> if an echo character is set, - * <code>false</code> otherwise. - */ -public boolean -echoCharIsSet() -{ - if (echoChar == '\u0000') - return(false); - else - return(true); -} - -/*************************************************************************/ - -/** - * Returns the minimum size for this text field. - * - * @return The minimum size for this text field. - */ -public Dimension -getMinimumSize() -{ - return getMinimumSize (getColumns ()); -} - -/*************************************************************************/ - -/** - * Returns the minimum size of a text field with the specified number - * of columns. - * - * @param columns The number of columns to get the minimum size for. - */ -public Dimension -getMinimumSize(int columns) -{ - return minimumSize (columns); -} - -/*************************************************************************/ - -/** - * Returns the minimum size for this text field. - * - * @return The minimum size for this text field. - * - * @deprecated This method is deprecated in favor of - * <code>getMinimumSize()</code>. - */ -public Dimension -minimumSize() -{ - return minimumSize (getColumns ()); -} - -/*************************************************************************/ - -/** - * Returns the minimum size of a text field with the specified number - * of columns. - * - * @param columns The number of columns to get the minimum size for. - * - * @deprecated This method is deprecated in favor of - * <code>getMinimumSize(int)</code>. - */ -public Dimension -minimumSize(int columns) -{ - TextFieldPeer peer = (TextFieldPeer) getPeer (); - if (peer == null) - return null; // FIXME: What do we do if there is no peer? - - return peer.getMinimumSize (columns); -} - -/*************************************************************************/ - -/** - * Returns the preferred size for this text field. - * - * @return The preferred size for this text field. - */ -public Dimension -getPreferredSize() -{ - return getPreferredSize (getColumns ()); -} - -/*************************************************************************/ - -/** - * Returns the preferred size of a text field with the specified number - * of columns. - * - * @param columns The number of columns to get the preferred size for. - */ -public Dimension -getPreferredSize(int columns) -{ - return preferredSize (columns); -} - -/*************************************************************************/ - -/** - * Returns the preferred size for this text field. - * - * @return The preferred size for this text field. - * - * @deprecated This method is deprecated in favor of - * <code>getPreferredSize()</code>. - */ -public Dimension -preferredSize() -{ - return preferredSize (getColumns ()); -} - -/*************************************************************************/ - -/** - * Returns the preferred size of a text field with the specified number - * of columns. - * - * @param columns The number of columns to get the preferred size for. - * - * @deprecated This method is deprecated in favor of - * <code>getPreferredSize(int)</code>. - */ -public Dimension -preferredSize(int columns) -{ - TextFieldPeer peer = (TextFieldPeer) getPeer (); - if (peer == null) - return new Dimension (0, 0); - - return peer.getPreferredSize (columns); -} - -/*************************************************************************/ - -/** - * Notifies this object that it should create its native peer. - */ -public void -addNotify() -{ - if (getPeer() != null) - return; - - setPeer((ComponentPeer)getToolkit().createTextField(this)); -} - -/*************************************************************************/ - -/** - * Addes a new listener to the list of action listeners for this - * object. - * - * @param listener The listener to add to the list. - */ -public synchronized void -addActionListener(ActionListener listener) -{ - action_listeners = AWTEventMulticaster.add(action_listeners, listener); - - enableEvents(AWTEvent.ACTION_EVENT_MASK); -} - -/*************************************************************************/ - -/** - * Removes the specified listener from the list of action listeners - * for this object. - * - * @param listener The listener to remove from the list. - */ -public synchronized void -removeActionListener(ActionListener listener) -{ - action_listeners = AWTEventMulticaster.remove(action_listeners, listener); -} - -/*************************************************************************/ - -/** - * Processes the specified event. If the event is an instance of - * <code>ActionEvent</code> then <code>processActionEvent()</code> is - * called to process it, otherwise the event is sent to the - * superclass. - * - * @param event The event to process. - */ -protected void -processEvent(AWTEvent event) -{ - if (event instanceof ActionEvent) - processActionEvent((ActionEvent)event); - else - super.processEvent(event); -} - -/*************************************************************************/ - -/** - * Processes an action event by calling any registered listeners. - * Note to subclasses: This method is not called unless action events - * are enabled on this object. This will be true if any listeners - * are registered, or if action events were specifically enabled - * using <code>enableEvents()</code>. - * - * @param event The event to process. - */ -protected void -processActionEvent(ActionEvent event) -{ - if (action_listeners != null) - action_listeners.actionPerformed(event); -} - -void -dispatchEventImpl(AWTEvent e) -{ - if (e.id <= ActionEvent.ACTION_LAST - && e.id >= ActionEvent.ACTION_FIRST - && (action_listeners != null - || (eventMask & AWTEvent.ACTION_EVENT_MASK) != 0)) - processEvent(e); - else - super.dispatchEventImpl(e); -} - -/*************************************************************************/ - -/** - * Returns a debug string for this object. - * - * @return A debug string for this object. - */ -protected String -paramString() -{ - return(getClass().getName() + "(columns=" + getColumns() + ",echoChar=" + - getEchoChar()); -} - - /** - * Returns an array of all the objects currently registered as FooListeners - * upon this <code>TextField</code>. FooListeners are registered using the - * addFooListener method. - * - * @exception ClassCastException If listenerType doesn't specify a class or - * interface that implements java.util.EventListener. - * - * @since 1.3 - */ - public EventListener[] getListeners (Class listenerType) - { - if (listenerType == ActionListener.class) - return AWTEventMulticaster.getListeners (action_listeners, listenerType); - - return super.getListeners (listenerType); - } - - /** - * Return all ActionListeners register to this <code>TextField</code> object - * as an array. - * - * @since 1.4 - */ - public ActionListener[] getActionListeners () - { - return (ActionListener[]) getListeners (ActionListener.class); - } - - protected class AccessibleAWTTextField extends AccessibleAWTTextComponent - { - protected AccessibleAWTTextField() - { - } - - public AccessibleStateSet getAccessibleStateSet() - { - return super.getAccessibleStateSet(); - } - } - - public AccessibleContext getAccessibleContext() - { - return new AccessibleAWTTextField(); - } - -} // class TextField diff --git a/libjava/java/awt/TexturePaint.java b/libjava/java/awt/TexturePaint.java deleted file mode 100644 index a12e38463f1..00000000000 --- a/libjava/java/awt/TexturePaint.java +++ /dev/null @@ -1,75 +0,0 @@ -/* TexturePaint.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.awt.geom.AffineTransform; -import java.awt.geom.Rectangle2D; -import java.awt.image.BufferedImage; -import java.awt.image.ColorModel; - -/** STUB CLASS ONLY */ -public class TexturePaint implements Paint -{ - private final BufferedImage texture; - private final Rectangle2D anchor; - public TexturePaint(BufferedImage texture, Rectangle2D anchor) - { - this.texture = texture; - this.anchor = anchor; - } - public BufferedImage getImage() - { - return texture; - } - public Rectangle2D getAnchorRect() - { - return anchor; - } - public PaintContext createContext(ColorModel cm, Rectangle deviceBounds, - Rectangle2D userBounds, - AffineTransform xform, - RenderingHints hints) - { - throw new Error("not implemented"); - } - public int getTransparency() - { - throw new Error("not implemented"); - } -} // class TexturePaint diff --git a/libjava/java/awt/Toolkit.java b/libjava/java/awt/Toolkit.java deleted file mode 100644 index c7c6f9f0ecb..00000000000 --- a/libjava/java/awt/Toolkit.java +++ /dev/null @@ -1,995 +0,0 @@ -/* Toolkit.java -- AWT Toolkit superclass - Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005 - Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.awt.datatransfer.Clipboard; -import java.awt.dnd.DragGestureEvent; -import java.awt.dnd.DragGestureListener; -import java.awt.dnd.DragGestureRecognizer; -import java.awt.dnd.DragSource; -import java.awt.dnd.peer.DragSourceContextPeer; -import java.awt.event.AWTEventListener; -import java.awt.event.KeyEvent; -import java.awt.im.InputMethodHighlight; -import java.awt.image.ColorModel; -import java.awt.image.ImageObserver; -import java.awt.image.ImageProducer; -import java.awt.peer.ButtonPeer; -import java.awt.peer.CanvasPeer; -import java.awt.peer.CheckboxMenuItemPeer; -import java.awt.peer.CheckboxPeer; -import java.awt.peer.ChoicePeer; -import java.awt.peer.DialogPeer; -import java.awt.peer.FileDialogPeer; -import java.awt.peer.FontPeer; -import java.awt.peer.FramePeer; -import java.awt.peer.LabelPeer; -import java.awt.peer.LightweightPeer; -import java.awt.peer.ListPeer; -import java.awt.peer.MenuBarPeer; -import java.awt.peer.MenuItemPeer; -import java.awt.peer.MenuPeer; -import java.awt.peer.PanelPeer; -import java.awt.peer.PopupMenuPeer; -import java.awt.peer.ScrollPanePeer; -import java.awt.peer.ScrollbarPeer; -import java.awt.peer.TextAreaPeer; -import java.awt.peer.TextFieldPeer; -import java.awt.peer.WindowPeer; -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; -import java.net.URL; -import java.util.Map; -import java.util.Properties; - -/** - * The AWT system uses a set of native peer objects to implement its - * widgets. These peers are provided by a peer toolkit, that is accessed - * via a subclass of this superclass. The system toolkit is retrieved - * by the static methods <code>getDefaultToolkit</code>. This method - * determines the system toolkit by examining the system property - * <code>awt.toolkit</code>. That property is set to the name of the - * <code>Toolkit</code> subclass for the specified peer set. If the - * <code>awt.toolkit</code> property is not set, then the default - * toolkit <code>gnu.java.awt.peer.gtk.GtkToolkit</code> is used. This - * toolkit creates its peers using the GTK+ toolkit. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public abstract class Toolkit -{ - /** The default toolkit name. */ - private static String default_toolkit_name - = gnu.classpath.Configuration.default_awt_peer_toolkit; - - /** - * The toolkit in use. Once we load it, we don't ever change it - * if the awt.toolkit property is set. - */ - private static Toolkit toolkit; - - /** The toolkit properties. */ - private static Properties props = new Properties(); - - protected final Map desktopProperties = new Properties(); - - protected final PropertyChangeSupport desktopPropsSupport - = new PropertyChangeSupport(this); - - /** - * Default constructor for subclasses. - */ - public Toolkit() - { - } - - /** - * Creates a peer object for the specified <code>Button</code>. - * - * @param target The <code>Button</code> to create the peer for. - * - * @return The peer for the specified <code>Button</code> object. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. - */ - protected abstract ButtonPeer createButton(Button target); - - /** - * Creates a peer object for the specified <code>TextField</code>. - * - * @param target The <code>TextField</code> to create the peer for. - * - * @return The peer for the specified <code>TextField</code> object. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. - */ - protected abstract TextFieldPeer createTextField(TextField target); - - /** - * Creates a peer object for the specified <code>Label</code>. - * - * @param target The <code>Label</code> to create the peer for. - * - * @return The peer for the specified <code>Label</code> object. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. - */ - protected abstract LabelPeer createLabel(Label target); - - /** - * Creates a peer object for the specified <code>List</code>. - * - * @param target The <code>List</code> to create the peer for. - * - * @return The peer for the specified <code>List</code> object. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. - */ - protected abstract ListPeer createList(List target); - - /** - * Creates a peer object for the specified <code>Checkbox</code>. - * - * @param target The <code>Checkbox</code> to create the peer for. - * - * @return The peer for the specified <code>Checkbox</code> object. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. - */ - protected abstract CheckboxPeer createCheckbox(Checkbox target); - - /** - * Creates a peer object for the specified <code>Scrollbar</code>. - * - * @param target The <code>Scrollbar</code> to create the peer for. - * - * @return The peer for the specified <code>Scrollbar</code> object. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. - */ - protected abstract ScrollbarPeer createScrollbar(Scrollbar target); - - /** - * Creates a peer object for the specified <code>ScrollPane</code>. - * - * @param target The <code>ScrollPane</code> to create the peer for. - * - * @return The peer for the specified <code>ScrollPane</code> object. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. - */ - protected abstract ScrollPanePeer createScrollPane(ScrollPane target); - - /** - * Creates a peer object for the specified <code>TextArea</code>. - * - * @param target The <code>TextArea</code> to create the peer for. - * - * @return The peer for the specified <code>TextArea</code> object. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. - */ - protected abstract TextAreaPeer createTextArea(TextArea target); - - /** - * Creates a peer object for the specified <code>Choice</code>. - * - * @param target The <code>Choice</code> to create the peer for. - * - * @return The peer for the specified <code>Choice</code> object. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. - */ - protected abstract ChoicePeer createChoice(Choice target); - - /** - * Creates a peer object for the specified <code>Frame</code>. - * - * @param target The <code>Frame</code> to create the peer for. - * - * @return The peer for the specified <code>Frame</code> object. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. - */ - protected abstract FramePeer createFrame(Frame target); - - /** - * Creates a peer object for the specified <code>Canvas</code>. - * - * @param target The <code>Canvas</code> to create the peer for. - * - * @return The peer for the specified <code>Canvas</code> object. - */ - protected abstract CanvasPeer createCanvas(Canvas target); - - /** - * Creates a peer object for the specified <code>Panel</code>. - * - * @param target The <code>Panel</code> to create the peer for. - * - * @return The peer for the specified <code>Panel</code> object. - */ - protected abstract PanelPeer createPanel(Panel target); - - /** - * Creates a peer object for the specified <code>Window</code>. - * - * @param target The <code>Window</code> to create the peer for. - * - * @return The peer for the specified <code>Window</code> object. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. - */ - protected abstract WindowPeer createWindow(Window target); - - /** - * Creates a peer object for the specified <code>Dialog</code>. - * - * @param target The dialog to create the peer for - * - * @return The peer for the specified font name. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. - */ - protected abstract DialogPeer createDialog(Dialog target); - - /** - * Creates a peer object for the specified <code>MenuBar</code>. - * - * @param target The <code>MenuBar</code> to create the peer for. - * - * @return The peer for the specified <code>MenuBar</code> object. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. - */ - protected abstract MenuBarPeer createMenuBar(MenuBar target); - - /** - * Creates a peer object for the specified <code>Menu</code>. - * - * @param target The <code>Menu</code> to create the peer for. - * - * @return The peer for the specified <code>Menu</code> object. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. - */ - protected abstract MenuPeer createMenu(Menu target); - - /** - * Creates a peer object for the specified <code>PopupMenu</code>. - * - * @param target The <code>PopupMenu</code> to create the peer for. - * - * @return The peer for the specified <code>PopupMenu</code> object. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. - */ - protected abstract PopupMenuPeer createPopupMenu(PopupMenu target); - - /** - * Creates a peer object for the specified <code>MenuItem</code>. - * - * @param target The <code>MenuItem</code> to create the peer for. - * - * @return The peer for the specified <code>MenuItem</code> object. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. - */ - protected abstract MenuItemPeer createMenuItem(MenuItem target); - - /** - * Creates a peer object for the specified <code>FileDialog</code>. - * - * @param target The <code>FileDialog</code> to create the peer for. - * - * @return The peer for the specified <code>FileDialog</code> object. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. - */ - protected abstract FileDialogPeer createFileDialog(FileDialog target); - - /** - * Creates a peer object for the specified <code>CheckboxMenuItem</code>. - * - * @param target The <code>CheckboxMenuItem</code> to create the peer for. - * - * @return The peer for the specified <code>CheckboxMenuItem</code> object. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. - */ - protected abstract CheckboxMenuItemPeer - createCheckboxMenuItem(CheckboxMenuItem target); - - /** - * Creates a peer object for the specified <code>Component</code>. The - * peer returned by this method is not a native windowing system peer - * with its own native window. Instead, this method allows the component - * to draw on its parent window as a "lightweight" widget. - * - * @param target The <code>Component</code> to create the peer for. - * - * @return The peer for the specified <code>Component</code> object. - */ - protected LightweightPeer createComponent(Component target) - { - return new gnu.java.awt.peer.GLightweightPeer (target); - } - - /** - * Creates a peer object for the specified font name. - * - * @param name The font to create the peer for. - * @param style The font style to create the peer for. - * - * @return The peer for the specified font name. - * - * @deprecated - */ - protected abstract FontPeer getFontPeer(String name, int style); - - /** - * Copies the current system colors into the specified array. This is - * the interface used by the <code>SystemColor</code> class. Although - * this method fills in the array with some default colors a real Toolkit - * should override this method and provide real system colors for the - * native GUI platform. - * - * @param systemColors The array to copy the system colors into. - * It must be at least 26 elements. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. - * - * @see java.awt.SystemColor - */ - protected void loadSystemColors(int systemColors[]) - { - systemColors[SystemColor.DESKTOP] = 0xFF005C5C; - systemColors[SystemColor.ACTIVE_CAPTION] = 0xFF000080; - systemColors[SystemColor.ACTIVE_CAPTION_TEXT] = 0xFFFFFFFF; - systemColors[SystemColor.ACTIVE_CAPTION_BORDER] = 0xFFC0C0C0; - systemColors[SystemColor.INACTIVE_CAPTION] = 0xFF808080; - systemColors[SystemColor.INACTIVE_CAPTION_TEXT] = 0xFFC0C0C0; - systemColors[SystemColor.INACTIVE_CAPTION_BORDER] = 0xFFC0C0C0; - systemColors[SystemColor.WINDOW] = 0xFFFFFFFF; - systemColors[SystemColor.WINDOW_BORDER] = 0xFF000000; - systemColors[SystemColor.WINDOW_TEXT] = 0xFF000000; - systemColors[SystemColor.MENU] = 0xFFC0C0C0; - systemColors[SystemColor.MENU_TEXT] = 0xFF000000; - systemColors[SystemColor.TEXT] = 0xFFC0C0C0; - systemColors[SystemColor.TEXT_TEXT] = 0xFF000000; - systemColors[SystemColor.TEXT_HIGHLIGHT] = 0xFF000090; - systemColors[SystemColor.TEXT_HIGHLIGHT_TEXT] = 0xFFFFFFFF; - systemColors[SystemColor.TEXT_INACTIVE_TEXT] = 0xFF808080; - systemColors[SystemColor.CONTROL] = 0xFFC0C0C0; - systemColors[SystemColor.CONTROL_TEXT] = 0xFF000000; - systemColors[SystemColor.CONTROL_HIGHLIGHT] = 0xFFFFFFFF; - systemColors[SystemColor.CONTROL_LT_HIGHLIGHT] = 0xFFE0E0E0; - systemColors[SystemColor.CONTROL_SHADOW] = 0xFF808080; - systemColors[SystemColor.CONTROL_DK_SHADOW] = 0xFF000000; - systemColors[SystemColor.SCROLLBAR] = 0xFFE0E0E0; - systemColors[SystemColor.INFO] = 0xFFE0E000; - systemColors[SystemColor.INFO_TEXT] = 0xFF000000; - } - - /** - * @since 1.4 - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. - */ - public void setDynamicLayout(boolean dynamic) - { - } - - /** - * @since 1.4 - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. - */ - protected boolean isDynamicLayoutSet() - { - return false; - } - - /** - * @since 1.4 - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. - */ - public boolean isDynamicLayoutActive() - { - return false; - } - - /** - * Returns the dimensions of the screen in pixels. - * - * @return The dimensions of the screen in pixels. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. - */ - public abstract Dimension getScreenSize(); - - /** - * Returns the screen resolution in dots per square inch. - * - * @return The screen resolution in dots per square inch. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. - */ - public abstract int getScreenResolution(); - - /** - * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. - * - * @since 1.4 - */ - public Insets getScreenInsets(GraphicsConfiguration gc) - { - return null; - } - - /** - * Returns the color model of the screen. - * - * @return The color model of the screen. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. - */ - public abstract ColorModel getColorModel(); - - /** - * Returns the names of the available fonts. - * - * @return The names of the available fonts. - * - * @deprecated - */ - public abstract String[] getFontList(); - - /** - * Return the font metrics for the specified font - * - * @param name The name of the font to return metrics for. - * - * @return The requested font metrics. - * - * @deprecated - */ - public abstract FontMetrics getFontMetrics(Font name); - - /** - * Flushes any buffered data to the screen so that it is in sync with - * what the AWT system has drawn to it. - */ - public abstract void sync(); - - /** - * Returns an instance of the default toolkit. The default toolkit is - * the subclass of <code>Toolkit</code> specified in the system property - * <code>awt.toolkit</code>, or <code>gnu.java.awt.peer.gtk.GtkToolkit</code> - * if the property is not set. - * - * @return An instance of the system default toolkit. - * - * @throws AWTError If the toolkit cannot be loaded. - */ - public static Toolkit getDefaultToolkit() - { - if (toolkit != null) - return toolkit; - String toolkit_name = System.getProperty("awt.toolkit", - default_toolkit_name); - try - { - Class cls = Class.forName(toolkit_name); - Object obj = cls.newInstance(); - if (!(obj instanceof Toolkit)) - throw new AWTError(toolkit_name + " is not a subclass of " + - "java.awt.Toolkit"); - toolkit = (Toolkit) obj; - return toolkit; - } - catch (ThreadDeath death) - { - throw death; - } - catch (Throwable t) - { - AWTError e = new AWTError("Cannot load AWT toolkit: " + toolkit_name); - throw (AWTError) e.initCause(t); - } - } - - /** - * Returns an image from the specified file, which must be in a - * recognized format. Supported formats vary from toolkit to toolkit. - * - * @return name The name of the file to read the image from. - */ - public abstract Image getImage(String name); - - /** - * Returns an image from the specified URL, which must be in a - * recognized format. Supported formats vary from toolkit to toolkit. - * - * @return url The URl to read the image from. - */ - public abstract Image getImage(URL url); - - public abstract Image createImage(String filename); - - public abstract Image createImage(URL url); - - /** - * Readies an image to be rendered on the screen. The width and height - * values can be set to the default sizes for the image by passing -1 - * in those parameters. - * - * @param image The image to prepare for rendering. - * @param width The width of the image. - * @param height The height of the image. - * @param observer The observer to receive events about the preparation - * process. - * - * @return <code>true</code> if the image is already prepared for rendering, - * <code>false</code> otherwise. - */ - public abstract boolean prepareImage(Image image, int width, int height, - ImageObserver observer); - - /** - * Checks the status of specified image as it is being readied for - * rendering. - * - * @param image The image to prepare for rendering. - * @param width The width of the image. - * @param height The height of the image. - * @param observer The observer to receive events about the preparation - * process. - * - * @return A union of the bitmasks from - * <code>java.awt.image.ImageObserver</code> that indicates the current - * state of the imaging readying process. - */ - public abstract int checkImage(Image image, int width, int height, - ImageObserver observer); - - /** - * Creates an image using the specified <code>ImageProducer</code> - * - * @param producer The <code>ImageProducer</code> to create the image from. - * - * @return The created image. - */ - public abstract Image createImage(ImageProducer producer); - - /** - * Creates an image from the specified byte array. The array must be in - * a recognized format. Supported formats vary from toolkit to toolkit. - * - * @param data The raw image data. - * - * @return The created image. - */ - public Image createImage(byte[] data) - { - return createImage(data, 0, data.length); - } - - /** - * Creates an image from the specified portion of the byte array passed. - * The array must be in a recognized format. Supported formats vary from - * toolkit to toolkit. - * - * @param data The raw image data. - * @param offset The offset into the data where the image data starts. - * @param len The length of the image data. - * - * @return The created image. - */ - public abstract Image createImage(byte[] data, int offset, int len); - - /** - * Returns a instance of <code>PrintJob</code> for the specified - * arguments. - * - * @param frame The window initiating the print job. - * @param title The print job title. - * @param props The print job properties. - * - * @return The requested print job, or <code>null</code> if the job - * was cancelled. - * - * @exception NullPointerException If frame is null, - * or GraphicsEnvironment.isHeadless() returns true. - * @exception SecurityException If this thread is not allowed to initiate - * a print job request. - */ - public abstract PrintJob getPrintJob(Frame frame, String title, - Properties props); - - /** - * Returns a instance of <code>PrintJob</code> for the specified - * arguments. - * - * @param frame The window initiating the print job. - * @param title The print job title. - * @param jobAttr A set of job attributes which will control the print job. - * @param pageAttr A set of page attributes which will control the print job. - * - * @exception NullPointerException If frame is null, and either jobAttr is null - * or jobAttr.getDialog() returns JobAttributes.DialogType.NATIVE. - * @exception IllegalArgumentException If pageAttrspecifies differing cross - * feed and feed resolutions, or when GraphicsEnvironment.isHeadless() returns - * true. - * @exception SecurityException If this thread is not allowed to initiate - * a print job request. - * - * @since 1.3 - */ - public PrintJob getPrintJob(Frame frame, String title, - JobAttributes jobAttr, PageAttributes pageAttr) - { - return null; - } - - /** - * Causes a "beep" tone to be generated. - */ - public abstract void beep(); - - /** - * Returns the system clipboard. - * - * @return THe system clipboard. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. - */ - public abstract Clipboard getSystemClipboard(); - - /** - * Gets the singleton instance of the system selection as a Clipboard object. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. - * - * @since 1.4 - */ - public Clipboard getSystemSelection() - { - return null; - } - - /** - * Returns the accelerator key mask for menu shortcuts. The default is - * <code>Event.CTRL_MASK</code>. A toolkit must override this method - * to change the default. - * - * @return The key mask for the menu accelerator key. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. - */ - public int getMenuShortcutKeyMask() - { - return Event.CTRL_MASK; - } - - /** - * Returns whether the given locking key on the keyboard is currently in its - * "on" state. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. - * @exception IllegalArgumentException If keyCode is not one of the valid keys. - * @exception UnsupportedOperationException If the host system doesn't allow - * getting the state of this key programmatically, or if the keyboard doesn't - * have this key. - */ - public boolean getLockingKeyState(int keyCode) - { - if (keyCode != KeyEvent.VK_CAPS_LOCK - && keyCode != KeyEvent.VK_NUM_LOCK - && keyCode != KeyEvent.VK_SCROLL_LOCK) - throw new IllegalArgumentException(); - - throw new UnsupportedOperationException(); - } - - /** - * Sets the state of the given locking key on the keyboard. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. - * @exception IllegalArgumentException If keyCode is not one of the valid keys. - * @exception UnsupportedOperationException If the host system doesn't allow - * getting the state of this key programmatically, or if the keyboard doesn't - * have this key. - */ - public void setLockingKeyState(int keyCode, boolean on) - { - if (keyCode != KeyEvent.VK_CAPS_LOCK - && keyCode != KeyEvent.VK_NUM_LOCK - && keyCode != KeyEvent.VK_SCROLL_LOCK) - throw new IllegalArgumentException(); - - throw new UnsupportedOperationException(); - } - - /** - * Returns the native container object of the specified component. This - * method is necessary because the parent component might be a lightweight - * component. - * - * @param component The component to fetch the native container for. - * - * @return The native container object for this component. - */ - protected static Container getNativeContainer(Component component) - { - component = component.getParent(); - while (true) - { - if (component == null) - return null; - if (! (component instanceof Container)) - { - component = component.getParent(); - continue; - } - if (component.getPeer() instanceof LightweightPeer) - { - component = component.getParent(); - continue; - } - return (Container) component; - } - } - - /** - * Creates a new custom cursor object. - * - * @exception IndexOutOfBoundsException If the hotSpot values are outside - * the bounds of the cursor. - * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. - */ - public Cursor createCustomCursor(Image cursor, Point hotSpot, String name) - { - // Presumably the only reason this isn't abstract is for backwards - // compatibility? FIXME? - return null; - } - - /** - * Returns the supported cursor dimension which is closest to the - * desired sizes. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. - */ - public Dimension getBestCursorSize(int preferredWidth, int preferredHeight) - { - return new Dimension (0,0); - } - - /** - * Returns the maximum number of colors the Toolkit supports in a custom - * cursor palette. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. - */ - public int getMaximumCursorColors() - { - return 0; - } - - /** - * Returns whether Toolkit supports this state for Frames. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. - * - * @since 1.4 - */ - public boolean isFrameStateSupported(int state) - { - return false; - } - - /** - * Returns the value of the property with the specified name, or the - * default value if the property does not exist. - * - * @param key The name of the property to retrieve. - * @param def The default value of the property. - */ - public static String getProperty(String key, String def) - { - return props.getProperty(key, def); - } - - - /** - * Returns the event queue that is suitable for the calling context. - * - * <p>Despite the word “System” in the name of this - * method, a toolkit may provide different event queues for each - * applet. There is no guarantee that the same queue is shared - * system-wide. - * - * <p>The implementation first checks whether a - * SecurityManager has been installed. If so, its {@link - * java.lang.SecurityManager#checkAwtEventQueueAccess()} method gets - * called. The security manager will throw a SecurityException if it - * does not grant the permission to access the event queue. - * - * <p>Next, the call is delegated to {@link - * #getSystemEventQueueImpl()}. - * - * @return The event queue for this applet (or application). - * - * @throws SecurityException if a security manager has been - * installed, and it does not grant the permission to access the - * event queue. - */ - public final EventQueue getSystemEventQueue() - { - SecurityManager sm; - - sm = System.getSecurityManager(); - if (sm != null) - sm.checkAwtEventQueueAccess(); - - return getSystemEventQueueImpl(); - } - - - /** - * Returns the event queue that is suitable for the calling context. - * - * <p>Despite the word “System” in the name of this - * method, a toolkit may provide different event queues for each - * applet. There is no guarantee that the same queue is shared - * system-wide. - * - * <p>No security checks are performed, which is why this method - * may only be called by Toolkits. - * - * @see #getSystemEventQueue() - */ - protected abstract EventQueue getSystemEventQueueImpl(); - - - /** - * @since 1.3 - */ - public abstract DragSourceContextPeer - createDragSourceContextPeer(DragGestureEvent e); - - /** - * @since 1.3 - */ - public DragGestureRecognizer - createDragGestureRecognizer(Class recognizer, DragSource ds, - Component comp, int actions, - DragGestureListener l) - { - return null; - } - - public final Object getDesktopProperty(String propertyName) - { - return desktopProperties.get(propertyName); - } - - protected final void setDesktopProperty(String name, Object newValue) - { - Object oldValue = getDesktopProperty(name); - desktopProperties.put(name, newValue); - desktopPropsSupport.firePropertyChange(name, oldValue, newValue); - } - - protected Object lazilyLoadDesktopProperty(String name) - { - // FIXME - what is this?? - return null; - } - - protected void initializeDesktopProperties() - { - // Overridden by toolkit implementation? - } - - public void addPropertyChangeListener(String name, - PropertyChangeListener pcl) - { - desktopPropsSupport.addPropertyChangeListener(name, pcl); - } - - public void removePropertyChangeListener(String name, - PropertyChangeListener pcl) - { - desktopPropsSupport.removePropertyChangeListener(name, pcl); - } - - /** - * @since 1.4 - */ - public PropertyChangeListener[] getPropertyChangeListeners() - { - return desktopPropsSupport.getPropertyChangeListeners(); - } - - /** - * @since 1.4 - */ - public PropertyChangeListener[] getPropertyChangeListeners(String name) - { - return desktopPropsSupport.getPropertyChangeListeners(name); - } - - public void addAWTEventListener(AWTEventListener listener, long eventMask) - { - // SecurityManager s = System.getSecurityManager(); - // if (s != null) - // s.checkPermission(AWTPermission("listenToAllAWTEvents")); - // FIXME - } - - public void removeAWTEventListener(AWTEventListener listener) - { - // FIXME - } - - /** - * @since 1.4 - */ - public AWTEventListener[] getAWTEventListeners() - { - return null; - } - - /** - * @since 1.4 - */ - public AWTEventListener[] getAWTEventListeners(long mask) - { - return null; - } - - /** - * @since 1.3 - */ - public abstract Map mapInputMethodHighlight(InputMethodHighlight highlight); -} // class Toolkit diff --git a/libjava/java/awt/Transparency.java b/libjava/java/awt/Transparency.java deleted file mode 100644 index 88858717693..00000000000 --- a/libjava/java/awt/Transparency.java +++ /dev/null @@ -1,67 +0,0 @@ -/* Transparency.java -- common transparency modes in graphics - Copyright (C) 2000, 2002, 2005 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.awt; - -/** - * A common transparency mode for layering graphics. - * - * @author Warren Levy (warrenl@cygnus.com) - * @since 1.1 - * @status updated to 1.4 - */ -public interface Transparency -{ - /** Image data which is completely opaque, for an alpha value of 1.0. */ - int OPAQUE = 1; - - /** - * Image data which is either completely opaque or transparent, for an - * exact integer alpha value. - */ - int BITMASK = 2; - - /** Image data which is translucent, for a non-integer alpha value. */ - int TRANSLUCENT = 3; - - /** - * Return the transparency type. - * - * @return One of {@link #OPAQUE}, {@link #BITMASK}, or {@link #TRANSLUCENT}. - */ - int getTransparency(); -} // interface Transparency diff --git a/libjava/java/awt/Window.java b/libjava/java/awt/Window.java deleted file mode 100644 index 87b6c5767c5..00000000000 --- a/libjava/java/awt/Window.java +++ /dev/null @@ -1,1132 +0,0 @@ -/* Window.java -- - Copyright (C) 1999, 2000, 2002, 2003, 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.awt.event.ComponentEvent; -import java.awt.event.FocusEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.awt.event.WindowFocusListener; -import java.awt.event.WindowListener; -import java.awt.event.WindowStateListener; -import java.awt.image.BufferStrategy; -import java.awt.peer.WindowPeer; -import java.lang.ref.Reference; -import java.lang.ref.WeakReference; -import java.util.EventListener; -import java.util.Iterator; -import java.util.Locale; -import java.util.ResourceBundle; -import java.util.Vector; - -import javax.accessibility.Accessible; -import javax.accessibility.AccessibleContext; -import javax.accessibility.AccessibleRole; -import javax.accessibility.AccessibleState; -import javax.accessibility.AccessibleStateSet; - -/** - * This class represents a top-level window with no decorations. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Warren Levy (warrenl@cygnus.com) - */ -public class Window extends Container implements Accessible -{ - private static final long serialVersionUID = 4497834738069338734L; - - // Serialized fields, from Sun's serialization spec. - private String warningString = null; - private int windowSerializedDataVersion = 0; // FIXME - /** @since 1.2 */ - // private FocusManager focusMgr; // FIXME: what is this? - /** @since 1.2 */ - private int state = 0; - /** @since 1.4 */ - private boolean focusableWindowState = true; - - // A list of other top-level windows owned by this window. - private transient Vector ownedWindows = new Vector(); - - private transient WindowListener windowListener; - private transient WindowFocusListener windowFocusListener; - private transient WindowStateListener windowStateListener; - private transient GraphicsConfiguration graphicsConfiguration; - - private transient boolean shown; - - // This is package-private to avoid an accessor method. - transient Component windowFocusOwner; - - /* - * The number used to generate the name returned by getName. - */ - private static transient long next_window_number; - - protected class AccessibleAWTWindow extends AccessibleAWTContainer - { - public AccessibleRole getAccessibleRole() - { - return AccessibleRole.WINDOW; - } - - public AccessibleStateSet getAccessibleStateSet() - { - AccessibleStateSet states = super.getAccessibleStateSet(); - if (isActive()) - states.add(AccessibleState.ACTIVE); - return states; - } - } - - /** - * This (package access) constructor is used by subclasses that want - * to build windows that do not have parents. Eg. toplevel - * application frames. Subclasses cannot call super(null), since - * null is an illegal argument. - */ - Window() - { - visible = false; - // Windows are the only Containers that default to being focus - // cycle roots. - focusCycleRoot = true; - setLayout(new BorderLayout()); - - addWindowFocusListener (new WindowAdapter () - { - public void windowGainedFocus (WindowEvent event) - { - if (windowFocusOwner != null) - { - // FIXME: move this section and the other similar - // sections in Component into a separate method. - EventQueue eq = Toolkit.getDefaultToolkit ().getSystemEventQueue (); - synchronized (eq) - { - KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager (); - Component currentFocusOwner = manager.getGlobalPermanentFocusOwner (); - if (currentFocusOwner != null) - { - eq.postEvent (new FocusEvent (currentFocusOwner, FocusEvent.FOCUS_LOST, - false, windowFocusOwner)); - eq.postEvent (new FocusEvent (windowFocusOwner, FocusEvent.FOCUS_GAINED, - false, currentFocusOwner)); - } - else - eq.postEvent (new FocusEvent (windowFocusOwner, FocusEvent.FOCUS_GAINED, false)); - } - } - } - }); - } - - Window(GraphicsConfiguration gc) - { - this(); - graphicsConfiguration = gc; - } - - /** - * Initializes a new instance of <code>Window</code> with the specified - * parent. The window will initially be invisible. - * - * @param owner The owning <code>Frame</code> of this window. - * - * @exception IllegalArgumentException If the owner's GraphicsConfiguration - * is not from a screen device, or if owner is null; this exception is always - * thrown when GraphicsEnvironment.isHeadless returns true. - */ - public Window(Frame owner) - { - this (owner, owner.getGraphicsConfiguration ()); - } - - /** - * Initializes a new instance of <code>Window</code> with the specified - * parent. The window will initially be invisible. - * - * @exception IllegalArgumentException If the owner's GraphicsConfiguration - * is not from a screen device, or if owner is null; this exception is always - * thrown when GraphicsEnvironment.isHeadless returns true. - * - * @since 1.2 - */ - public Window(Window owner) - { - this (owner, owner.getGraphicsConfiguration ()); - } - - /** - * Initializes a new instance of <code>Window</code> with the specified - * parent. The window will initially be invisible. - * - * @exception IllegalArgumentException If owner is null or if gc is not from a - * screen device; this exception is always thrown when - * GraphicsEnvironment.isHeadless returns true. - * - * @since 1.3 - */ - public Window(Window owner, GraphicsConfiguration gc) - { - this (); - - synchronized (getTreeLock()) - { - if (owner == null) - throw new IllegalArgumentException ("owner must not be null"); - - parent = owner; - owner.ownedWindows.add(new WeakReference(this)); - } - - // FIXME: make this text visible in the window. - SecurityManager s = System.getSecurityManager(); - if (s != null && ! s.checkTopLevelWindow(this)) - warningString = System.getProperty("awt.appletWarning"); - - if (gc != null - && gc.getDevice().getType() != GraphicsDevice.TYPE_RASTER_SCREEN) - throw new IllegalArgumentException ("gc must be from a screen device"); - - if (gc == null) - graphicsConfiguration = GraphicsEnvironment.getLocalGraphicsEnvironment() - .getDefaultScreenDevice() - .getDefaultConfiguration(); - else - graphicsConfiguration = gc; - } - - GraphicsConfiguration getGraphicsConfigurationImpl() - { - if (graphicsConfiguration != null) - return graphicsConfiguration; - - return super.getGraphicsConfigurationImpl(); - } - - /** - * Creates the native peer for this window. - */ - public void addNotify() - { - if (peer == null) - peer = getToolkit().createWindow(this); - super.addNotify(); - } - - /** - * Relays out this window's child components at their preferred size. - * - * @specnote pack() doesn't appear to be called internally by show(), so - * we duplicate some of the functionality. - */ - public void pack() - { - if (parent != null && !parent.isDisplayable()) - parent.addNotify(); - if (peer == null) - addNotify(); - - setSize(getPreferredSize()); - - validate(); - } - - /** - * Shows on-screen this window and any of its owned windows for whom - * isVisible returns true. - */ - public void show() - { - if (parent != null && !parent.isDisplayable()) - parent.addNotify(); - if (peer == null) - addNotify(); - - // Show visible owned windows. - synchronized (getTreeLock()) - { - Iterator e = ownedWindows.iterator(); - while(e.hasNext()) - { - Window w = (Window)(((Reference) e.next()).get()); - if (w != null) - { - if (w.isVisible()) - w.getPeer().setVisible(true); - } - else - // Remove null weak reference from ownedWindows. - // Unfortunately this can't be done in the Window's - // finalize method because there is no way to guarantee - // synchronous access to ownedWindows there. - e.remove(); - } - } - validate(); - super.show(); - toFront(); - - KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager (); - manager.setGlobalFocusedWindow (this); - - if (!shown) - { - FocusTraversalPolicy policy = getFocusTraversalPolicy (); - Component initialFocusOwner = null; - - if (policy != null) - initialFocusOwner = policy.getInitialComponent (this); - - if (initialFocusOwner != null) - initialFocusOwner.requestFocusInWindow (); - - shown = true; - } - } - - public void hide() - { - // Hide visible owned windows. - synchronized (getTreeLock ()) - { - Iterator e = ownedWindows.iterator(); - while(e.hasNext()) - { - Window w = (Window)(((Reference) e.next()).get()); - if (w != null) - { - if (w.isVisible() && w.getPeer() != null) - w.getPeer().setVisible(false); - } - else - e.remove(); - } - } - super.hide(); - } - - public boolean isDisplayable() - { - if (super.isDisplayable()) - return true; - return peer != null; - } - - /** - * Destroys any resources associated with this window. This includes - * all components in the window and all owned top-level windows. - */ - public void dispose() - { - hide(); - - synchronized (getTreeLock ()) - { - Iterator e = ownedWindows.iterator(); - while(e.hasNext()) - { - Window w = (Window)(((Reference) e.next()).get()); - if (w != null) - w.dispose(); - else - // Remove null weak reference from ownedWindows. - e.remove(); - } - - for (int i = 0; i < ncomponents; ++i) - component[i].removeNotify(); - this.removeNotify(); - - // Post a WINDOW_CLOSED event. - WindowEvent we = new WindowEvent(this, WindowEvent.WINDOW_CLOSED); - getToolkit().getSystemEventQueue().postEvent(we); - } - } - - /** - * Sends this window to the back so that all other windows display in - * front of it. - */ - public void toBack() - { - if (peer != null) - { - WindowPeer wp = (WindowPeer) peer; - wp.toBack(); - } - } - - /** - * Brings this window to the front so that it displays in front of - * any other windows. - */ - public void toFront() - { - if (peer != null) - { - WindowPeer wp = (WindowPeer) peer; - wp.toFront(); - } - } - - /** - * Returns the toolkit used to create this window. - * - * @return The toolkit used to create this window. - * - * @specnote Unlike Component.getToolkit, this implementation always - * returns the value of Toolkit.getDefaultToolkit(). - */ - public Toolkit getToolkit() - { - return Toolkit.getDefaultToolkit(); - } - - /** - * Returns the warning string that will be displayed if this window is - * popped up by an unsecure applet or application. - * - * @return The unsecure window warning message. - */ - public final String getWarningString() - { - return warningString; - } - - /** - * Returns the locale that this window is configured for. - * - * @return The locale this window is configured for. - */ - public Locale getLocale() - { - return locale == null ? Locale.getDefault() : locale; - } - - /* - /** @since 1.2 - public InputContext getInputContext() - { - // FIXME - } - */ - - /** - * Sets the cursor for this window to the specifiec cursor. - * - * @param cursor The new cursor for this window. - */ - public void setCursor(Cursor cursor) - { - super.setCursor(cursor); - } - - public Window getOwner() - { - return (Window) parent; - } - - /** @since 1.2 */ - public Window[] getOwnedWindows() - { - Window [] trimmedList; - synchronized (getTreeLock ()) - { - // Windows with non-null weak references in ownedWindows. - Window [] validList = new Window [ownedWindows.size()]; - - Iterator e = ownedWindows.iterator(); - int numValid = 0; - while (e.hasNext()) - { - Window w = (Window)(((Reference) e.next()).get()); - if (w != null) - validList[numValid++] = w; - else - // Remove null weak reference from ownedWindows. - e.remove(); - } - - if (numValid != validList.length) - { - trimmedList = new Window [numValid]; - System.arraycopy (validList, 0, trimmedList, 0, numValid); - } - else - trimmedList = validList; - } - return trimmedList; - } - - /** - * Adds the specified listener to the list of <code>WindowListeners</code> - * that will receive events for this window. - * - * @param listener The <code>WindowListener</code> to add. - */ - public synchronized void addWindowListener(WindowListener listener) - { - windowListener = AWTEventMulticaster.add(windowListener, listener); - } - - /** - * Removes the specified listener from the list of - * <code>WindowListeners</code> that will receive events for this window. - * - * @param listener The <code>WindowListener</code> to remove. - */ - public synchronized void removeWindowListener(WindowListener listener) - { - windowListener = AWTEventMulticaster.remove(windowListener, listener); - } - - /** - * Returns an array of all the window listeners registered on this window. - * - * @since 1.4 - */ - public synchronized WindowListener[] getWindowListeners() - { - return (WindowListener[]) - AWTEventMulticaster.getListeners(windowListener, - WindowListener.class); - } - - /** - * Returns an array of all the window focus listeners registered on this - * window. - * - * @since 1.4 - */ - public synchronized WindowFocusListener[] getWindowFocusListeners() - { - return (WindowFocusListener[]) - AWTEventMulticaster.getListeners(windowFocusListener, - WindowFocusListener.class); - } - - /** - * Returns an array of all the window state listeners registered on this - * window. - * - * @since 1.4 - */ - public synchronized WindowStateListener[] getWindowStateListeners() - { - return (WindowStateListener[]) - AWTEventMulticaster.getListeners(windowStateListener, - WindowStateListener.class); - } - - /** - * Adds the specified listener to this window. - */ - public void addWindowFocusListener (WindowFocusListener wfl) - { - windowFocusListener = AWTEventMulticaster.add (windowFocusListener, wfl); - } - - /** - * Adds the specified listener to this window. - * - * @since 1.4 - */ - public void addWindowStateListener (WindowStateListener wsl) - { - windowStateListener = AWTEventMulticaster.add (windowStateListener, wsl); - } - - /** - * Removes the specified listener from this window. - */ - public void removeWindowFocusListener (WindowFocusListener wfl) - { - windowFocusListener = AWTEventMulticaster.remove (windowFocusListener, wfl); - } - - /** - * Removes the specified listener from this window. - * - * @since 1.4 - */ - public void removeWindowStateListener (WindowStateListener wsl) - { - windowStateListener = AWTEventMulticaster.remove (windowStateListener, wsl); - } - - /** - * Returns an array of all the objects currently registered as FooListeners - * upon this Window. FooListeners are registered using the addFooListener - * method. - * - * @exception ClassCastException If listenerType doesn't specify a class or - * interface that implements java.util.EventListener. - * - * @since 1.3 - */ - public EventListener[] getListeners(Class listenerType) - { - if (listenerType == WindowListener.class) - return getWindowListeners(); - return super.getListeners(listenerType); - } - - void dispatchEventImpl(AWTEvent e) - { - // Make use of event id's in order to avoid multiple instanceof tests. - if (e.id <= WindowEvent.WINDOW_LAST - && e.id >= WindowEvent.WINDOW_FIRST - && (windowListener != null - || windowFocusListener != null - || windowStateListener != null - || (eventMask & AWTEvent.WINDOW_EVENT_MASK) != 0)) - processEvent(e); - else - super.dispatchEventImpl(e); - } - - /** - * Processes the specified event for this window. If the event is an - * instance of <code>WindowEvent</code>, then - * <code>processWindowEvent()</code> is called to process the event, - * otherwise the superclass version of this method is invoked. - * - * @param evt The event to process. - */ - protected void processEvent(AWTEvent evt) - { - if (evt instanceof WindowEvent) - processWindowEvent((WindowEvent) evt); - else - super.processEvent(evt); - } - - /** - * Dispatches this event to any listeners that are listening for - * <code>WindowEvents</code> on this window. This method only gets - * invoked if it is enabled via <code>enableEvents()</code> or if - * a listener has been added. - * - * @param evt The event to process. - */ - protected void processWindowEvent(WindowEvent evt) - { - int id = evt.getID(); - - if (id == WindowEvent.WINDOW_GAINED_FOCUS - || id == WindowEvent.WINDOW_LOST_FOCUS) - processWindowFocusEvent (evt); - else if (id == WindowEvent.WINDOW_STATE_CHANGED) - processWindowStateEvent (evt); - else - { - if (windowListener != null) - { - switch (evt.getID()) - { - case WindowEvent.WINDOW_ACTIVATED: - windowListener.windowActivated(evt); - break; - - case WindowEvent.WINDOW_CLOSED: - windowListener.windowClosed(evt); - break; - - case WindowEvent.WINDOW_CLOSING: - windowListener.windowClosing(evt); - break; - - case WindowEvent.WINDOW_DEACTIVATED: - windowListener.windowDeactivated(evt); - break; - - case WindowEvent.WINDOW_DEICONIFIED: - windowListener.windowDeiconified(evt); - break; - - case WindowEvent.WINDOW_ICONIFIED: - windowListener.windowIconified(evt); - break; - - case WindowEvent.WINDOW_OPENED: - windowListener.windowOpened(evt); - break; - - default: - break; - } - } - } - } - - /** - * Identifies if this window is active. The active window is a Frame or - * Dialog that has focus or owns the active window. - * - * @return true if active, else false. - * @since 1.4 - */ - public boolean isActive() - { - KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager (); - return manager.getActiveWindow() == this; - } - - /** - * Identifies if this window is focused. A window is focused if it is the - * focus owner or it contains the focus owner. - * - * @return true if focused, else false. - * @since 1.4 - */ - public boolean isFocused() - { - KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager (); - return manager.getFocusedWindow() == this; - } - - /** - * Returns the child window that has focus if this window is active. - * This method returns <code>null</code> if this window is not active - * or no children have focus. - * - * @return The component that has focus, or <code>null</code> if no - * component has focus. - */ - public Component getFocusOwner () - { - KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager (); - - Window activeWindow = manager.getActiveWindow (); - - // The currently-focused Component belongs to the active Window. - if (activeWindow == this) - return manager.getFocusOwner (); - else - return windowFocusOwner; - } - - /** - * Set the focus owner for this window. This method is used to - * remember which component was focused when this window lost - * top-level focus, so that when it regains top-level focus the same - * child component can be refocused. - * - * @param windowFocusOwner the component in this window that owns - * the focus. - */ - void setFocusOwner (Component windowFocusOwner) - { - this.windowFocusOwner = windowFocusOwner; - } - - /** - * Post a Java 1.0 event to the event queue. - * - * @param e The event to post. - * - * @deprecated - */ - public boolean postEvent(Event e) - { - return handleEvent (e); - } - - /** - * Tests whether or not this window is visible on the screen. - * - * @return <code>true</code> if this window is visible, <code>false</code> - * otherwise. - */ - public boolean isShowing() - { - return super.isShowing(); - } - - public void setLocationRelativeTo (Component c) - { - if (c == null || !c.isShowing ()) - { - int x = 0; - int y = 0; - - GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment (); - Point center = ge.getCenterPoint (); - x = center.x - (width / 2); - y = center.y - (height / 2); - setLocation (x, y); - } - // FIXME: handle case where component is non-null. - } - - /** - * A BltBufferStrategy for windows. - */ - private class WindowBltBufferStrategy extends BltBufferStrategy - { - /** - * Creates a block transfer strategy for this window. - * - * @param numBuffers the number of buffers in this strategy - * @param accelerated true if the buffer should be accelerated, - * false otherwise - */ - WindowBltBufferStrategy(int numBuffers, boolean accelerated) - { - super(numBuffers, - new BufferCapabilities(new ImageCapabilities(accelerated), - new ImageCapabilities(accelerated), - BufferCapabilities.FlipContents.COPIED)); - } - } - - /** - * A FlipBufferStrategy for windows. - */ - private class WindowFlipBufferStrategy extends FlipBufferStrategy - { - /** - * Creates a flip buffer strategy for this window. - * - * @param numBuffers the number of buffers in this strategy - * - * @throws AWTException if the requested number of buffers is not - * supported - */ - WindowFlipBufferStrategy(int numBuffers) - throws AWTException - { - super(numBuffers, - new BufferCapabilities(new ImageCapabilities(true), - new ImageCapabilities(true), - BufferCapabilities.FlipContents.COPIED)); - } - } - - /** - * Creates a buffering strategy that manages how this window is - * repainted. This method attempts to create the optimum strategy - * based on the desired number of buffers. Hardware or software - * acceleration may be used. - * - * createBufferStrategy attempts different levels of optimization, - * but guarantees that some strategy with the requested number of - * buffers will be created even if it is not optimal. First it - * attempts to create a page flipping strategy, then an accelerated - * blitting strategy, then an unaccelerated blitting strategy. - * - * Calling this method causes any existing buffer strategy to be - * destroyed. - * - * @param numBuffers the number of buffers in this strategy - * - * @throws IllegalArgumentException if requested number of buffers - * is less than one - * @throws IllegalStateException if this window is not displayable - * - * @since 1.4 - */ - public void createBufferStrategy(int numBuffers) - { - if (numBuffers < 1) - throw new IllegalArgumentException("Window.createBufferStrategy: number" - + " of buffers is less than one"); - - if (!isDisplayable()) - throw new IllegalStateException("Window.createBufferStrategy: window is" - + " not displayable"); - - // try a flipping strategy - try - { - bufferStrategy = new WindowFlipBufferStrategy(numBuffers); - return; - } - catch (AWTException e) - { - } - - // try an accelerated blitting strategy - try - { - bufferStrategy = new WindowBltBufferStrategy(numBuffers, true); - } - catch (AWTException e) - { - } - - // fall back to an unaccelerated blitting strategy - try - { - bufferStrategy = new WindowBltBufferStrategy(numBuffers, false); - } - catch (AWTException e) - { - } - } - - /** - * Creates a buffering strategy that manages how this window is - * repainted. This method attempts to create a strategy based on - * the specified capabilities and throws an exception if the - * requested strategy is not supported. - * - * Calling this method causes any existing buffer strategy to be - * destroyed. - * - * @param numBuffers the number of buffers in this strategy - * @param caps the requested buffering capabilities - * - * @throws AWTException if the requested capabilities are not - * supported - * @throws IllegalArgumentException if requested number of buffers - * is less than one or if caps is null - * - * @since 1.4 - */ - public void createBufferStrategy(int numBuffers, - BufferCapabilities caps) - { - if (numBuffers < 1) - throw new IllegalArgumentException("Window.createBufferStrategy: number" - + " of buffers is less than one"); - - if (caps == null) - throw new IllegalArgumentException("Window.createBufferStrategy:" - + " capabilities object is null"); - - // a flipping strategy was requested - if (caps.isPageFlipping()) - { - try - { - bufferStrategy = new WindowFlipBufferStrategy(numBuffers); - } - catch (AWTException e) - { - } - } - else - bufferStrategy = new WindowBltBufferStrategy(numBuffers, true); - } - - /** - * Returns the buffer strategy used by the window. - * - * @return the buffer strategy. - * @since 1.4 - */ - public BufferStrategy getBufferStrategy() - { - return bufferStrategy; - } - - /** - * @since 1.2 - * - * @deprecated - */ - public void applyResourceBundle(ResourceBundle rb) - { - throw new Error ("Not implemented"); - } - - /** - * @since 1.2 - * - * @deprecated - */ - public void applyResourceBundle(String rbName) - { - ResourceBundle rb = ResourceBundle.getBundle(rbName, Locale.getDefault(), - ClassLoader.getSystemClassLoader()); - if (rb != null) - applyResourceBundle(rb); - } - - /** - * Gets the AccessibleContext associated with this <code>Window</code>. - * The context is created, if necessary. - * - * @return the associated context - */ - public AccessibleContext getAccessibleContext() - { - /* Create the context if this is the first request */ - if (accessibleContext == null) - accessibleContext = new AccessibleAWTWindow(); - return accessibleContext; - } - - /** - * Get graphics configuration. The implementation for Window will - * not ask any parent containers, since Window is a toplevel - * window and not actually embedded in the parent component. - */ - public GraphicsConfiguration getGraphicsConfiguration() - { - if (graphicsConfiguration != null) return graphicsConfiguration; - if (peer != null) return peer.getGraphicsConfiguration(); - return null; - } - - protected void processWindowFocusEvent(WindowEvent event) - { - if (windowFocusListener != null) - { - switch (event.getID ()) - { - case WindowEvent.WINDOW_GAINED_FOCUS: - windowFocusListener.windowGainedFocus (event); - break; - - case WindowEvent.WINDOW_LOST_FOCUS: - windowFocusListener.windowLostFocus (event); - break; - - default: - break; - } - } - } - - /** - * @since 1.4 - */ - protected void processWindowStateEvent(WindowEvent event) - { - if (windowStateListener != null - && event.getID () == WindowEvent.WINDOW_STATE_CHANGED) - windowStateListener.windowStateChanged (event); - } - - /** - * Returns whether this <code>Window</code> can get the focus or not. - * - * @since 1.4 - */ - public final boolean isFocusableWindow () - { - if (getFocusableWindowState () == false) - return false; - - if (this instanceof Dialog - || this instanceof Frame) - return true; - - // FIXME: Implement more possible cases for returning true. - - return false; - } - - /** - * Returns the value of the focusableWindowState property. - * - * @since 1.4 - */ - public boolean getFocusableWindowState () - { - return focusableWindowState; - } - - /** - * Sets the value of the focusableWindowState property. - * - * @since 1.4 - */ - public void setFocusableWindowState (boolean focusableWindowState) - { - this.focusableWindowState = focusableWindowState; - } - - // setBoundsCallback is needed so that when a user moves a window, - // the Window's location can be updated without calling the peer's - // setBounds method. When a user moves a window the peer window's - // location is updated automatically and the windowing system sends - // a message back to the application informing it of its updated - // dimensions. We must update the AWT Window class with these new - // dimensions. But we don't want to call the peer's setBounds - // method, because the peer's dimensions have already been updated. - // (Under X, having this method prevents Configure event loops when - // moving windows: Component.setBounds -> peer.setBounds -> - // postConfigureEvent -> Component.setBounds -> ... In some cases - // Configure event loops cause windows to jitter back and forth - // continuously). - void setBoundsCallback (int x, int y, int w, int h) - { - if (this.x == x && this.y == y && width == w && height == h) - return; - invalidate(); - boolean resized = width != w || height != h; - boolean moved = this.x != x || this.y != y; - this.x = x; - this.y = y; - width = w; - height = h; - if (resized && isShowing ()) - { - ComponentEvent ce = - new ComponentEvent(this, ComponentEvent.COMPONENT_RESIZED); - getToolkit().getSystemEventQueue().postEvent(ce); - } - if (moved && isShowing ()) - { - ComponentEvent ce = - new ComponentEvent(this, ComponentEvent.COMPONENT_MOVED); - getToolkit().getSystemEventQueue().postEvent(ce); - } - } - - /** - * Generate a unique name for this window. - * - * @return A unique name for this window. - */ - String generateName() - { - return "win" + getUniqueLong(); - } - - private static synchronized long getUniqueLong() - { - return next_window_number++; - } -} diff --git a/libjava/java/awt/color/CMMException.java b/libjava/java/awt/color/CMMException.java deleted file mode 100644 index ab328ec8492..00000000000 --- a/libjava/java/awt/color/CMMException.java +++ /dev/null @@ -1,63 +0,0 @@ -/* CMMException.java -- error in the native CMM - Copyright (C) 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.color; - -/** - * Thrown when there is an error in the native CMM. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @status updated to 1.4 - */ -public class CMMException extends RuntimeException -{ - /** - * Compatible with JDK 1.2+. - */ - private static final long serialVersionUID = 5775558044142994965L; - - /** - * Create a new instance with a specified detailed error message. - * - * @param message the message - */ - public CMMException(String message) - { - super(message); - } -} // class CMMException diff --git a/libjava/java/awt/color/ColorSpace.java b/libjava/java/awt/color/ColorSpace.java deleted file mode 100644 index 79369da710f..00000000000 --- a/libjava/java/awt/color/ColorSpace.java +++ /dev/null @@ -1,183 +0,0 @@ -/* ColorSpace.java -- transforms between color spaces - Copyright (C) 2000, 2002 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.color; - -import java.io.Serializable; - -/** - * NEEDS DOCUMENTATION - * - * @author Rolf W. Rasmussen (rolfwr@ii.uib.no) - * @since 1.2 - */ -public abstract class ColorSpace implements Serializable -{ - /** - * Compatible with JDK 1.2+. - */ - private static final long serialVersionUID = -409452704308689724L; - - public static final int TYPE_XYZ = 0; - public static final int TYPE_Lab = 1; - public static final int TYPE_Luv = 2; - public static final int TYPE_YCbCr = 3; - public static final int TYPE_Yxy = 4; - public static final int TYPE_RGB = 5; - public static final int TYPE_GRAY = 6; - public static final int TYPE_HSV = 7; - public static final int TYPE_HLS = 8; - public static final int TYPE_CMYK = 9; - // mysterious gap in the enumeration sequenece - public static final int TYPE_CMY = 11; - public static final int TYPE_2CLR = 12; - public static final int TYPE_3CLR = 13; - public static final int TYPE_4CLR = 14; - public static final int TYPE_5CLR = 15; - public static final int TYPE_6CLR = 16; - public static final int TYPE_7CLR = 17; - public static final int TYPE_8CLR = 18; - public static final int TYPE_9CLR = 19; - public static final int TYPE_ACLR = 20; - public static final int TYPE_BCLR = 21; - public static final int TYPE_CCLR = 22; - public static final int TYPE_DCLR = 23; - public static final int TYPE_ECLR = 24; - public static final int TYPE_FCLR = 25; - - public static final int CS_sRGB = 1000; - public static final int CS_LINEAR_RGB = 1004; - public static final int CS_CIEXYZ = 1001; - public static final int CS_PYCC = 1002; - public static final int CS_GRAY = 1003; - - private static final int CS_BASE = CS_sRGB; - private static final int CS_END = CS_LINEAR_RGB + 1; - private static final int CS_COUNT = CS_END - CS_BASE; - - // Instances are lazily instantiated - private static final ColorSpace[] INSTANCES = new ColorSpace[CS_COUNT]; - - /** - * @serial - */ - // Visible in subclass. - final int type; - - /** - * @serial - */ - // Visible in subclass. - final int numComponents; - - protected ColorSpace(int type, int numcomponents) - { - this.type = type; - numComponents = numcomponents; - } - - public static ColorSpace getInstance(int colorspace) - { - if ((colorspace >= CS_BASE) && (colorspace < CS_END)) - { - int instanceIndex = colorspace - CS_BASE; - if (INSTANCES[instanceIndex] == null) - { - ICC_Profile profile = new ICC_Profile(colorspace); - INSTANCES[instanceIndex] = new ICC_ColorSpace(profile); - } - return INSTANCES[instanceIndex]; - } - throw new IllegalArgumentException("unknown/unsupported colorspace"); - } - - public boolean isCS_sRGB() - { - return type == CS_sRGB; - } - - /** - * Transforms a color value assumed to be in this ColorSpace into a value in - * the default CS_sRGB color space. - * - * @exception ArrayIndexOutOfBoundsException If array length is not at least - * the number of components in this ColorSpace. - */ - public abstract float[] toRGB(float[] colorvalue); - - public abstract float[] fromRGB(float[] rgbvalue); - - public abstract float[] toCIEXYZ(float[] colorvalue); - - public abstract float[] fromCIEXYZ(float[] colorvalue); - - public int getType() - { - return type; - } - - public int getNumComponents() - { - return numComponents; - } - - public String getName(int idx) - { - return "type " + type; - } - - /** - * @since 1.4 - */ - public float getMinValue(int idx) - { - if (idx < 0 || idx >= numComponents) - throw new IllegalArgumentException(); - return 0; - } - - /** - * @since 1.4 - */ - public float getMaxValue(int idx) - { - if (idx < 0 || idx >= numComponents) - throw new IllegalArgumentException(); - return 1; - } -} // class ColorSpace diff --git a/libjava/java/awt/color/ICC_ColorSpace.java b/libjava/java/awt/color/ICC_ColorSpace.java deleted file mode 100644 index b50048cf94b..00000000000 --- a/libjava/java/awt/color/ICC_ColorSpace.java +++ /dev/null @@ -1,314 +0,0 @@ -/* ICC_ColorSpace.java -- the canonical color space implementation - Copyright (C) 2000, 2002, 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.color; - -import gnu.java.awt.color.CieXyzConverter; -import gnu.java.awt.color.ClutProfileConverter; -import gnu.java.awt.color.ColorSpaceConverter; -import gnu.java.awt.color.GrayProfileConverter; -import gnu.java.awt.color.GrayScaleConverter; -import gnu.java.awt.color.LinearRGBConverter; -import gnu.java.awt.color.PyccConverter; -import gnu.java.awt.color.RgbProfileConverter; -import gnu.java.awt.color.SrgbConverter; - -import java.io.IOException; -import java.io.ObjectInputStream; - -/** - * ICC_ColorSpace - an implementation of ColorSpace - * - * While an ICC_Profile class abstracts the data in an ICC profile file - * an ICC_ColorSpace performs the color space conversions defined by - * an ICC_Profile instance. - * - * Typically, an ICC_Profile will either be created using getInstance, - * either from the built-in colorspaces, or from an ICC profile file. - * Then a ICC_Colorspace will be used to perform transforms from the - * device colorspace to and from the profile color space. - * - * The PCS used by ColorSpace is CIE XYZ relative a D50 white point. - * (Profiles using a CIE Lab PCS will have their input and output converted - * to D50 CIE XYZ accordingly. - * - * Note that a valid profile may not contain transforms in both directions, - * in which case the output may be undefined. - * All built-in colorspaces have bidirectional transforms, but developers - * using an ICC profile file may want to check the profile class using - * the ICC_Profile.getProfileClass() method. Input class profiles are - * guaranteed to have transforms to the PCS, output class profiles are - * guaranteed to have transforms from the PCS to device space. - * - * @author Sven de Marothy - * @author Rolf W. Rasmussen (rolfwr@ii.uib.no) - * @since 1.2 - */ -public class ICC_ColorSpace extends ColorSpace -{ - /** - * Compatible with JDK 1.2+. - */ - private static final long serialVersionUID = 3455889114070431483L; - - /** - * @serial - */ - private ICC_Profile thisProfile; - - /** - * @serial - */ - private float[] minVal; - - /** - * @serial - */ - private float[] maxVal; - - /** - * @serial - */ - private float[] diffMinMax; - - /** - * @serial - */ - private float[] invDiffMinMax; - - /** - * @serial - */ - private boolean needScaleInit; - - /** - * Tells us if the PCS is CIE LAB (must be CIEXYZ otherwise) - */ - private transient int type; - private transient int nComponents; - private transient ColorSpaceConverter converter; - - /** - * Constructs a new ICC_ColorSpace from an ICC_Profile object. - * - * @exception IllegalArgumentException If profile is inappropriate for - * representing a ColorSpace. - */ - public ICC_ColorSpace(ICC_Profile profile) - { - super(profile.getColorSpaceType(), profile.getNumComponents()); - - converter = getConverter(profile); - thisProfile = profile; - nComponents = profile.getNumComponents(); - type = profile.getColorSpaceType(); - makeArrays(); - } - - /** - * Return the profile - */ - public ICC_Profile getProfile() - { - return thisProfile; - } - - /** - * Transforms a color value assumed to be in this ColorSpace into a value in - * the default CS_sRGB color space. - * - * @exception ArrayIndexOutOfBoundsException If array length is not at least - * the number of components in this ColorSpace. - */ - public float[] toRGB(float[] colorvalue) - { - return converter.toRGB(colorvalue); - } - - /** - * Transforms a color value assumed to be in the default CS_sRGB color space - * into this ColorSpace. - * - * @exception ArrayIndexOutOfBoundsException If array length is not at - * least 3. - */ - public float[] fromRGB(float[] rgbvalue) - { - return converter.fromRGB(rgbvalue); - } - - /** - * Transforms a color value assumed to be in this ColorSpace into the - * CS_CIEXYZ conversion color space. - * - * @exception ArrayIndexOutOfBoundsException If array length is not at - * least the number of components in this ColorSpace. - */ - public float[] toCIEXYZ(float[] colorvalue) - { - return converter.toCIEXYZ(colorvalue); - } - - /** - * Transforms a color value assumed to be in the CS_CIEXYZ conversion color - * space into this ColorSpace. - * - * @exception ArrayIndexOutOfBoundsException If array length is not at - * least 3. - */ - public float[] fromCIEXYZ(float[] colorvalue) - { - return converter.fromCIEXYZ(colorvalue); - } - - public boolean isCS_sRGB() - { - return converter instanceof SrgbConverter; - } - - /** - * Returns the minimum normalized color component value for the specified - * component. - * - * @exception IllegalArgumentException If component is less than 0 or greater - * than numComponents - 1. - * - * @since 1.4 - */ - public float getMinValue(int idx) - { - // FIXME: Not 100% certain of this. - if (type == ColorSpace.TYPE_Lab && (idx == 1 || idx == 2)) - return -128f; - - if (idx < 0 || idx >= nComponents) - throw new IllegalArgumentException(); - return 0; - } - - /** - * Returns the maximum normalized color component value for the specified - * component. - * - * @exception IllegalArgumentException If component is less than 0 or greater - * than numComponents - 1. - * - * @since 1.4 - */ - public float getMaxValue(int idx) - { - if (type == ColorSpace.TYPE_XYZ && idx >= 0 && idx <= 2) - return 1 + 32767 / 32768f; - else if (type == ColorSpace.TYPE_Lab) - { - if (idx == 0) - return 100; - if (idx == 1 || idx == 2) - return 127; - } - if (idx < 0 || idx >= nComponents) - throw new IllegalArgumentException(); - return 1; - } - - /** - * Returns a colorspace converter suitable for a given profile - */ - private ColorSpaceConverter getConverter(ICC_Profile profile) - { - ColorSpaceConverter converter; - switch (profile.isPredefined()) - { - case CS_sRGB: - converter = new SrgbConverter(); - break; - case CS_CIEXYZ: - converter = new CieXyzConverter(); - break; - case CS_GRAY: - converter = new GrayScaleConverter(); - break; - case CS_LINEAR_RGB: - converter = new LinearRGBConverter(); - break; - case CS_PYCC: - converter = new PyccConverter(); - break; - default: - if (profile instanceof ICC_ProfileRGB) - converter = new RgbProfileConverter((ICC_ProfileRGB) profile); - else if (profile instanceof ICC_ProfileGray) - converter = new GrayProfileConverter((ICC_ProfileGray) profile); - else - converter = new ClutProfileConverter(profile); - break; - } - return converter; - } - - /** - * Serialization compatibility requires these variable to be set, - * although we don't use them. Perhaps we should? - */ - private void makeArrays() - { - minVal = new float[nComponents]; - maxVal = new float[nComponents]; - - invDiffMinMax = diffMinMax = null; - for (int i = 0; i < nComponents; i++) - { - minVal[i] = getMinValue(i); - maxVal[i] = getMaxValue(i); - } - needScaleInit = true; - } - - /** - * Deserializes the object - */ - private void readObject(ObjectInputStream s) - throws IOException, ClassNotFoundException - { - s.defaultReadObject(); - // set up objects - converter = getConverter(thisProfile); - nComponents = thisProfile.getNumComponents(); - type = thisProfile.getColorSpaceType(); - } -} // class ICC_ColorSpace diff --git a/libjava/java/awt/color/ICC_Profile.java b/libjava/java/awt/color/ICC_Profile.java deleted file mode 100644 index 75f55a1dacb..00000000000 --- a/libjava/java/awt/color/ICC_Profile.java +++ /dev/null @@ -1,1244 +0,0 @@ -/* ICC_Profile.java -- color space profiling - Copyright (C) 2000, 2002, 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.color; - -import gnu.java.awt.color.ProfileHeader; -import gnu.java.awt.color.TagEntry; - -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.ObjectStreamException; -import java.io.OutputStream; -import java.io.Serializable; -import java.io.UnsupportedEncodingException; -import java.nio.ByteBuffer; -import java.util.Enumeration; -import java.util.Hashtable; - -/** - * ICC Profile - represents an ICC Color profile. - * The ICC profile format is a standard file format which maps the transform - * from a device color space to a standard Profile Color Space (PCS), which - * can either be CIE L*a*b or CIE XYZ. - * (With the exception of device link profiles which map from one device space - * to another) - * - * ICC profiles calibrated to specific input/output devices are used when color - * fidelity is of importance. - * - * An instance of ICC_Profile can be created using the getInstance() methods, - * either using one of the predefined color spaces enumerated in ColorSpace, - * or from an ICC profile file, or from an input stream. - * - * An ICC_ColorSpace object can then be created to transform color values - * through the profile. - * - * The ICC_Profile class implements the version 2 format specified by - * International Color Consortium Specification ICC.1:1998-09, - * and its addendum ICC.1A:1999-04, April 1999 - * (available at www.color.org) - * - * @author Sven de Marothy - * @author Rolf W. Rasmussen (rolfwr@ii.uib.no) - * @since 1.2 - */ -public class ICC_Profile implements Serializable -{ - /** - * Compatible with JDK 1.2+. - */ - private static final long serialVersionUID = -3938515861990936766L; - - /** - * ICC Profile classes - */ - public static final int CLASS_INPUT = 0; - public static final int CLASS_DISPLAY = 1; - public static final int CLASS_OUTPUT = 2; - public static final int CLASS_DEVICELINK = 3; - public static final int CLASS_COLORSPACECONVERSION = 4; - public static final int CLASS_ABSTRACT = 5; - public static final int CLASS_NAMEDCOLOR = 6; - - /** - * ICC Profile class signatures - */ - public static final int icSigInputClass = 0x73636e72; // 'scnr' - public static final int icSigDisplayClass = 0x6d6e7472; // 'mntr' - public static final int icSigOutputClass = 0x70727472; // 'prtr' - public static final int icSigLinkClass = 0x6c696e6b; // 'link' - public static final int icSigColorSpaceClass = 0x73706163; // 'spac' - public static final int icSigAbstractClass = 0x61627374; // 'abst' - public static final int icSigNamedColorClass = 0x6e6d636c; // 'nmcl' - - /** - * Color space signatures - */ - public static final int icSigXYZData = 0x58595A20; // 'XYZ ' - public static final int icSigLabData = 0x4C616220; // 'Lab ' - public static final int icSigLuvData = 0x4C757620; // 'Luv ' - public static final int icSigYCbCrData = 0x59436272; // 'YCbr' - public static final int icSigYxyData = 0x59787920; // 'Yxy ' - public static final int icSigRgbData = 0x52474220; // 'RGB ' - public static final int icSigGrayData = 0x47524159; // 'GRAY' - public static final int icSigHsvData = 0x48535620; // 'HSV ' - public static final int icSigHlsData = 0x484C5320; // 'HLS ' - public static final int icSigCmykData = 0x434D594B; // 'CMYK' - public static final int icSigCmyData = 0x434D5920; // 'CMY ' - public static final int icSigSpace2CLR = 0x32434C52; // '2CLR' - public static final int icSigSpace3CLR = 0x33434C52; // '3CLR' - public static final int icSigSpace4CLR = 0x34434C52; // '4CLR' - public static final int icSigSpace5CLR = 0x35434C52; // '5CLR' - public static final int icSigSpace6CLR = 0x36434C52; // '6CLR' - public static final int icSigSpace7CLR = 0x37434C52; // '7CLR' - public static final int icSigSpace8CLR = 0x38434C52; // '8CLR' - public static final int icSigSpace9CLR = 0x39434C52; // '9CLR' - public static final int icSigSpaceACLR = 0x41434C52; // 'ACLR' - public static final int icSigSpaceBCLR = 0x42434C52; // 'BCLR' - public static final int icSigSpaceCCLR = 0x43434C52; // 'CCLR' - public static final int icSigSpaceDCLR = 0x44434C52; // 'DCLR' - public static final int icSigSpaceECLR = 0x45434C52; // 'ECLR' - public static final int icSigSpaceFCLR = 0x46434C52; // 'FCLR' - - /** - * Rendering intents - */ - public static final int icPerceptual = 0; - public static final int icRelativeColorimetric = 1; - public static final int icSaturation = 2; - public static final int icAbsoluteColorimetric = 3; - - /** - * Tag signatures - */ - public static final int icSigAToB0Tag = 0x41324230; // 'A2B0' - public static final int icSigAToB1Tag = 0x41324231; // 'A2B1' - public static final int icSigAToB2Tag = 0x41324232; // 'A2B2' - public static final int icSigBlueColorantTag = 0x6258595A; // 'bXYZ' - public static final int icSigBlueTRCTag = 0x62545243; // 'bTRC' - public static final int icSigBToA0Tag = 0x42324130; // 'B2A0' - public static final int icSigBToA1Tag = 0x42324131; // 'B2A1' - public static final int icSigBToA2Tag = 0x42324132; // 'B2A2' - public static final int icSigCalibrationDateTimeTag = 0x63616C74; // 'calt' - public static final int icSigCharTargetTag = 0x74617267; // 'targ' - public static final int icSigCopyrightTag = 0x63707274; // 'cprt' - public static final int icSigCrdInfoTag = 0x63726469; // 'crdi' - public static final int icSigDeviceMfgDescTag = 0x646D6E64; // 'dmnd' - public static final int icSigDeviceModelDescTag = 0x646D6464; // 'dmdd' - public static final int icSigDeviceSettingsTag = 0x64657673; // 'devs' - public static final int icSigGamutTag = 0x67616D74; // 'gamt' - public static final int icSigGrayTRCTag = 0x6b545243; // 'kTRC' - public static final int icSigGreenColorantTag = 0x6758595A; // 'gXYZ' - public static final int icSigGreenTRCTag = 0x67545243; // 'gTRC' - public static final int icSigLuminanceTag = 0x6C756d69; // 'lumi' - public static final int icSigMeasurementTag = 0x6D656173; // 'meas' - public static final int icSigMediaBlackPointTag = 0x626B7074; // 'bkpt' - public static final int icSigMediaWhitePointTag = 0x77747074; // 'wtpt' - public static final int icSigNamedColor2Tag = 0x6E636C32; // 'ncl2' - public static final int icSigOutputResponseTag = 0x72657370; // 'resp' - public static final int icSigPreview0Tag = 0x70726530; // 'pre0' - public static final int icSigPreview1Tag = 0x70726531; // 'pre1' - public static final int icSigPreview2Tag = 0x70726532; // 'pre2' - public static final int icSigProfileDescriptionTag = 0x64657363; // 'desc' - public static final int icSigProfileSequenceDescTag = 0x70736571; // 'pseq' - public static final int icSigPs2CRD0Tag = 0x70736430; // 'psd0' - public static final int icSigPs2CRD1Tag = 0x70736431; // 'psd1' - public static final int icSigPs2CRD2Tag = 0x70736432; // 'psd2' - public static final int icSigPs2CRD3Tag = 0x70736433; // 'psd3' - public static final int icSigPs2CSATag = 0x70733273; // 'ps2s' - public static final int icSigPs2RenderingIntentTag = 0x70733269; // 'ps2i' - public static final int icSigRedColorantTag = 0x7258595A; // 'rXYZ' - public static final int icSigRedTRCTag = 0x72545243; // 'rTRC' - public static final int icSigScreeningDescTag = 0x73637264; // 'scrd' - public static final int icSigScreeningTag = 0x7363726E; // 'scrn' - public static final int icSigTechnologyTag = 0x74656368; // 'tech' - public static final int icSigUcrBgTag = 0x62666420; // 'bfd ' - public static final int icSigViewingCondDescTag = 0x76756564; // 'vued' - public static final int icSigViewingConditionsTag = 0x76696577; // 'view' - public static final int icSigChromaticityTag = 0x6368726D; // 'chrm' - - /** - * Non-ICC tag 'head' for use in retrieving the header with getData() - */ - public static final int icSigHead = 0x68656164; - - /** - * Header offsets - */ - public static final int icHdrSize = 0; - public static final int icHdrCmmId = 4; - public static final int icHdrVersion = 8; - public static final int icHdrDeviceClass = 12; - public static final int icHdrColorSpace = 16; - public static final int icHdrPcs = 20; - public static final int icHdrDate = 24; - public static final int icHdrMagic = 36; - public static final int icHdrPlatform = 40; - public static final int icHdrFlags = 44; - public static final int icHdrManufacturer = 48; - public static final int icHdrModel = 52; - public static final int icHdrAttributes = 56; - public static final int icHdrRenderingIntent = 64; - public static final int icHdrIlluminant = 68; - public static final int icHdrCreator = 80; - - /** - * - */ - public static final int icTagType = 0; - public static final int icTagReserved = 4; - public static final int icCurveCount = 8; - public static final int icCurveData = 12; - public static final int icXYZNumberX = 8; - - /** - * offset of the Tag table - */ - private static final int tagTableOffset = 128; - - /** - * @serial - */ - private static final int iccProfileSerializedDataVersion = 1; - - /** - * Constants related to generating profiles for - * built-in colorspace profiles - */ - /** - * Copyright notice to stick into built-in-profile files. - */ - private static final String copyrightNotice = "Generated by GNU Classpath."; - - /** - * Resolution of the TRC to use for predefined profiles. - * 1024 should suffice. - */ - private static final int TRC_POINTS = 1024; - - /** - * CIE 1931 D50 white point (in Lab coordinates) - */ - private static final float[] D50 = { 0.96422f, 1.00f, 0.82521f }; - - /** - * Color space profile ID - * Set to the predefined profile class (e.g. CS_sRGB) if a predefined - * color space is used, set to -1 otherwise. - * (or if the profile has been modified) - */ - private transient int profileID; - - /** - * The profile header data - */ - private transient ProfileHeader header; - - /** - * A hashtable containing the profile tags as TagEntry objects - */ - private transient Hashtable tagTable; - - /** - * Contructor for predefined colorspaces - */ - ICC_Profile(int profileID) - { - header = null; - tagTable = null; - createProfile(profileID); - } - - /** - * Constructs an ICC_Profile from a header and a table of loaded tags. - */ - ICC_Profile(ProfileHeader h, Hashtable tags) throws IllegalArgumentException - { - header = h; - tagTable = tags; - profileID = -1; // Not a predefined color space - } - - /** - * Constructs an ICC_Profile from a byte array of data. - */ - ICC_Profile(byte[] data) throws IllegalArgumentException - { - // get header and verify it - header = new ProfileHeader(data); - header.verifyHeader(data.length); - tagTable = createTagTable(data); - profileID = -1; // Not a predefined color space - } - - /** - * Free up the used memory. - */ - protected void finalize() - { - } - - /** - * Returns an ICC_Profile instance from a byte array of profile data. - * - * An instance of the specialized classes ICC_ProfileRGB or ICC_ProfileGray - * may be returned if appropriate. - * - * @throws IllegalArgumentException if the profile data is an invalid - * v2 profile. - * - * @param data - the profile data - * @return An ICC_Profile object - */ - public static ICC_Profile getInstance(byte[] data) - { - ProfileHeader header = new ProfileHeader(data); - - // verify it as a correct ICC header, including size - header.verifyHeader(data.length); - - Hashtable tags = createTagTable(data); - - if (isRGBProfile(header, tags)) - return new ICC_ProfileRGB(data); - if (isGrayProfile(header, tags)) - return new ICC_ProfileGray(data); - - return new ICC_Profile(header, tags); - } - - /** - * Returns an predefined ICC_Profile instance. - * - * This will construct an ICC_Profile instance from one of the predefined - * color spaces in the ColorSpace class. (e.g. CS_sRGB, CS_GRAY, etc) - * - * An instance of the specialized classes ICC_ProfileRGB or ICC_ProfileGray - * may be returned if appropriate. - * - * @return An ICC_Profile object - */ - public static ICC_Profile getInstance(int cspace) - { - if (cspace == ColorSpace.CS_sRGB || cspace == ColorSpace.CS_LINEAR_RGB) - return new ICC_ProfileRGB(cspace); - if (cspace == ColorSpace.CS_GRAY) - return new ICC_ProfileGray(cspace); - return new ICC_Profile(cspace); - } - - /** - * Returns an ICC_Profile instance from an ICC Profile file. - * - * An instance of the specialized classes ICC_ProfileRGB or ICC_ProfileGray - * may be returned if appropriate. - * - * @throws IllegalArgumentException if the profile data is an invalid - * v2 profile. - * @throws IOException if the file could not be read. - * - * @param filename - the file name of the profile file. - * @return An ICC_Profile object - */ - public static ICC_Profile getInstance(String filename) - throws IOException - { - return getInstance(new FileInputStream(filename)); - } - - /** - * Returns an ICC_Profile instance from an InputStream. - * - * This method can be used for reading ICC profiles embedded in files - * which support this. (JPEG and SVG for instance). - * - * The stream is treated in the following way: The profile header - * (128 bytes) is read first, and the header is validated. If the profile - * header is valid, it will then attempt to read the rest of the profile - * from the stream. The stream is not closed after reading. - * - * An instance of the specialized classes ICC_ProfileRGB or ICC_ProfileGray - * may be returned if appropriate. - * - * @throws IllegalArgumentException if the profile data is an invalid - * v2 profile. - * @throws IOException if the stream could not be read. - * - * @param in - the input stream to read the profile from. - * @return An ICC_Profile object - */ - public static ICC_Profile getInstance(InputStream in) - throws IOException - { - // read the header - byte[] headerData = new byte[ProfileHeader.HEADERSIZE]; - if (in.read(headerData) != ProfileHeader.HEADERSIZE) - throw new IllegalArgumentException("Invalid profile header"); - - ProfileHeader header = new ProfileHeader(headerData); - - // verify it as a correct ICC header, but do not verify the - // size as we are reading from a stream. - header.verifyHeader(-1); - - // get the size - byte[] data = new byte[header.getSize()]; - System.arraycopy(headerData, 0, data, 0, ProfileHeader.HEADERSIZE); - - // read the rest - if (in.read(data, ProfileHeader.HEADERSIZE, - header.getSize() - ProfileHeader.HEADERSIZE) != header.getSize() - - ProfileHeader.HEADERSIZE) - throw new IOException("Incorrect profile size"); - - return getInstance(data); - } - - /** - * Returns the major version number - */ - public int getMajorVersion() - { - return header.getMajorVersion(); - } - - /** - * Returns the minor version number. - * - * Only the least-significant byte contains data, in BCD form: - * the least-significant nibble is the BCD bug fix revision, - * the most-significant nibble is the BCD minor revision number. - * - * (E.g. For a v2.1.0 profile this will return <code>0x10</code>) - */ - public int getMinorVersion() - { - return header.getMinorVersion(); - } - - /** - * Returns the device class of this profile, - * - * (E.g. CLASS_INPUT for a scanner profile, - * CLASS_OUTPUT for a printer) - */ - public int getProfileClass() - { - return header.getProfileClass(); - } - - /** - * Returns the color space of this profile, in terms - * of the color space constants defined in ColorSpace. - * (For example, it may be a ColorSpace.TYPE_RGB) - */ - public int getColorSpaceType() - { - return header.getColorSpace(); - } - - /** - * Returns the color space of this profile's Profile Connection Space (OCS) - * - * In terms of the color space constants defined in ColorSpace. - * This may be TYPE_XYZ or TYPE_Lab - */ - public int getPCSType() - { - return header.getProfileColorSpace(); - } - - /** - * Writes the profile data to an ICC profile file. - * @param filename - The name of the file to write - * @throws IOException if the write failed. - */ - public void write(String filename) throws IOException - { - FileOutputStream out = new FileOutputStream(filename); - write(out); - out.flush(); - out.close(); - } - - /** - * Writes the profile data in ICC profile file-format to a stream. - * This is useful for embedding ICC profiles in file formats which - * support this (such as JPEG and SVG). - * - * The stream is not closed after writing. - * @param out - The outputstream to which the profile data should be written - * @throws IOException if the write failed. - */ - public void write(OutputStream out) throws IOException - { - out.write(getData()); - } - - /** - * Returns the data corresponding to this ICC_Profile as a byte array. - * - * @return The data in a byte array, - * where the first element corresponds to first byte of the profile file. - */ - public byte[] getData() - { - int size = getSize(); - byte[] data = new byte[size]; - - // Header - System.arraycopy(header.getData(size), 0, data, 0, ProfileHeader.HEADERSIZE); - // # of tags - byte[] tt = getTagTable(); - System.arraycopy(tt, 0, data, ProfileHeader.HEADERSIZE, tt.length); - - Enumeration e = tagTable.elements(); - while (e.hasMoreElements()) - { - TagEntry tag = (TagEntry) e.nextElement(); - System.arraycopy(tag.getData(), 0, - data, tag.getOffset(), tag.getSize()); - } - return data; - } - - /** - * Returns the ICC profile tag data - * The non ICC-tag icSigHead is also permitted to request the header data. - * - * @param tagSignature The ICC signature of the requested tag - * @return A byte array containing the tag data - */ - public byte[] getData(int tagSignature) - { - if (tagSignature == icSigHead) - return header.getData(getSize()); - - TagEntry t = (TagEntry) tagTable.get(TagEntry.tagHashKey(tagSignature)); - if (t == null) - return null; - return t.getData(); - } - - /** - * Sets the ICC profile tag data. - * - * Note that an ICC profile can only contain one tag of each type, if - * a tag already exists with the given signature, it is replaced. - * - * @param tagSignature - The signature of the tag to set - * @param data - A byte array containing the tag data - */ - public void setData(int tagSignature, byte[] data) - { - profileID = -1; // Not a predefined color space if modified. - - if (tagSignature == icSigHead) - header = new ProfileHeader(data); - else - { - TagEntry t = new TagEntry(tagSignature, data); - tagTable.put(t.hashKey(), t); - } - } - - /** - * Get the number of components in the profile's device color space. - */ - public int getNumComponents() - { - int[] lookup = - { - ColorSpace.TYPE_RGB, 3, ColorSpace.TYPE_CMY, 3, - ColorSpace.TYPE_CMYK, 4, ColorSpace.TYPE_GRAY, 1, - ColorSpace.TYPE_YCbCr, 3, ColorSpace.TYPE_XYZ, 3, - ColorSpace.TYPE_Lab, 3, ColorSpace.TYPE_HSV, 3, - ColorSpace.TYPE_2CLR, 2, ColorSpace.TYPE_Luv, 3, - ColorSpace.TYPE_Yxy, 3, ColorSpace.TYPE_HLS, 3, - ColorSpace.TYPE_3CLR, 3, ColorSpace.TYPE_4CLR, 4, - ColorSpace.TYPE_5CLR, 5, ColorSpace.TYPE_6CLR, 6, - ColorSpace.TYPE_7CLR, 7, ColorSpace.TYPE_8CLR, 8, - ColorSpace.TYPE_9CLR, 9, ColorSpace.TYPE_ACLR, 10, - ColorSpace.TYPE_BCLR, 11, ColorSpace.TYPE_CCLR, 12, - ColorSpace.TYPE_DCLR, 13, ColorSpace.TYPE_ECLR, 14, - ColorSpace.TYPE_FCLR, 15 - }; - for (int i = 0; i < lookup.length; i += 2) - if (header.getColorSpace() == lookup[i]) - return lookup[i + 1]; - return 3; // should never happen. - } - - /** - * After deserializing we must determine if the class we want - * is really one of the more specialized ICC_ProfileRGB or - * ICC_ProfileGray classes. - */ - protected Object readResolve() throws ObjectStreamException - { - if (isRGBProfile(header, tagTable)) - return new ICC_ProfileRGB(getData()); - if (isGrayProfile(header, tagTable)) - return new ICC_ProfileGray(getData()); - return this; - } - - /** - * Deserializes an instance - */ - private void readObject(ObjectInputStream s) - throws IOException, ClassNotFoundException - { - s.defaultReadObject(); - String predef = (String) s.readObject(); - byte[] data = (byte[]) s.readObject(); - - if (data != null) - { - header = new ProfileHeader(data); - tagTable = createTagTable(data); - profileID = -1; // Not a predefined color space - } - - if (predef != null) - { - predef = predef.intern(); - if (predef.equals("CS_sRGB")) - createProfile(ColorSpace.CS_sRGB); - if (predef.equals("CS_LINEAR_RGB")) - createProfile(ColorSpace.CS_LINEAR_RGB); - if (predef.equals("CS_CIEXYZ")) - createProfile(ColorSpace.CS_CIEXYZ); - if (predef.equals("CS_GRAY")) - createProfile(ColorSpace.CS_GRAY); - if (predef.equals("CS_PYCC")) - createProfile(ColorSpace.CS_PYCC); - } - } - - /** - * Serializes an instance - * The format is a String and a byte array, - * The string is non-null if the instance is one of the built-in profiles. - * Otherwise the byte array is non-null and represents the profile data. - */ - private void writeObject(ObjectOutputStream s) throws IOException - { - s.defaultWriteObject(); - if (profileID == ColorSpace.CS_sRGB) - s.writeObject("CS_sRGB"); - else if (profileID == ColorSpace.CS_LINEAR_RGB) - s.writeObject("CS_LINEAR_RGB"); - else if (profileID == ColorSpace.CS_CIEXYZ) - s.writeObject("CS_CIEXYZ"); - else if (profileID == ColorSpace.CS_GRAY) - s.writeObject("CS_GRAY"); - else if (profileID == ColorSpace.CS_PYCC) - s.writeObject("CS_PYCC"); - else - { - s.writeObject(null); // null string - s.writeObject(getData()); // data - return; - } - s.writeObject(null); // null data - } - - /** - * Sorts a ICC profile byte array into TagEntry objects stored in - * a hash table. - */ - private static Hashtable createTagTable(byte[] data) - throws IllegalArgumentException - { - ByteBuffer buf = ByteBuffer.wrap(data); - int nTags = buf.getInt(tagTableOffset); - - Hashtable tagTable = new Hashtable(); - for (int i = 0; i < nTags; i++) - { - TagEntry te = new TagEntry(buf.getInt(tagTableOffset - + i * TagEntry.entrySize + 4), - buf.getInt(tagTableOffset - + i * TagEntry.entrySize + 8), - buf.getInt(tagTableOffset - + i * TagEntry.entrySize + 12), - data); - - if (tagTable.put(te.hashKey(), te) != null) - throw new IllegalArgumentException("Duplicate tag in profile:" + te); - } - return tagTable; - } - - /** - * Returns the total size of the padded, stored data - * Note: Tags must be stored on 4-byte aligned offsets. - */ - private int getSize() - { - int totalSize = ProfileHeader.HEADERSIZE; // size of header - - int tagTableSize = 4 + tagTable.size() * TagEntry.entrySize; // size of tag table - if ((tagTableSize & 0x0003) != 0) - tagTableSize += 4 - (tagTableSize & 0x0003); // pad - totalSize += tagTableSize; - - Enumeration e = tagTable.elements(); - while (e.hasMoreElements()) - { // tag data - int tagSize = ((TagEntry) e.nextElement()).getSize(); - if ((tagSize & 0x0003) != 0) - tagSize += 4 - (tagSize & 0x0003); // pad - totalSize += tagSize; - } - return totalSize; - } - - /** - * Generates the tag index table - */ - private byte[] getTagTable() - { - int tagTableSize = 4 + tagTable.size() * TagEntry.entrySize; - if ((tagTableSize & 0x0003) != 0) - tagTableSize += 4 - (tagTableSize & 0x0003); // pad - - int offset = 4; - int tagOffset = ProfileHeader.HEADERSIZE + tagTableSize; - ByteBuffer buf = ByteBuffer.allocate(tagTableSize); - buf.putInt(tagTable.size()); // number of tags - - Enumeration e = tagTable.elements(); - while (e.hasMoreElements()) - { - TagEntry tag = (TagEntry) e.nextElement(); - buf.putInt(offset, tag.getSignature()); - buf.putInt(offset + 4, tagOffset); - buf.putInt(offset + 8, tag.getSize()); - tag.setOffset(tagOffset); - int tagSize = tag.getSize(); - if ((tagSize & 0x0003) != 0) - tagSize += 4 - (tagSize & 0x0003); // pad - tagOffset += tagSize; - offset += 12; - } - return buf.array(); - } - - /** - * Returns if the criteria for an ICC_ProfileRGB are met. - * This means: - * Color space is TYPE_RGB - * (r,g,b)ColorantTags included - * (r,g,b)TRCTags included - * mediaWhitePointTag included - */ - private static boolean isRGBProfile(ProfileHeader header, Hashtable tags) - { - if (header.getColorSpace() != ColorSpace.TYPE_RGB) - return false; - if (tags.get(TagEntry.tagHashKey(icSigRedColorantTag)) == null) - return false; - if (tags.get(TagEntry.tagHashKey(icSigGreenColorantTag)) == null) - return false; - if (tags.get(TagEntry.tagHashKey(icSigBlueColorantTag)) == null) - return false; - if (tags.get(TagEntry.tagHashKey(icSigRedTRCTag)) == null) - return false; - if (tags.get(TagEntry.tagHashKey(icSigGreenTRCTag)) == null) - return false; - if (tags.get(TagEntry.tagHashKey(icSigBlueTRCTag)) == null) - return false; - return (tags.get(TagEntry.tagHashKey(icSigMediaWhitePointTag)) != null); - } - - /** - * Returns if the criteria for an ICC_ProfileGray are met. - * This means: - * Colorspace is TYPE_GRAY - * grayTRCTag included - * mediaWhitePointTag included - */ - private static boolean isGrayProfile(ProfileHeader header, Hashtable tags) - { - if (header.getColorSpace() != ColorSpace.TYPE_GRAY) - return false; - if (tags.get(TagEntry.tagHashKey(icSigGrayTRCTag)) == null) - return false; - return (tags.get(TagEntry.tagHashKey(icSigMediaWhitePointTag)) != null); - } - - /** - * Returns curve data for a 'curv'-type tag - * If it's a gamma curve, a single entry will be returned with the - * gamma value (including 1.0 for linear response) - * Otherwise the TRC table is returned. - * - * (Package private - used by ICC_ProfileRGB and ICC_ProfileGray) - */ - short[] getCurve(int signature) - { - byte[] data = getData(signature); - short[] curve; - - // can't find tag? - if (data == null) - return null; - - // not an curve type tag? - ByteBuffer buf = ByteBuffer.wrap(data); - if (buf.getInt(0) != 0x63757276) // 'curv' type - return null; - int count = buf.getInt(8); - if (count == 0) - { - curve = new short[1]; - curve[0] = 0x0100; // 1.00 in u8fixed8 - return curve; - } - if (count == 1) - { - curve = new short[1]; - curve[0] = buf.getShort(12); // other u8fixed8 gamma - return curve; - } - curve = new short[count]; - for (int i = 0; i < count; i++) - curve[i] = buf.getShort(12 + i * 2); - return curve; - } - - /** - * Returns XYZ tristimulus values for an 'XYZ ' type tag - * @return the XYZ values, or null if the tag was not an 'XYZ ' type tag. - * - * (Package private - used by ICC_ProfileXYZ and ICC_ProfileGray) - */ - float[] getXYZData(int signature) - { - byte[] data = getData(signature); - - // can't find tag? - if (data == null) - return null; - - // not an XYZData type tag? - ByteBuffer buf = ByteBuffer.wrap(data); - if (buf.getInt(0) != icSigXYZData) // 'XYZ ' type - return null; - - float[] point = new float[3]; - - // get the X,Y,Z tristimulus values - point[0] = ((float) buf.getInt(8)) / 65536f; - point[1] = ((float) buf.getInt(12)) / 65536f; - point[2] = ((float) buf.getInt(16)) / 65536f; - return point; - } - - /** - * Returns the profile ID if it's a predefined profile - * Or -1 for a profile loaded from an ICC profile - * - * (Package private - used by ICC_ColorSpace) - */ - int isPredefined() - { - return profileID; - } - - /** - * Creates a tag of XYZ-value type. - */ - private byte[] makeXYZData(float[] values) - { - ByteBuffer buf = ByteBuffer.allocate(20); - buf.putInt(0, icSigXYZData); // 'XYZ ' - buf.putInt(4, 0); - buf.putInt(8, (int) (values[0] * 65536.0)); - buf.putInt(12, (int) (values[1] * 65536.0)); - buf.putInt(16, (int) (values[2] * 65536.0)); - return buf.array(); - } - - /** - * Creates a tag of text type - */ - private byte[] makeTextTag(String text) - { - int length = text.length(); - ByteBuffer buf = ByteBuffer.allocate(8 + length + 1); - byte[] data; - try - { - data = text.getBytes("US-ASCII"); - } - catch (UnsupportedEncodingException e) - { - data = new byte[length]; // shouldn't happen - } - - buf.putInt(0, (int) 0x74657874); // 'text' - buf.putInt(4, 0); - for (int i = 0; i < length; i++) - buf.put(8 + i, data[i]); - buf.put(8 + length, (byte) 0); // null-terminate - return buf.array(); - } - - /** - * Creates a tag of textDescriptionType - */ - private byte[] makeDescTag(String text) - { - int length = text.length(); - ByteBuffer buf = ByteBuffer.allocate(90 + length + 1); - buf.putInt(0, (int) 0x64657363); // 'desc' - buf.putInt(4, 0); // reserved - buf.putInt(8, length + 1); // ASCII length, including null termination - byte[] data; - - try - { - data = text.getBytes("US-ASCII"); - } - catch (UnsupportedEncodingException e) - { - data = new byte[length]; // shouldn't happen - } - - for (int i = 0; i < length; i++) - buf.put(12 + i, data[i]); - buf.put(12 + length, (byte) 0); // null-terminate - - for (int i = 0; i < 39; i++) - buf.putShort(13 + length + (i * 2), (short) 0); // 78 bytes we can ignore - - return buf.array(); - } - - /** - * Creates a tag of TRC type (linear curve) - */ - private byte[] makeTRC() - { - ByteBuffer buf = ByteBuffer.allocate(12); - buf.putInt(0, 0x63757276); // 'curv' type - buf.putInt(4, 0); // reserved - buf.putInt(8, 0); - return buf.array(); - } - - /** - * Creates a tag of TRC type (single gamma value) - */ - private byte[] makeTRC(float gamma) - { - short gammaValue = (short) (gamma * 256f); - ByteBuffer buf = ByteBuffer.allocate(14); - buf.putInt(0, 0x63757276); // 'curv' type - buf.putInt(4, 0); // reserved - buf.putInt(8, 1); - buf.putShort(12, gammaValue); // 1.00 in u8fixed8 - return buf.array(); - } - - /** - * Creates a tag of TRC type (TRC curve points) - */ - private byte[] makeTRC(float[] trc) - { - ByteBuffer buf = ByteBuffer.allocate(12 + 2 * trc.length); - buf.putInt(0, 0x63757276); // 'curv' type - buf.putInt(4, 0); // reserved - buf.putInt(8, trc.length); // number of points - - // put the curve values - for (int i = 0; i < trc.length; i++) - buf.putShort(12 + i * 2, (short) (trc[i] * 65535f)); - - return buf.array(); - } - - /** - * Creates an identity color lookup table. - */ - private byte[] makeIdentityClut() - { - final int nIn = 3; - final int nOut = 3; - final int nInEntries = 256; - final int nOutEntries = 256; - final int gridpoints = 16; - - // gridpoints**nIn - final int clutSize = 2 * nOut * gridpoints * gridpoints * gridpoints; - final int totalSize = clutSize + 2 * nInEntries * nIn - + 2 * nOutEntries * nOut + 52; - - ByteBuffer buf = ByteBuffer.allocate(totalSize); - buf.putInt(0, 0x6D667432); // 'mft2' - buf.putInt(4, 0); // reserved - buf.put(8, (byte) nIn); // number input channels - buf.put(9, (byte) nOut); // number output channels - buf.put(10, (byte) gridpoints); // number gridpoints - buf.put(11, (byte) 0); // padding - - // identity matrix - buf.putInt(12, 65536); // = 1 in s15.16 fixed point - buf.putInt(16, 0); - buf.putInt(20, 0); - buf.putInt(24, 0); - buf.putInt(28, 65536); - buf.putInt(32, 0); - buf.putInt(36, 0); - buf.putInt(40, 0); - buf.putInt(44, 65536); - - buf.putShort(48, (short) nInEntries); // input table entries - buf.putShort(50, (short) nOutEntries); // output table entries - - // write the linear input channels, unsigned 16.16 fixed point, - // from 0.0 to FF.FF - for (int channel = 0; channel < 3; channel++) - for (int i = 0; i < nInEntries; i++) - { - short n = (short) ((i << 8) | i); // assumes 256 entries - buf.putShort(52 + (channel * nInEntries + i) * 2, n); - } - int clutOffset = 52 + nInEntries * nIn * 2; - - for (int x = 0; x < gridpoints; x++) - for (int y = 0; y < gridpoints; y++) - for (int z = 0; z < gridpoints; z++) - { - int offset = clutOffset + z * 2 * nOut + y * gridpoints * 2 * nOut - + x * gridpoints * gridpoints * 2 * nOut; - double xf = ((double) x) / ((double) gridpoints - 1.0); - double yf = ((double) y) / ((double) gridpoints - 1.0); - double zf = ((double) z) / ((double) gridpoints - 1.0); - buf.putShort(offset, (short) (xf * 65535.0)); - buf.putShort(offset + 2, (short) (yf * 65535.0)); - buf.putShort(offset + 4, (short) (zf * 65535.0)); - } - - for (int channel = 0; channel < 3; channel++) - for (int i = 0; i < nOutEntries; i++) - { - short n = (short) ((i << 8) | i); // assumes 256 entries - buf.putShort(clutOffset + clutSize + (channel * nOutEntries + i) * 2, - n); - } - - return buf.array(); - } - - /** - * Creates profile data corresponding to the built-in colorspaces. - */ - private void createProfile(int colorSpace) throws IllegalArgumentException - { - this.profileID = colorSpace; - header = new ProfileHeader(); - tagTable = new Hashtable(); - - switch (colorSpace) - { - case ColorSpace.CS_sRGB: - createRGBProfile(); - return; - case ColorSpace.CS_LINEAR_RGB: - createLinearRGBProfile(); - return; - case ColorSpace.CS_CIEXYZ: - createCIEProfile(); - return; - case ColorSpace.CS_GRAY: - createGrayProfile(); - return; - case ColorSpace.CS_PYCC: - createPyccProfile(); - return; - default: - throw new IllegalArgumentException("Not a predefined color space!"); - } - } - - /** - * Creates an ICC_Profile representing the sRGB color space - */ - private void createRGBProfile() - { - header.setColorSpace( ColorSpace.TYPE_RGB ); - header.setProfileColorSpace( ColorSpace.TYPE_XYZ ); - ICC_ColorSpace cs = new ICC_ColorSpace(this); - - float[] r = { 1f, 0f, 0f }; - float[] g = { 0f, 1f, 0f }; - float[] b = { 0f, 0f, 1f }; - float[] black = { 0f, 0f, 0f }; - - // CIE 1931 D50 white point (in Lab coordinates) - float[] white = D50; - - // Get tristimulus values (matrix elements) - r = cs.toCIEXYZ(r); - g = cs.toCIEXYZ(g); - b = cs.toCIEXYZ(b); - - // Generate the sRGB TRC curve, this is the linear->nonlinear - // RGB transform. - cs = new ICC_ColorSpace(getInstance(ICC_ColorSpace.CS_LINEAR_RGB)); - float[] points = new float[TRC_POINTS]; - float[] in = new float[3]; - for (int i = 0; i < TRC_POINTS; i++) - { - in[0] = in[1] = in[2] = ((float) i) / ((float) TRC_POINTS - 1); - in = cs.fromRGB(in); - // Note this value is the same for all components. - points[i] = in[0]; - } - - setData(icSigRedColorantTag, makeXYZData(r)); - setData(icSigGreenColorantTag, makeXYZData(g)); - setData(icSigBlueColorantTag, makeXYZData(b)); - setData(icSigMediaWhitePointTag, makeXYZData(white)); - setData(icSigMediaBlackPointTag, makeXYZData(black)); - setData(icSigRedTRCTag, makeTRC(points)); - setData(icSigGreenTRCTag, makeTRC(points)); - setData(icSigBlueTRCTag, makeTRC(points)); - setData(icSigCopyrightTag, makeTextTag(copyrightNotice)); - setData(icSigProfileDescriptionTag, makeDescTag("Generic sRGB")); - this.profileID = ColorSpace.CS_sRGB; - } - - /** - * Creates an linear sRGB profile - */ - private void createLinearRGBProfile() - { - header.setColorSpace(ColorSpace.TYPE_RGB); - header.setProfileColorSpace(ColorSpace.TYPE_XYZ); - ICC_ColorSpace cs = new ICC_ColorSpace(this); - - float[] r = { 1f, 0f, 0f }; - float[] g = { 0f, 1f, 0f }; - float[] b = { 0f, 0f, 1f }; - float[] black = { 0f, 0f, 0f }; - - float[] white = D50; - - // Get tristimulus values (matrix elements) - r = cs.toCIEXYZ(r); - g = cs.toCIEXYZ(g); - b = cs.toCIEXYZ(b); - - setData(icSigRedColorantTag, makeXYZData(r)); - setData(icSigGreenColorantTag, makeXYZData(g)); - setData(icSigBlueColorantTag, makeXYZData(b)); - - setData(icSigMediaWhitePointTag, makeXYZData(white)); - setData(icSigMediaBlackPointTag, makeXYZData(black)); - - setData(icSigRedTRCTag, makeTRC()); - setData(icSigGreenTRCTag, makeTRC()); - setData(icSigBlueTRCTag, makeTRC()); - setData(icSigCopyrightTag, makeTextTag(copyrightNotice)); - setData(icSigProfileDescriptionTag, makeDescTag("Linear RGB")); - this.profileID = ColorSpace.CS_LINEAR_RGB; - } - - /** - * Creates an CIE XYZ identity profile - */ - private void createCIEProfile() - { - header.setColorSpace( ColorSpace.TYPE_XYZ ); - header.setProfileColorSpace( ColorSpace.TYPE_XYZ ); - header.setProfileClass( CLASS_COLORSPACECONVERSION ); - ICC_ColorSpace cs = new ICC_ColorSpace(this); - - float[] white = D50; - - setData(icSigMediaWhitePointTag, makeXYZData(white)); - setData(icSigAToB0Tag, makeIdentityClut()); - setData(icSigBToA0Tag, makeIdentityClut()); - setData(icSigCopyrightTag, makeTextTag(copyrightNotice)); - setData(icSigProfileDescriptionTag, makeDescTag("CIE XYZ identity profile")); - this.profileID = ColorSpace.CS_CIEXYZ; - } - - /** - * Creates a linear gray ICC_Profile - */ - private void createGrayProfile() - { - header.setColorSpace(ColorSpace.TYPE_GRAY); - header.setProfileColorSpace(ColorSpace.TYPE_XYZ); - - // CIE 1931 D50 white point (in Lab coordinates) - float[] white = D50; - - setData(icSigMediaWhitePointTag, makeXYZData(white)); - setData(icSigGrayTRCTag, makeTRC(1.0f)); - setData(icSigCopyrightTag, makeTextTag(copyrightNotice)); - setData(icSigProfileDescriptionTag, makeDescTag("Linear grayscale")); - this.profileID = ColorSpace.CS_GRAY; - } - - /** - * XXX Implement me - */ - private void createPyccProfile() - { - header.setColorSpace(ColorSpace.TYPE_3CLR); - header.setProfileColorSpace(ColorSpace.TYPE_XYZ); - - // Create CLUTs here. :-) - - setData(icSigCopyrightTag, makeTextTag(copyrightNotice)); - setData(icSigProfileDescriptionTag, makeDescTag("Photo YCC")); - this.profileID = ColorSpace.CS_PYCC; - } -} // class ICC_Profile diff --git a/libjava/java/awt/color/ICC_ProfileGray.java b/libjava/java/awt/color/ICC_ProfileGray.java deleted file mode 100644 index 3b5948dc8fc..00000000000 --- a/libjava/java/awt/color/ICC_ProfileGray.java +++ /dev/null @@ -1,133 +0,0 @@ -/* ICC_ProfileGray.java -- the ICC profile for a Gray colorspace - Copyright (C) 2002, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.color; - -/** - * ICC_ProfileGray - a special case of ICC_Profiles. - * - * The ICC_Profile.getInstance() method will return an instance of the - * ICC_ProfileGray subclass when all the following conditions are met: - * The device color space of the profile is TYPE_GRAY. - * The profile contains a gray TRCTag. - * The profile contains a mediaWhitePointTag. - * - * As per the ICC specification, the color space conversion can then - * be done through the following method: - * linearGray = grayTRC[deviceGray] - * - * Note that if the profile contains a CLUT for the color space conversion, - * it should be used instead, and the TRC information ignored. - * - * @author Sven de Marothy - * @since 1.2 - */ -public class ICC_ProfileGray extends ICC_Profile -{ - /** - * Compatible with JDK 1.2+. - */ - private static final long serialVersionUID = -1124721290732002649L; - private transient float[] whitePoint; - - /** - * Package-private constructor used by ICC_ColorSpace for creating an - * ICC_ProfileGray from a predefined ColorSpace (CS_GRAY) - */ - ICC_ProfileGray(int cspace) - { - super(cspace); - whitePoint = getXYZData(icSigMediaWhitePointTag); - } - - /** - * Package-private constructor used by ICC_ColorSpace for creating an - * ICC_ProfileGray from profile data. - */ - ICC_ProfileGray(byte[] data) - { - super(data); - whitePoint = getXYZData(icSigMediaWhitePointTag); - } - - - /** - * Returns the media white point of the profile. - */ - public float[] getMediaWhitePoint() - { - float[] wp = new float[3]; - wp[0] = whitePoint[0]; - wp[1] = whitePoint[1]; - wp[2] = whitePoint[2]; - return wp; - } - - /** - * Returns the TRC gamma value. - * @throws ProfileDataException if the TRC is described by a lookup - * table and not a gamma value. - */ - public float getGamma() - { - short[] data = getCurve(icSigGrayTRCTag); - if (data == null) - throw new IllegalArgumentException("Couldn't read Gray TRC data."); - if (data.length != 1) - throw new ProfileDataException("TRC is a table, not a gamma value."); - - // convert the unsigned 7.8 fixed-point gamma to a float. - double gamma = (double) (data[0] & (0xFFFF)) / 256.0; - return (float) gamma; - } - - /** - * Returns the TRC lookup table. - * @throws ProfileDataException if the TRC is described by a gamma value - * and not a lookup table. - */ - public short[] getTRC() - { - short[] data = getCurve(icSigGrayTRCTag); - if (data == null) - throw new IllegalArgumentException("Couldn't read Gray TRC data."); - if (data.length <= 1) - throw new ProfileDataException("Gamma value, not a TRC table."); - return data; - } -} // class ICC_ProfileGray diff --git a/libjava/java/awt/color/ICC_ProfileRGB.java b/libjava/java/awt/color/ICC_ProfileRGB.java deleted file mode 100644 index 00393328bbd..00000000000 --- a/libjava/java/awt/color/ICC_ProfileRGB.java +++ /dev/null @@ -1,227 +0,0 @@ -/* ICC_ProfileRGB.java -- the ICC profile for a RGB colorspace - Copyright (C) 2002, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.color; - -/** - * ICC_ProfileRGB - a special case of ICC_Profiles. - * - * The ICC_Profile.getInstance() method will return an instance of the - * ICC_ProfileRGB subclass when all the following conditions are met: - * The device color space of the profile is TYPE_RGB. - * The profile contains red, green and blue ColorantTags. - * The profile contains red, green and blue TRCTags. - * The profile contains a mediaWhitePointTag included. - * - * As per the ICC specification, the color space conversion can then - * be done through the following method: - * linearR = redTRC[deviceR] - * linearG = greenTRC[deviceG] - * linearB = blueTRC[deviceB] - * TRC curves are either a single gamma value, or a 1-dimensional lookup table. - * - * Followed by the matrix transform: - * PCS = M*linear - * - * Where PCS is the vector of profile color space (must be XYZ) coordinates, - * linear is the vector of linear RGB coordinates, and the matrix M is - * constructed from the ColorantTags, where the columns are red, green and - * blue respectively, and the rows are X, Y and Z. - * - * Note that if the profile contains a CLUT for the color space conversion, - * it should be used instead, and the TRC information ignored. - * - * @author Sven de Marothy - * @since 1.2 - */ -public class ICC_ProfileRGB extends ICC_Profile -{ - /** - * Compatible with JDK 1.2+. - */ - private static final long serialVersionUID = 8505067385152579334L; - - public static final int REDCOMPONENT = 0; - - public static final int GREENCOMPONENT = 1; - - public static final int BLUECOMPONENT = 2; - - private transient float[][] matrix; - - private transient float[] gamma; - - private transient float[] whitePoint; - - - /** - * Package-private constructor used by ICC_ColorSpace for creating an - * ICC_ProfileRGB from a predefined ColorSpace (CS_LINEAR_RGB and CS_sRGB) - */ - ICC_ProfileRGB(int cspace) - { - super(cspace); - matrix = createMatrix(); - whitePoint = getXYZData(icSigMediaWhitePointTag); - } - - /** - * Package-private constructor used by ICC_ColorSpace for creating an - * ICC_ProfileRGB from profile data. - */ - ICC_ProfileRGB(byte[] data) - { - super(data); - matrix = createMatrix(); - whitePoint = getXYZData(icSigMediaWhitePointTag); - } - - /** - * Returns the media white point of the profile. - */ - public float[] getMediaWhitePoint() - { - float[] wp = new float[3]; - wp[0] = whitePoint[0]; - wp[1] = whitePoint[1]; - wp[2] = whitePoint[2]; - return wp; - } - - /** - * Returns the colorant matrix of the conversion. - */ - public float[][] getMatrix() - { - float[][] mat = new float[3][3]; - for (int i = 0; i < 3; i++) - for (int j = 0; j < 3; j++) - mat[i][j] = matrix[i][j]; - return mat; - } - - /** - * Returns the gamma value of a component - * @throws ProfileDataException if the TRC is described by a lookup - * table and not a gamma value. - */ - public float getGamma(int component) - { - short[] data; - switch (component) - { - case REDCOMPONENT: - data = getCurve(icSigRedTRCTag); - break; - case GREENCOMPONENT: - data = getCurve(icSigGreenTRCTag); - break; - case BLUECOMPONENT: - data = getCurve(icSigBlueTRCTag); - break; - default: - throw new IllegalArgumentException("Not a valid component"); - } - if (data == null) - throw new IllegalArgumentException("Error reading TRC"); - - if (data.length != 1) - throw new ProfileDataException("Not a single-gamma TRC"); - - // convert the unsigned 7.8 fixed-point gamma to a float. - float gamma = (float) (((int) data[0] & 0xFF00) >> 8); - double fraction = ((int) data[0] & 0x00FF) / 256.0; - gamma += (float) fraction; - return gamma; - } - - /** - * Returns the TRC lookup table for a component - * @throws ProfileDataException if the TRC is described by a gamma - * value and not a lookup table. - */ - public short[] getTRC(int component) - { - short[] data; - switch (component) - { - case REDCOMPONENT: - data = getCurve(icSigRedTRCTag); - break; - case GREENCOMPONENT: - data = getCurve(icSigGreenTRCTag); - break; - case BLUECOMPONENT: - data = getCurve(icSigBlueTRCTag); - break; - default: - throw new IllegalArgumentException("Not a valid component"); - } - if (data == null) - throw new IllegalArgumentException("Error reading TRC"); - - if (data.length <= 1) - throw new ProfileDataException("Gamma value, not a TRC table."); - - return data; - } - - /** - * Creates the colorspace conversion matrix from the RGB tristimulus - * values. - */ - private float[][] createMatrix() throws IllegalArgumentException - { - float[][] mat = new float[3][3]; - float[] r; - float[] g; - float[] b; - r = getXYZData(icSigRedColorantTag); - g = getXYZData(icSigGreenColorantTag); - b = getXYZData(icSigBlueColorantTag); - if (r == null || g == null || b == null) - throw new IllegalArgumentException("Error reading colorant tags!"); - for (int i = 0; i < 3; i++) - { - mat[i][0] = r[i]; - mat[i][1] = g[i]; - mat[i][2] = b[i]; - } - return mat; - } -} // class ICC_ProfileRGB diff --git a/libjava/java/awt/color/ProfileDataException.java b/libjava/java/awt/color/ProfileDataException.java deleted file mode 100644 index 1af23b1835c..00000000000 --- a/libjava/java/awt/color/ProfileDataException.java +++ /dev/null @@ -1,64 +0,0 @@ -/* ProfileDataException.java -- error in processing an ICC_Profile - Copyright (C) 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.color; - -/** - * Thrown when there is an error accessing or processing an - * <code>ICC_Profile</code>. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @status updated to 1.4 - */ -public class ProfileDataException extends RuntimeException -{ - /** - * Compatible with JDK 1.2+. - */ - private static final long serialVersionUID = 7286140888240322498L; - - /** - * Create a new instance with a specified detailed error message. - * - * @param message the message - */ - public ProfileDataException(String message) - { - super(message); - } -} // class ProfileDataException diff --git a/libjava/java/awt/datatransfer/Clipboard.java b/libjava/java/awt/datatransfer/Clipboard.java deleted file mode 100644 index 9953a724dba..00000000000 --- a/libjava/java/awt/datatransfer/Clipboard.java +++ /dev/null @@ -1,114 +0,0 @@ -/* Clipboard.java -- Class for transferring data via cut and paste. - Copyright (C) 1999, 2001 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.datatransfer; - -/** - * This class allows data to be transferred using a cut and paste type - * mechanism. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public class Clipboard -{ - /** - * The data being transferred. - */ - protected Transferable contents; - - /** - * The owner of this clipboard. - */ - protected ClipboardOwner owner; - - // The clipboard name - private String name; - - /** - * Initializes a new instance of <code>Clipboard</code> with the - * specified name. - * - * @param name The clipboard name. - */ - public Clipboard(String name) - { - this.name = name; - } - - /** - * Returns the name of the clipboard. - */ - public String getName() - { - return name; - } - - /** - * Returns the contents of the clipboard. - * - * @param requestor The object requesting the contents. - * - * @exception IllegalStateException If the clipboard is currently unavailable - */ - public synchronized Transferable getContents(Object requestor) - { - return contents; - } - - /** - * Sets the content and owner of this clipboard. - * If the given owner is different from the current owner - * then lostOwnership is called on the current owner. - * XXX - is this called with the old or new contents. - * - * @param contents The new clipboard contents. - * @param owner The new clipboard owner - * - * @exception IllegalStateException If the clipboard is currently unavailable - */ - public synchronized void setContents(Transferable contents, ClipboardOwner owner) - { - if (this.owner != owner) - if (this.owner != null) - this.owner.lostOwnership(this, contents); - - this.owner = owner; - this.contents = contents; - } -} - diff --git a/libjava/java/awt/datatransfer/ClipboardOwner.java b/libjava/java/awt/datatransfer/ClipboardOwner.java deleted file mode 100644 index df758254a55..00000000000 --- a/libjava/java/awt/datatransfer/ClipboardOwner.java +++ /dev/null @@ -1,57 +0,0 @@ -/* ClipboardOwner.java -- Interface for clipboard providers - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.datatransfer; - -/** - * This interface is for classes that will own a clipboard object. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public interface ClipboardOwner -{ - /** - * This method is called to notify this object that it no longer - * has ownership of the specified <code>Clipboard</code>. - * - * @param clipboard The clipboard for which ownership was lost. - * @param contents The contents of the clipboard which are no longer owned. - */ - void lostOwnership (Clipboard clipboard, Transferable contents); -} - diff --git a/libjava/java/awt/datatransfer/DataFlavor.java b/libjava/java/awt/datatransfer/DataFlavor.java deleted file mode 100644 index e5fbd240293..00000000000 --- a/libjava/java/awt/datatransfer/DataFlavor.java +++ /dev/null @@ -1,1034 +0,0 @@ -/* DataFlavor.java -- A type of data to transfer via the clipboard. - Copyright (C) 1999, 2001, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.datatransfer; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.io.Reader; -import java.io.StringReader; -import java.io.UnsupportedEncodingException; -import java.nio.ByteBuffer; -import java.nio.CharBuffer; - -/** - * This class represents a particular data format used for transferring - * data via the clipboard. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public class DataFlavor implements java.io.Externalizable, Cloneable -{ - static final long serialVersionUID = 8367026044764648243L; - - // FIXME: Serialization: Need to write methods for. - -/** - * This is the data flavor used for tranferring plain text. The MIME - * type is "text/plain; charset=unicode". The representation class - * is <code>java.io.InputStream</code>. - * - * @deprecated The charset unicode is platform specific and InputStream - * deals with bytes not chars. Use <code>getRederForText()</code>. - */ -public static final DataFlavor plainTextFlavor; - -/** - * This is the data flavor used for transferring Java strings. The - * MIME type is "application/x-java-serialized-object" and the - * representation class is <code>java.lang.String</code>. - */ -public static final DataFlavor stringFlavor; - -/** - * This is a data flavor used for transferring lists of files. The - * representation type is a <code>java.util.List</code>, with each element of - * the list being a <code>java.io.File</code>. - */ -public static final DataFlavor javaFileListFlavor; - -/** - * This is an image flavor used for transferring images. The - * representation type is a <code>java.awt.Image</code>. - */ -public static final DataFlavor imageFlavor; - -/** - * This is the MIME type used for transferring a serialized object. - * The representation class is the type of object be deserialized. - */ -public static final String javaSerializedObjectMimeType = - "application/x-java-serialized-object"; - -/** - * This is the MIME type used to transfer a Java object reference within - * the same JVM. The representation class is the class of the object - * being transferred. - */ -public static final String javaJVMLocalObjectMimeType = - "application/x-java-jvm-local-objectref"; - -/** - * This is the MIME type used to transfer a link to a remote object. - * The representation class is the type of object being linked to. - */ -public static final String javaRemoteObjectMimeType = - "application/x-java-remote-object"; - -static -{ - plainTextFlavor - = new DataFlavor(java.io.InputStream.class, - "text/plain; charset=unicode", - "plain unicode text"); - - stringFlavor - = new DataFlavor(java.lang.String.class, - "Java Unicode String"); - - javaFileListFlavor - = new DataFlavor(java.util.List.class, - "Java File List"); - - // javaFileListFlavor.mimeType = "application/x-java-file-list"; - - imageFlavor - = new DataFlavor(java.awt.Image.class, - "Java Image"); -} - -/*************************************************************************/ - -/* - * Instance Variables - */ - -// The MIME type for this flavor -private final String mimeType; - -// The representation class for this flavor -private final Class representationClass; - -// The human readable name of this flavor -private String humanPresentableName; - -/*************************************************************************/ - -/* - * Static Methods - */ - -/** - * This method attempts to load the named class. The following class - * loaders are searched in order: the bootstrap class loader, the - * system class loader, the context class loader (if it exists), and - * the specified fallback class loader. - * - * @param className The name of the class to load. - * @param classLoader The class loader to use if all others fail, which - * may be <code>null</code>. - * - * @exception ClassNotFoundException If the class cannot be loaded. - */ -protected static final Class -tryToLoadClass(String className, ClassLoader classLoader) - throws ClassNotFoundException -{ - try - { - return(Class.forName(className)); - } - catch(Exception e) { ; } - // Commented out for Java 1.1 - /* - try - { - return(className.getClass().getClassLoader().findClass(className)); - } - catch(Exception e) { ; } - - try - { - return(ClassLoader.getSystemClassLoader().findClass(className)); - } - catch(Exception e) { ; } - */ - - // FIXME: What is the context class loader? - /* - try - { - } - catch(Exception e) { ; } - */ - - if (classLoader != null) - return(classLoader.loadClass(className)); - else - throw new ClassNotFoundException(className); -} - -/*************************************************************************/ - -/* - * Constructors - */ - -/** - * Empty public constructor needed for externalization. - * Should not be used for normal instantiation. - */ -public -DataFlavor() -{ - mimeType = null; - representationClass = null; - humanPresentableName = null; -} - -/*************************************************************************/ - -/** - * Private constructor. - */ -private -DataFlavor(Class representationClass, - String mimeType, - String humanPresentableName) -{ - this.representationClass = representationClass; - this.mimeType = mimeType; - if (humanPresentableName != null) - this.humanPresentableName = humanPresentableName; - else - this.humanPresentableName = mimeType; -} - -/*************************************************************************/ - -/** - * Initializes a new instance of <code>DataFlavor</code>. The class - * and human readable name are specified, the MIME type will be - * "application/x-java-serialized-object". If the human readable name - * is not specified (<code>null</code>) then the human readable name - * will be the same as the MIME type. - * - * @param representationClass The representation class for this object. - * @param humanPresentableName The display name of the object. - */ -public -DataFlavor(Class representationClass, String humanPresentableName) -{ - this(representationClass, - "application/x-java-serialized-object" - + "; class=" - + representationClass.getName(), - humanPresentableName); -} - -/*************************************************************************/ - -/** - * Initializes a new instance of <code>DataFlavor</code> with the - * specified MIME type and description. If the MIME type has a - * "class=<rep class>" parameter then the representation class will - * be the class name specified. Otherwise the class defaults to - * <code>java.io.InputStream</code>. If the human readable name - * is not specified (<code>null</code>) then the human readable name - * will be the same as the MIME type. - * - * @param mimeType The MIME type for this flavor. - * @param humanPresentableName The display name of this flavor. - * @param classLoader The class loader for finding classes if the default - * class loaders do not work. - * - * @exception IllegalArgumentException If the representation class - * specified cannot be loaded. - * @exception ClassNotFoundException If the class is not loaded. - */ -public -DataFlavor(String mimeType, String humanPresentableName, - ClassLoader classLoader) throws ClassNotFoundException -{ - this(getRepresentationClassFromMime(mimeType, classLoader), - mimeType, humanPresentableName); -} - -private static Class -getRepresentationClassFromMime(String mimeString, ClassLoader classLoader) -{ - String classname = getParameter("class", mimeString); - if (classname != null) - { - try - { - return tryToLoadClass(classname, classLoader); - } - catch(Exception e) - { - throw new IllegalArgumentException("classname: " + e.getMessage()); - } - } - else - { - return java.io.InputStream.class; - } -} - -/*************************************************************************/ - -/** - * Initializes a new instance of <code>DataFlavor</code> with the - * specified MIME type and description. If the MIME type has a - * "class=<rep class>" parameter then the representation class will - * be the class name specified. Otherwise the class defaults to - * <code>java.io.InputStream</code>. If the human readable name - * is not specified (<code>null</code>) then the human readable name - * will be the same as the MIME type. This is the same as calling - * <code>new DataFlavor(mimeType, humanPresentableName, null)</code>. - * - * @param mimeType The MIME type for this flavor. - * @param humanPresentableName The display name of this flavor. - * - * @exception IllegalArgumentException If the representation class - * specified cannot be loaded. - */ -public -DataFlavor(String mimeType, String humanPresentableName) -{ - this (getRepresentationClassFromMime (mimeType, null), humanPresentableName); -} - -/*************************************************************************/ - -/** - * Initializes a new instance of <code>DataFlavor</code> with the specified - * MIME type. This type can have a "class=" parameter to specify the - * representation class, and then the class must exist or an exception will - * be thrown. If there is no "class=" parameter then the representation class - * will be <code>java.io.InputStream</code>. This is the same as calling - * <code>new DataFlavor(mimeType, null)</code>. - * - * @param mimeType The MIME type for this flavor. - * - * @exception IllegalArgumentException If a class is not specified in - * the MIME type. - * @exception ClassNotFoundException If the class cannot be loaded. - */ -public -DataFlavor(String mimeType) throws ClassNotFoundException -{ - this(mimeType, null); -} - -/*************************************************************************/ - -/** - * Returns the MIME type of this flavor. - * - * @return The MIME type for this flavor. - */ -public String -getMimeType() -{ - return(mimeType); -} - -/*************************************************************************/ - -/** - * Returns the representation class for this flavor. - * - * @return The representation class for this flavor. - */ -public Class -getRepresentationClass() -{ - return(representationClass); -} - -/*************************************************************************/ - -/** - * Returns the human presentable name for this flavor. - * - * @return The human presentable name for this flavor. - */ -public String -getHumanPresentableName() -{ - return(humanPresentableName); -} - -/*************************************************************************/ - -/** - * Returns the primary MIME type for this flavor. - * - * @return The primary MIME type for this flavor. - */ -public String -getPrimaryType() -{ - int idx = mimeType.indexOf("/"); - if (idx == -1) - return(mimeType); - - return(mimeType.substring(0, idx)); -} - -/*************************************************************************/ - -/** - * Returns the MIME subtype for this flavor. - * - * @return The MIME subtype for this flavor. - */ -public String -getSubType() -{ - int idx = mimeType.indexOf("/"); - if (idx == -1) - return(""); - - String subtype = mimeType.substring(idx + 1); - - idx = subtype.indexOf(" "); - if (idx == -1) - return(subtype); - else - return(subtype.substring(0, idx)); -} - -/*************************************************************************/ - -/** - * Returns the value of the named MIME type parameter, or <code>null</code> - * if the parameter does not exist. Given the parameter name and the mime - * string. - * - * @param paramName The name of the parameter. - * @param mimeString The mime string from where the name should be found. - * - * @return The value of the parameter or null. - */ -private static String -getParameter(String paramName, String mimeString) -{ - int idx = mimeString.indexOf(paramName + "="); - if (idx == -1) - return(null); - - String value = mimeString.substring(idx + paramName.length() + 1); - - idx = value.indexOf(" "); - if (idx == -1) - return(value); - else - return(value.substring(0, idx)); -} - -/*************************************************************************/ - -/** - * Returns the value of the named MIME type parameter, or <code>null</code> - * if the parameter does not exist. - * - * @param paramName The name of the paramter. - * - * @return The value of the parameter. - */ -public String -getParameter(String paramName) -{ - return getParameter(paramName, mimeType); -} - -/*************************************************************************/ - -/** - * Sets the human presentable name to the specified value. - * - * @param humanPresentableName The new display name. - */ -public void -setHumanPresentableName(String humanPresentableName) -{ - this.humanPresentableName = humanPresentableName; -} - -/*************************************************************************/ - -/** - * Tests the MIME type of this object for equality against the specified - * MIME type. - * - * @param mimeType The MIME type to test against. - * - * @return <code>true</code> if the MIME type is equal to this object's - * MIME type, <code>false</code> otherwise. - * - * @exception NullPointerException If mimeType is null. - */ -public boolean -isMimeTypeEqual(String mimeType) -{ - // FIXME: Need to handle default attributes and parameters - - return(this.mimeType.equals(mimeType)); -} - -/*************************************************************************/ - -/** - * Tests the MIME type of this object for equality against the specified - * data flavor's MIME type - * - * @param flavor The flavor to test against. - * - * @return <code>true</code> if the flavor's MIME type is equal to this - * object's MIME type, <code>false</code> otherwise. - */ -public final boolean -isMimeTypeEqual(DataFlavor flavor) -{ - return(isMimeTypeEqual(flavor.getMimeType())); -} - -/*************************************************************************/ - -/** - * Tests whether or not this flavor represents a serialized object. - * - * @return <code>true</code> if this flavor represents a serialized - * object, <code>false</code> otherwise. - */ -public boolean -isMimeTypeSerializedObject() -{ - return(mimeType.startsWith(javaSerializedObjectMimeType)); -} - -/*************************************************************************/ - -/** - * Tests whether or not this flavor has a representation class of - * <code>java.io.InputStream</code>. - * - * @return <code>true</code> if the representation class of this flavor - * is <code>java.io.InputStream</code>, <code>false</code> otherwise. - */ -public boolean -isRepresentationClassInputStream() -{ - return(representationClass.getName().equals("java.io.InputStream")); -} - -/*************************************************************************/ - -/** - * Tests whether the representation class for this flavor is - * serializable. - * - * @return <code>true</code> if the representation class is serializable, - * <code>false</code> otherwise. - */ -public boolean -isRepresentationClassSerializable() -{ - Class[] interfaces = representationClass.getInterfaces(); - - int i = 0; - while (i < interfaces.length) - { - if (interfaces[i].getName().equals("java.io.Serializable")) - return(true); - ++i; - } - - return(false); -} - -/*************************************************************************/ - -/** - * Tests whether the representation class for his flavor is remote. - * - * @return <code>true</code> if the representation class is remote, - * <code>false</code> otherwise. - */ -public boolean -isRepresentationClassRemote() -{ - // FIXME: Implement - throw new RuntimeException("Not implemented"); -} - -/*************************************************************************/ - -/** - * Tests whether or not this flavor represents a serialized object. - * - * @return <code>true</code> if this flavor represents a serialized - * object, <code>false</code> otherwise. - */ -public boolean -isFlavorSerializedObjectType() -{ - // FIXME: What is the diff between this and isMimeTypeSerializedObject? - return(mimeType.startsWith(javaSerializedObjectMimeType)); -} - -/*************************************************************************/ - -/** - * Tests whether or not this flavor represents a remote object. - * - * @return <code>true</code> if this flavor represents a remote object, - * <code>false</code> otherwise. - */ -public boolean -isFlavorRemoteObjectType() -{ - return(mimeType.startsWith(javaRemoteObjectMimeType)); -} - -/*************************************************************************/ - -/** - * Tests whether or not this flavor represents a list of files. - * - * @return <code>true</code> if this flavor represents a list of files, - * <code>false</code> otherwise. - */ -public boolean -isFlavorJavaFileListType() -{ - if (this.mimeType.equals(javaFileListFlavor.mimeType) && - this.representationClass.equals(javaFileListFlavor.representationClass)) - return(true); - - return(false); -} - -/*************************************************************************/ - -/** - * Returns a copy of this object. - * - * @return A copy of this object. - * - * @exception CloneNotSupportedException If the object's class does not support - * the Cloneable interface. Subclasses that override the clone method can also - * throw this exception to indicate that an instance cannot be cloned. - */ -public Object clone () throws CloneNotSupportedException -{ - try - { - return(super.clone()); - } - catch(Exception e) - { - return(null); - } -} - -/*************************************************************************/ - -/** - * This method test the specified <code>DataFlavor</code> for equality - * against this object. This will be true if the MIME type and - * representation type are the equal. - * - * @param flavor The <code>DataFlavor</code> to test against. - * - * @return <code>true</code> if the flavor is equal to this object, - * <code>false</code> otherwise. - */ -public boolean -equals(DataFlavor flavor) -{ - if (flavor == null) - return(false); - - if (!this.mimeType.toLowerCase().equals(flavor.mimeType.toLowerCase())) - return(false); - - if (!this.representationClass.equals(flavor.representationClass)) - return(false); - - return(true); -} - -/*************************************************************************/ - -/** - * This method test the specified <code>Object</code> for equality - * against this object. This will be true if the following conditions - * are met: - * <p> - * <ul> - * <li>The object is not <code>null</code>.</li> - * <li>The object is an instance of <code>DataFlavor</code>.</li> - * <li>The object's MIME type and representation class are equal to - * this object's.</li> - * </ul> - * - * @param obj The <code>Object</code> to test against. - * - * @return <code>true</code> if the flavor is equal to this object, - * <code>false</code> otherwise. - */ -public boolean -equals(Object obj) -{ - if (!(obj instanceof DataFlavor)) - return(false); - - return(equals((DataFlavor)obj)); -} - -/*************************************************************************/ - -/** - * Tests whether or not the specified string is equal to the MIME type - * of this object. - * - * @param str The string to test against. - * - * @return <code>true</code> if the string is equal to this object's MIME - * type, <code>false</code> otherwise. - * - * @deprecated Not compatible with <code>hashCode()</code>. - * Use <code>isMimeTypeEqual()</code> - */ -public boolean -equals(String str) -{ - return(isMimeTypeEqual(str)); -} - -/*************************************************************************/ - -/** - * Returns the hash code for this data flavor. - * The hash code is based on the (lower case) mime type and the - * representation class. - */ -public int -hashCode() -{ - return(mimeType.toLowerCase().hashCode()^representationClass.hashCode()); -} - -/*************************************************************************/ - -/** - * Returns <code>true</code> when the given <code>DataFlavor</code> - * matches this one. - */ -public boolean -match(DataFlavor dataFlavor) -{ - // XXX - How is this different from equals? - return(equals(dataFlavor)); -} - -/*************************************************************************/ - -/** - * This method exists for backward compatibility. It simply returns - * the same name/value pair passed in. - * - * @param name The parameter name. - * @param value The parameter value. - * - * @return The name/value pair. - * - * @deprecated - */ -protected String -normalizeMimeTypeParameter(String name, String value) -{ - return(name + "=" + value); -} - -/*************************************************************************/ - -/** - * This method exists for backward compatibility. It simply returns - * the MIME type string unchanged. - * - * @param type The MIME type. - * - * @return The MIME type. - * - * @deprecated - */ -protected String -normalizeMimeType(String type) -{ - return(type); -} - -/*************************************************************************/ - -/** - * Serialize this class. - * - * @param stream The <code>ObjectOutput</code> stream to serialize to. - * - * @exception IOException If an error occurs. - */ -public void -writeExternal(ObjectOutput stream) throws IOException -{ - // FIXME: Implement me -} - -/*************************************************************************/ - -/** - * De-serialize this class. - * - * @param stream The <code>ObjectInput</code> stream to deserialize from. - * - * @exception IOException If an error ocurs. - * @exception ClassNotFoundException If the class for an object being restored - * cannot be found. - */ -public void -readExternal(ObjectInput stream) throws IOException, ClassNotFoundException -{ - // FIXME: Implement me -} - -/*************************************************************************/ - -/** - * Returns a string representation of this DataFlavor. Including the - * representation class name, MIME type and human presentable name. - */ -public String -toString() -{ - return("DataFlavor[representationClass=" - + representationClass.getName() - + ",mimeType=" - + mimeType - + "humanPresentableName=" - + humanPresentableName); -} - -/*************************************************************************/ - -/** - * XXX - Currently returns <code>plainTextFlavor</code>. - */ -public static final DataFlavor -getTextPlainUnicodeFlavor() -{ - return(plainTextFlavor); -} - -/*************************************************************************/ - -/** - * XXX - Currently returns <code>java.io.InputStream</code>. - * - * @since 1.3 - */ -public final Class -getDefaultRepresentationClass() -{ - return(java.io.InputStream.class); -} -/*************************************************************************/ - -/** - * XXX - Currently returns <code>java.io.InputStream</code>. - */ -public final String -getDefaultRepresentationClassAsString() -{ - return(getDefaultRepresentationClass().getName()); -} - -/*************************************************************************/ - -/** - * Selects the best supported text flavor on this implementation. - * Returns <code>null</code> when none of the given flavors is liked. - * - * The <code>DataFlavor</code> returned the first data flavor in the - * array that has either a representation class which is (a subclass of) - * <code>Reader</code> or <code>String</code>, or has a representation - * class which is (a subclass of) <code>InputStream</code> and has a - * primary MIME type of "text" and has an supported encoding. - */ -public static final DataFlavor -selectBestTextFlavor(DataFlavor[] availableFlavors) -{ - for(int i=0; i<availableFlavors.length; i++) - { - DataFlavor df = availableFlavors[i]; - Class c = df.representationClass; - - // A Reader or String is good. - if ((Reader.class.isAssignableFrom(c)) - || (String.class.isAssignableFrom(c))) - { - return df; - } - - // A InputStream is good if the mime primary type is "text" - if ((InputStream.class.isAssignableFrom(c)) - && ("text".equals(df.getPrimaryType()))) - { - String encoding = availableFlavors[i].getParameter("charset"); - if (encoding == null) - encoding = "us-ascii"; - Reader r = null; - try - { - // Try to construct a dummy reader with the found encoding - r = new InputStreamReader - (new ByteArrayInputStream(new byte[0]), encoding); - } - catch(UnsupportedEncodingException uee) { /* ignore */ } - if (r != null) - return df; - } - } - - // Nothing found - return(null); -} - -/*************************************************************************/ - -/** - * Creates a <code>Reader</code> for a given <code>Transferable</code>. - * - * If the representation class is a (subclass of) <code>Reader</code> - * then an instance of the representation class is returned. If the - * representatation class is a <code>String</code> then a - * <code>StringReader</code> is returned. And if the representation class - * is a (subclass of) <code>InputStream</code> and the primary MIME type - * is "text" then a <code>InputStreamReader</code> for the correct charset - * encoding is returned. - * - * @param transferable The <code>Transferable</code> for which a text - * <code>Reader</code> is requested. - * - * @exception IllegalArgumentException If the representation class is not one - * of the seven listed above or the Transferable has null data. - * @exception NullPointerException If the Transferable is null. - * @exception UnsupportedFlavorException when the transferable doesn't - * support this <code>DataFlavor</code>. Or if the representable class - * isn't a (subclass of) <code>Reader</code>, <code>String</code>, - * <code>InputStream</code> and/or the primary MIME type isn't "text". - * @exception IOException when any IOException occurs. - * @exception UnsupportedEncodingException if the "charset" isn't supported - * on this platform. - */ -public Reader getReaderForText(Transferable transferable) - throws UnsupportedFlavorException, IOException -{ - if (!transferable.isDataFlavorSupported(this)) - throw new UnsupportedFlavorException(this); - - if (Reader.class.isAssignableFrom(representationClass)) - return((Reader)transferable.getTransferData(this)); - - if (String.class.isAssignableFrom(representationClass)) - return(new StringReader((String)transferable.getTransferData(this))); - - if (InputStream.class.isAssignableFrom(representationClass) - && "text".equals(getPrimaryType())) - { - InputStream in = (InputStream)transferable.getTransferData(this); - String encoding = getParameter("charset"); - if (encoding == null) - encoding = "us-ascii"; - return(new InputStreamReader(in, encoding)); - } - - throw new UnsupportedFlavorException(this); -} - - /** - * Returns whether the representation class for this DataFlavor is - * @see java.nio.ByteBuffer or a subclass thereof. - * - * @since 1.4 - */ - public boolean isRepresentationClassByteBuffer () - { - return ByteBuffer.class.isAssignableFrom (representationClass); - } - - /** - * Returns whether the representation class for this DataFlavor is - * @see java.nio.CharBuffer or a subclass thereof. - * - * @since 1.4 - */ - public boolean isRepresentationClassCharBuffer () - { - return CharBuffer.class.isAssignableFrom (representationClass); - } - - /** - * Returns whether the representation class for this DataFlavor is - * @see java.io.Reader or a subclass thereof. - * - * @since 1.4 - */ - public boolean isRepresentationClassReader () - { - return Reader.class.isAssignableFrom (representationClass); - } - -} // class DataFlavor - diff --git a/libjava/java/awt/datatransfer/FlavorMap.java b/libjava/java/awt/datatransfer/FlavorMap.java deleted file mode 100644 index 59718c4513c..00000000000 --- a/libjava/java/awt/datatransfer/FlavorMap.java +++ /dev/null @@ -1,75 +0,0 @@ -/* FlavorMap.java -- Maps between flavor names and MIME types. - Copyright (C) 1999, 2001 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.datatransfer; - -import java.util.Map; - -/** - * This interface maps between native platform type names and DataFlavors. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public interface FlavorMap -{ - /** - * Maps the specified <code>DataFlavor</code> objects to the native - * data type name. The returned <code>Map</code> has keys that are - * the data flavors and values that are strings. The returned map - * may be modified. This can be useful for implementing nested mappings. - * - * @param flavors An array of data flavors to map - * or null for all data flavors. - * - * @return A <code>Map</code> of native data types. - */ - Map getNativesForFlavors (DataFlavor[] flavors); - - /** - * Maps the specified native type names to <code>DataFlavor</code>'s. - * The returned <code>Map</code> has keys that are strings and values - * that are <code>DataFlavor</code>'s. The returned map may be - * modified. This can be useful for implementing nested mappings. - * - * @param natives An array of native types to map - * or null for all native types. - * - * @return A <code>Map</code> of data flavors. - */ - Map getFlavorsForNatives (String[] natives); -} diff --git a/libjava/java/awt/datatransfer/FlavorTable.java b/libjava/java/awt/datatransfer/FlavorTable.java deleted file mode 100644 index 11cdda06ca7..00000000000 --- a/libjava/java/awt/datatransfer/FlavorTable.java +++ /dev/null @@ -1,73 +0,0 @@ -/* FlavorTable.java -- A relaxed mapping between flavors - Copyright (C) 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.datatransfer; - -import java.util.List; - -/** - * A FlavorMap which no longer requires a 1-to-1 mapping between flavors. Any - * native can map to multiple flavors, and any flavor can map to multiple - * natives; although the mappings are usually symmetric. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.4 - * @status updated to 1.4 - */ -public interface FlavorTable extends FlavorMap -{ - /** - * Returns a list of String natives corresponding to the given flavor. The - * list should be sorted from best to worst. The list must be modifiable - * without affecting this table. - * - * @param flavor the flavor to look up, or null to return all natives - * @return the sorted list of natives - */ - List getNativesForFlavor(DataFlavor flavor); - - /** - * Returns a list of flavors corresponding to the given String native. The - * list should be sorted from best to worst. The list must be modifiable - * without affecting this table. - * - * @param name the native name to look up, or null to return all flavors - * @return the sorted list of flavors - */ - List getFlavorsForNative(String name); -} diff --git a/libjava/java/awt/datatransfer/MimeTypeParseException.java b/libjava/java/awt/datatransfer/MimeTypeParseException.java deleted file mode 100644 index 6113ab760b8..00000000000 --- a/libjava/java/awt/datatransfer/MimeTypeParseException.java +++ /dev/null @@ -1,70 +0,0 @@ -/* MimeTypeParseException.java -- thrown when MIME string couldn't be parsed - Copyright (C) 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.datatransfer; - -/** - * MIME string couldn't be parsed correctly. - * - * @author Mark Wielaard (mark@klomp.org) - * @status updated to 1.4 - */ -public class MimeTypeParseException extends Exception -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = -5604407764691570741L; - - /** - * Create a new instance without any message. - */ - public MimeTypeParseException() - { - } - - /** - * Create a new instance with a specified detailed error message. - * - * @param message the message - */ - public MimeTypeParseException(String message) - { - super(message); - } -} // class MimeTypeParseException diff --git a/libjava/java/awt/datatransfer/StringSelection.java b/libjava/java/awt/datatransfer/StringSelection.java deleted file mode 100644 index b74f2fa6418..00000000000 --- a/libjava/java/awt/datatransfer/StringSelection.java +++ /dev/null @@ -1,158 +0,0 @@ -/* StringSelection.java -- Clipboard handler for text. - Copyright (C) 1999, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.datatransfer; - -import java.io.IOException; -import java.io.StringReader; - -/** - * This class transfers a string as plain text using the clipboard. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public class StringSelection implements Transferable, ClipboardOwner -{ - -/* - * Class Variables - */ - -// List of flavors we support -// XXX: DataFlavor.plainTextFlavor is deprecated. -static final DataFlavor[] supported_flavors - = { DataFlavor.stringFlavor, - DataFlavor.plainTextFlavor }; - -/*************************************************************************/ - -/* - * Instance Variables - */ - -// This is the data to transfer -private String data; - - /** - * Transfer the specfied string as text. - * - * @param data the data for the string selection - */ - public StringSelection(String data) - { - this.data = data; - } - -/** - * Returns a list of supported data flavors. - * - * @return A list of supported data flavors. - */ -public DataFlavor[] -getTransferDataFlavors() -{ - return(supported_flavors); -} - -/*************************************************************************/ - -/** - * Tests whether or not the specified data flavor is supported. - * - * @param flavor The data flavor to test. - * - * @return <code>true</code> if the data flavor is supported, - * <code>false</code> otherwise. - */ -public boolean -isDataFlavorSupported(DataFlavor flavor) -{ - for (int i = 0; i < supported_flavors.length; i++) - if (supported_flavors[i].equals(flavor)) - return(true); - - return(false); -} - -/*************************************************************************/ - -/** - * This method returns the data in the requested format. - * - * @param flavor The desired data flavor. - * - * @return The transferred data. - * - * @exception UnsupportedFlavorException If the specified flavor is not - * supported. - * @exception IOException If any other error occurs. - */ -public Object -getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, - IOException -{ - if (!isDataFlavorSupported(flavor)) - throw new UnsupportedFlavorException(flavor); - - if (DataFlavor.plainTextFlavor == flavor) - /* The behavior of this method for DataFlavor.plainTextFlavor and - equivalent DataFlavors is inconsistent with the definition of - DataFlavor.plainTextFlavor. We choose to do like Sun's implementation - and return a Reader instead of an InputString. */ - /* return(new StringBufferInputStream(data)); */ - return(new StringReader(data)); - else // DataFlavor.stringFlavor - return data; -} - -/*************************************************************************/ - -/** - * Called when ownership of the clipboard object is lost. - * - * @param clipboard The affected clipboard. - * @param contents The clipboard contents. - */ -public void -lostOwnership(Clipboard clipboard, Transferable contents) -{ - // FIXME: What does this do? -} - -} // class StringSelection - diff --git a/libjava/java/awt/datatransfer/SystemFlavorMap.java b/libjava/java/awt/datatransfer/SystemFlavorMap.java deleted file mode 100644 index f6530f5117c..00000000000 --- a/libjava/java/awt/datatransfer/SystemFlavorMap.java +++ /dev/null @@ -1,169 +0,0 @@ -/* SystemFlavorMap.java -- Maps between native flavor names and MIME types. - Copyright (C) 2001, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.datatransfer; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * This class maps between native platform type names and DataFlavors. - * - * XXX - The current implementation does no mapping at all. - * - * @author Mark Wielaard (mark@klomp.org) - * - * @since 1.2 - */ -public final class SystemFlavorMap implements FlavorMap, FlavorTable -{ - /** - * The default (instance) flavor map. - */ - private static FlavorMap defaultFlavorMap; - - /** - * Private constructor. - */ - private SystemFlavorMap () - { - } - - /** - * Maps the specified <code>DataFlavor</code> objects to the native - * data type name. The returned <code>Map</code> has keys that are - * the data flavors and values that are strings. The returned map - * may be modified. This can be useful for implementing nested mappings. - * - * @param flavors An array of data flavors to map - * or null for all data flavors. - * - * @return A <code>Map</code> of native data types to data flavors. - */ - public Map getNativesForFlavors (DataFlavor[] flavors) - { - return new HashMap(); - } - - /** - * Maps the specified native type names to <code>DataFlavor</code>'s. - * The returned <code>Map</code> has keys that are strings and values - * that are <code>DataFlavor</code>'s. The returned map may be - * modified. This can be useful for implementing nested mappings. - * - * @param natives An array of native types to map - * or null for all native types. - * - * @return A <code>Map</code> of data flavors to native type names. - */ - public Map getFlavorsForNatives (String[] natives) - { - return new HashMap(); - } - - /** - * Returns the default (instance) (System)FlavorMap. - */ - public static FlavorMap getDefaultFlavorMap () - { - if (defaultFlavorMap == null) - defaultFlavorMap = new SystemFlavorMap (); - - return defaultFlavorMap; - } - - /** - * Returns the native type name for the given java mime type. - */ - public static String encodeJavaMIMEType (String mime) - { - return null; - } - - /** - * Returns the native type name for the given data flavor. - */ - public static String encodeDataFlavor (DataFlavor df) - { - return null; - } - - /** - * Returns true if the native type name can be represented as - * a java mime type. - */ - public static boolean isJavaMIMEType (String name) - { - return false; - } - - /** - * Returns the java mime type for the given the native type name. - */ - public static String decodeJavaMIMEType (String name) - { - return null; - } - - /** - * Returns the data flavor given the native type name - * or null when no such data flavor exists. - */ - public static DataFlavor decodeDataFlavor (String name) - throws ClassNotFoundException - { - String javaMIMEType = decodeJavaMIMEType (name); - - if (javaMIMEType != null) - return new DataFlavor (javaMIMEType); - else - return null; - } - - public List getFlavorsForNative (String nat) - { - throw new Error ("Not implemented"); - } - - public List getNativesForFlavor (DataFlavor flav) - { - throw new Error ("Not implemented"); - } - -} // class SystemFlavorMap diff --git a/libjava/java/awt/datatransfer/Transferable.java b/libjava/java/awt/datatransfer/Transferable.java deleted file mode 100644 index 80753923618..00000000000 --- a/libjava/java/awt/datatransfer/Transferable.java +++ /dev/null @@ -1,83 +0,0 @@ -/* Transferable.java -- Data transfer source - Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.datatransfer; - -import java.io.IOException; - -/** - * This interface is implemented by classes that can transfer data. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @since 1.1 - * @status updated to 1.4 - */ -public interface Transferable -{ - /** - * This method returns a list of available data flavors for the data being - * transferred. The array returned will be sorted from most preferred - * flavor at the beginning to least preferred at the end. - * - * @return adA list of data flavors for this data - */ - DataFlavor[] getTransferDataFlavors(); - - /** - * Tests whether or not this data can be delivered in the specified data - * flavor. - * - * @param flavor the data flavor to test - * @return true if the data flavor is supported - */ - boolean isDataFlavorSupported(DataFlavor flavor); - - /** - * Returns the data in the specified <code>DataFlavor</code>. - * - * @param flavor the data flavor to return - * @return the data in the appropriate flavor - * @throws UnsupportedFlavorException if the flavor is not supported - * @throws IOException if the data is not available - * @see DataFlavor#getRepresentationClass - */ - Object getTransferData(DataFlavor flavor) - throws UnsupportedFlavorException, IOException; - -} // interface Transferable - diff --git a/libjava/java/awt/datatransfer/UnsupportedFlavorException.java b/libjava/java/awt/datatransfer/UnsupportedFlavorException.java deleted file mode 100644 index 1c1da0348c3..00000000000 --- a/libjava/java/awt/datatransfer/UnsupportedFlavorException.java +++ /dev/null @@ -1,65 +0,0 @@ -/* UnsupportedFlavorException.java -- ata flavor is not valid - Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.datatransfer; - -/** - * The data flavor requested is not supported for the transfer data. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @see Transferable#getTransferData(DataFlavor) - * @status updated to 1.4 - */ -public class UnsupportedFlavorException extends Exception -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = 5383814944251665601L; - - /** - * Initializes a new instance of <code>UnsupportedDataFlavor</code> - * for the specified data flavor. - * - * @param flavor the data flavor that is not supported - */ - public UnsupportedFlavorException(DataFlavor flavor) - { - super(flavor == null ? null : flavor.getHumanPresentableName()); - } -} // class UnsupportedFlavorException diff --git a/libjava/java/awt/dnd/Autoscroll.java b/libjava/java/awt/dnd/Autoscroll.java deleted file mode 100644 index ba4d4476cfc..00000000000 --- a/libjava/java/awt/dnd/Autoscroll.java +++ /dev/null @@ -1,70 +0,0 @@ -/* Autoscroll.java -- - Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.dnd; - -import java.awt.Insets; -import java.awt.Point; - -/** - * During DnD operations it is possible that a user may wish to drop the - * subject of the operation on a region of a scrollable GUI control that - * is not currently visible to the user. - * - * @author Michael Koch (konqueror@gmx.de) - * @since 1.2 - * @status updated to 1.4 - */ -public interface Autoscroll -{ - /** - * This method returns the Insets describing the autoscrolling region or - * border relative to the geometry of the implementing Component - */ - Insets getAutoscrollInsets (); - - /** - * Notify the Component to autoscroll - * - * @param location A Point indicating the location of the cursor that - * triggered this operation - */ - void autoscroll (Point location); - -} // interface Autoscroll - diff --git a/libjava/java/awt/dnd/DnDConstants.java b/libjava/java/awt/dnd/DnDConstants.java deleted file mode 100644 index 85c9c0528e6..00000000000 --- a/libjava/java/awt/dnd/DnDConstants.java +++ /dev/null @@ -1,77 +0,0 @@ -/* DnDConstants.java -- constants for drag-and-drop operations - Copyright (C) 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.dnd; - -/** - * This class contains various constants used in drag-and-drop operations. - * Why it is not an interface is beyond me. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.2 - * @status updated to 1.4 - */ -public final class DnDConstants -{ - /** No action takes place. */ - public static final int ACTION_NONE = 0; - - /** The copy action. */ - public static final int ACTION_COPY = 1; - - /** The move action. */ - public static final int ACTION_MOVE = 2; - - /** Either a copy or a move. */ - public static final int ACTION_COPY_OR_MOVE = 3; - - /** - * A link action. This does not copy or move, but creates a reference back - * to the original. However, since platforms differ on how a reference should - * behave, this action is not recommended for common use. - */ - public static final int ACTION_LINK = 1073741824; - - /** A synonym for {@link #ACTION_LINK}. */ - public static final int ACTION_REFERENCE = ACTION_LINK; - - private DnDConstants() - { - // Do nothing here. - } -} diff --git a/libjava/java/awt/dnd/DnDEventMulticaster.java b/libjava/java/awt/dnd/DnDEventMulticaster.java deleted file mode 100644 index d9f5ec00f1d..00000000000 --- a/libjava/java/awt/dnd/DnDEventMulticaster.java +++ /dev/null @@ -1,74 +0,0 @@ -/* DnDEventMulticaster.java -- helper class for listener chains in java.awt.dnd - Copyright (C) 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.dnd; - -import java.awt.AWTEventMulticaster; -import java.util.EventListener; - -class DnDEventMulticaster extends AWTEventMulticaster -{ - protected DnDEventMulticaster (EventListener a, EventListener b) - { - super (a, b); - } - - public static DragSourceListener add (DragSourceListener a, - DragSourceListener b) - { - return (DragSourceListener) addInternal (a, b); - } - - public static DragSourceMotionListener add (DragSourceMotionListener a, - DragSourceMotionListener b) - { - return (DragSourceMotionListener) addInternal (a, b); - } - - public static DragSourceListener remove (DragSourceListener a, - DragSourceListener b) - { - return (DragSourceListener) removeInternal (a, b); - } - - public static DragSourceMotionListener remove (DragSourceMotionListener a, - DragSourceMotionListener b) - { - return (DragSourceMotionListener) removeInternal (a, b); - } -} diff --git a/libjava/java/awt/dnd/DragGestureEvent.java b/libjava/java/awt/dnd/DragGestureEvent.java deleted file mode 100644 index 9f2bc7c98b8..00000000000 --- a/libjava/java/awt/dnd/DragGestureEvent.java +++ /dev/null @@ -1,156 +0,0 @@ -/* DragGestureEvent.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.dnd; - -import java.awt.Component; -import java.awt.Cursor; -import java.awt.Image; -import java.awt.Point; -import java.awt.datatransfer.Transferable; -import java.awt.event.InputEvent; -import java.util.EventObject; -import java.util.Iterator; -import java.util.List; - -/** - * STUBBED - * @see DragGestureRecognizer - * @see DragGestureListener - * @see DragSource - * @since 1.2 - */ -public class DragGestureEvent extends EventObject -{ - /** - * Compatible with JDK 1.2+. - */ - private static final long serialVersionUID = 9080172649166731306L; - - private DragSource dragSource; - private Component component; - private final Point origin; - private final int action; - - public DragGestureEvent(DragGestureRecognizer dgr, int action, Point origin, - List events) - { - super(dgr); - if (origin == null || events == null) - throw new IllegalArgumentException(); - this.origin = origin; - this.action = action; - } - - public DragGestureRecognizer getSourceAsDragGestureRecognizer() - { - return (DragGestureRecognizer) source; - } - public Component getComponent() - { - return null; - } - public DragSource getDragSource() - { - return null; - } - public Point getDragOrigin() - { - return origin; - } - public Iterator iterator() - { - return null; - } - public Object[] toArray() - { - return null; - } - public Object[] toArray(Object[] array) - { - return array; - } - public int getDragAction() - { - return 0; - } - public InputEvent getTriggerEvent() - { - return null; - } - - /** - * Starts the drag given the initial Cursor to display, the Transferable - * object, and the DragSourceListener to use. - * - * @exception InvalidDnDOperationException If the Drag and Drop system is - * unable to initiate a drag operation, or if the user attempts to start - * a drag while an existing drag operation is still executing. - */ - public void startDrag(Cursor dragCursor, Transferable trans) - { - startDrag(dragCursor, null, null, trans, null); - } - - /** - * Starts the drag given the initial Cursor to display, the Transferable - * object, and the DragSourceListener to use. - * - * @exception InvalidDnDOperationException If the Drag and Drop system is - * unable to initiate a drag operation, or if the user attempts to start - * a drag while an existing drag operation is still executing. - */ - public void startDrag(Cursor dragCursor, Transferable trans, - DragSourceListener l) - { - startDrag(dragCursor, null, null, trans, l); - } - - /** - * Starts the drag given the initial Cursor to display, the Transferable - * object, and the DragSourceListener to use. - * - * @exception InvalidDnDOperationException If the Drag and Drop system is - * unable to initiate a drag operation, or if the user attempts to start - * a drag while an existing drag operation is still executing. - */ - public void startDrag(Cursor dragCursor, Image dragImage, Point imageOffset, - Transferable trans, DragSourceListener l) - { - } -} // class DragGestureEvent diff --git a/libjava/java/awt/dnd/DragGestureListener.java b/libjava/java/awt/dnd/DragGestureListener.java deleted file mode 100644 index e8befe80f19..00000000000 --- a/libjava/java/awt/dnd/DragGestureListener.java +++ /dev/null @@ -1,63 +0,0 @@ -/* DragGestureListener.java -- - Copyright (C) 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.dnd; - -import java.util.EventListener; - -/** - * This is a listener for starting a drag-and-drop gesture. Upon receiving - * notification, the implementor then starts the drag operation. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @see DragGestureRecognizer - * @see DragGestureEvent - * @see DragSource - * @since 1.2 - * @status updated to 1.4 - */ -public interface DragGestureListener extends EventListener -{ - /** - * Called when the native platform notifies the virtual machine that a - * drag-and-drop has been initiated. - * - * @param e the event - */ - void dragGestureRecognized(DragGestureEvent e); -} // interface DragGestureListener diff --git a/libjava/java/awt/dnd/DragGestureRecognizer.java b/libjava/java/awt/dnd/DragGestureRecognizer.java deleted file mode 100644 index 07b822e7a68..00000000000 --- a/libjava/java/awt/dnd/DragGestureRecognizer.java +++ /dev/null @@ -1,179 +0,0 @@ -/* DragGestureRecognizer.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.dnd; - -import java.awt.Component; -import java.awt.Point; -import java.awt.event.InputEvent; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.TooManyListenersException; - -/** - * STUBBED - * @since 1.2 - */ -public abstract class DragGestureRecognizer implements Serializable -{ - /** - * Compatible with JDK 1.2+. - */ - private static final long serialVersionUID = 8996673345831063337L; - - protected DragSource dragSource; - protected Component component; - protected transient DragGestureListener dragGestureListener; - protected int sourceActions; - protected ArrayList events = new ArrayList(); - - protected DragGestureRecognizer(DragSource ds, Component c, int sa, - DragGestureListener dgl) - { - if (ds == null) - throw new IllegalArgumentException(); - dragSource = ds; - component = c; - sourceActions = sa; - dragGestureListener = dgl; - } - - protected DragGestureRecognizer(DragSource ds, Component c, int sa) - { - this(ds, c, sa, null); - } - - protected DragGestureRecognizer(DragSource ds, Component c) - { - this(ds, c, 0, null); - } - - protected DragGestureRecognizer(DragSource ds) - { - this(ds, null, 0, null); - } - - protected abstract void registerListeners(); - - protected abstract void unregisterListeners(); - - public DragSource getDragSource() - { - return dragSource; - } - - public Component getComponent() - { - return component; - } - - public void setComponent(Component c) - { - component = c; - } - - public int getSourceActions() - { - return sourceActions; - } - - public void setSourceActions(int sa) - { - sourceActions = sa; - } - - public InputEvent getTriggerEvent() - { - return events.size() > 0 ? (InputEvent) events.get(0) : null; - } - - public void resetRecognizer() - { - throw new Error("not implemented"); - } - - /** - * Register a new DragGestureListener. - * - * @exception TooManyListenersException If a DragGestureListener has already - * been added. - */ - public void addDragGestureListener(DragGestureListener dgl) - throws TooManyListenersException - { - if (dragGestureListener != null) - throw new TooManyListenersException(); - dragGestureListener = dgl; - } - - public void removeDragGestureListener(DragGestureListener dgl) - { - if (dragGestureListener != dgl) - throw new IllegalArgumentException(); - dragGestureListener = null; - } - - protected void fireDragGestureRecognized(int dragAction, Point p) - { - throw new Error("not implemented"); - } - - protected void appendEvent(InputEvent e) - { - if (e == null) - return; - events.add(e); - } - - private void readObject(ObjectInputStream s) - throws ClassNotFoundException, IOException - { - s.defaultReadObject(); - dragGestureListener = (DragGestureListener) s.readObject(); - } - - private void writeObject(ObjectOutputStream s) throws IOException - { - s.defaultWriteObject(); - s.writeObject(dragGestureListener instanceof Serializable - ? dragGestureListener : null); - } -} // class DragGestureRecognizer diff --git a/libjava/java/awt/dnd/DragSource.java b/libjava/java/awt/dnd/DragSource.java deleted file mode 100644 index 13ffc961510..00000000000 --- a/libjava/java/awt/dnd/DragSource.java +++ /dev/null @@ -1,257 +0,0 @@ -/* DragSource.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.dnd; - -import java.awt.Component; -import java.awt.Cursor; -import java.awt.GraphicsEnvironment; -import java.awt.HeadlessException; -import java.awt.Image; -import java.awt.Point; -import java.awt.Toolkit; -import java.awt.datatransfer.FlavorMap; -import java.awt.datatransfer.SystemFlavorMap; -import java.awt.datatransfer.Transferable; -import java.awt.dnd.peer.DragSourceContextPeer; -import java.io.Serializable; -import java.util.EventListener; - -/** - * @since 1.2 - */ -public class DragSource implements Serializable -{ - /** - * Compatible with JDK 1.2+. - */ - private static final long serialVersionUID = 6236096958971414066L; - - public static final Cursor DefaultCopyDrop = null; - public static final Cursor DefaultMoveDrop = null; - public static final Cursor DefaultLinkDrop = null; - public static final Cursor DefaultCopyNoDrop = null; - public static final Cursor DefaultMoveNoDrop = null; - public static final Cursor DefaultLinkNoDrop = null; - - private transient FlavorMap flavorMap = SystemFlavorMap.getDefaultFlavorMap (); - - private transient DragSourceListener dragSourceListener; - private transient DragSourceMotionListener dragSourceMotionListener; - - /** - * Initializes the drag source. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. - */ - public DragSource() - { - if (GraphicsEnvironment.isHeadless()) - throw new HeadlessException (); - } - - /** - * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. - */ - public static DragSource getDefaultDragSource() - { - return null; - } - - public static boolean isDragImageSupported() - { - return false; - } - - /** - * Start a drag, given the DragGestureEvent that initiated the drag. - * - * @exception InvalidDnDOperationException If the Drag and Drop system is - * unable to initiate a drag operation, or if the user attempts to start - * a drag while an existing drag operation is still executing. - */ - public void startDrag(DragGestureEvent trigger, Cursor dragCursor, - Image dragImage, Point imageOffset, - Transferable trans, DragSourceListener dsl, - FlavorMap map) - { - } - - /** - * Start a drag, given the DragGestureEvent that initiated the drag. - * - * @exception InvalidDnDOperationException If the Drag and Drop system is - * unable to initiate a drag operation, or if the user attempts to start - * a drag while an existing drag operation is still executing. - */ - public void startDrag(DragGestureEvent trigger, Cursor dragCursor, - Transferable trans, DragSourceListener dsl, - FlavorMap map) - { - startDrag(trigger, dragCursor, null, null, trans, dsl, map); - } - - /** - * Start a drag, given the DragGestureEvent that initiated the drag. - * - * @exception InvalidDnDOperationException If the Drag and Drop system is - * unable to initiate a drag operation, or if the user attempts to start - * a drag while an existing drag operation is still executing. - */ - public void startDrag(DragGestureEvent trigger, Cursor dragCursor, - Image dragImage, Point imageOffset, - Transferable trans, DragSourceListener dsl) - { - startDrag(trigger, dragCursor, dragImage, imageOffset, trans, dsl, null); - } - - /** - * Start a drag, given the DragGestureEvent that initiated the drag. - * - * @exception InvalidDnDOperationException If the Drag and Drop system is - * unable to initiate a drag operation, or if the user attempts to start - * a drag while an existing drag operation is still executing. - */ - public void startDrag(DragGestureEvent trigger, Cursor dragCursor, - Transferable trans, DragSourceListener dsl) - { - startDrag(trigger, dragCursor, null, null, trans, dsl, null); - } - - /** - * Creates the DragSourceContext to handle this drag. - * - * @exception IllegalArgumentException FIXME - * @exception NullPointerException If dscp, dgl, dragImage or t is null. - */ - protected DragSourceContext - createDragSourceContext(DragSourceContextPeer peer, DragGestureEvent dge, - Cursor cursor, Image image, Point offset, - Transferable t, DragSourceListener dsl) - { - return null; - } - - public FlavorMap getFlavorMap() - { - return flavorMap; - } - - public DragGestureRecognizer - createDragGestureRecognizer(Class recognizer, Component c, int actions, - DragGestureListener dgl) - { - return Toolkit.getDefaultToolkit () - .createDragGestureRecognizer (recognizer, this, c, actions, - dgl); - } - - public DragGestureRecognizer - createDefaultDragGestureRecognizer(Component c, int actions, - DragGestureListener dgl) - { - return createDragGestureRecognizer (MouseDragGestureRecognizer.class, c, - actions, dgl); - } - - /** - * @since 1.4 - */ - public void addDragSourceListener(DragSourceListener l) - { - DnDEventMulticaster.add (dragSourceListener, l); - } - - /** - * @since 1.4 - */ - public void removeDragSourceListener(DragSourceListener l) - { - DnDEventMulticaster.remove (dragSourceListener, l); - } - - /** - * @since 1.4 - */ - public DragSourceListener[] getDragSourceListeners() - { - return (DragSourceListener[]) getListeners (DragSourceListener.class); - } - - /** - * @since 1.4 - */ - public void addDragSourceMotionListener(DragSourceMotionListener l) - { - DnDEventMulticaster.add (dragSourceMotionListener, l); - } - - /** - * @since 1.4 - */ - public void removeDragSourceMotionListener(DragSourceMotionListener l) - { - DnDEventMulticaster.remove (dragSourceMotionListener, l); - } - - /** - * @since 1.4 - */ - public DragSourceMotionListener[] getDragSourceMotionListeners () - { - return (DragSourceMotionListener[]) getListeners - (DragSourceMotionListener.class); - } - - /** - * @since 1.4 - */ - public EventListener[] getListeners (Class listenerType) - { - if (listenerType == DragSourceListener.class) - return DnDEventMulticaster.getListeners (dragSourceListener, - listenerType); - - if (listenerType == DragSourceMotionListener.class) - return DnDEventMulticaster.getListeners (dragSourceMotionListener, - listenerType); - - // Return an empty EventListener array. - return new EventListener [0]; - } -} // class DragSource diff --git a/libjava/java/awt/dnd/DragSourceAdapter.java b/libjava/java/awt/dnd/DragSourceAdapter.java deleted file mode 100644 index 90d9a698347..00000000000 --- a/libjava/java/awt/dnd/DragSourceAdapter.java +++ /dev/null @@ -1,126 +0,0 @@ -/* DragSourceAdapter.java -- drag-and-drop listener adapter - Copyright (C) 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.dnd; - -/** - * This class implements <code>DragSourceListener</code> and - * <code>DragSourceMotionListener</code>, and implements all methods - * with empty bodies. This allows a listener interested in implementing only - * a subset of these interfaces to extend this class and override only the - * desired methods. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @see DragSourceEvent - * @see DragSourceListener - * @see DragSourceMotionListener - * @since 1.4 - * @status updated to 1.4 - */ -public abstract class DragSourceAdapter - implements DragSourceListener, DragSourceMotionListener -{ - /** - * Default constructor. - */ - public DragSourceAdapter() - { - } - - /** - * Called when the cursor hotspot enters a drop site which will accept the - * drag. - * - * @param e the event - */ - public void dragEnter(DragSourceDragEvent e) - { - } - - /** - * Called when the cursor hotspot moves inside of a drop site which will - * accept the drag. - * - * @param e the event - */ - public void dragOver(DragSourceDragEvent e) - { - } - - /** - * Called whenever the mouse is moved during a drag-and-drop operation. - * - * @param e the event - */ - public void dragMouseMoved(DragSourceDragEvent e) - { - } - - /** - * Called when the user modifies the drop gesture. This is often the case - * when additional mouse or key events are received during the drag. - * - * @param e the event - */ - public void dropActionChanged(DragSourceDragEvent e) - { - } - - /** - * Called when the cursor hotspot moves outside of a drop site which will - * accept the drag. This could also happen if the drop site is no longer - * active, or no longer accepts the drag. - * - * @param e the event - */ - public void dragExit(DragSourceEvent e) - { - } - - /** - * Called when the drag and drop operation is complete. After this event, - * <code>getDropSuccess</code> of the event is valid, and - * <code>getDropAction</code> holds the action requested by the drop site. - * Furthermore, the <code>DragSourceContext</code> is invalidated. - * - * @param e the event - */ - public void dragDropEnd(DragSourceDropEvent e) - { - } -} // class DragSourceAdapter diff --git a/libjava/java/awt/dnd/DragSourceContext.java b/libjava/java/awt/dnd/DragSourceContext.java deleted file mode 100644 index 2cf0d6d0bc9..00000000000 --- a/libjava/java/awt/dnd/DragSourceContext.java +++ /dev/null @@ -1,200 +0,0 @@ -/* DragSourceContext.java -- - Copyright (C) 2002 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.dnd; - -import java.awt.Component; -import java.awt.Cursor; -import java.awt.Image; -import java.awt.Point; -import java.awt.datatransfer.Transferable; -import java.awt.dnd.peer.DragSourceContextPeer; -import java.io.Serializable; -import java.util.TooManyListenersException; - -/** - * @since 1.2 - */ -public class DragSourceContext - implements DragSourceListener, DragSourceMotionListener, Serializable -{ - /** - * Compatible with JDK 1.2+ - */ - static final long serialVersionUID = -115407898692194719L; - - protected static final int DEFAULT = 0; - protected static final int ENTER = 1; - protected static final int OVER = 2; - protected static final int CHANGED = 3; - - private DragSourceContextPeer peer; - private Cursor cursor; - private Transferable transferable; - private DragGestureEvent trigger; - private DragSourceListener dragSourceListener; - private boolean useCustomCursor; // FIXME: currently unused but needed for serialization. - private int sourceActions; // FIXME: currently unused but needed for serialization. - private Image image; - private Point offset; - - /** - * Initializes a drag source context. - * - * @exception IllegalArgumentException If Component or DragSource of trigger - * are null, the drag action for the trigger event is DnDConstants.ACTION_NONE - * or if the source actions for the DragGestureRecognizer associated with the - * trigger event are equal to DnDConstants.ACTION_NONE. - * @exception NullPointerException If peer or trigger is null. - */ - public DragSourceContext (DragSourceContextPeer peer, - DragGestureEvent trigger, Cursor cursor, - Image image, Point offset, Transferable trans, - DragSourceListener dsl) - { - if (peer == null - || trigger == null) - throw new NullPointerException (); - - if (trigger.getComponent () == null - || trigger.getDragSource () == null - || trigger.getDragAction () == DnDConstants.ACTION_NONE - || trigger.getSourceAsDragGestureRecognizer () - .getSourceActions () == DnDConstants.ACTION_NONE) - throw new IllegalArgumentException (); - - this.peer = peer; - this.trigger = trigger; - this.cursor = cursor; - this.image = image; - this.offset = offset; - this.transferable = trans; - this.dragSourceListener = dsl; - - throw new Error ("not implemented"); - } - - public DragSource getDragSource() - { - return trigger.getDragSource (); - } - - public Component getComponent() - { - return trigger.getComponent (); - } - - public DragGestureEvent getTrigger() - { - return trigger; - } - - public int getSourceActions() - { - return trigger.getSourceAsDragGestureRecognizer ().getSourceActions (); - } - - public void setCursor (Cursor cursor) - { - this.cursor = cursor; - // FIXME: Check if we need to do more here - } - - public Cursor getCursor() - { - return cursor; - } - - /** - * Adds a <code>DragSourceListener</code>. - * - * @exception TooManyListenersException If a <code>DragSourceListener</code> - * has already been added. - */ - public void addDragSourceListener (DragSourceListener dsl) - throws TooManyListenersException - { - if (dragSourceListener != null) - throw new TooManyListenersException (); - - dragSourceListener = dsl; - } - - public void removeDragSourceListener (DragSourceListener dsl) - { - if (dragSourceListener == dsl) - dragSourceListener = null; - } - - public void transferablesFlavorsChanged() - { - } - - public void dragEnter(DragSourceDragEvent e) - { - } - - public void dragOver(DragSourceDragEvent e) - { - } - - public void dragExit(DragSourceEvent e) - { - } - - public void dropActionChanged(DragSourceDragEvent e) - { - } - - public void dragDropEnd(DragSourceDropEvent e) - { - } - - public void dragMouseMoved(DragSourceDragEvent e) - { - } - - public Transferable getTransferable() - { - return transferable; - } - - protected void updateCurrentCursor(int dropOp, int targetAct, int status) - { - } -} // class DragSourceContext diff --git a/libjava/java/awt/dnd/DragSourceDragEvent.java b/libjava/java/awt/dnd/DragSourceDragEvent.java deleted file mode 100644 index 511700b616d..00000000000 --- a/libjava/java/awt/dnd/DragSourceDragEvent.java +++ /dev/null @@ -1,102 +0,0 @@ -/* DragSourceDragEvent.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.dnd; - -import gnu.java.awt.EventModifier; - -/** - * @author Michael Koch - * @since 1.2 - */ -public class DragSourceDragEvent extends DragSourceEvent -{ - /** - * Compatible with JDK 1.2+ - */ - private static final long serialVersionUID = 481346297933902471L; - - private final int dropAction; - private final int targetActions; - private final int gestureModifiers; - - public DragSourceDragEvent(DragSourceContext context, int dropAction, - int actions, int modifiers) - { - super(context); - this.dropAction = dropAction; - targetActions = actions; - gestureModifiers = EventModifier.extend(modifiers); - } - - public DragSourceDragEvent(DragSourceContext context, int dropAction, - int actions, int modifiers, int x, int y) - { - super(context, x, y); - this.dropAction = dropAction; - targetActions = actions; - gestureModifiers = EventModifier.extend(modifiers); - } - - public int getTargetActions() - { - return targetActions; - } - - public int getGestureModifiers() - { - return EventModifier.revert(gestureModifiers); - } - - public int getGestureModifiersEx() - { - return gestureModifiers; - } - - public int getUserAction() - { - return dropAction; - } - - public int getDropAction() - { - return (dropAction - & targetActions - & ((DragSourceContext) source).getSourceActions()); - } -} // class DragSourceDragEvent diff --git a/libjava/java/awt/dnd/DragSourceDropEvent.java b/libjava/java/awt/dnd/DragSourceDropEvent.java deleted file mode 100644 index 7621262d839..00000000000 --- a/libjava/java/awt/dnd/DragSourceDropEvent.java +++ /dev/null @@ -1,89 +0,0 @@ -/* DragSourceDragEvent.java -- - Copyright (C) 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.awt.dnd; - -/** - * @author Michael Koch (konqueror@gmx.de) - * @since 1.2 - * - * Written using JDK 1.4.1 Online API - * Status: JDK 1.4 complete - */ -public class DragSourceDropEvent extends DragSourceEvent -{ - /** - * Compatible with JDK 1.2+ - */ - private static final long serialVersionUID = -5571321229470821891L; - - private final int dropAction; - private final boolean dropSuccess; - - public DragSourceDropEvent (DragSourceContext context) - { - super (context); - this.dropAction = 0; - this.dropSuccess = false; - } - - public DragSourceDropEvent (DragSourceContext context, int dropAction, - boolean dropSuccess) - { - super (context); - this.dropAction = dropAction; - this.dropSuccess = dropSuccess; - } - - public DragSourceDropEvent (DragSourceContext context, int dropAction, - boolean dropSuccess, int x, int y) - { - super (context, x, y); - this.dropAction = dropAction; - this.dropSuccess = dropSuccess; - } - - public int getDropAction() - { - return dropAction & ((DragSourceContext) source).getSourceActions(); - } - - public boolean getDropSuccess() - { - return dropSuccess; - } -} // class DragSourceDropEvent diff --git a/libjava/java/awt/dnd/DragSourceEvent.java b/libjava/java/awt/dnd/DragSourceEvent.java deleted file mode 100644 index c5cd42a4e2b..00000000000 --- a/libjava/java/awt/dnd/DragSourceEvent.java +++ /dev/null @@ -1,93 +0,0 @@ -/* DragSourceEvent.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.dnd; - -import java.awt.Point; -import java.util.EventObject; - -/** - * @since 1.2 - */ -public class DragSourceEvent extends EventObject -{ - /** - * Compatible with JDK 1.2+ - */ - private static final long serialVersionUID = -763287114604032641L; - - private final boolean locationSpecified; - private final int x; - private final int y; - - public DragSourceEvent(DragSourceContext context) - { - super(context); - locationSpecified = false; - x = 0; - y = 0; - } - - public DragSourceEvent(DragSourceContext context, int x, int y) - { - super(context); - locationSpecified = true; - this.x = x; - this.y = y; - } - - public DragSourceContext getDragSourceContext() - { - return (DragSourceContext) source; - } - - public Point getLocation() - { - return locationSpecified ? new Point(x, y) : null; - } - - public int getX() - { - return x; - } - - public int getY() - { - return y; - } -} // class DragSourceEvent diff --git a/libjava/java/awt/dnd/DragSourceListener.java b/libjava/java/awt/dnd/DragSourceListener.java deleted file mode 100644 index aac6e94ebe7..00000000000 --- a/libjava/java/awt/dnd/DragSourceListener.java +++ /dev/null @@ -1,97 +0,0 @@ -/* DragSourceListener.java -- listen to events during the drag - Copyright (C) 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.dnd; - -import java.util.EventListener; - -/** - * This class allows an object to listen for drag and drop events. It can - * be used to provide appropriate feedback for "drag over" actions. You can - * also use a <code>DragSourceAdapter</code> to filter the events you are - * interested in. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.2 - * @status updated to 1.4 - */ -public interface DragSourceListener extends EventListener -{ - /** - * Called when the cursor hotspot enters a drop site which will accept the - * drag. - * - * @param e the drag source drag event - */ - void dragEnter(DragSourceDragEvent e); - - /** - * Called when the cursor hotspot moves inside of a drop site which will - * accept the drag. - * - * @param e the drag source drag event - */ - void dragOver(DragSourceDragEvent e); - - /** - * Called when the user modifies the drop gesture. This is often the case - * when additional mouse or key events are received during the drag. - * - * @param e the drag source drag event - */ - void dropActionChanged(DragSourceDragEvent e); - - /** - * Called when the cursor hotspot moves outside of a drop site which will - * accept the drag. This could also happen if the drop site is no longer - * active, or no longer accepts the drag. - * - * @param e the drag source drag event - */ - void dragExit(DragSourceEvent e); - - /** - * Called when the drag and drop operation is complete. After this event, - * <code>getDropSuccess</code> of the event is valid, and - * <code>getDropAction</code> holds the action requested by the drop site. - * Furthermore, the <code>DragSourceContext</code> is invalidated. - * - * @param e the drag source drag event - */ - void dragDropEnd(DragSourceDropEvent e); -} // interface DragSourceListener diff --git a/libjava/java/awt/dnd/DragSourceMotionListener.java b/libjava/java/awt/dnd/DragSourceMotionListener.java deleted file mode 100644 index 5d04c227100..00000000000 --- a/libjava/java/awt/dnd/DragSourceMotionListener.java +++ /dev/null @@ -1,64 +0,0 @@ -/* DragSourceMotionListener.java -- tracks motion in the drag source - Copyright (C) 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.dnd; - -import java.util.EventListener; - -/** - * This is a listener for mouse motion in the drag source before the drop - * event occurs. You can also use a <code>DragSourceAdapter</code> to filter - * the events you are interested in. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @see DragSourceDragEvent - * @see DragSource - * @see DragSourceListener - * @see DragSourceAdapter - * @since 1.4 - * @status updated to 1.4 - */ -public interface DragSourceMotionListener extends EventListener -{ - /** - * Called whenever the mouse is moved during a drag-and-drop operation. - * - * @param e the event - */ - void dragMouseMoved(DragSourceDragEvent e); -} // interface DragSourceMotionListener diff --git a/libjava/java/awt/dnd/DropTarget.java b/libjava/java/awt/dnd/DropTarget.java deleted file mode 100644 index 9fd7ef896fb..00000000000 --- a/libjava/java/awt/dnd/DropTarget.java +++ /dev/null @@ -1,293 +0,0 @@ -/* DropTarget.java -- - Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.dnd; - -import java.awt.Component; -import java.awt.GraphicsEnvironment; -import java.awt.HeadlessException; -import java.awt.Point; -import java.awt.datatransfer.FlavorMap; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.io.Serializable; -import java.util.EventListener; -import java.util.TooManyListenersException; - -/** - * @author Michael Koch - * @since 1.2 - */ -public class DropTarget - implements DropTargetListener, EventListener, Serializable -{ - /** - * Compatible with JDK 1.2+ - */ - private static final long serialVersionUID = -6283860791671019047L; - - /** @specnote According to the online documentation, this is - * protected, but in reality it is public. */ - public static class DropTargetAutoScroller - implements ActionListener - { - private Component component; - private Point point; - - protected DropTargetAutoScroller (Component c, Point p) - { - component = c; - point = p; - } - - protected void updateLocation (Point newLocn) - { - point = newLocn; - } - - protected void stop () - { - } - - public void actionPerformed (ActionEvent e) - { - } - } - - private Component component; - private FlavorMap flavorMap; - private int actions; - private DropTargetContext dropTargetContext; - private DropTargetListener dropTargetListener; - private boolean active = true; - - /** - * Creates a <code>DropTarget</code> object. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() - * returns true. - */ - public DropTarget () - { - this (null, 0, null, true, null); - } - - /** - * Creates a <code>DropTarget</code> object. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() - * returns true. - */ - public DropTarget (Component c, DropTargetListener dtl) - { - this (c, 0, dtl, true, null); - } - - /** - * Creates a <code>DropTarget</code> object. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() - * returns true. - */ - public DropTarget (Component c, int i, DropTargetListener dtl) - { - this (c, i, dtl, true, null); - } - - /** - * Creates a <code>DropTarget</code> object. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() - * returns true. - */ - public DropTarget (Component c, int i, DropTargetListener dtl, boolean b) - { - this (c, i, dtl, b, null); - } - - /** - * Creates a <code>DropTarget</code> object. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() - * returns true. - */ - public DropTarget (Component c, int i, DropTargetListener dtl, boolean b, - FlavorMap fm) - { - if (GraphicsEnvironment.isHeadless ()) - throw new HeadlessException (); - - component = c; - actions = i; - dropTargetListener = dtl; - flavorMap = fm; - - setActive (b); - } - - /** - * Sets the component associated with this drop target object. - */ - public void setComponent (Component c) - { - component = c; - } - - /** - * Returns the component associated with this drop target object. - */ - public Component getComponent () - { - return component; - } - - /** - * Sets the default actions. - */ - public void setDefaultActions (int ops) - { - actions = ops; - } - - /** - * Returns the default actions. - */ - public int getDefaultActions () - { - return actions; - } - - public void setActive (boolean active) - { - this.active = active; - } - - public boolean isActive() - { - return active; - } - - /** - * Adds a new <code>DropTargetListener</code>. - * - * @exception TooManyListenersException Sun's JDK does not, despite - * documentation, throw this exception here when you install an additional - * <code>DropTargetListener</code>. So to be compatible, we do the same - * thing. - */ - public void addDropTargetListener (DropTargetListener dtl) - throws TooManyListenersException - { - dropTargetListener = dtl; - } - - public void removeDropTargetListener(DropTargetListener dtl) - { - // FIXME: Do we need to do something with dtl ? - dropTargetListener = null; - } - - public void dragEnter(DropTargetDragEvent dtde) - { - } - - public void dragOver(DropTargetDragEvent dtde) - { - } - - public void dropActionChanged(DropTargetDragEvent dtde) - { - } - - public void dragExit(DropTargetEvent dte) - { - } - - public void drop(DropTargetDropEvent dtde) - { - } - - public FlavorMap getFlavorMap() - { - return flavorMap; - } - - public void setFlavorMap(FlavorMap fm) - { - flavorMap = fm; - } - - public void addNotify(java.awt.peer.ComponentPeer peer) - { - } - - public void removeNotify(java.awt.peer.ComponentPeer peer) - { - } - - public DropTargetContext getDropTargetContext() - { - if (dropTargetContext == null) - dropTargetContext = createDropTargetContext (); - - return dropTargetContext; - } - - protected DropTargetContext createDropTargetContext() - { - return new DropTargetContext (this); - } - - protected DropTarget.DropTargetAutoScroller createDropTargetAutoScroller - (Component c, Point p) - { - return new DropTarget.DropTargetAutoScroller (c, p); - } - - protected void initializeAutoscrolling(Point p) - { - } - - protected void updateAutoscroll(Point dragCursorLocn) - { - } - - protected void clearAutoscroll() - { - } -} // class DropTarget diff --git a/libjava/java/awt/dnd/DropTargetAdapter.java b/libjava/java/awt/dnd/DropTargetAdapter.java deleted file mode 100644 index 13c6b9f4b6d..00000000000 --- a/libjava/java/awt/dnd/DropTargetAdapter.java +++ /dev/null @@ -1,100 +0,0 @@ -/* DragSourceAdapter.java -- drag-and-drop listener adapter - Copyright (C) 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.awt.dnd; - -/** - * This class implements <code>DropTargetListener</code>, and implements all methods - * with empty bodies. This allows a listener interested in implementing only - * a subset of these interfaces to extend this class and override only the - * desired methods. - * - * @author Michael Koch (konqueror@gmx.de) - * @since 1.4 - * @status updated to 1.4 - */ -public abstract class DropTargetAdapter - implements DropTargetListener -{ - /** - * Default constructor. - */ - public DropTargetAdapter() - { - } - - /** - * Called when the cursor hotspot enters a drop site which will accept the - * drag. - * - * @param e the event - */ - public void dragEnter (DropTargetDragEvent e) - { - } - - /** - * Called when the cursor hotspot moves inside of a drop site which will - * accept the drag. - * - * @param e the event - */ - public void dragOver (DropTargetDragEvent e) - { - } - - /** - * Called when the user modifies the drop gesture. This is often the case - * when additional mouse or key events are received during the drag. - * - * @param e the event - */ - public void dropActionChanged (DropTargetDragEvent e) - { - } - - /** - * Called when the cursor hotspot moves outside of a drop site which will - * accept the drag. This could also happen if the drop site is no longer - * active, or no longer accepts the drag. - * - * @param e the event - */ - public void dragExit(DropTargetEvent e) - { - } -} // class DropTargetAdapter diff --git a/libjava/java/awt/dnd/DropTargetContext.java b/libjava/java/awt/dnd/DropTargetContext.java deleted file mode 100644 index d1fb66e6f35..00000000000 --- a/libjava/java/awt/dnd/DropTargetContext.java +++ /dev/null @@ -1,188 +0,0 @@ -/* DropTargetContext.java -- - Copyright (C) 2002, 2003, 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.awt.dnd; - -import java.awt.Component; -import java.awt.datatransfer.DataFlavor; -import java.awt.datatransfer.Transferable; -import java.awt.datatransfer.UnsupportedFlavorException; -import java.io.IOException; -import java.io.Serializable; -import java.util.Arrays; -import java.util.List; - -/** - * @author Michael Koch (konqueror@gmx.de) - * @since 1.2 - */ -public class DropTargetContext implements Serializable -{ - static final long serialVersionUID = -634158968993743371L; - - /** @specnote According to the online documentation, this is - * protected, but in reality it is public. */ - public class TransferableProxy implements Transferable - { - protected boolean isLocal; - protected Transferable transferable; - - TransferableProxy (Transferable t, boolean local) - { - this.transferable = t; - this.isLocal = local; - } - - public DataFlavor[] getTransferDataFlavors () - { - return transferable.getTransferDataFlavors (); - } - - public boolean isDataFlavorSupported (DataFlavor flavor) - { - return transferable.isDataFlavorSupported (flavor); - } - - public Object getTransferData (DataFlavor flavor) - throws UnsupportedFlavorException, IOException - { - return transferable.getTransferData (flavor); - } - } - - private DropTarget dropTarget; - private int targetActions; - private java.awt.dnd.peer.DropTargetContextPeer dtcp; - - // package private - DropTargetContext (DropTarget dropTarget) - { - this.dropTarget = dropTarget; - } - - public DropTarget getDropTarget () - { - return dropTarget; - } - - public Component getComponent () - { - return dropTarget.getComponent (); - } - - public void addNotify (java.awt.dnd.peer.DropTargetContextPeer dtcp) - { - this.dtcp = dtcp; - } - - public void removeNotify () - { - this.dtcp = null; - } - - protected void setTargetActions (int actions) - { - targetActions = actions; - } - - protected int getTargetActions() - { - return targetActions; - } - - /** - * Signals that the drop is completed. - * - * @exception InvalidDnDOperationException If a drop is not outstanding. - */ - public void dropComplete (boolean success) - { - // FIXME: implement this - } - - protected void acceptDrag (int dragOperation) - { - // FIXME: implement this - } - - protected void rejectDrag () - { - // FIXME: implement this - } - - protected void acceptDrop (int dropOperation) - { - // FIXME: implement this - } - - protected void rejectDrop () - { - // FIXME: implement this - } - - protected DataFlavor[] getCurrentDataFlavors () - { - // FIXME: implement this - return null; - } - - protected List getCurrentDataFlavorsAsList () - { - return Arrays.asList (getCurrentDataFlavors ()); - } - - protected boolean isDataFlavorSupported (DataFlavor flavor) - { - return getCurrentDataFlavorsAsList ().contains (flavor); - } - - /** - * Return the <code>Transferable</code> operandof this operation. - * - * @exception InvalidDnDOperationException If a drag is not outstanding. - */ - protected Transferable getTransferable() throws InvalidDnDOperationException - { - // FIXME: implement this - return null; - } - - protected Transferable createTransferableProxy(Transferable t, boolean local) - { - return new TransferableProxy (t, local); - } -} // class DropTargetContext diff --git a/libjava/java/awt/dnd/DropTargetDragEvent.java b/libjava/java/awt/dnd/DropTargetDragEvent.java deleted file mode 100644 index 6cdc3a292be..00000000000 --- a/libjava/java/awt/dnd/DropTargetDragEvent.java +++ /dev/null @@ -1,140 +0,0 @@ -/* DropTargetDragEvent.java -- - Copyright (C) 2002, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.dnd; - -import java.awt.Point; -import java.awt.datatransfer.DataFlavor; -import java.util.List; - -/** - * @since 1.2 - */ -public class DropTargetDragEvent extends DropTargetEvent -{ - /** - * Compatible with 1.2+ - */ - private static final long serialVersionUID = -8422265619058953682L; - - private final int dropAction; - private final int srcActions; - private final Point location; - - /** - * Initializes a <code>DropTargetDragEvent</code>. - * - * @exception IllegalArgumentException If dropAction is not one of DnDConstants, - * srcActions is not a bitwise mask of DnDConstants, or dtc is null. - * @exception NullPointerException If location is null. - */ - public DropTargetDragEvent (DropTargetContext context, Point location, - int dropAction, int srcActions) - { - super (context); - - if (location == null) - throw new NullPointerException (); - - if (context == null) - throw new IllegalArgumentException (); - - if (dropAction != DnDConstants.ACTION_NONE - && dropAction != DnDConstants.ACTION_COPY - && dropAction != DnDConstants.ACTION_MOVE - && dropAction != DnDConstants.ACTION_COPY_OR_MOVE - && dropAction != DnDConstants.ACTION_LINK - && dropAction != DnDConstants.ACTION_REFERENCE) - throw new IllegalArgumentException (); - - int srcActionsMask = DnDConstants.ACTION_NONE - | DnDConstants.ACTION_COPY - | DnDConstants.ACTION_MOVE - | DnDConstants.ACTION_COPY_OR_MOVE - | DnDConstants.ACTION_LINK - | DnDConstants.ACTION_REFERENCE; - - if (~(srcActions ^ srcActionsMask) != 0) - throw new IllegalArgumentException (); - - this.dropAction = dropAction; - this.srcActions = srcActions; - this.location = location; - } - - public void acceptDrag (int dragOperation) - { - context.acceptDrag (dragOperation); - } - - public DataFlavor[] getCurrentDataFlavors () - { - return context.getCurrentDataFlavors (); - } - - public List getCurrentDataFlavorsAsList () - { - return context.getCurrentDataFlavorsAsList (); - } - - public int getDropAction() - { - return 0; - //return dropAction & ((DropTargetContext) source).getTargetActions(); - } - - public Point getLocation () - { - return location; - } - - public int getSourceActions () - { - return srcActions; - } - - public boolean isDataFlavorSupported (DataFlavor df) - { - return context.isDataFlavorSupported (df); - } - - public void rejectDrag () - { - context.rejectDrag (); - } -} // class DropTargetDragEvent diff --git a/libjava/java/awt/dnd/DropTargetDropEvent.java b/libjava/java/awt/dnd/DropTargetDropEvent.java deleted file mode 100644 index 0c0777f78d0..00000000000 --- a/libjava/java/awt/dnd/DropTargetDropEvent.java +++ /dev/null @@ -1,170 +0,0 @@ -/* DropTargetDropEvent.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.awt.dnd; - -import java.awt.Point; -import java.awt.datatransfer.DataFlavor; -import java.awt.datatransfer.Transferable; -import java.util.List; - -/** - * @since 1.2 - */ -public class DropTargetDropEvent extends DropTargetEvent -{ - /** - * Compatible with JDK 1.2+ - */ - private static final long serialVersionUID = -1721911170440459322L; - - private final int dropAction; - private final int actions; - private final Point location; - private final boolean isLocalTx; - - /** - * Initializes a <code>DropTargetDropEvent</code>. By default this constructor - * assumes that the target is not int same JVM. - * - * @exception IllegalArgumentException If dropAction is not one of DnDConstants, - * actions is not a bitwise mask of DnDConstants, or dtc is null. - * @exception NullPointerException If location is null. - */ - public DropTargetDropEvent (DropTargetContext dtc, Point location, - int dropAction, int actions) - { - this (dtc, location, dropAction, actions, false); - } - - /** - * Initializes a <code>DropTargetDropEvent</code>. - * - * @exception IllegalArgumentException If dropAction is not one of DnDConstants, - * actions is not a bitwise mask of DnDConstants, or dtc is null. - * @exception NullPointerException If location is null. - */ - public DropTargetDropEvent (DropTargetContext dtc, Point location, - int dropAction, int actions, boolean isLocalTx) - { - super (dtc); - - if (location == null) - throw new NullPointerException (); - - if (dtc == null) - throw new IllegalArgumentException (); - - if (dropAction != DnDConstants.ACTION_NONE - && dropAction != DnDConstants.ACTION_COPY - && dropAction != DnDConstants.ACTION_MOVE - && dropAction != DnDConstants.ACTION_COPY_OR_MOVE - && dropAction != DnDConstants.ACTION_LINK - && dropAction != DnDConstants.ACTION_REFERENCE) - throw new IllegalArgumentException (); - - int actionsMask = DnDConstants.ACTION_NONE - | DnDConstants.ACTION_COPY - | DnDConstants.ACTION_MOVE - | DnDConstants.ACTION_COPY_OR_MOVE - | DnDConstants.ACTION_LINK - | DnDConstants.ACTION_REFERENCE; - - if (~(actions ^ actionsMask) != 0) - throw new IllegalArgumentException (); - - this.dropAction = dropAction; - this.actions = actions; - this.location = location; - this.isLocalTx = isLocalTx; - } - - public Point getLocation () - { - return location; - } - - public DataFlavor[] getCurrentDataFlavors () - { - return context.getCurrentDataFlavors (); - } - - public List getCurrentDataFlavorsAsList () - { - return context.getCurrentDataFlavorsAsList (); - } - - public boolean isDataFlavorSupported (DataFlavor flavor) - { - return context.isDataFlavorSupported (flavor); - } - - public int getSourceActions () - { - return actions; - } - - public int getDropAction () - { - return dropAction; - } - - public Transferable getTransferable () - { - return context.getTransferable (); - } - - public void acceptDrop (int dropAction) - { - context.acceptDrop (dropAction); - } - - public void rejectDrop () - { - context.rejectDrop (); - } - - public void dropComplete (boolean success) - { - // FIXME: implement this - } - - public boolean isLocalTransfer() - { - return isLocalTx; - } -} // class DropTargetDropEvent diff --git a/libjava/java/awt/dnd/DropTargetEvent.java b/libjava/java/awt/dnd/DropTargetEvent.java deleted file mode 100644 index 56a4d481a16..00000000000 --- a/libjava/java/awt/dnd/DropTargetEvent.java +++ /dev/null @@ -1,56 +0,0 @@ -/* DropTarget.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.awt.dnd; - -import java.util.EventObject; - -public class DropTargetEvent extends EventObject -{ - protected DropTargetContext context; - - public DropTargetEvent (DropTargetContext context) - { - super (context); - this.context = context; - } - - public DropTargetContext getDropTargetContext () - { - return context; - } -} diff --git a/libjava/java/awt/dnd/DropTargetListener.java b/libjava/java/awt/dnd/DropTargetListener.java deleted file mode 100644 index ceb839bac27..00000000000 --- a/libjava/java/awt/dnd/DropTargetListener.java +++ /dev/null @@ -1,89 +0,0 @@ -/* DropTargetListener.java -- listen to events during the drop - Copyright (C) 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.dnd; - -import java.util.EventListener; - -/** - * @author Michael Koch (konqueror@gmx.de) - * @since 1.2 - * @status updated to 1.4 - */ -public interface DropTargetListener extends EventListener -{ - /** - * Called when the cursor hotspot enters a drop site which will accept the - * drag. - * - * @param e the drag source drag event - */ - void dragEnter (DropTargetDragEvent e); - - /** - * Called when the cursor hotspot moves inside of a drop site which will - * accept the drag. - * - * @param e the drag source drag event - */ - void dragOver (DropTargetDragEvent e); - - /** - * Called when the user modifies the drop gesture. This is often the case - * when additional mouse or key events are received during the drag. - * - * @param e the drag source drag event - */ - void dropActionChanged (DropTargetDragEvent e); - - /** - * Called when the cursor hotspot moves outside of a drop site which will - * accept the drag. This could also happen if the drop site is no longer - * active, or no longer accepts the drag. - * - * @param e the drag source drag event - */ - void dragExit (DropTargetEvent e); - - /** - * Called when the drag operation has terminated with a drop. - * - * @param e the drag source drag event - */ - void drop (DropTargetDropEvent e); -} // interface DropTargetListener diff --git a/libjava/java/awt/dnd/InvalidDnDOperationException.java b/libjava/java/awt/dnd/InvalidDnDOperationException.java deleted file mode 100644 index 2fd9767e03d..00000000000 --- a/libjava/java/awt/dnd/InvalidDnDOperationException.java +++ /dev/null @@ -1,73 +0,0 @@ -/* InvalidDnDOperationException.java -- thrown when drag-and-drop fails - Copyright (C) 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.dnd; - -/** - * Thrown when a method in the java.awt.dnd package is unable to perform a - * requested operation, usually because the underlying DnD system is in the - * wrong state. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.2 - * @status updated to 1.4 - */ -public class InvalidDnDOperationException extends IllegalStateException -{ - /** - * Compatible with JDK 1.2+. - */ - private static final long serialVersionUID = -6062568741193956678L; - - /** - * Create an exception without a message. - */ - public InvalidDnDOperationException() - { - } - - /** - * Create an exception with a message. - * - * @param s the message - */ - public InvalidDnDOperationException(String s) - { - super(s); - } -} // class InvalidDnDOperationException diff --git a/libjava/java/awt/dnd/MouseDragGestureRecognizer.java b/libjava/java/awt/dnd/MouseDragGestureRecognizer.java deleted file mode 100644 index 9a2a7bc4c79..00000000000 --- a/libjava/java/awt/dnd/MouseDragGestureRecognizer.java +++ /dev/null @@ -1,131 +0,0 @@ -/* MouseDragGestureRecognizer.java -- - Copyright (C) 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.awt.dnd; - -import java.awt.Component; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; -import java.awt.event.MouseMotionListener; - -/** - * @author Michael Koch (konqueror@gmx.de) - */ -public abstract class MouseDragGestureRecognizer - extends DragGestureRecognizer - implements MouseListener, MouseMotionListener -{ - /** - * Creates a <code>MouseDragGestureRecognizer</code> object. - */ - protected MouseDragGestureRecognizer (DragSource ds, Component c, int act, - DragGestureListener dgl) - { - super (ds, c, act, dgl); - } - - /** - * Creates a <code>MouseDragGestureRecognizer</code> object. - */ - protected MouseDragGestureRecognizer (DragSource ds, Component c, int act) - { - super (ds, c, act); - } - - /** - * Creates a <code>MouseDragGestureRecognizer</code> object. - */ - protected MouseDragGestureRecognizer (DragSource ds, Component c) - { - super (ds, c); - } - - /** - * Creates a <code>MouseDragGestureRecognizer</code> object. - */ - protected MouseDragGestureRecognizer (DragSource ds) - { - super (ds); - } - - protected void registerListeners () - { - component.addMouseListener (this); - component.addMouseMotionListener (this); - } - - protected void unregisterListeners () - { - component.removeMouseListener (this); - component.removeMouseMotionListener (this); - } - - public void mouseClicked (MouseEvent e) - { - // Do nothing in here by default. - } - - public void mousePressed (MouseEvent e) - { - // Do nothing in here by default. - } - - public void mouseReleased (MouseEvent e) - { - // Do nothing in here by default. - } - - public void mouseEntered (MouseEvent e) - { - // Do nothing in here by default. - } - - public void mouseExited (MouseEvent e) - { - // Do nothing in here by default. - } - - public void mouseDragged (MouseEvent e) - { - // Do nothing in here by default. - } - - public void mouseMoved (MouseEvent e) - { - // Do nothing in here by default. - } -} // class MouseDragGestureRecognizer diff --git a/libjava/java/awt/dnd/peer/DragSourceContextPeer.java b/libjava/java/awt/dnd/peer/DragSourceContextPeer.java deleted file mode 100644 index 8c134b623a7..00000000000 --- a/libjava/java/awt/dnd/peer/DragSourceContextPeer.java +++ /dev/null @@ -1,57 +0,0 @@ -/* DragSourceContextPeer.java -- interface for drag-and-drop peers - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.dnd.peer; - -import java.awt.Cursor; -import java.awt.Image; -import java.awt.Point; -import java.awt.dnd.DragSourceContext; -import java.awt.dnd.InvalidDnDOperationException; - -/** - * STUBBED - */ -public interface DragSourceContextPeer -{ - void startDrag(DragSourceContext context, Cursor c, Image i, Point p) - throws InvalidDnDOperationException; - Cursor getCursor(); - void setCursor(Cursor c) throws InvalidDnDOperationException; - void transferablesFlavorsChanged(); -} // interface DragSourceContextPeer diff --git a/libjava/java/awt/dnd/peer/DropTargetContextPeer.java b/libjava/java/awt/dnd/peer/DropTargetContextPeer.java deleted file mode 100644 index 6eae29b3810..00000000000 --- a/libjava/java/awt/dnd/peer/DropTargetContextPeer.java +++ /dev/null @@ -1,68 +0,0 @@ -/* DropTargetContextPeer.java -- interface for drag-and-drop peers - Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.dnd.peer; - -import java.awt.datatransfer.DataFlavor; -import java.awt.datatransfer.Transferable; -import java.awt.dnd.DropTarget; -import java.awt.dnd.InvalidDnDOperationException; - - -/** - * Used to control state of recipient protocol from the - * <code>DropTargetListener</code>. Occurs when a <code>Component</code> - * with an associated <code>DropTarget</code> and visible geometry is first - * intersected by a logical cursor. - * - * @author Michael Koch (konqueror@gmx.de) - */ -public interface DropTargetContextPeer -{ - void setTargetActions(int actions); - int getTargetActions(); - DropTarget getDropTarget(); - DataFlavor[] getTransferDataFlavors(); - Transferable getTransferable() throws InvalidDnDOperationException; - boolean isTransferableJVMLocal(); - void acceptDrag(int dragAction); - void rejectDrag(); - void acceptDrop(int dropAction); - void rejectDrop(); - void dropComplete(boolean success); -} diff --git a/libjava/java/awt/dnd/peer/DropTargetPeer.java b/libjava/java/awt/dnd/peer/DropTargetPeer.java deleted file mode 100644 index ec17cbe4be9..00000000000 --- a/libjava/java/awt/dnd/peer/DropTargetPeer.java +++ /dev/null @@ -1,48 +0,0 @@ -/* DropTargetPeer.java -- interface for drag-and-drop peers - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.awt.dnd.peer; - -import java.awt.dnd.DropTarget; - -/** - */ -public interface DropTargetPeer -{ - void addDropTarget (DropTarget target); - void removeDropTarget (DropTarget target); -} // interface DropTargetContextPeer diff --git a/libjava/java/awt/event/AWTEventListener.java b/libjava/java/awt/event/AWTEventListener.java deleted file mode 100644 index 8662b74006d..00000000000 --- a/libjava/java/awt/event/AWTEventListener.java +++ /dev/null @@ -1,64 +0,0 @@ -/* AWTEventListener.java -- listen for all events in the AWT system - Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.event; - -import java.awt.AWTEvent; -import java.util.EventListener; - -/** - * This listener is for classes that need to listen to all events in the AWT - * system. In general, this should not be used except for classes like - * javax.accessibility or by event recorders. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @see AWTEvent - * @see Toolkit#addAWTEventListener(AWTEventListener, long) - * @see Toolkit#removeAWTEventListener(AWTEventListener) - * @since 1.2 - * @status updated to 1.4 - */ -public interface AWTEventListener extends EventListener -{ - /** - * This method is called when any event in the AWT system is dispatched. - * - * @param event the AWTEvent that was dispatched - */ - void eventDispatched(AWTEvent event); -} // interface AWTEventListener diff --git a/libjava/java/awt/event/AWTEventListenerProxy.java b/libjava/java/awt/event/AWTEventListenerProxy.java deleted file mode 100644 index 9fccfc7ea2c..00000000000 --- a/libjava/java/awt/event/AWTEventListenerProxy.java +++ /dev/null @@ -1,154 +0,0 @@ -/* AWTEventListenerProxy.java -- wrapper/filter for AWTEventListener - Copyright (C) 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.event; - -import java.awt.AWTEvent; -import java.util.EventListenerProxy; - -/** - * This class allows adding an AWTEventListener which only pays attention to - * a specific event mask. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @see Toolkit - * @see EventListenerProxy - * @since 1.4 - * @status updated to 1.4 - */ -public class AWTEventListenerProxy extends EventListenerProxy - implements AWTEventListener -{ - /** The event mask. */ - private final long mask; - - /** - * Construct an AWT Event Listener which only listens to events in the given - * mask, passing the work on to the real listener. - * - * @param eventMask the mask of events to listen to - * @param listener the wrapped listener - */ - public AWTEventListenerProxy(long eventMask, AWTEventListener listener) - { - super(listener); - mask = eventMask; - } - - /** - * Forwards events on to the delegate if they meet the event mask. - * - * @param event the property change event to filter - * @throws NullPointerException if the delegate this was created with is null - */ - public void eventDispatched(AWTEvent event) - { - int id = event == null ? 0 : event.getID(); - if (((mask & AWTEvent.ACTION_EVENT_MASK) != 0 - && event instanceof ActionEvent) - || ((mask & AWTEvent.ADJUSTMENT_EVENT_MASK) != 0 - && event instanceof AdjustmentEvent) - || ((mask & AWTEvent.COMPONENT_EVENT_MASK) != 0 - && event instanceof ComponentEvent - && (id >= ComponentEvent.COMPONENT_FIRST - && id <= ComponentEvent.COMPONENT_LAST)) - || ((mask & AWTEvent.CONTAINER_EVENT_MASK) != 0 - && event instanceof ContainerEvent) - || ((mask & AWTEvent.FOCUS_EVENT_MASK) != 0 - && event instanceof FocusEvent) - || ((mask & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) != 0 - && event instanceof HierarchyEvent - && (id == HierarchyEvent.ANCESTOR_MOVED - || id == HierarchyEvent.ANCESTOR_RESIZED)) - || ((mask & AWTEvent.HIERARCHY_EVENT_MASK) != 0 - && event instanceof HierarchyEvent - && id == HierarchyEvent.HIERARCHY_CHANGED) - || ((mask & AWTEvent.INPUT_METHOD_EVENT_MASK) != 0 - && event instanceof InputMethodEvent) - || ((mask & AWTEvent.INVOCATION_EVENT_MASK) != 0 - && event instanceof InvocationEvent) - || ((mask & AWTEvent.ITEM_EVENT_MASK) != 0 - && event instanceof ItemEvent) - || ((mask & AWTEvent.KEY_EVENT_MASK) != 0 - && event instanceof KeyEvent) - || ((mask & AWTEvent.MOUSE_EVENT_MASK) != 0 - && event instanceof MouseEvent - && (id == MouseEvent.MOUSE_PRESSED - || id == MouseEvent.MOUSE_RELEASED - || id == MouseEvent.MOUSE_CLICKED - || id == MouseEvent.MOUSE_ENTERED - || id == MouseEvent.MOUSE_EXITED)) - || ((mask & AWTEvent.MOUSE_MOTION_EVENT_MASK) != 0 - && event instanceof MouseEvent - && (id == MouseEvent.MOUSE_MOVED - || id == MouseEvent.MOUSE_DRAGGED)) - || ((mask & AWTEvent.MOUSE_WHEEL_EVENT_MASK) != 0 - && event instanceof MouseWheelEvent) - || ((mask & AWTEvent.PAINT_EVENT_MASK) != 0 - && event instanceof PaintEvent) - || ((mask & AWTEvent.TEXT_EVENT_MASK) != 0 - && event instanceof TextEvent) - || ((mask & AWTEvent.WINDOW_EVENT_MASK) != 0 - && event instanceof WindowEvent - && (id == WindowEvent.WINDOW_OPENED - || id == WindowEvent.WINDOW_CLOSING - || id == WindowEvent.WINDOW_CLOSED - || id == WindowEvent.WINDOW_ICONIFIED - || id == WindowEvent.WINDOW_DEICONIFIED - || id == WindowEvent.WINDOW_ACTIVATED - || id == WindowEvent.WINDOW_DEACTIVATED)) - || ((mask & AWTEvent.WINDOW_FOCUS_EVENT_MASK) != 0 - && event instanceof WindowEvent - && (id == WindowEvent.WINDOW_GAINED_FOCUS - || id == WindowEvent.WINDOW_LOST_FOCUS)) - || ((mask & AWTEvent.WINDOW_STATE_EVENT_MASK) != 0 - && event instanceof WindowEvent - && id == WindowEvent.WINDOW_STATE_CHANGED)) - ((AWTEventListener) getListener()).eventDispatched(event); - } - - /** - * This returns the event mask associated with this listener. - * - * @return the event mask - */ - public long getEventMask() - { - return mask; - } -} // class AWTEventListenerProxy diff --git a/libjava/java/awt/event/ActionEvent.java b/libjava/java/awt/event/ActionEvent.java deleted file mode 100644 index 4bce7d45ce0..00000000000 --- a/libjava/java/awt/event/ActionEvent.java +++ /dev/null @@ -1,226 +0,0 @@ -/* ActionEvent.java -- an action has been triggered - Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.event; - -import java.awt.AWTEvent; -import java.awt.EventQueue; - -/** - * This event is generated when an action on a component (such as a - * button press) occurs. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @see ActionListener - * @since 1.1 - * @status updated to 1.4 - */ -public class ActionEvent extends AWTEvent -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = -7671078796273832149L; - - /** Bit mask indicating the shift key was pressed. */ - public static final int SHIFT_MASK = InputEvent.SHIFT_MASK; - - /** Bit mask indicating the control key was pressed. */ - public static final int CTRL_MASK = InputEvent.CTRL_MASK; - - /** Bit mask indicating the that meta key was pressed. */ - public static final int META_MASK = InputEvent.META_MASK; - - /** Bit mask indicating that the alt key was pressed. */ - public static final int ALT_MASK = InputEvent.ALT_MASK; - - /** The first id number in the range of action id's. */ - public static final int ACTION_FIRST = 1001; - - /** The last id number in the range of action id's. */ - public static final int ACTION_LAST = 1001; - - /** An event id indicating that an action has occurred. */ - public static final int ACTION_PERFORMED = 1001; - - /** - * A nonlocalized string that gives more specific details of the event cause. - * - * @see #getActionCommand() - * @serial the command for this event - */ - private final String actionCommand; - - /** - * The bitmask of the modifiers that were pressed during the action. - * - * @see #getModifiers() - * @serial modifiers for this event - */ - private final int modifiers; - - /** - * The timestamp of this event; usually the same as the underlying input - * event. - * - * @see #getWhen() - * @serial the timestamp of the event - * @since 1.4 - */ - private final long when; - - /** - * Initializes a new instance of <code>ActionEvent</code> with the - * specified source, id, and command. Note that an invalid id leads to - * unspecified results. - * - * @param source the event source - * @param id the event id - * @param command the command string for this action - * @throws IllegalArgumentException if source is null - */ - public ActionEvent(Object source, int id, String command) - { - this(source, id, command, EventQueue.getMostRecentEventTime(), 0); - } - - /** - * Initializes a new instance of <code>ActionEvent</code> with the - * specified source, id, command, and modifiers. Note that an invalid id - * leads to unspecified results. - * - * @param source the event source - * @param id the event id - * @param command the command string for this action - * @param modifiers the bitwise or of modifier keys down during the action - * @throws IllegalArgumentException if source is null - */ - public ActionEvent(Object source, int id, String command, int modifiers) - { - this(source, id, command, EventQueue.getMostRecentEventTime(), modifiers); - } - - /** - * Initializes a new instance of <code>ActionEvent</code> with the - * specified source, id, command, and modifiers, and timestamp. Note that - * an invalid id leads to unspecified results. - * - * @param source the event source - * @param id the event id - * @param command the command string for this action - * @param when the timestamp of the event - * @param modifiers the bitwise or of modifier keys down during the action - * @throws IllegalArgumentException if source is null - * @since 1.4 - */ - public ActionEvent(Object source, int id, String command, long when, - int modifiers) - { - super(source, id); - actionCommand = command; - this.when = when; - this.modifiers = modifiers; - } - - /** - * Returns the command string associated with this action. - * - * @return the command string associated with this action - */ - public String getActionCommand() - { - return actionCommand; - } - - /** - * Gets the timestamp of when this action took place. Usually, this - * corresponds to the timestamp of the underlying InputEvent. - * - * @return the timestamp of this action - * @since 1.4 - */ - public long getWhen() - { - return when; - } - - /** - * Returns the keys held down during the action. This value will be a - * combination of the bit mask constants defined in this class, or 0 if no - * modifiers were pressed. - * - * @return the modifier bits - */ - public int getModifiers() - { - return modifiers; - } - - /** - * Returns a string that identifies the action event. This is in the format - * <code>"ACTION_PERFORMED,cmd=" + getActionCommand() + ",when=" + getWhen() - * + ",modifiers=" + <modifier string></code>, where the modifier - * string is in the order "Meta", "Ctrl", "Alt", "Shift", "Alt Graph", and - * "Button1", separated by '+', according to the bits set in getModifiers(). - * - * @return a string identifying the event - */ - public String paramString() - { - StringBuffer s = new StringBuffer(id == ACTION_PERFORMED - ? "ACTION_PERFORMED,cmd=" - : "unknown type,cmd="); - s.append(actionCommand).append(",when=").append(when).append(",modifiers"); - int len = s.length(); - s.setLength(len + 1); - if ((modifiers & META_MASK) != 0) - s.append("+Meta"); - if ((modifiers & CTRL_MASK) != 0) - s.append("+Ctrl"); - if ((modifiers & ALT_MASK) != 0) - s.append("+Alt"); - if ((modifiers & SHIFT_MASK) != 0) - s.append("+Shift"); - if ((modifiers & InputEvent.ALT_GRAPH_MASK) != 0) - s.append("+Alt Graph"); - if ((modifiers & InputEvent.BUTTON1_MASK) != 0) - s.append("+Button1"); - s.setCharAt(len, '='); - return s.toString(); - } -} // class ActionEvent diff --git a/libjava/java/awt/event/ActionListener.java b/libjava/java/awt/event/ActionListener.java deleted file mode 100644 index 4c302cca310..00000000000 --- a/libjava/java/awt/event/ActionListener.java +++ /dev/null @@ -1,59 +0,0 @@ -/* ActionListener.java -- listens for action events - Copyright (C) 1999, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.event; - -import java.util.EventListener; - -/** - * This interface is for classes that listen for action events. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @see ActionEvent - * @since 1.1 - * @status updated to 1.4 - */ -public interface ActionListener extends EventListener -{ - /** - * This method is invoked when an action occurs. - * - * @param event the <code>ActionEvent</code> that occurred - */ - void actionPerformed(ActionEvent event); -} diff --git a/libjava/java/awt/event/AdjustmentEvent.java b/libjava/java/awt/event/AdjustmentEvent.java deleted file mode 100644 index 867c577d356..00000000000 --- a/libjava/java/awt/event/AdjustmentEvent.java +++ /dev/null @@ -1,222 +0,0 @@ -/* AdjustmentEvent.java -- an adjustable value was changed - Copyright (C) 1999, 2002, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.event; - -import java.awt.AWTEvent; -import java.awt.Adjustable; - -/** - * This class represents an event that is generated when an adjustable - * value is changed. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @see Adjustable - * @see AdjustmentListener - * @since 1.1 - * @status updated to 1.4 - */ -public class AdjustmentEvent extends AWTEvent -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = 5700290645205279921L; - - /** This is the first id in the range of ids used by adjustment events. */ - public static final int ADJUSTMENT_FIRST = 601; - - /** This is the last id in the range of ids used by adjustment events. */ - public static final int ADJUSTMENT_LAST = 601; - - /** This is the id indicating an adjustment value changed. */ - public static final int ADJUSTMENT_VALUE_CHANGED = 601; - - /** Adjustment type for unit increments. */ - public static final int UNIT_INCREMENT = 1; - - /** Adjustment type for unit decrements. */ - public static final int UNIT_DECREMENT = 2; - - /** Adjustment type for block decrements. */ - public static final int BLOCK_DECREMENT = 3; - - /** Adjustment type for block increments. */ - public static final int BLOCK_INCREMENT = 4; - - /** Adjustment type for tracking adjustments. */ - public static final int TRACK = 5; - - /** - * The adjustable object that caused the event. - * - * @see #getAdjustable() - * @serial the cause - */ - private final Adjustable adjustable; - - /** - * The type of adjustment, one of {@link #UNIT_INCREMENT}, - * {@link #UNIT_DECREMENT}, {@link #BLOCK_INCREMENT}, - * {@link #BLOCK_DECREMENT}, or {@link #TRACK}. - * - * @see #getAdjustmentType() - * @serial the adjustment type - */ - private final int adjustmentType; - - /** - * The new value of the adjustable; it should be in the range of the - * adjustable cause. - * - * @see #getValue() - * @serial the adjustment value - */ - private final int value; - - /** - * True if this is in a series of multiple adjustment events. - * - * @see #getValueIsAdjusting() - * @serial true if this is not the last adjustment - * @since 1.4 - */ - private final boolean isAdjusting; - - /** - * Initializes an instance of <code>AdjustmentEvent</code> with the - * specified source, id, type, and value. Note that an invalid id leads to - * unspecified results. - * - * @param source the source of the event - * @param id the event id - * @param type the event type, one of the constants of this class - * @param value the value of the adjustment - * @throws IllegalArgumentException if source is null - */ - public AdjustmentEvent(Adjustable source, int id, int type, int value) - { - this(source, id, type, value, false); - } - - /** - * Initializes an instance of <code>AdjustmentEvent</code> with the - * specified source, id, type, and value. Note that an invalid id leads to - * unspecified results. - * - * @param source the source of the event - * @param id the event id - * @param type the event type, one of the constants of this class - * @param value the value of the adjustment - * @param isAdjusting if this event is in a chain of adjustments - * @throws IllegalArgumentException if source is null - * @since 1.4 - */ - public AdjustmentEvent(Adjustable source, int id, int type, int value, - boolean isAdjusting) - { - super(source, id); - this.adjustmentType = type; - this.value = value; - adjustable = source; - this.isAdjusting = isAdjusting; - } - - /** - * This method returns the source of the event as an <code>Adjustable</code>. - * - * @return the <code>Adjustable</code> source of the event - */ - public Adjustable getAdjustable() - { - return adjustable; - } - - /** - * Returns the new value of the adjustable object. - * - * @return the value of the event - */ - public int getValue() - { - return value; - } - - /** - * Returns the type of the event, which will be one of - * {@link #UNIT_INCREMENT}, {@link #UNIT_DECREMENT}, - * {@link #BLOCK_INCREMENT}, {@link #BLOCK_DECREMENT}, or {@link #TRACK}. - * - * @return the type of the event - */ - public int getAdjustmentType() - { - return adjustmentType; - } - - /** - * Test if this event is part of a sequence of multiple adjustements. - * - * @return true if this is not the last adjustment - * @since 1.4 - */ - public boolean getValueIsAdjusting() - { - return isAdjusting; - } - - /** - * Returns a string that describes the event. This is in the format - * <code>"ADJUSTMENT_VALUE_CHANGED,adjType=" + <type> + ",value=" - * + getValue() + ",isAdjusting=" + getValueIsAdjusting()</code>, where - * type is the name of the constant returned by getAdjustmentType(). - * - * @return a string that describes the event - */ - public String paramString() - { - return (id == ADJUSTMENT_VALUE_CHANGED - ? "ADJUSTMENT_VALUE_CHANGED,adjType=" : "unknown type,adjType=") - + (adjustmentType == UNIT_INCREMENT ? "UNIT_INCREMENT,value=" - : adjustmentType == UNIT_DECREMENT ? "UNIT_DECREMENT,value=" - : adjustmentType == BLOCK_INCREMENT ? "BLOCK_INCREMENT,value=" - : adjustmentType == BLOCK_DECREMENT ? "BLOCK_DECREMENT,value=" - : adjustmentType == TRACK ? "TRACK,value=" : "unknown type,value=") - + value + ",isAdjusting=" + isAdjusting; - } -} // class AdjustmentEvent diff --git a/libjava/java/awt/event/AdjustmentListener.java b/libjava/java/awt/event/AdjustmentListener.java deleted file mode 100644 index 1eb2e3bcfa1..00000000000 --- a/libjava/java/awt/event/AdjustmentListener.java +++ /dev/null @@ -1,58 +0,0 @@ -/* AdjustmentListener.java -- listen for adjustment events - Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.event; - -import java.util.EventListener; - -/** - * Interface for classes that listen for adjustment events. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @since 1.1 - * @status updated to 1.4 - */ -public interface AdjustmentListener extends EventListener -{ - /** - * This method is called when an adjustable value changes. - * - * @param event the <code>AdjustmentEvent</code> that occurred - */ - void adjustmentValueChanged(AdjustmentEvent event); -} // interface AdjustmentListener diff --git a/libjava/java/awt/event/ComponentAdapter.java b/libjava/java/awt/event/ComponentAdapter.java deleted file mode 100644 index 6b4893f0fc2..00000000000 --- a/libjava/java/awt/event/ComponentAdapter.java +++ /dev/null @@ -1,97 +0,0 @@ -/* ComponentAdapter.java -- convenience class for writing component listeners - Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.event; - -/** - * This class implements <code>ComponentListener</code> and implements - * all methods with empty bodies. This allows a listener interested in - * implementing only a subset of the <code>ComponentListener</code> - * interface to extend this class and override only the desired methods. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @see ComponentEvent - * @see ComponentListener - * @since 1.1 - * @status updated to 1.4 - */ -public abstract class ComponentAdapter implements ComponentListener -{ - /** - * Do nothing default constructor for subclasses. - */ - public ComponentAdapter() - { - } - - /** - * Implements this method from the interface with an empty body. - * - * @param event the event, ignored in this implementation - */ - public void componentResized(ComponentEvent event) - { - } - - /** - * Implements this method from the interface with an empty body. - * - * @param event the event, ignored in this implementation - */ - public void componentMoved(ComponentEvent event) - { - } - - /** - * Implements this method from the interface with an empty body. - * - * @param event the event, ignored in this implementation - */ - public void componentShown(ComponentEvent event) - { - } - - /** - * Implements this method from the interface with an empty body. - * - * @param event the event, ignored in this implementation - */ - public void componentHidden(ComponentEvent event) - { - } -} // class ComponentAdapter diff --git a/libjava/java/awt/event/ComponentEvent.java b/libjava/java/awt/event/ComponentEvent.java deleted file mode 100644 index ba9c2a5b3f2..00000000000 --- a/libjava/java/awt/event/ComponentEvent.java +++ /dev/null @@ -1,137 +0,0 @@ -/* ComponentEvent.java -- notification of events for components - Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.event; - -import java.awt.AWTEvent; -import java.awt.Component; - -/** - * This class is for events generated when a component is moved, resized, - * hidden, or shown. These events normally do not need to be handled by the - * application, since the AWT system automatically takes care of them. This - * is also the superclass for other events on components, but - * ComponentListeners ignore such subclasses. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @see ComponentAdapter - * @see ComponentListener - * @since 1.1 - * @status updated to 1.4 - */ -public class ComponentEvent extends AWTEvent -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = 8101406823902992965L; - - /** This is the first id in the range of ids used by this class. */ - public static final int COMPONENT_FIRST = 100; - - /** This is the last id in the range of ids used by this class. */ - public static final int COMPONENT_LAST = 103; - - /** This id indicates that a component was moved. */ - public static final int COMPONENT_MOVED = 100; - - /** This id indicates that a component was resized. */ - public static final int COMPONENT_RESIZED = 101; - - /** This id indicates that a component was shown. */ - public static final int COMPONENT_SHOWN = 102; - - /** This id indicates that a component was hidden. */ - public static final int COMPONENT_HIDDEN = 103; - - /** - * Initializes a new instance of <code>ComponentEvent</code> with the - * specified source and id. Note that an invalid id leads to unspecified - * results. - * - * @param source the source of the event - * @param id the event id - * @throws IllegalArgumentException if source is null - */ - public ComponentEvent(Component source, int id) - { - super(source, id); - } - - /** - * This method returns the event source as a <code>Component</code>. If the - * source has subsequently been modified to a non-Component, this returns - * null. - * - * @return the event source as a <code>Component</code>, or null - */ - public Component getComponent() - { - return source instanceof Component ? (Component) source : null; - } - - /** - * This method returns a string identifying this event. This is the field - * name of the id type, and for COMPONENT_MOVED or COMPONENT_RESIZED, the - * new bounding box of the component. - * - * @return a string identifying this event - */ - public String paramString() - { - // Unlike Sun, we don't throw NullPointerException or ClassCastException - // when source was illegally changed. - switch (id) - { - case COMPONENT_MOVED: - return "COMPONENT_MOVED " - + (source instanceof Component - ? ((Component) source).getBounds() : (Object) ""); - case COMPONENT_RESIZED: - return "COMPONENT_RESIZED " - + (source instanceof Component - ? ((Component) source).getBounds() : (Object) ""); - case COMPONENT_SHOWN: - return "COMPONENT_SHOWN"; - case COMPONENT_HIDDEN: - return "COMPONENT_HIDDEN"; - default: - return "unknown type"; - } - } -} // class ComponentEvent diff --git a/libjava/java/awt/event/ComponentListener.java b/libjava/java/awt/event/ComponentListener.java deleted file mode 100644 index b43faaed7ff..00000000000 --- a/libjava/java/awt/event/ComponentListener.java +++ /dev/null @@ -1,84 +0,0 @@ -/* ComponentListener.java -- receive all events for a component - Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.event; - -import java.util.EventListener; - -/** - * This interface is for classes that receive all events from a component. - * Normally it is not necessary to process these events since the AWT - * handles them internally, taking all appropriate actions. To watch a subset - * of these events, use a ComponentAdapter. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @see ComponentAdapter - * @see ComponentEvent - * @since 1.1 - * @status updated to 1.4 - */ -public interface ComponentListener extends EventListener -{ - /** - * This method is called when the component is resized. - * - * @param event the <code>ComponentEvent</code> indicating the resize - */ - void componentResized(ComponentEvent event); - - /** - * This method is called when the component is moved. - * - * @param event the <code>ComponentEvent</code> indicating the move - */ - void componentMoved(ComponentEvent event); - - /** - * This method is called when the component is made visible. - * - * @param event the <code>ComponentEvent</code> indicating the visibility - */ - void componentShown(ComponentEvent event); - - /** - * This method is called when the component is hidden. - * - * @param event the <code>ComponentEvent</code> indicating the visibility - */ - void componentHidden(ComponentEvent event); -} // interface ComponentListener diff --git a/libjava/java/awt/event/ContainerAdapter.java b/libjava/java/awt/event/ContainerAdapter.java deleted file mode 100644 index c847adfa211..00000000000 --- a/libjava/java/awt/event/ContainerAdapter.java +++ /dev/null @@ -1,79 +0,0 @@ -/* ContainerAdapter.java -- convenience class for writing container listeners - Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.event; - -/** - * This class implements <code>ContainerListener</code> and implements - * all methods with empty bodies. This allows a listener interested in - * implementing only a subset of the <code>ContainerListener</code> - * interface to extend this class and override only the desired methods. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @see ContainerEvent - * @see ContainerListener - * @since 1.1 - * @status updated to 1.4 - */ -public abstract class ContainerAdapter implements ContainerListener -{ - /** - * Do nothing default constructor for subclasses. - */ - public ContainerAdapter() - { - } - - /** - * Implements this method from the interface with an empty body. - * - * @param event the event, ignored in this implementation - */ - public void componentAdded(ContainerEvent event) - { - } - - /** - * Implements this method from the interface with an empty body. - * - * @param event the event, ignored in this implementation - */ - public void componentRemoved(ContainerEvent event) - { - } -} // class ContainerAdapter diff --git a/libjava/java/awt/event/ContainerEvent.java b/libjava/java/awt/event/ContainerEvent.java deleted file mode 100644 index 3c401fe1a04..00000000000 --- a/libjava/java/awt/event/ContainerEvent.java +++ /dev/null @@ -1,135 +0,0 @@ -/* ContainerEvent.java -- components added/removed from a container - Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.event; - -import java.awt.Component; -import java.awt.Container; - -/** - * This event is generated when a component is added or removed from a - * container. Applications do not ordinarily need to handle these events - * since the AWT system handles them internally. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @see ContainerAdapter - * @see ContainerListener - * @since 1.1 - * @status updated to 1.4 - */ -public class ContainerEvent extends ComponentEvent -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = -4114942250539772041L; - - /** This is the first id in the id range used by this class. */ - public static final int CONTAINER_FIRST = 300; - - /** This is the last id in the id range used by this class. */ - public static final int CONTAINER_LAST = 301; - - /** This id indicates a component was added to the container. */ - public static final int COMPONENT_ADDED = 300; - - /** This id indicates a component was removed from the container. */ - public static final int COMPONENT_REMOVED = 301; - - /** - * The non-null child component that was added or removed. - * - * @serial the child component that changed - */ - private final Component child; - - /** - * Initializes a new instance of <code>ContainerEvent</code> with the - * specified source and id. Additionally, the affected child component - * is also passed as a parameter. Note that an invalid id leads to - * unspecified results. - * - * @param source the source container of the event - * @param id the event id - * @param child the child component affected by this event - * @throws IllegalArgumentException if source is null - */ - public ContainerEvent(Component source, int id, Component child) - { - super(source, id); - this.child = child; - } - - /** - * Returns the source of this event as a <code>Container</code>. - * - * @return the source of the event - * @throws ClassCastException if the source is changed to a non-Container - */ - public Container getContainer() - { - return (Container) source; - } - - /** - * This method returns the child object that was added or removed from - * the container. - * - * @return the child object added or removed - */ - public Component getChild() - { - return child; - } - - /** - * This method returns a string identifying this event. It is formatted as: - * <code>(getID() == COMPONENT_ADDED ? "COMPONENT_ADDED" - * : "COMPONENT_REMOVED") + ",child=" + getChild().getName()</code>. - * - * @return a string identifying this event - */ - public String paramString() - { - // Unlike Sun, we don't throw NullPointerException if child is illegally - // null. - return (id == COMPONENT_ADDED ? "COMPONENT_ADDED,child=" - : id == COMPONENT_REMOVED ? "COMPONENT_REMOVED,child=" - : "unknown type,child=") + (child == null ? "" : child.getName()); - } -} // class ContainerEvent diff --git a/libjava/java/awt/event/ContainerListener.java b/libjava/java/awt/event/ContainerListener.java deleted file mode 100644 index b37d4340839..00000000000 --- a/libjava/java/awt/event/ContainerListener.java +++ /dev/null @@ -1,70 +0,0 @@ -/* ContainerListener.java -- listen for container events - Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.event; - -import java.util.EventListener; - -/** - * This interface is for classes that wish to listen for all events from - * container objects. This is normally not necessary since the AWT system - * listens for and processes these events. To watch a subset of these events, - * use a ContainerAdapter. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @see ContainerAdapter - * @see ContainerEvent - * @since 1.1 - * @status updated to 1.4 - */ -public interface ContainerListener extends EventListener -{ - /** - * This method is called when a component is added to the container. - * - * @param event the <code>ContainerEvent</code> indicating component addition - */ - void componentAdded(ContainerEvent event); - - /** - * This method is called when a component is removed from the container. - * - * @param event the <code>ContainerEvent</code> indicating component removal - */ - void componentRemoved(ContainerEvent event); -} // interface ContainerListener diff --git a/libjava/java/awt/event/FocusAdapter.java b/libjava/java/awt/event/FocusAdapter.java deleted file mode 100644 index fb0532a3a91..00000000000 --- a/libjava/java/awt/event/FocusAdapter.java +++ /dev/null @@ -1,79 +0,0 @@ -/* FocusAdapter.java -- convenience class for writing focus listeners - Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.event; - -/** - * This class implements <code>FocusListener</code> and implements all - * methods with empty bodies. This allows a listener interested in - * implementing only a subset of the <code>FocusListener</code> interface to - * extend this class and override only the desired methods. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @see FocusEvent - * @see FocusListener - * @since 1.1 - * @status updated to 1.4 - */ -public abstract class FocusAdapter implements FocusListener -{ - /** - * Do nothing default constructor for subclasses. - */ - public FocusAdapter() - { - } - - /** - * Implements this method from the interface with an empty body. - * - * @param event the event, ignored in this implementation - */ - public void focusGained(FocusEvent event) - { - } - - /** - * Implements this method from the interface with an empty body. - * - * @param event the event, ignored in this implementation - */ - public void focusLost(FocusEvent event) - { - } -} // class FocusAdapter diff --git a/libjava/java/awt/event/FocusEvent.java b/libjava/java/awt/event/FocusEvent.java deleted file mode 100644 index a44284aea75..00000000000 --- a/libjava/java/awt/event/FocusEvent.java +++ /dev/null @@ -1,181 +0,0 @@ -/* FocusEvent.java -- generated for a focus change - Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.event; - -import java.awt.Component; - -/** - * This class represents an event generated when a focus change occurs for a - * component. There are both temporary changes, such as when focus is stolen - * during a sroll then returned, and permanent changes, such as when the user - * TABs through focusable components. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @see FocusAdapter - * @see FocusListener - * @since 1.1 - * @status updated to 1.4 - */ -public class FocusEvent extends ComponentEvent -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = 523753786457416396L; - - /** This is the first id in the range of ids used by this class. */ - public static final int FOCUS_FIRST = 1004; - - /** This is the last id in the range of ids used by this class. */ - public static final int FOCUS_LAST = 1005; - - /** This is the event id for a focus gained event. */ - public static final int FOCUS_GAINED = 1004; - - /** This is the event id for a focus lost event. */ - public static final int FOCUS_LOST = 1005; - - /** - * Indicates whether or not the focus change is temporary. - * - * @see #isTemporary() - * @serial true if the focus change is temporary - */ - private final boolean temporary; - - /** - * The other component which is giving up or stealing focus from this - * component, if known. - * - * @see #getOppositeComponent() - * @serial the component with the opposite focus event, or null - * @since 1.4 - */ - private final Component opposite; - - /** - * Initializes a new instance of <code>FocusEvent</code> with the - * specified source, id, temporary status, and opposite counterpart. Note - * that an invalid id leads to unspecified results. - * - * @param source the component that is gaining or losing focus - * @param id the event id - * @param temporary true if the focus change is temporary - * @param opposite the component receiving the opposite focus event, or null - * @throws IllegalArgumentException if source is null - */ - public FocusEvent(Component source, int id, boolean temporary, - Component opposite) - { - super(source, id); - this.temporary = temporary; - this.opposite = opposite; - } - - /** - * Initializes a new instance of <code>FocusEvent</code> with the - * specified source, id, and temporary status. Note that an invalid id - * leads to unspecified results. - * - * @param source the component that is gaining or losing focus - * @param id the event id - * @param temporary true if the focus change is temporary - * @throws IllegalArgumentException if source is null - */ - public FocusEvent(Component source, int id, boolean temporary) - { - this(source, id, temporary, null); - } - - /** - * Initializes a new instance of <code>FocusEvent</code> with the - * specified source and id. Note that an invalid id leads to unspecified - * results. - * - * @param source the component that is gaining or losing focus - * @param id the event id - * @throws IllegalArgumentException if source is null - */ - public FocusEvent(Component source, int id) - { - this(source, id, false, null); - } - - /** - * This method tests whether or not the focus change is temporary or - * permanent. - * - * @return true if the focus change is temporary - */ - public boolean isTemporary() - { - return temporary; - } - - /** - * Returns the component which received the opposite focus event. If this - * component gained focus, the opposite lost focus; likewise if this - * component is giving up focus, the opposite is gaining it. If this - * information is unknown, perhaps because the opposite is a native - * application, this returns null. - * - * @return the component with the focus opposite, or null - * @since 1.4 - */ - public Component getOppositeComponent() - { - return opposite; - } - - /** - * Returns a string identifying this event. This is formatted as: - * <code>(getID() == FOCUS_GAINED ? "FOCUS_GAINED" : "FOCUS_LOST") - * + (isTemporary() ? ",temporary," : ",permanent,") + "opposite=" - * + getOppositeComponent()</code>. - * - * @return a string identifying this event - */ - public String paramString() - { - return (id == FOCUS_GAINED ? "FOCUS_GAINED" - : id == FOCUS_LOST ? "FOCUS_LOST" : "unknown type") - + (temporary ? ",temporary,opposite=" : ",permanent,opposite=") - + opposite; - } -} // class FocusEvent diff --git a/libjava/java/awt/event/FocusListener.java b/libjava/java/awt/event/FocusListener.java deleted file mode 100644 index 1f7201825a7..00000000000 --- a/libjava/java/awt/event/FocusListener.java +++ /dev/null @@ -1,69 +0,0 @@ -/* FocusListener.java -- listen for focus changes - Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.event; - -import java.util.EventListener; - -/** - * This interface is for classes that wish to be notified of changes of - * keyboard focus for a component. To watch a subset of these events, use a - * FocusAdapter. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @see FocusAdapter - * @see FocusEvent - * @since 1.1 - * @status updated to 1.4 - */ -public interface FocusListener extends EventListener -{ - /** - * This method is called when a component gains the keyboard focus. - * - * @param event the <code>FocusEvent</code> indicating that focus was gained - */ - void focusGained(FocusEvent event); - - /** - * This method is invoked when a component loses the keyboard focus. - * - * @param event the <code>FocusEvent</code> indicating that focus was lost - */ - void focusLost(FocusEvent event); -} // interface FocusListener diff --git a/libjava/java/awt/event/HierarchyBoundsAdapter.java b/libjava/java/awt/event/HierarchyBoundsAdapter.java deleted file mode 100644 index 340cf01edf1..00000000000 --- a/libjava/java/awt/event/HierarchyBoundsAdapter.java +++ /dev/null @@ -1,78 +0,0 @@ -/* HierarchyBoundsAdapter.java -- convenience class for writing listeners - Copyright (C) 2000, 2002 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.awt.event; - -/** - * This class implements <code>HierarchyBoundsListener</code> and implements - * all methods with empty bodies. This allows a listener interested in - * implementing only a subset of the <code>HierarchyBoundsListener</code> - * interface to extend this class and override only the desired methods. - * - * @author Bryce McKinlay - * @see HierarchyBoundsListener - * @see HierarchyEvent - * @since 1.3 - * @status updated to 1.4 - */ -public abstract class HierarchyBoundsAdapter implements HierarchyBoundsListener -{ - /** - * Do nothing default constructor for subclasses. - */ - public HierarchyBoundsAdapter() - { - } - - /** - * Implements this method from the interface with an empty body. - * - * @param event the event, ignored in this implementation - */ - public void ancestorMoved(HierarchyEvent event) - { - } - - /** - * Implements this method from the interface with an empty body. - * - * @param event the event, ignored in this implementation - */ - public void ancestorResized(HierarchyEvent event) - { - } -} diff --git a/libjava/java/awt/event/HierarchyBoundsListener.java b/libjava/java/awt/event/HierarchyBoundsListener.java deleted file mode 100644 index 689623744e3..00000000000 --- a/libjava/java/awt/event/HierarchyBoundsListener.java +++ /dev/null @@ -1,70 +0,0 @@ -/* HierarchyBoundsListener.java -- listens to bounds changes of parents - Copyright (C) 2000, 2002 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.event; - -import java.util.EventListener; - -/** - * This listens for changes in an ancestors size or location. Normally it is - * not necessary to process these events since the AWT handles them - * internally, taking all appropriate actions. To watch a subset of these - * events, use a HierarchyBoundsAdapter. - * - * @author Bryce McKinlay - * @see HierarchyBoundsAdapter - * @see HierarchyEvent - * @since 1.3 - * @status updated to 1.4 - */ -public interface HierarchyBoundsListener extends EventListener -{ - /** - * Called when an ancestor component of the source is moved. - * - * @param e the event describing the ancestor's motion - */ - void ancestorMoved(HierarchyEvent e); - - /** - * Called when an ancestor component is resized. - * - * @param e the event describing the ancestor's resizing - */ - void ancestorResized(HierarchyEvent e); -} // interface HierarchyBoundsListener diff --git a/libjava/java/awt/event/HierarchyEvent.java b/libjava/java/awt/event/HierarchyEvent.java deleted file mode 100644 index e10cefbefcb..00000000000 --- a/libjava/java/awt/event/HierarchyEvent.java +++ /dev/null @@ -1,253 +0,0 @@ -/* HierarchyEvent.java -- generated for a change in hierarchy - Copyright (C) 2000, 2002 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.event; - -import java.awt.AWTEvent; -import java.awt.Component; -import java.awt.Container; - -/** - * This class represents an event generated for an ancestor component which - * may affect this component. These events normally do not need to be handled - * by the application, since the AWT system automatically takes care of them. - * - * <p>There are two types of hierarchy events. The first type is handled by - * HierarchyListener, and includes addition or removal of an ancestor, or - * an ancestor changing its on-screen status (visible and/or displayble). The - * second type is handled by HierarchyBoundsListener, and includes resizing - * or moving of an ancestor. - * - * @author Bryce McKinlay - * @see HierarchyListener - * @see HierarchyBoundsAdapter - * @see HierarchyBoundsListener - * @since 1.3 - * @status updated to 1.4 - */ -public class HierarchyEvent extends AWTEvent -{ - /** - * Compatible with JDK 1.3+. - */ - private static final long serialVersionUID = -5337576970038043990L; - - /** This is the first id in the range of ids used by this class. */ - public static final int HIERARCHY_FIRST = 1400; - - /** This id indicates that the hierarchy tree changed. */ - public static final int HIERARCHY_CHANGED = 1400; - - /** This id indicates that an ancestor was moved. */ - public static final int ANCESTOR_MOVED = 1401; - - /** This id indicates that an ancestor was resized. */ - public static final int ANCESTOR_RESIZED = 1402; - - /** This is the last id in the range of ids used by this class. */ - public static final int HIERARCHY_LAST = 1402; - - /** This indicates that the HIERARCHY_CHANGED is a changed parent. */ - public static final int PARENT_CHANGED = 1; - - /** - * This indicates that the HIERARCHY_CHANGED is caused by a change in - * displayability. - * - * @see Component#isDisplayable() - * @see Component#addNotify() - * @see Component#removeNotify() - */ - public static final int DISPLAYABILITY_CHANGED = 2; - - /** - * This indicates that the HIERARCHY_CHANGED is a changed visibility. - * - * @see Component#isShowing() - * @see Component#addNotify() - * @see Component#removeNotify() - * @see Component#show() - * @see Component#hide() - */ - public static final int SHOWING_CHANGED = 4; - - /** - * The component at the top of the changed hierarchy. - * - * @serial the top component changed - */ - private final Component changed; - - /** - * The parent of this component, either before or after the change depending - * on the type of change. - * - * @serial the parent component changed - */ - private final Container changedParent; - - /** - * The bitmask of HIERARCHY_CHANGED event types. - * - * @serial the change flags - */ - private final long changeFlags; - - /** - * Initializes a new instance of <code>HierarchyEvent</code> with the - * specified parameters. Note that an invalid id leads to unspecified - * results. - * - * @param source the component whose hierarchy changed - * @param id the event id - * @param changed the top component in the tree of changed hierarchy - * @param changedParent the updated parent of this object - * @throws IllegalArgumentException if source is null - */ - public HierarchyEvent(Component source, int id, Component changed, - Container changedParent) - { - this(source, id, changed, changedParent, 0); - } - - /** - * Initializes a new instance of <code>HierarchyEvent</code> with the - * specified parameters. Note that an invalid id leads to unspecified - * results. - * - * @param source the component whose hierarchy changed - * @param id the event id - * @param changed the top component in the tree of changed hierarchy - * @param changedParent the updated parent of this object - * @param changeFlags the bitmask of specific HIERARCHY_CHANGED events - * @throws IllegalArgumentException if source is null - */ - public HierarchyEvent(Component source, int id, Component changed, - Container changedParent, long changeFlags) - { - super(source, id); - this.changed = changed; - this.changedParent = changedParent; - this.changeFlags = changeFlags; - } - - /** - * This method returns the event source as a <code>Component</code>. If the - * source has subsequently been modified to a non-Component, this returns - * null. - * - * @return the event source as a <code>Component</code>, or null - */ - public Component getComponent() - { - return source instanceof Component ? (Component) source : null; - } - - /** - * Returns the component at the top of the hierarchy which changed. - * - * @return the top changed component - */ - public Component getChanged() - { - return changed; - } - - /** - * Returns the parent of the component listed in <code>getChanged()</code>. - * If the cause of this event was <code>Container.add</code>, this is the - * new parent; if the cause was <code>Container.remove</code>, this is the - * old parent; otherwise it is the unchanged parent. - * - * @return the parent container of the changed component - */ - public Container getChangedParent() - { - return changedParent; - } - - /** - * If this is a HIERARCHY_CHANGED event, this returns a bitmask of the - * types of changes that took place. - * - * @return the bitwise or of hierarchy change types, or 0 - * @see #PARENT_CHANGED - * @see #DISPLAYABILITY_CHANGED - * @see #SHOWING_CHANGED - */ - public long getChangeFlags() - { - return changeFlags; - } - - /** - * This method returns a string identifying this event. This is the field - * name of the id type, followed by a parenthesized listing of the changed - * component and its parent container. In addition, if the type is - * HIERARCHY_CHANGED, the flags preceed the changed component, in the - * order PARENT_CHANGED, DISPLAYABILITY_CHANGED, and SHOWING_CHANGED. - * - * @return a string identifying this event - */ - public String paramString() - { - StringBuffer r = new StringBuffer(); - switch (id) - { - case HIERARCHY_CHANGED: - r.append("HIERARCHY_CHANGED ("); - if ((changeFlags & PARENT_CHANGED) != 0) - r.append("PARENT_CHANGED,"); - if ((changeFlags & DISPLAYABILITY_CHANGED) != 0) - r.append("DISPLAYABILITY_CHANGED,"); - if ((changeFlags & SHOWING_CHANGED) != 0) - r.append("SHOWING_CHANGED,"); - break; - case ANCESTOR_MOVED: - r.append("ANCESTOR_MOVED ("); - break; - case ANCESTOR_RESIZED: - r.append("ANCESTOR_RESIZED ("); - break; - default: - return "unknown type"; - } - r.append(changed).append(',').append(changedParent).append(')'); - return r.toString(); - } -} // class HierarchyEvent diff --git a/libjava/java/awt/event/HierarchyListener.java b/libjava/java/awt/event/HierarchyListener.java deleted file mode 100644 index f90414b866b..00000000000 --- a/libjava/java/awt/event/HierarchyListener.java +++ /dev/null @@ -1,62 +0,0 @@ -/* HierarchyListener.java -- listens to changes in the component hierarchy - Copyright (C) 2000, 2002 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.event; - -import java.util.EventListener; - -/** - * This listens for changes in the hierarchy tree of components. Normally it is - * not necessary to process these events since the AWT handles them - * internally, taking all appropriate actions. - * - * @author Bryce McKinlay - * @see HierarchyEvent - * @since 1.3 - * @status updated to 1.4 - */ -public interface HierarchyListener extends EventListener -{ - /** - * Called when the hierarchy of this component changes. Use - * <code>getChangeFlags()</code> on the event to see what exactly changed. - * - * @param e the event describing the change - */ - void hierarchyChanged(HierarchyEvent e); -} // interface HierarchyListener diff --git a/libjava/java/awt/event/InputEvent.java b/libjava/java/awt/event/InputEvent.java deleted file mode 100644 index 8f9aed611f8..00000000000 --- a/libjava/java/awt/event/InputEvent.java +++ /dev/null @@ -1,381 +0,0 @@ -/* InputEvent.java -- common superclass of component input events - Copyright (C) 1999, 2002, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.event; - -import gnu.java.awt.EventModifier; - -import java.awt.Component; - -/** - * This is the common superclass for all component input classes. These are - * passed to listeners before the component, so that listeners can consume - * the event before it does its default behavior. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @see KeyEvent - * @see KeyAdapter - * @see MouseEvent - * @see MouseAdapter - * @see MouseMotionAdapter - * @see MouseWheelEvent - * @since 1.1 - * @status updated to 1.4 - */ -public abstract class InputEvent extends ComponentEvent -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = -2482525981698309786L; - - /** - * This is the bit mask which indicates the shift key is down. It is - * recommended that SHIFT_DOWN_MASK be used instead. - * - * @see #SHIFT_DOWN_MASK - */ - public static final int SHIFT_MASK = 1; - - /** - * This is the bit mask which indicates the control key is down. It is - * recommended that CTRL_DOWN_MASK be used instead. - * - * @see #CTRL_DOWN_MASK - */ - public static final int CTRL_MASK = 2; - - /** - * This is the bit mask which indicates the meta key is down. It is - * recommended that META_DOWN_MASK be used instead. - * - * @see #META_DOWN_MASK - */ - public static final int META_MASK = 4; - - /** - * This is the bit mask which indicates the alt key is down. It is - * recommended that ALT_DOWN_MASK be used instead. - * - * @see #ALT_DOWN_MASK - */ - public static final int ALT_MASK = 8; - - /** - * This is the bit mask which indicates the alt-graph modifier is in effect. - * It is recommended that ALT_GRAPH_DOWN_MASK be used instead. - * - * @see #ALT_GRAPH_DOWN_MASK - */ - public static final int ALT_GRAPH_MASK = 0x20; - - /** - * This bit mask indicates mouse button one is down. It is recommended that - * BUTTON1_DOWN_MASK be used instead. - * - * @see #BUTTON1_DOWN_MASK - */ - public static final int BUTTON1_MASK = 0x10; - - /** - * This bit mask indicates mouse button two is down. It is recommended that - * BUTTON2_DOWN_MASK be used instead. - * - * @see #BUTTON2_DOWN_MASK - */ - public static final int BUTTON2_MASK = 8; - - /** - * This bit mask indicates mouse button three is down. It is recommended - * that BUTTON3_DOWN_MASK be used instead. - * - * @see #BUTTON3_DOWN_MASK - */ - public static final int BUTTON3_MASK = 4; - - /** - * The SHIFT key extended modifier. - * - * @since 1.4 - */ - public static final int SHIFT_DOWN_MASK = 0x0040; - - /** - * The CTRL key extended modifier. - * - * @since 1.4 - */ - public static final int CTRL_DOWN_MASK = 0x0080; - - /** - * The META key extended modifier. - * - * @since 1.4 - */ - public static final int META_DOWN_MASK = 0x0100; - - /** - * The ALT key extended modifier. - * - * @since 1.4 - */ - public static final int ALT_DOWN_MASK = 0x0200; - - /** - * The mouse button1 key extended modifier. - * - * @since 1.4 - */ - public static final int BUTTON1_DOWN_MASK = 0x0400; - - /** - * The mouse button2 extended modifier. - * - * @since 1.4 - */ - public static final int BUTTON2_DOWN_MASK = 0x0800; - - /** - * The mouse button3 extended modifier. - * - * @since 1.4 - */ - public static final int BUTTON3_DOWN_MASK = 0x1000; - - /** - * The ALT_GRAPH key extended modifier. - * - * @since 1.4 - */ - public static final int ALT_GRAPH_DOWN_MASK = 0x2000; - - /** The mask to convert new to old, package visible for use in subclasses. */ - static final int CONVERT_MASK - = EventModifier.NEW_MASK & ~(BUTTON2_DOWN_MASK | BUTTON3_DOWN_MASK); - - /** - * The timestamp when this event occurred. - * - * @see #getWhen() - * @serial the timestamp - */ - private final long when; - - /** - * The modifiers in effect for this event. Package visible for use by - * subclasses. The old style (bitmask 0x3f) should not be mixed with the - * new style (bitmasks 0xffffffc0). - * - * @see #getModifiers() - * @see MouseEvent - * @serial the modifier state, stored in the new style - */ - int modifiers; - - /** - * Initializes a new instance of <code>InputEvent</code> with the specified - * source, id, timestamp, and modifiers. Note that an invalid id leads to - * unspecified results. - * - * @param source the source of the event - * @param id the event id - * @param when the timestamp when the event occurred - * @param modifiers the modifiers in effect for this event, old or new style - * @throws IllegalArgumentException if source is null - */ - InputEvent(Component source, int id, long when, int modifiers) - { - super(source, id); - this.when = when; - this.modifiers = EventModifier.extend(modifiers); - } - - /** - * This method tests whether or not the shift key was down during the event. - * - * @return true if the shift key is down - */ - public boolean isShiftDown() - { - return (modifiers & SHIFT_DOWN_MASK) != 0; - } - - /** - * This method tests whether or not the control key was down during the - * event. - * - * @return true if the control key is down - */ - public boolean isControlDown() - { - return (modifiers & CTRL_DOWN_MASK) != 0; - } - - /** - * This method tests whether or not the meta key was down during the event. - * - * @return true if the meta key is down - */ - public boolean isMetaDown() - { - return (modifiers & META_DOWN_MASK) != 0; - } - - /** - * This method tests whether or not the alt key was down during the event. - * - * @return true if the alt key is down - */ - public boolean isAltDown() - { - return (modifiers & ALT_DOWN_MASK) != 0; - } - - /** - * This method tests whether or not the alt-graph modifier was in effect - * during the event. - * - * @return true if the alt-graph modifier is down - */ - public boolean isAltGraphDown() - { - return (modifiers & ALT_GRAPH_DOWN_MASK) != 0; - } - - /** - * This method returns the timestamp when this event occurred. - * - * @return the timestamp when this event occurred - */ - public long getWhen() - { - return when; - } - - /** - * This method returns the old-style modifiers in effect for this event. - * Note that this is ambiguous between button2 and alt, and between - * button3 and meta. Also, code which generated these modifiers tends to - * only list the modifier that just changed, even if others were down at - * the time. Consider using getModifiersEx instead. This will be a union - * of the bit masks defined in this class that are applicable to the event. - * - * @return the modifiers in effect for this event - * @see #getModifiersEx() - */ - public int getModifiers() - { - return EventModifier.revert(modifiers); - } - - /** - * Returns the extended modifiers (new-style) for this event. This represents - * the state of all modal keys and mouse buttons at the time of the event, - * and does not suffer from the problems mentioned in getModifiers. - * - * <p>For an example of checking multiple modifiers, this code will return - * true only if SHIFT and BUTTON1 were pressed and CTRL was not: - * <pre> - * int onmask = InputEvent.SHIFT_DOWN_MASK | InputEvent.BUTTON1_DOWN_MASK; - * int offmask = InputEvent.CTRL_DOWN_MASK; - * return (event.getModifiersEx() & (onmask | offmask)) == onmask; - * </pre> - * - * @return the bitwise or of all modifiers pressed during the event - * @since 1.4 - */ - public int getModifiersEx() - { - return modifiers; - } - - /** - * Consumes this event. A consumed event is not processed further by the AWT - * system. - */ - public void consume() - { - consumed = true; - } - - /** - * This method tests whether or not this event has been consumed. - * - * @return true if this event has been consumed - */ - public boolean isConsumed() - { - return consumed; - } - - /** - * Convert the extended modifier bitmask into a String, such as "Shift" or - * "Ctrl+Button1". - * - * XXX Sun claims this can be localized via the awt.properties file - how - * do we implement that? - * - * @param modifiers the modifiers - * @return a string representation of the modifiers in this bitmask - * @since 1.4 - */ - public static String getModifiersExText(int modifiers) - { - modifiers &= EventModifier.NEW_MASK; - if (modifiers == 0) - return ""; - StringBuffer s = new StringBuffer(); - if ((modifiers & META_DOWN_MASK) != 0) - s.append("Meta+"); - if ((modifiers & CTRL_DOWN_MASK) != 0) - s.append("Ctrl+"); - if ((modifiers & ALT_DOWN_MASK) != 0) - s.append("Alt+"); - if ((modifiers & SHIFT_DOWN_MASK) != 0) - s.append("Shift+"); - if ((modifiers & ALT_GRAPH_DOWN_MASK) != 0) - s.append("Alt Graph+"); - if ((modifiers & BUTTON1_DOWN_MASK) != 0) - s.append("Button1+"); - if ((modifiers & BUTTON2_DOWN_MASK) != 0) - s.append("Button2+"); - if ((modifiers & BUTTON3_DOWN_MASK) != 0) - s.append("Button3+"); - return s.substring(0, s.length() - 1); - } -} // class InputEvent diff --git a/libjava/java/awt/event/InputMethodEvent.java b/libjava/java/awt/event/InputMethodEvent.java deleted file mode 100644 index f6711a8fa5a..00000000000 --- a/libjava/java/awt/event/InputMethodEvent.java +++ /dev/null @@ -1,303 +0,0 @@ -/* InputMethodEvent.java -- events from a text input method - Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.event; - -import java.awt.AWTEvent; -import java.awt.Component; -import java.awt.EventQueue; -import java.awt.font.TextHitInfo; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.text.AttributedCharacterIterator; - -/** - * This class is for event generated by change in a text input method. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @see InputMethodListener - * @since 1.2 - * @status updated to 1.4 - */ -public class InputMethodEvent extends AWTEvent -{ - /** - * Compatible with JDK 1.2+. - */ - private static final long serialVersionUID = 4727190874778922661L; - - /** This is the first id in the range of event ids used by this class. */ - public static final int INPUT_METHOD_FIRST = 1100; - - /** This event id indicates that the text in the input method has changed. */ - public static final int INPUT_METHOD_TEXT_CHANGED = 1100; - - /** This event id indicates that the input method curor point has changed. */ - public static final int CARET_POSITION_CHANGED = 1101; - - /** This is the last id in the range of event ids used by this class. */ - public static final int INPUT_METHOD_LAST = 1101; - - /** - * The timestamp when this event was created. - * - * @serial the timestamp - * @since 1.4 - */ - private long when; - - /** The input method text. */ - private final transient AttributedCharacterIterator text; - - /** The number of committed characters in the text. */ - private final transient int committedCharacterCount; - - /** The caret. */ - private final transient TextHitInfo caret; - - /** The most important position to be visible. */ - private final transient TextHitInfo visiblePosition; - - /** - * Initializes a new instance of <code>InputMethodEvent</code> with the - * specified source, id, timestamp, text, char count, caret, and visible - * position. - * - * @param source the source that generated the event - * @param id the event id - * @param when the timestamp of the event - * @param text the input text - * @param committedCharacterCount the number of committed characters - * @param caret the caret position - * @param visiblePosition the position most important to make visible - * @throws IllegalArgumentException if source is null, id is invalid, id is - * CARET_POSITION_CHANGED and text is non-null, or if - * committedCharacterCount is out of range - * @since 1.4 - */ - public InputMethodEvent(Component source, int id, long when, - AttributedCharacterIterator text, - int committedCharacterCount, TextHitInfo caret, - TextHitInfo visiblePosition) - { - super(source, id); - this.when = when; - this.text = text; - this.committedCharacterCount = committedCharacterCount; - this.caret = caret; - this.visiblePosition = visiblePosition; - if (id < INPUT_METHOD_FIRST || id > INPUT_METHOD_LAST - || (id == CARET_POSITION_CHANGED && text != null) - || committedCharacterCount < 0 - || (committedCharacterCount - > (text == null ? 0 : text.getEndIndex() - text.getBeginIndex()))) - throw new IllegalArgumentException(); - } - - /** - * Initializes a new instance of <code>InputMethodEvent</code> with the - * specified source, id, text, char count, caret, and visible position. - * - * @param source the source that generated the event - * @param id the event id - * @param text the input text - * @param committedCharacterCount the number of committed characters - * @param caret the caret position - * @param visiblePosition the position most important to make visible - * @throws IllegalArgumentException if source is null, id is invalid, id is - * CARET_POSITION_CHANGED and text is non-null, or if - * committedCharacterCount is out of range - * @since 1.4 - */ - public InputMethodEvent(Component source, int id, - AttributedCharacterIterator text, - int committedCharacterCount, TextHitInfo caret, - TextHitInfo visiblePosition) - { - this(source, id, EventQueue.getMostRecentEventTime(), text, - committedCharacterCount, caret, visiblePosition); - } - - /** - * Initializes a new instance of <code>InputMethodEvent</code> with the - * specified source, id, caret, and visible position, and with a null - * text and char count. - * - * @param source the source that generated the event - * @param id the event id - * @param caret the caret position - * @param visiblePosition the position most important to make visible - * @throws IllegalArgumentException if source is null or id is invalid - * @since 1.4 - */ - public InputMethodEvent(Component source, int id, TextHitInfo caret, - TextHitInfo visiblePosition) - { - this(source, id, EventQueue.getMostRecentEventTime(), null, 0, caret, - visiblePosition); - } - - /** - * This method returns the input method text. This can be <code>null</code>, - * and will always be null for <code>CARET_POSITION_CHANGED</code> events. - * Characters from 0 to <code>getCommittedCharacterCount()-1</code> have - * been committed, the remaining characters are composed text. - * - * @return the input method text, or null - */ - public AttributedCharacterIterator getText() - { - return text; - } - - /** - * Returns the number of committed characters in the input method text. - * - * @return the number of committed characters in the input method text - */ - public int getCommittedCharacterCount() - { - return committedCharacterCount; - } - - /** - * Returns the caret position. The caret offset is relative to the composed - * text of the most recent <code>INPUT_METHOD_TEXT_CHANGED</code> event. - * - * @return the caret position, or null - */ - public TextHitInfo getCaret() - { - return caret; - } - - /** - * Returns the position that is most important to be visible, or null if - * such a hint is not necessary. The caret offset is relative to the composed - * text of the most recent <code>INPUT_METHOD_TEXT_CHANGED</code> event. - * - * @return the position that is most important to be visible - */ - public TextHitInfo getVisiblePosition() - { - return visiblePosition; - } - - /** - * This method consumes the event. A consumed event is not processed - * in the default manner by the component that generated it. - */ - public void consume() - { - consumed = true; - } - - /** - * This method tests whether or not this event has been consumed. - * - * @return true if the event has been consumed - */ - public boolean isConsumed() - { - return consumed; - } - - /** - * Return the timestamp of this event. - * - * @return the timestamp - * @since 1.4 - */ - public long getWhen() - { - return when; - } - - /** - * This method returns a string identifying the event. This contains the - * event ID, the committed and composed characters separated by '+', the - * number of committed characters, the caret, and the visible position. - * - * @return a string identifying the event - */ - public String paramString() - { - StringBuffer s - = new StringBuffer(80 + (text == null ? 0 - : text.getEndIndex() - text.getBeginIndex())); - s.append(id == INPUT_METHOD_TEXT_CHANGED ? "INPUT_METHOD_TEXT_CHANGED, " - : "CARET_POSITION_CHANGED, "); - if (text == null) - s.append("no text, 0 characters committed, caret: "); - else - { - s.append('"'); - int i = text.getBeginIndex(); - int j = committedCharacterCount; - while (--j >= 0) - s.append(text.setIndex(i++)); - s.append("\" + \""); - j = text.getEndIndex() - i; - while (--j >= 0) - s.append(text.setIndex(i++)); - s.append("\", ").append(committedCharacterCount) - .append(" characters committed, caret: "); - } - s.append(caret == null ? (Object) "no caret" : caret).append(", ") - .append(visiblePosition == null ? (Object) "no visible position" - : visiblePosition); - return s.toString(); - } - - /** - * Reads in the object from a serial stream, updating when to - * {@link EventQueue#getMostRecentEventTime()} if necessary. - * - * @param s the stream to read from - * @throws IOException if deserialization fails - * @throws ClassNotFoundException if deserialization fails - * @serialData default, except for updating when - */ - private void readObject(ObjectInputStream s) - throws IOException, ClassNotFoundException - { - s.defaultReadObject(); - if (when == 0) - when = EventQueue.getMostRecentEventTime(); - } -} // class InputMethodEvent diff --git a/libjava/java/awt/event/InputMethodListener.java b/libjava/java/awt/event/InputMethodListener.java deleted file mode 100644 index 8baf022983a..00000000000 --- a/libjava/java/awt/event/InputMethodListener.java +++ /dev/null @@ -1,69 +0,0 @@ -/* InputMethodListener.java -- listen for input method events - Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.event; - -import java.util.EventListener; - -/** - * This interface is for classes that wish to receive events from an input - * method. For a text component to use input methods, it must also install - * an InputMethodRequests handler. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @see InputMethodEvent - * @see InputMethodRequests - * @since 1.2 - * @status updated to 1.4 - */ -public interface InputMethodListener extends EventListener -{ - /** - * This method is called when the text is changed. - * - * @param event the <code>InputMethodEvent</code> indicating the text change - */ - void inputMethodTextChanged(InputMethodEvent event); - - /** - * This method is called when the cursor position within the text is changed. - * - * @param event the <code>InputMethodEvent</code> indicating the change - */ - void caretPositionChanged(InputMethodEvent event); -} // interface InputMethodListener diff --git a/libjava/java/awt/event/InvocationEvent.java b/libjava/java/awt/event/InvocationEvent.java deleted file mode 100644 index 75feb62bd94..00000000000 --- a/libjava/java/awt/event/InvocationEvent.java +++ /dev/null @@ -1,237 +0,0 @@ -/* InvocationEvent.java -- call a runnable when dispatched - Copyright (C) 1999, 2002, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.event; - -import java.awt.AWTEvent; -import java.awt.ActiveEvent; -import java.awt.EventQueue; - -/** - * This event executes {@link Runnable#run()} of a target object when it is - * dispatched. This class is used by calls to <code>invokeLater</code> and - * <code>invokeAndWait</code>, so client code can use this fact to avoid - * writing special-casing AWTEventListener objects. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @see ActiveEvent - * @see EventQueue#invokeLater(Runnable) - * @see EventQueue#invokeAndWait(Runnable) - * @see AWTEventListener - * @since 1.2 - * @status updated to 1.4 - */ -public class InvocationEvent extends AWTEvent implements ActiveEvent -{ - /** - * Compatible with JDK 1.2+. - */ - private static final long serialVersionUID = 436056344909459450L; - - /** This is the first id in the range of event ids used by this class. */ - public static final int INVOCATION_FIRST = 1200; - - /** This is the default id for this event type. */ - public static final int INVOCATION_DEFAULT = 1200; - - /** This is the last id in the range of event ids used by this class. */ - public static final int INVOCATION_LAST = 1200; - - /** - * This is the <code>Runnable</code> object to call when dispatched. - * - * @serial the runnable to execute - */ - protected Runnable runnable; - - /** - * This is the object to call <code>notifyAll()</code> on when - * the call to <code>run()</code> returns, or <code>null</code> if no - * object is to be notified. - * - * @serial the object to notify - */ - protected Object notifier; - - /** - * This variable is set to <code>true</code> if exceptions are caught - * and stored in a variable during the call to <code>run()</code>, otherwise - * exceptions are ignored and propagate up. - * - * @serial true to catch exceptions - */ - protected boolean catchExceptions; - - /** - * This is the caught exception thrown in the <code>run()</code> method. It - * is null if exceptions are ignored, the run method hasn't completed, or - * there were no exceptions. - * - * @serial the caught exception, if any - */ - private Exception exception; - - /** - * The timestamp when this event was created. - * - * @see #getWhen() - * @serial the timestamp - * @since 1.4 - */ - private final long when = EventQueue.getMostRecentEventTime(); - - /** - * Initializes a new instance of <code>InvocationEvent</code> with the - * specified source and runnable. - * - * @param source the source of the event - * @param runnable the <code>Runnable</code> object to invoke - * @throws IllegalArgumentException if source is null - */ - public InvocationEvent(Object source, Runnable runnable) - { - this(source, INVOCATION_DEFAULT, runnable, null, false); - } - - /** - * Initializes a new instance of <code>InvocationEvent</code> with the - * specified source, runnable, and notifier. It will also catch exceptions - * if specified. If notifier is non-null, this will call notifyAll() on - * the object when the runnable is complete. If catchExceptions is true, - * this traps any exception in the runnable, otherwise it lets the exception - * propagate up the Event Dispatch thread. - * - * @param source the source of the event - * @param runnable the <code>Runnable</code> object to invoke - * @param notifier the object to notify, or null - * @param catchExceptions true to catch exceptions from the runnable - */ - public InvocationEvent(Object source, Runnable runnable, Object notifier, - boolean catchExceptions) - { - this(source, INVOCATION_DEFAULT, runnable, notifier, catchExceptions); - } - - /** - * Initializes a new instance of <code>InvocationEvent</code> with the - * specified source, runnable, and notifier. It will also catch exceptions - * if specified. If notifier is non-null, this will call notifyAll() on - * the object when the runnable is complete. If catchExceptions is true, - * this traps any exception in the runnable, otherwise it lets the exception - * propagate up the Event Dispatch thread. Note that an invalid id leads to - * unspecified results. - * - * @param source the source of the event - * @param id the event id - * @param runnable the <code>Runnable</code> object to invoke - * @param notifier the object to notify, or null - * @param catchExceptions true to catch exceptions from the runnable - */ - protected InvocationEvent(Object source, int id, Runnable runnable, - Object notifier, boolean catchExceptions) - { - super(source, id); - this.runnable = runnable; - this.notifier = notifier; - this.catchExceptions = catchExceptions; - } - - /** - * This method calls the <code>run()</code> method of the runnable, traps - * exceptions if instructed to do so, and calls <code>notifyAll()</code> - * on any notifier if all worked successfully. - */ - public void dispatch() - { - if (catchExceptions) - try - { - runnable.run(); - } - catch (Exception e) - { - exception = e; - } - else - runnable.run(); - - Object o = notifier; - if (o != null) - synchronized(o) - { - o.notifyAll(); - } - } - - /** - * This method returns the exception that occurred during the execution of - * the runnable, or <code>null</code> if not exception was thrown or - * exceptions were not caught. - * - * @return the exception thrown by the runnable - */ - public Exception getException() - { - return exception; - } - - /** - * Gets the timestamp of when this event was created. - * - * @return the timestamp of this event - * @since 1.4 - */ - public long getWhen() - { - return when; - } - - /** - * This method returns a string identifying this event. This is formatted as: - * <code>"INVOCATION_DEFAULT,runnable=" + runnable + ",notifier=" + notifier - * + ",catchExceptions=" + catchExceptions + ",when=" + getWhen()</code>. - * - * @return a string identifying this event - */ - public String paramString() - { - return (id == INVOCATION_DEFAULT ? "INVOCATION_DEFAULT,runnable=" - : "unknown type,runnable=") + runnable + ",notifier=" + notifier - + ",catchExceptions=" + catchExceptions + ",when=" + when; - } -} // class InvocationEvent diff --git a/libjava/java/awt/event/ItemEvent.java b/libjava/java/awt/event/ItemEvent.java deleted file mode 100644 index 467815b1608..00000000000 --- a/libjava/java/awt/event/ItemEvent.java +++ /dev/null @@ -1,155 +0,0 @@ -/* ItemEvent.java -- event for item state changes - Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.event; - -import java.awt.AWTEvent; -import java.awt.ItemSelectable; - -/** - * This event is generated when a selection item changes state. This is an - * abstraction that distills a large number of individual mouse or keyboard - * events into a simpler "item selected" and "item deselected" events. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @see ItemSelectable - * @see ItemListener - * @since 1.1 - * @status updated to 1.4 - */ -public class ItemEvent extends AWTEvent -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = -608708132447206933L; - - /** This is the first id in the event id range used by this class. */ - public static final int ITEM_FIRST = 701; - - /** This is the last id in the event id range used by this class. */ - public static final int ITEM_LAST = 701; - - /** This event id indicates a state change occurred. */ - public static final int ITEM_STATE_CHANGED = 701; - - /** This type indicates that the item was selected. */ - public static final int SELECTED = 1; - - /** This type indicates that the item was deselected. */ - public static final int DESELECTED = 2; - - /** - * The item affected by this event. - * - * @serial the item of the selection - */ - private final Object item; - - /** - * The state change direction, one of {@link #SELECTED} or - * {@link #DESELECTED}. - * - * @serial the selection state - */ - private final int stateChange; - - /** - * Initializes a new instance of <code>ItemEvent</code> with the specified - * source, id, and state change constant. Note that an invalid id leads to - * unspecified results. - * - * @param source the source of the event - * @param id the event id - * @param item the item affected by the state change - * @param stateChange one of {@link #SELECTED} or {@link #DESELECTED} - */ - public ItemEvent(ItemSelectable source, int id, Object item, int stateChange) - { - super(source, id); - this.item = item; - this.stateChange = stateChange; - } - - /** - * This method returns the event source as an <code>ItemSelectable</code>. - * - * @return the event source as an <code>ItemSelected</code> - * @throws ClassCastException if source is changed to a non-ItemSelectable - */ - public ItemSelectable getItemSelectable() - { - return (ItemSelectable) source; - } - - /** - * Returns the item affected by this state change. - * - * @return the item affected by this state change - */ - public Object getItem() - { - return item; - } - - /** - * Returns the type of state change, either {@link #SELECTED} or - * {@link #DESELECTED}. - * - * @return the type of state change - */ - public int getStateChange() - { - return stateChange; - } - - /** - * Returns a string identifying this event. This is in the format: - * <code>"ITEM_STATE_CHANGED,item=" + item + ",stateChange=" - * + (getStateChange() == DESELECTED ? "DESELECTED" : "SELECTED")</code>. - * - * @return a string identifying this event - */ - public String paramString() - { - return (id == ITEM_STATE_CHANGED ? "ITEM_STATE_CHANGED,item=" - : "unknown type,item=") + item + ",stateChange=" - + (stateChange == SELECTED ? "SELECTED" - : stateChange == DESELECTED ? "DESELECTED" : "unknown type"); - } -} // class ItemEvent diff --git a/libjava/java/awt/event/ItemListener.java b/libjava/java/awt/event/ItemListener.java deleted file mode 100644 index 34fe7901b12..00000000000 --- a/libjava/java/awt/event/ItemListener.java +++ /dev/null @@ -1,61 +0,0 @@ -/* ItemListener.java -- listen for item events - Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.event; - -import java.util.EventListener; - -/** - * This interface is for classes that wish to receive events when an - * item's selection state changes. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @see ItemSelectable - * @see ItemEvent - * @since 1.1 - * @status updated to 1.4 - */ -public interface ItemListener extends EventListener -{ - /** - * This method is called when an item's state is changed. - * - * @param event the <code>ItemEvent</code> indicating the change - */ - void itemStateChanged(ItemEvent event); -} // interface ItemListener diff --git a/libjava/java/awt/event/KeyAdapter.java b/libjava/java/awt/event/KeyAdapter.java deleted file mode 100644 index c01d61ff339..00000000000 --- a/libjava/java/awt/event/KeyAdapter.java +++ /dev/null @@ -1,88 +0,0 @@ -/* KeyAdapter.java -- convenience class for writing key listeners - Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.event; - -/** - * This class implements <code>KeyListener</code> and implements all methods - * with empty bodies. This allows a listener interested in implementing only - * a subset of the <code>KeyListener</code> interface to extend this class - * and override only the desired methods. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @see KeyEvent - * @see KeyListener - * @since 1.1 - * @status updated to 1.4 - */ -public abstract class KeyAdapter implements KeyListener -{ - /** - * Do nothing default constructor for subclasses. - */ - public KeyAdapter() - { - } - - /** - * Implements this method in the interface with an empty body. - * - * @param event the event, ignored in this implementation - */ - public void keyTyped(KeyEvent event) - { - } - - /** - * Implements this method in the interface with an empty body. - * - * @param event the event, ignored in this implementation - */ - public void keyPressed(KeyEvent event) - { - } - - /** - * Implements this method in the interface with an empty body. - * - * @param event the event, ignored in this implementation - */ - public void keyReleased(KeyEvent event) - { - } -} // class KeyAdapter diff --git a/libjava/java/awt/event/KeyEvent.java b/libjava/java/awt/event/KeyEvent.java deleted file mode 100644 index a40a8e15c04..00000000000 --- a/libjava/java/awt/event/KeyEvent.java +++ /dev/null @@ -1,1740 +0,0 @@ -/* KeyEvent.java -- event for key presses - Copyright (C) 1999, 2002, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.event; - -import gnu.java.awt.EventModifier; - -import java.awt.Component; -import java.io.IOException; -import java.io.ObjectInputStream; - -/** - * This event is generated when a key is pressed or released. There are two - * categories of key events: - * - * <p><em>"Key typed" events</em> are higher-level, and have already - * compensated for modifiers and keyboard layout to generate a single Unicode - * character. It may take several key press events to generate one key typed. - * The <code>getKeyCode</code> method will return <code>VK_UNDEFINED</code>, - * and <code>getKeyChar</code> will return a valid Unicode character or - * <code>CHAR_UNDEFINED</code>. - * - * <p><em>"Key pressed" and "key released" events</em> are lower-level, and - * are platform and keyboard dependent. They correspond to the actaul motion - * on a keyboard, and return a virtual key code which labels the key that was - * pressed. The <code>getKeyCode</code> method will return one of the - * <code>VK_*</code> constants (except VK_UNDEFINED), and the - * <code>getKeyChar</code> method is undefined. - * - * <p>Some keys do not generate key typed events, such as the F1 or HELP keys. - * Not all keyboards can generate all virtual keys, and no attempt is made to - * simulate the ones that can't be typed. Virtual keys correspond to the - * keyboard layout, so for example, VK_Q in English is VK_A in French. Also, - * there are some additional virtual keys to ease handling of actions, such - * as VK_ALL_CANDIDATES in place of ALT+VK_CONVERT. Do not rely on the value - * of the VK_* constants, except for VK_ENTER, VK_BACK_SPACE, and VK_TAB. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Eric Blake (ebb9@email.byu.edu) - * @see KeyAdapter - * @see KeyListener - * @since 1.1 - * @status updated to 1.4 - */ -public class KeyEvent extends InputEvent -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = -2352130953028126954L; - - /** This is the first id in the range of event ids used by this class. */ - public static final int KEY_FIRST = 400; - - /** This is the last id in the range of event ids used by this class. */ - public static final int KEY_LAST = 402; - - /** - * This event id indicates a key was typed, which is a key press followed - * by a key release to generate an actual Unicode character. It may take - * several key presses to generate one key typed event, and some action - * keys have no corresponding key typed. - */ - public static final int KEY_TYPED = 400; - - /** This event id indicates a key was pressed. */ - public static final int KEY_PRESSED = 401; - - /** This event it indicates a key was released. */ - public static final int KEY_RELEASED = 402; - - /** The virtual key Enter, which will always map to '\n'. */ - public static final int VK_ENTER = '\n'; - - /** The virtual key Backspace, which will always map to '\b'. */ - public static final int VK_BACK_SPACE = '\b'; - - /** The virtual key Tab, which will always map to '\t'. */ - public static final int VK_TAB = '\t'; - - /** The virtual key Cancel. */ - public static final int VK_CANCEL = 3; - - /** The virtual key VK_CLEAR. */ - public static final int VK_CLEAR = 12; - - /** The virtual key VK_SHIFT. */ - public static final int VK_SHIFT = 16; - - /** The virtual key VK_CONTROL. */ - public static final int VK_CONTROL = 17; - - /** The virtual key VK_ALT. */ - public static final int VK_ALT = 18; - - /** The virtual key VK_PAUSE. */ - public static final int VK_PAUSE = 19; - - /** The virtual key VK_CAPS_LOCK. */ - public static final int VK_CAPS_LOCK = 20; - - /** The virtual key VK_ESCAPE. */ - public static final int VK_ESCAPE = 27; - - /** The virtual key VK_SPACE. */ - public static final int VK_SPACE = ' '; - - /** The virtual key VK_PAGE_UP. */ - public static final int VK_PAGE_UP = 33; - - /** The virtual key VK_PAGE_DOWN. */ - public static final int VK_PAGE_DOWN = 34; - - /** The virtual key VK_END. */ - public static final int VK_END = 35; - - /** The virtual key VK_HOME. */ - public static final int VK_HOME = 36; - - /** - * The virtual key for the non-numpad VK_LEFT. - * - * @see #VK_KP_LEFT - */ - public static final int VK_LEFT = 37; - - /** - * The virtual key for the non-numpad VK_UP. - * - * @see #VK_KP_UP - */ - public static final int VK_UP = 38; - - /** - * The virtual key for the non-numpad VK_RIGHT. - * - * @see #VK_KP_RIGHT - */ - public static final int VK_RIGHT = 39; - - /** - * The virtual key for the non-numpad VK_DOWN. - * - * @see #VK_KP_DOWN - */ - public static final int VK_DOWN = 40; - - /** The virtual key VK_COMMA. */ - public static final int VK_COMMA = ','; - - /** - * The virtual key VK_MINUS. - * - * @since 1.2 - */ - public static final int VK_MINUS = '-'; - - /** The virtual key VK_PERIOD. */ - public static final int VK_PERIOD = '.'; - - /** The virtual key VK_SLASH. */ - public static final int VK_SLASH = '/'; - - /** The virtual key VK_0. */ - public static final int VK_0 = '0'; - - /** The virtual key VK_1. */ - public static final int VK_1 = '1'; - - /** The virtual key VK_2. */ - public static final int VK_2 = '2'; - - /** The virtual key VK_3. */ - public static final int VK_3 = '3'; - - /** The virtual key VK_4. */ - public static final int VK_4 = '4'; - - /** The virtual key VK_5. */ - public static final int VK_5 = '5'; - - /** The virtual key VK_6. */ - public static final int VK_6 = '6'; - - /** The virtual key VK_7. */ - public static final int VK_7 = '7'; - - /** The virtual key VK_8. */ - public static final int VK_8 = '8'; - - /** The virtual key VK_9. */ - public static final int VK_9 = '9'; - - /** The virtual key VK_SEMICOLON. */ - public static final int VK_SEMICOLON = ';'; - - /** The virtual key VK_EQUALS. */ - public static final int VK_EQUALS = '='; - - /** The virtual key VK_A. */ - public static final int VK_A = 'A'; - - /** The virtual key VK_B. */ - public static final int VK_B = 'B'; - - /** The virtual key VK_C. */ - public static final int VK_C = 'C'; - - /** The virtual key VK_D. */ - public static final int VK_D = 'D'; - - /** The virtual key VK_E. */ - public static final int VK_E = 'E'; - - /** The virtual key VK_F. */ - public static final int VK_F = 'F'; - - /** The virtual key VK_G. */ - public static final int VK_G = 'G'; - - /** The virtual key VK_H. */ - public static final int VK_H = 'H'; - - /** The virtual key VK_I. */ - public static final int VK_I = 'I'; - - /** The virtual key VK_J. */ - public static final int VK_J = 'J'; - - /** The virtual key VK_K. */ - public static final int VK_K = 'K'; - - /** The virtual key VK_L. */ - public static final int VK_L = 'L'; - - /** The virtual key VK_M. */ - public static final int VK_M = 'M'; - - /** The virtual key VK_N. */ - public static final int VK_N = 'N'; - - /** The virtual key VK_O. */ - public static final int VK_O = 'O'; - - /** The virtual key VK_P. */ - public static final int VK_P = 'P'; - - /** The virtual key VK_Q. */ - public static final int VK_Q = 'Q'; - - /** The virtual key VK_R. */ - public static final int VK_R = 'R'; - - /** The virtual key VK_S. */ - public static final int VK_S = 'S'; - - /** The virtual key VK_T. */ - public static final int VK_T = 'T'; - - /** The virtual key VK_U. */ - public static final int VK_U = 'U'; - - /** The virtual key VK_V. */ - public static final int VK_V = 'V'; - - /** The virtual key VK_W. */ - public static final int VK_W = 'W'; - - /** The virtual key VK_X. */ - public static final int VK_X = 'X'; - - /** The virtual key VK_Y. */ - public static final int VK_Y = 'Y'; - - /** The virtual key VK_Z. */ - public static final int VK_Z = 'Z'; - - /** The virtual key VK_OPEN_BRACKET. */ - public static final int VK_OPEN_BRACKET = '['; - - /** The virtual key VK_BACK_SLASH. */ - public static final int VK_BACK_SLASH = '\\'; - - /** The virtual key VK_CLOSE_BRACKET. */ - public static final int VK_CLOSE_BRACKET = ']'; - - /** The virtual key VK_NUMPAD0. */ - public static final int VK_NUMPAD0 = 96; - - /** The virtual key VK_NUMPAD1. */ - public static final int VK_NUMPAD1 = 97; - - /** The virtual key VK_NUMPAD2. */ - public static final int VK_NUMPAD2 = 98; - - /** The virtual key VK_NUMPAD3. */ - public static final int VK_NUMPAD3 = 99; - - /** The virtual key VK_NUMPAD4. */ - public static final int VK_NUMPAD4 = 100; - - /** The virtual key VK_NUMPAD5. */ - public static final int VK_NUMPAD5 = 101; - - /** The virtual key VK_NUMPAD6. */ - public static final int VK_NUMPAD6 = 102; - - /** The virtual key VK_NUMPAD7. */ - public static final int VK_NUMPAD7 = 103; - - /** The virtual key VK_NUMPAD8. */ - public static final int VK_NUMPAD8 = 104; - - /** The virtual key VK_NUMPAD9. */ - public static final int VK_NUMPAD9 = 105; - - /** The virtual key VK_MULTIPLY. */ - public static final int VK_MULTIPLY = 106; - - /** The virtual key VK_ADD. */ - public static final int VK_ADD = 107; - - /** - * The virtual key VK_SEPARATOR, handily mispelled for those who can't - * figure it out. - * - * @deprecated use {@link #VK_SEPARATOR} - */ - public static final int VK_SEPARATER = 108; - - /** - * The virtual key VK_SEPARATOR. - * - * @since 1.4 - */ - public static final int VK_SEPARATOR = 108; - - /** The virtual key VK_SUBTRACT. */ - public static final int VK_SUBTRACT = 109; - - /** The virtual key VK_DECIMAL. */ - public static final int VK_DECIMAL = 110; - - /** The virtual key VK_DIVIDE. */ - public static final int VK_DIVIDE = 111; - - /** The virtual key VK_DELETE. */ - public static final int VK_DELETE = 127; - - /** The virtual key VK_NUM_LOCK. */ - public static final int VK_NUM_LOCK = 144; - - /** The virtual key VK_SCROLL_LOCK. */ - public static final int VK_SCROLL_LOCK = 145; - - /** The virtual key VK_F1. */ - public static final int VK_F1 = 112; - - /** The virtual key VK_F2. */ - public static final int VK_F2 = 113; - - /** The virtual key VK_F3. */ - public static final int VK_F3 = 114; - - /** The virtual key VK_F4. */ - public static final int VK_F4 = 115; - - /** The virtual key VK_F5. */ - public static final int VK_F5 = 116; - - /** The virtual key VK_F6. */ - public static final int VK_F6 = 117; - - /** The virtual key VK_F7. */ - public static final int VK_F7 = 118; - - /** The virtual key VK_F8. */ - public static final int VK_F8 = 119; - - /** The virtual key VK_F9. */ - public static final int VK_F9 = 120; - - /** The virtual key VK_F10. */ - public static final int VK_F10 = 121; - - /** The virtual key VK_F11. */ - public static final int VK_F11 = 122; - - /** The virtual key VK_F12. */ - public static final int VK_F12 = 123; - - /** - * The virtual key VK_F13. - * - * @since 1.2 - */ - public static final int VK_F13 = 61440; - - /** - * The virtual key VK_F14. - * - * @since 1.2 - */ - public static final int VK_F14 = 61441; - - /** - * The virtual key VK_F15. - * - * @since 1.2 - */ - public static final int VK_F15 = 61442; - - /** - * The virtual key VK_F16. - * - * @since 1.2 - */ - public static final int VK_F16 = 61443; - - /** - * The virtual key VK_F17. - * - * @since 1.2 - */ - public static final int VK_F17 = 61444; - - /** - * The virtual key VK_F18. - * - * @since 1.2 - */ - public static final int VK_F18 = 61445; - - /** - * The virtual key VK_F19. - * - * @since 1.2 - */ - public static final int VK_F19 = 61446; - - /** - * The virtual key VK_F20. - * - * @since 1.2 - */ - public static final int VK_F20 = 61447; - - /** - * The virtual key VK_F21. - * - * @since 1.2 - */ - public static final int VK_F21 = 61448; - - /** - * The virtual key VK_F22. - * - * @since 1.2 - */ - public static final int VK_F22 = 61449; - - /** - * The virtual key VK_F23. - * - * @since 1.2 - */ - public static final int VK_F23 = 61450; - - /** - * The virtual key VK_F24. - * - * @since 1.2 - */ - public static final int VK_F24 = 61451; - - /** The virtual key VK_PRINTSCREEN. */ - public static final int VK_PRINTSCREEN = 154; - - /** The virtual key VK_INSERT. */ - public static final int VK_INSERT = 155; - - /** The virtual key VK_HELP. */ - public static final int VK_HELP = 156; - - /** The virtual key VK_META. */ - public static final int VK_META = 157; - - /** The virtual key VK_BACK_QUOTE. */ - public static final int VK_BACK_QUOTE = 192; - - /** The virtual key VK_QUOTE. */ - public static final int VK_QUOTE = 222; - - /** - * The virtual key for the numpad VK_KP_UP. - * - * @see #VK_UP - * @since 1.2 - */ - public static final int VK_KP_UP = 224; - - /** - * The virtual key for the numpad VK_KP_DOWN. - * - * @see #VK_DOWN - * @since 1.2 - */ - public static final int VK_KP_DOWN = 225; - - /** - * The virtual key for the numpad VK_KP_LEFT. - * - * @see #VK_LEFT - * @since 1.2 - */ - public static final int VK_KP_LEFT = 226; - - /** - * The virtual key for the numpad VK_KP_RIGHT. - * - * @see #VK_RIGHT - * @since 1.2 - */ - public static final int VK_KP_RIGHT = 227; - - /** - * The virtual key VK_DEAD_GRAVE. - * - * @since 1.2 - */ - public static final int VK_DEAD_GRAVE = 128; - - /** - * The virtual key VK_DEAD_ACUTE. - * - * @since 1.2 - */ - public static final int VK_DEAD_ACUTE = 129; - - /** - * The virtual key VK_DEAD_CIRCUMFLEX. - * - * @since 1.2 - */ - public static final int VK_DEAD_CIRCUMFLEX = 130; - - /** - * The virtual key VK_DEAD_TILDE. - * - * @since 1.2 - */ - public static final int VK_DEAD_TILDE = 131; - - /** - * The virtual key VK_DEAD_MACRON. - * - * @since 1.2 - */ - public static final int VK_DEAD_MACRON = 132; - - /** - * The virtual key VK_DEAD_BREVE. - * - * @since 1.2 - */ - public static final int VK_DEAD_BREVE = 133; - - /** - * The virtual key VK_DEAD_ABOVEDOT. - * - * @since 1.2 - */ - public static final int VK_DEAD_ABOVEDOT = 134; - - /** - * The virtual key VK_DEAD_DIAERESIS. - * - * @since 1.2 - */ - public static final int VK_DEAD_DIAERESIS = 135; - - /** - * The virtual key VK_DEAD_ABOVERING. - * - * @since 1.2 - */ - public static final int VK_DEAD_ABOVERING = 136; - - /** - * The virtual key VK_DEAD_DOUBLEACUTE. - * - * @since 1.2 - */ - public static final int VK_DEAD_DOUBLEACUTE = 137; - - /** - * The virtual key VK_DEAD_CARON. - * - * @since 1.2 - */ - public static final int VK_DEAD_CARON = 138; - - /** - * The virtual key VK_DEAD_CEDILLA. - * - * @since 1.2 - */ - public static final int VK_DEAD_CEDILLA = 139; - - /** - * The virtual key VK_DEAD_OGONEK. - * - * @since 1.2 - */ - public static final int VK_DEAD_OGONEK = 140; - - /** - * The virtual key VK_DEAD_IOTA. - * - * @since 1.2 - */ - public static final int VK_DEAD_IOTA = 141; - - /** - * The virtual key VK_DEAD_VOICED_SOUND. - * - * @since 1.2 - */ - public static final int VK_DEAD_VOICED_SOUND = 142; - - /** - * The virtual key VK_DEAD_SEMIVOICED_SOUND. - * - * @since 1.2 - */ - public static final int VK_DEAD_SEMIVOICED_SOUND = 143; - - /** - * The virtual key VK_AMPERSAND. - * - * @since 1.2 - */ - public static final int VK_AMPERSAND = 150; - - /** - * The virtual key VK_ASTERISK. - * - * @since 1.2 - */ - public static final int VK_ASTERISK = 151; - - /** - * The virtual key VK_QUOTEDBL. - * - * @since 1.2 - */ - public static final int VK_QUOTEDBL = 152; - - /** - * The virtual key VK_LESS. - * - * @since 1.2 - */ - public static final int VK_LESS = 153; - - /** - * The virtual key VK_GREATER. - * - * @since 1.2 - */ - public static final int VK_GREATER = 160; - - /** - * The virtual key VK_BRACELEFT. - * - * @since 1.2 - */ - public static final int VK_BRACELEFT = 161; - - /** - * The virtual key VK_BRACERIGHT. - * - * @since 1.2 - */ - public static final int VK_BRACERIGHT = 162; - - /** - * The virtual key VK_AT. - * - * @since 1.2 - */ - public static final int VK_AT = 512; - - /** - * The virtual key VK_COLON. - * - * @since 1.2 - */ - public static final int VK_COLON = 513; - - /** - * The virtual key VK_CIRCUMFLEX. - * - * @since 1.2 - */ - public static final int VK_CIRCUMFLEX = 514; - - /** - * The virtual key VK_DOLLAR. - * - * @since 1.2 - */ - public static final int VK_DOLLAR = 515; - - /** - * The virtual key VK_EURO_SIGN. - * - * @since 1.2 - */ - public static final int VK_EURO_SIGN = 516; - - /** - * The virtual key VK_EXCLAMATION_MARK. - * - * @since 1.2 - */ - public static final int VK_EXCLAMATION_MARK = 517; - - /** - * The virtual key VK_INVERTED_EXCLAMATION_MARK. - * - * @since 1.2 - */ - public static final int VK_INVERTED_EXCLAMATION_MARK = 518; - - /** - * The virtual key VK_LEFT_PARENTHESIS. - * - * @since 1.2 - */ - public static final int VK_LEFT_PARENTHESIS = 519; - - /** - * The virtual key VK_NUMBER_SIGN. - * - * @since 1.2 - */ - public static final int VK_NUMBER_SIGN = 520; - - /** - * The virtual key VK_PLUS. - * - * @since 1.2 - */ - public static final int VK_PLUS = 521; - - /** - * The virtual key VK_RIGHT_PARENTHESIS. - * - * @since 1.2 - */ - public static final int VK_RIGHT_PARENTHESIS = 522; - - /** - * The virtual key VK_UNDERSCORE. - * - * @since 1.2 - */ - public static final int VK_UNDERSCORE = 523; - - /** The virtual key VK_FINAL. */ - public static final int VK_FINAL = 24; - - /** The virtual key VK_CONVERT. */ - public static final int VK_CONVERT = 28; - - /** The virtual key VK_NONCONVERT. */ - public static final int VK_NONCONVERT = 29; - - /** The virtual key VK_ACCEPT. */ - public static final int VK_ACCEPT = 30; - - /** The virtual key VK_MODECHANGE. */ - public static final int VK_MODECHANGE = 31; - - /** The virtual key VK_KANA. */ - public static final int VK_KANA = 21; - - /** The virtual key VK_KANJI. */ - public static final int VK_KANJI = 25; - - /** - * The virtual key VK_ALPHANUMERIC. - * - * @since 1.2 - */ - public static final int VK_ALPHANUMERIC = 240; - - /** - * The virtual key VK_KATAKANA. - * - * @since 1.2 - */ - public static final int VK_KATAKANA = 241; - - /** - * The virtual key VK_HIRAGANA. - * - * @since 1.2 - */ - public static final int VK_HIRAGANA = 242; - - /** - * The virtual key VK_FULL_WIDTH. - * - * @since 1.2 - */ - public static final int VK_FULL_WIDTH = 243; - - /** - * The virtual key VK_HALF_WIDTH. - * - * @since 1.2 - */ - public static final int VK_HALF_WIDTH = 244; - - /** - * The virtual key VK_ROMAN_CHARACTERS. - * - * @since 1.2 - */ - public static final int VK_ROMAN_CHARACTERS = 245; - - /** - * The virtual key VK_ALL_CANDIDATES. - * - * @since 1.2 - */ - public static final int VK_ALL_CANDIDATES = 256; - - /** - * The virtual key VK_PREVIOUS_CANDIDATE. - * - * @since 1.2 - */ - public static final int VK_PREVIOUS_CANDIDATE = 257; - - /** - * The virtual key VK_CODE_INPUT. - * - * @since 1.2 - */ - public static final int VK_CODE_INPUT = 258; - - /** - * The virtual key VK_JAPANESE_KATAKANA. - * - * @since 1.2 - */ - public static final int VK_JAPANESE_KATAKANA = 259; - - /** - * The virtual key VK_JAPANESE_HIRAGANA. - * - * @since 1.2 - */ - public static final int VK_JAPANESE_HIRAGANA = 260; - - /** - * The virtual key VK_JAPANESE_ROMAN. - * - * @since 1.2 - */ - public static final int VK_JAPANESE_ROMAN = 261; - - /** - * The virtual key VK_KANA_LOCK. - * - * @since 1.3 - */ - public static final int VK_KANA_LOCK = 262; - - /** - * The virtual key VK_INPUT_METHOD_ON_OFF. - * - * @since 1.3 - */ - public static final int VK_INPUT_METHOD_ON_OFF = 263; - - /** - * The virtual key VK_CUT. - * - * @since 1.2 - */ - public static final int VK_CUT = 65489; - - /** - * The virtual key VK_COPY. - * - * @since 1.2 - */ - public static final int VK_COPY = 65485; - - /** - * The virtual key VK_PASTE. - * - * @since 1.2 - */ - public static final int VK_PASTE = 65487; - - /** - * The virtual key VK_UNDO. - * - * @since 1.2 - */ - public static final int VK_UNDO = 65483; - - /** - * The virtual key VK_AGAIN. - * - * @since 1.2 - */ - public static final int VK_AGAIN = 65481; - - /** - * The virtual key VK_FIND. - * - * @since 1.2 - */ - public static final int VK_FIND = 65488; - - /** - * The virtual key VK_PROPS. - * - * @since 1.2 - */ - public static final int VK_PROPS = 65482; - - /** - * The virtual key VK_STOP. - * - * @since 1.2 - */ - public static final int VK_STOP = 65480; - - /** - * The virtual key VK_COMPOSE. - * - * @since 1.2 - */ - public static final int VK_COMPOSE = 65312; - - /** - * The virtual key VK_ALT_GRAPH. - * - * @since 1.2 - */ - public static final int VK_ALT_GRAPH = 65406; - - /** - * The virtual key VK_UNDEFINED. This is used for key typed events, which - * do not have a virtual key. - */ - public static final int VK_UNDEFINED = 0; - - /** - * The only char with no valid Unicode interpretation. This is used for - * key pressed and key released events which do not have a valid keyChar. - */ - public static final char CHAR_UNDEFINED = '\uffff'; - - /** - * Indicates unknown or irrelavent key location. This is also used for - * key typed events, which do not need a location. - * - * @since 1.4 - */ - public static final int KEY_LOCATION_UNKNOWN = 0; - - /** - * Indicates a standard key location, with no left/right variants and not - * on the numeric pad. - * - * @since 1.4 - */ - public static final int KEY_LOCATION_STANDARD = 1; - - /** - * Indicates the key is on the left side of the keyboard, such as the left - * shift. - * - * @since 1.4 - */ - public static final int KEY_LOCATION_LEFT = 2; - - /** - * Indicates the key is on the right side of the keyboard, such as the right - * shift. - * - * @since 1.4 - */ - public static final int KEY_LOCATION_RIGHT = 3; - - /** - * Indicates the key is on the numeric pad, such as the numpad 0. - * - * @since 1.4 - */ - public static final int KEY_LOCATION_NUMPAD = 4; - - /** - * The code assigned to the physical keyboard location (as adjusted by the - * keyboard layout). Use the symbolic VK_* names instead of numbers. - * - * @see #getKeyCode() - * @serial the VK_ code for this key - */ - private int keyCode; - - /** - * The Unicode character produced by the key type event. This has no meaning - * for key pressed and key released events. - * - * @see #getKeyChar() - * @serial the Unicode value for this key - */ - private char keyChar; - - /** - * The keyboard location of the key. One of {@link #KEY_LOCATION_UNKNOWN}, - * {@link #KEY_LOCATION_STANDARD}, {@link #KEY_LOCATION_LEFT}, - * {@link #KEY_LOCATION_RIGHT}, or {@link #KEY_LOCATION_NUMPAD}. - * - * @see #getKeyLocation() - * @serial the key location - * @since 1.4 - */ - private final int keyLocation; - - /** - * Stores the state of the native event dispatching system, to correctly - * dispatch in Component#dispatchEventImpl when a proxy is active. - * - * XXX Does this matter in Classpath? - * - * @serial whether the proxy is active - */ - private boolean isProxyActive; - - - /** - * Initializes a new instance of <code>KeyEvent</code> with the specified - * information. Note that an invalid id leads to unspecified results. - * - * @param source the component that generated this event - * @param id the event id - * @param when the timestamp when the even occurred - * @param modifiers the modifier keys during the event, in old or new style - * @param keyCode the integer constant for the virtual key type - * @param keyChar the Unicode value of the key - * @param keyLocation the location of the key - * @throws IllegalArgumentException if source is null, if keyLocation is - * invalid, or if (id == KEY_TYPED && (keyCode != VK_UNDEFINED - * || keyChar == CHAR_UNDEFINED)) - */ - public KeyEvent(Component source, int id, long when, int modifiers, - int keyCode, char keyChar, int keyLocation) - { - super(source, id, when, modifiers); - this.keyCode = keyCode; - this.keyChar = keyChar; - this.keyLocation = keyLocation; - if ((id == KEY_TYPED && (keyCode != VK_UNDEFINED - || keyChar == CHAR_UNDEFINED)) - || keyLocation < KEY_LOCATION_UNKNOWN - || keyLocation > KEY_LOCATION_NUMPAD) - throw new IllegalArgumentException(); - } - - /** - * Initializes a new instance of <code>KeyEvent</code> with the specified - * information. Note that an invalid id leads to unspecified results. - * - * @param source the component that generated this event - * @param id the event id - * @param when the timestamp when the even occurred - * @param modifiers the modifier keys during the event, in old or new style - * @param keyCode the integer constant for the virtual key type - * @param keyChar the Unicode value of the key - * @throws IllegalArgumentException if source is null, or if - * (id == KEY_TYPED && (keyCode != VK_UNDEFINED - * || keyChar == CHAR_UNDEFINED)) - */ - public KeyEvent(Component source, int id, long when, int modifiers, - int keyCode, char keyChar) - { - this(source, id, when, modifiers, keyCode, keyChar, KEY_LOCATION_UNKNOWN); - } - - /** - * Initializes a new instance of <code>KeyEvent</code> with the specified - * information. Note that an invalid id leads to unspecified results. - * - * @param source the component that generated this event - * @param id the event id - * @param when the timestamp when the even occurred - * @param modifiers the modifier keys during the event, in old or new style - * @param keyCode the integer constant for the virtual key type - * @throws IllegalArgumentException if source is null, or if - * id == KEY_TYPED but keyCode != VK_UNDEFINED - * - * @deprecated - */ - public KeyEvent(Component source, int id, long when, int modifiers, - int keyCode) - { - this(source, id, when, modifiers, keyCode, '\0', KEY_LOCATION_UNKNOWN); - } - - /** - * Returns the key code for the event key. This will be one of the - * <code>VK_*</code> constants defined in this class. If the event type is - * KEY_TYPED, the result will be VK_UNDEFINED. - * - * @return the key code for this event - */ - public int getKeyCode() - { - return keyCode; - } - - /** - * Sets the key code for this event. This must be one of the - * <code>VK_*</code> constants defined in this class. - * - * @param keyCode the new key code for this event - */ - public void setKeyCode(int keyCode) - { - this.keyCode = keyCode; - } - - /** - * Returns the Unicode value for the event key. This will be - * <code>CHAR_UNDEFINED</code> if there is no Unicode equivalent for - * this key, usually when this is a KEY_PRESSED or KEY_RELEASED event. - * - * @return the Unicode character for this event - */ - public char getKeyChar() - { - return keyChar; - } - - /** - * Sets the Unicode character for this event to the specified value. - * - * @param keyChar the new Unicode character for this event - */ - public void setKeyChar(char keyChar) - { - this.keyChar = keyChar; - } - - /** - * Sets the modifier keys to the specified value. This should be a union - * of the bit mask constants from <code>InputEvent</code>. The use of this - * method is not recommended, particularly for KEY_TYPED events, which do - * not check if the modifiers were changed. - * - * @param modifiers the new modifier value, in either old or new style - * @see InputEvent - * - * @deprecated - */ - public void setModifiers(int modifiers) - { - this.modifiers = EventModifier.extend(modifiers); - } - - /** - * Returns the keyboard location of the key that generated this event. This - * provides a way to distinguish between keys like left and right shift - * which share a common key code. The result will be one of - * {@link #KEY_LOCATION_UNKNOWN}, {@link #KEY_LOCATION_STANDARD}, - * {@link #KEY_LOCATION_LEFT}, {@link #KEY_LOCATION_RIGHT}, or - * {@link #KEY_LOCATION_NUMPAD}. - * - * @return the key location - * @since 1.4 - */ - public int getKeyLocation() - { - return keyLocation; - } - - /** - * Returns the text name of key code, such as "HOME", "F1", or "A". - * - * XXX Sun claims this can be localized via the awt.properties file - how - * do we implement that? - * - * @return the text name of the key code - */ - public static String getKeyText(int keyCode) - { - switch (keyCode) - { - case VK_CANCEL: - return "Cancel"; - case VK_BACK_SPACE: - return "Backspace"; - case VK_TAB: - return "Tab"; - case VK_ENTER: - return "Enter"; - case VK_CLEAR: - return "Clear"; - case VK_SHIFT: - return "Shift"; - case VK_CONTROL: - return "Ctrl"; - case VK_ALT: - return "Alt"; - case VK_PAUSE: - return "Pause"; - case VK_CAPS_LOCK: - return "Caps Lock"; - case VK_KANA: - return "Kana"; - case VK_FINAL: - return "Final"; - case VK_KANJI: - return "Kanji"; - case VK_ESCAPE: - return "Escape"; - case VK_CONVERT: - return "Convert"; - case VK_NONCONVERT: - return "No Convert"; - case VK_ACCEPT: - return "Accept"; - case VK_MODECHANGE: - return "Mode Change"; - case VK_SPACE: - return "Space"; - case VK_PAGE_UP: - return "Page Up"; - case VK_PAGE_DOWN: - return "Page Down"; - case VK_END: - return "End"; - case VK_HOME: - return "Home"; - case VK_LEFT: - case VK_KP_LEFT: - return "Left"; - case VK_UP: - case VK_KP_UP: - return "Up"; - case VK_RIGHT: - case VK_KP_RIGHT: - return "Right"; - case VK_DOWN: - case VK_KP_DOWN: - return "Down"; - case VK_MINUS: - return "Minus"; - case VK_MULTIPLY: - return "NumPad *"; - case VK_ADD: - return "NumPad +"; - case VK_SEPARATOR: - return "NumPad ,"; - case VK_SUBTRACT: - return "NumPad -"; - case VK_DECIMAL: - return "NumPad ."; - case VK_DIVIDE: - return "NumPad /"; - case VK_DELETE: - return "Delete"; - case VK_DEAD_GRAVE: - return "Dead Grave"; - case VK_DEAD_ACUTE: - return "Dead Acute"; - case VK_DEAD_CIRCUMFLEX: - return "Dead Circumflex"; - case VK_DEAD_TILDE: - return "Dead Tilde"; - case VK_DEAD_MACRON: - return "Dead Macron"; - case VK_DEAD_BREVE: - return "Dead Breve"; - case VK_DEAD_ABOVEDOT: - return "Dead Above Dot"; - case VK_DEAD_DIAERESIS: - return "Dead Diaeresis"; - case VK_DEAD_ABOVERING: - return "Dead Above Ring"; - case VK_DEAD_DOUBLEACUTE: - return "Dead Double Acute"; - case VK_DEAD_CARON: - return "Dead Caron"; - case VK_DEAD_CEDILLA: - return "Dead Cedilla"; - case VK_DEAD_OGONEK: - return "Dead Ogonek"; - case VK_DEAD_IOTA: - return "Dead Iota"; - case VK_DEAD_VOICED_SOUND: - return "Dead Voiced Sound"; - case VK_DEAD_SEMIVOICED_SOUND: - return "Dead Semivoiced Sound"; - case VK_NUM_LOCK: - return "Num Lock"; - case VK_SCROLL_LOCK: - return "Scroll Lock"; - case VK_AMPERSAND: - return "Ampersand"; - case VK_ASTERISK: - return "Asterisk"; - case VK_QUOTEDBL: - return "Double Quote"; - case VK_LESS: - return "Less"; - case VK_PRINTSCREEN: - return "Print Screen"; - case VK_INSERT: - return "Insert"; - case VK_HELP: - return "Help"; - case VK_META: - return "Meta"; - case VK_GREATER: - return "Greater"; - case VK_BRACELEFT: - return "Left Brace"; - case VK_BRACERIGHT: - return "Right Brace"; - case VK_BACK_QUOTE: - return "Back Quote"; - case VK_QUOTE: - return "Quote"; - case VK_ALPHANUMERIC: - return "Alphanumeric"; - case VK_KATAKANA: - return "Katakana"; - case VK_HIRAGANA: - return "Hiragana"; - case VK_FULL_WIDTH: - return "Full-Width"; - case VK_HALF_WIDTH: - return "Half-Width"; - case VK_ROMAN_CHARACTERS: - return "Roman Characters"; - case VK_ALL_CANDIDATES: - return "All Candidates"; - case VK_PREVIOUS_CANDIDATE: - return "Previous Candidate"; - case VK_CODE_INPUT: - return "Code Input"; - case VK_JAPANESE_KATAKANA: - return "Japanese Katakana"; - case VK_JAPANESE_HIRAGANA: - return "Japanese Hiragana"; - case VK_JAPANESE_ROMAN: - return "Japanese Roman"; - case VK_KANA_LOCK: - return "Kana Lock"; - case VK_INPUT_METHOD_ON_OFF: - return "Input Method On/Off"; - case VK_AT: - return "At"; - case VK_COLON: - return "Colon"; - case VK_CIRCUMFLEX: - return "Circumflex"; - case VK_DOLLAR: - return "Dollar"; - case VK_EURO_SIGN: - return "Euro"; - case VK_EXCLAMATION_MARK: - return "Exclamation Mark"; - case VK_INVERTED_EXCLAMATION_MARK: - return "Inverted Exclamation Mark"; - case VK_LEFT_PARENTHESIS: - return "Left Parenthesis"; - case VK_NUMBER_SIGN: - return "Number Sign"; - case VK_PLUS: - return "Plus"; - case VK_RIGHT_PARENTHESIS: - return "Right Parenthesis"; - case VK_UNDERSCORE: - return "Underscore"; - case VK_COMPOSE: - return "Compose"; - case VK_ALT_GRAPH: - return "Alt Graph"; - case VK_STOP: - return "Stop"; - case VK_AGAIN: - return "Again"; - case VK_PROPS: - return "Props"; - case VK_UNDO: - return "Undo"; - case VK_COPY: - return "Copy"; - case VK_PASTE: - return "Paste"; - case VK_FIND: - return "Find"; - case VK_CUT: - return "Cut"; - case VK_COMMA: - case VK_PERIOD: - case VK_SLASH: - case VK_0: - case VK_1: - case VK_2: - case VK_3: - case VK_4: - case VK_5: - case VK_6: - case VK_7: - case VK_8: - case VK_9: - case VK_SEMICOLON: - case VK_EQUALS: - case VK_A: - case VK_B: - case VK_C: - case VK_D: - case VK_E: - case VK_F: - case VK_G: - case VK_H: - case VK_I: - case VK_J: - case VK_K: - case VK_L: - case VK_M: - case VK_N: - case VK_O: - case VK_P: - case VK_Q: - case VK_R: - case VK_S: - case VK_T: - case VK_U: - case VK_V: - case VK_W: - case VK_X: - case VK_Y: - case VK_Z: - case VK_OPEN_BRACKET: - case VK_BACK_SLASH: - case VK_CLOSE_BRACKET: - return "" + (char) keyCode; - case VK_NUMPAD0: - case VK_NUMPAD1: - case VK_NUMPAD2: - case VK_NUMPAD3: - case VK_NUMPAD4: - case VK_NUMPAD5: - case VK_NUMPAD6: - case VK_NUMPAD7: - case VK_NUMPAD8: - case VK_NUMPAD9: - return "NumPad-" + (keyCode - VK_NUMPAD0); - case VK_F1: - case VK_F2: - case VK_F3: - case VK_F4: - case VK_F5: - case VK_F6: - case VK_F7: - case VK_F8: - case VK_F9: - case VK_F10: - case VK_F11: - case VK_F12: - return "F" + (keyCode - (VK_F1 - 1)); - case VK_F13: - case VK_F14: - case VK_F15: - case VK_F16: - case VK_F17: - case VK_F18: - case VK_F19: - case VK_F20: - case VK_F21: - case VK_F22: - case VK_F23: - case VK_F24: - return "F" + (keyCode - (VK_F13 - 13)); - default: - // This is funky on negative numbers, but that's Sun's fault. - return "Unknown keyCode: 0x" + (keyCode < 0 ? "-" : "") - + Integer.toHexString(Math.abs(keyCode)); - } - } - - /** - * Returns a string describing the modifiers, such as "Shift" or - * "Ctrl+Button1". - * - * XXX Sun claims this can be localized via the awt.properties file - how - * do we implement that? - * - * @param modifiers the old-style modifiers to convert to text - * @return a string representation of the modifiers in this bitmask - */ - public static String getKeyModifiersText(int modifiers) - { - return getModifiersExText(EventModifier.extend(modifiers - & EventModifier.OLD_MASK)); - } - - /** - * Tests whether or not this key is an action key. An action key typically - * does not fire a KEY_TYPED event, and is not a modifier. - * - * @return true if this is an action key - */ - public boolean isActionKey() - { - switch (keyCode) - { - case VK_PAUSE: - case VK_CAPS_LOCK: - case VK_KANA: - case VK_FINAL: - case VK_KANJI: - case VK_CONVERT: - case VK_NONCONVERT: - case VK_ACCEPT: - case VK_MODECHANGE: - case VK_PAGE_UP: - case VK_PAGE_DOWN: - case VK_END: - case VK_HOME: - case VK_LEFT: - case VK_UP: - case VK_RIGHT: - case VK_DOWN: - case VK_F1: - case VK_F2: - case VK_F3: - case VK_F4: - case VK_F5: - case VK_F6: - case VK_F7: - case VK_F8: - case VK_F9: - case VK_F10: - case VK_F11: - case VK_F12: - case VK_NUM_LOCK: - case VK_SCROLL_LOCK: - case VK_PRINTSCREEN: - case VK_INSERT: - case VK_HELP: - case VK_KP_UP: - case VK_KP_DOWN: - case VK_KP_LEFT: - case VK_KP_RIGHT: - case VK_ALPHANUMERIC: - case VK_KATAKANA: - case VK_HIRAGANA: - case VK_FULL_WIDTH: - case VK_HALF_WIDTH: - case VK_ROMAN_CHARACTERS: - case VK_ALL_CANDIDATES: - case VK_PREVIOUS_CANDIDATE: - case VK_CODE_INPUT: - case VK_JAPANESE_KATAKANA: - case VK_JAPANESE_HIRAGANA: - case VK_JAPANESE_ROMAN: - case VK_KANA_LOCK: - case VK_INPUT_METHOD_ON_OFF: - case VK_F13: - case VK_F14: - case VK_F15: - case VK_F16: - case VK_F17: - case VK_F18: - case VK_F19: - case VK_F20: - case VK_F21: - case VK_F22: - case VK_F23: - case VK_F24: - case VK_STOP: - case VK_AGAIN: - case VK_PROPS: - case VK_UNDO: - case VK_COPY: - case VK_PASTE: - case VK_FIND: - case VK_CUT: - return true; - default: - return false; - } - } - - /** - * Returns a string identifying the event. This is formatted as the - * field name of the id type, followed by the keyCode, then the - * keyChar, modifiers (if any), extModifiers (if any), and - * keyLocation. - * - * @return a string identifying the event - */ - public String paramString() - { - StringBuffer s = new StringBuffer(); - - switch (id) - { - case KEY_PRESSED: - s.append("KEY_PRESSED"); - break; - case KEY_RELEASED: - s.append("KEY_RELEASED"); - break; - case KEY_TYPED: - s.append("KEY_TYPED"); - break; - default: - s.append("unknown type"); - } - - s.append(",keyCode=").append(keyCode); - - s.append(",keyText=").append(getKeyText(keyCode)); - - s.append(",keyChar="); - if (isActionKey() - || keyCode == VK_SHIFT - || keyCode == VK_CONTROL - || keyCode == VK_ALT) - s.append("Undefined keyChar"); - else - { - /* This output string must be selected by examining keyChar - * rather than keyCode, because key code information is not - * included in KEY_TYPED events. - */ - if (keyChar == VK_BACK_SPACE - || keyChar == VK_TAB - || keyChar == VK_ENTER - || keyChar == VK_ESCAPE - || keyChar == VK_DELETE) - s.append(getKeyText(keyChar)); - else - s.append("'").append(keyChar).append("'"); - } - - if ((modifiers & CONVERT_MASK) != 0) - s.append(",modifiers=").append(getModifiersExText(modifiers - & CONVERT_MASK)); - if (modifiers != 0) - s.append(",extModifiers=").append(getModifiersExText(modifiers)); - - s.append(",keyLocation=KEY_LOCATION_"); - switch (keyLocation) - { - case KEY_LOCATION_UNKNOWN: - s.append("UNKNOWN"); - break; - case KEY_LOCATION_STANDARD: - s.append("STANDARD"); - break; - case KEY_LOCATION_LEFT: - s.append("LEFT"); - break; - case KEY_LOCATION_RIGHT: - s.append("RIGHT"); - break; - case KEY_LOCATION_NUMPAD: - s.append("NUMPAD"); - } - - return s.toString(); - } - - /** - * Reads in the object from a serial stream. - * - * @param s the stream to read from - * @throws IOException if deserialization fails - * @throws ClassNotFoundException if deserialization fails - * @serialData default, except that the modifiers are converted to new style - */ - private void readObject(ObjectInputStream s) - throws IOException, ClassNotFoundException - { - s.defaultReadObject(); - modifiers = EventModifier.extend(modifiers); - } -} // class KeyEvent diff --git a/libjava/java/awt/event/KeyListener.java b/libjava/java/awt/event/KeyListener.java deleted file mode 100644 index 5c0a640f67e..00000000000 --- a/libjava/java/awt/event/KeyListener.java +++ /dev/null @@ -1,77 +0,0 @@ -/* KeyListener.java -- listen for keyboard presses - Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.event; - -import java.util.EventListener; - -/** - * This interface is for classes that wish to receive keyboard events. To - * watch a subset of these events, use a KeyAdapter. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @see KeyAdapter - * @see KeyEvent - * @since 1.1 - * @status updated to 1.4 - */ -public interface KeyListener extends EventListener -{ - /** - * This method is called when a key is typed. A key is considered typed - * when it and all modifiers have been pressed and released, mapping to - * a single virtual key. - * - * @param event the <code>KeyEvent</code> indicating that a key was typed - */ - void keyTyped(KeyEvent event); - - /** - * This method is called when a key is pressed. - * - * @param event the <code>KeyEvent</code> indicating the key press - */ - void keyPressed(KeyEvent event); - - /** - * This method is called when a key is released. - * - * @param event the <code>KeyEvent</code> indicating the key release - */ - void keyReleased(KeyEvent event); -} // interface KeyListener diff --git a/libjava/java/awt/event/MouseAdapter.java b/libjava/java/awt/event/MouseAdapter.java deleted file mode 100644 index 9f40c285ac7..00000000000 --- a/libjava/java/awt/event/MouseAdapter.java +++ /dev/null @@ -1,106 +0,0 @@ -/* MouseAdapter.java -- convenience class for writing mouse listeners - Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.event; - -/** - * This class implements <code>MouseListener</code> and implements all methods - * with empty bodies. This allows a listener interested in implementing only - * a subset of the <code>MouseListener</code> interface to extend this class - * and override only the desired methods. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @see MouseEvent - * @see MouseListener - * @since 1.1 - * @status updated to 1.4 - */ -public abstract class MouseAdapter implements MouseListener -{ - /** - * Do nothing default constructor for subclasses. - */ - public MouseAdapter() - { - } - - /** - * Implements this method in the interface with an empty method body. - * - * @param event the event, ignored in this implementation - */ - public void mouseClicked(MouseEvent event) - { - } - - /** - * Implements this method in the interface with an empty method body. - * - * @param event the event, ignored in this implementation - */ - public void mousePressed(MouseEvent event) - { - } - - /** - * Implements this method in the interface with an empty method body. - * - * @param event the event, ignored in this implementation - */ - public void mouseReleased(MouseEvent event) - { - } - - /** - * Implements this method in the interface with an empty method body. - * - * @param event the event, ignored in this implementation - */ - public void mouseEntered(MouseEvent event) - { - } - - /** - * Implements this method in the interface with an empty method body. - * - * @param event the event, ignored in this implementation - */ - public void mouseExited(MouseEvent event) - { - } -} // class MouseAdapter diff --git a/libjava/java/awt/event/MouseEvent.java b/libjava/java/awt/event/MouseEvent.java deleted file mode 100644 index 249c3d112e4..00000000000 --- a/libjava/java/awt/event/MouseEvent.java +++ /dev/null @@ -1,432 +0,0 @@ -/* MouseEvent.java -- a mouse event - Copyright (C) 1999, 2002, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.event; - -import gnu.java.awt.EventModifier; - -import java.awt.Component; -import java.awt.Point; -import java.io.IOException; -import java.io.ObjectInputStream; - -/** - * This event is generated for a mouse event. There are three main categories - * of mouse events: Regular events include pressing, releasing, and clicking - * buttons, as well as moving over the boundary of the unobscured portion of - * a component. Motion events include movement and dragging. Wheel events are - * covered separately by the subclass MouseWheelEvent. - * - * <p>A mouse event is tied to the unobstructed visible component that the - * mouse cursor was over at the time of the action. The button that was - * most recently pressed is the only one that shows up in - * <code>getModifiers</code>, and is returned by <code>getButton</code>, - * while all buttons that are down show up in <code>getModifiersEx</code>. - * - * <p>Drag events may be cut short if native drag-and-drop operations steal - * the event. Likewise, if a mouse drag exceeds the bounds of a window or - * virtual device, some platforms may clip the path to fit in the bounds of - * the component. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Eric Blake (ebb9@email.byu.edu) - * @see MouseAdapter - * @see MouseListener - * @see MouseMotionAdapter - * @see MouseMotionListener - * @see MouseWheelListener - * @since 1.1 - * @status updated to 1.4 - */ -public class MouseEvent extends InputEvent -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = -991214153494842848L; - - /** This is the first id in the range of event ids used by this class. */ - public static final int MOUSE_FIRST = 500; - - /** This is the last id in the range of event ids used by this class. */ - public static final int MOUSE_LAST = 507; - - /** This event id indicates that the mouse was clicked. */ - public static final int MOUSE_CLICKED = 500; - - /** This event id indicates that the mouse was pressed. */ - public static final int MOUSE_PRESSED = 501; - - /** This event id indicates that the mouse was released. */ - public static final int MOUSE_RELEASED = 502; - - /** This event id indicates that the mouse was moved. */ - public static final int MOUSE_MOVED = 503; - - /** This event id indicates that the mouse entered a component. */ - public static final int MOUSE_ENTERED = 504; - - /** This event id indicates that the mouse exited a component. */ - public static final int MOUSE_EXITED = 505; - - /** - * This indicates that no button changed state. - * - * @see #getButton() - * @since 1.4 - */ - public static final int NOBUTTON = 0; - - /** - * This indicates that button 1 changed state. - * - * @see #getButton() - * @since 1.4 - */ - public static final int BUTTON1 = 1; - - /** - * This indicates that button 2 changed state. - * - * @see #getButton() - * @since 1.4 - */ - public static final int BUTTON2 = 2; - - /** - * This indicates that button 3 changed state. - * - * @see #getButton() - * @since 1.4 - */ - public static final int BUTTON3 = 3; - - /** This event id indicates that the mouse was dragged over a component. */ - public static final int MOUSE_DRAGGED = 506; - - /** - * This event id indicates that the mouse wheel was rotated. - * - * @since 1.4 - */ - public static final int MOUSE_WHEEL = 507; - - /** - * The X coordinate of the mouse cursor at the time of the event. - * - * @see #getX() - * @serial the x coordinate - */ - private int x; - - /** - * The Y coordinate of the mouse cursor at the time of the event. - * - * @see #getY() - * @serial the y coordinate - */ - private int y; - - /** - * The number of clicks that took place. For MOUSE_CLICKED, MOUSE_PRESSED, - * and MOUSE_RELEASED, this will be at least 1; otherwise it is 0. - * - * see #getClickCount() - * @serial the number of clicks - */ - private final int clickCount; - - /** - * Indicates which mouse button changed state. Can only be one of - * {@link #NOBUTTON}, {@link #BUTTON1}, {@link #BUTTON2}, or - * {@link #BUTTON3}. - * - * @see #getButton() - * @since 1.4 - */ - private int button; - - /** - * Whether or not this event should trigger a popup menu. - * - * @see PopupMenu - * @see #isPopupTrigger() - * @serial true if this is a popup trigger - */ - private final boolean popupTrigger; - - /** - * Initializes a new instance of <code>MouseEvent</code> with the specified - * information. Note that an invalid id leads to unspecified results. - * - * @param source the source of the event - * @param id the event id - * @param when the timestamp of when the event occurred - * @param modifiers the modifier keys during the event, in old or new style - * @param x the X coordinate of the mouse point - * @param y the Y coordinate of the mouse point - * @param clickCount the number of mouse clicks for this event - * @param popupTrigger true if this event triggers a popup menu - * @param button the most recent mouse button to change state - * @throws IllegalArgumentException if source is null or button is invalid - * @since 1.4 - */ - public MouseEvent(Component source, int id, long when, int modifiers, - int x, int y, int clickCount, boolean popupTrigger, - int button) - { - super(source, id, when, modifiers); - this.x = x; - this.y = y; - this.clickCount = clickCount; - this.popupTrigger = popupTrigger; - this.button = button; - if (button < NOBUTTON || button > BUTTON3) - throw new IllegalArgumentException(); - if ((modifiers & EventModifier.OLD_MASK) != 0) - { - if ((modifiers & BUTTON1_MASK) != 0) - this.button = BUTTON1; - else if ((modifiers & BUTTON2_MASK) != 0) - this.button = BUTTON2; - else if ((modifiers & BUTTON3_MASK) != 0) - this.button = BUTTON3; - } - } - - /** - * Initializes a new instance of <code>MouseEvent</code> with the specified - * information. Note that an invalid id leads to unspecified results. - * - * @param source the source of the event - * @param id the event id - * @param when the timestamp of when the event occurred - * @param modifiers the modifier keys during the event, in old or new style - * @param x the X coordinate of the mouse point - * @param y the Y coordinate of the mouse point - * @param clickCount the number of mouse clicks for this event - * @param popupTrigger true if this event triggers a popup menu - * @throws IllegalArgumentException if source is null - */ - public MouseEvent(Component source, int id, long when, int modifiers, - int x, int y, int clickCount, boolean popupTrigger) - { - this(source, id, when, modifiers, x, y, clickCount, popupTrigger, - NOBUTTON); - } - - /** - * This method returns the X coordinate of the mouse position. This is - * relative to the source component. - * - * @return the x coordinate - */ - public int getX() - { - return x; - } - - /** - * This method returns the Y coordinate of the mouse position. This is - * relative to the source component. - * - * @return the y coordinate - */ - public int getY() - { - return y; - } - - /** - * This method returns a <code>Point</code> for the x,y position of - * the mouse pointer. This is relative to the source component. - * - * @return a <code>Point</code> for the event position - */ - public Point getPoint() - { - return new Point(x, y); - } - - /** - * Translates the event coordinates by the specified x and y offsets. - * - * @param dx the value to add to the X coordinate of this event - * @param dy the value to add to the Y coordiante of this event - */ - public void translatePoint(int dx, int dy) - { - x += dx; - y += dy; - } - - /** - * This method returns the number of mouse clicks associated with this - * event. - * - * @return the number of mouse clicks for this event - */ - public int getClickCount() - { - return clickCount; - } - - /** - * Returns which button, if any, was the most recent to change state. This - * will be one of {@link #NOBUTTON}, {@link #BUTTON1}, {@link #BUTTON2}, or - * {@link #BUTTON3}. - * - * @return the button that changed state - * @since 1.4 - */ - public int getButton() - { - return button; - } - - /** - * This method tests whether or not the event is a popup menu trigger. This - * should be checked in both MousePressed and MouseReleased to be - * cross-platform compatible, as different systems have different popup - * triggers. - * - * @return true if the event is a popup menu trigger - */ - public boolean isPopupTrigger() - { - return popupTrigger; - } - - /** - * Returns a string describing the modifiers, such as "Shift" or - * "Ctrl+Button1". - * - * XXX Sun claims this can be localized via the awt.properties file - how - * do we implement that? - * - * @param modifiers the old-style modifiers to convert to text - * @return a string representation of the modifiers in this bitmask - */ - public static String getMouseModifiersText(int modifiers) - { - modifiers &= EventModifier.OLD_MASK; - if ((modifiers & BUTTON2_MASK) != 0) - modifiers |= BUTTON2_DOWN_MASK; - if ((modifiers & BUTTON3_MASK) != 0) - modifiers |= BUTTON3_DOWN_MASK; - return getModifiersExText(EventModifier.extend(modifiers)); - } - - /** - * Returns a string identifying this event. This is formatted as the field - * name of the id type, followed by the (x,y) point, the most recent button - * changed, modifiers (if any), extModifiers (if any), and clickCount. - * - * @return a string identifying this event - */ - public String paramString() - { - StringBuffer s = new StringBuffer(); - switch (id) - { - case MOUSE_CLICKED: - s.append("MOUSE_CLICKED,("); - break; - case MOUSE_PRESSED: - s.append("MOUSE_PRESSED,("); - break; - case MOUSE_RELEASED: - s.append("MOUSE_RELEASED,("); - break; - case MOUSE_MOVED: - s.append("MOUSE_MOVED,("); - break; - case MOUSE_ENTERED: - s.append("MOUSE_ENTERED,("); - break; - case MOUSE_EXITED: - s.append("MOUSE_EXITED,("); - break; - case MOUSE_DRAGGED: - s.append("MOUSE_DRAGGED,("); - break; - case MOUSE_WHEEL: - s.append("MOUSE_WHEEL,("); - break; - default: - s.append("unknown type,("); - } - s.append(x).append(',').append(y).append("),button=").append(button); - if ((modifiers & EventModifier.NEW_MASK) != 0) - { - int mod = modifiers; - if ((mod & (ALT_DOWN_MASK | BUTTON2_DOWN_MASK)) != 0) - mod |= ALT_DOWN_MASK | BUTTON2_DOWN_MASK; - if ((mod & (META_DOWN_MASK | BUTTON3_DOWN_MASK)) != 0) - mod |= META_DOWN_MASK | BUTTON3_DOWN_MASK; - s.append(",modifiers=").append(getModifiersExText(mod)); - } - if (modifiers != 0) - s.append(",extModifiers=").append(getModifiersExText(modifiers)); - return s.append(",clickCount=").append(clickCount).toString(); - } - - /** - * Reads in the object from a serial stream. - * - * @param s the stream to read from - * @throws IOException if deserialization fails - * @throws ClassNotFoundException if deserialization fails - * @serialData default, except that the modifiers are converted to new style - */ - private void readObject(ObjectInputStream s) - throws IOException, ClassNotFoundException - { - s.defaultReadObject(); - if ((modifiers & EventModifier.OLD_MASK) != 0) - { - if ((modifiers & BUTTON1_MASK) != 0) - button = BUTTON1; - else if ((modifiers & BUTTON2_MASK) != 0) - button = BUTTON2; - else if ((modifiers & BUTTON3_MASK) != 0) - button = BUTTON3; - modifiers = EventModifier.extend(modifiers); - } - } -} // class MouseEvent diff --git a/libjava/java/awt/event/MouseListener.java b/libjava/java/awt/event/MouseListener.java deleted file mode 100644 index 4508019e108..00000000000 --- a/libjava/java/awt/event/MouseListener.java +++ /dev/null @@ -1,94 +0,0 @@ -/* MouseListener.java -- listen for mouse clicks and crossing component edges - Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.event; - -import java.util.EventListener; - -/** - * This interface is for classes that wish to receive mouse events other than - * simple motion events. This includes clicks (but not mouse wheel events), - * and crossing component boundaries without change in button status. To - * track moves and drags, use MouseMotionListener, and to track wheel events, - * use MouseWheelListener. To watch a subset of these events, use a - * MouseAdapter. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @see MouseAdapter - * @see MouseEvent - * @since 1.1 - * @status updated to 1.4 - */ -public interface MouseListener extends EventListener -{ - /** - * This method is called when the mouse is clicked (pressed and released - * in short succession) on a component. - * - * @param event the <code>MouseEvent</code> indicating the click - */ - void mouseClicked(MouseEvent event); - - /** - * This method is called when the mouse is pressed over a component. - * - * @param event the <code>MouseEvent</code> for the press - */ - void mousePressed(MouseEvent event); - - /** - * This method is called when the mouse is released over a component. - * - * @param event the <code>MouseEvent</code> for the release - */ - void mouseReleased(MouseEvent event); - - /** - * This method is called when the mouse enters a component. - * - * @param event the <code>MouseEvent</code> for the entry - */ - void mouseEntered(MouseEvent event); - - /** - * This method is called when the mouse exits a component. - * - * @param event the <code>MouseEvent</code> for the exit - */ - void mouseExited(MouseEvent event); -} // interface MouseListener diff --git a/libjava/java/awt/event/MouseMotionAdapter.java b/libjava/java/awt/event/MouseMotionAdapter.java deleted file mode 100644 index 8a295f66cc0..00000000000 --- a/libjava/java/awt/event/MouseMotionAdapter.java +++ /dev/null @@ -1,79 +0,0 @@ -/* MouseMotionAdapter.java -- convenience class for mouse motion listeners - Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.event; - -/** - * This class implements <code>MouseMotionListener</code> and implements all - * methods with empty bodies. This allows a listener interested in - * implementing only a subset of the <code>MouseMotionListener</code> - * interface to extend this class and override only the desired methods. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @see MouseEvent - * @see MouseMotionListener - * @since 1.1 - * @status updated to 1.4 - */ -public abstract class MouseMotionAdapter implements MouseMotionListener -{ - /** - * Do nothing default constructor for subclasses. - */ - public MouseMotionAdapter() - { - } - - /** - * Implement this method in the interface with an empty body. - * - * @param event the event, ignored in this implementation - */ - public void mouseDragged(MouseEvent event) - { - } - - /** - * Implement this method in the interface with an empty body. - * - * @param event the event, ignored in this implementation - */ - public void mouseMoved(MouseEvent event) - { - } -} // class MouseMotionAdapter diff --git a/libjava/java/awt/event/MouseMotionListener.java b/libjava/java/awt/event/MouseMotionListener.java deleted file mode 100644 index ba2c5698b11..00000000000 --- a/libjava/java/awt/event/MouseMotionListener.java +++ /dev/null @@ -1,72 +0,0 @@ -/* MouseMotionListener.java -- listen to mouse motion events - Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.event; - -import java.util.EventListener; - -/** - * This interface is for classes that wish to be notified of mouse movements. - * This includes moves and drags, but not crossing component boundaries. To - * track other mouse events, use MouseListener or MouseWheelListener. To - * watch a subset of these events, use a MouseMotionAdapter. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @see MouseMotionAdapter - * @see MouseEvent - * @since 1.1 - * @status updated to 1.4 - */ -public interface MouseMotionListener extends EventListener -{ - /** - * This method is called when the mouse is moved over a component - * while a button has been pressed. - * - * @param event the <code>MouseEvent</code> indicating the motion - */ - void mouseDragged(MouseEvent event); - - /** - * This method is called when the mouse is moved over a component - * while no button is pressed. - * - * @param event the <code>MouseEvent</code> indicating the motion - */ - void mouseMoved(MouseEvent event); -} // interface MouseMotionListener diff --git a/libjava/java/awt/event/MouseWheelEvent.java b/libjava/java/awt/event/MouseWheelEvent.java deleted file mode 100644 index 04286088bd1..00000000000 --- a/libjava/java/awt/event/MouseWheelEvent.java +++ /dev/null @@ -1,226 +0,0 @@ -/* MouseWheelEvent.java -- a mouse wheel event - Copyright (C) 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.event; - -import java.awt.Component; - -/** - * This event is generated for a mouse wheel rotation. The wheel (the middle - * mouse button on most modern mice) can be rotated towards or away from the - * user, and is ofteh used for scrolling. - * - * <p>Because of the special use for scrolling components, MouseWheelEvents - * often affect a different component than the one located at the point of - * the event. If the component under the mouse cursor does not accept wheel - * events, the event is passed to the first ancestor container which does. This - * is often a ScrollPane, which knows how to scroll. If an AWT component is - * built from a native widget that knows how to use mouse wheel events, that - * component will consume the event. - * - * <p>The two most common scroll types are "units" (lines at a time) or - * "blocks" (pages at a time). The initial setting is taken from the platform, - * although the user can adjust the setting at any time. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @see MouseWheelListener - * @see ScrollPane - * @see ScrollPane#setWheelScrollingEnabled(boolean) - * @see JScrollPane - * @see JScrollPane#setWheelScrollingEnabled(boolean) - * @since 1.4 - * @status updated to 1.4 - */ -public class MouseWheelEvent extends MouseEvent -{ - /** - * Compatible with JDK 1.4+. - */ - private static final long serialVersionUID = 6459879390515399677L; - - /** - * Indicates scrolling by units (lines). - * - * @see #getScrollType() - */ - public static final int WHEEL_UNIT_SCROLL = 0; - - /** - * Indicates scrolling by blocks (pages). - * - * @see #getScrollType() - */ - public static final int WHEEL_BLOCK_SCROLL = 1; - - /** - * Indicates what scroll type should take place. This should be limited - * to {@link #WHEEL_UNIT_SCROLL} and {@link #WHEEL_BLOCK_SCROLL}. - * - * @serial the scroll type - */ - private final int scrollType; - - /** - * Indicates the scroll amount. This is only meaningful if scrollType is - * WHEEL_UNIT_SCROLL. - * - * @serial the number of lines to scroll - */ - private final int scrollAmount; - - /** - * Indicates how far the mouse wheel was rotated. - * - * @serial the rotation amount - */ - private final int wheelRotation; - - /** - * Initializes a new instance of <code>MouseWheelEvent</code> with the - * specified information. Note that an invalid id leads to unspecified - * results. - * - * @param source the source of the event - * @param id the event id - * @param when the timestamp of when the event occurred - * @param modifiers any modifier bits for this event - * @param x the X coordinate of the mouse point - * @param y the Y coordinate of the mouse point - * @param clickCount the number of mouse clicks for this event - * @param popupTrigger true if this event triggers a popup menu - * @param scrollType one of {@link #WHEEL_UNIT_SCROLL}, - * {@link #WHEEL_BLOCK_SCROLL} - * @param scrollAmount the number of units to scroll, ignored for block type - * @param wheelRotation the number of rotation "clicks" - * @throws IllegalArgumentException if source is null - * @see MouseEvent#MouseEvent(Component, int, long, int, int, int, int, - * boolean) - */ - public MouseWheelEvent(Component source, int id, long when, int modifiers, - int x, int y, int clickCount, boolean popupTrigger, - int scrollType, int scrollAmount, int wheelRotation) - { - super(source, id, when, modifiers, x, y, clickCount, popupTrigger); - this.scrollType = scrollType; - this.scrollAmount = scrollAmount; - this.wheelRotation = wheelRotation; - } - - /** - * This method returns the scrolling pattern this event requests. Legal - * values are WHEEL_UNIT_SCROLL and WHEEL_BLOCK_SCROLL. - * - * @return the scroll type - * @see Adjustable#getUnitIncrement() - * @see Adjustable#getBlockIncrement() - * @see Scrollable#getScrollableUnitIncrement(Rectangle, int, int) - * @see Scrollable#getScrollableBlockIncrement(Rectangle, int, int) - */ - public int getScrollType() - { - return scrollType; - } - - /** - * Returns the number of units to scroll in response to this event. This - * only makes sense when the scroll type is WHEEL_UNIT_SCROLL. - * - * @return the number of scroll units, if defined - * @see #getScrollType() - */ - public int getScrollAmount() - { - return scrollAmount; - } - - /** - * Gets the number of "clicks" the wheel was rotated. Negative values move - * up (away) from the user, positive values move down (towards) the user. - * - * @return the number of rotation clicks - */ - public int getWheelRotation() - { - return wheelRotation; - } - - /** - * This is a convenience method which aids in a common listener for scrolling - * a scrollpane (although this is already built into ScrollPane and - * JScrollPane). This method only makes sense when getScrollType() returns - * WHEEL_UNIT_SCROLL. - * - * <p>This accounts for direction of scroll and amount of wheel movement, as - * interpreted by the platform settings. - * - * @return the number of units to scroll - * @see #getScrollType() - * @see #getScrollAmount() - * @see MouseWheelListener - * @see Adjustable - * @see Adjustable#getUnitIncrement() - * @see Scrollable - * @see Scrollable#getScrollableUnitIncrement(Rectangle, int, int) - * @see ScrollPane - * @see ScrollPane#setWheelScrollingEnabled(boolean) - * @see JScrollPane - * @see JScrollPane#setWheelScrollingEnabled(boolean) - */ - public int getUnitsToScroll() - { - return wheelRotation * scrollAmount; - } - - /** - * Returns a string identifying this event. For mouse wheel events, this - * is <code>super.paramString() + ",scrollType=WHEEL_" + - * (getScrollType() == WHEEL_UNIT_SCROLL ? "UNIT" : "BLOCK") - * + "_SCROLL,scrollAmount=" + getScrollAmount() + ",wheelRotation=" - * + getWheelRotation()</code>. - * - * @return a string identifying this event - */ - public String paramString() - { - return super.paramString() + ",scrollType=" - + (scrollType == WHEEL_UNIT_SCROLL ? "WHEEL_UNIT_SCROLL" - : scrollType == WHEEL_BLOCK_SCROLL ? "WHEEL_BLOCK_SCROLL" - : "unknown scroll type") - + ",scrollAmount=" + scrollAmount + ",wheelRotation=" + wheelRotation; - } -} // class MouseWheelEvent diff --git a/libjava/java/awt/event/MouseWheelListener.java b/libjava/java/awt/event/MouseWheelListener.java deleted file mode 100644 index 1125582e1df..00000000000 --- a/libjava/java/awt/event/MouseWheelListener.java +++ /dev/null @@ -1,60 +0,0 @@ -/* MouseWheelListener.java -- listen for mouse wheel events - Copyright (C) 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.event; - -import java.util.EventListener; - -/** - * This interface is for classes that wish to receive mouse wheel events. For - * other events, use MouseListener or MouseMotionListener. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @see MouseWheelEvent - * @since 1.4 - * @status updated to 1.4 - */ -public interface MouseWheelListener extends EventListener -{ - /** - * This method is called when the mouse wheel is rotated. - * - * @param event the <code>MouseWheelEvent</code> indicating the rotation - */ - void mouseWheelMoved(MouseWheelEvent event); -} // interface MouseWheelListener diff --git a/libjava/java/awt/event/PaintEvent.java b/libjava/java/awt/event/PaintEvent.java deleted file mode 100644 index bb89c3722b5..00000000000 --- a/libjava/java/awt/event/PaintEvent.java +++ /dev/null @@ -1,127 +0,0 @@ -/* PaintEvent.java -- an area of the screen needs to be repainted - Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.event; - -import java.awt.Component; -import java.awt.Rectangle; - -/** - * This event is generated when an area of the screen needs to be painted. - * This event is not meant for users, but exists to allow proper serialization - * behavior in the EventQueue with user-accessible events. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @since 1.1 - * @status updated to 1.4 - */ -public class PaintEvent extends ComponentEvent -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = 1267492026433337593L; - - /** This is the first id in the range of event ids used by this class. */ - public static final int PAINT_FIRST = 800; - - /** This is the last id in the range of event ids used by this class. */ - public static final int PAINT_LAST = 801; - - /** This id is for paint event types. */ - public static final int PAINT = 800; - - /** This id is for update event types. */ - public static final int UPDATE = 801; - - /** - * This is the rectange to be painted or updated. - * - * @see #getUpdateRect() - * @see #setUpdateRect(Rectangle) - * @serial the non-null rectangle to be painted - */ - private Rectangle updateRect; - - /** - * Initializes a new instance of <code>PaintEvent</code> with the specified - * source, id, and update region. Note that an invalid id leads to - * unspecified results. - * - * @param source the event source - * @param id the event id - * @param updateRect the rectangle to repaint - * @throws IllegalArgumentException if source is null - */ - public PaintEvent(Component source, int id, Rectangle updateRect) - { - super(source, id); - this.updateRect = updateRect; - } - - /** - * Returns the rectange to be updated for this event. - * - * @return the rectangle to update - */ - public Rectangle getUpdateRect() - { - return updateRect; - } - - /** - * Sets the rectangle to be updated for this event. - * - * @param updateRect the new update rectangle for this event - */ - public void setUpdateRect(Rectangle updateRect) - { - this.updateRect = updateRect; - } - - /** - * Returns a string identifying this event. - * - * @return a string identifying this event - */ - public String paramString() - { - return (id == PAINT ? "PAINT,updateRect=" : id == UPDATE - ? "UPDATE,updateRect=" : "unknown type,updateRect=") + updateRect; - } -} // class PaintEvent diff --git a/libjava/java/awt/event/TextEvent.java b/libjava/java/awt/event/TextEvent.java deleted file mode 100644 index 43f4bb0e95b..00000000000 --- a/libjava/java/awt/event/TextEvent.java +++ /dev/null @@ -1,92 +0,0 @@ -/* TextEvent.java -- event for text changes - Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.event; - -import java.awt.AWTEvent; - -/** - * This event is generated when a text box changes contents. This is an - * abstraction that distills a large number of individual mouse or keyboard - * events into a simpler "text changed" event. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @see TextComponent - * @see TextListener - * @since 1.1 - * @status updated to 1.4 - */ -public class TextEvent extends AWTEvent -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = 6269902291250941179L; - - /** This is the first id in the range of event ids used by this class. */ - public static final int TEXT_FIRST = 900; - - /** This is the last id in the range of event ids used by this class. */ - public static final int TEXT_LAST = 900; - - /** This event id indicates that the text of an object has changed. */ - public static final int TEXT_VALUE_CHANGED = 900; - - /** - * Initializes a new instance of <code>TextEvent</code> with the specified - * source and id. Note that an invalid id leads to unspecified results. - * - * @param source the (TextComponent) object that generated this event - * @param id the event id - * @throws IllegalArgumentException if source is null - */ - public TextEvent(Object source, int id) - { - super(source, id); - } - - /** - * Returns a string identifying this event. This is "TEXT_VALUE_CHANGED". - * - * @return a string identifying this event - */ - public String paramString() - { - return id == TEXT_VALUE_CHANGED ? "TEXT_VALUE_CHANGED" : "unknown type"; - } -} // class TextEvent diff --git a/libjava/java/awt/event/TextListener.java b/libjava/java/awt/event/TextListener.java deleted file mode 100644 index bcdd7fa7a11..00000000000 --- a/libjava/java/awt/event/TextListener.java +++ /dev/null @@ -1,60 +0,0 @@ -/* TextListener.java -- listen for text changes - Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.event; - -import java.util.EventListener; - -/** - * This interface is for classes that wish to be notified when text changes - * in a component. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @see TextEvent - * @since 1.1 - * @status updated to 1.4 - */ -public interface TextListener extends EventListener -{ - /** - * This method is called when the text being monitored changes. - * - * @param event the <code>TextEvent</code> indicating the change - */ - void textValueChanged(TextEvent event); -} // interface TextListener diff --git a/libjava/java/awt/event/WindowAdapter.java b/libjava/java/awt/event/WindowAdapter.java deleted file mode 100644 index 708de588c05..00000000000 --- a/libjava/java/awt/event/WindowAdapter.java +++ /dev/null @@ -1,156 +0,0 @@ -/* WindowAdapter.java -- convenience class for writing window listeners - Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.event; - -/** - * This class implements <code>WindowListener</code>, - * <code>WindowStateListener</code>, and <code>WindowFocusListener</code>, and - * implements all methods with empty bodies. This allows a listener - * interested in listening to only a subset of any <code>WindowEvent</code> - * actions to extend this class and override only the desired methods. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @see ComponentEvent - * @see ComponentListener - * @since 1.1 - * @status updated to 1.4 - */ -public abstract class WindowAdapter - implements WindowListener, WindowStateListener, WindowFocusListener -{ - /** - * Do nothing default constructor for subclasses. - */ - public WindowAdapter() - { - } - - /** - * Implements this method from the interface with an empty method body. - * - * @param event the event, ignored in this implementation - */ - public void windowOpened(WindowEvent event) - { - } - - /** - * Implements this method from the interface with an empty method body. - * - * @param event the event, ignored in this implementation - */ - public void windowClosing(WindowEvent event) - { - } - - /** - * Implements this method from the interface with an empty method body. - * - * @param event the event, ignored in this implementation - */ - public void windowClosed(WindowEvent event) - { - } - - /** - * Implements this method from the interface with an empty method body. - * - * @param event the event, ignored in this implementation - */ - public void windowIconified(WindowEvent event) - { - } - - /** - * Implements this method from the interface with an empty method body. - * - * @param event the event, ignored in this implementation - */ - public void windowDeiconified(WindowEvent event) - { - } - - /** - * Implements this method from the interface with an empty method body. - * - * @param event the event, ignored in this implementation - */ - public void windowActivated(WindowEvent event) - { - } - - /** - * Implements this method from the interface with an empty method body. - * - * @param event the event, ignored in this implementation - */ - public void windowDeactivated(WindowEvent event) - { - } - - /** - * Implements this method from the interface with an empty method body. - * - * @param event the event, ignored in this implementation - * @since 1.4 - */ - public void windowStateChanged(WindowEvent event) - { - } - - /** - * Implements this method from the interface with an empty method body. - * - * @param event the event, ignored in this implementation - * @since 1.4 - */ - public void windowGainedFocus(WindowEvent event) - { - } - - /** - * Implements this method from the interface with an empty method body. - * - * @param event the event, ignored in this implementation - * @since 1.4 - */ - public void windowLostFocus(WindowEvent event) - { - } -} // class WindowAdapter diff --git a/libjava/java/awt/event/WindowEvent.java b/libjava/java/awt/event/WindowEvent.java deleted file mode 100644 index 19229ca9dbc..00000000000 --- a/libjava/java/awt/event/WindowEvent.java +++ /dev/null @@ -1,311 +0,0 @@ -/* WindowEvent.java -- window change event - Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.event; - -import java.awt.Window; - -/** - * This event is generated when there is a change in a window. This includes - * creation, closing, iconification, activation, and focus changes. There - * are three listeners, for three types of events: WindowListeners deal with - * the lifecycle of a window, WindowStateListeners deal with window state - * like maximization, and WindowFocusListeners deal with focus switching to - * or from a window. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @see WindowAdapter - * @see WindowListener - * @see WindowFocusListener - * @see WindowStateListener - * @since 1.1 - * @status updated to 1.4 - */ -public class WindowEvent extends ComponentEvent -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = -1567959133147912127L; - - /** This is the first id in the range of event ids used by this class. */ - public static final int WINDOW_FIRST = 200; - - /** This is the id for a window that is opened. */ - public static final int WINDOW_OPENED = 200; - - /** This is the id for a window that is about to close. */ - public static final int WINDOW_CLOSING = 201; - - /** This is the id for a window that finished closing. */ - public static final int WINDOW_CLOSED = 202; - - /** This is the id for a window that is iconified. */ - public static final int WINDOW_ICONIFIED = 203; - - /** This is the id for a window that is de-iconified. */ - public static final int WINDOW_DEICONIFIED = 204; - - /** This is the id for a window that is activated. */ - public static final int WINDOW_ACTIVATED = 205; - - /** This is the id for a window that is de-activated. */ - public static final int WINDOW_DEACTIVATED = 206; - - /** - * This is the id for a window becoming the focused window. - * - * @since 1.4 - */ - public static final int WINDOW_GAINED_FOCUS = 207; - - /** - * This is the id for a window losing all focus. - * - * @since 1.4 - */ - public static final int WINDOW_LOST_FOCUS = 208; - - /** - * This is the id for a window state change, such as maximization. - * - * @since 1.4 - */ - public static final int WINDOW_STATE_CHANGED = 209; - - /** This is the last id in the range of event ids used by this class. */ - public static final int WINDOW_LAST = 209; - - /** - * The other Window involved in a focus or activation change. For - * WINDOW_ACTIVATED and WINDOW_GAINED_FOCUS events, this is the window that - * lost focus; for WINDOW_DEACTIVATED and WINDOW_LOST_FOCUS, this is the - * window that stole focus; and for other events (or when native - * implementation does not have the data available), this is null. - * - * @see #getOppositeWindow() - * @serial the opposite window, or null - * @since 1.4 - */ - private final Window opposite; - - /** - * The former state of the window. - * - * @serial bitmask of the old window state - * @since 1.4 - */ - private final int oldState; - - /** - * The present state of the window. - * - * @serial bitmask of the new window state - * @since 1.4 - */ - private final int newState; - - /** - * Initializes a new instance of <code>WindowEvent</code> with the specified - * parameters. Note that an invalid id leads to unspecified results. - * - * @param source the window that generated this event - * @param id the event id - * @param opposite the window that received the opposite event, or null - * @param oldState the previous state of this window - * @param newState the new state of this window - * @throws IllegalArgumentException if source is null - * @since 1.4 - */ - public WindowEvent(Window source, int id, Window opposite, - int oldState, int newState) - { - super(source, id); - this.opposite = opposite; - this.oldState = oldState; - this.newState = newState; - } - - /** - * Initializes a new instance of <code>WindowEvent</code> with the specified - * parameters. Note that an invalid id leads to unspecified results. - * - * @param source the window that generated this event - * @param id the event id - * @param opposite the window that received the opposite event, or null - * @throws IllegalArgumentException if source is null - * @since 1.4 - */ - public WindowEvent(Window source, int id, Window opposite) - { - this(source, id, opposite, 0, 0); - } - - /** - * Initializes a new instance of <code>WindowEvent</code> with the specified - * parameters. Note that an invalid id leads to unspecified results. - * - * @param source the window that generated this event - * @param id the event id - * @param oldState the previous state of this window - * @param newState the new state of this window - * @throws IllegalArgumentException if source is null - * @since 1.4 - */ - public WindowEvent(Window source, int id, int oldState, int newState) - { - this(source, id, null, oldState, newState); - } - - /** - * Initializes a new instance of <code>WindowEvent</code> with the specified - * parameters. Note that an invalid id leads to unspecified results. - * - * @param source the window that generated this event - * @param id the event id - * @throws IllegalArgumentException if source is null - */ - public WindowEvent(Window source, int id) - { - this(source, id, null, 0, 0); - } - - /** - * Returns the event source as a <code>Window</code>. If the source has - * subsequently been modified to a non-Window, this returns null. - * - * @return the event source as a <code>Window</code> - */ - public Window getWindow() - { - return source instanceof Window ? (Window) source : null; - } - - /** - * Returns the opposite window if this window was involved in an activation - * or focus change. For WINDOW_ACTIVATED and WINDOW_GAINED_FOCUS events, - * this is the window that lost focus; for WINDOW_DEACTIVATED and - * WINDOW_LOST_FOCUS, this is the window that stole focus; and for other - * events (or when native implementation does not have the data available), - * this is null. - * - * @return the opposite window, or null - * @since 1.4 - */ - public Window getOppositeWindow() - { - return opposite; - } - - /** - * Returns the state of this window before the event. This is the bitwise - * or of fields in Frame: NORMAL, ICONIFIED, MAXIMIZED_HORIZ, MAXIMIZED_VERT, - * and MAXIMIZED_BOTH. - * - * @return the former state - * @see Frame#getExtendedState() - * @since 1.4 - */ - public int getOldState() - { - return oldState; - } - - /** - * Returns the state of this window after the event. This is the bitwise - * or of fields in Frame: NORMAL, ICONIFIED, MAXIMIZED_HORIZ, MAXIMIZED_VERT, - * and MAXIMIZED_BOTH. - * - * @return the updated state - * @see Frame#getExtendedState() - * @since 1.4 - */ - public int getNewState() - { - return newState; - } - - /** - * Returns a string that identifies this event. This is formatted as the - * field name of the id, followed by the opposite window, old state, and - * new state. - * - * @return a string that identifies this event - */ - public String paramString() - { - StringBuffer s = new StringBuffer(); - switch (id) - { - case WINDOW_OPENED: - s.append("WINDOW_OPENED,opposite="); - break; - case WINDOW_CLOSING: - s.append("WINDOW_CLOSING,opposite="); - break; - case WINDOW_CLOSED: - s.append("WINDOW_CLOSED,opposite="); - break; - case WINDOW_ICONIFIED: - s.append("WINDOW_ICONIFIED,opposite="); - break; - case WINDOW_DEICONIFIED: - s.append("WINDOW_DEICONIFIED,opposite="); - break; - case WINDOW_ACTIVATED: - s.append("WINDOW_ACTIVATED,opposite="); - break; - case WINDOW_DEACTIVATED: - s.append("WINDOW_DEACTIVATED,opposite="); - break; - case WINDOW_GAINED_FOCUS: - s.append("WINDOW_GAINED_FOCUS,opposite="); - break; - case WINDOW_LOST_FOCUS: - s.append("WINDOW_LOST_FOCUS,opposite="); - break; - case WINDOW_STATE_CHANGED: - s.append("WINDOW_STATE_CHANGED,opposite="); - break; - default: - s.append("unknown type,opposite="); - } - return s.append(opposite).append(",oldState=").append(oldState) - .append(",newState=").append(newState).toString(); - } -} // class WindowEvent diff --git a/libjava/java/awt/event/WindowFocusListener.java b/libjava/java/awt/event/WindowFocusListener.java deleted file mode 100644 index 738425353e3..00000000000 --- a/libjava/java/awt/event/WindowFocusListener.java +++ /dev/null @@ -1,68 +0,0 @@ -/* WindowFocusListener.java -- listens for window focus events - Copyright (C) 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.event; - -import java.util.EventListener; - -/** - * This interface is for classes that wish to monitor events for window - * focus changes. To watch a subset of these events, use a WindowAdapter. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @see WindowAdapter - * @see WindowEvent - * @since 1.4 - * @status updated to 1.4 - */ -public interface WindowFocusListener extends EventListener -{ - /** - * This method is called when a window gains focus. - * - * @param event the <code>WindowEvent</code> indicating the focus change - */ - void windowGainedFocus(WindowEvent event); - - /** - * This method is called when a window loses focus. - * - * @param event the <code>WindowEvent</code> indicating the focus change - */ - void windowLostFocus(WindowEvent event); -} // interface WindowFocusListener diff --git a/libjava/java/awt/event/WindowListener.java b/libjava/java/awt/event/WindowListener.java deleted file mode 100644 index 3b0a1da23ef..00000000000 --- a/libjava/java/awt/event/WindowListener.java +++ /dev/null @@ -1,107 +0,0 @@ -/* WindowListener.java -- listens for window events - Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.event; - -import java.util.EventListener; - -/** - * This interface is for classes that wish to monitor events for window - * changes. To watch a subset of these events, use a WindowAdapter. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @see WindowAdapter - * @see WindowEvent - * @since 1.1 - * @status updated to 1.4 - */ -public interface WindowListener extends EventListener -{ - /** - * This method is called when the window is made visible. - * - * @param event the <code>WindowEvent</code> indicating the change - */ - void windowOpened(WindowEvent event); - - /** - * This method is called when the user calls the system menu close - * function, giving the program a chance to cancel the close. - * - * @param event the <code>WindowEvent</code> indicating the close attempt - */ - void windowClosing(WindowEvent event); - - /** - * This method is called when the window is closed. - * - * @param event the <code>WindowEvent</code> indicating the dispose - */ - void windowClosed(WindowEvent event); - - /** - * This method is called when the window is iconified. - * - * @param event the <code>WindowEvent</code> indicating the iconification - * @see Frame#setIconImage(Image) - */ - void windowIconified(WindowEvent event); - - /** - * This method is called when the window is deiconified. - * - * @param event the <code>WindowEvent</code> indicating the deiconification - */ - void windowDeiconified(WindowEvent event); - - /** - * This method is called when a window is activated. Only Frames and Dialogs - * can be active, and the active window always contains the component with - * focus. - * - * @param event the <code>WindowEvent</code> indicating the activation - */ - void windowActivated(WindowEvent event); - - /** - * This method is called when the window is deactivated. - * - * @param event the <code>WindowEvent</code> indicating the deactivation - */ - void windowDeactivated(WindowEvent event); -} // interface WindowListener diff --git a/libjava/java/awt/event/WindowStateListener.java b/libjava/java/awt/event/WindowStateListener.java deleted file mode 100644 index 9bc6174fda1..00000000000 --- a/libjava/java/awt/event/WindowStateListener.java +++ /dev/null @@ -1,62 +0,0 @@ -/* WindowStateListener.java -- listens for window state changes - Copyright (C) 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.event; - -import java.util.EventListener; - -/** - * This interface is for classes that wish to monitor events for window - * state changes. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @see WindowAdapter - * @see WindowEvent - * @since 1.4 - * @status updated to 1.4 - */ -public interface WindowStateListener extends EventListener -{ - /** - * This method is called when the window state is changed, because of - * iconification or maximization. - * - * @param event the <code>WindowEvent</code> indicating the change - */ - void windowStateChanged(WindowEvent event); -} // interface WindowStateListener diff --git a/libjava/java/awt/font/FontRenderContext.java b/libjava/java/awt/font/FontRenderContext.java deleted file mode 100644 index 78564a647da..00000000000 --- a/libjava/java/awt/font/FontRenderContext.java +++ /dev/null @@ -1,126 +0,0 @@ -/* FontRenderContext.java - Copyright (C) 2002, 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.font; - -import java.awt.geom.AffineTransform; - -/** - * @author Michael Koch - */ -public class FontRenderContext -{ - private AffineTransform affineTransform; - private boolean isAntiAliased; - private boolean usesFractionalMetrics; - - /** - * Construct a new <code>FontRenderContext</code>. - */ - protected FontRenderContext() - { - // Do nothing here. - } - - /** - * Construct a new <code>FontRenderContext</code>. - */ - public FontRenderContext (AffineTransform tx, boolean isAntiAliased, - boolean usesFractionalMetrics) - { - if (tx != null - && !tx.isIdentity ()) - { - this.affineTransform = new AffineTransform (tx); - } - - this.isAntiAliased = isAntiAliased; - this.usesFractionalMetrics = usesFractionalMetrics; - } - - public boolean equals (Object obj) - { - if (! (obj instanceof FontRenderContext)) - return false; - - return equals ((FontRenderContext) obj); - } - - public boolean equals (FontRenderContext rhs) - { - return (affineTransform.equals (rhs.getTransform ()) - && isAntiAliased == rhs.isAntiAliased () - && usesFractionalMetrics == rhs.usesFractionalMetrics ()); - } - - - /** - * Retrieves the affine transform for scaling typographical points - * to raster pixels. - * - * @return a clone of the transform object. - */ - public AffineTransform getTransform () - { - if (affineTransform == null) - return new AffineTransform (); - else - return new AffineTransform (affineTransform); - } - - - /** - * Returns the hash code of the font render context. - */ - public int hashCode () - { - // FIXME: check what SUN does here. - return affineTransform == null ? 0 : affineTransform.hashCode (); - } - - public boolean isAntiAliased () - { - return isAntiAliased; - } - - public boolean usesFractionalMetrics () - { - return usesFractionalMetrics; - } -} - diff --git a/libjava/java/awt/font/GlyphJustificationInfo.java b/libjava/java/awt/font/GlyphJustificationInfo.java deleted file mode 100644 index 5f45fd58498..00000000000 --- a/libjava/java/awt/font/GlyphJustificationInfo.java +++ /dev/null @@ -1,77 +0,0 @@ -/* GlyphJustificationInfo.java - Copyright (C) 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.font; - -/** - * @author Michael Koch - */ -public final class GlyphJustificationInfo -{ - public static final int PRIORITY_KASHIDA = 0; - public static final int PRIORITY_WHITESPACE = 1; - public static final int PRIORITY_INTERCHAR = 2; - public static final int PRIORITY_NONE = 3; - - public final float weight; - public final int growPriority; - public final boolean growAbsorb; - public final float growLeftLimit; - public final float growRightLimit; - public final int shrinkPriority; - public final boolean shrinkAbsorb; - public final float shrinkLeftLimit; - public final float shrinkRightLimit; - - public GlyphJustificationInfo (float weight, boolean growAbsorb, - int growPriority, float growLeftLimit, - float growRightLimit, boolean shrinkAbsorb, - int shrinkPriority, float shrinkLeftLimit, - float shrinkRightLimit) - { - this.weight = weight; - this.growAbsorb = growAbsorb; - this.growPriority = growPriority; - this.growLeftLimit = growLeftLimit; - this.growRightLimit = growRightLimit; - this.shrinkAbsorb = shrinkAbsorb; - this.shrinkPriority = shrinkPriority; - this.shrinkLeftLimit = shrinkLeftLimit; - this.shrinkRightLimit = shrinkRightLimit; - } -} diff --git a/libjava/java/awt/font/GlyphMetrics.java b/libjava/java/awt/font/GlyphMetrics.java deleted file mode 100644 index 28b2088cf8e..00000000000 --- a/libjava/java/awt/font/GlyphMetrics.java +++ /dev/null @@ -1,134 +0,0 @@ -/* GlyphMetrics.java - Copyright (C) 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.font; - -import java.awt.geom.Rectangle2D; - -/** - * @author Michael Koch - */ -public final class GlyphMetrics -{ - public static final byte COMBINING = 2; - public static final byte COMPONENT = 3; - public static final byte LIGATURE = 1; - public static final byte STANDARD = 0; - public static final byte WHITESPACE = 4; - - private boolean horizontal; - private float advanceX; - private float advanceY; - private Rectangle2D bounds; - private byte glyphType; - - public GlyphMetrics (boolean horizontal, float advanceX, float advanceY, - Rectangle2D bounds, byte glyphType) - { - this.horizontal = horizontal; - this.advanceX = advanceX; - this.advanceY = advanceY; - this.bounds = bounds; - this.glyphType = glyphType; - } - - public GlyphMetrics (float advance, Rectangle2D bounds, byte glyphType) - { - this (true, advance, advance, bounds, glyphType); - } - - public float getAdvance () - { - return horizontal ? advanceX : advanceY; - } - - public float getAdvanceX () - { - return advanceX; - } - - public float getAdvanceY () - { - return advanceY; - } - - public Rectangle2D getBounds2D () - { - return bounds; - } - - public float getLSB () - { - throw new Error ("not implemented"); - } - - public float getRSB () - { - throw new Error ("not implemented"); - } - - public int getType () - { - return glyphType; - } - - public boolean isCombining () - { - return (glyphType == COMBINING); - } - - public boolean isComponent () - { - return (glyphType == COMPONENT); - } - - public boolean isLigature() - { - return (glyphType == LIGATURE); - } - - public boolean isStandard() - { - return (glyphType == STANDARD); - } - - public boolean isWhitespace() - { - return (glyphType == WHITESPACE); - } -} diff --git a/libjava/java/awt/font/GlyphVector.java b/libjava/java/awt/font/GlyphVector.java deleted file mode 100644 index 57e2581edb4..00000000000 --- a/libjava/java/awt/font/GlyphVector.java +++ /dev/null @@ -1,145 +0,0 @@ -/* GlyphVector.java - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.font; - -import java.awt.Font; -import java.awt.Rectangle; -import java.awt.Shape; -import java.awt.geom.AffineTransform; -import java.awt.geom.Point2D; -import java.awt.geom.Rectangle2D; - -/** - * @author Michael Koch - */ -public abstract class GlyphVector implements Cloneable -{ - public static final int FLAG_COMPLEX_GLYPHS = 8; - public static final int FLAG_HAS_POSITION_ADJUSTMENTS = 2; - public static final int FLAG_HAS_TRANSFORMS = 1; - public static final int FLAG_MASK = 15; - public static final int FLAG_RUN_RTL = 4; - - /** - * Constructs a <code>GlyphVector</code> object. - */ - public GlyphVector () - { - } - - public abstract boolean equals (GlyphVector set); - - public abstract Font getFont (); - - public abstract FontRenderContext getFontRenderContext (); - - public int getGlyphCharIndex (int glyphIndex) - { - throw new Error ("not implemented"); - } - - public int[] getGlyphCharIndices (int beginGlyphIndex, int numEntries, - int[] codeReturn) - { - throw new Error ("not implemented"); - } - - public abstract int getGlyphCode (int glyphIndex); - - public abstract int[] getGlyphCodes (int beginGlyphIndex, int numEntries, - int[] codeReturn); - - public abstract GlyphJustificationInfo getGlyphJustificationInfo - (int glyphIndex); - - public abstract Shape getGlyphLogicalBounds (int glyphIndex); - - public abstract GlyphMetrics getGlyphMetrics (int glyphIndex); - - public abstract Shape getGlyphOutline (int glyphIndex); - - public Shape getGlyphOutline (int glyphIndex, float x, float y) - { - throw new Error ("not implemented"); - } - - public Rectangle getGlyphPixelBounds (int index, FontRenderContext renderFRC, - float x, float y) - { - throw new Error ("not implemented"); - } - - public abstract Point2D getGlyphPosition (int glyphIndex); - - public abstract float[] getGlyphPositions (int beginGlyphIndex, - int numEntries, - float[] positionReturn); - - public abstract AffineTransform getGlyphTransform (int glyphIndex); - - public abstract Shape getGlyphVisualBounds (int glyphIndex); - - public int getLayoutFlags () - { - throw new Error ("not implemented"); - } - - public abstract Rectangle2D getLogicalBounds (); - - public abstract int getNumGlyphs (); - - public abstract Shape getOutline (); - - public abstract Shape getOutline (float x, float y); - - public Rectangle getPixelBounds (FontRenderContext renderFRC, - float x, float y) - { - throw new Error ("not implemented"); - } - - public abstract Rectangle2D getVisualBounds (); - - public abstract void performDefaultLayout (); - - public abstract void setGlyphPosition (int glyphIndex, Point2D newPos); - - public abstract void setGlyphTransform (int glyphIndex, - AffineTransform newTX); -} diff --git a/libjava/java/awt/font/GraphicAttribute.java b/libjava/java/awt/font/GraphicAttribute.java deleted file mode 100644 index 79eae9955f5..00000000000 --- a/libjava/java/awt/font/GraphicAttribute.java +++ /dev/null @@ -1,84 +0,0 @@ -/* GraphicAttribute.java - Copyright (C) 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.font; - -import java.awt.Graphics2D; -import java.awt.geom.Rectangle2D; - -/** - * @author Michael Koch - */ -public abstract class GraphicAttribute -{ - public static final int BOTTOM_ALIGNMENT = -2; - public static final int CENTER_BASELINE = 1; - public static final int HANGING_BASELINE = 2; - public static final int ROMAN_BASELINE = 0; - public static final int TOP_ALIGNMENT = -1; - - private int alignment; - - protected GraphicAttribute (int alignment) - { - this.alignment = alignment; - } - - public abstract void draw (Graphics2D graphics, float x, float y); - - public abstract float getAdvance (); - - public final int getAlignment () - { - return alignment; - } - - public abstract float getAscent (); - - public Rectangle2D getBounds () - { - throw new Error ("not implemented"); - } - - public abstract float getDescent (); - - public GlyphJustificationInfo getJustificationInfo () - { - throw new Error ("not implemented"); - } -} diff --git a/libjava/java/awt/font/ImageGraphicAttribute.java b/libjava/java/awt/font/ImageGraphicAttribute.java deleted file mode 100644 index 77413f95dfc..00000000000 --- a/libjava/java/awt/font/ImageGraphicAttribute.java +++ /dev/null @@ -1,109 +0,0 @@ -/* ImageGraphicAttribute.java - Copyright (C) 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.font; - -import java.awt.Graphics2D; -import java.awt.Image; -import java.awt.geom.Rectangle2D; - -/** - * @author Michael Koch - */ -public final class ImageGraphicAttribute extends GraphicAttribute -{ - private Image image; - - public ImageGraphicAttribute (Image image, int alignment) - { - super (alignment); - this.image = image; - } - - public ImageGraphicAttribute (Image image, int alignment, float originX, - float originY) - { - super (alignment); - this.image = image; - - throw new Error ("not implemented"); - } - - public void draw (Graphics2D graphics, float x, float y) - { - throw new Error ("not implemented"); - } - - public boolean equals (Object obj) - { - if (! (obj instanceof ImageGraphicAttribute)) - return false; - - return equals ((ImageGraphicAttribute) obj); - } - - public boolean equals (ImageGraphicAttribute rhs) - { - throw new Error ("not implemented"); - } - - public float getAdvance () - { - throw new Error ("not implemented"); - } - - public float getAscent () - { - throw new Error ("not implemented"); - } - - public Rectangle2D getBounds () - { - throw new Error ("not implemented"); - } - - public float getDescent () - { - throw new Error ("not implemented"); - } - - public int hashCode () - { - throw new Error ("not implemented"); - } -} diff --git a/libjava/java/awt/font/LineBreakMeasurer.java b/libjava/java/awt/font/LineBreakMeasurer.java deleted file mode 100644 index 0a6a96922bd..00000000000 --- a/libjava/java/awt/font/LineBreakMeasurer.java +++ /dev/null @@ -1,113 +0,0 @@ -/* LineBreakMeasurer.java - Copyright (C) 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.font; - -import java.text.AttributedCharacterIterator; -import java.text.BreakIterator; - -public final class LineBreakMeasurer -{ - private AttributedCharacterIterator ci; - private FontRenderContext frc; - private BreakIterator bi; - - /** - * Constructs a <code>LineBreakMeasurer</code> object. - */ - public LineBreakMeasurer (AttributedCharacterIterator text, - FontRenderContext frc) - { - this (text, null, frc); - } - - /** - * Constructs a <code>LineBreakMeasurer</code> object. - */ - public LineBreakMeasurer (AttributedCharacterIterator text, - BreakIterator breakIter, FontRenderContext frc) - { - this.ci = text; - this.bi = breakIter; - this.frc = frc; - } - - public void deleteChar (AttributedCharacterIterator newParagraph, - int deletePos) - { - throw new Error ("not implemented"); - } - - public int getPosition () - { - return ci.getIndex (); - } - - public void insertChar (AttributedCharacterIterator newParagraph, - int insertPos) - { - throw new Error ("not implemented"); - } - - public TextLayout nextLayout (float wrappingWidth) - { - throw new Error ("not implemented"); - } - - public TextLayout nextLayout (float wrappingWidth, int offsetLimit, - boolean requireNextWord) - { - throw new Error ("not implemented"); - } - - public int nextOffset (float wrappingWidth) - { - throw new Error ("not implemented"); - } - - public int nextOffset (float wrappingWidth, int offsetLimit, - boolean requireNextWord) - { - throw new Error ("not implemented"); - } - - public void setPosition (int newPosition) - { - ci.setIndex (newPosition); - } -} diff --git a/libjava/java/awt/font/LineMetrics.java b/libjava/java/awt/font/LineMetrics.java deleted file mode 100644 index 3c45ad19a6e..00000000000 --- a/libjava/java/awt/font/LineMetrics.java +++ /dev/null @@ -1,67 +0,0 @@ -/* LineMetrics.java -- Information about about a line display characteristics - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.font; - -/** - * @author Michael Koch - */ -public abstract class LineMetrics -{ - public abstract float getAscent(); - - public abstract int getBaselineIndex(); - - public abstract float[] getBaselineOffsets(); - - public abstract float getDescent(); - - public abstract float getHeight(); - - public abstract float getLeading(); - - public abstract int getNumChars(); - - public abstract float getStrikethroughOffset(); - - public abstract float getStrikethroughThickness(); - - public abstract float getUnderlineOffset(); - - public abstract float getUnderlineThickness(); -} diff --git a/libjava/java/awt/font/MultipleMaster.java b/libjava/java/awt/font/MultipleMaster.java deleted file mode 100644 index 57417ea6010..00000000000 --- a/libjava/java/awt/font/MultipleMaster.java +++ /dev/null @@ -1,61 +0,0 @@ -/* MultipleMaster.java - Copyright (C) 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.font; - -import java.awt.Font; - -/** - * @author Michael Koch - */ -public interface MultipleMaster -{ - Font deriveMMFont (float[] axes); - - Font deriveMMFont (float[] glyphWidths, float avgStemWidth, - float typicalCapHeight, float typicalXHeight, - float italicAngle); - - float[] getDesignAxisDefaults(); - - String[] getDesignAxisNames(); - - float[] getDesignAxisRanges(); - - int getNumDesignAxes(); -} diff --git a/libjava/java/awt/font/NumericShaper.java b/libjava/java/awt/font/NumericShaper.java deleted file mode 100644 index efbdcd49dc4..00000000000 --- a/libjava/java/awt/font/NumericShaper.java +++ /dev/null @@ -1,137 +0,0 @@ -/* NumericShaper.java - Copyright (C) 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.font; - -import java.io.Serializable; - -/** - * @author Michael Koch - * @since 1.4 - */ -public final class NumericShaper implements Serializable -{ - private static final long serialVersionUID = -8022764705923730308L; - - public static final int ALL_RANGES = 524287; - public static final int ARABIC = 2; - public static final int BENGALI = 16; - public static final int DEVANAGARI = 8; - public static final int EASTERN_ARABIC = 4; - public static final int ETHIOPIC = 65536; - public static final int EUROPEAN = 1; - public static final int GUJARATI = 64; - public static final int GURMUKHI = 32; - public static final int KANNADA = 1024; - public static final int KHMER = 131072; - public static final int LAO = 8192; - public static final int MALAYALAM = 2048; - public static final int MONGOLIAN = 262144; - public static final int MYANMAR = 32768; - public static final int ORIYA = 128; - public static final int TAMIL = 256; - public static final int TELUGU = 512; - public static final int THAI = 4096; - public static final int TIBETAN = 16384; - - private int ranges; - private int context; - - private NumericShaper (int ranges, int context) - { - this.ranges = ranges; - this.context = context; - } - - public boolean equals (Object obj) - { - if (! (obj instanceof NumericShaper)) - return false; - - NumericShaper tmp = (NumericShaper) obj; - - return (ranges == tmp.ranges - && context == tmp.context); - } - - public static NumericShaper getContextualShaper (int ranges) - { - throw new Error ("not implemented"); - } - - public static NumericShaper getContextualShaper (int ranges, - int defaultContext) - { - throw new Error ("not implemented"); - } - - public int getRanges () - { - return ranges; - } - - public static NumericShaper getShaper (int singleRange) - { - throw new Error ("not implemented"); - } - - public int hashCode () - { - throw new Error ("not implemented"); - } - - public boolean isContextual () - { - throw new Error ("not implemented"); - } - - public void shape (char[] text, int start, int count) - { - shape (text, start, count, context); - } - - public void shape (char[] text, int start, int count, int context) - { - throw new Error ("not implemented"); - } - - public String toString () - { - throw new Error ("not implemented"); - } -} diff --git a/libjava/java/awt/font/OpenType.java b/libjava/java/awt/font/OpenType.java deleted file mode 100644 index ece3279cc7f..00000000000 --- a/libjava/java/awt/font/OpenType.java +++ /dev/null @@ -1,111 +0,0 @@ -/* OpenType.java - Copyright (C) 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.font; - -/** - * @author Michael Koch - */ -public interface OpenType -{ - int TAG_ACNT = 1633906292; - int TAG_AVAR = 1635148146; - int TAG_BASE = 1111577413; - int TAG_BDAT = 1650745716; - int TAG_BLOC = 1651273571; - int TAG_BSLN = 1651731566; - int TAG_CFF = 1128678944; - int TAG_CMAP = 1668112752; - int TAG_CVAR = 1668702578; - int TAG_CVT = 1668707360; - int TAG_DSIG = 1146308935; - int TAG_EBDT = 1161970772; - int TAG_EBLC = 1161972803; - int TAG_EBSC = 1161974595; - int TAG_FDSC = 1717859171; - int TAG_FEAT = 1717920116; - int TAG_FMTX = 1718449272; - int TAG_FPGM = 1718642541; - int TAG_FVAR = 1719034226; - int TAG_GASP = 1734439792; - int TAG_GDEF = 1195656518; - int TAG_GLYF = 1735162214; - int TAG_GPOS = 1196445523; - int TAG_GSUB = 1196643650; - int TAG_GVAR = 1735811442; - int TAG_HDMX = 1751412088; - int TAG_HEAD = 1751474532; - int TAG_HHEA = 1751672161; - int TAG_HMTX = 1752003704; - int TAG_JSTF = 1246975046; - int TAG_JUST = 1786082164; - int TAG_KERN = 1801810542; - int TAG_LCAR = 1818452338; - int TAG_LOCA = 1819239265; - int TAG_LTSH = 1280594760; - int TAG_MAXP = 1835104368; - int TAG_MMFX = 1296909912; - int TAG_MMSD = 1296913220; - int TAG_MORT = 1836020340; - int TAG_NAME = 1851878757; - int TAG_OPBD = 1836020340; - int TAG_OS2 = 1330851634; - int TAG_PCLT = 1346587732; - int TAG_POST = 1886352244; - int TAG_PREP = 1886545264; - int TAG_PROP = 1886547824; - int TAG_TRAK = 1953653099; - int TAG_TYP1 = 1954115633; - int TAG_VDMX = 1447316824; - int TAG_VHEA = 1986553185; - int TAG_VMTX = 1986884728; - - byte[] getFontTable (int sfntTag); - - byte[] getFontTable (int sfntTag, int offset, int count); - - byte[] getFontTable (String strSfntTag); - - byte[] getFontTable (String strSfntTag, int offset, int count); - - int getFontTableSize (int sfntTag); - - int getFontTableSize (String strSfntTag); - - int getVersion (); -} diff --git a/libjava/java/awt/font/ShapeGraphicAttribute.java b/libjava/java/awt/font/ShapeGraphicAttribute.java deleted file mode 100644 index 6d64dece5d8..00000000000 --- a/libjava/java/awt/font/ShapeGraphicAttribute.java +++ /dev/null @@ -1,105 +0,0 @@ -/* ShapeGraphicAttribute.java - Copyright (C) 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.font; - -import java.awt.Graphics2D; -import java.awt.Shape; -import java.awt.geom.Rectangle2D; - -public final class ShapeGraphicAttribute extends GraphicAttribute -{ - public static final boolean FILL = false; - public static final boolean STROKE = true; - - private Shape shape; - private boolean stroke; - - public ShapeGraphicAttribute (Shape shape, int alignment, boolean stroke) - { - super (alignment); - this.shape = shape; - this.stroke = stroke; - } - - public void draw (Graphics2D graphics, float x, float y) - { - throw new Error ("not implemented"); - } - - public boolean equals (Object obj) - { - if (! (obj instanceof ShapeGraphicAttribute)) - return false; - - return equals ((ShapeGraphicAttribute) obj); - } - - public boolean equals (ShapeGraphicAttribute rhs) - { - return (shape.equals (rhs.shape) - && getAlignment () == rhs.getAlignment () - && stroke == rhs.stroke); - } - - public float getAdvance () - { - throw new Error ("not implemented"); - } - - public float getAscent () - { - throw new Error ("not implemented"); - } - - public Rectangle2D getBounds () - { - return shape.getBounds2D (); - } - - public float getDescent () - { - throw new Error ("not implemented"); - } - - public int hashCode () - { - // FIXME: Check what SUN does here - return shape.hashCode (); - } -} diff --git a/libjava/java/awt/font/TextAttribute.java b/libjava/java/awt/font/TextAttribute.java deleted file mode 100644 index 6f5ed59f915..00000000000 --- a/libjava/java/awt/font/TextAttribute.java +++ /dev/null @@ -1,309 +0,0 @@ -/* TextAttribute.java -- - Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.font; - -import java.io.InvalidObjectException; -import java.text.AttributedCharacterIterator; - -/** - * Attributes (and associated values) that can be used to define an - * {@link java.text.AttributedString}. - */ -public final class TextAttribute extends AttributedCharacterIterator.Attribute -{ - private static final long serialVersionUID = 7744112784117861702L; - - /** A key for the background paint attribute. */ - public static final TextAttribute BACKGROUND = - new TextAttribute("background"); - - /** A key for the BIDI_EMBEDDING attribute. */ - public static final TextAttribute BIDI_EMBEDDING = - new TextAttribute("bidi_embedding"); - - /** A key for the CHAR_REPLACEMENT attribute. */ - public static final TextAttribute CHAR_REPLACEMENT = - new TextAttribute("char_replacement"); - - /** A key for the FAMILY attribute. */ - public static final TextAttribute FAMILY = new TextAttribute("family"); - - /** A key for the font attribute. */ - public static final TextAttribute FONT = new TextAttribute("font"); - - /** A key for the foreground paint attribute. */ - public static final TextAttribute FOREGROUND = - new TextAttribute("foreground"); - - /** A key for the INPUT_METHOD_HIGHLIGHT attribute. */ - public static final TextAttribute INPUT_METHOD_HIGHLIGHT = - new TextAttribute("input method highlight"); - - /** A key for the INPUT_METHOD_UNDERLINE attribute. */ - public static final TextAttribute INPUT_METHOD_UNDERLINE = - new TextAttribute("input method underline"); - - /** A key for the text justification attribute. */ - public static final TextAttribute JUSTIFICATION = - new TextAttribute("justification"); - - /** - * A value that can be used with the {@link #JUSTIFICATION} attribute to - * indicate full justification of the text. - */ - public static final Float JUSTIFICATION_FULL = new Float(1.0); - - /** - * A value that can be used with the {@link #JUSTIFICATION} attribute to - * indicate no justification of the text. - */ - public static final Float JUSTIFICATION_NONE = new Float(0.0); - - /** A key for the NUMERIC_SHAPING attribute. */ - public static final TextAttribute NUMERIC_SHAPING = - new TextAttribute("numeric_shaping"); - - /** A key for the POSTURE attribute. */ - public static final TextAttribute POSTURE = new TextAttribute("posture"); - - /** A value that can be used with the {@link #POSTURE} attribute. */ - public static final Float POSTURE_OBLIQUE = new Float(0.2); - - /** A value that can be used with the {@link #POSTURE} attribute. */ - public static final Float POSTURE_REGULAR = new Float(0.0); - - /** A key for the RUN_DIRECTION attribute. */ - public static final TextAttribute RUN_DIRECTION = - new TextAttribute("run_direction"); - - /** A value that can be used with the {@link #RUN_DIRECTION} attribute. */ - public static final Boolean RUN_DIRECTION_LTR = Boolean.FALSE; - - /** A value that can be used with the {@link #RUN_DIRECTION} attribute. */ - public static final Boolean RUN_DIRECTION_RTL = Boolean.TRUE; - - /** A key for the text size attribute. */ - public static final TextAttribute SIZE = new TextAttribute("size"); - - /** A key for the STRIKETHROUGH attribute. */ - public static final TextAttribute STRIKETHROUGH = - new TextAttribute("strikethrough"); - - /** A value that can be used with the {@link #STRIKETHROUGH} attribute. */ - public static final Boolean STRIKETHROUGH_ON = Boolean.TRUE; - - /** A key for the SUPERSCRIPT attribute. */ - public static final TextAttribute SUPERSCRIPT = - new TextAttribute("superscript"); - - /** A value that can be used with the {@link #SUPERSCRIPT} attribute. */ - public static final Integer SUPERSCRIPT_SUB = new Integer(-1); - - /** A value that can be used with the {@link #SUPERSCRIPT} attribute. */ - public static final Integer SUPERSCRIPT_SUPER = new Integer(1); - - /** A key for the SWAP_COLORS attribute. */ - public static final TextAttribute SWAP_COLORS = - new TextAttribute("swap_colors"); - - /** A value that can be used with the {@link #SWAP_COLORS} attribute. */ - public static final Boolean SWAP_COLORS_ON = Boolean.TRUE; - - /** A key for the TRANFORM attribute. */ - public static final TextAttribute TRANSFORM = new TextAttribute("transform"); - - /** A key for the UNDERLINE attribute. */ - public static final TextAttribute UNDERLINE = new TextAttribute("underline"); - - /** A value that can be used with the {@link #UNDERLINE} attribute. */ - public static final Integer UNDERLINE_LOW_DASHED = new Integer(5); - - /** A value that can be used with the {@link #UNDERLINE} attribute. */ - public static final Integer UNDERLINE_LOW_DOTTED = new Integer(3); - - /** A value that can be used with the {@link #UNDERLINE} attribute. */ - public static final Integer UNDERLINE_LOW_GRAY = new Integer(4); - - /** A value that can be used with the {@link #UNDERLINE} attribute. */ - public static final Integer UNDERLINE_LOW_ONE_PIXEL = new Integer(1); - - /** A value that can be used with the {@link #UNDERLINE} attribute. */ - public static final Integer UNDERLINE_LOW_TWO_PIXEL = new Integer(2); - - /** A value that can be used with the {@link #UNDERLINE} attribute. */ - public static final Integer UNDERLINE_ON = new Integer(0); - - /** A key for the WEIGHT attribute. */ - public static final TextAttribute WEIGHT = new TextAttribute("weight"); - - /** A value that can be used with the {@link #WEIGHT} attribute. */ - public static final Float WEIGHT_BOLD = new Float(2.0); - - /** A value that can be used with the {@link #WEIGHT} attribute. */ - public static final Float WEIGHT_DEMIBOLD = new Float(1.75); - - /** A value that can be used with the {@link #WEIGHT} attribute. */ - public static final Float WEIGHT_DEMILIGHT = new Float(0.875); - - /** A value that can be used with the {@link #WEIGHT} attribute. */ - public static final Float WEIGHT_EXTRA_LIGHT = new Float(0.5); - - /** A value that can be used with the {@link #WEIGHT} attribute. */ - public static final Float WEIGHT_EXTRABOLD = new Float(2.5); - - /** A value that can be used with the {@link #WEIGHT} attribute. */ - public static final Float WEIGHT_HEAVY = new Float(2.25); - - /** A value that can be used with the {@link #WEIGHT} attribute. */ - public static final Float WEIGHT_LIGHT = new Float(0.75); - - /** A value that can be used with the {@link #WEIGHT} attribute. */ - public static final Float WEIGHT_MEDIUM = new Float(1.5); - - /** A value that can be used with the {@link #WEIGHT} attribute. */ - public static final Float WEIGHT_REGULAR = new Float(1.0); - - /** A value that can be used with the {@link #WEIGHT} attribute. */ - public static final Float WEIGHT_SEMIBOLD = new Float(1.25); - - /** A value that can be used with the {@link #WEIGHT} attribute. */ - public static final Float WEIGHT_ULTRABOLD = new Float(2.75); - - /** A key for the WIDTH attribute. */ - public static final TextAttribute WIDTH = new TextAttribute("width"); - - /** A value that can be used with the {@link #WIDTH} attribute. */ - public static final Float WIDTH_CONDENSED = new Float(0.75); - - /** A value that can be used with the {@link #WIDTH} attribute. */ - public static final Float WIDTH_EXTENDED = new Float(1.5); - - /** A value that can be used with the {@link #WIDTH} attribute. */ - public static final Float WIDTH_REGULAR = new Float(1.0); - - /** A value that can be used with the {@link #WIDTH} attribute. */ - public static final Float WIDTH_SEMI_CONDENSED = new Float(0.875); - - /** A value that can be used with the {@link #WIDTH} attribute. */ - public static final Float WIDTH_SEMI_EXTENDED = new Float(1.25); - - /** - * Creates a new attribute. - * - * @param name the name. - */ - protected TextAttribute(String name) - { - super(name); - } - - /** - * After deserialization, this method ensures that only one instance of - * each attribute is used. - * - * @return The (single) attribute instance. - * - * @throws InvalidObjectException if the attribute is not recognised. - */ - protected Object readResolve() - throws InvalidObjectException - { - if (this.getName().equals("background")) - return BACKGROUND; - - if (this.getName().equals("bidi_embedding")) - return BIDI_EMBEDDING; - - if (this.getName().equals("char_replacement")) - return CHAR_REPLACEMENT; - - if (this.getName().equals("family")) - return FAMILY; - - if (this.getName().equals("font")) - return FONT; - - if (this.getName().equals("foreground")) - return FOREGROUND; - - if (this.getName().equals("input method highlight")) - return INPUT_METHOD_HIGHLIGHT; - - if (this.getName().equals("input method underline")) - return INPUT_METHOD_UNDERLINE; - - if (this.getName().equals("justification")) - return JUSTIFICATION; - - if (this.getName().equals("numeric_shaping")) - return NUMERIC_SHAPING; - - if (this.getName().equals("posture")) - return POSTURE; - - if (this.getName().equals("run_direction")) - return RUN_DIRECTION; - - if (this.getName().equals("size")) - return SIZE; - - if (this.getName().equals("strikethrough")) - return STRIKETHROUGH; - - if (this.getName().equals("superscript")) - return SUPERSCRIPT; - - if (this.getName().equals("swap_colors")) - return SWAP_COLORS; - - if (this.getName().equals("transform")) - return TRANSFORM; - - if (this.getName().equals("underline")) - return UNDERLINE; - - if (this.getName().equals("weight")) - return WEIGHT; - - if (this.getName().equals("width")) - return WIDTH; - - throw new InvalidObjectException("Can't resolve Attribute: " + getName()); - } -} diff --git a/libjava/java/awt/font/TextHitInfo.java b/libjava/java/awt/font/TextHitInfo.java deleted file mode 100644 index 2b23e1963cd..00000000000 --- a/libjava/java/awt/font/TextHitInfo.java +++ /dev/null @@ -1,125 +0,0 @@ -/* TextHitInfo.java -- - Copyright (C) 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.awt.font; - -/** - * @author John Leuner (jewel@debian.org) - */ -public final class TextHitInfo -{ - private int charIndex; - private boolean leadingEdge; - - TextHitInfo (int charIndex, boolean leadingEdge) - { - this.charIndex = charIndex; - this.leadingEdge = leadingEdge; - } - - public int getCharIndex() - { - return charIndex; - } - - public boolean isLeadingEdge() - { - return leadingEdge; - } - - public int getInsertionIndex() - { - return (leadingEdge ? charIndex : charIndex + 1); - } - - public int hashCode() - { - return charIndex; - } - - public boolean equals(Object obj) - { - if(obj instanceof TextHitInfo) - return this.equals((TextHitInfo) obj); - - return false; - } - - public boolean equals(TextHitInfo hitInfo) - { - return (charIndex == hitInfo.getCharIndex ()) - && (leadingEdge == hitInfo.isLeadingEdge ()); - } - - public static TextHitInfo leading(int charIndex) - { - return new TextHitInfo (charIndex, true); - } - - public static TextHitInfo trailing(int charIndex) - { - return new TextHitInfo (charIndex, false); - } - - public static TextHitInfo beforeOffset(int offset) - { - return new TextHitInfo (offset, false); - } - - public static TextHitInfo afterOffset(int offset) - { - return new TextHitInfo (offset, true); - } - - public TextHitInfo getOtherHit() - { - return (leadingEdge ? trailing (charIndex - 1) : leading (charIndex + 1)); - } - - public TextHitInfo getOffsetHit(int offset) - { - return new TextHitInfo (charIndex + offset, leadingEdge); - } - - public String toString() - { - return "TextHitInfo[" - + charIndex - + (leadingEdge ? "L" : "T" ) - + "]"; - } -} diff --git a/libjava/java/awt/font/TextLayout.java b/libjava/java/awt/font/TextLayout.java deleted file mode 100644 index bb641614a92..00000000000 --- a/libjava/java/awt/font/TextLayout.java +++ /dev/null @@ -1,332 +0,0 @@ -/* TextLayout.java -- - Copyright (C) 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.font; - -import gnu.java.awt.ClasspathToolkit; -import gnu.java.awt.peer.ClasspathTextLayoutPeer; - -import java.awt.Font; -import java.awt.Graphics2D; -import java.awt.Shape; -import java.awt.Toolkit; -import java.awt.geom.AffineTransform; -import java.awt.geom.Rectangle2D; -import java.text.AttributedCharacterIterator; -import java.text.AttributedString; -import java.util.Map; - -/** - * @author Michael Koch - */ -public final class TextLayout implements Cloneable -{ - public static final CaretPolicy DEFAULT_CARET_POLICY = new CaretPolicy (); - ClasspathTextLayoutPeer peer; - - public static class CaretPolicy - { - public CaretPolicy () - { - // Do nothing here. - } - - public TextHitInfo getStrongCaret (TextHitInfo hit1, TextHitInfo hit2, - TextLayout layout) - { - return layout.peer.getStrongCaret(hit1, hit2); - } - } - - public TextLayout (AttributedCharacterIterator text, FontRenderContext frc) - { - AttributedString as = new AttributedString (text); - ClasspathToolkit tk = (ClasspathToolkit)(Toolkit.getDefaultToolkit ()); - peer = tk.getClasspathTextLayoutPeer(as, frc); - } - - public TextLayout (String string, Font font, FontRenderContext frc) - { - AttributedString as = new AttributedString (string); - as.addAttribute (TextAttribute.FONT, font); - ClasspathToolkit tk = (ClasspathToolkit)(Toolkit.getDefaultToolkit ()); - peer = tk.getClasspathTextLayoutPeer(as, frc); - } - - public TextLayout (String string, Map attributes, FontRenderContext frc) - { - AttributedString as = new AttributedString (string, attributes); - ClasspathToolkit tk = (ClasspathToolkit)(Toolkit.getDefaultToolkit ()); - peer = tk.getClasspathTextLayoutPeer(as, frc); - } - - protected Object clone () - { - try - { - TextLayout tl = (TextLayout) super.clone (); - tl.peer = (ClasspathTextLayoutPeer) this.peer.clone(); - return tl; - } - catch (CloneNotSupportedException e) - { - // This should never occur - throw new InternalError (); - } - } - - - public void draw (Graphics2D g2, float x, float y) - { - peer.draw(g2, x, y); - } - - public boolean equals (Object obj) - { - if (! (obj instanceof TextLayout)) - return false; - - return equals ((TextLayout) obj); - } - - public boolean equals (TextLayout tl) - { - return this.peer.equals(tl.peer); - } - - public float getAdvance () - { - return peer.getAdvance(); - } - - public float getAscent () - { - return peer.getAscent(); - } - - public byte getBaseline () - { - return peer.getBaseline(); - } - - public float[] getBaselineOffsets () - { - return peer.getBaselineOffsets(); - } - - public Shape getBlackBoxBounds (int firstEndpoint, int secondEndpoint) - { - return peer.getBlackBoxBounds(firstEndpoint, secondEndpoint); - } - - public Rectangle2D getBounds() - { - return peer.getBounds(); - } - - public float[] getCaretInfo (TextHitInfo hit) - { - return getCaretInfo(hit, getBounds()); - } - - public float[] getCaretInfo (TextHitInfo hit, Rectangle2D bounds) - { - return peer.getCaretInfo(hit, bounds); - } - - public Shape getCaretShape (TextHitInfo hit) - { - return getCaretShape(hit, getBounds()); - } - - public Shape getCaretShape (TextHitInfo hit, Rectangle2D bounds) - { - return peer.getCaretShape(hit, bounds); - } - - public Shape[] getCaretShapes (int offset) - { - return getCaretShapes(offset, getBounds()); - } - - public Shape[] getCaretShapes (int offset, Rectangle2D bounds) - { - return getCaretShapes(offset, getBounds(), DEFAULT_CARET_POLICY); - } - - public Shape[] getCaretShapes (int offset, Rectangle2D bounds, - TextLayout.CaretPolicy policy) - { - return peer.getCaretShapes(offset, bounds, policy); - } - - public int getCharacterCount () - { - return peer.getCharacterCount(); - } - - public byte getCharacterLevel (int index) - { - return peer.getCharacterLevel(index); - } - - public float getDescent () - { - return peer.getDescent(); - } - - public TextLayout getJustifiedLayout (float justificationWidth) - { - return peer.getJustifiedLayout(justificationWidth); - } - - public float getLeading () - { - return peer.getLeading(); - } - - public Shape getLogicalHighlightShape (int firstEndpoint, int secondEndpoint) - { - return getLogicalHighlightShape (firstEndpoint, secondEndpoint, getBounds()); - } - - public Shape getLogicalHighlightShape (int firstEndpoint, int secondEndpoint, - Rectangle2D bounds) - { - return peer.getLogicalHighlightShape(firstEndpoint, secondEndpoint, bounds); - } - - public int[] getLogicalRangesForVisualSelection (TextHitInfo firstEndpoint, - TextHitInfo secondEndpoint) - { - return peer.getLogicalRangesForVisualSelection(firstEndpoint, secondEndpoint); - } - - public TextHitInfo getNextLeftHit (int offset) - { - return getNextLeftHit(offset, DEFAULT_CARET_POLICY); - } - - public TextHitInfo getNextLeftHit (int offset, TextLayout.CaretPolicy policy) - { - return peer.getNextLeftHit(offset, policy); - } - - public TextHitInfo getNextLeftHit (TextHitInfo hit) - { - return getNextLeftHit(hit.getCharIndex()); - } - - public TextHitInfo getNextRightHit (int offset) - { - return getNextRightHit(offset, DEFAULT_CARET_POLICY); - } - - public TextHitInfo getNextRightHit (int offset, TextLayout.CaretPolicy policy) - { - return peer.getNextRightHit(offset, policy); - } - - public TextHitInfo getNextRightHit (TextHitInfo hit) - { - return getNextRightHit(hit.getCharIndex()); - } - - public Shape getOutline (AffineTransform tx) - { - return peer.getOutline(tx); - } - - public float getVisibleAdvance () - { - return peer.getVisibleAdvance(); - } - - public Shape getVisualHighlightShape (TextHitInfo firstEndpoint, - TextHitInfo secondEndpoint) - { - return getVisualHighlightShape(firstEndpoint, secondEndpoint, getBounds()); - } - - public Shape getVisualHighlightShape (TextHitInfo firstEndpoint, - TextHitInfo secondEndpoint, - Rectangle2D bounds) - { - return peer.getVisualHighlightShape(firstEndpoint, secondEndpoint, bounds); - } - - public TextHitInfo getVisualOtherHit (TextHitInfo hit) - { - return peer.getVisualOtherHit(hit); - } - - protected void handleJustify (float justificationWidth) - { - peer.handleJustify(justificationWidth); - } - - public int hashCode () - { - return peer.hashCode(); - } - - public TextHitInfo hitTestChar (float x, float y) - { - return hitTestChar(x, y, getBounds()); - } - - public TextHitInfo hitTestChar (float x, float y, Rectangle2D bounds) - { - return peer.hitTestChar(x, y, bounds); - } - - public boolean isLeftToRight () - { - return peer.isLeftToRight(); - } - - public boolean isVertical () - { - return peer.isVertical(); - } - - public String toString () - { - return peer.toString(); - } -} diff --git a/libjava/java/awt/font/TextMeasurer.java b/libjava/java/awt/font/TextMeasurer.java deleted file mode 100644 index 7fcdc87a83c..00000000000 --- a/libjava/java/awt/font/TextMeasurer.java +++ /dev/null @@ -1,97 +0,0 @@ -/* TextMeasurer.java - Copyright (C) 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.font; - -import java.text.AttributedCharacterIterator; - -/** - * @author Michael Koch - * @since 1.3 - */ -public final class TextMeasurer implements Cloneable -{ - private AttributedCharacterIterator ci; - private FontRenderContext frc; - - public TextMeasurer (AttributedCharacterIterator text, FontRenderContext frc) - { - this.ci = text; - this.frc = frc; - } - - protected Object clone () - { - try - { - return super.clone (); - } - catch (CloneNotSupportedException e) - { - // This may never occur - throw new InternalError (); - } - } - - public void deleteChar (AttributedCharacterIterator newParagraph, - int deletePos) - { - throw new Error ("not implemented"); - } - - public float getAdvanceBetween (int start, int limit) - { - throw new Error ("not implemented"); - } - - public TextLayout getLayout (int start, int limit) - { - throw new Error ("not implemented"); - } - - public int getLineBreakIndex (int start, float maxAdvance) - { - throw new Error ("not implemented"); - } - - public void insertChar (AttributedCharacterIterator newParagraph, - int insertPos) - { - throw new Error ("not implemented"); - } -} diff --git a/libjava/java/awt/font/TransformAttribute.java b/libjava/java/awt/font/TransformAttribute.java deleted file mode 100644 index 977cafa032e..00000000000 --- a/libjava/java/awt/font/TransformAttribute.java +++ /dev/null @@ -1,100 +0,0 @@ -/* TransformAttribute.java -- - Copyright (C) 2003, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.font; - -import java.awt.geom.AffineTransform; -import java.io.Serializable; - -/** - * This class provides a mechanism for using an {@link AffineTransform} as - * an <i>immutable</i> attribute (for example, in the - * {@link java.text.AttributedString} class). Any transform passed to - * this class is copied before being stored, and any transform handed out - * by this class is a copy of the stored transform. In this way, it is - * not possible to modify the stored transform. - * - * @author Michael Koch - */ -public final class TransformAttribute implements Serializable -{ - private static final long serialVersionUID = 3356247357827709530L; - - private AffineTransform affineTransform; - - /** - * Creates a new attribute that contains a copy of the given transform. - * - * @param transform the transform (<code>null</code> not permitted). - * - * @throws IllegalArgumentException if <code>transform</code> is - * <code>null</code>. - */ - public TransformAttribute (AffineTransform transform) - { - if (transform == null) - { - throw new IllegalArgumentException("Null 'transform' not permitted."); - } - this.affineTransform = new AffineTransform (transform); - } - - /** - * Returns a copy of the transform contained by this attribute. - * - * @return A copy of the transform. - */ - public AffineTransform getTransform () - { - return (AffineTransform) affineTransform.clone(); - } - - /** - * Returns <code>true</code> if the transform contained by this attribute is - * an identity transform, and <code>false</code> otherwise. - * - * @return <code>true</code> if the transform contained by this attribute is - * an identity transform, and <code>false</code> otherwise. - * - * @since 1.4 - */ - public boolean isIdentity () - { - return (affineTransform == null ? false : affineTransform.isIdentity ()); - } -} diff --git a/libjava/java/awt/geom/AffineTransform.java b/libjava/java/awt/geom/AffineTransform.java deleted file mode 100644 index 4d1a4d6d5d4..00000000000 --- a/libjava/java/awt/geom/AffineTransform.java +++ /dev/null @@ -1,1487 +0,0 @@ -/* AffineTransform.java -- transform coordinates between two 2-D spaces - Copyright (C) 2000, 2001, 2002, 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.geom; - -import java.awt.Shape; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.Serializable; - -/** - * This class represents an affine transformation between two coordinate - * spaces in 2 dimensions. Such a transform preserves the "straightness" - * and "parallelness" of lines. The transform is built from a sequence of - * translations, scales, flips, rotations, and shears. - * - * <p>The transformation can be represented using matrix math on a 3x3 array. - * Given (x,y), the transformation (x',y') can be found by: - * <pre> - * [ x'] [ m00 m01 m02 ] [ x ] [ m00*x + m01*y + m02 ] - * [ y'] = [ m10 m11 m12 ] [ y ] = [ m10*x + m11*y + m12 ] - * [ 1 ] [ 0 0 1 ] [ 1 ] [ 1 ] - * </pre> - * The bottom row of the matrix is constant, so a transform can be uniquely - * represented (as in {@link #toString()}) by - * "[[m00, m01, m02], [m10, m11, m12]]". - * - * @author Tom Tromey (tromey@cygnus.com) - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.2 - * @status partially updated to 1.4, still has some problems - */ -public class AffineTransform implements Cloneable, Serializable -{ - /** - * Compatible with JDK 1.2+. - */ - private static final long serialVersionUID = 1330973210523860834L; - - /** - * The transformation is the identity (x' = x, y' = y). All other transforms - * have either a combination of the appropriate transform flag bits for - * their type, or the type GENERAL_TRANSFORM. - * - * @see #TYPE_TRANSLATION - * @see #TYPE_UNIFORM_SCALE - * @see #TYPE_GENERAL_SCALE - * @see #TYPE_FLIP - * @see #TYPE_QUADRANT_ROTATION - * @see #TYPE_GENERAL_ROTATION - * @see #TYPE_GENERAL_TRANSFORM - * @see #getType() - */ - public static final int TYPE_IDENTITY = 0; - - /** - * The transformation includes a translation - shifting in the x or y - * direction without changing length or angles. - * - * @see #TYPE_IDENTITY - * @see #TYPE_UNIFORM_SCALE - * @see #TYPE_GENERAL_SCALE - * @see #TYPE_FLIP - * @see #TYPE_QUADRANT_ROTATION - * @see #TYPE_GENERAL_ROTATION - * @see #TYPE_GENERAL_TRANSFORM - * @see #getType() - */ - public static final int TYPE_TRANSLATION = 1; - - /** - * The transformation includes a uniform scale - length is scaled in both - * the x and y directions by the same amount, without affecting angles. - * This is mutually exclusive with TYPE_GENERAL_SCALE. - * - * @see #TYPE_IDENTITY - * @see #TYPE_TRANSLATION - * @see #TYPE_GENERAL_SCALE - * @see #TYPE_FLIP - * @see #TYPE_QUADRANT_ROTATION - * @see #TYPE_GENERAL_ROTATION - * @see #TYPE_GENERAL_TRANSFORM - * @see #TYPE_MASK_SCALE - * @see #getType() - */ - public static final int TYPE_UNIFORM_SCALE = 2; - - /** - * The transformation includes a general scale - length is scaled in either - * or both the x and y directions, but by different amounts; without - * affecting angles. This is mutually exclusive with TYPE_UNIFORM_SCALE. - * - * @see #TYPE_IDENTITY - * @see #TYPE_TRANSLATION - * @see #TYPE_UNIFORM_SCALE - * @see #TYPE_FLIP - * @see #TYPE_QUADRANT_ROTATION - * @see #TYPE_GENERAL_ROTATION - * @see #TYPE_GENERAL_TRANSFORM - * @see #TYPE_MASK_SCALE - * @see #getType() - */ - public static final int TYPE_GENERAL_SCALE = 4; - - /** - * This constant checks if either variety of scale transform is performed. - * - * @see #TYPE_UNIFORM_SCALE - * @see #TYPE_GENERAL_SCALE - */ - public static final int TYPE_MASK_SCALE = 6; - - /** - * The transformation includes a flip about an axis, swapping between - * right-handed and left-handed coordinate systems. In a right-handed - * system, the positive x-axis rotates counter-clockwise to the positive - * y-axis; in a left-handed system it rotates clockwise. - * - * @see #TYPE_IDENTITY - * @see #TYPE_TRANSLATION - * @see #TYPE_UNIFORM_SCALE - * @see #TYPE_GENERAL_SCALE - * @see #TYPE_QUADRANT_ROTATION - * @see #TYPE_GENERAL_ROTATION - * @see #TYPE_GENERAL_TRANSFORM - * @see #getType() - */ - public static final int TYPE_FLIP = 64; - - /** - * The transformation includes a rotation of a multiple of 90 degrees (PI/2 - * radians). Angles are rotated, but length is preserved. This is mutually - * exclusive with TYPE_GENERAL_ROTATION. - * - * @see #TYPE_IDENTITY - * @see #TYPE_TRANSLATION - * @see #TYPE_UNIFORM_SCALE - * @see #TYPE_GENERAL_SCALE - * @see #TYPE_FLIP - * @see #TYPE_GENERAL_ROTATION - * @see #TYPE_GENERAL_TRANSFORM - * @see #TYPE_MASK_ROTATION - * @see #getType() - */ - public static final int TYPE_QUADRANT_ROTATION = 8; - - /** - * The transformation includes a rotation by an arbitrary angle. Angles are - * rotated, but length is preserved. This is mutually exclusive with - * TYPE_QUADRANT_ROTATION. - * - * @see #TYPE_IDENTITY - * @see #TYPE_TRANSLATION - * @see #TYPE_UNIFORM_SCALE - * @see #TYPE_GENERAL_SCALE - * @see #TYPE_FLIP - * @see #TYPE_QUADRANT_ROTATION - * @see #TYPE_GENERAL_TRANSFORM - * @see #TYPE_MASK_ROTATION - * @see #getType() - */ - public static final int TYPE_GENERAL_ROTATION = 16; - - /** - * This constant checks if either variety of rotation is performed. - * - * @see #TYPE_QUADRANT_ROTATION - * @see #TYPE_GENERAL_ROTATION - */ - public static final int TYPE_MASK_ROTATION = 24; - - /** - * The transformation is an arbitrary conversion of coordinates which - * could not be decomposed into the other TYPEs. - * - * @see #TYPE_IDENTITY - * @see #TYPE_TRANSLATION - * @see #TYPE_UNIFORM_SCALE - * @see #TYPE_GENERAL_SCALE - * @see #TYPE_FLIP - * @see #TYPE_QUADRANT_ROTATION - * @see #TYPE_GENERAL_ROTATION - * @see #getType() - */ - public static final int TYPE_GENERAL_TRANSFORM = 32; - - /** - * The X coordinate scaling element of the transform matrix. - * - * @serial matrix[0,0] - */ - private double m00; - - /** - * The Y coordinate shearing element of the transform matrix. - * - * @serial matrix[1,0] - */ - private double m10; - - /** - * The X coordinate shearing element of the transform matrix. - * - * @serial matrix[0,1] - */ - private double m01; - - /** - * The Y coordinate scaling element of the transform matrix. - * - * @serial matrix[1,1] - */ - private double m11; - - /** - * The X coordinate translation element of the transform matrix. - * - * @serial matrix[0,2] - */ - private double m02; - - /** - * The Y coordinate translation element of the transform matrix. - * - * @serial matrix[1,2] - */ - private double m12; - - /** The type of this transform. */ - private transient int type; - - /** - * Construct a new identity transform: - * <pre> - * [ 1 0 0 ] - * [ 0 1 0 ] - * [ 0 0 1 ] - * </pre> - */ - public AffineTransform() - { - m00 = m11 = 1; - } - - /** - * Create a new transform which copies the given one. - * - * @param tx the transform to copy - * @throws NullPointerException if tx is null - */ - public AffineTransform(AffineTransform tx) - { - setTransform(tx); - } - - /** - * Construct a transform with the given matrix entries: - * <pre> - * [ m00 m01 m02 ] - * [ m10 m11 m12 ] - * [ 0 0 1 ] - * </pre> - * - * @param m00 the x scaling component - * @param m10 the y shearing component - * @param m01 the x shearing component - * @param m11 the y scaling component - * @param m02 the x translation component - * @param m12 the y translation component - */ - public AffineTransform(float m00, float m10, - float m01, float m11, - float m02, float m12) - { - this.m00 = m00; - this.m10 = m10; - this.m01 = m01; - this.m11 = m11; - this.m02 = m02; - this.m12 = m12; - updateType(); - } - - /** - * Construct a transform from a sequence of float entries. The array must - * have at least 4 entries, which has a translation factor of 0; or 6 - * entries, for specifying all parameters: - * <pre> - * [ f[0] f[2] (f[4]) ] - * [ f[1] f[3] (f[5]) ] - * [ 0 0 1 ] - * </pre> - * - * @param f the matrix to copy from, with at least 4 (6) entries - * @throws NullPointerException if f is null - * @throws ArrayIndexOutOfBoundsException if f is too small - */ - public AffineTransform(float[] f) - { - m00 = f[0]; - m10 = f[1]; - m01 = f[2]; - m11 = f[3]; - if (f.length >= 6) - { - m02 = f[4]; - m12 = f[5]; - } - updateType(); - } - - /** - * Construct a transform with the given matrix entries: - * <pre> - * [ m00 m01 m02 ] - * [ m10 m11 m12 ] - * [ 0 0 1 ] - * </pre> - * - * @param m00 the x scaling component - * @param m10 the y shearing component - * @param m01 the x shearing component - * @param m11 the y scaling component - * @param m02 the x translation component - * @param m12 the y translation component - */ - public AffineTransform(double m00, double m10, double m01, - double m11, double m02, double m12) - { - this.m00 = m00; - this.m10 = m10; - this.m01 = m01; - this.m11 = m11; - this.m02 = m02; - this.m12 = m12; - updateType(); - } - - /** - * Construct a transform from a sequence of double entries. The array must - * have at least 4 entries, which has a translation factor of 0; or 6 - * entries, for specifying all parameters: - * <pre> - * [ d[0] d[2] (d[4]) ] - * [ d[1] d[3] (d[5]) ] - * [ 0 0 1 ] - * </pre> - * - * @param d the matrix to copy from, with at least 4 (6) entries - * @throws NullPointerException if d is null - * @throws ArrayIndexOutOfBoundsException if d is too small - */ - public AffineTransform(double[] d) - { - m00 = d[0]; - m10 = d[1]; - m01 = d[2]; - m11 = d[3]; - if (d.length >= 6) - { - m02 = d[4]; - m12 = d[5]; - } - updateType(); - } - - /** - * Returns a translation transform: - * <pre> - * [ 1 0 tx ] - * [ 0 1 ty ] - * [ 0 0 1 ] - * </pre> - * - * @param tx the x translation distance - * @param ty the y translation distance - * @return the translating transform - */ - public static AffineTransform getTranslateInstance(double tx, double ty) - { - AffineTransform t = new AffineTransform(); - t.setToTranslation(tx, ty); - return t; - } - - /** - * Returns a rotation transform. A positive angle (in radians) rotates - * the positive x-axis to the positive y-axis: - * <pre> - * [ cos(theta) -sin(theta) 0 ] - * [ sin(theta) cos(theta) 0 ] - * [ 0 0 1 ] - * </pre> - * - * @param theta the rotation angle - * @return the rotating transform - */ - public static AffineTransform getRotateInstance(double theta) - { - AffineTransform t = new AffineTransform(); - t.setToRotation(theta); - return t; - } - - /** - * Returns a rotation transform about a point. A positive angle (in radians) - * rotates the positive x-axis to the positive y-axis. This is the same - * as calling: - * <pre> - * AffineTransform tx = new AffineTransform(); - * tx.setToTranslation(x, y); - * tx.rotate(theta); - * tx.translate(-x, -y); - * </pre> - * - * <p>The resulting matrix is: - * <pre> - * [ cos(theta) -sin(theta) x-x*cos+y*sin ] - * [ sin(theta) cos(theta) y-x*sin-y*cos ] - * [ 0 0 1 ] - * </pre> - * - * @param theta the rotation angle - * @param x the x coordinate of the pivot point - * @param y the y coordinate of the pivot point - * @return the rotating transform - */ - public static AffineTransform getRotateInstance(double theta, - double x, double y) - { - AffineTransform t = new AffineTransform(); - t.setToTranslation(x, y); - t.rotate(theta); - t.translate(-x, -y); - return t; - } - - /** - * Returns a scaling transform: - * <pre> - * [ sx 0 0 ] - * [ 0 sy 0 ] - * [ 0 0 1 ] - * </pre> - * - * @param sx the x scaling factor - * @param sy the y scaling factor - * @return the scaling transform - */ - public static AffineTransform getScaleInstance(double sx, double sy) - { - AffineTransform t = new AffineTransform(); - t.setToScale(sx, sy); - return t; - } - - /** - * Returns a shearing transform (points are shifted in the x direction based - * on a factor of their y coordinate, and in the y direction as a factor of - * their x coordinate): - * <pre> - * [ 1 shx 0 ] - * [ shy 1 0 ] - * [ 0 0 1 ] - * </pre> - * - * @param shx the x shearing factor - * @param shy the y shearing factor - * @return the shearing transform - */ - public static AffineTransform getShearInstance(double shx, double shy) - { - AffineTransform t = new AffineTransform(); - t.setToShear(shx, shy); - return t; - } - - /** - * Returns the type of this transform. The result is always valid, although - * it may not be the simplest interpretation (in other words, there are - * sequences of transforms which reduce to something simpler, which this - * does not always detect). The result is either TYPE_GENERAL_TRANSFORM, - * or a bit-wise combination of TYPE_TRANSLATION, the mutually exclusive - * TYPE_*_ROTATIONs, and the mutually exclusive TYPE_*_SCALEs. - * - * @return The type. - * - * @see #TYPE_IDENTITY - * @see #TYPE_TRANSLATION - * @see #TYPE_UNIFORM_SCALE - * @see #TYPE_GENERAL_SCALE - * @see #TYPE_QUADRANT_ROTATION - * @see #TYPE_GENERAL_ROTATION - * @see #TYPE_GENERAL_TRANSFORM - */ - public int getType() - { - return type; - } - - /** - * Return the determinant of this transform matrix. If the determinant is - * non-zero, the transform is invertible; otherwise operations which require - * an inverse throw a NoninvertibleTransformException. A result very near - * zero, due to rounding errors, may indicate that inversion results do not - * carry enough precision to be meaningful. - * - * <p>If this is a uniform scale transformation, the determinant also - * represents the squared value of the scale. Otherwise, it carries little - * additional meaning. The determinant is calculated as: - * <pre> - * | m00 m01 m02 | - * | m10 m11 m12 | = m00 * m11 - m01 * m10 - * | 0 0 1 | - * </pre> - * - * @return the determinant - * @see #createInverse() - */ - public double getDeterminant() - { - return m00 * m11 - m01 * m10; - } - - /** - * Return the matrix of values used in this transform. If the matrix has - * fewer than 6 entries, only the scale and shear factors are returned; - * otherwise the translation factors are copied as well. The resulting - * values are: - * <pre> - * [ d[0] d[2] (d[4]) ] - * [ d[1] d[3] (d[5]) ] - * [ 0 0 1 ] - * </pre> - * - * @param d the matrix to store the results into; with 4 (6) entries - * @throws NullPointerException if d is null - * @throws ArrayIndexOutOfBoundsException if d is too small - */ - public void getMatrix(double[] d) - { - d[0] = m00; - d[1] = m10; - d[2] = m01; - d[3] = m11; - if (d.length >= 6) - { - d[4] = m02; - d[5] = m12; - } - } - - /** - * Returns the X coordinate scaling factor of the matrix. - * - * @return m00 - * @see #getMatrix(double[]) - */ - public double getScaleX() - { - return m00; - } - - /** - * Returns the Y coordinate scaling factor of the matrix. - * - * @return m11 - * @see #getMatrix(double[]) - */ - public double getScaleY() - { - return m11; - } - - /** - * Returns the X coordinate shearing factor of the matrix. - * - * @return m01 - * @see #getMatrix(double[]) - */ - public double getShearX() - { - return m01; - } - - /** - * Returns the Y coordinate shearing factor of the matrix. - * - * @return m10 - * @see #getMatrix(double[]) - */ - public double getShearY() - { - return m10; - } - - /** - * Returns the X coordinate translation factor of the matrix. - * - * @return m02 - * @see #getMatrix(double[]) - */ - public double getTranslateX() - { - return m02; - } - - /** - * Returns the Y coordinate translation factor of the matrix. - * - * @return m12 - * @see #getMatrix(double[]) - */ - public double getTranslateY() - { - return m12; - } - - /** - * Concatenate a translation onto this transform. This is equivalent, but - * more efficient than - * <code>concatenate(AffineTransform.getTranslateInstance(tx, ty))</code>. - * - * @param tx the x translation distance - * @param ty the y translation distance - * @see #getTranslateInstance(double, double) - * @see #concatenate(AffineTransform) - */ - public void translate(double tx, double ty) - { - m02 += tx * m00 + ty * m01; - m12 += tx * m10 + ty * m11; - updateType(); - } - - /** - * Concatenate a rotation onto this transform. This is equivalent, but - * more efficient than - * <code>concatenate(AffineTransform.getRotateInstance(theta))</code>. - * - * @param theta the rotation angle - * @see #getRotateInstance(double) - * @see #concatenate(AffineTransform) - */ - public void rotate(double theta) - { - double c = Math.cos(theta); - double s = Math.sin(theta); - double n00 = m00 * c + m01 * s; - double n01 = m00 * -s + m01 * c; - double n10 = m10 * c + m11 * s; - double n11 = m10 * -s + m11 * c; - m00 = n00; - m01 = n01; - m10 = n10; - m11 = n11; - updateType(); - } - - /** - * Concatenate a rotation about a point onto this transform. This is - * equivalent, but more efficient than - * <code>concatenate(AffineTransform.getRotateInstance(theta, x, y))</code>. - * - * @param theta the rotation angle - * @param x the x coordinate of the pivot point - * @param y the y coordinate of the pivot point - * @see #getRotateInstance(double, double, double) - * @see #concatenate(AffineTransform) - */ - public void rotate(double theta, double x, double y) - { - translate(x, y); - rotate(theta); - translate(-x, -y); - } - - /** - * Concatenate a scale onto this transform. This is equivalent, but more - * efficient than - * <code>concatenate(AffineTransform.getScaleInstance(sx, sy))</code>. - * - * @param sx the x scaling factor - * @param sy the y scaling factor - * @see #getScaleInstance(double, double) - * @see #concatenate(AffineTransform) - */ - public void scale(double sx, double sy) - { - m00 *= sx; - m01 *= sy; - m10 *= sx; - m11 *= sy; - updateType(); - } - - /** - * Concatenate a shearing onto this transform. This is equivalent, but more - * efficient than - * <code>concatenate(AffineTransform.getShearInstance(sx, sy))</code>. - * - * @param shx the x shearing factor - * @param shy the y shearing factor - * @see #getShearInstance(double, double) - * @see #concatenate(AffineTransform) - */ - public void shear(double shx, double shy) - { - double n00 = m00 + (shy * m01); - double n01 = m01 + (shx * m00); - double n10 = m10 + (shy * m11); - double n11 = m11 + (shx * m10); - m00 = n00; - m01 = n01; - m10 = n10; - m11 = n11; - updateType(); - } - - /** - * Reset this transform to the identity (no transformation): - * <pre> - * [ 1 0 0 ] - * [ 0 1 0 ] - * [ 0 0 1 ] - * </pre> - */ - public void setToIdentity() - { - m00 = m11 = 1; - m01 = m02 = m10 = m12 = 0; - type = TYPE_IDENTITY; - } - - /** - * Set this transform to a translation: - * <pre> - * [ 1 0 tx ] - * [ 0 1 ty ] - * [ 0 0 1 ] - * </pre> - * - * @param tx the x translation distance - * @param ty the y translation distance - */ - public void setToTranslation(double tx, double ty) - { - m00 = m11 = 1; - m01 = m10 = 0; - m02 = tx; - m12 = ty; - type = (tx == 0 && ty == 0) ? TYPE_UNIFORM_SCALE : TYPE_TRANSLATION; - } - - /** - * Set this transform to a rotation. A positive angle (in radians) rotates - * the positive x-axis to the positive y-axis: - * <pre> - * [ cos(theta) -sin(theta) 0 ] - * [ sin(theta) cos(theta) 0 ] - * [ 0 0 1 ] - * </pre> - * - * @param theta the rotation angle - */ - public void setToRotation(double theta) - { - double c = Math.cos(theta); - double s = Math.sin(theta); - m00 = c; - m01 = -s; - m02 = 0; - m10 = s; - m11 = c; - m12 = 0; - type = (c == 1 ? TYPE_IDENTITY - : c == 0 || c == -1 ? TYPE_QUADRANT_ROTATION - : TYPE_GENERAL_ROTATION); - } - - /** - * Set this transform to a rotation about a point. A positive angle (in - * radians) rotates the positive x-axis to the positive y-axis. This is the - * same as calling: - * <pre> - * tx.setToTranslation(x, y); - * tx.rotate(theta); - * tx.translate(-x, -y); - * </pre> - * - * <p>The resulting matrix is: - * <pre> - * [ cos(theta) -sin(theta) x-x*cos+y*sin ] - * [ sin(theta) cos(theta) y-x*sin-y*cos ] - * [ 0 0 1 ] - * </pre> - * - * @param theta the rotation angle - * @param x the x coordinate of the pivot point - * @param y the y coordinate of the pivot point - */ - public void setToRotation(double theta, double x, double y) - { - double c = Math.cos(theta); - double s = Math.sin(theta); - m00 = c; - m01 = -s; - m02 = x - x * c + y * s; - m10 = s; - m11 = c; - m12 = y - x * s - y * c; - updateType(); - } - - /** - * Set this transform to a scale: - * <pre> - * [ sx 0 0 ] - * [ 0 sy 0 ] - * [ 0 0 1 ] - * </pre> - * - * @param sx the x scaling factor - * @param sy the y scaling factor - */ - public void setToScale(double sx, double sy) - { - m00 = sx; - m01 = m02 = m10 = m12 = 0; - m11 = sy; - type = (sx != sy ? TYPE_GENERAL_SCALE - : sx == 1 ? TYPE_IDENTITY : TYPE_UNIFORM_SCALE); - } - - /** - * Set this transform to a shear (points are shifted in the x direction based - * on a factor of their y coordinate, and in the y direction as a factor of - * their x coordinate): - * <pre> - * [ 1 shx 0 ] - * [ shy 1 0 ] - * [ 0 0 1 ] - * </pre> - * - * @param shx the x shearing factor - * @param shy the y shearing factor - */ - public void setToShear(double shx, double shy) - { - m00 = m11 = 1; - m01 = shx; - m10 = shy; - m02 = m12 = 0; - updateType(); - } - - /** - * Set this transform to a copy of the given one. - * - * @param tx the transform to copy - * @throws NullPointerException if tx is null - */ - public void setTransform(AffineTransform tx) - { - m00 = tx.m00; - m01 = tx.m01; - m02 = tx.m02; - m10 = tx.m10; - m11 = tx.m11; - m12 = tx.m12; - type = tx.type; - } - - /** - * Set this transform to the given values: - * <pre> - * [ m00 m01 m02 ] - * [ m10 m11 m12 ] - * [ 0 0 1 ] - * </pre> - * - * @param m00 the x scaling component - * @param m10 the y shearing component - * @param m01 the x shearing component - * @param m11 the y scaling component - * @param m02 the x translation component - * @param m12 the y translation component - */ - public void setTransform(double m00, double m10, double m01, - double m11, double m02, double m12) - { - this.m00 = m00; - this.m10 = m10; - this.m01 = m01; - this.m11 = m11; - this.m02 = m02; - this.m12 = m12; - updateType(); - } - - /** - * Set this transform to the result of performing the original version of - * this followed by tx. This is commonly used when chaining transformations - * from one space to another. In matrix form: - * <pre> - * [ this ] = [ this ] x [ tx ] - * </pre> - * - * @param tx the transform to concatenate - * @throws NullPointerException if tx is null - * @see #preConcatenate(AffineTransform) - */ - public void concatenate(AffineTransform tx) - { - double n00 = m00 * tx.m00 + m01 * tx.m10; - double n01 = m00 * tx.m01 + m01 * tx.m11; - double n02 = m00 * tx.m02 + m01 * tx.m12 + m02; - double n10 = m10 * tx.m00 + m11 * tx.m10; - double n11 = m10 * tx.m01 + m11 * tx.m11; - double n12 = m10 * tx.m02 + m11 * tx.m12 + m12; - m00 = n00; - m01 = n01; - m02 = n02; - m10 = n10; - m11 = n11; - m12 = n12; - updateType(); - } - - /** - * Set this transform to the result of performing tx followed by the - * original version of this. This is less common than normal concatenation, - * but can still be used to chain transformations from one space to another. - * In matrix form: - * <pre> - * [ this ] = [ tx ] x [ this ] - * </pre> - * - * @param tx the transform to concatenate - * @throws NullPointerException if tx is null - * @see #concatenate(AffineTransform) - */ - public void preConcatenate(AffineTransform tx) - { - double n00 = tx.m00 * m00 + tx.m01 * m10; - double n01 = tx.m00 * m01 + tx.m01 * m11; - double n02 = tx.m00 * m02 + tx.m01 * m12 + tx.m02; - double n10 = tx.m10 * m00 + tx.m11 * m10; - double n11 = tx.m10 * m01 + tx.m11 * m11; - double n12 = tx.m10 * m02 + tx.m11 * m12 + tx.m12; - m00 = n00; - m01 = n01; - m02 = n02; - m10 = n10; - m11 = n11; - m12 = n12; - updateType(); - } - - /** - * Returns a transform, which if concatenated to this one, will result in - * the identity transform. This is useful for undoing transformations, but - * is only possible if the original transform has an inverse (ie. does not - * map multiple points to the same line or point). A transform exists only - * if getDeterminant() has a non-zero value. - * - * The inverse is calculated as: - * - * <pre> - * - * Let A be the matrix for which we want to find the inverse: - * - * A = [ m00 m01 m02 ] - * [ m10 m11 m12 ] - * [ 0 0 1 ] - * - * - * 1 - * inverse (A) = --- x adjoint(A) - * det - * - * - * - * = 1 [ m11 -m01 m01*m12-m02*m11 ] - * --- x [ -m10 m00 -m00*m12+m10*m02 ] - * det [ 0 0 m00*m11-m10*m01 ] - * - * - * - * = [ m11/det -m01/det m01*m12-m02*m11/det ] - * [ -m10/det m00/det -m00*m12+m10*m02/det ] - * [ 0 0 1 ] - * - * - * </pre> - * - * - * - * @return a new inverse transform - * @throws NoninvertibleTransformException if inversion is not possible - * @see #getDeterminant() - */ - public AffineTransform createInverse() - throws NoninvertibleTransformException - { - double det = getDeterminant(); - if (det == 0) - throw new NoninvertibleTransformException("can't invert transform"); - - double im00 = m11 / det; - double im10 = -m10 / det; - double im01 = -m01 / det; - double im11 = m00 / det; - double im02 = (m01 * m12 - m02 * m11) / det; - double im12 = (-m00 * m12 + m10 * m02) / det; - - return new AffineTransform (im00, im10, im01, im11, im02, im12); - } - - /** - * Perform this transformation on the given source point, and store the - * result in the destination (creating it if necessary). It is safe for - * src and dst to be the same. - * - * @param src the source point - * @param dst the destination, or null - * @return the transformation of src, in dst if it was non-null - * @throws NullPointerException if src is null - */ - public Point2D transform(Point2D src, Point2D dst) - { - if (dst == null) - dst = new Point2D.Double(); - double x = src.getX(); - double y = src.getY(); - double nx = m00 * x + m01 * y + m02; - double ny = m10 * x + m11 * y + m12; - dst.setLocation(nx, ny); - return dst; - } - - /** - * Perform this transformation on an array of points, storing the results - * in another (possibly same) array. This will not create a destination - * array, but will create points for the null entries of the destination. - * The transformation is done sequentially. While having a single source - * and destination point be the same is safe, you should be aware that - * duplicate references to the same point in the source, and having the - * source overlap the destination, may result in your source points changing - * from a previous transform before it is their turn to be evaluated. - * - * @param src the array of source points - * @param srcOff the starting offset into src - * @param dst the array of destination points (may have null entries) - * @param dstOff the starting offset into dst - * @param num the number of points to transform - * @throws NullPointerException if src or dst is null, or src has null - * entries - * @throws ArrayIndexOutOfBoundsException if array bounds are exceeded - * @throws ArrayStoreException if new points are incompatible with dst - */ - public void transform(Point2D[] src, int srcOff, - Point2D[] dst, int dstOff, int num) - { - while (--num >= 0) - dst[dstOff] = transform(src[srcOff++], dst[dstOff++]); - } - - /** - * Perform this transformation on an array of points, in (x,y) pairs, - * storing the results in another (possibly same) array. This will not - * create a destination array. All sources are copied before the - * transformation, so that no result will overwrite a point that has not yet - * been evaluated. - * - * @param srcPts the array of source points - * @param srcOff the starting offset into src - * @param dstPts the array of destination points - * @param dstOff the starting offset into dst - * @param num the number of points to transform - * @throws NullPointerException if src or dst is null - * @throws ArrayIndexOutOfBoundsException if array bounds are exceeded - */ - public void transform(float[] srcPts, int srcOff, - float[] dstPts, int dstOff, int num) - { - if (srcPts == dstPts && dstOff > srcOff - && num > 1 && srcOff + 2 * num > dstOff) - { - float[] f = new float[2 * num]; - System.arraycopy(srcPts, srcOff, f, 0, 2 * num); - srcPts = f; - } - while (--num >= 0) - { - float x = srcPts[srcOff++]; - float y = srcPts[srcOff++]; - dstPts[dstOff++] = (float) (m00 * x + m01 * y + m02); - dstPts[dstOff++] = (float) (m10 * x + m11 * y + m12); - } - } - - /** - * Perform this transformation on an array of points, in (x,y) pairs, - * storing the results in another (possibly same) array. This will not - * create a destination array. All sources are copied before the - * transformation, so that no result will overwrite a point that has not yet - * been evaluated. - * - * @param srcPts the array of source points - * @param srcOff the starting offset into src - * @param dstPts the array of destination points - * @param dstOff the starting offset into dst - * @param num the number of points to transform - * @throws NullPointerException if src or dst is null - * @throws ArrayIndexOutOfBoundsException if array bounds are exceeded - */ - public void transform(double[] srcPts, int srcOff, - double[] dstPts, int dstOff, int num) - { - if (srcPts == dstPts && dstOff > srcOff - && num > 1 && srcOff + 2 * num > dstOff) - { - double[] d = new double[2 * num]; - System.arraycopy(srcPts, srcOff, d, 0, 2 * num); - srcPts = d; - } - while (--num >= 0) - { - double x = srcPts[srcOff++]; - double y = srcPts[srcOff++]; - dstPts[dstOff++] = m00 * x + m01 * y + m02; - dstPts[dstOff++] = m10 * x + m11 * y + m12; - } - } - - /** - * Perform this transformation on an array of points, in (x,y) pairs, - * storing the results in another array. This will not create a destination - * array. - * - * @param srcPts the array of source points - * @param srcOff the starting offset into src - * @param dstPts the array of destination points - * @param dstOff the starting offset into dst - * @param num the number of points to transform - * @throws NullPointerException if src or dst is null - * @throws ArrayIndexOutOfBoundsException if array bounds are exceeded - */ - public void transform(float[] srcPts, int srcOff, - double[] dstPts, int dstOff, int num) - { - while (--num >= 0) - { - float x = srcPts[srcOff++]; - float y = srcPts[srcOff++]; - dstPts[dstOff++] = m00 * x + m01 * y + m02; - dstPts[dstOff++] = m10 * x + m11 * y + m12; - } - } - - /** - * Perform this transformation on an array of points, in (x,y) pairs, - * storing the results in another array. This will not create a destination - * array. - * - * @param srcPts the array of source points - * @param srcOff the starting offset into src - * @param dstPts the array of destination points - * @param dstOff the starting offset into dst - * @param num the number of points to transform - * @throws NullPointerException if src or dst is null - * @throws ArrayIndexOutOfBoundsException if array bounds are exceeded - */ - public void transform(double[] srcPts, int srcOff, - float[] dstPts, int dstOff, int num) - { - while (--num >= 0) - { - double x = srcPts[srcOff++]; - double y = srcPts[srcOff++]; - dstPts[dstOff++] = (float) (m00 * x + m01 * y + m02); - dstPts[dstOff++] = (float) (m10 * x + m11 * y + m12); - } - } - - /** - * Perform the inverse of this transformation on the given source point, - * and store the result in the destination (creating it if necessary). It - * is safe for src and dst to be the same. - * - * @param src the source point - * @param dst the destination, or null - * @return the inverse transformation of src, in dst if it was non-null - * @throws NullPointerException if src is null - * @throws NoninvertibleTransformException if the inverse does not exist - * @see #getDeterminant() - */ - public Point2D inverseTransform(Point2D src, Point2D dst) - throws NoninvertibleTransformException - { - return createInverse().transform(src, dst); - } - - /** - * Perform the inverse of this transformation on an array of points, in - * (x,y) pairs, storing the results in another (possibly same) array. This - * will not create a destination array. All sources are copied before the - * transformation, so that no result will overwrite a point that has not yet - * been evaluated. - * - * @param srcPts the array of source points - * @param srcOff the starting offset into src - * @param dstPts the array of destination points - * @param dstOff the starting offset into dst - * @param num the number of points to transform - * @throws NullPointerException if src or dst is null - * @throws ArrayIndexOutOfBoundsException if array bounds are exceeded - * @throws NoninvertibleTransformException if the inverse does not exist - * @see #getDeterminant() - */ - public void inverseTransform(double[] srcPts, int srcOff, - double[] dstPts, int dstOff, int num) - throws NoninvertibleTransformException - { - createInverse().transform(srcPts, srcOff, dstPts, dstOff, num); - } - - /** - * Perform this transformation, less any translation, on the given source - * point, and store the result in the destination (creating it if - * necessary). It is safe for src and dst to be the same. The reduced - * transform is equivalent to: - * <pre> - * [ x' ] = [ m00 m01 ] [ x ] = [ m00 * x + m01 * y ] - * [ y' ] [ m10 m11 ] [ y ] = [ m10 * x + m11 * y ] - * </pre> - * - * @param src the source point - * @param dst the destination, or null - * @return the delta transformation of src, in dst if it was non-null - * @throws NullPointerException if src is null - */ - public Point2D deltaTransform(Point2D src, Point2D dst) - { - if (dst == null) - dst = new Point2D.Double(); - double x = src.getX(); - double y = src.getY(); - double nx = m00 * x + m01 * y; - double ny = m10 * x + m11 * y; - dst.setLocation(nx, ny); - return dst; - } - - /** - * Perform this transformation, less any translation, on an array of points, - * in (x,y) pairs, storing the results in another (possibly same) array. - * This will not create a destination array. All sources are copied before - * the transformation, so that no result will overwrite a point that has - * not yet been evaluated. The reduced transform is equivalent to: - * <pre> - * [ x' ] = [ m00 m01 ] [ x ] = [ m00 * x + m01 * y ] - * [ y' ] [ m10 m11 ] [ y ] = [ m10 * x + m11 * y ] - * </pre> - * - * @param srcPts the array of source points - * @param srcOff the starting offset into src - * @param dstPts the array of destination points - * @param dstOff the starting offset into dst - * @param num the number of points to transform - * @throws NullPointerException if src or dst is null - * @throws ArrayIndexOutOfBoundsException if array bounds are exceeded - */ - public void deltaTransform(double[] srcPts, int srcOff, - double[] dstPts, int dstOff, - int num) - { - if (srcPts == dstPts && dstOff > srcOff - && num > 1 && srcOff + 2 * num > dstOff) - { - double[] d = new double[2 * num]; - System.arraycopy(srcPts, srcOff, d, 0, 2 * num); - srcPts = d; - } - while (--num >= 0) - { - double x = srcPts[srcOff++]; - double y = srcPts[srcOff++]; - dstPts[dstOff++] = m00 * x + m01 * y; - dstPts[dstOff++] = m10 * x + m11 * y; - } - } - - /** - * Return a new Shape, based on the given one, where the path of the shape - * has been transformed by this transform. Notice that this uses GeneralPath, - * which only stores points in float precision. - * - * @param src the shape source to transform - * @return the shape, transformed by this, <code>null</code> if src is - * <code>null</code>. - * @see GeneralPath#transform(AffineTransform) - */ - public Shape createTransformedShape(Shape src) - { - if(src == null) - return null; - GeneralPath p = new GeneralPath(src); - p.transform(this); - return p; - } - - /** - * Returns a string representation of the transform, in the format: - * <code>"AffineTransform[[" + m00 + ", " + m01 + ", " + m02 + "], [" - * + m10 + ", " + m11 + ", " + m12 + "]]"</code>. - * - * @return the string representation - */ - public String toString() - { - return "AffineTransform[[" + m00 + ", " + m01 + ", " + m02 + "], [" - + m10 + ", " + m11 + ", " + m12 + "]]"; - } - - /** - * Tests if this transformation is the identity: - * <pre> - * [ 1 0 0 ] - * [ 0 1 0 ] - * [ 0 0 1 ] - * </pre> - * - * @return true if this is the identity transform - */ - public boolean isIdentity() - { - // Rather than rely on type, check explicitly. - return (m00 == 1 && m01 == 0 && m02 == 0 - && m10 == 0 && m11 == 1 && m12 == 0); - } - - /** - * Create a new transform of the same run-time type, with the same - * transforming properties as this one. - * - * @return the clone - */ - public Object clone() - { - try - { - return super.clone(); - } - catch (CloneNotSupportedException e) - { - throw (Error) new InternalError().initCause(e); // Impossible - } - } - - /** - * Return the hashcode for this transformation. The formula is not - * documented, but appears to be the same as: - * <pre> - * long l = Double.doubleToLongBits(getScaleX()); - * l = l * 31 + Double.doubleToLongBits(getShearY()); - * l = l * 31 + Double.doubleToLongBits(getShearX()); - * l = l * 31 + Double.doubleToLongBits(getScaleY()); - * l = l * 31 + Double.doubleToLongBits(getTranslateX()); - * l = l * 31 + Double.doubleToLongBits(getTranslateY()); - * return (int) ((l >> 32) ^ l); - * </pre> - * - * @return the hashcode - */ - public int hashCode() - { - long l = Double.doubleToLongBits(m00); - l = l * 31 + Double.doubleToLongBits(m10); - l = l * 31 + Double.doubleToLongBits(m01); - l = l * 31 + Double.doubleToLongBits(m11); - l = l * 31 + Double.doubleToLongBits(m02); - l = l * 31 + Double.doubleToLongBits(m12); - return (int) ((l >> 32) ^ l); - } - - /** - * Compares two transforms for equality. This returns true if they have the - * same matrix values. - * - * @param obj the transform to compare - * @return true if it is equal - */ - public boolean equals(Object obj) - { - if (! (obj instanceof AffineTransform)) - return false; - AffineTransform t = (AffineTransform) obj; - return (m00 == t.m00 && m01 == t.m01 && m02 == t.m02 - && m10 == t.m10 && m11 == t.m11 && m12 == t.m12); - } - - /** - * Helper to decode the type from the matrix. This is not guaranteed - * to find the optimal type, but at least it will be valid. - */ - private void updateType() - { - double det = getDeterminant(); - if (det == 0) - { - type = TYPE_GENERAL_TRANSFORM; - return; - } - // Scale (includes rotation by PI) or translation. - if (m01 == 0 && m10 == 0) - { - if (m00 == m11) - type = m00 == 1 ? TYPE_IDENTITY : TYPE_UNIFORM_SCALE; - else - type = TYPE_GENERAL_SCALE; - if (m02 != 0 || m12 != 0) - type |= TYPE_TRANSLATION; - } - // Rotation. - else if (m00 == m11 && m01 == -m10) - { - type = m00 == 0 ? TYPE_QUADRANT_ROTATION : TYPE_GENERAL_ROTATION; - if (det != 1) - type |= TYPE_UNIFORM_SCALE; - if (m02 != 0 || m12 != 0) - type |= TYPE_TRANSLATION; - } - else - type = TYPE_GENERAL_TRANSFORM; - } - - /** - * Reads a transform from an object stream. - * - * @param s the stream to read from - * @throws ClassNotFoundException if there is a problem deserializing - * @throws IOException if there is a problem deserializing - */ - private void readObject(ObjectInputStream s) - throws ClassNotFoundException, IOException - { - s.defaultReadObject(); - updateType(); - } -} // class AffineTransform diff --git a/libjava/java/awt/geom/Arc2D.java b/libjava/java/awt/geom/Arc2D.java deleted file mode 100644 index eff34a08144..00000000000 --- a/libjava/java/awt/geom/Arc2D.java +++ /dev/null @@ -1,1399 +0,0 @@ -/* Arc2D.java -- represents an arc in 2-D space - Copyright (C) 2002, 2003, 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.awt.geom; - -import java.util.NoSuchElementException; - - -/** - * This class represents all arcs (segments of an ellipse in 2-D space). The - * arcs are defined by starting angle and extent (arc length) in degrees, as - * opposed to radians (like the rest of Java), and can be open, chorded, or - * wedge shaped. The angles are skewed according to the ellipse, so that 45 - * degrees always points to the upper right corner (positive x, negative y) - * of the bounding rectangle. A positive extent draws a counterclockwise arc, - * and while the angle can be any value, the path iterator only traverses the - * first 360 degrees. Storage is up to the subclasses. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @author Sven de Marothy (sven@physto.se) - * @since 1.2 - */ -public abstract class Arc2D extends RectangularShape -{ - /** - * An open arc, with no segment connecting the endpoints. This type of - * arc still contains the same points as a chorded version. - */ - public static final int OPEN = 0; - - /** - * A closed arc with a single segment connecting the endpoints (a chord). - */ - public static final int CHORD = 1; - - /** - * A closed arc with two segments, one from each endpoint, meeting at the - * center of the ellipse. - */ - public static final int PIE = 2; - - /** The closure type of this arc. This is package-private to avoid an - * accessor method. */ - int type; - - /** - * Create a new arc, with the specified closure type. - * - * @param type one of {@link #OPEN}, {@link #CHORD}, or {@link #PIE}. - * @throws IllegalArgumentException if type is invalid - */ - protected Arc2D(int type) - { - if (type < OPEN || type > PIE) - throw new IllegalArgumentException(); - this.type = type; - } - - /** - * Get the starting angle of the arc in degrees. - * - * @return the starting angle - * @see #setAngleStart(double) - */ - public abstract double getAngleStart(); - - /** - * Get the extent angle of the arc in degrees. - * - * @return the extent angle - * @see #setAngleExtent(double) - */ - public abstract double getAngleExtent(); - - /** - * Return the closure type of the arc. - * - * @return the closure type - * @see #OPEN - * @see #CHORD - * @see #PIE - * @see #setArcType(int) - */ - public int getArcType() - { - return type; - } - - /** - * Returns the starting point of the arc. - * - * @return the start point - */ - public Point2D getStartPoint() - { - double angle = Math.toRadians(getAngleStart()); - double rx = getWidth() / 2; - double ry = getHeight() / 2; - double x = getX() + rx + rx * Math.cos(angle); - double y = getY() + ry - ry * Math.sin(angle); - return new Point2D.Double(x, y); - } - - /** - * Returns the ending point of the arc. - * - * @return the end point - */ - public Point2D getEndPoint() - { - double angle = Math.toRadians(getAngleStart() + getAngleExtent()); - double rx = getWidth() / 2; - double ry = getHeight() / 2; - double x = getX() + rx + rx * Math.cos(angle); - double y = getY() + ry - ry * Math.sin(angle); - return new Point2D.Double(x, y); - } - - /** - * Set the parameters of the arc. The angles are in degrees, and a positive - * extent sweeps counterclockwise (from the positive x-axis to the negative - * y-axis). - * - * @param x the new x coordinate of the upper left of the bounding box - * @param y the new y coordinate of the upper left of the bounding box - * @param w the new width of the bounding box - * @param h the new height of the bounding box - * @param start the start angle, in degrees - * @param extent the arc extent, in degrees - * @param type one of {@link #OPEN}, {@link #CHORD}, or {@link #PIE} - * @throws IllegalArgumentException if type is invalid - */ - public abstract void setArc(double x, double y, double w, double h, - double start, double extent, int type); - - /** - * Set the parameters of the arc. The angles are in degrees, and a positive - * extent sweeps counterclockwise (from the positive x-axis to the negative - * y-axis). - * - * @param p the upper left point of the bounding box - * @param d the dimensions of the bounding box - * @param start the start angle, in degrees - * @param extent the arc extent, in degrees - * @param type one of {@link #OPEN}, {@link #CHORD}, or {@link #PIE} - * @throws IllegalArgumentException if type is invalid - * @throws NullPointerException if p or d is null - */ - public void setArc(Point2D p, Dimension2D d, double start, double extent, - int type) - { - setArc(p.getX(), p.getY(), d.getWidth(), d.getHeight(), start, extent, type); - } - - /** - * Set the parameters of the arc. The angles are in degrees, and a positive - * extent sweeps counterclockwise (from the positive x-axis to the negative - * y-axis). - * - * @param r the new bounding box - * @param start the start angle, in degrees - * @param extent the arc extent, in degrees - * @param type one of {@link #OPEN}, {@link #CHORD}, or {@link #PIE} - * @throws IllegalArgumentException if type is invalid - * @throws NullPointerException if r is null - */ - public void setArc(Rectangle2D r, double start, double extent, int type) - { - setArc(r.getX(), r.getY(), r.getWidth(), r.getHeight(), start, extent, type); - } - - /** - * Set the parameters of the arc from the given one. - * - * @param a the arc to copy - * @throws NullPointerException if a is null - */ - public void setArc(Arc2D a) - { - setArc(a.getX(), a.getY(), a.getWidth(), a.getHeight(), a.getAngleStart(), - a.getAngleExtent(), a.getArcType()); - } - - /** - * Set the parameters of the arc. The angles are in degrees, and a positive - * extent sweeps counterclockwise (from the positive x-axis to the negative - * y-axis). This controls the center point and radius, so the arc will be - * circular. - * - * @param x the x coordinate of the center of the circle - * @param y the y coordinate of the center of the circle - * @param r the radius of the circle - * @param start the start angle, in degrees - * @param extent the arc extent, in degrees - * @param type one of {@link #OPEN}, {@link #CHORD}, or {@link #PIE} - * @throws IllegalArgumentException if type is invalid - */ - public void setArcByCenter(double x, double y, double r, double start, - double extent, int type) - { - setArc(x - r, y - r, r + r, r + r, start, extent, type); - } - - /** - * Sets the parameters of the arc by finding the tangents of two lines, and - * using the specified radius. The arc will be circular, will begin on the - * tangent point of the line extending from p1 to p2, and will end on the - * tangent point of the line extending from p2 to p3. - * - * XXX What happens if the points are colinear, or the radius negative? - * - * @param p1 the first point - * @param p2 the tangent line intersection point - * @param p3 the third point - * @param r the radius of the arc - * @throws NullPointerException if any point is null - */ - public void setArcByTangent(Point2D p1, Point2D p2, Point2D p3, double r) - { - if ((p2.getX() - p1.getX()) * (p3.getY() - p1.getY()) - - (p3.getX() - p1.getX()) * (p2.getY() - p1.getY()) > 0) - { - Point2D p = p3; - p3 = p1; - p1 = p; - } - - // normalized tangent vectors - double dx1 = (p1.getX() - p2.getX()) / p1.distance(p2); - double dy1 = (p1.getY() - p2.getY()) / p1.distance(p2); - double dx2 = (p2.getX() - p3.getX()) / p3.distance(p2); - double dy2 = (p2.getY() - p3.getY()) / p3.distance(p2); - double theta1 = Math.atan2(dx1, dy1); - double theta2 = Math.atan2(dx2, dy2); - - double dx = r * Math.cos(theta2) - r * Math.cos(theta1); - double dy = -r * Math.sin(theta2) + r * Math.sin(theta1); - - if (theta1 < 0) - theta1 += 2 * Math.PI; - if (theta2 < 0) - theta2 += 2 * Math.PI; - if (theta2 < theta1) - theta2 += 2 * Math.PI; - - // Vectors of the lines, not normalized, note we change - // the direction of line 2. - dx1 = p1.getX() - p2.getX(); - dy1 = p1.getY() - p2.getY(); - dx2 = p3.getX() - p2.getX(); - dy2 = p3.getY() - p2.getY(); - - // Calculate the tangent point to the second line - double t2 = -(dx1 * dy - dy1 * dx) / (dx2 * dy1 - dx1 * dy2); - double x2 = t2 * (p3.getX() - p2.getX()) + p2.getX(); - double y2 = t2 * (p3.getY() - p2.getY()) + p2.getY(); - - // calculate the center point - double x = x2 - r * Math.cos(theta2); - double y = y2 + r * Math.sin(theta2); - - setArc(x - r, y - r, 2 * r, 2 * r, Math.toDegrees(theta1), - Math.toDegrees(theta2 - theta1), getArcType()); - } - - /** - * Set the start, in degrees. - * - * @param start the new start angle - * @see #getAngleStart() - */ - public abstract void setAngleStart(double start); - - /** - * Set the extent, in degrees. - * - * @param extent the new extent angle - * @see #getAngleExtent() - */ - public abstract void setAngleExtent(double extent); - - /** - * Sets the starting angle to the angle of the given point relative to - * the center of the arc. The extent remains constant; in other words, - * this rotates the arc. - * - * @param p the new start point - * @throws NullPointerException if p is null - * @see #getStartPoint() - * @see #getAngleStart() - */ - public void setAngleStart(Point2D p) - { - // Normalize. - double x = p.getX() - (getX() + getWidth() / 2); - double y = p.getY() - (getY() + getHeight() / 2); - setAngleStart(Math.toDegrees(Math.atan2(-y, x))); - } - - /** - * Sets the starting and extent angles to those of the given points - * relative to the center of the arc. The arc will be non-empty, and will - * extend counterclockwise. - * - * @param x1 the first x coordinate - * @param y1 the first y coordinate - * @param x2 the second x coordinate - * @param y2 the second y coordinate - * @see #setAngleStart(Point2D) - */ - public void setAngles(double x1, double y1, double x2, double y2) - { - // Normalize the points. - double mx = getX(); - double my = getY(); - double mw = getWidth(); - double mh = getHeight(); - x1 = x1 - (mx + mw / 2); - y1 = y1 - (my + mh / 2); - x2 = x2 - (mx + mw / 2); - y2 = y2 - (my + mh / 2); - double start = Math.toDegrees(Math.atan2(-y1, x1)); - double extent = Math.toDegrees(Math.atan2(-y2, x2)) - start; - if (extent < 0) - extent += 360; - setAngleStart(start); - setAngleExtent(extent); - } - - /** - * Sets the starting and extent angles to those of the given points - * relative to the center of the arc. The arc will be non-empty, and will - * extend counterclockwise. - * - * @param p1 the first point - * @param p2 the second point - * @throws NullPointerException if either point is null - * @see #setAngleStart(Point2D) - */ - public void setAngles(Point2D p1, Point2D p2) - { - setAngles(p1.getX(), p1.getY(), p2.getX(), p2.getY()); - } - - /** - * Set the closure type of this arc. - * - * @param type one of {@link #OPEN}, {@link #CHORD}, or {@link #PIE} - * @throws IllegalArgumentException if type is invalid - * @see #getArcType() - */ - public void setArcType(int type) - { - if (type < OPEN || type > PIE) - throw new IllegalArgumentException(); - this.type = type; - } - - /** - * Sets the location and bounds of the ellipse of which this arc is a part. - * - * @param x the new x coordinate - * @param y the new y coordinate - * @param w the new width - * @param h the new height - * @see #getFrame() - */ - public void setFrame(double x, double y, double w, double h) - { - setArc(x, y, w, h, getAngleStart(), getAngleExtent(), type); - } - - /** - * Gets the bounds of the arc. This is much tighter than - * <code>getBounds</code>, as it takes into consideration the start and - * end angles, and the center point of a pie wedge, rather than just the - * overall ellipse. - * - * @return the bounds of the arc - * @see #getBounds() - */ - public Rectangle2D getBounds2D() - { - double extent = getAngleExtent(); - if (Math.abs(extent) >= 360) - return makeBounds(getX(), getY(), getWidth(), getHeight()); - - // Find the minimal bounding box. This determined by its extrema, - // which are the center, the endpoints of the arc, and any local - // maximum contained by the arc. - double rX = getWidth() / 2; - double rY = getHeight() / 2; - double centerX = getX() + rX; - double centerY = getY() + rY; - - Point2D p1 = getStartPoint(); - Rectangle2D result = makeBounds(p1.getX(), p1.getY(), 0, 0); - result.add(getEndPoint()); - - if (type == PIE) - result.add(centerX, centerY); - if (containsAngle(0)) - result.add(centerX + rX, centerY); - if (containsAngle(90)) - result.add(centerX, centerY - rY); - if (containsAngle(180)) - result.add(centerX - rX, centerY); - if (containsAngle(270)) - result.add(centerX, centerY + rY); - - return result; - } - - /** - * Construct a bounding box in a precision appropriate for the subclass. - * - * @param x the x coordinate - * @param y the y coordinate - * @param w the width - * @param h the height - * @return the rectangle for use in getBounds2D - */ - protected abstract Rectangle2D makeBounds(double x, double y, double w, - double h); - - /** - * Tests if the given angle, in degrees, is included in the arc. - * All angles are normalized to be between 0 and 360 degrees. - * - * @param a the angle to test - * @return true if it is contained - */ - public boolean containsAngle(double a) - { - double start = getAngleStart(); - double extent = getAngleExtent(); - double end = start + extent; - - if (extent == 0) - return false; - - if (extent >= 360 || extent <= -360) - return true; - - if (extent < 0) - { - end = start; - start += extent; - } - - start %= 360; - while (start < 0) - start += 360; - - end %= 360; - while (end < start) - end += 360; - - a %= 360; - while (a < start) - a += 360; - - return a >= start && a < end; // starting angle included, ending angle not - } - - /** - * Determines if the arc contains the given point. If the bounding box - * is empty, then this will return false. - * - * The area considered 'inside' an arc of type OPEN is the same as the - * area inside an equivalent filled CHORD-type arc. The area considered - * 'inside' a CHORD-type arc is the same as the filled area. - * - * @param x the x coordinate to test - * @param y the y coordinate to test - * @return true if the point is inside the arc - */ - public boolean contains(double x, double y) - { - double w = getWidth(); - double h = getHeight(); - double extent = getAngleExtent(); - if (w <= 0 || h <= 0 || extent == 0) - return false; - - double mx = getX() + w / 2; - double my = getY() + h / 2; - double dx = (x - mx) * 2 / w; - double dy = (y - my) * 2 / h; - if ((dx * dx + dy * dy) >= 1.0) - return false; - - double angle = Math.toDegrees(Math.atan2(-dy, dx)); - if (getArcType() == PIE) - return containsAngle(angle); - - double a1 = Math.toRadians(getAngleStart()); - double a2 = Math.toRadians(getAngleStart() + extent); - double x1 = mx + getWidth() * Math.cos(a1) / 2; - double y1 = my - getHeight() * Math.sin(a1) / 2; - double x2 = mx + getWidth() * Math.cos(a2) / 2; - double y2 = my - getHeight() * Math.sin(a2) / 2; - double sgn = ((x2 - x1) * (my - y1) - (mx - x1) * (y2 - y1)) * ((x2 - x1) * (y - - y1) - (x - x1) * (y2 - y1)); - - if (Math.abs(extent) > 180) - { - if (containsAngle(angle)) - return true; - return sgn > 0; - } - else - { - if (! containsAngle(angle)) - return false; - return sgn < 0; - } - } - - /** - * Tests if a given rectangle intersects the area of the arc. - * - * For a definition of the 'inside' area, see the contains() method. - * @see #contains(double, double) - * - * @param x the x coordinate of the rectangle - * @param y the y coordinate of the rectangle - * @param w the width of the rectangle - * @param h the height of the rectangle - * @return true if the two shapes share common points - */ - public boolean intersects(double x, double y, double w, double h) - { - double extent = getAngleExtent(); - if (extent == 0) - return false; - - if (contains(x, y) || contains(x, y + h) || contains(x + w, y) - || contains(x + w, y + h)) - return true; - - Rectangle2D rect = new Rectangle2D.Double(x, y, w, h); - - double a = getWidth() / 2.0; - double b = getHeight() / 2.0; - - double mx = getX() + a; - double my = getY() + b; - double x1 = mx + a * Math.cos(Math.toRadians(getAngleStart())); - double y1 = my - b * Math.sin(Math.toRadians(getAngleStart())); - double x2 = mx + a * Math.cos(Math.toRadians(getAngleStart() + extent)); - double y2 = my - b * Math.sin(Math.toRadians(getAngleStart() + extent)); - - if (getArcType() != CHORD) - { - // check intersections against the pie radii - if (rect.intersectsLine(mx, my, x1, y1)) - return true; - if (rect.intersectsLine(mx, my, x2, y2)) - return true; - } - else// check the chord - if (rect.intersectsLine(x1, y1, x2, y2)) - return true; - - // Check the Arc segment against the four edges - double dx; - - // Check the Arc segment against the four edges - double dy; - dy = y - my; - dx = a * Math.sqrt(1 - ((dy * dy) / (b * b))); - if (! java.lang.Double.isNaN(dx)) - { - if (mx + dx >= x && mx + dx <= x + w - && containsAngle(Math.toDegrees(Math.atan2(-dy, dx)))) - return true; - if (mx - dx >= x && mx - dx <= x + w - && containsAngle(Math.toDegrees(Math.atan2(-dy, -dx)))) - return true; - } - dy = (y + h) - my; - dx = a * Math.sqrt(1 - ((dy * dy) / (b * b))); - if (! java.lang.Double.isNaN(dx)) - { - if (mx + dx >= x && mx + dx <= x + w - && containsAngle(Math.toDegrees(Math.atan2(-dy, dx)))) - return true; - if (mx - dx >= x && mx - dx <= x + w - && containsAngle(Math.toDegrees(Math.atan2(-dy, -dx)))) - return true; - } - dx = x - mx; - dy = b * Math.sqrt(1 - ((dx * dx) / (a * a))); - if (! java.lang.Double.isNaN(dy)) - { - if (my + dy >= y && my + dy <= y + h - && containsAngle(Math.toDegrees(Math.atan2(-dy, dx)))) - return true; - if (my - dy >= y && my - dy <= y + h - && containsAngle(Math.toDegrees(Math.atan2(dy, dx)))) - return true; - } - - dx = (x + w) - mx; - dy = b * Math.sqrt(1 - ((dx * dx) / (a * a))); - if (! java.lang.Double.isNaN(dy)) - { - if (my + dy >= y && my + dy <= y + h - && containsAngle(Math.toDegrees(Math.atan2(-dy, dx)))) - return true; - if (my - dy >= y && my - dy <= y + h - && containsAngle(Math.toDegrees(Math.atan2(dy, dx)))) - return true; - } - - // Check whether the arc is contained within the box - if (rect.contains(mx, my)) - return true; - - return false; - } - - /** - * Tests if a given rectangle is contained in the area of the arc. - * - * @param x the x coordinate of the rectangle - * @param y the y coordinate of the rectangle - * @param w the width of the rectangle - * @param h the height of the rectangle - * @return true if the arc contains the rectangle - */ - public boolean contains(double x, double y, double w, double h) - { - double extent = getAngleExtent(); - if (extent == 0) - return false; - - if (! (contains(x, y) && contains(x, y + h) && contains(x + w, y) - && contains(x + w, y + h))) - return false; - - Rectangle2D rect = new Rectangle2D.Double(x, y, w, h); - - double a = getWidth() / 2.0; - double b = getHeight() / 2.0; - - double mx = getX() + a; - double my = getY() + b; - double x1 = mx + a * Math.cos(Math.toRadians(getAngleStart())); - double y1 = my - b * Math.sin(Math.toRadians(getAngleStart())); - double x2 = mx + a * Math.cos(Math.toRadians(getAngleStart() + extent)); - double y2 = my - b * Math.sin(Math.toRadians(getAngleStart() + extent)); - if (getArcType() != CHORD) - { - // check intersections against the pie radii - if (rect.intersectsLine(mx, my, x1, y1)) - return false; - - if (rect.intersectsLine(mx, my, x2, y2)) - return false; - } - else if (rect.intersectsLine(x1, y1, x2, y2)) - return false; - return true; - } - - /** - * Tests if a given rectangle is contained in the area of the arc. - * - * @param r the rectangle - * @return true if the arc contains the rectangle - */ - public boolean contains(Rectangle2D r) - { - return contains(r.getX(), r.getY(), r.getWidth(), r.getHeight()); - } - - /** - * Returns an iterator over this arc, with an optional transformation. - * This iterator is threadsafe, so future modifications to the arc do not - * affect the iteration. - * - * @param at the transformation, or null - * @return a path iterator - */ - public PathIterator getPathIterator(AffineTransform at) - { - return new ArcIterator(this, at); - } - - /** - * This class is used to iterate over an arc. Since ellipses are a subclass - * of arcs, this is used by Ellipse2D as well. - * - * @author Eric Blake (ebb9@email.byu.edu) - */ - static final class ArcIterator implements PathIterator - { - /** The current iteration. */ - private int current; - - /** The last iteration. */ - private final int limit; - - /** The optional transformation. */ - private final AffineTransform xform; - - /** The x coordinate of the bounding box. */ - private final double x; - - /** The y coordinate of the bounding box. */ - private final double y; - - /** The width of the bounding box. */ - private final double w; - - /** The height of the bounding box. */ - private final double h; - - /** The start angle, in radians (not degrees). */ - private final double start; - - /** The extent angle, in radians (not degrees). */ - private final double extent; - - /** The arc closure type. */ - private final int type; - - /** - * Construct a new iterator over an arc. - * - * @param a the arc - * @param xform the transform - */ - public ArcIterator(Arc2D a, AffineTransform xform) - { - this.xform = xform; - x = a.getX(); - y = a.getY(); - w = a.getWidth(); - h = a.getHeight(); - double start = a.getAngleStart() * (Math.PI / 180); - double extent = a.getAngleExtent() * (Math.PI / 180); - - if (extent < 0) - { - extent = -extent; - start = 2 * Math.PI - extent + start; - } - this.start = start; - this.extent = extent; - - type = a.type; - if (w < 0 || h < 0) - limit = -1; - else if (extent == 0) - limit = type; - else if (extent <= Math.PI / 2.0) - limit = type + 1; - else if (extent <= Math.PI) - limit = type + 2; - else if (extent <= 3.0 * (Math.PI / 2.0)) - limit = type + 3; - else - limit = type + 4; - } - - /** - * Construct a new iterator over an ellipse. - * - * @param e the ellipse - * @param xform the transform - */ - public ArcIterator(Ellipse2D e, AffineTransform xform) - { - this.xform = xform; - x = e.getX(); - y = e.getY(); - w = e.getWidth(); - h = e.getHeight(); - start = 0; - extent = 2 * Math.PI; - type = CHORD; - limit = (w < 0 || h < 0) ? -1 : 5; - } - - /** - * Return the winding rule. - * - * @return {@link PathIterator#WIND_NON_ZERO} - */ - public int getWindingRule() - { - return WIND_NON_ZERO; - } - - /** - * Test if the iteration is complete. - * - * @return true if more segments exist - */ - public boolean isDone() - { - return current > limit; - } - - /** - * Advance the iterator. - */ - public void next() - { - current++; - } - - /** - * Put the current segment into the array, and return the segment type. - * - * @param coords an array of 6 elements - * @return the segment type - * @throws NullPointerException if coords is null - * @throws ArrayIndexOutOfBoundsException if coords is too small - */ - public int currentSegment(float[] coords) - { - double[] double_coords = new double[6]; - int code = currentSegment(double_coords); - for (int i = 0; i < 6; ++i) - coords[i] = (float) double_coords[i]; - return code; - } - - /** - * Put the current segment into the array, and return the segment type. - * - * @param coords an array of 6 elements - * @return the segment type - * @throws NullPointerException if coords is null - * @throws ArrayIndexOutOfBoundsException if coords is too small - */ - public int currentSegment(double[] coords) - { - double rx = w / 2; - double ry = h / 2; - double xmid = x + rx; - double ymid = y + ry; - - if (current > limit) - throw new NoSuchElementException("arc iterator out of bounds"); - - if (current == 0) - { - coords[0] = xmid + rx * Math.cos(start); - coords[1] = ymid - ry * Math.sin(start); - if (xform != null) - xform.transform(coords, 0, coords, 0, 1); - return SEG_MOVETO; - } - - if (type != OPEN && current == limit) - return SEG_CLOSE; - - if ((current == limit - 1) && (type == PIE)) - { - coords[0] = xmid; - coords[1] = ymid; - if (xform != null) - xform.transform(coords, 0, coords, 0, 1); - return SEG_LINETO; - } - - // note that this produces a cubic approximation of the arc segment, - // not a true ellipsoid. there's no ellipsoid path segment code, - // unfortunately. the cubic approximation looks about right, though. - double kappa = (Math.sqrt(2.0) - 1.0) * (4.0 / 3.0); - double quad = (Math.PI / 2.0); - - double curr_begin = start + (current - 1) * quad; - double curr_extent = Math.min((start + extent) - curr_begin, quad); - double portion_of_a_quadrant = curr_extent / quad; - - double x0 = xmid + rx * Math.cos(curr_begin); - double y0 = ymid - ry * Math.sin(curr_begin); - - double x1 = xmid + rx * Math.cos(curr_begin + curr_extent); - double y1 = ymid - ry * Math.sin(curr_begin + curr_extent); - - AffineTransform trans = new AffineTransform(); - double[] cvec = new double[2]; - double len = kappa * portion_of_a_quadrant; - double angle = curr_begin; - - // in a hypothetical "first quadrant" setting, our first control - // vector would be sticking up, from [1,0] to [1,kappa]. - // - // let us recall however that in java2d, y coords are upside down - // from what one would consider "normal" first quadrant rules, so we - // will *subtract* the y value of this control vector from our first - // point. - cvec[0] = 0; - cvec[1] = len; - trans.scale(rx, ry); - trans.rotate(angle); - trans.transform(cvec, 0, cvec, 0, 1); - coords[0] = x0 + cvec[0]; - coords[1] = y0 - cvec[1]; - - // control vector #2 would, ideally, be sticking out and to the - // right, in a first quadrant arc segment. again, subtraction of y. - cvec[0] = 0; - cvec[1] = -len; - trans.rotate(curr_extent); - trans.transform(cvec, 0, cvec, 0, 1); - coords[2] = x1 + cvec[0]; - coords[3] = y1 - cvec[1]; - - // end point - coords[4] = x1; - coords[5] = y1; - - if (xform != null) - xform.transform(coords, 0, coords, 0, 3); - - return SEG_CUBICTO; - } - } // class ArcIterator - - /** - * This class implements an arc in double precision. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.2 - */ - public static class Double extends Arc2D - { - /** The x coordinate of the box bounding the ellipse of this arc. */ - public double x; - - /** The y coordinate of the box bounding the ellipse of this arc. */ - public double y; - - /** The width of the box bounding the ellipse of this arc. */ - public double width; - - /** The height of the box bounding the ellipse of this arc. */ - public double height; - - /** The start angle of this arc, in degrees. */ - public double start; - - /** The extent angle of this arc, in degrees. */ - public double extent; - - /** - * Create a new, open arc at (0,0) with 0 extent. - */ - public Double() - { - super(OPEN); - } - - /** - * Create a new arc of the given type at (0,0) with 0 extent. - * - * @param type the arc type: {@link #OPEN}, {@link #CHORD}, or {@link #PIE} - * @throws IllegalArgumentException if type is invalid - */ - public Double(int type) - { - super(type); - } - - /** - * Create a new arc with the given dimensions. - * - * @param x the x coordinate - * @param y the y coordinate - * @param w the width - * @param h the height - * @param start the start angle, in degrees - * @param extent the extent, in degrees - * @param type the arc type: {@link #OPEN}, {@link #CHORD}, or {@link #PIE} - * @throws IllegalArgumentException if type is invalid - */ - public Double(double x, double y, double w, double h, double start, - double extent, int type) - { - super(type); - this.x = x; - this.y = y; - width = w; - height = h; - this.start = start; - this.extent = extent; - } - - /** - * Create a new arc with the given dimensions. - * - * @param r the bounding box - * @param start the start angle, in degrees - * @param extent the extent, in degrees - * @param type the arc type: {@link #OPEN}, {@link #CHORD}, or {@link #PIE} - * @throws IllegalArgumentException if type is invalid - * @throws NullPointerException if r is null - */ - public Double(Rectangle2D r, double start, double extent, int type) - { - super(type); - x = r.getX(); - y = r.getY(); - width = r.getWidth(); - height = r.getHeight(); - this.start = start; - this.extent = extent; - } - - /** - * Return the x coordinate of the bounding box. - * - * @return the value of x - */ - public double getX() - { - return x; - } - - /** - * Return the y coordinate of the bounding box. - * - * @return the value of y - */ - public double getY() - { - return y; - } - - /** - * Return the width of the bounding box. - * - * @return the value of width - */ - public double getWidth() - { - return width; - } - - /** - * Return the height of the bounding box. - * - * @return the value of height - */ - public double getHeight() - { - return height; - } - - /** - * Return the start angle of the arc, in degrees. - * - * @return the value of start - */ - public double getAngleStart() - { - return start; - } - - /** - * Return the extent of the arc, in degrees. - * - * @return the value of extent - */ - public double getAngleExtent() - { - return extent; - } - - /** - * Tests if the arc contains points. - * - * @return true if the arc has no interior - */ - public boolean isEmpty() - { - return width <= 0 || height <= 0; - } - - /** - * Sets the arc to the given dimensions. - * - * @param x the x coordinate - * @param y the y coordinate - * @param w the width - * @param h the height - * @param start the start angle, in degrees - * @param extent the extent, in degrees - * @param type the arc type: {@link #OPEN}, {@link #CHORD}, or {@link #PIE} - * @throws IllegalArgumentException if type is invalid - */ - public void setArc(double x, double y, double w, double h, double start, - double extent, int type) - { - this.x = x; - this.y = y; - width = w; - height = h; - this.start = start; - this.extent = extent; - setArcType(type); - } - - /** - * Sets the start angle of the arc. - * - * @param start the new start angle - */ - public void setAngleStart(double start) - { - this.start = start; - } - - /** - * Sets the extent angle of the arc. - * - * @param extent the new extent angle - */ - public void setAngleExtent(double extent) - { - this.extent = extent; - } - - /** - * Creates a tight bounding box given dimensions that more precise than - * the bounding box of the ellipse. - * - * @param x the x coordinate - * @param y the y coordinate - * @param w the width - * @param h the height - */ - protected Rectangle2D makeBounds(double x, double y, double w, double h) - { - return new Rectangle2D.Double(x, y, w, h); - } - } // class Double - - /** - * This class implements an arc in float precision. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.2 - */ - public static class Float extends Arc2D - { - /** The x coordinate of the box bounding the ellipse of this arc. */ - public float x; - - /** The y coordinate of the box bounding the ellipse of this arc. */ - public float y; - - /** The width of the box bounding the ellipse of this arc. */ - public float width; - - /** The height of the box bounding the ellipse of this arc. */ - public float height; - - /** The start angle of this arc, in degrees. */ - public float start; - - /** The extent angle of this arc, in degrees. */ - public float extent; - - /** - * Create a new, open arc at (0,0) with 0 extent. - */ - public Float() - { - super(OPEN); - } - - /** - * Create a new arc of the given type at (0,0) with 0 extent. - * - * @param type the arc type: {@link #OPEN}, {@link #CHORD}, or {@link #PIE} - * @throws IllegalArgumentException if type is invalid - */ - public Float(int type) - { - super(type); - } - - /** - * Create a new arc with the given dimensions. - * - * @param x the x coordinate - * @param y the y coordinate - * @param w the width - * @param h the height - * @param start the start angle, in degrees - * @param extent the extent, in degrees - * @param type the arc type: {@link #OPEN}, {@link #CHORD}, or {@link #PIE} - * @throws IllegalArgumentException if type is invalid - */ - public Float(float x, float y, float w, float h, float start, - float extent, int type) - { - super(type); - this.x = x; - this.y = y; - width = w; - height = h; - this.start = start; - this.extent = extent; - } - - /** - * Create a new arc with the given dimensions. - * - * @param r the bounding box - * @param start the start angle, in degrees - * @param extent the extent, in degrees - * @param type the arc type: {@link #OPEN}, {@link #CHORD}, or {@link #PIE} - * @throws IllegalArgumentException if type is invalid - * @throws NullPointerException if r is null - */ - public Float(Rectangle2D r, float start, float extent, int type) - { - super(type); - x = (float) r.getX(); - y = (float) r.getY(); - width = (float) r.getWidth(); - height = (float) r.getHeight(); - this.start = start; - this.extent = (float) extent; - } - - /** - * Return the x coordinate of the bounding box. - * - * @return the value of x - */ - public double getX() - { - return x; - } - - /** - * Return the y coordinate of the bounding box. - * - * @return the value of y - */ - public double getY() - { - return y; - } - - /** - * Return the width of the bounding box. - * - * @return the value of width - */ - public double getWidth() - { - return width; - } - - /** - * Return the height of the bounding box. - * - * @return the value of height - */ - public double getHeight() - { - return height; - } - - /** - * Return the start angle of the arc, in degrees. - * - * @return the value of start - */ - public double getAngleStart() - { - return start; - } - - /** - * Return the extent of the arc, in degrees. - * - * @return the value of extent - */ - public double getAngleExtent() - { - return extent; - } - - /** - * Tests if the arc contains points. - * - * @return true if the arc has no interior - */ - public boolean isEmpty() - { - return width <= 0 || height <= 0; - } - - /** - * Sets the arc to the given dimensions. - * - * @param x the x coordinate - * @param y the y coordinate - * @param w the width - * @param h the height - * @param start the start angle, in degrees - * @param extent the extent, in degrees - * @param type the arc type: {@link #OPEN}, {@link #CHORD}, or {@link #PIE} - * @throws IllegalArgumentException if type is invalid - */ - public void setArc(double x, double y, double w, double h, double start, - double extent, int type) - { - this.x = (float) x; - this.y = (float) y; - width = (float) w; - height = (float) h; - this.start = (float) start; - this.extent = (float) extent; - setArcType(type); - } - - /** - * Sets the start angle of the arc. - * - * @param start the new start angle - */ - public void setAngleStart(double start) - { - this.start = (float) start; - } - - /** - * Sets the extent angle of the arc. - * - * @param extent the new extent angle - */ - public void setAngleExtent(double extent) - { - this.extent = (float) extent; - } - - /** - * Creates a tight bounding box given dimensions that more precise than - * the bounding box of the ellipse. - * - * @param x the x coordinate - * @param y the y coordinate - * @param w the width - * @param h the height - */ - protected Rectangle2D makeBounds(double x, double y, double w, double h) - { - return new Rectangle2D.Float((float) x, (float) y, (float) w, (float) h); - } - } // class Float -} // class Arc2D diff --git a/libjava/java/awt/geom/Area.java b/libjava/java/awt/geom/Area.java deleted file mode 100644 index 7a0fac43a34..00000000000 --- a/libjava/java/awt/geom/Area.java +++ /dev/null @@ -1,3312 +0,0 @@ -/* Area.java -- represents a shape built by constructive area geometry - Copyright (C) 2002, 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.awt.geom; - -import java.awt.Rectangle; -import java.awt.Shape; -import java.util.Vector; - - -/** - * The Area class represents any area for the purpose of - * Constructive Area Geometry (CAG) manipulations. CAG manipulations - * work as an area-wise form of boolean logic, where the basic operations are: - * <P><li>Add (in boolean algebra: A <B>or</B> B)<BR> - * <li>Subtract (in boolean algebra: A <B>and</B> (<B>not</B> B) )<BR> - * <li>Intersect (in boolean algebra: A <B>and</B> B)<BR> - * <li>Exclusive Or <BR> - * <img src="doc-files/Area-1.png" width="342" height="302" - * alt="Illustration of CAG operations" /><BR> - * Above is an illustration of the CAG operations on two ring shapes.<P> - * - * The contains and intersects() methods are also more accurate than the - * specification of #Shape requires.<P> - * - * Please note that constructing an Area can be slow - * (Self-intersection resolving is proportional to the square of - * the number of segments).<P> - * @see #add(Area) - * @see #subtract(Area) - * @see #intersect(Area) - * @see #exclusiveOr(Area) - * - * @author Sven de Marothy (sven@physto.se) - * - * @since 1.2 - * @status Works, but could be faster and more reliable. - */ -public class Area implements Shape, Cloneable -{ - /** - * General numerical precision - */ - private static final double EPSILON = 1E-11; - - /** - * recursive subdivision epsilon - (see getRecursionDepth) - */ - private static final double RS_EPSILON = 1E-13; - - /** - * Snap distance - points within this distance are considered equal - */ - private static final double PE_EPSILON = 1E-11; - - /** - * Segment vectors containing solid areas and holes - * This is package-private to avoid an accessor method. - */ - Vector solids; - - /** - * Segment vectors containing solid areas and holes - * This is package-private to avoid an accessor method. - */ - Vector holes; - - /** - * Vector (temporary) storing curve-curve intersections - */ - private Vector cc_intersections; - - /** - * Winding rule WIND_NON_ZERO used, after construction, - * this is irrelevant. - */ - private int windingRule; - - /** - * Constructs an empty Area - */ - public Area() - { - solids = new Vector(); - holes = new Vector(); - } - - /** - * Constructs an Area from any given Shape. <P> - * - * If the Shape is self-intersecting, the created Area will consist - * of non-self-intersecting subpaths, and any inner paths which - * are found redundant in accordance with the Shape's winding rule - * will not be included. - * - * @param s the shape (<code>null</code> not permitted). - * - * @throws NullPointerException if <code>s</code> is <code>null</code>. - */ - public Area(Shape s) - { - this(); - - Vector p = makeSegment(s); - - // empty path - if (p == null) - return; - - // delete empty paths - for (int i = 0; i < p.size(); i++) - if (((Segment) p.elementAt(i)).getSignedArea() == 0.0) - p.remove(i--); - - /* - * Resolve self intersecting paths into non-intersecting - * solids and holes. - * Algorithm is as follows: - * 1: Create nodes at all self intersections - * 2: Put all segments into a list - * 3: Grab a segment, follow it, change direction at each node, - * removing segments from the list in the process - * 4: Repeat (3) until no segments remain in the list - * 5: Remove redundant paths and sort into solids and holes - */ - Vector paths = new Vector(); - Segment v; - - for (int i = 0; i < p.size(); i++) - { - Segment path = (Segment) p.elementAt(i); - createNodesSelf(path); - } - - if (p.size() > 1) - { - for (int i = 0; i < p.size() - 1; i++) - for (int j = i + 1; j < p.size(); j++) - { - Segment path1 = (Segment) p.elementAt(i); - Segment path2 = (Segment) p.elementAt(j); - createNodes(path1, path2); - } - } - - // we have intersecting points. - Vector segments = new Vector(); - - for (int i = 0; i < p.size(); i++) - { - Segment path = v = (Segment) p.elementAt(i); - do - { - segments.add(v); - v = v.next; - } - while (v != path); - } - - paths = weilerAtherton(segments); - deleteRedundantPaths(paths); - } - - /** - * Performs an add (union) operation on this area with another Area.<BR> - * @param area - the area to be unioned with this one - */ - public void add(Area area) - { - if (equals(area)) - return; - if (area.isEmpty()) - return; - - Area B = (Area) area.clone(); - - Vector pathA = new Vector(); - Vector pathB = new Vector(); - pathA.addAll(solids); - pathA.addAll(holes); - pathB.addAll(B.solids); - pathB.addAll(B.holes); - - int nNodes = 0; - - for (int i = 0; i < pathA.size(); i++) - { - Segment a = (Segment) pathA.elementAt(i); - for (int j = 0; j < pathB.size(); j++) - { - Segment b = (Segment) pathB.elementAt(j); - nNodes += createNodes(a, b); - } - } - - Vector paths = new Vector(); - Segment v; - - // we have intersecting points. - Vector segments = new Vector(); - - // In a union operation, we keep all - // segments of A oustide B and all B outside A - for (int i = 0; i < pathA.size(); i++) - { - v = (Segment) pathA.elementAt(i); - Segment path = v; - do - { - if (v.isSegmentOutside(area)) - segments.add(v); - v = v.next; - } - while (v != path); - } - - for (int i = 0; i < pathB.size(); i++) - { - v = (Segment) pathB.elementAt(i); - Segment path = v; - do - { - if (v.isSegmentOutside(this)) - segments.add(v); - v = v.next; - } - while (v != path); - } - - paths = weilerAtherton(segments); - deleteRedundantPaths(paths); - } - - /** - * Performs a subtraction operation on this Area.<BR> - * @param area the area to be subtracted from this area. - * @throws NullPointerException if <code>area</code> is <code>null</code>. - */ - public void subtract(Area area) - { - if (isEmpty() || area.isEmpty()) - return; - - if (equals(area)) - { - reset(); - return; - } - - Vector pathA = new Vector(); - Area B = (Area) area.clone(); - pathA.addAll(solids); - pathA.addAll(holes); - - // reverse the directions of B paths. - setDirection(B.holes, true); - setDirection(B.solids, false); - - Vector pathB = new Vector(); - pathB.addAll(B.solids); - pathB.addAll(B.holes); - - int nNodes = 0; - - // create nodes - for (int i = 0; i < pathA.size(); i++) - { - Segment a = (Segment) pathA.elementAt(i); - for (int j = 0; j < pathB.size(); j++) - { - Segment b = (Segment) pathB.elementAt(j); - nNodes += createNodes(a, b); - } - } - - Vector paths = new Vector(); - - // we have intersecting points. - Vector segments = new Vector(); - - // In a subtraction operation, we keep all - // segments of A oustide B and all B within A - // We outsideness-test only one segment in each path - // and the segments before and after any node - for (int i = 0; i < pathA.size(); i++) - { - Segment v = (Segment) pathA.elementAt(i); - Segment path = v; - if (v.isSegmentOutside(area) && v.node == null) - segments.add(v); - boolean node = false; - do - { - if ((v.node != null || node)) - { - node = (v.node != null); - if (v.isSegmentOutside(area)) - segments.add(v); - } - v = v.next; - } - while (v != path); - } - - for (int i = 0; i < pathB.size(); i++) - { - Segment v = (Segment) pathB.elementAt(i); - Segment path = v; - if (! v.isSegmentOutside(this) && v.node == null) - segments.add(v); - v = v.next; - boolean node = false; - do - { - if ((v.node != null || node)) - { - node = (v.node != null); - if (! v.isSegmentOutside(this)) - segments.add(v); - } - v = v.next; - } - while (v != path); - } - - paths = weilerAtherton(segments); - deleteRedundantPaths(paths); - } - - /** - * Performs an intersection operation on this Area.<BR> - * @param area - the area to be intersected with this area. - * @throws NullPointerException if <code>area</code> is <code>null</code>. - */ - public void intersect(Area area) - { - if (isEmpty() || area.isEmpty()) - { - reset(); - return; - } - if (equals(area)) - return; - - Vector pathA = new Vector(); - Area B = (Area) area.clone(); - pathA.addAll(solids); - pathA.addAll(holes); - - Vector pathB = new Vector(); - pathB.addAll(B.solids); - pathB.addAll(B.holes); - - int nNodes = 0; - - // create nodes - for (int i = 0; i < pathA.size(); i++) - { - Segment a = (Segment) pathA.elementAt(i); - for (int j = 0; j < pathB.size(); j++) - { - Segment b = (Segment) pathB.elementAt(j); - nNodes += createNodes(a, b); - } - } - - Vector paths = new Vector(); - - // we have intersecting points. - Vector segments = new Vector(); - - // In an intersection operation, we keep all - // segments of A within B and all B within A - // (The rest must be redundant) - // We outsideness-test only one segment in each path - // and the segments before and after any node - for (int i = 0; i < pathA.size(); i++) - { - Segment v = (Segment) pathA.elementAt(i); - Segment path = v; - if (! v.isSegmentOutside(area) && v.node == null) - segments.add(v); - boolean node = false; - do - { - if ((v.node != null || node)) - { - node = (v.node != null); - if (! v.isSegmentOutside(area)) - segments.add(v); - } - v = v.next; - } - while (v != path); - } - - for (int i = 0; i < pathB.size(); i++) - { - Segment v = (Segment) pathB.elementAt(i); - Segment path = v; - if (! v.isSegmentOutside(this) && v.node == null) - segments.add(v); - v = v.next; - boolean node = false; - do - { - if ((v.node != null || node)) - { - node = (v.node != null); - if (! v.isSegmentOutside(this)) - segments.add(v); - } - v = v.next; - } - while (v != path); - } - - paths = weilerAtherton(segments); - deleteRedundantPaths(paths); - } - - /** - * Performs an exclusive-or operation on this Area.<BR> - * @param area - the area to be XORed with this area. - * @throws NullPointerException if <code>area</code> is <code>null</code>. - */ - public void exclusiveOr(Area area) - { - if (area.isEmpty()) - return; - - if (isEmpty()) - { - Area B = (Area) area.clone(); - solids = B.solids; - holes = B.holes; - return; - } - if (equals(area)) - { - reset(); - return; - } - - Vector pathA = new Vector(); - - Area B = (Area) area.clone(); - Vector pathB = new Vector(); - pathA.addAll(solids); - pathA.addAll(holes); - - // reverse the directions of B paths. - setDirection(B.holes, true); - setDirection(B.solids, false); - pathB.addAll(B.solids); - pathB.addAll(B.holes); - - int nNodes = 0; - - for (int i = 0; i < pathA.size(); i++) - { - Segment a = (Segment) pathA.elementAt(i); - for (int j = 0; j < pathB.size(); j++) - { - Segment b = (Segment) pathB.elementAt(j); - nNodes += createNodes(a, b); - } - } - - Vector paths = new Vector(); - Segment v; - - // we have intersecting points. - Vector segments = new Vector(); - - // In an XOR operation, we operate on all segments - for (int i = 0; i < pathA.size(); i++) - { - v = (Segment) pathA.elementAt(i); - Segment path = v; - do - { - segments.add(v); - v = v.next; - } - while (v != path); - } - - for (int i = 0; i < pathB.size(); i++) - { - v = (Segment) pathB.elementAt(i); - Segment path = v; - do - { - segments.add(v); - v = v.next; - } - while (v != path); - } - - paths = weilerAtherton(segments); - deleteRedundantPaths(paths); - } - - /** - * Clears the Area object, creating an empty area. - */ - public void reset() - { - solids = new Vector(); - holes = new Vector(); - } - - /** - * Returns whether this area encloses any area. - * @return true if the object encloses any area. - */ - public boolean isEmpty() - { - if (solids.size() == 0) - return true; - - double totalArea = 0; - for (int i = 0; i < solids.size(); i++) - totalArea += Math.abs(((Segment) solids.elementAt(i)).getSignedArea()); - for (int i = 0; i < holes.size(); i++) - totalArea -= Math.abs(((Segment) holes.elementAt(i)).getSignedArea()); - if (totalArea <= EPSILON) - return true; - - return false; - } - - /** - * Determines whether the Area consists entirely of line segments - * @return true if the Area lines-only, false otherwise - */ - public boolean isPolygonal() - { - for (int i = 0; i < holes.size(); i++) - if (! ((Segment) holes.elementAt(i)).isPolygonal()) - return false; - for (int i = 0; i < solids.size(); i++) - if (! ((Segment) solids.elementAt(i)).isPolygonal()) - return false; - return true; - } - - /** - * Determines if the Area is rectangular.<P> - * - * This is strictly qualified. An area is considered rectangular if:<BR> - * <li>It consists of a single polygonal path.<BR> - * <li>It is oriented parallel/perpendicular to the xy axis<BR> - * <li>It must be exactly rectangular, i.e. small errors induced by - * transformations may cause a false result, although the area is - * visibly rectangular.<P> - * @return true if the above criteria are met, false otherwise - */ - public boolean isRectangular() - { - if (isEmpty()) - return true; - - if (holes.size() != 0 || solids.size() != 1) - return false; - - Segment path = (Segment) solids.elementAt(0); - if (! path.isPolygonal()) - return false; - - int nCorners = 0; - Segment s = path; - do - { - Segment s2 = s.next; - double d1 = (s.P2.getX() - s.P1.getX())*(s2.P2.getX() - s2.P1.getX())/ - ((s.P1.distance(s.P2)) * (s2.P1.distance(s2.P2))); - double d2 = (s.P2.getY() - s.P1.getY())*(s2.P2.getY() - s2.P1.getY())/ - ((s.P1.distance(s.P2)) * (s2.P1.distance(s2.P2))); - double dotproduct = d1 + d2; - - // For some reason, only rectangles on the XY axis count. - if (d1 != 0 && d2 != 0) - return false; - - if (Math.abs(dotproduct) == 0) // 90 degree angle - nCorners++; - else if ((Math.abs(1.0 - dotproduct) > 0)) // 0 degree angle? - return false; // if not, return false - - s = s.next; - } - while (s != path); - - return nCorners == 4; - } - - /** - * Returns whether the Area consists of more than one simple - * (non self-intersecting) subpath. - * - * @return true if the Area consists of none or one simple subpath, - * false otherwise. - */ - public boolean isSingular() - { - return (holes.size() == 0 && solids.size() <= 1); - } - - /** - * Returns the bounding box of the Area.<P> Unlike the CubicCurve2D and - * QuadraticCurve2D classes, this method will return the tightest possible - * bounding box, evaluating the extreme points of each curved segment.<P> - * @return the bounding box - */ - public Rectangle2D getBounds2D() - { - if (solids.size() == 0) - return new Rectangle2D.Double(0.0, 0.0, 0.0, 0.0); - - double xmin; - double xmax; - double ymin; - double ymax; - xmin = xmax = ((Segment) solids.elementAt(0)).P1.getX(); - ymin = ymax = ((Segment) solids.elementAt(0)).P1.getY(); - - for (int path = 0; path < solids.size(); path++) - { - Rectangle2D r = ((Segment) solids.elementAt(path)).getPathBounds(); - xmin = Math.min(r.getMinX(), xmin); - ymin = Math.min(r.getMinY(), ymin); - xmax = Math.max(r.getMaxX(), xmax); - ymax = Math.max(r.getMaxY(), ymax); - } - - return (new Rectangle2D.Double(xmin, ymin, (xmax - xmin), (ymax - ymin))); - } - - /** - * Returns the bounds of this object in Rectangle format. - * Please note that this may lead to loss of precision. - * - * @return The bounds. - * @see #getBounds2D() - */ - public Rectangle getBounds() - { - return getBounds2D().getBounds(); - } - - /** - * Create a new area of the same run-time type with the same contents as - * this one. - * - * @return the clone - */ - public Object clone() - { - try - { - Area clone = new Area(); - for (int i = 0; i < solids.size(); i++) - clone.solids.add(((Segment) solids.elementAt(i)).cloneSegmentList()); - for (int i = 0; i < holes.size(); i++) - clone.holes.add(((Segment) holes.elementAt(i)).cloneSegmentList()); - return clone; - } - catch (CloneNotSupportedException e) - { - throw (Error) new InternalError().initCause(e); // Impossible - } - } - - /** - * Compares two Areas. - * - * @param area the area to compare against this area (<code>null</code> - * permitted). - * @return <code>true</code> if the areas are equal, and <code>false</code> - * otherwise. - */ - public boolean equals(Area area) - { - if (area == null) - return false; - - if (! getBounds2D().equals(area.getBounds2D())) - return false; - - if (solids.size() != area.solids.size() - || holes.size() != area.holes.size()) - return false; - - Vector pathA = new Vector(); - pathA.addAll(solids); - pathA.addAll(holes); - Vector pathB = new Vector(); - pathB.addAll(area.solids); - pathB.addAll(area.holes); - - int nPaths = pathA.size(); - boolean[][] match = new boolean[2][nPaths]; - - for (int i = 0; i < nPaths; i++) - { - for (int j = 0; j < nPaths; j++) - { - Segment p1 = (Segment) pathA.elementAt(i); - Segment p2 = (Segment) pathB.elementAt(j); - if (! match[0][i] && ! match[1][j]) - if (p1.pathEquals(p2)) - match[0][i] = match[1][j] = true; - } - } - - boolean result = true; - for (int i = 0; i < nPaths; i++) - result = result && match[0][i] && match[1][i]; - return result; - } - - /** - * Transforms this area by the AffineTransform at. - * - * @param at the transform. - */ - public void transform(AffineTransform at) - { - for (int i = 0; i < solids.size(); i++) - ((Segment) solids.elementAt(i)).transformSegmentList(at); - for (int i = 0; i < holes.size(); i++) - ((Segment) holes.elementAt(i)).transformSegmentList(at); - - // Note that the orientation is not invariant under inversion - if ((at.getType() & AffineTransform.TYPE_FLIP) != 0) - { - setDirection(holes, false); - setDirection(solids, true); - } - } - - /** - * Returns a new Area equal to this one, transformed - * by the AffineTransform at. - * @param at the transform. - * @return the transformed area - * @throws NullPointerException if <code>at</code> is <code>null</code>. - */ - public Area createTransformedArea(AffineTransform at) - { - Area a = (Area) clone(); - a.transform(at); - return a; - } - - /** - * Determines if the point (x,y) is contained within this Area. - * - * @param x the x-coordinate of the point. - * @param y the y-coordinate of the point. - * @return true if the point is contained, false otherwise. - */ - public boolean contains(double x, double y) - { - int n = 0; - for (int i = 0; i < solids.size(); i++) - if (((Segment) solids.elementAt(i)).contains(x, y)) - n++; - - for (int i = 0; i < holes.size(); i++) - if (((Segment) holes.elementAt(i)).contains(x, y)) - n--; - - return (n != 0); - } - - /** - * Determines if the Point2D p is contained within this Area. - * - * @param p the point. - * @return <code>true</code> if the point is contained, <code>false</code> - * otherwise. - * @throws NullPointerException if <code>p</code> is <code>null</code>. - */ - public boolean contains(Point2D p) - { - return contains(p.getX(), p.getY()); - } - - /** - * Determines if the rectangle specified by (x,y) as the upper-left - * and with width w and height h is completely contained within this Area, - * returns false otherwise.<P> - * - * This method should always produce the correct results, unlike for other - * classes in geom. - * - * @param x the x-coordinate of the rectangle. - * @param y the y-coordinate of the rectangle. - * @param w the width of the the rectangle. - * @param h the height of the rectangle. - * @return <code>true</code> if the rectangle is considered contained - */ - public boolean contains(double x, double y, double w, double h) - { - LineSegment[] l = new LineSegment[4]; - l[0] = new LineSegment(x, y, x + w, y); - l[1] = new LineSegment(x, y + h, x + w, y + h); - l[2] = new LineSegment(x, y, x, y + h); - l[3] = new LineSegment(x + w, y, x + w, y + h); - - // Since every segment in the area must a contour - // between inside/outside segments, ANY intersection - // will mean the rectangle is not entirely contained. - for (int i = 0; i < 4; i++) - { - for (int path = 0; path < solids.size(); path++) - { - Segment v; - Segment start; - start = v = (Segment) solids.elementAt(path); - do - { - if (l[i].hasIntersections(v)) - return false; - v = v.next; - } - while (v != start); - } - for (int path = 0; path < holes.size(); path++) - { - Segment v; - Segment start; - start = v = (Segment) holes.elementAt(path); - do - { - if (l[i].hasIntersections(v)) - return false; - v = v.next; - } - while (v != start); - } - } - - // Is any point inside? - if (! contains(x, y)) - return false; - - // Final hoop: Is the rectangle non-intersecting and inside, - // but encloses a hole? - Rectangle2D r = new Rectangle2D.Double(x, y, w, h); - for (int path = 0; path < holes.size(); path++) - if (! ((Segment) holes.elementAt(path)).isSegmentOutside(r)) - return false; - - return true; - } - - /** - * Determines if the Rectangle2D specified by r is completely contained - * within this Area, returns false otherwise.<P> - * - * This method should always produce the correct results, unlike for other - * classes in geom. - * - * @param r the rectangle. - * @return <code>true</code> if the rectangle is considered contained - * - * @throws NullPointerException if <code>r</code> is <code>null</code>. - */ - public boolean contains(Rectangle2D r) - { - return contains(r.getX(), r.getY(), r.getWidth(), r.getHeight()); - } - - /** - * Determines if the rectangle specified by (x,y) as the upper-left - * and with width w and height h intersects any part of this Area. - * - * @param x the x-coordinate for the rectangle. - * @param y the y-coordinate for the rectangle. - * @param w the width of the rectangle. - * @param h the height of the rectangle. - * @return <code>true</code> if the rectangle intersects the area, - * <code>false</code> otherwise. - */ - public boolean intersects(double x, double y, double w, double h) - { - if (solids.size() == 0) - return false; - - LineSegment[] l = new LineSegment[4]; - l[0] = new LineSegment(x, y, x + w, y); - l[1] = new LineSegment(x, y + h, x + w, y + h); - l[2] = new LineSegment(x, y, x, y + h); - l[3] = new LineSegment(x + w, y, x + w, y + h); - - // Return true on any intersection - for (int i = 0; i < 4; i++) - { - for (int path = 0; path < solids.size(); path++) - { - Segment v; - Segment start; - start = v = (Segment) solids.elementAt(path); - do - { - if (l[i].hasIntersections(v)) - return true; - v = v.next; - } - while (v != start); - } - for (int path = 0; path < holes.size(); path++) - { - Segment v; - Segment start; - start = v = (Segment) holes.elementAt(path); - do - { - if (l[i].hasIntersections(v)) - return true; - v = v.next; - } - while (v != start); - } - } - - // Non-intersecting, Is any point inside? - if (contains(x + w * 0.5, y + h * 0.5)) - return true; - - // What if the rectangle encloses the whole shape? - Point2D p = ((Segment) solids.elementAt(0)).getMidPoint(); - if ((new Rectangle2D.Double(x, y, w, h)).contains(p)) - return true; - return false; - } - - /** - * Determines if the Rectangle2D specified by r intersects any - * part of this Area. - * @param r the rectangle to test intersection with (<code>null</code> - * not permitted). - * @return <code>true</code> if the rectangle intersects the area, - * <code>false</code> otherwise. - * @throws NullPointerException if <code>r</code> is <code>null</code>. - */ - public boolean intersects(Rectangle2D r) - { - return intersects(r.getX(), r.getY(), r.getWidth(), r.getHeight()); - } - - /** - * Returns a PathIterator object defining the contour of this Area, - * transformed by at. - * - * @param at the transform. - * @return A path iterator. - */ - public PathIterator getPathIterator(AffineTransform at) - { - return (new AreaIterator(at)); - } - - /** - * Returns a flattened PathIterator object defining the contour of this - * Area, transformed by at and with a defined flatness. - * - * @param at the transform. - * @param flatness the flatness. - * @return A path iterator. - */ - public PathIterator getPathIterator(AffineTransform at, double flatness) - { - return new FlatteningPathIterator(getPathIterator(at), flatness); - } - - //--------------------------------------------------------------------- - // Non-public methods and classes - - /** - * Private pathiterator object. - */ - private class AreaIterator implements PathIterator - { - private Vector segments; - private int index; - private AffineTransform at; - - // Simple compound type for segments - class IteratorSegment - { - int type; - double[] coords; - - IteratorSegment() - { - coords = new double[6]; - } - } - - /** - * The contructor here does most of the work, - * creates a vector of IteratorSegments, which can - * readily be returned - */ - public AreaIterator(AffineTransform at) - { - this.at = at; - index = 0; - segments = new Vector(); - Vector allpaths = new Vector(); - allpaths.addAll(solids); - allpaths.addAll(holes); - - for (int i = 0; i < allpaths.size(); i++) - { - Segment v = (Segment) allpaths.elementAt(i); - Segment start = v; - - IteratorSegment is = new IteratorSegment(); - is.type = SEG_MOVETO; - is.coords[0] = start.P1.getX(); - is.coords[1] = start.P1.getY(); - segments.add(is); - - do - { - is = new IteratorSegment(); - is.type = v.pathIteratorFormat(is.coords); - segments.add(is); - v = v.next; - } - while (v != start); - - is = new IteratorSegment(); - is.type = SEG_CLOSE; - segments.add(is); - } - } - - public int currentSegment(double[] coords) - { - IteratorSegment s = (IteratorSegment) segments.elementAt(index); - if (at != null) - at.transform(s.coords, 0, coords, 0, 3); - else - for (int i = 0; i < 6; i++) - coords[i] = s.coords[i]; - return (s.type); - } - - public int currentSegment(float[] coords) - { - IteratorSegment s = (IteratorSegment) segments.elementAt(index); - double[] d = new double[6]; - if (at != null) - { - at.transform(s.coords, 0, d, 0, 3); - for (int i = 0; i < 6; i++) - coords[i] = (float) d[i]; - } - else - for (int i = 0; i < 6; i++) - coords[i] = (float) s.coords[i]; - return (s.type); - } - - // Note that the winding rule should not matter here, - // EVEN_ODD is chosen because it renders faster. - public int getWindingRule() - { - return (PathIterator.WIND_EVEN_ODD); - } - - public boolean isDone() - { - return (index >= segments.size()); - } - - public void next() - { - index++; - } - } - - /** - * Performs the fundamental task of the Weiler-Atherton algorithm, - * traverse a list of segments, for each segment: - * Follow it, removing segments from the list and switching paths - * at each node. Do so until the starting segment is reached. - * - * Returns a Vector of the resulting paths. - */ - private Vector weilerAtherton(Vector segments) - { - Vector paths = new Vector(); - while (segments.size() > 0) - { - // Iterate over the path - Segment start = (Segment) segments.elementAt(0); - Segment s = start; - do - { - segments.remove(s); - if (s.node != null) - { // switch over - s.next = s.node; - s.node = null; - } - s = s.next; // continue - } - while (s != start); - - paths.add(start); - } - return paths; - } - - /** - * A small wrapper class to store intersection points - */ - private class Intersection - { - Point2D p; // the 2D point of intersection - double ta; // the parametric value on a - double tb; // the parametric value on b - Segment seg; // segment placeholder for node setting - - public Intersection(Point2D p, double ta, double tb) - { - this.p = p; - this.ta = ta; - this.tb = tb; - } - } - - /** - * Returns the recursion depth necessary to approximate the - * curve by line segments within the error RS_EPSILON. - * - * This is done with Wang's formula: - * L0 = max{0<=i<=N-2}(|xi - 2xi+1 + xi+2|,|yi - 2yi+1 + yi+2|) - * r0 = log4(sqrt(2)*N*(N-1)*L0/8e) - * Where e is the maximum distance error (RS_EPSILON) - */ - private int getRecursionDepth(CubicSegment curve) - { - double x0 = curve.P1.getX(); - double y0 = curve.P1.getY(); - - double x1 = curve.cp1.getX(); - double y1 = curve.cp1.getY(); - - double x2 = curve.cp2.getX(); - double y2 = curve.cp2.getY(); - - double x3 = curve.P2.getX(); - double y3 = curve.P2.getY(); - - double L0 = Math.max(Math.max(Math.abs(x0 - 2 * x1 + x2), - Math.abs(x1 - 2 * x2 + x3)), - Math.max(Math.abs(y0 - 2 * y1 + y2), - Math.abs(y1 - 2 * y2 + y3))); - - double f = Math.sqrt(2) * 6.0 * L0 / (8.0 * RS_EPSILON); - - int r0 = (int) Math.ceil(Math.log(f) / Math.log(4.0)); - return (r0); - } - - /** - * Performs recursive subdivision: - * @param c1 - curve 1 - * @param c2 - curve 2 - * @param depth1 - recursion depth of curve 1 - * @param depth2 - recursion depth of curve 2 - * @param t1 - global parametric value of the first curve's starting point - * @param t2 - global parametric value of the second curve's starting point - * @param w1 - global parametric length of curve 1 - * @param c1 - global parametric length of curve 2 - * - * The final four parameters are for keeping track of the parametric - * value of the curve. For a full curve t = 0, w = 1, w is halved with - * each subdivision. - */ - private void recursiveSubdivide(CubicCurve2D c1, CubicCurve2D c2, - int depth1, int depth2, double t1, - double t2, double w1, double w2) - { - boolean flat1 = depth1 <= 0; - boolean flat2 = depth2 <= 0; - - if (flat1 && flat2) - { - double xlk = c1.getP2().getX() - c1.getP1().getX(); - double ylk = c1.getP2().getY() - c1.getP1().getY(); - - double xnm = c2.getP2().getX() - c2.getP1().getX(); - double ynm = c2.getP2().getY() - c2.getP1().getY(); - - double xmk = c2.getP1().getX() - c1.getP1().getX(); - double ymk = c2.getP1().getY() - c1.getP1().getY(); - double det = xnm * ylk - ynm * xlk; - - if (det + 1.0 == 1.0) - return; - - double detinv = 1.0 / det; - double s = (xnm * ymk - ynm * xmk) * detinv; - double t = (xlk * ymk - ylk * xmk) * detinv; - if ((s < 0.0) || (s > 1.0) || (t < 0.0) || (t > 1.0)) - return; - - double[] temp = new double[2]; - temp[0] = t1 + s * w1; - temp[1] = t2 + t * w1; - cc_intersections.add(temp); - return; - } - - CubicCurve2D.Double c11 = new CubicCurve2D.Double(); - CubicCurve2D.Double c12 = new CubicCurve2D.Double(); - CubicCurve2D.Double c21 = new CubicCurve2D.Double(); - CubicCurve2D.Double c22 = new CubicCurve2D.Double(); - - if (! flat1 && ! flat2) - { - depth1--; - depth2--; - w1 = w1 * 0.5; - w2 = w2 * 0.5; - c1.subdivide(c11, c12); - c2.subdivide(c21, c22); - if (c11.getBounds2D().intersects(c21.getBounds2D())) - recursiveSubdivide(c11, c21, depth1, depth2, t1, t2, w1, w2); - if (c11.getBounds2D().intersects(c22.getBounds2D())) - recursiveSubdivide(c11, c22, depth1, depth2, t1, t2 + w2, w1, w2); - if (c12.getBounds2D().intersects(c21.getBounds2D())) - recursiveSubdivide(c12, c21, depth1, depth2, t1 + w1, t2, w1, w2); - if (c12.getBounds2D().intersects(c22.getBounds2D())) - recursiveSubdivide(c12, c22, depth1, depth2, t1 + w1, t2 + w2, w1, w2); - return; - } - - if (! flat1) - { - depth1--; - c1.subdivide(c11, c12); - w1 = w1 * 0.5; - if (c11.getBounds2D().intersects(c2.getBounds2D())) - recursiveSubdivide(c11, c2, depth1, depth2, t1, t2, w1, w2); - if (c12.getBounds2D().intersects(c2.getBounds2D())) - recursiveSubdivide(c12, c2, depth1, depth2, t1 + w1, t2, w1, w2); - return; - } - - depth2--; - c2.subdivide(c21, c22); - w2 = w2 * 0.5; - if (c1.getBounds2D().intersects(c21.getBounds2D())) - recursiveSubdivide(c1, c21, depth1, depth2, t1, t2, w1, w2); - if (c1.getBounds2D().intersects(c22.getBounds2D())) - recursiveSubdivide(c1, c22, depth1, depth2, t1, t2 + w2, w1, w2); - } - - /** - * Returns a set of interesections between two Cubic segments - * Or null if no intersections were found. - * - * The method used to find the intersection is recursive midpoint - * subdivision. Outline description: - * - * 1) Check if the bounding boxes of the curves intersect, - * 2) If so, divide the curves in the middle and test the bounding - * boxes again, - * 3) Repeat until a maximum recursion depth has been reached, where - * the intersecting curves can be approximated by line segments. - * - * This is a reasonably accurate method, although the recursion depth - * is typically around 20, the bounding-box tests allow for significant - * pruning of the subdivision tree. - * - * This is package-private to avoid an accessor method. - */ - Intersection[] cubicCubicIntersect(CubicSegment curve1, CubicSegment curve2) - { - Rectangle2D r1 = curve1.getBounds(); - Rectangle2D r2 = curve2.getBounds(); - - if (! r1.intersects(r2)) - return null; - - cc_intersections = new Vector(); - recursiveSubdivide(curve1.getCubicCurve2D(), curve2.getCubicCurve2D(), - getRecursionDepth(curve1), getRecursionDepth(curve2), - 0.0, 0.0, 1.0, 1.0); - - if (cc_intersections.size() == 0) - return null; - - Intersection[] results = new Intersection[cc_intersections.size()]; - for (int i = 0; i < cc_intersections.size(); i++) - { - double[] temp = (double[]) cc_intersections.elementAt(i); - results[i] = new Intersection(curve1.evaluatePoint(temp[0]), temp[0], - temp[1]); - } - cc_intersections = null; - return (results); - } - - /** - * Returns the intersections between a line and a quadratic bezier - * Or null if no intersections are found1 - * This is done through combining the line's equation with the - * parametric form of the Bezier and solving the resulting quadratic. - * This is package-private to avoid an accessor method. - */ - Intersection[] lineQuadIntersect(LineSegment l, QuadSegment c) - { - double[] y = new double[3]; - double[] x = new double[3]; - double[] r = new double[3]; - int nRoots; - double x0 = c.P1.getX(); - double y0 = c.P1.getY(); - double x1 = c.cp.getX(); - double y1 = c.cp.getY(); - double x2 = c.P2.getX(); - double y2 = c.P2.getY(); - - double lx0 = l.P1.getX(); - double ly0 = l.P1.getY(); - double lx1 = l.P2.getX(); - double ly1 = l.P2.getY(); - double dx = lx1 - lx0; - double dy = ly1 - ly0; - - // form r(t) = y(t) - x(t) for the bezier - y[0] = y0; - y[1] = 2 * (y1 - y0); - y[2] = (y2 - 2 * y1 + y0); - - x[0] = x0; - x[1] = 2 * (x1 - x0); - x[2] = (x2 - 2 * x1 + x0); - - // a point, not a line - if (dy == 0 && dx == 0) - return null; - - // line on y axis - if (dx == 0 || (dy / dx) > 1.0) - { - double k = dx / dy; - x[0] -= lx0; - y[0] -= ly0; - y[0] *= k; - y[1] *= k; - y[2] *= k; - } - else - { - double k = dy / dx; - x[0] -= lx0; - y[0] -= ly0; - x[0] *= k; - x[1] *= k; - x[2] *= k; - } - - for (int i = 0; i < 3; i++) - r[i] = y[i] - x[i]; - - if ((nRoots = QuadCurve2D.solveQuadratic(r)) > 0) - { - Intersection[] temp = new Intersection[nRoots]; - int intersections = 0; - for (int i = 0; i < nRoots; i++) - { - double t = r[i]; - if (t >= 0.0 && t <= 1.0) - { - Point2D p = c.evaluatePoint(t); - - // if the line is on an axis, snap the point to that axis. - if (dx == 0) - p.setLocation(lx0, p.getY()); - if (dy == 0) - p.setLocation(p.getX(), ly0); - - if (p.getX() <= Math.max(lx0, lx1) - && p.getX() >= Math.min(lx0, lx1) - && p.getY() <= Math.max(ly0, ly1) - && p.getY() >= Math.min(ly0, ly1)) - { - double lineparameter = p.distance(l.P1) / l.P2.distance(l.P1); - temp[i] = new Intersection(p, lineparameter, t); - intersections++; - } - } - else - temp[i] = null; - } - if (intersections == 0) - return null; - - Intersection[] rValues = new Intersection[intersections]; - - for (int i = 0; i < nRoots; i++) - if (temp[i] != null) - rValues[--intersections] = temp[i]; - return (rValues); - } - return null; - } - - /** - * Returns the intersections between a line and a cubic segment - * This is done through combining the line's equation with the - * parametric form of the Bezier and solving the resulting quadratic. - * This is package-private to avoid an accessor method. - */ - Intersection[] lineCubicIntersect(LineSegment l, CubicSegment c) - { - double[] y = new double[4]; - double[] x = new double[4]; - double[] r = new double[4]; - int nRoots; - double x0 = c.P1.getX(); - double y0 = c.P1.getY(); - double x1 = c.cp1.getX(); - double y1 = c.cp1.getY(); - double x2 = c.cp2.getX(); - double y2 = c.cp2.getY(); - double x3 = c.P2.getX(); - double y3 = c.P2.getY(); - - double lx0 = l.P1.getX(); - double ly0 = l.P1.getY(); - double lx1 = l.P2.getX(); - double ly1 = l.P2.getY(); - double dx = lx1 - lx0; - double dy = ly1 - ly0; - - // form r(t) = y(t) - x(t) for the bezier - y[0] = y0; - y[1] = 3 * (y1 - y0); - y[2] = 3 * (y2 + y0 - 2 * y1); - y[3] = y3 - 3 * y2 + 3 * y1 - y0; - - x[0] = x0; - x[1] = 3 * (x1 - x0); - x[2] = 3 * (x2 + x0 - 2 * x1); - x[3] = x3 - 3 * x2 + 3 * x1 - x0; - - // a point, not a line - if (dy == 0 && dx == 0) - return null; - - // line on y axis - if (dx == 0 || (dy / dx) > 1.0) - { - double k = dx / dy; - x[0] -= lx0; - y[0] -= ly0; - y[0] *= k; - y[1] *= k; - y[2] *= k; - y[3] *= k; - } - else - { - double k = dy / dx; - x[0] -= lx0; - y[0] -= ly0; - x[0] *= k; - x[1] *= k; - x[2] *= k; - x[3] *= k; - } - for (int i = 0; i < 4; i++) - r[i] = y[i] - x[i]; - - if ((nRoots = CubicCurve2D.solveCubic(r)) > 0) - { - Intersection[] temp = new Intersection[nRoots]; - int intersections = 0; - for (int i = 0; i < nRoots; i++) - { - double t = r[i]; - if (t >= 0.0 && t <= 1.0) - { - // if the line is on an axis, snap the point to that axis. - Point2D p = c.evaluatePoint(t); - if (dx == 0) - p.setLocation(lx0, p.getY()); - if (dy == 0) - p.setLocation(p.getX(), ly0); - - if (p.getX() <= Math.max(lx0, lx1) - && p.getX() >= Math.min(lx0, lx1) - && p.getY() <= Math.max(ly0, ly1) - && p.getY() >= Math.min(ly0, ly1)) - { - double lineparameter = p.distance(l.P1) / l.P2.distance(l.P1); - temp[i] = new Intersection(p, lineparameter, t); - intersections++; - } - } - else - temp[i] = null; - } - - if (intersections == 0) - return null; - - Intersection[] rValues = new Intersection[intersections]; - for (int i = 0; i < nRoots; i++) - if (temp[i] != null) - rValues[--intersections] = temp[i]; - return (rValues); - } - return null; - } - - /** - * Returns the intersection between two lines, or null if there is no - * intersection. - * This is package-private to avoid an accessor method. - */ - Intersection linesIntersect(LineSegment a, LineSegment b) - { - Point2D P1 = a.P1; - Point2D P2 = a.P2; - Point2D P3 = b.P1; - Point2D P4 = b.P2; - - if (! Line2D.linesIntersect(P1.getX(), P1.getY(), P2.getX(), P2.getY(), - P3.getX(), P3.getY(), P4.getX(), P4.getY())) - return null; - - double x1 = P1.getX(); - double y1 = P1.getY(); - double rx = P2.getX() - x1; - double ry = P2.getY() - y1; - - double x2 = P3.getX(); - double y2 = P3.getY(); - double sx = P4.getX() - x2; - double sy = P4.getY() - y2; - - double determinant = sx * ry - sy * rx; - double nom = (sx * (y2 - y1) + sy * (x1 - x2)); - - // Parallel lines don't intersect. At least we pretend they don't. - if (Math.abs(determinant) < EPSILON) - return null; - - nom = nom / determinant; - - if (nom == 0.0) - return null; - if (nom == 1.0) - return null; - - Point2D p = new Point2D.Double(x1 + nom * rx, y1 + nom * ry); - - return new Intersection(p, p.distance(P1) / P1.distance(P2), - p.distance(P3) / P3.distance(P4)); - } - - /** - * Determines if two points are equal, within an error margin - * 'snap distance' - * This is package-private to avoid an accessor method. - */ - boolean pointEquals(Point2D a, Point2D b) - { - return (a.equals(b) || a.distance(b) < PE_EPSILON); - } - - /** - * Helper method - * Turns a shape into a Vector of Segments - */ - private Vector makeSegment(Shape s) - { - Vector paths = new Vector(); - PathIterator pi = s.getPathIterator(null); - double[] coords = new double[6]; - Segment subpath = null; - Segment current = null; - double cx; - double cy; - double subpathx; - double subpathy; - cx = cy = subpathx = subpathy = 0.0; - - this.windingRule = pi.getWindingRule(); - - while (! pi.isDone()) - { - Segment v; - switch (pi.currentSegment(coords)) - { - case PathIterator.SEG_MOVETO: - if (subpath != null) - { // close existing open path - current.next = new LineSegment(cx, cy, subpathx, subpathy); - current = current.next; - current.next = subpath; - } - subpath = null; - subpathx = cx = coords[0]; - subpathy = cy = coords[1]; - break; - - // replace 'close' with a line-to. - case PathIterator.SEG_CLOSE: - if (subpath != null && (subpathx != cx || subpathy != cy)) - { - current.next = new LineSegment(cx, cy, subpathx, subpathy); - current = current.next; - current.next = subpath; - cx = subpathx; - cy = subpathy; - subpath = null; - } - else if (subpath != null) - { - current.next = subpath; - subpath = null; - } - break; - case PathIterator.SEG_LINETO: - if (cx != coords[0] || cy != coords[1]) - { - v = new LineSegment(cx, cy, coords[0], coords[1]); - if (subpath == null) - { - subpath = current = v; - paths.add(subpath); - } - else - { - current.next = v; - current = current.next; - } - cx = coords[0]; - cy = coords[1]; - } - break; - case PathIterator.SEG_QUADTO: - v = new QuadSegment(cx, cy, coords[0], coords[1], coords[2], - coords[3]); - if (subpath == null) - { - subpath = current = v; - paths.add(subpath); - } - else - { - current.next = v; - current = current.next; - } - cx = coords[2]; - cy = coords[3]; - break; - case PathIterator.SEG_CUBICTO: - v = new CubicSegment(cx, cy, coords[0], coords[1], coords[2], - coords[3], coords[4], coords[5]); - if (subpath == null) - { - subpath = current = v; - paths.add(subpath); - } - else - { - current.next = v; - current = current.next; - } - - // check if the cubic is self-intersecting - double[] lpts = ((CubicSegment) v).getLoop(); - if (lpts != null) - { - // if it is, break off the loop into its own path. - v.subdivideInsert(lpts[0]); - v.next.subdivideInsert((lpts[1] - lpts[0]) / (1.0 - lpts[0])); - - CubicSegment loop = (CubicSegment) v.next; - v.next = loop.next; - loop.next = loop; - - v.P2 = v.next.P1 = loop.P2 = loop.P1; // snap points - paths.add(loop); - current = v.next; - } - - cx = coords[4]; - cy = coords[5]; - break; - } - pi.next(); - } - - if (subpath != null) - { // close any open path - if (subpathx != cx || subpathy != cy) - { - current.next = new LineSegment(cx, cy, subpathx, subpathy); - current = current.next; - current.next = subpath; - } - else - current.next = subpath; - } - - if (paths.size() == 0) - return (null); - - return (paths); - } - - /** - * Find the intersections of two separate closed paths, - * A and B, split the segments at the intersection points, - * and create nodes pointing from one to the other - */ - private int createNodes(Segment A, Segment B) - { - int nNodes = 0; - - Segment a = A; - Segment b = B; - - do - { - do - { - nNodes += a.splitIntersections(b); - b = b.next; - } - while (b != B); - - a = a.next; // move to the next segment - } - while (a != A); // until one wrap. - - return (nNodes); - } - - /** - * Find the intersections of a path with itself. - * Splits the segments at the intersection points, - * and create nodes pointing from one to the other. - */ - private int createNodesSelf(Segment A) - { - int nNodes = 0; - Segment a = A; - - if (A.next == A) - return 0; - - do - { - Segment b = a.next; - do - { - if (b != a) // necessary - nNodes += a.splitIntersections(b); - b = b.next; - } - while (b != A); - a = a.next; // move to the next segment - } - while (a != A); // until one wrap. - - return (nNodes); - } - - /** - * Deletes paths which are redundant from a list, (i.e. solid areas within - * solid areas) Clears any nodes. Sorts the remaining paths into solids - * and holes, sets their orientation and sets the solids and holes lists. - */ - private void deleteRedundantPaths(Vector paths) - { - int npaths = paths.size(); - - int[][] contains = new int[npaths][npaths]; - int[][] windingNumbers = new int[npaths][2]; - int neg; - Rectangle2D[] bb = new Rectangle2D[npaths]; // path bounding boxes - - neg = ((windingRule == PathIterator.WIND_NON_ZERO) ? -1 : 1); - - for (int i = 0; i < npaths; i++) - bb[i] = ((Segment) paths.elementAt(i)).getPathBounds(); - - // Find which path contains which, assign winding numbers - for (int i = 0; i < npaths; i++) - { - Segment pathA = (Segment) paths.elementAt(i); - pathA.nullNodes(); // remove any now-redundant nodes, in case. - int windingA = pathA.hasClockwiseOrientation() ? 1 : neg; - - for (int j = 0; j < npaths; j++) - if (i != j) - { - Segment pathB = (Segment) paths.elementAt(j); - - // A contains B - if (bb[i].intersects(bb[j])) - { - Segment s = pathB.next; - while (s.P1.getY() == s.P2.getY() && s != pathB) - s = s.next; - Point2D p = s.getMidPoint(); - if (pathA.contains(p.getX(), p.getY())) - contains[i][j] = windingA; - } - else - // A does not contain B - contains[i][j] = 0; - } - else - contains[i][j] = windingA; // i == j - } - - for (int i = 0; i < npaths; i++) - { - windingNumbers[i][0] = 0; - for (int j = 0; j < npaths; j++) - windingNumbers[i][0] += contains[j][i]; - windingNumbers[i][1] = contains[i][i]; - } - - Vector solids = new Vector(); - Vector holes = new Vector(); - - if (windingRule == PathIterator.WIND_NON_ZERO) - { - for (int i = 0; i < npaths; i++) - { - if (windingNumbers[i][0] == 0) - holes.add(paths.elementAt(i)); - else if (windingNumbers[i][0] - windingNumbers[i][1] == 0 - && Math.abs(windingNumbers[i][0]) == 1) - solids.add(paths.elementAt(i)); - } - } - else - { - windingRule = PathIterator.WIND_NON_ZERO; - for (int i = 0; i < npaths; i++) - { - if ((windingNumbers[i][0] & 1) == 0) - holes.add(paths.elementAt(i)); - else if ((windingNumbers[i][0] & 1) == 1) - solids.add(paths.elementAt(i)); - } - } - - setDirection(holes, false); - setDirection(solids, true); - this.holes = holes; - this.solids = solids; - } - - /** - * Sets the winding direction of a Vector of paths - * @param clockwise gives the direction, - * true = clockwise, false = counter-clockwise - */ - private void setDirection(Vector paths, boolean clockwise) - { - Segment v; - for (int i = 0; i < paths.size(); i++) - { - v = (Segment) paths.elementAt(i); - if (clockwise != v.hasClockwiseOrientation()) - v.reverseAll(); - } - } - - /** - * Class representing a linked-list of vertices forming a closed polygon, - * convex or concave, without holes. - */ - private abstract class Segment implements Cloneable - { - // segment type, PathIterator segment types are used. - Point2D P1; - Point2D P2; - Segment next; - Segment node; - - Segment() - { - P1 = P2 = null; - node = next = null; - } - - /** - * Reverses the direction of a single segment - */ - abstract void reverseCoords(); - - /** - * Returns the segment's midpoint - */ - abstract Point2D getMidPoint(); - - /** - * Returns the bounding box of this segment - */ - abstract Rectangle2D getBounds(); - - /** - * Transforms a single segment - */ - abstract void transform(AffineTransform at); - - /** - * Returns the PathIterator type of a segment - */ - abstract int getType(); - - /** - */ - abstract int splitIntersections(Segment b); - - /** - * Returns the PathIterator coords of a segment - */ - abstract int pathIteratorFormat(double[] coords); - - /** - * Returns the number of intersections on the positive X axis, - * with the origin at (x,y), used for contains()-testing - * - * (Although that could be done by the line-intersect methods, - * a dedicated method is better to guarantee consitent handling - * of endpoint-special-cases) - */ - abstract int rayCrossing(double x, double y); - - /** - * Subdivides the segment at parametric value t, inserting - * the new segment into the linked list after this, - * such that this becomes [0,t] and this.next becomes [t,1] - */ - abstract void subdivideInsert(double t); - - /** - * Returns twice the area of a curve, relative the P1-P2 line - * Used for area calculations. - */ - abstract double curveArea(); - - /** - * Compare two segments. - */ - abstract boolean equals(Segment b); - - /** - * Determines if this path of segments contains the point (x,y) - */ - boolean contains(double x, double y) - { - Segment v = this; - int crossings = 0; - do - { - int n = v.rayCrossing(x, y); - crossings += n; - v = v.next; - } - while (v != this); - return ((crossings & 1) == 1); - } - - /** - * Nulls all nodes of the path. Clean up any 'hairs'. - */ - void nullNodes() - { - Segment v = this; - do - { - v.node = null; - v = v.next; - } - while (v != this); - } - - /** - * Transforms each segment in the closed path - */ - void transformSegmentList(AffineTransform at) - { - Segment v = this; - do - { - v.transform(at); - v = v.next; - } - while (v != this); - } - - /** - * Determines the winding direction of the path - * By the sign of the area. - */ - boolean hasClockwiseOrientation() - { - return (getSignedArea() > 0.0); - } - - /** - * Returns the bounds of this path - */ - public Rectangle2D getPathBounds() - { - double xmin; - double xmax; - double ymin; - double ymax; - xmin = xmax = P1.getX(); - ymin = ymax = P1.getY(); - - Segment v = this; - do - { - Rectangle2D r = v.getBounds(); - xmin = Math.min(r.getMinX(), xmin); - ymin = Math.min(r.getMinY(), ymin); - xmax = Math.max(r.getMaxX(), xmax); - ymax = Math.max(r.getMaxY(), ymax); - v = v.next; - } - while (v != this); - - return (new Rectangle2D.Double(xmin, ymin, (xmax - xmin), (ymax - ymin))); - } - - /** - * Calculates twice the signed area of the path; - */ - double getSignedArea() - { - Segment s; - double area = 0.0; - - s = this; - do - { - area += s.curveArea(); - - area += s.P1.getX() * s.next.P1.getY() - - s.P1.getY() * s.next.P1.getX(); - s = s.next; - } - while (s != this); - - return area; - } - - /** - * Reverses the orientation of the whole polygon - */ - void reverseAll() - { - reverseCoords(); - Segment v = next; - Segment former = this; - while (v != this) - { - v.reverseCoords(); - Segment vnext = v.next; - v.next = former; - former = v; - v = vnext; - } - next = former; - } - - /** - * Inserts a Segment after this one - */ - void insert(Segment v) - { - Segment n = next; - next = v; - v.next = n; - } - - /** - * Returns if this segment path is polygonal - */ - boolean isPolygonal() - { - Segment v = this; - do - { - if (! (v instanceof LineSegment)) - return false; - v = v.next; - } - while (v != this); - return true; - } - - /** - * Clones this path - */ - Segment cloneSegmentList() throws CloneNotSupportedException - { - Vector list = new Vector(); - Segment v = next; - - while (v != this) - { - list.add(v); - v = v.next; - } - - Segment clone = (Segment) this.clone(); - v = clone; - for (int i = 0; i < list.size(); i++) - { - clone.next = (Segment) ((Segment) list.elementAt(i)).clone(); - clone = clone.next; - } - clone.next = v; - return v; - } - - /** - * Creates a node between this segment and segment b - * at the given intersection - * @return the number of nodes created (0 or 1) - */ - int createNode(Segment b, Intersection i) - { - Point2D p = i.p; - if ((pointEquals(P1, p) || pointEquals(P2, p)) - && (pointEquals(b.P1, p) || pointEquals(b.P2, p))) - return 0; - - subdivideInsert(i.ta); - b.subdivideInsert(i.tb); - - // snap points - b.P2 = b.next.P1 = P2 = next.P1 = i.p; - - node = b.next; - b.node = next; - return 1; - } - - /** - * Creates multiple nodes from a list of intersections, - * This must be done in the order of ascending parameters, - * and the parameters must be recalculated in accordance - * with each split. - * @return the number of nodes created - */ - protected int createNodes(Segment b, Intersection[] x) - { - Vector v = new Vector(); - for (int i = 0; i < x.length; i++) - { - Point2D p = x[i].p; - if (! ((pointEquals(P1, p) || pointEquals(P2, p)) - && (pointEquals(b.P1, p) || pointEquals(b.P2, p)))) - v.add(x[i]); - } - - int nNodes = v.size(); - Intersection[] A = new Intersection[nNodes]; - Intersection[] B = new Intersection[nNodes]; - for (int i = 0; i < nNodes; i++) - A[i] = B[i] = (Intersection) v.elementAt(i); - - // Create two lists sorted by the parameter - // Bubble sort, OK I suppose, since the number of intersections - // cannot be larger than 9 (cubic-cubic worst case) anyway - for (int i = 0; i < nNodes - 1; i++) - { - for (int j = i + 1; j < nNodes; j++) - { - if (A[i].ta > A[j].ta) - { - Intersection swap = A[i]; - A[i] = A[j]; - A[j] = swap; - } - if (B[i].tb > B[j].tb) - { - Intersection swap = B[i]; - B[i] = B[j]; - B[j] = swap; - } - } - } - // subdivide a - Segment s = this; - for (int i = 0; i < nNodes; i++) - { - s.subdivideInsert(A[i].ta); - - // renormalize the parameters - for (int j = i + 1; j < nNodes; j++) - A[j].ta = (A[j].ta - A[i].ta) / (1.0 - A[i].ta); - - A[i].seg = s; - s = s.next; - } - - // subdivide b, set nodes - s = b; - for (int i = 0; i < nNodes; i++) - { - s.subdivideInsert(B[i].tb); - - for (int j = i + 1; j < nNodes; j++) - B[j].tb = (B[j].tb - B[i].tb) / (1.0 - B[i].tb); - - // set nodes - B[i].seg.node = s.next; // node a -> b - s.node = B[i].seg.next; // node b -> a - - // snap points - B[i].seg.P2 = B[i].seg.next.P1 = s.P2 = s.next.P1 = B[i].p; - s = s.next; - } - return nNodes; - } - - /** - * Determines if two paths are equal. - * Colinear line segments are ignored in the comparison. - */ - boolean pathEquals(Segment B) - { - if (! getPathBounds().equals(B.getPathBounds())) - return false; - - Segment startA = getTopLeft(); - Segment startB = B.getTopLeft(); - Segment a = startA; - Segment b = startB; - do - { - if (! a.equals(b)) - return false; - - if (a instanceof LineSegment) - a = ((LineSegment) a).lastCoLinear(); - if (b instanceof LineSegment) - b = ((LineSegment) b).lastCoLinear(); - - a = a.next; - b = b.next; - } - while (a != startA && b != startB); - return true; - } - - /** - * Return the segment with the top-leftmost first point - */ - Segment getTopLeft() - { - Segment v = this; - Segment tl = this; - do - { - if (v.P1.getY() < tl.P1.getY()) - tl = v; - else if (v.P1.getY() == tl.P1.getY()) - { - if (v.P1.getX() < tl.P1.getX()) - tl = v; - } - v = v.next; - } - while (v != this); - return tl; - } - - /** - * Returns if the path has a segment outside a shape - */ - boolean isSegmentOutside(Shape shape) - { - return ! shape.contains(getMidPoint()); - } - } // class Segment - - private class LineSegment extends Segment - { - public LineSegment(double x1, double y1, double x2, double y2) - { - super(); - P1 = new Point2D.Double(x1, y1); - P2 = new Point2D.Double(x2, y2); - } - - public LineSegment(Point2D p1, Point2D p2) - { - super(); - P1 = (Point2D) p1.clone(); - P2 = (Point2D) p2.clone(); - } - - /** - * Clones this segment - */ - public Object clone() - { - return new LineSegment(P1, P2); - } - - /** - * Transforms the segment - */ - void transform(AffineTransform at) - { - P1 = at.transform(P1, null); - P2 = at.transform(P2, null); - } - - /** - * Swap start and end points - */ - void reverseCoords() - { - Point2D p = P1; - P1 = P2; - P2 = p; - } - - /** - * Returns the segment's midpoint - */ - Point2D getMidPoint() - { - return (new Point2D.Double(0.5 * (P1.getX() + P2.getX()), - 0.5 * (P1.getY() + P2.getY()))); - } - - /** - * Returns twice the area of a curve, relative the P1-P2 line - * Obviously, a line does not enclose any area besides the line - */ - double curveArea() - { - return 0; - } - - /** - * Returns the PathIterator type of a segment - */ - int getType() - { - return (PathIterator.SEG_LINETO); - } - - /** - * Subdivides the segment at parametric value t, inserting - * the new segment into the linked list after this, - * such that this becomes [0,t] and this.next becomes [t,1] - */ - void subdivideInsert(double t) - { - Point2D p = new Point2D.Double((P2.getX() - P1.getX()) * t + P1.getX(), - (P2.getY() - P1.getY()) * t + P1.getY()); - insert(new LineSegment(p, P2)); - P2 = p; - next.node = node; - node = null; - } - - /** - * Determines if two line segments are strictly colinear - */ - boolean isCoLinear(LineSegment b) - { - double x1 = P1.getX(); - double y1 = P1.getY(); - double x2 = P2.getX(); - double y2 = P2.getY(); - double x3 = b.P1.getX(); - double y3 = b.P1.getY(); - double x4 = b.P2.getX(); - double y4 = b.P2.getY(); - - if ((y1 - y3) * (x4 - x3) - (x1 - x3) * (y4 - y3) != 0.0) - return false; - - return ((x2 - x1) * (y4 - y3) - (y2 - y1) * (x4 - x3) == 0.0); - } - - /** - * Return the last segment colinear with this one. - * Used in comparing paths. - */ - Segment lastCoLinear() - { - Segment prev = this; - Segment v = next; - - while (v instanceof LineSegment) - { - if (isCoLinear((LineSegment) v)) - { - prev = v; - v = v.next; - } - else - return prev; - } - return prev; - } - - /** - * Compare two segments. - * We must take into account that the lines may be broken into colinear - * subsegments and ignore them. - */ - boolean equals(Segment b) - { - if (! (b instanceof LineSegment)) - return false; - Point2D p1 = P1; - Point2D p3 = b.P1; - - if (! p1.equals(p3)) - return false; - - Point2D p2 = lastCoLinear().P2; - Point2D p4 = ((LineSegment) b).lastCoLinear().P2; - return (p2.equals(p4)); - } - - /** - * Returns a line segment - */ - int pathIteratorFormat(double[] coords) - { - coords[0] = P2.getX(); - coords[1] = P2.getY(); - return (PathIterator.SEG_LINETO); - } - - /** - * Returns if the line has intersections. - */ - boolean hasIntersections(Segment b) - { - if (b instanceof LineSegment) - return (linesIntersect(this, (LineSegment) b) != null); - - if (b instanceof QuadSegment) - return (lineQuadIntersect(this, (QuadSegment) b) != null); - - if (b instanceof CubicSegment) - return (lineCubicIntersect(this, (CubicSegment) b) != null); - - return false; - } - - /** - * Splits intersections into nodes, - * This one handles line-line, line-quadratic, line-cubic - */ - int splitIntersections(Segment b) - { - if (b instanceof LineSegment) - { - Intersection i = linesIntersect(this, (LineSegment) b); - - if (i == null) - return 0; - - return createNode(b, i); - } - - Intersection[] x = null; - - if (b instanceof QuadSegment) - x = lineQuadIntersect(this, (QuadSegment) b); - - if (b instanceof CubicSegment) - x = lineCubicIntersect(this, (CubicSegment) b); - - if (x == null) - return 0; - - if (x.length == 1) - return createNode(b, (Intersection) x[0]); - - return createNodes(b, x); - } - - /** - * Returns the bounding box of this segment - */ - Rectangle2D getBounds() - { - return (new Rectangle2D.Double(Math.min(P1.getX(), P2.getX()), - Math.min(P1.getY(), P2.getY()), - Math.abs(P1.getX() - P2.getX()), - Math.abs(P1.getY() - P2.getY()))); - } - - /** - * Returns the number of intersections on the positive X axis, - * with the origin at (x,y), used for contains()-testing - */ - int rayCrossing(double x, double y) - { - double x0 = P1.getX() - x; - double y0 = P1.getY() - y; - double x1 = P2.getX() - x; - double y1 = P2.getY() - y; - - if (y0 * y1 > 0) - return 0; - - if (x0 < 0 && x1 < 0) - return 0; - - if (y0 == 0.0) - y0 -= EPSILON; - - if (y1 == 0.0) - y1 -= EPSILON; - - if (Line2D.linesIntersect(x0, y0, x1, y1, - EPSILON, 0.0, Double.MAX_VALUE, 0.0)) - return 1; - return 0; - } - } // class LineSegment - - /** - * Quadratic Bezier curve segment - * - * Note: Most peers don't support quadratics directly, so it might make - * sense to represent them as cubics internally and just be done with it. - * I think we should be peer-agnostic, however, and stay faithful to the - * input geometry types as far as possible. - */ - private class QuadSegment extends Segment - { - Point2D cp; // control point - - /** - * Constructor, takes the coordinates of the start, control, - * and end point, respectively. - */ - QuadSegment(double x1, double y1, double cx, double cy, double x2, - double y2) - { - super(); - P1 = new Point2D.Double(x1, y1); - P2 = new Point2D.Double(x2, y2); - cp = new Point2D.Double(cx, cy); - } - - /** - * Clones this segment - */ - public Object clone() - { - return new QuadSegment(P1.getX(), P1.getY(), cp.getX(), cp.getY(), - P2.getX(), P2.getY()); - } - - /** - * Returns twice the area of a curve, relative the P1-P2 line - * - * The area formula can be derived by using Green's formula in the - * plane on the parametric form of the bezier. - */ - double curveArea() - { - double x0 = P1.getX(); - double y0 = P1.getY(); - double x1 = cp.getX(); - double y1 = cp.getY(); - double x2 = P2.getX(); - double y2 = P2.getY(); - - double P = (y2 - 2 * y1 + y0); - double Q = 2 * (y1 - y0); - - double A = (x2 - 2 * x1 + x0); - double B = 2 * (x1 - x0); - - double area = (B * P - A * Q) / 3.0; - return (area); - } - - /** - * Compare two segments. - */ - boolean equals(Segment b) - { - if (! (b instanceof QuadSegment)) - return false; - - return (P1.equals(b.P1) && cp.equals(((QuadSegment) b).cp) - && P2.equals(b.P2)); - } - - /** - * Returns a Point2D corresponding to the parametric value t - * of the curve - */ - Point2D evaluatePoint(double t) - { - double x0 = P1.getX(); - double y0 = P1.getY(); - double x1 = cp.getX(); - double y1 = cp.getY(); - double x2 = P2.getX(); - double y2 = P2.getY(); - - return new Point2D.Double(t * t * (x2 - 2 * x1 + x0) + 2 * t * (x1 - x0) - + x0, - t * t * (y2 - 2 * y1 + y0) + 2 * t * (y1 - y0) - + y0); - } - - /** - * Returns the bounding box of this segment - */ - Rectangle2D getBounds() - { - double x0 = P1.getX(); - double y0 = P1.getY(); - double x1 = cp.getX(); - double y1 = cp.getY(); - double x2 = P2.getX(); - double y2 = P2.getY(); - double r0; - double r1; - - double xmax = Math.max(x0, x2); - double ymax = Math.max(y0, y2); - double xmin = Math.min(x0, x2); - double ymin = Math.min(y0, y2); - - r0 = 2 * (y1 - y0); - r1 = 2 * (y2 - 2 * y1 + y0); - if (r1 != 0.0) - { - double t = -r0 / r1; - if (t > 0.0 && t < 1.0) - { - double y = evaluatePoint(t).getY(); - ymax = Math.max(y, ymax); - ymin = Math.min(y, ymin); - } - } - r0 = 2 * (x1 - x0); - r1 = 2 * (x2 - 2 * x1 + x0); - if (r1 != 0.0) - { - double t = -r0 / r1; - if (t > 0.0 && t < 1.0) - { - double x = evaluatePoint(t).getY(); - xmax = Math.max(x, xmax); - xmin = Math.min(x, xmin); - } - } - - return (new Rectangle2D.Double(xmin, ymin, xmax - xmin, ymax - ymin)); - } - - /** - * Returns a cubic segment corresponding to this curve - */ - CubicSegment getCubicSegment() - { - double x1 = P1.getX() + 2.0 * (cp.getX() - P1.getX()) / 3.0; - double y1 = P1.getY() + 2.0 * (cp.getY() - P1.getY()) / 3.0; - double x2 = cp.getX() + (P2.getX() - cp.getX()) / 3.0; - double y2 = cp.getY() + (P2.getY() - cp.getY()) / 3.0; - - return new CubicSegment(P1.getX(), P1.getY(), x1, y1, x2, y2, P2.getX(), - P2.getY()); - } - - /** - * Returns the segment's midpoint - */ - Point2D getMidPoint() - { - return evaluatePoint(0.5); - } - - /** - * Returns the PathIterator type of a segment - */ - int getType() - { - return (PathIterator.SEG_QUADTO); - } - - /** - * Returns the PathIterator coords of a segment - */ - int pathIteratorFormat(double[] coords) - { - coords[0] = cp.getX(); - coords[1] = cp.getY(); - coords[2] = P2.getX(); - coords[3] = P2.getY(); - return (PathIterator.SEG_QUADTO); - } - - /** - * Returns the number of intersections on the positive X axis, - * with the origin at (x,y), used for contains()-testing - */ - int rayCrossing(double x, double y) - { - double x0 = P1.getX() - x; - double y0 = P1.getY() - y; - double x1 = cp.getX() - x; - double y1 = cp.getY() - y; - double x2 = P2.getX() - x; - double y2 = P2.getY() - y; - double[] r = new double[3]; - int nRoots; - int nCrossings = 0; - - /* check if curve may intersect X+ axis. */ - if ((x0 > 0.0 || x1 > 0.0 || x2 > 0.0) && (y0 * y1 <= 0 || y1 * y2 <= 0)) - { - if (y0 == 0.0) - y0 -= EPSILON; - if (y2 == 0.0) - y2 -= EPSILON; - - r[0] = y0; - r[1] = 2 * (y1 - y0); - r[2] = (y2 - 2 * y1 + y0); - - nRoots = QuadCurve2D.solveQuadratic(r); - for (int i = 0; i < nRoots; i++) - if (r[i] > 0.0f && r[i] < 1.0f) - { - double t = r[i]; - if (t * t * (x2 - 2 * x1 + x0) + 2 * t * (x1 - x0) + x0 > 0.0) - nCrossings++; - } - } - return nCrossings; - } - - /** - * Swap start and end points - */ - void reverseCoords() - { - Point2D temp = P1; - P1 = P2; - P2 = temp; - } - - /** - * Splits intersections into nodes, - * This one handles quadratic-quadratic only, - * Quadratic-line is passed on to the LineSegment class, - * Quadratic-cubic is passed on to the CubicSegment class - */ - int splitIntersections(Segment b) - { - if (b instanceof LineSegment) - return (b.splitIntersections(this)); - - if (b instanceof CubicSegment) - return (b.splitIntersections(this)); - - if (b instanceof QuadSegment) - { - // Use the cubic-cubic intersection routine for quads as well, - // Since a quadratic can be exactly described as a cubic, this - // should not be a problem; - // The recursion depth will be the same in any case. - Intersection[] x = cubicCubicIntersect(getCubicSegment(), - ((QuadSegment) b) - .getCubicSegment()); - if (x == null) - return 0; - - if (x.length == 1) - return createNode(b, (Intersection) x[0]); - - return createNodes(b, x); - } - return 0; - } - - /** - * Subdivides the segment at parametric value t, inserting - * the new segment into the linked list after this, - * such that this becomes [0,t] and this.next becomes [t,1] - */ - void subdivideInsert(double t) - { - double x0 = P1.getX(); - double y0 = P1.getY(); - double x1 = cp.getX(); - double y1 = cp.getY(); - double x2 = P2.getX(); - double y2 = P2.getY(); - - double p10x = x0 + t * (x1 - x0); - double p10y = y0 + t * (y1 - y0); - double p11x = x1 + t * (x2 - x1); - double p11y = y1 + t * (y2 - y1); - double p20x = p10x + t * (p11x - p10x); - double p20y = p10y + t * (p11y - p10y); - - insert(new QuadSegment(p20x, p20y, p11x, p11y, x2, y2)); - P2 = next.P1; - cp.setLocation(p10x, p10y); - - next.node = node; - node = null; - } - - /** - * Transforms the segment - */ - void transform(AffineTransform at) - { - P1 = at.transform(P1, null); - P2 = at.transform(P2, null); - cp = at.transform(cp, null); - } - } // class QuadSegment - - /** - * Cubic Bezier curve segment - */ - private class CubicSegment extends Segment - { - Point2D cp1; // control points - Point2D cp2; // control points - - /** - * Constructor - takes coordinates of the starting point, - * first control point, second control point and end point, - * respecively. - */ - public CubicSegment(double x1, double y1, double c1x, double c1y, - double c2x, double c2y, double x2, double y2) - { - super(); - P1 = new Point2D.Double(x1, y1); - P2 = new Point2D.Double(x2, y2); - cp1 = new Point2D.Double(c1x, c1y); - cp2 = new Point2D.Double(c2x, c2y); - } - - /** - * Clones this segment - */ - public Object clone() - { - return new CubicSegment(P1.getX(), P1.getY(), cp1.getX(), cp1.getY(), - cp2.getX(), cp2.getY(), P2.getX(), P2.getY()); - } - - /** - * Returns twice the area of a curve, relative the P1-P2 line - * - * The area formula can be derived by using Green's formula in the - * plane on the parametric form of the bezier. - */ - double curveArea() - { - double x0 = P1.getX(); - double y0 = P1.getY(); - double x1 = cp1.getX(); - double y1 = cp1.getY(); - double x2 = cp2.getX(); - double y2 = cp2.getY(); - double x3 = P2.getX(); - double y3 = P2.getY(); - - double P = y3 - 3 * y2 + 3 * y1 - y0; - double Q = 3 * (y2 + y0 - 2 * y1); - double R = 3 * (y1 - y0); - - double A = x3 - 3 * x2 + 3 * x1 - x0; - double B = 3 * (x2 + x0 - 2 * x1); - double C = 3 * (x1 - x0); - - double area = (B * P - A * Q) / 5.0 + (C * P - A * R) / 2.0 - + (C * Q - B * R) / 3.0; - - return (area); - } - - /** - * Compare two segments. - */ - boolean equals(Segment b) - { - if (! (b instanceof CubicSegment)) - return false; - - return (P1.equals(b.P1) && cp1.equals(((CubicSegment) b).cp1) - && cp2.equals(((CubicSegment) b).cp2) && P2.equals(b.P2)); - } - - /** - * Returns a Point2D corresponding to the parametric value t - * of the curve - */ - Point2D evaluatePoint(double t) - { - double x0 = P1.getX(); - double y0 = P1.getY(); - double x1 = cp1.getX(); - double y1 = cp1.getY(); - double x2 = cp2.getX(); - double y2 = cp2.getY(); - double x3 = P2.getX(); - double y3 = P2.getY(); - - return new Point2D.Double(-(t * t * t) * (x0 - 3 * x1 + 3 * x2 - x3) - + 3 * t * t * (x0 - 2 * x1 + x2) - + 3 * t * (x1 - x0) + x0, - -(t * t * t) * (y0 - 3 * y1 + 3 * y2 - y3) - + 3 * t * t * (y0 - 2 * y1 + y2) - + 3 * t * (y1 - y0) + y0); - } - - /** - * Returns the bounding box of this segment - */ - Rectangle2D getBounds() - { - double x0 = P1.getX(); - double y0 = P1.getY(); - double x1 = cp1.getX(); - double y1 = cp1.getY(); - double x2 = cp2.getX(); - double y2 = cp2.getY(); - double x3 = P2.getX(); - double y3 = P2.getY(); - double[] r = new double[3]; - - double xmax = Math.max(x0, x3); - double ymax = Math.max(y0, y3); - double xmin = Math.min(x0, x3); - double ymin = Math.min(y0, y3); - - r[0] = 3 * (y1 - y0); - r[1] = 6.0 * (y2 + y0 - 2 * y1); - r[2] = 3.0 * (y3 - 3 * y2 + 3 * y1 - y0); - - int n = QuadCurve2D.solveQuadratic(r); - for (int i = 0; i < n; i++) - { - double t = r[i]; - if (t > 0 && t < 1.0) - { - double y = evaluatePoint(t).getY(); - ymax = Math.max(y, ymax); - ymin = Math.min(y, ymin); - } - } - - r[0] = 3 * (x1 - x0); - r[1] = 6.0 * (x2 + x0 - 2 * x1); - r[2] = 3.0 * (x3 - 3 * x2 + 3 * x1 - x0); - n = QuadCurve2D.solveQuadratic(r); - for (int i = 0; i < n; i++) - { - double t = r[i]; - if (t > 0 && t < 1.0) - { - double x = evaluatePoint(t).getX(); - xmax = Math.max(x, xmax); - xmin = Math.min(x, xmin); - } - } - return (new Rectangle2D.Double(xmin, ymin, (xmax - xmin), (ymax - ymin))); - } - - /** - * Returns a CubicCurve2D object corresponding to this segment. - */ - CubicCurve2D getCubicCurve2D() - { - return new CubicCurve2D.Double(P1.getX(), P1.getY(), cp1.getX(), - cp1.getY(), cp2.getX(), cp2.getY(), - P2.getX(), P2.getY()); - } - - /** - * Returns the parametric points of self-intersection if the cubic - * is self-intersecting, null otherwise. - */ - double[] getLoop() - { - double x0 = P1.getX(); - double y0 = P1.getY(); - double x1 = cp1.getX(); - double y1 = cp1.getY(); - double x2 = cp2.getX(); - double y2 = cp2.getY(); - double x3 = P2.getX(); - double y3 = P2.getY(); - double[] r = new double[4]; - double k; - double R; - double T; - double A; - double B; - double[] results = new double[2]; - - R = x3 - 3 * x2 + 3 * x1 - x0; - T = y3 - 3 * y2 + 3 * y1 - y0; - - // A qudratic - if (R == 0.0 && T == 0.0) - return null; - - // true cubic - if (R != 0.0 && T != 0.0) - { - A = 3 * (x2 + x0 - 2 * x1) / R; - B = 3 * (x1 - x0) / R; - - double P = 3 * (y2 + y0 - 2 * y1) / T; - double Q = 3 * (y1 - y0) / T; - - if (A == P || Q == B) - return null; - - k = (Q - B) / (A - P); - } - else - { - if (R == 0.0) - { - // quadratic in x - k = -(3 * (x1 - x0)) / (3 * (x2 + x0 - 2 * x1)); - A = 3 * (y2 + y0 - 2 * y1) / T; - B = 3 * (y1 - y0) / T; - } - else - { - // quadratic in y - k = -(3 * (y1 - y0)) / (3 * (y2 + y0 - 2 * y1)); - A = 3 * (x2 + x0 - 2 * x1) / R; - B = 3 * (x1 - x0) / R; - } - } - - r[0] = -k * k * k - A * k * k - B * k; - r[1] = 3 * k * k + 2 * k * A + 2 * B; - r[2] = -3 * k; - r[3] = 2; - - int n = CubicCurve2D.solveCubic(r); - if (n != 3) - return null; - - // sort r - double t; - for (int i = 0; i < 2; i++) - for (int j = i + 1; j < 3; j++) - if (r[j] < r[i]) - { - t = r[i]; - r[i] = r[j]; - r[j] = t; - } - - if (Math.abs(r[0] + r[2] - k) < 1E-13) - if (r[0] >= 0.0 && r[0] <= 1.0 && r[2] >= 0.0 && r[2] <= 1.0) - if (evaluatePoint(r[0]).distance(evaluatePoint(r[2])) < PE_EPSILON * 10) - { // we snap the points anyway - results[0] = r[0]; - results[1] = r[2]; - return (results); - } - return null; - } - - /** - * Returns the segment's midpoint - */ - Point2D getMidPoint() - { - return evaluatePoint(0.5); - } - - /** - * Returns the PathIterator type of a segment - */ - int getType() - { - return (PathIterator.SEG_CUBICTO); - } - - /** - * Returns the PathIterator coords of a segment - */ - int pathIteratorFormat(double[] coords) - { - coords[0] = cp1.getX(); - coords[1] = cp1.getY(); - coords[2] = cp2.getX(); - coords[3] = cp2.getY(); - coords[4] = P2.getX(); - coords[5] = P2.getY(); - return (PathIterator.SEG_CUBICTO); - } - - /** - * Returns the number of intersections on the positive X axis, - * with the origin at (x,y), used for contains()-testing - */ - int rayCrossing(double x, double y) - { - double x0 = P1.getX() - x; - double y0 = P1.getY() - y; - double x1 = cp1.getX() - x; - double y1 = cp1.getY() - y; - double x2 = cp2.getX() - x; - double y2 = cp2.getY() - y; - double x3 = P2.getX() - x; - double y3 = P2.getY() - y; - double[] r = new double[4]; - int nRoots; - int nCrossings = 0; - - /* check if curve may intersect X+ axis. */ - if ((x0 > 0.0 || x1 > 0.0 || x2 > 0.0 || x3 > 0.0) - && (y0 * y1 <= 0 || y1 * y2 <= 0 || y2 * y3 <= 0)) - { - if (y0 == 0.0) - y0 -= EPSILON; - if (y3 == 0.0) - y3 -= EPSILON; - - r[0] = y0; - r[1] = 3 * (y1 - y0); - r[2] = 3 * (y2 + y0 - 2 * y1); - r[3] = y3 - 3 * y2 + 3 * y1 - y0; - - if ((nRoots = CubicCurve2D.solveCubic(r)) > 0) - for (int i = 0; i < nRoots; i++) - { - if (r[i] > 0.0 && r[i] < 1.0) - { - double t = r[i]; - if (-(t * t * t) * (x0 - 3 * x1 + 3 * x2 - x3) - + 3 * t * t * (x0 - 2 * x1 + x2) + 3 * t * (x1 - x0) - + x0 > 0.0) - nCrossings++; - } - } - } - return nCrossings; - } - - /** - * Swap start and end points - */ - void reverseCoords() - { - Point2D p = P1; - P1 = P2; - P2 = p; - p = cp1; // swap control points - cp1 = cp2; - cp2 = p; - } - - /** - * Splits intersections into nodes, - * This one handles cubic-cubic and cubic-quadratic intersections - */ - int splitIntersections(Segment b) - { - if (b instanceof LineSegment) - return (b.splitIntersections(this)); - - Intersection[] x = null; - - if (b instanceof QuadSegment) - x = cubicCubicIntersect(this, ((QuadSegment) b).getCubicSegment()); - - if (b instanceof CubicSegment) - x = cubicCubicIntersect(this, (CubicSegment) b); - - if (x == null) - return 0; - - if (x.length == 1) - return createNode(b, x[0]); - - return createNodes(b, x); - } - - /** - * Subdivides the segment at parametric value t, inserting - * the new segment into the linked list after this, - * such that this becomes [0,t] and this.next becomes [t,1] - */ - void subdivideInsert(double t) - { - CubicSegment s = (CubicSegment) clone(); - double p1x = (s.cp1.getX() - s.P1.getX()) * t + s.P1.getX(); - double p1y = (s.cp1.getY() - s.P1.getY()) * t + s.P1.getY(); - - double px = (s.cp2.getX() - s.cp1.getX()) * t + s.cp1.getX(); - double py = (s.cp2.getY() - s.cp1.getY()) * t + s.cp1.getY(); - - s.cp2.setLocation((s.P2.getX() - s.cp2.getX()) * t + s.cp2.getX(), - (s.P2.getY() - s.cp2.getY()) * t + s.cp2.getY()); - - s.cp1.setLocation((s.cp2.getX() - px) * t + px, - (s.cp2.getY() - py) * t + py); - - double p2x = (px - p1x) * t + p1x; - double p2y = (py - p1y) * t + p1y; - - double p3x = (s.cp1.getX() - p2x) * t + p2x; - double p3y = (s.cp1.getY() - p2y) * t + p2y; - s.P1.setLocation(p3x, p3y); - - // insert new curve - insert(s); - - // set this curve - cp1.setLocation(p1x, p1y); - cp2.setLocation(p2x, p2y); - P2 = s.P1; - next.node = node; - node = null; - } - - /** - * Transforms the segment - */ - void transform(AffineTransform at) - { - P1 = at.transform(P1, null); - P2 = at.transform(P2, null); - cp1 = at.transform(cp1, null); - cp2 = at.transform(cp2, null); - } - } // class CubicSegment -} // class Area diff --git a/libjava/java/awt/geom/CubicCurve2D.java b/libjava/java/awt/geom/CubicCurve2D.java deleted file mode 100644 index 50c381194bb..00000000000 --- a/libjava/java/awt/geom/CubicCurve2D.java +++ /dev/null @@ -1,1724 +0,0 @@ -/* CubicCurve2D.java -- represents a parameterized cubic curve in 2-D space - Copyright (C) 2002, 2003, 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.awt.geom; - -import java.awt.Rectangle; -import java.awt.Shape; -import java.util.NoSuchElementException; - - -/** - * A two-dimensional curve that is parameterized with a cubic - * function. - * - * <p><img src="doc-files/CubicCurve2D-1.png" width="350" height="180" - * alt="A drawing of a CubicCurve2D" /> - * - * @author Eric Blake (ebb9@email.byu.edu) - * @author Graydon Hoare (graydon@redhat.com) - * @author Sascha Brawer (brawer@dandelis.ch) - * @author Sven de Marothy (sven@physto.se) - * - * @since 1.2 - */ -public abstract class CubicCurve2D implements Shape, Cloneable -{ - private static final double BIG_VALUE = java.lang.Double.MAX_VALUE / 10.0; - private static final double EPSILON = 1E-10; - - /** - * Constructs a new CubicCurve2D. Typical users will want to - * construct instances of a subclass, such as {@link - * CubicCurve2D.Float} or {@link CubicCurve2D.Double}. - */ - protected CubicCurve2D() - { - } - - /** - * Returns the <i>x</i> coordinate of the curve’s start - * point. - */ - public abstract double getX1(); - - /** - * Returns the <i>y</i> coordinate of the curve’s start - * point. - */ - public abstract double getY1(); - - /** - * Returns the curve’s start point. - */ - public abstract Point2D getP1(); - - /** - * Returns the <i>x</i> coordinate of the curve’s first - * control point. - */ - public abstract double getCtrlX1(); - - /** - * Returns the <i>y</i> coordinate of the curve’s first - * control point. - */ - public abstract double getCtrlY1(); - - /** - * Returns the curve’s first control point. - */ - public abstract Point2D getCtrlP1(); - - /** - * Returns the <i>x</i> coordinate of the curve’s second - * control point. - */ - public abstract double getCtrlX2(); - - /** - * Returns the <i>y</i> coordinate of the curve’s second - * control point. - */ - public abstract double getCtrlY2(); - - /** - * Returns the curve’s second control point. - */ - public abstract Point2D getCtrlP2(); - - /** - * Returns the <i>x</i> coordinate of the curve’s end - * point. - */ - public abstract double getX2(); - - /** - * Returns the <i>y</i> coordinate of the curve’s end - * point. - */ - public abstract double getY2(); - - /** - * Returns the curve’s end point. - */ - public abstract Point2D getP2(); - - /** - * Changes the curve geometry, separately specifying each coordinate - * value. - * - * <p><img src="doc-files/CubicCurve2D-1.png" width="350" height="180" - * alt="A drawing of a CubicCurve2D" /> - * - * @param x1 the <i>x</i> coordinate of the curve’s new start - * point. - * - * @param y1 the <i>y</i> coordinate of the curve’s new start - * point. - * - * @param cx1 the <i>x</i> coordinate of the curve’s new - * first control point. - * - * @param cy1 the <i>y</i> coordinate of the curve’s new - * first control point. - * - * @param cx2 the <i>x</i> coordinate of the curve’s new - * second control point. - * - * @param cy2 the <i>y</i> coordinate of the curve’s new - * second control point. - * - * @param x2 the <i>x</i> coordinate of the curve’s new end - * point. - * - * @param y2 the <i>y</i> coordinate of the curve’s new end - * point. - */ - public abstract void setCurve(double x1, double y1, double cx1, double cy1, - double cx2, double cy2, double x2, double y2); - - /** - * Changes the curve geometry, specifying coordinate values in an - * array. - * - * @param coords an array containing the new coordinate values. The - * <i>x</i> coordinate of the new start point is located at - * <code>coords[offset]</code>, its <i>y</i> coordinate at - * <code>coords[offset + 1]</code>. The <i>x</i> coordinate of the - * new first control point is located at <code>coords[offset + - * 2]</code>, its <i>y</i> coordinate at <code>coords[offset + - * 3]</code>. The <i>x</i> coordinate of the new second control - * point is located at <code>coords[offset + 4]</code>, its <i>y</i> - * coordinate at <code>coords[offset + 5]</code>. The <i>x</i> - * coordinate of the new end point is located at <code>coords[offset - * + 6]</code>, its <i>y</i> coordinate at <code>coords[offset + - * 7]</code>. - * - * @param offset the offset of the first coordinate value in - * <code>coords</code>. - */ - public void setCurve(double[] coords, int offset) - { - setCurve(coords[offset++], coords[offset++], coords[offset++], - coords[offset++], coords[offset++], coords[offset++], - coords[offset++], coords[offset++]); - } - - /** - * Changes the curve geometry, specifying coordinate values in - * separate Point objects. - * - * <p><img src="doc-files/CubicCurve2D-1.png" width="350" height="180" - * alt="A drawing of a CubicCurve2D" /> - * - * <p>The curve does not keep any reference to the passed point - * objects. Therefore, a later change to <code>p1</code>, - * <code>c1</code>, <code>c2</code> or <code>p2</code> will not - * affect the curve geometry. - * - * @param p1 the new start point. - * @param c1 the new first control point. - * @param c2 the new second control point. - * @param p2 the new end point. - */ - public void setCurve(Point2D p1, Point2D c1, Point2D c2, Point2D p2) - { - setCurve(p1.getX(), p1.getY(), c1.getX(), c1.getY(), c2.getX(), c2.getY(), - p2.getX(), p2.getY()); - } - - /** - * Changes the curve geometry, specifying coordinate values in an - * array of Point objects. - * - * <p><img src="doc-files/CubicCurve2D-1.png" width="350" height="180" - * alt="A drawing of a CubicCurve2D" /> - * - * <p>The curve does not keep references to the passed point - * objects. Therefore, a later change to the <code>pts</code> array - * or any of its elements will not affect the curve geometry. - * - * @param pts an array containing the points. The new start point - * is located at <code>pts[offset]</code>, the new first control - * point at <code>pts[offset + 1]</code>, the new second control - * point at <code>pts[offset + 2]</code>, and the new end point - * at <code>pts[offset + 3]</code>. - * - * @param offset the offset of the start point in <code>pts</code>. - */ - public void setCurve(Point2D[] pts, int offset) - { - setCurve(pts[offset].getX(), pts[offset++].getY(), pts[offset].getX(), - pts[offset++].getY(), pts[offset].getX(), pts[offset++].getY(), - pts[offset].getX(), pts[offset++].getY()); - } - - /** - * Changes the curve geometry to that of another curve. - * - * @param c the curve whose coordinates will be copied. - */ - public void setCurve(CubicCurve2D c) - { - setCurve(c.getX1(), c.getY1(), c.getCtrlX1(), c.getCtrlY1(), - c.getCtrlX2(), c.getCtrlY2(), c.getX2(), c.getY2()); - } - - /** - * Calculates the squared flatness of a cubic curve, directly - * specifying each coordinate value. The flatness is the maximal - * distance of a control point to the line between start and end - * point. - * - * <p><img src="doc-files/CubicCurve2D-4.png" width="350" height="180" - * alt="A drawing that illustrates the flatness" /> - * - * <p>In the above drawing, the straight line connecting start point - * P1 and end point P2 is depicted in gray. In comparison to C1, - * control point C2 is father away from the gray line. Therefore, - * the result will be the square of the distance between C2 and the - * gray line, i.e. the squared length of the red line. - * - * @param x1 the <i>x</i> coordinate of the start point P1. - * @param y1 the <i>y</i> coordinate of the start point P1. - * @param cx1 the <i>x</i> coordinate of the first control point C1. - * @param cy1 the <i>y</i> coordinate of the first control point C1. - * @param cx2 the <i>x</i> coordinate of the second control point C2. - * @param cy2 the <i>y</i> coordinate of the second control point C2. - * @param x2 the <i>x</i> coordinate of the end point P2. - * @param y2 the <i>y</i> coordinate of the end point P2. - */ - public static double getFlatnessSq(double x1, double y1, double cx1, - double cy1, double cx2, double cy2, - double x2, double y2) - { - return Math.max(Line2D.ptSegDistSq(x1, y1, x2, y2, cx1, cy1), - Line2D.ptSegDistSq(x1, y1, x2, y2, cx2, cy2)); - } - - /** - * Calculates the flatness of a cubic curve, directly specifying - * each coordinate value. The flatness is the maximal distance of a - * control point to the line between start and end point. - * - * <p><img src="doc-files/CubicCurve2D-4.png" width="350" height="180" - * alt="A drawing that illustrates the flatness" /> - * - * <p>In the above drawing, the straight line connecting start point - * P1 and end point P2 is depicted in gray. In comparison to C1, - * control point C2 is father away from the gray line. Therefore, - * the result will be the distance between C2 and the gray line, - * i.e. the length of the red line. - * - * @param x1 the <i>x</i> coordinate of the start point P1. - * @param y1 the <i>y</i> coordinate of the start point P1. - * @param cx1 the <i>x</i> coordinate of the first control point C1. - * @param cy1 the <i>y</i> coordinate of the first control point C1. - * @param cx2 the <i>x</i> coordinate of the second control point C2. - * @param cy2 the <i>y</i> coordinate of the second control point C2. - * @param x2 the <i>x</i> coordinate of the end point P2. - * @param y2 the <i>y</i> coordinate of the end point P2. - */ - public static double getFlatness(double x1, double y1, double cx1, - double cy1, double cx2, double cy2, - double x2, double y2) - { - return Math.sqrt(getFlatnessSq(x1, y1, cx1, cy1, cx2, cy2, x2, y2)); - } - - /** - * Calculates the squared flatness of a cubic curve, specifying the - * coordinate values in an array. The flatness is the maximal - * distance of a control point to the line between start and end - * point. - * - * <p><img src="doc-files/CubicCurve2D-4.png" width="350" height="180" - * alt="A drawing that illustrates the flatness" /> - * - * <p>In the above drawing, the straight line connecting start point - * P1 and end point P2 is depicted in gray. In comparison to C1, - * control point C2 is father away from the gray line. Therefore, - * the result will be the square of the distance between C2 and the - * gray line, i.e. the squared length of the red line. - * - * @param coords an array containing the coordinate values. The - * <i>x</i> coordinate of the start point P1 is located at - * <code>coords[offset]</code>, its <i>y</i> coordinate at - * <code>coords[offset + 1]</code>. The <i>x</i> coordinate of the - * first control point C1 is located at <code>coords[offset + - * 2]</code>, its <i>y</i> coordinate at <code>coords[offset + - * 3]</code>. The <i>x</i> coordinate of the second control point C2 - * is located at <code>coords[offset + 4]</code>, its <i>y</i> - * coordinate at <code>coords[offset + 5]</code>. The <i>x</i> - * coordinate of the end point P2 is located at <code>coords[offset - * + 6]</code>, its <i>y</i> coordinate at <code>coords[offset + - * 7]</code>. - * - * @param offset the offset of the first coordinate value in - * <code>coords</code>. - */ - public static double getFlatnessSq(double[] coords, int offset) - { - return getFlatnessSq(coords[offset++], coords[offset++], coords[offset++], - coords[offset++], coords[offset++], coords[offset++], - coords[offset++], coords[offset++]); - } - - /** - * Calculates the flatness of a cubic curve, specifying the - * coordinate values in an array. The flatness is the maximal - * distance of a control point to the line between start and end - * point. - * - * <p><img src="doc-files/CubicCurve2D-4.png" width="350" height="180" - * alt="A drawing that illustrates the flatness" /> - * - * <p>In the above drawing, the straight line connecting start point - * P1 and end point P2 is depicted in gray. In comparison to C1, - * control point C2 is father away from the gray line. Therefore, - * the result will be the distance between C2 and the gray line, - * i.e. the length of the red line. - * - * @param coords an array containing the coordinate values. The - * <i>x</i> coordinate of the start point P1 is located at - * <code>coords[offset]</code>, its <i>y</i> coordinate at - * <code>coords[offset + 1]</code>. The <i>x</i> coordinate of the - * first control point C1 is located at <code>coords[offset + - * 2]</code>, its <i>y</i> coordinate at <code>coords[offset + - * 3]</code>. The <i>x</i> coordinate of the second control point C2 - * is located at <code>coords[offset + 4]</code>, its <i>y</i> - * coordinate at <code>coords[offset + 5]</code>. The <i>x</i> - * coordinate of the end point P2 is located at <code>coords[offset - * + 6]</code>, its <i>y</i> coordinate at <code>coords[offset + - * 7]</code>. - * - * @param offset the offset of the first coordinate value in - * <code>coords</code>. - */ - public static double getFlatness(double[] coords, int offset) - { - return Math.sqrt(getFlatnessSq(coords[offset++], coords[offset++], - coords[offset++], coords[offset++], - coords[offset++], coords[offset++], - coords[offset++], coords[offset++])); - } - - /** - * Calculates the squared flatness of this curve. The flatness is - * the maximal distance of a control point to the line between start - * and end point. - * - * <p><img src="doc-files/CubicCurve2D-4.png" width="350" height="180" - * alt="A drawing that illustrates the flatness" /> - * - * <p>In the above drawing, the straight line connecting start point - * P1 and end point P2 is depicted in gray. In comparison to C1, - * control point C2 is father away from the gray line. Therefore, - * the result will be the square of the distance between C2 and the - * gray line, i.e. the squared length of the red line. - */ - public double getFlatnessSq() - { - return getFlatnessSq(getX1(), getY1(), getCtrlX1(), getCtrlY1(), - getCtrlX2(), getCtrlY2(), getX2(), getY2()); - } - - /** - * Calculates the flatness of this curve. The flatness is the - * maximal distance of a control point to the line between start and - * end point. - * - * <p><img src="doc-files/CubicCurve2D-4.png" width="350" height="180" - * alt="A drawing that illustrates the flatness" /> - * - * <p>In the above drawing, the straight line connecting start point - * P1 and end point P2 is depicted in gray. In comparison to C1, - * control point C2 is father away from the gray line. Therefore, - * the result will be the distance between C2 and the gray line, - * i.e. the length of the red line. - */ - public double getFlatness() - { - return Math.sqrt(getFlatnessSq(getX1(), getY1(), getCtrlX1(), getCtrlY1(), - getCtrlX2(), getCtrlY2(), getX2(), getY2())); - } - - /** - * Subdivides this curve into two halves. - * - * <p><img src="doc-files/CubicCurve2D-3.png" width="700" - * height="180" alt="A drawing that illustrates the effects of - * subdividing a CubicCurve2D" /> - * - * @param left a curve whose geometry will be set to the left half - * of this curve, or <code>null</code> if the caller is not - * interested in the left half. - * - * @param right a curve whose geometry will be set to the right half - * of this curve, or <code>null</code> if the caller is not - * interested in the right half. - */ - public void subdivide(CubicCurve2D left, CubicCurve2D right) - { - // Use empty slots at end to share single array. - double[] d = new double[] - { - getX1(), getY1(), getCtrlX1(), getCtrlY1(), getCtrlX2(), - getCtrlY2(), getX2(), getY2(), 0, 0, 0, 0, 0, 0 - }; - subdivide(d, 0, d, 0, d, 6); - if (left != null) - left.setCurve(d, 0); - if (right != null) - right.setCurve(d, 6); - } - - /** - * Subdivides a cubic curve into two halves. - * - * <p><img src="doc-files/CubicCurve2D-3.png" width="700" - * height="180" alt="A drawing that illustrates the effects of - * subdividing a CubicCurve2D" /> - * - * @param src the curve to be subdivided. - * - * @param left a curve whose geometry will be set to the left half - * of <code>src</code>, or <code>null</code> if the caller is not - * interested in the left half. - * - * @param right a curve whose geometry will be set to the right half - * of <code>src</code>, or <code>null</code> if the caller is not - * interested in the right half. - */ - public static void subdivide(CubicCurve2D src, CubicCurve2D left, - CubicCurve2D right) - { - src.subdivide(left, right); - } - - /** - * Subdivides a cubic curve into two halves, passing all coordinates - * in an array. - * - * <p><img src="doc-files/CubicCurve2D-3.png" width="700" - * height="180" alt="A drawing that illustrates the effects of - * subdividing a CubicCurve2D" /> - * - * <p>The left end point and the right start point will always be - * identical. Memory-concious programmers thus may want to pass the - * same array for both <code>left</code> and <code>right</code>, and - * set <code>rightOff</code> to <code>leftOff + 6</code>. - * - * @param src an array containing the coordinates of the curve to be - * subdivided. The <i>x</i> coordinate of the start point P1 is - * located at <code>src[srcOff]</code>, its <i>y</i> at - * <code>src[srcOff + 1]</code>. The <i>x</i> coordinate of the - * first control point C1 is located at <code>src[srcOff + - * 2]</code>, its <i>y</i> at <code>src[srcOff + 3]</code>. The - * <i>x</i> coordinate of the second control point C2 is located at - * <code>src[srcOff + 4]</code>, its <i>y</i> at <code>src[srcOff + - * 5]</code>. The <i>x</i> coordinate of the end point is located at - * <code>src[srcOff + 6]</code>, its <i>y</i> at <code>src[srcOff + - * 7]</code>. - * - * @param srcOff an offset into <code>src</code>, specifying - * the index of the start point’s <i>x</i> coordinate. - * - * @param left an array that will receive the coordinates of the - * left half of <code>src</code>. It is acceptable to pass - * <code>src</code>. A caller who is not interested in the left half - * can pass <code>null</code>. - * - * @param leftOff an offset into <code>left</code>, specifying the - * index where the start point’s <i>x</i> coordinate will be - * stored. - * - * @param right an array that will receive the coordinates of the - * right half of <code>src</code>. It is acceptable to pass - * <code>src</code> or <code>left</code>. A caller who is not - * interested in the right half can pass <code>null</code>. - * - * @param rightOff an offset into <code>right</code>, specifying the - * index where the start point’s <i>x</i> coordinate will be - * stored. - */ - public static void subdivide(double[] src, int srcOff, double[] left, - int leftOff, double[] right, int rightOff) - { - // To understand this code, please have a look at the image - // "CubicCurve2D-3.png" in the sub-directory "doc-files". - double src_C1_x; - double src_C1_y; - double src_C2_x; - double src_C2_y; - double left_P1_x; - double left_P1_y; - double left_C1_x; - double left_C1_y; - double left_C2_x; - double left_C2_y; - double right_C1_x; - double right_C1_y; - double right_C2_x; - double right_C2_y; - double right_P2_x; - double right_P2_y; - double Mid_x; // Mid = left.P2 = right.P1 - double Mid_y; // Mid = left.P2 = right.P1 - - left_P1_x = src[srcOff]; - left_P1_y = src[srcOff + 1]; - src_C1_x = src[srcOff + 2]; - src_C1_y = src[srcOff + 3]; - src_C2_x = src[srcOff + 4]; - src_C2_y = src[srcOff + 5]; - right_P2_x = src[srcOff + 6]; - right_P2_y = src[srcOff + 7]; - - left_C1_x = (left_P1_x + src_C1_x) / 2; - left_C1_y = (left_P1_y + src_C1_y) / 2; - right_C2_x = (right_P2_x + src_C2_x) / 2; - right_C2_y = (right_P2_y + src_C2_y) / 2; - Mid_x = (src_C1_x + src_C2_x) / 2; - Mid_y = (src_C1_y + src_C2_y) / 2; - left_C2_x = (left_C1_x + Mid_x) / 2; - left_C2_y = (left_C1_y + Mid_y) / 2; - right_C1_x = (Mid_x + right_C2_x) / 2; - right_C1_y = (Mid_y + right_C2_y) / 2; - Mid_x = (left_C2_x + right_C1_x) / 2; - Mid_y = (left_C2_y + right_C1_y) / 2; - - if (left != null) - { - left[leftOff] = left_P1_x; - left[leftOff + 1] = left_P1_y; - left[leftOff + 2] = left_C1_x; - left[leftOff + 3] = left_C1_y; - left[leftOff + 4] = left_C2_x; - left[leftOff + 5] = left_C2_y; - left[leftOff + 6] = Mid_x; - left[leftOff + 7] = Mid_y; - } - - if (right != null) - { - right[rightOff] = Mid_x; - right[rightOff + 1] = Mid_y; - right[rightOff + 2] = right_C1_x; - right[rightOff + 3] = right_C1_y; - right[rightOff + 4] = right_C2_x; - right[rightOff + 5] = right_C2_y; - right[rightOff + 6] = right_P2_x; - right[rightOff + 7] = right_P2_y; - } - } - - /** - * Finds the non-complex roots of a cubic equation, placing the - * results into the same array as the equation coefficients. The - * following equation is being solved: - * - * <blockquote><code>eqn[3]</code> · <i>x</i><sup>3</sup> - * + <code>eqn[2]</code> · <i>x</i><sup>2</sup> - * + <code>eqn[1]</code> · <i>x</i> - * + <code>eqn[0]</code> - * = 0 - * </blockquote> - * - * <p>For some background about solving cubic equations, see the - * article <a - * href="http://planetmath.org/encyclopedia/CubicFormula.html" - * >“Cubic Formula”</a> in <a - * href="http://planetmath.org/" >PlanetMath</a>. For an extensive - * library of numerical algorithms written in the C programming - * language, see the <a href= "http://www.gnu.org/software/gsl/">GNU - * Scientific Library</a>, from which this implementation was - * adapted. - * - * @param eqn an array with the coefficients of the equation. When - * this procedure has returned, <code>eqn</code> will contain the - * non-complex solutions of the equation, in no particular order. - * - * @return the number of non-complex solutions. A result of 0 - * indicates that the equation has no non-complex solutions. A - * result of -1 indicates that the equation is constant (i.e., - * always or never zero). - * - * @see #solveCubic(double[], double[]) - * @see QuadCurve2D#solveQuadratic(double[],double[]) - * - * @author Brian Gough (bjg@network-theory.com) - * (original C implementation in the <a href= - * "http://www.gnu.org/software/gsl/">GNU Scientific Library</a>) - * - * @author Sascha Brawer (brawer@dandelis.ch) - * (adaptation to Java) - */ - public static int solveCubic(double[] eqn) - { - return solveCubic(eqn, eqn); - } - - /** - * Finds the non-complex roots of a cubic equation. The following - * equation is being solved: - * - * <blockquote><code>eqn[3]</code> · <i>x</i><sup>3</sup> - * + <code>eqn[2]</code> · <i>x</i><sup>2</sup> - * + <code>eqn[1]</code> · <i>x</i> - * + <code>eqn[0]</code> - * = 0 - * </blockquote> - * - * <p>For some background about solving cubic equations, see the - * article <a - * href="http://planetmath.org/encyclopedia/CubicFormula.html" - * >“Cubic Formula”</a> in <a - * href="http://planetmath.org/" >PlanetMath</a>. For an extensive - * library of numerical algorithms written in the C programming - * language, see the <a href= "http://www.gnu.org/software/gsl/">GNU - * Scientific Library</a>, from which this implementation was - * adapted. - * - * @see QuadCurve2D#solveQuadratic(double[],double[]) - * - * @param eqn an array with the coefficients of the equation. - * - * @param res an array into which the non-complex roots will be - * stored. The results may be in an arbitrary order. It is safe to - * pass the same array object reference for both <code>eqn</code> - * and <code>res</code>. - * - * @return the number of non-complex solutions. A result of 0 - * indicates that the equation has no non-complex solutions. A - * result of -1 indicates that the equation is constant (i.e., - * always or never zero). - * - * @author Brian Gough (bjg@network-theory.com) - * (original C implementation in the <a href= - * "http://www.gnu.org/software/gsl/">GNU Scientific Library</a>) - * - * @author Sascha Brawer (brawer@dandelis.ch) - * (adaptation to Java) - */ - public static int solveCubic(double[] eqn, double[] res) - { - // Adapted from poly/solve_cubic.c in the GNU Scientific Library - // (GSL), revision 1.7 of 2003-07-26. For the original source, see - // http://www.gnu.org/software/gsl/ - // - // Brian Gough, the author of that code, has granted the - // permission to use it in GNU Classpath under the GNU Classpath - // license, and has assigned the copyright to the Free Software - // Foundation. - // - // The Java implementation is very similar to the GSL code, but - // not a strict one-to-one copy. For example, GSL would sort the - // result. - - double a; - double b; - double c; - double q; - double r; - double Q; - double R; - double c3; - double Q3; - double R2; - double CR2; - double CQ3; - - // If the cubic coefficient is zero, we have a quadratic equation. - c3 = eqn[3]; - if (c3 == 0) - return QuadCurve2D.solveQuadratic(eqn, res); - - // Divide the equation by the cubic coefficient. - c = eqn[0] / c3; - b = eqn[1] / c3; - a = eqn[2] / c3; - - // We now need to solve x^3 + ax^2 + bx + c = 0. - q = a * a - 3 * b; - r = 2 * a * a * a - 9 * a * b + 27 * c; - - Q = q / 9; - R = r / 54; - - Q3 = Q * Q * Q; - R2 = R * R; - - CR2 = 729 * r * r; - CQ3 = 2916 * q * q * q; - - if (R == 0 && Q == 0) - { - // The GNU Scientific Library would return three identical - // solutions in this case. - res[0] = -a / 3; - return 1; - } - - if (CR2 == CQ3) - { - /* this test is actually R2 == Q3, written in a form suitable - for exact computation with integers */ - /* Due to finite precision some double roots may be missed, and - considered to be a pair of complex roots z = x +/- epsilon i - close to the real axis. */ - double sqrtQ = Math.sqrt(Q); - - if (R > 0) - { - res[0] = -2 * sqrtQ - a / 3; - res[1] = sqrtQ - a / 3; - } - else - { - res[0] = -sqrtQ - a / 3; - res[1] = 2 * sqrtQ - a / 3; - } - return 2; - } - - if (CR2 < CQ3) /* equivalent to R2 < Q3 */ - { - double sqrtQ = Math.sqrt(Q); - double sqrtQ3 = sqrtQ * sqrtQ * sqrtQ; - double theta = Math.acos(R / sqrtQ3); - double norm = -2 * sqrtQ; - res[0] = norm * Math.cos(theta / 3) - a / 3; - res[1] = norm * Math.cos((theta + 2.0 * Math.PI) / 3) - a / 3; - res[2] = norm * Math.cos((theta - 2.0 * Math.PI) / 3) - a / 3; - - // The GNU Scientific Library sorts the results. We don't. - return 3; - } - - double sgnR = (R >= 0 ? 1 : -1); - double A = -sgnR * Math.pow(Math.abs(R) + Math.sqrt(R2 - Q3), 1.0 / 3.0); - double B = Q / A; - res[0] = A + B - a / 3; - return 1; - } - - /** - * Determines whether a position lies inside the area bounded - * by the curve and the straight line connecting its end points. - * - * <p><img src="doc-files/CubicCurve2D-5.png" width="350" height="180" - * alt="A drawing of the area spanned by the curve" /> - * - * <p>The above drawing illustrates in which area points are - * considered “inside” a CubicCurve2D. - */ - public boolean contains(double x, double y) - { - if (! getBounds2D().contains(x, y)) - return false; - - return ((getAxisIntersections(x, y, true, BIG_VALUE) & 1) != 0); - } - - /** - * Determines whether a point lies inside the area bounded - * by the curve and the straight line connecting its end points. - * - * <p><img src="doc-files/CubicCurve2D-5.png" width="350" height="180" - * alt="A drawing of the area spanned by the curve" /> - * - * <p>The above drawing illustrates in which area points are - * considered “inside” a CubicCurve2D. - */ - public boolean contains(Point2D p) - { - return contains(p.getX(), p.getY()); - } - - /** - * Determines whether any part of a rectangle is inside the area bounded - * by the curve and the straight line connecting its end points. - * - * <p><img src="doc-files/CubicCurve2D-5.png" width="350" height="180" - * alt="A drawing of the area spanned by the curve" /> - * - * <p>The above drawing illustrates in which area points are - * considered “inside” in a CubicCurve2D. - * @see #contains(double, double) - */ - public boolean intersects(double x, double y, double w, double h) - { - if (! getBounds2D().contains(x, y, w, h)) - return false; - - /* Does any edge intersect? */ - if (getAxisIntersections(x, y, true, w) != 0 /* top */ - || getAxisIntersections(x, y + h, true, w) != 0 /* bottom */ - || getAxisIntersections(x + w, y, false, h) != 0 /* right */ - || getAxisIntersections(x, y, false, h) != 0) /* left */ - return true; - - /* No intersections, is any point inside? */ - if ((getAxisIntersections(x, y, true, BIG_VALUE) & 1) != 0) - return true; - - return false; - } - - /** - * Determines whether any part of a Rectangle2D is inside the area bounded - * by the curve and the straight line connecting its end points. - * @see #intersects(double, double, double, double) - */ - public boolean intersects(Rectangle2D r) - { - return intersects(r.getX(), r.getY(), r.getWidth(), r.getHeight()); - } - - /** - * Determine whether a rectangle is entirely inside the area that is bounded - * by the curve and the straight line connecting its end points. - * - * <p><img src="doc-files/CubicCurve2D-5.png" width="350" height="180" - * alt="A drawing of the area spanned by the curve" /> - * - * <p>The above drawing illustrates in which area points are - * considered “inside” a CubicCurve2D. - * @see #contains(double, double) - */ - public boolean contains(double x, double y, double w, double h) - { - if (! getBounds2D().intersects(x, y, w, h)) - return false; - - /* Does any edge intersect? */ - if (getAxisIntersections(x, y, true, w) != 0 /* top */ - || getAxisIntersections(x, y + h, true, w) != 0 /* bottom */ - || getAxisIntersections(x + w, y, false, h) != 0 /* right */ - || getAxisIntersections(x, y, false, h) != 0) /* left */ - return false; - - /* No intersections, is any point inside? */ - if ((getAxisIntersections(x, y, true, BIG_VALUE) & 1) != 0) - return true; - - return false; - } - - /** - * Determine whether a Rectangle2D is entirely inside the area that is - * bounded by the curve and the straight line connecting its end points. - * - * <p><img src="doc-files/CubicCurve2D-5.png" width="350" height="180" - * alt="A drawing of the area spanned by the curve" /> - * - * <p>The above drawing illustrates in which area points are - * considered “inside” a CubicCurve2D. - * @see #contains(double, double) - */ - public boolean contains(Rectangle2D r) - { - return contains(r.getX(), r.getY(), r.getWidth(), r.getHeight()); - } - - /** - * Determines the smallest rectangle that encloses the - * curve’s start, end and control points. - */ - public Rectangle getBounds() - { - return getBounds2D().getBounds(); - } - - public PathIterator getPathIterator(final AffineTransform at) - { - return new PathIterator() - { - /** Current coordinate. */ - private int current = 0; - - public int getWindingRule() - { - return WIND_NON_ZERO; - } - - public boolean isDone() - { - return current >= 2; - } - - public void next() - { - current++; - } - - public int currentSegment(float[] coords) - { - int result; - switch (current) - { - case 0: - coords[0] = (float) getX1(); - coords[1] = (float) getY1(); - result = SEG_MOVETO; - break; - case 1: - coords[0] = (float) getCtrlX1(); - coords[1] = (float) getCtrlY1(); - coords[2] = (float) getCtrlX2(); - coords[3] = (float) getCtrlY2(); - coords[4] = (float) getX2(); - coords[5] = (float) getY2(); - result = SEG_CUBICTO; - break; - default: - throw new NoSuchElementException("cubic iterator out of bounds"); - } - if (at != null) - at.transform(coords, 0, coords, 0, 3); - return result; - } - - public int currentSegment(double[] coords) - { - int result; - switch (current) - { - case 0: - coords[0] = getX1(); - coords[1] = getY1(); - result = SEG_MOVETO; - break; - case 1: - coords[0] = getCtrlX1(); - coords[1] = getCtrlY1(); - coords[2] = getCtrlX2(); - coords[3] = getCtrlY2(); - coords[4] = getX2(); - coords[5] = getY2(); - result = SEG_CUBICTO; - break; - default: - throw new NoSuchElementException("cubic iterator out of bounds"); - } - if (at != null) - at.transform(coords, 0, coords, 0, 3); - return result; - } - }; - } - - public PathIterator getPathIterator(AffineTransform at, double flatness) - { - return new FlatteningPathIterator(getPathIterator(at), flatness); - } - - /** - * Create a new curve with the same contents as this one. - * - * @return the clone. - */ - public Object clone() - { - try - { - return super.clone(); - } - catch (CloneNotSupportedException e) - { - throw (Error) new InternalError().initCause(e); // Impossible - } - } - - /** - * Helper method used by contains() and intersects() methods, that - * returns the number of curve/line intersections on a given axis - * extending from a certain point. - * - * @param x x coordinate of the origin point - * @param y y coordinate of the origin point - * @param useYaxis axis used, if true the positive Y axis is used, - * false uses the positive X axis. - * - * This is an implementation of the line-crossings algorithm, - * Detailed in an article on Eric Haines' page: - * http://www.acm.org/tog/editors/erich/ptinpoly/ - * - * A special-case not adressed in this code is self-intersections - * of the curve, e.g. if the axis intersects the self-itersection, - * the degenerate roots of the polynomial will erroneously count as - * a single intersection of the curve, and not two. - */ - private int getAxisIntersections(double x, double y, boolean useYaxis, - double distance) - { - int nCrossings = 0; - double a0; - double a1; - double a2; - double a3; - double b0; - double b1; - double b2; - double b3; - double[] r = new double[4]; - int nRoots; - - a0 = a3 = 0.0; - - if (useYaxis) - { - a0 = getY1() - y; - a1 = getCtrlY1() - y; - a2 = getCtrlY2() - y; - a3 = getY2() - y; - b0 = getX1() - x; - b1 = getCtrlX1() - x; - b2 = getCtrlX2() - x; - b3 = getX2() - x; - } - else - { - a0 = getX1() - x; - a1 = getCtrlX1() - x; - a2 = getCtrlX2() - x; - a3 = getX2() - x; - b0 = getY1() - y; - b1 = getCtrlY1() - y; - b2 = getCtrlY2() - y; - b3 = getY2() - y; - } - - /* If the axis intersects a start/endpoint, shift it up by some small - amount to guarantee the line is 'inside' - If this is not done, bad behaviour may result for points on that axis.*/ - if (a0 == 0.0 || a3 == 0.0) - { - double small = getFlatness() * EPSILON; - if (a0 == 0.0) - a0 -= small; - if (a3 == 0.0) - a3 -= small; - } - - if (useYaxis) - { - if (Line2D.linesIntersect(b0, a0, b3, a3, EPSILON, 0.0, distance, 0.0)) - nCrossings++; - } - else - { - if (Line2D.linesIntersect(a0, b0, a3, b3, 0.0, EPSILON, 0.0, distance)) - nCrossings++; - } - - r[0] = a0; - r[1] = 3 * (a1 - a0); - r[2] = 3 * (a2 + a0 - 2 * a1); - r[3] = a3 - 3 * a2 + 3 * a1 - a0; - - if ((nRoots = solveCubic(r)) != 0) - for (int i = 0; i < nRoots; i++) - { - double t = r[i]; - if (t >= 0.0 && t <= 1.0) - { - double crossing = -(t * t * t) * (b0 - 3 * b1 + 3 * b2 - b3) - + 3 * t * t * (b0 - 2 * b1 + b2) - + 3 * t * (b1 - b0) + b0; - if (crossing > 0.0 && crossing <= distance) - nCrossings++; - } - } - - return (nCrossings); - } - - /** - * A two-dimensional curve that is parameterized with a cubic - * function and stores coordinate values in double-precision - * floating-point format. - * - * @see CubicCurve2D.Float - * - * @author Eric Blake (ebb9@email.byu.edu) - * @author Sascha Brawer (brawer@dandelis.ch) - */ - public static class Double extends CubicCurve2D - { - /** - * The <i>x</i> coordinate of the curve’s start point. - */ - public double x1; - - /** - * The <i>y</i> coordinate of the curve’s start point. - */ - public double y1; - - /** - * The <i>x</i> coordinate of the curve’s first control point. - */ - public double ctrlx1; - - /** - * The <i>y</i> coordinate of the curve’s first control point. - */ - public double ctrly1; - - /** - * The <i>x</i> coordinate of the curve’s second control point. - */ - public double ctrlx2; - - /** - * The <i>y</i> coordinate of the curve’s second control point. - */ - public double ctrly2; - - /** - * The <i>x</i> coordinate of the curve’s end point. - */ - public double x2; - - /** - * The <i>y</i> coordinate of the curve’s end point. - */ - public double y2; - - /** - * Constructs a new CubicCurve2D that stores its coordinate values - * in double-precision floating-point format. All points are - * initially at position (0, 0). - */ - public Double() - { - } - - /** - * Constructs a new CubicCurve2D that stores its coordinate values - * in double-precision floating-point format, specifying the - * initial position of each point. - * - * <p><img src="doc-files/CubicCurve2D-1.png" width="350" height="180" - * alt="A drawing of a CubicCurve2D" /> - * - * @param x1 the <i>x</i> coordinate of the curve’s start - * point. - * - * @param y1 the <i>y</i> coordinate of the curve’s start - * point. - * - * @param cx1 the <i>x</i> coordinate of the curve’s first - * control point. - * - * @param cy1 the <i>y</i> coordinate of the curve’s first - * control point. - * - * @param cx2 the <i>x</i> coordinate of the curve’s second - * control point. - * - * @param cy2 the <i>y</i> coordinate of the curve’s second - * control point. - * - * @param x2 the <i>x</i> coordinate of the curve’s end - * point. - * - * @param y2 the <i>y</i> coordinate of the curve’s end - * point. - */ - public Double(double x1, double y1, double cx1, double cy1, double cx2, - double cy2, double x2, double y2) - { - this.x1 = x1; - this.y1 = y1; - ctrlx1 = cx1; - ctrly1 = cy1; - ctrlx2 = cx2; - ctrly2 = cy2; - this.x2 = x2; - this.y2 = y2; - } - - /** - * Returns the <i>x</i> coordinate of the curve’s start - * point. - */ - public double getX1() - { - return x1; - } - - /** - * Returns the <i>y</i> coordinate of the curve’s start - * point. - */ - public double getY1() - { - return y1; - } - - /** - * Returns the curve’s start point. - */ - public Point2D getP1() - { - return new Point2D.Double(x1, y1); - } - - /** - * Returns the <i>x</i> coordinate of the curve’s first - * control point. - */ - public double getCtrlX1() - { - return ctrlx1; - } - - /** - * Returns the <i>y</i> coordinate of the curve’s first - * control point. - */ - public double getCtrlY1() - { - return ctrly1; - } - - /** - * Returns the curve’s first control point. - */ - public Point2D getCtrlP1() - { - return new Point2D.Double(ctrlx1, ctrly1); - } - - /** - * Returns the <i>x</i> coordinate of the curve’s second - * control point. - */ - public double getCtrlX2() - { - return ctrlx2; - } - - /** - * Returns the <i>y</i> coordinate of the curve’s second - * control point. - */ - public double getCtrlY2() - { - return ctrly2; - } - - /** - * Returns the curve’s second control point. - */ - public Point2D getCtrlP2() - { - return new Point2D.Double(ctrlx2, ctrly2); - } - - /** - * Returns the <i>x</i> coordinate of the curve’s end - * point. - */ - public double getX2() - { - return x2; - } - - /** - * Returns the <i>y</i> coordinate of the curve’s end - * point. - */ - public double getY2() - { - return y2; - } - - /** - * Returns the curve’s end point. - */ - public Point2D getP2() - { - return new Point2D.Double(x2, y2); - } - - /** - * Changes the curve geometry, separately specifying each coordinate - * value. - * - * <p><img src="doc-files/CubicCurve2D-1.png" width="350" height="180" - * alt="A drawing of a CubicCurve2D" /> - * - * @param x1 the <i>x</i> coordinate of the curve’s new start - * point. - * - * @param y1 the <i>y</i> coordinate of the curve’s new start - * point. - * - * @param cx1 the <i>x</i> coordinate of the curve’s new - * first control point. - * - * @param cy1 the <i>y</i> coordinate of the curve’s new - * first control point. - * - * @param cx2 the <i>x</i> coordinate of the curve’s new - * second control point. - * - * @param cy2 the <i>y</i> coordinate of the curve’s new - * second control point. - * - * @param x2 the <i>x</i> coordinate of the curve’s new end - * point. - * - * @param y2 the <i>y</i> coordinate of the curve’s new end - * point. - */ - public void setCurve(double x1, double y1, double cx1, double cy1, - double cx2, double cy2, double x2, double y2) - { - this.x1 = x1; - this.y1 = y1; - ctrlx1 = cx1; - ctrly1 = cy1; - ctrlx2 = cx2; - ctrly2 = cy2; - this.x2 = x2; - this.y2 = y2; - } - - /** - * Determines the smallest rectangle that encloses the - * curve’s start, end and control points. As the - * illustration below shows, the invisible control points may cause - * the bounds to be much larger than the area that is actually - * covered by the curve. - * - * <p><img src="doc-files/CubicCurve2D-2.png" width="350" height="180" - * alt="An illustration of the bounds of a CubicCurve2D" /> - */ - public Rectangle2D getBounds2D() - { - double nx1 = Math.min(Math.min(x1, ctrlx1), Math.min(ctrlx2, x2)); - double ny1 = Math.min(Math.min(y1, ctrly1), Math.min(ctrly2, y2)); - double nx2 = Math.max(Math.max(x1, ctrlx1), Math.max(ctrlx2, x2)); - double ny2 = Math.max(Math.max(y1, ctrly1), Math.max(ctrly2, y2)); - return new Rectangle2D.Double(nx1, ny1, nx2 - nx1, ny2 - ny1); - } - } - - /** - * A two-dimensional curve that is parameterized with a cubic - * function and stores coordinate values in single-precision - * floating-point format. - * - * @see CubicCurve2D.Float - * - * @author Eric Blake (ebb9@email.byu.edu) - * @author Sascha Brawer (brawer@dandelis.ch) - */ - public static class Float extends CubicCurve2D - { - /** - * The <i>x</i> coordinate of the curve’s start point. - */ - public float x1; - - /** - * The <i>y</i> coordinate of the curve’s start point. - */ - public float y1; - - /** - * The <i>x</i> coordinate of the curve’s first control point. - */ - public float ctrlx1; - - /** - * The <i>y</i> coordinate of the curve’s first control point. - */ - public float ctrly1; - - /** - * The <i>x</i> coordinate of the curve’s second control point. - */ - public float ctrlx2; - - /** - * The <i>y</i> coordinate of the curve’s second control point. - */ - public float ctrly2; - - /** - * The <i>x</i> coordinate of the curve’s end point. - */ - public float x2; - - /** - * The <i>y</i> coordinate of the curve’s end point. - */ - public float y2; - - /** - * Constructs a new CubicCurve2D that stores its coordinate values - * in single-precision floating-point format. All points are - * initially at position (0, 0). - */ - public Float() - { - } - - /** - * Constructs a new CubicCurve2D that stores its coordinate values - * in single-precision floating-point format, specifying the - * initial position of each point. - * - * <p><img src="doc-files/CubicCurve2D-1.png" width="350" height="180" - * alt="A drawing of a CubicCurve2D" /> - * - * @param x1 the <i>x</i> coordinate of the curve’s start - * point. - * - * @param y1 the <i>y</i> coordinate of the curve’s start - * point. - * - * @param cx1 the <i>x</i> coordinate of the curve’s first - * control point. - * - * @param cy1 the <i>y</i> coordinate of the curve’s first - * control point. - * - * @param cx2 the <i>x</i> coordinate of the curve’s second - * control point. - * - * @param cy2 the <i>y</i> coordinate of the curve’s second - * control point. - * - * @param x2 the <i>x</i> coordinate of the curve’s end - * point. - * - * @param y2 the <i>y</i> coordinate of the curve’s end - * point. - */ - public Float(float x1, float y1, float cx1, float cy1, float cx2, - float cy2, float x2, float y2) - { - this.x1 = x1; - this.y1 = y1; - ctrlx1 = cx1; - ctrly1 = cy1; - ctrlx2 = cx2; - ctrly2 = cy2; - this.x2 = x2; - this.y2 = y2; - } - - /** - * Returns the <i>x</i> coordinate of the curve’s start - * point. - */ - public double getX1() - { - return x1; - } - - /** - * Returns the <i>y</i> coordinate of the curve’s start - * point. - */ - public double getY1() - { - return y1; - } - - /** - * Returns the curve’s start point. - */ - public Point2D getP1() - { - return new Point2D.Float(x1, y1); - } - - /** - * Returns the <i>x</i> coordinate of the curve’s first - * control point. - */ - public double getCtrlX1() - { - return ctrlx1; - } - - /** - * Returns the <i>y</i> coordinate of the curve’s first - * control point. - */ - public double getCtrlY1() - { - return ctrly1; - } - - /** - * Returns the curve’s first control point. - */ - public Point2D getCtrlP1() - { - return new Point2D.Float(ctrlx1, ctrly1); - } - - /** - * Returns the <i>s</i> coordinate of the curve’s second - * control point. - */ - public double getCtrlX2() - { - return ctrlx2; - } - - /** - * Returns the <i>y</i> coordinate of the curve’s second - * control point. - */ - public double getCtrlY2() - { - return ctrly2; - } - - /** - * Returns the curve’s second control point. - */ - public Point2D getCtrlP2() - { - return new Point2D.Float(ctrlx2, ctrly2); - } - - /** - * Returns the <i>x</i> coordinate of the curve’s end - * point. - */ - public double getX2() - { - return x2; - } - - /** - * Returns the <i>y</i> coordinate of the curve’s end - * point. - */ - public double getY2() - { - return y2; - } - - /** - * Returns the curve’s end point. - */ - public Point2D getP2() - { - return new Point2D.Float(x2, y2); - } - - /** - * Changes the curve geometry, separately specifying each coordinate - * value as a double-precision floating-point number. - * - * <p><img src="doc-files/CubicCurve2D-1.png" width="350" height="180" - * alt="A drawing of a CubicCurve2D" /> - * - * @param x1 the <i>x</i> coordinate of the curve’s new start - * point. - * - * @param y1 the <i>y</i> coordinate of the curve’s new start - * point. - * - * @param cx1 the <i>x</i> coordinate of the curve’s new - * first control point. - * - * @param cy1 the <i>y</i> coordinate of the curve’s new - * first control point. - * - * @param cx2 the <i>x</i> coordinate of the curve’s new - * second control point. - * - * @param cy2 the <i>y</i> coordinate of the curve’s new - * second control point. - * - * @param x2 the <i>x</i> coordinate of the curve’s new end - * point. - * - * @param y2 the <i>y</i> coordinate of the curve’s new end - * point. - */ - public void setCurve(double x1, double y1, double cx1, double cy1, - double cx2, double cy2, double x2, double y2) - { - this.x1 = (float) x1; - this.y1 = (float) y1; - ctrlx1 = (float) cx1; - ctrly1 = (float) cy1; - ctrlx2 = (float) cx2; - ctrly2 = (float) cy2; - this.x2 = (float) x2; - this.y2 = (float) y2; - } - - /** - * Changes the curve geometry, separately specifying each coordinate - * value as a single-precision floating-point number. - * - * <p><img src="doc-files/CubicCurve2D-1.png" width="350" height="180" - * alt="A drawing of a CubicCurve2D" /> - * - * @param x1 the <i>x</i> coordinate of the curve’s new start - * point. - * - * @param y1 the <i>y</i> coordinate of the curve’s new start - * point. - * - * @param cx1 the <i>x</i> coordinate of the curve’s new - * first control point. - * - * @param cy1 the <i>y</i> coordinate of the curve’s new - * first control point. - * - * @param cx2 the <i>x</i> coordinate of the curve’s new - * second control point. - * - * @param cy2 the <i>y</i> coordinate of the curve’s new - * second control point. - * - * @param x2 the <i>x</i> coordinate of the curve’s new end - * point. - * - * @param y2 the <i>y</i> coordinate of the curve’s new end - * point. - */ - public void setCurve(float x1, float y1, float cx1, float cy1, float cx2, - float cy2, float x2, float y2) - { - this.x1 = x1; - this.y1 = y1; - ctrlx1 = cx1; - ctrly1 = cy1; - ctrlx2 = cx2; - ctrly2 = cy2; - this.x2 = x2; - this.y2 = y2; - } - - /** - * Determines the smallest rectangle that encloses the - * curve’s start, end and control points. As the - * illustration below shows, the invisible control points may cause - * the bounds to be much larger than the area that is actually - * covered by the curve. - * - * <p><img src="doc-files/CubicCurve2D-2.png" width="350" height="180" - * alt="An illustration of the bounds of a CubicCurve2D" /> - */ - public Rectangle2D getBounds2D() - { - float nx1 = (float) Math.min(Math.min(x1, ctrlx1), Math.min(ctrlx2, x2)); - float ny1 = (float) Math.min(Math.min(y1, ctrly1), Math.min(ctrly2, y2)); - float nx2 = (float) Math.max(Math.max(x1, ctrlx1), Math.max(ctrlx2, x2)); - float ny2 = (float) Math.max(Math.max(y1, ctrly1), Math.max(ctrly2, y2)); - return new Rectangle2D.Float(nx1, ny1, nx2 - nx1, ny2 - ny1); - } - } -} diff --git a/libjava/java/awt/geom/Dimension2D.java b/libjava/java/awt/geom/Dimension2D.java deleted file mode 100644 index 6b5ce8830a9..00000000000 --- a/libjava/java/awt/geom/Dimension2D.java +++ /dev/null @@ -1,118 +0,0 @@ -/* Dimension2D.java -- abstraction of a dimension - Copyright (C) 1999, 2000, 2002 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.geom; - -/** - * This stores a dimension in 2-dimensional space - a width (along the x-axis) - * and height (along the y-axis). The storage is left to subclasses. - * - * @author Per Bothner (bothner@cygnus.com) - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.2 - * @status updated to 1.4 - */ -public abstract class Dimension2D implements Cloneable -{ - /** - * The default constructor. - */ - protected Dimension2D() - { - } - - /** - * Get the width of this dimension. A negative result, while legal, is - * undefined in meaning. - * - * @return the width - */ - public abstract double getWidth(); - - /** - * Get the height of this dimension. A negative result, while legal, is - * undefined in meaning. - * - * @return the height - */ - public abstract double getHeight(); - - /** - * Set the size of this dimension to the requested values. Loss of precision - * may occur. - * - * @param w the new width - * @param h the new height - */ - public abstract void setSize(double w, double h); - - /** - * Set the size of this dimension to the requested value. Loss of precision - * may occur. - * - * @param d the dimension containing the new values - * - * @throws NullPointerException if d is null - */ - public void setSize(Dimension2D d) - { - setSize(d.getWidth(), d.getHeight()); - } - - /** - * Create a new dimension of the same run-time type with the same contents - * as this one. - * - * @return the clone - * - * @exception OutOfMemoryError If there is not enough memory available. - * - * @since 1.2 - */ - public Object clone() - { - try - { - return super.clone(); - } - catch (CloneNotSupportedException e) - { - throw (Error) new InternalError().initCause(e); // Impossible - } - } -} // class Dimension2D diff --git a/libjava/java/awt/geom/Ellipse2D.java b/libjava/java/awt/geom/Ellipse2D.java deleted file mode 100644 index e8830770f60..00000000000 --- a/libjava/java/awt/geom/Ellipse2D.java +++ /dev/null @@ -1,413 +0,0 @@ -/* Ellipse2D.java -- represents an ellipse in 2-D space - Copyright (C) 2000, 2002, 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.awt.geom; - - -/** - * Ellipse2D is the shape of an ellipse. - * <BR> - * <img src="doc-files/Ellipse-1.png" width="347" height="221" - * alt="A drawing of an ellipse" /><BR> - * The ellipse is defined by it's bounding box (shown in red), - * and is defined by the implicit curve:<BR> - * <blockquote>(<i>x</i>/<i>a</i>)<sup>2</sup> + - * (<i>y</i>/<i>b</i>)<sup>2</sup> = 1<BR><BR></blockquote> - * - * @author Tom Tromey (tromey@cygnus.com) - * @author Eric Blake (ebb9@email.byu.edu) - * - * @since 1.2 - */ -public abstract class Ellipse2D extends RectangularShape -{ - /** - * Ellipse2D is defined as abstract. - * Implementing classes are Ellipse2D.Float and Ellipse2D.Double. - */ - protected Ellipse2D() - { - } - - /** - * Determines if a point is contained within the ellipse. <P> - * @param x - x coordinate of the point. - * @param y - y coordinate of the point. - * @return true if the point is within the ellipse, false otherwise. - */ - public boolean contains(double x, double y) - { - double rx = getWidth() / 2; - double ry = getHeight() / 2; - double tx = (x - (getX() + rx)) / rx; - double ty = (y - (getY() + ry)) / ry; - return tx * tx + ty * ty < 1.0; - } - - /** - * Determines if a rectangle is completely contained within the - * ellipse. <P> - * @param x - x coordinate of the upper-left corner of the rectangle - * @param y - y coordinate of the upper-left corner of the rectangle - * @param w - width of the rectangle - * @param h - height of the rectangle - * @return true if the rectangle is completely contained, false otherwise. - */ - public boolean contains(double x, double y, double w, double h) - { - double x2 = x + w; - double y2 = y + h; - return (contains(x, y) && contains(x, y2) && contains(x2, y) - && contains(x2, y2)); - } - - /** - * Returns a PathIterator object corresponding to the ellipse.<P> - * - * Note: An ellipse cannot be represented exactly in PathIterator - * segments, the outline is thefore approximated with cubic - * Bezier segments. - * - * @param at an optional transform. - * @return A path iterator. - */ - public PathIterator getPathIterator(AffineTransform at) - { - // An ellipse is just a complete arc. - return new Arc2D.ArcIterator(this, at); - } - - /** - * Determines if a rectangle intersects any part of the ellipse.<P> - * @param x - x coordinate of the upper-left corner of the rectangle - * @param y - y coordinate of the upper-left corner of the rectangle - * @param w - width of the rectangle - * @param h - height of the rectangle - * @return true if the rectangle intersects the ellipse, false otherwise. - */ - public boolean intersects(double x, double y, double w, double h) - { - Rectangle2D r = new Rectangle2D.Double(x, y, w, h); - if (! r.intersects(getX(), getY(), getWidth(), getHeight())) - return false; - - if (contains(x, y) || contains(x, y + h) || contains(x + w, y) - || contains(x + w, y + h)) - return true; - - Line2D l1 = new Line2D.Double(getX(), getY() + (getHeight() / 2), - getX() + getWidth(), - getY() + (getHeight() / 2)); - Line2D l2 = new Line2D.Double(getX() + (getWidth() / 2), getY(), - getX() + (getWidth() / 2), - getY() + getHeight()); - - if (l1.intersects(r) || l2.intersects(r)) - return true; - - return false; - } - - /** - * An {@link Ellipse2D} that stores its coordinates using <code>double</code> - * primitives. - */ - public static class Double extends Ellipse2D - { - /** - * The height of the ellipse. - */ - public double height; - - /** - * The width of the ellipse. - */ - public double width; - - /** - * The upper-left x coordinate of the bounding-box - */ - public double x; - - /** - * The upper-left y coordinate of the bounding-box - */ - public double y; - - /** - * Creates a new Ellipse2D with an upper-left coordinate of (0,0) - * and a zero size. - */ - public Double() - { - } - - /** - * Creates a new Ellipse2D within a given rectangle - * using double-precision coordinates.<P> - * @param x - x coordinate of the upper-left of the bounding rectangle - * @param y - y coordinate of the upper-left of the bounding rectangle - * @param w - width of the ellipse - * @param h - height of the ellipse - */ - public Double(double x, double y, double w, double h) - { - this.x = x; - this.y = y; - height = h; - width = w; - } - - /** - * Returns the bounding-box of the ellipse. - * @return The bounding box. - */ - public Rectangle2D getBounds2D() - { - return new Rectangle2D.Double(x, y, width, height); - } - - /** - * Returns the height of the ellipse. - * @return The height of the ellipse. - */ - public double getHeight() - { - return height; - } - - /** - * Returns the width of the ellipse. - * @return The width of the ellipse. - */ - public double getWidth() - { - return width; - } - - /** - * Returns x coordinate of the upper-left corner of - * the ellipse's bounding-box. - * @return The x coordinate. - */ - public double getX() - { - return x; - } - - /** - * Returns y coordinate of the upper-left corner of - * the ellipse's bounding-box. - * @return The y coordinate. - */ - public double getY() - { - return y; - } - - /** - * Returns <code>true</code> if the ellipse encloses no area, and - * <code>false</code> otherwise. - * - * @return A boolean. - */ - public boolean isEmpty() - { - return height <= 0 || width <= 0; - } - - /** - * Sets the geometry of the ellipse's bounding box.<P> - * - * @param x - x coordinate of the upper-left of the bounding rectangle - * @param y - y coordinate of the upper-left of the bounding rectangle - * @param w - width of the ellipse - * @param h - height of the ellipse - */ - public void setFrame(double x, double y, double w, double h) - { - this.x = x; - this.y = y; - height = h; - width = w; - } - } // class Double - - /** - * An {@link Ellipse2D} that stores its coordinates using <code>float</code> - * primitives. - */ - public static class Float extends Ellipse2D - { - /** - * The height of the ellipse. - */ - public float height; - - /** - * The width of the ellipse. - */ - public float width; - - /** - * The upper-left x coordinate of the bounding-box - */ - public float x; - - /** - * The upper-left y coordinate of the bounding-box - */ - public float y; - - /** - * Creates a new Ellipse2D with an upper-left coordinate of (0,0) - * and a zero size. - */ - public Float() - { - } - - /** - * Creates a new Ellipse2D within a given rectangle - * using floating-point precision.<P> - * @param x - x coordinate of the upper-left of the bounding rectangle - * @param y - y coordinate of the upper-left of the bounding rectangle - * @param w - width of the ellipse - * @param h - height of the ellipse - * - */ - public Float(float x, float y, float w, float h) - { - this.x = x; - this.y = y; - this.height = h; - this.width = w; - } - - /** - * Returns the bounding-box of the ellipse. - * @return The bounding box. - */ - public Rectangle2D getBounds2D() - { - return new Rectangle2D.Float(x, y, width, height); - } - - /** - * Returns the height of the ellipse. - * @return The height of the ellipse. - */ - public double getHeight() - { - return height; - } - - /** - * Returns the width of the ellipse. - * @return The width of the ellipse. - */ - public double getWidth() - { - return width; - } - - /** - * Returns x coordinate of the upper-left corner of - * the ellipse's bounding-box. - * @return The x coordinate. - */ - public double getX() - { - return x; - } - - /** - * Returns y coordinate of the upper-left corner of - * the ellipse's bounding-box. - * @return The y coordinate. - */ - public double getY() - { - return y; - } - - /** - * Returns <code>true</code> if the ellipse encloses no area, and - * <code>false</code> otherwise. - * - * @return A boolean. - */ - public boolean isEmpty() - { - return height <= 0 || width <= 0; - } - - /** - * Sets the geometry of the ellipse's bounding box.<P> - * - * @param x - x coordinate of the upper-left of the bounding rectangle - * @param y - y coordinate of the upper-left of the bounding rectangle - * @param w - width of the ellipse - * @param h - height of the ellipse - */ - public void setFrame(float x, float y, float w, float h) - { - this.x = x; - this.y = y; - height = h; - width = w; - } - - /** - * Sets the geometry of the ellipse's bounding box. - * - * Note: This leads to a loss of precision.<P> - * - * @param x - x coordinate of the upper-left of the bounding rectangle - * @param y - y coordinate of the upper-left of the bounding rectangle - * @param w - width of the ellipse - * @param h - height of the ellipse - */ - public void setFrame(double x, double y, double w, double h) - { - this.x = (float) x; - this.y = (float) y; - height = (float) h; - width = (float) w; - } - } // class Float -} // class Ellipse2D diff --git a/libjava/java/awt/geom/FlatteningPathIterator.java b/libjava/java/awt/geom/FlatteningPathIterator.java deleted file mode 100644 index b06e6cc47b8..00000000000 --- a/libjava/java/awt/geom/FlatteningPathIterator.java +++ /dev/null @@ -1,579 +0,0 @@ -/* FlatteningPathIterator.java -- Approximates curves by straight lines - Copyright (C) 2003 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.geom; - -import java.util.NoSuchElementException; - - -/** - * A PathIterator for approximating curved path segments by sequences - * of straight lines. Instances of this class will only return - * segments of type {@link PathIterator#SEG_MOVETO}, {@link - * PathIterator#SEG_LINETO}, and {@link PathIterator#SEG_CLOSE}. - * - * <p>The accuracy of the approximation is determined by two - * parameters: - * - * <ul><li>The <i>flatness</i> is a threshold value for deciding when - * a curved segment is consided flat enough for being approximated by - * a single straight line. Flatness is defined as the maximal distance - * of a curve control point to the straight line that connects the - * curve start and end. A lower flatness threshold means a closer - * approximation. See {@link QuadCurve2D#getFlatness()} and {@link - * CubicCurve2D#getFlatness()} for drawings which illustrate the - * meaning of flatness.</li> - * - * <li>The <i>recursion limit</i> imposes an upper bound for how often - * a curved segment gets subdivided. A limit of <i>n</i> means that - * for each individual quadratic and cubic Bézier spline - * segment, at most 2<sup><small><i>n</i></small></sup> {@link - * PathIterator#SEG_LINETO} segments will be created.</li></ul> - * - * <p><b>Memory Efficiency:</b> The memory consumption grows linearly - * with the recursion limit. Neither the <i>flatness</i> parameter nor - * the number of segments in the flattened path will affect the memory - * consumption. - * - * <p><b>Thread Safety:</b> Multiple threads can safely work on - * separate instances of this class. However, multiple threads should - * not concurrently access the same instance, as no synchronization is - * performed. - * - * @see <a href="doc-files/FlatteningPathIterator-1.html" - * >Implementation Note</a> - * - * @author Sascha Brawer (brawer@dandelis.ch) - * - * @since 1.2 - */ -public class FlatteningPathIterator - implements PathIterator -{ - /** - * The PathIterator whose curved segments are being approximated. - */ - private final PathIterator srcIter; - - - /** - * The square of the flatness threshold value, which determines when - * a curve segment is considered flat enough that no further - * subdivision is needed. - * - * <p>Calculating flatness actually produces the squared flatness - * value. To avoid the relatively expensive calculation of a square - * root for each curve segment, we perform all flatness comparisons - * on squared values. - * - * @see QuadCurve2D#getFlatnessSq() - * @see CubicCurve2D#getFlatnessSq() - */ - private final double flatnessSq; - - - /** - * The maximal number of subdivions that are performed to - * approximate a quadratic or cubic curve segment. - */ - private final int recursionLimit; - - - /** - * A stack for holding the coordinates of subdivided segments. - * - * @see <a href="doc-files/FlatteningPathIterator-1.html" - * >Implementation Note</a> - */ - private double[] stack; - - - /** - * The current stack size. - * - * @see <a href="doc-files/FlatteningPathIterator-1.html" - * >Implementation Note</a> - */ - private int stackSize; - - - /** - * The number of recursions that were performed to arrive at - * a segment on the stack. - * - * @see <a href="doc-files/FlatteningPathIterator-1.html" - * >Implementation Note</a> - */ - private int[] recLevel; - - - - private final double[] scratch = new double[6]; - - - /** - * The segment type of the last segment that was returned by - * the source iterator. - */ - private int srcSegType; - - - /** - * The current <i>x</i> position of the source iterator. - */ - private double srcPosX; - - - /** - * The current <i>y</i> position of the source iterator. - */ - private double srcPosY; - - - /** - * A flag that indicates when this path iterator has finished its - * iteration over path segments. - */ - private boolean done; - - - /** - * Constructs a new PathIterator for approximating an input - * PathIterator with straight lines. The approximation works by - * recursive subdivisons, until the specified flatness threshold is - * not exceeded. - * - * <p>There will not be more than 10 nested recursion steps, which - * means that a single <code>SEG_QUADTO</code> or - * <code>SEG_CUBICTO</code> segment is approximated by at most - * 2<sup><small>10</small></sup> = 1024 straight lines. - */ - public FlatteningPathIterator(PathIterator src, double flatness) - { - this(src, flatness, 10); - } - - - /** - * Constructs a new PathIterator for approximating an input - * PathIterator with straight lines. The approximation works by - * recursive subdivisons, until the specified flatness threshold is - * not exceeded. Additionally, the number of recursions is also - * bound by the specified recursion limit. - */ - public FlatteningPathIterator(PathIterator src, double flatness, - int limit) - { - if (flatness < 0 || limit < 0) - throw new IllegalArgumentException(); - - srcIter = src; - flatnessSq = flatness * flatness; - recursionLimit = limit; - fetchSegment(); - } - - - /** - * Returns the maximally acceptable flatness. - * - * @see QuadCurve2D#getFlatness() - * @see CubicCurve2D#getFlatness() - */ - public double getFlatness() - { - return Math.sqrt(flatnessSq); - } - - - /** - * Returns the maximum number of recursive curve subdivisions. - */ - public int getRecursionLimit() - { - return recursionLimit; - } - - - // Documentation will be copied from PathIterator. - public int getWindingRule() - { - return srcIter.getWindingRule(); - } - - - // Documentation will be copied from PathIterator. - public boolean isDone() - { - return done; - } - - - // Documentation will be copied from PathIterator. - public void next() - { - if (stackSize > 0) - { - --stackSize; - if (stackSize > 0) - { - switch (srcSegType) - { - case PathIterator.SEG_QUADTO: - subdivideQuadratic(); - return; - - case PathIterator.SEG_CUBICTO: - subdivideCubic(); - return; - - default: - throw new IllegalStateException(); - } - } - } - - srcIter.next(); - fetchSegment(); - } - - - // Documentation will be copied from PathIterator. - public int currentSegment(double[] coords) - { - if (done) - throw new NoSuchElementException(); - - switch (srcSegType) - { - case PathIterator.SEG_CLOSE: - return srcSegType; - - case PathIterator.SEG_MOVETO: - case PathIterator.SEG_LINETO: - coords[0] = srcPosX; - coords[1] = srcPosY; - return srcSegType; - - case PathIterator.SEG_QUADTO: - if (stackSize == 0) - { - coords[0] = srcPosX; - coords[1] = srcPosY; - } - else - { - int sp = stack.length - 4 * stackSize; - coords[0] = stack[sp + 2]; - coords[1] = stack[sp + 3]; - } - return PathIterator.SEG_LINETO; - - case PathIterator.SEG_CUBICTO: - if (stackSize == 0) - { - coords[0] = srcPosX; - coords[1] = srcPosY; - } - else - { - int sp = stack.length - 6 * stackSize; - coords[0] = stack[sp + 4]; - coords[1] = stack[sp + 5]; - } - return PathIterator.SEG_LINETO; - } - - throw new IllegalStateException(); - } - - - // Documentation will be copied from PathIterator. - public int currentSegment(float[] coords) - { - if (done) - throw new NoSuchElementException(); - - switch (srcSegType) - { - case PathIterator.SEG_CLOSE: - return srcSegType; - - case PathIterator.SEG_MOVETO: - case PathIterator.SEG_LINETO: - coords[0] = (float) srcPosX; - coords[1] = (float) srcPosY; - return srcSegType; - - case PathIterator.SEG_QUADTO: - if (stackSize == 0) - { - coords[0] = (float) srcPosX; - coords[1] = (float) srcPosY; - } - else - { - int sp = stack.length - 4 * stackSize; - coords[0] = (float) stack[sp + 2]; - coords[1] = (float) stack[sp + 3]; - } - return PathIterator.SEG_LINETO; - - case PathIterator.SEG_CUBICTO: - if (stackSize == 0) - { - coords[0] = (float) srcPosX; - coords[1] = (float) srcPosY; - } - else - { - int sp = stack.length - 6 * stackSize; - coords[0] = (float) stack[sp + 4]; - coords[1] = (float) stack[sp + 5]; - } - return PathIterator.SEG_LINETO; - } - - throw new IllegalStateException(); - } - - - /** - * Fetches the next segment from the source iterator. - */ - private void fetchSegment() - { - int sp; - - if (srcIter.isDone()) - { - done = true; - return; - } - - srcSegType = srcIter.currentSegment(scratch); - - switch (srcSegType) - { - case PathIterator.SEG_CLOSE: - return; - - case PathIterator.SEG_MOVETO: - case PathIterator.SEG_LINETO: - srcPosX = scratch[0]; - srcPosY = scratch[1]; - return; - - case PathIterator.SEG_QUADTO: - if (recursionLimit == 0) - { - srcPosX = scratch[2]; - srcPosY = scratch[3]; - stackSize = 0; - return; - } - sp = 4 * recursionLimit; - stackSize = 1; - if (stack == null) - { - stack = new double[sp + /* 4 + 2 */ 6]; - recLevel = new int[recursionLimit + 1]; - } - recLevel[0] = 0; - stack[sp] = srcPosX; // P1.x - stack[sp + 1] = srcPosY; // P1.y - stack[sp + 2] = scratch[0]; // C.x - stack[sp + 3] = scratch[1]; // C.y - srcPosX = stack[sp + 4] = scratch[2]; // P2.x - srcPosY = stack[sp + 5] = scratch[3]; // P2.y - subdivideQuadratic(); - break; - - case PathIterator.SEG_CUBICTO: - if (recursionLimit == 0) - { - srcPosX = scratch[4]; - srcPosY = scratch[5]; - stackSize = 0; - return; - } - sp = 6 * recursionLimit; - stackSize = 1; - if ((stack == null) || (stack.length < sp + 8)) - { - stack = new double[sp + /* 6 + 2 */ 8]; - recLevel = new int[recursionLimit + 1]; - } - recLevel[0] = 0; - stack[sp] = srcPosX; // P1.x - stack[sp + 1] = srcPosY; // P1.y - stack[sp + 2] = scratch[0]; // C1.x - stack[sp + 3] = scratch[1]; // C1.y - stack[sp + 4] = scratch[2]; // C2.x - stack[sp + 5] = scratch[3]; // C2.y - srcPosX = stack[sp + 6] = scratch[4]; // P2.x - srcPosY = stack[sp + 7] = scratch[5]; // P2.y - subdivideCubic(); - return; - } - } - - - /** - * Repeatedly subdivides the quadratic curve segment that is on top - * of the stack. The iteration terminates when the recursion limit - * has been reached, or when the resulting segment is flat enough. - */ - private void subdivideQuadratic() - { - int sp; - int level; - - sp = stack.length - 4 * stackSize - 2; - level = recLevel[stackSize - 1]; - while ((level < recursionLimit) - && (QuadCurve2D.getFlatnessSq(stack, sp) >= flatnessSq)) - { - recLevel[stackSize] = recLevel[stackSize - 1] = ++level; - QuadCurve2D.subdivide(stack, sp, stack, sp - 4, stack, sp); - ++stackSize; - sp -= 4; - } - } - - - /** - * Repeatedly subdivides the cubic curve segment that is on top - * of the stack. The iteration terminates when the recursion limit - * has been reached, or when the resulting segment is flat enough. - */ - private void subdivideCubic() - { - int sp; - int level; - - sp = stack.length - 6 * stackSize - 2; - level = recLevel[stackSize - 1]; - while ((level < recursionLimit) - && (CubicCurve2D.getFlatnessSq(stack, sp) >= flatnessSq)) - { - recLevel[stackSize] = recLevel[stackSize - 1] = ++level; - - CubicCurve2D.subdivide(stack, sp, stack, sp - 6, stack, sp); - ++stackSize; - sp -= 6; - } - } - - - /* These routines were useful for debugging. Since they would - * just bloat the implementation, they are commented out. - * - * - - private static String segToString(int segType, double[] d, int offset) - { - String s; - - switch (segType) - { - case PathIterator.SEG_CLOSE: - return "SEG_CLOSE"; - - case PathIterator.SEG_MOVETO: - return "SEG_MOVETO (" + d[offset] + ", " + d[offset + 1] + ")"; - - case PathIterator.SEG_LINETO: - return "SEG_LINETO (" + d[offset] + ", " + d[offset + 1] + ")"; - - case PathIterator.SEG_QUADTO: - return "SEG_QUADTO (" + d[offset] + ", " + d[offset + 1] - + ") (" + d[offset + 2] + ", " + d[offset + 3] + ")"; - - case PathIterator.SEG_CUBICTO: - return "SEG_CUBICTO (" + d[offset] + ", " + d[offset + 1] - + ") (" + d[offset + 2] + ", " + d[offset + 3] - + ") (" + d[offset + 4] + ", " + d[offset + 5] + ")"; - } - - throw new IllegalStateException(); - } - - - private void dumpQuadraticStack(String msg) - { - int sp = stack.length - 4 * stackSize - 2; - int i = 0; - System.err.print(" " + msg + ":"); - while (sp < stack.length) - { - System.err.print(" (" + stack[sp] + ", " + stack[sp+1] + ")"); - if (i < recLevel.length) - System.out.print("/" + recLevel[i++]); - if (sp + 3 < stack.length) - System.err.print(" [" + stack[sp+2] + ", " + stack[sp+3] + "]"); - sp += 4; - } - System.err.println(); - } - - - private void dumpCubicStack(String msg) - { - int sp = stack.length - 6 * stackSize - 2; - int i = 0; - System.err.print(" " + msg + ":"); - while (sp < stack.length) - { - System.err.print(" (" + stack[sp] + ", " + stack[sp+1] + ")"); - if (i < recLevel.length) - System.out.print("/" + recLevel[i++]); - if (sp + 3 < stack.length) - { - System.err.print(" [" + stack[sp+2] + ", " + stack[sp+3] + "]"); - System.err.print(" [" + stack[sp+4] + ", " + stack[sp+5] + "]"); - } - sp += 6; - } - System.err.println(); - } - - * - * - */ -} diff --git a/libjava/java/awt/geom/GeneralPath.java b/libjava/java/awt/geom/GeneralPath.java deleted file mode 100644 index f54855874dc..00000000000 --- a/libjava/java/awt/geom/GeneralPath.java +++ /dev/null @@ -1,958 +0,0 @@ -/* GeneralPath.java -- represents a shape built from subpaths - Copyright (C) 2002, 2003, 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.geom; - -import java.awt.Rectangle; -import java.awt.Shape; - - -/** - * A general geometric path, consisting of any number of subpaths - * constructed out of straight lines and cubic or quadratic Bezier - * curves. - * - * <p>The inside of the curve is defined for drawing purposes by a winding - * rule. Either the WIND_EVEN_ODD or WIND_NON_ZERO winding rule can be chosen. - * - * <p><img src="doc-files/GeneralPath-1.png" width="300" height="210" - * alt="A drawing of a GeneralPath" /> - * <p>The EVEN_ODD winding rule defines a point as inside a path if: - * A ray from the point towards infinity in an arbitrary direction - * intersects the path an odd number of times. Points <b>A</b> and - * <b>C</b> in the image are considered to be outside the path. - * (both intersect twice) - * Point <b>B</b> intersects once, and is inside. - * - * <p>The NON_ZERO winding rule defines a point as inside a path if: - * The path intersects the ray in an equal number of opposite directions. - * Point <b>A</b> in the image is outside (one intersection in the - * ’up’ - * direction, one in the ’down’ direction) Point <b>B</b> in - * the image is inside (one intersection ’down’) - * Point <b>C</b> in the image is outside (two intersections - * ’down’) - * - * @see Line2D - * @see CubicCurve2D - * @see QuadCurve2D - * - * @author Sascha Brawer (brawer@dandelis.ch) - * @author Sven de Marothy (sven@physto.se) - * - * @since 1.2 - */ -public final class GeneralPath implements Shape, Cloneable -{ - public static final int WIND_EVEN_ODD = PathIterator.WIND_EVEN_ODD; - public static final int WIND_NON_ZERO = PathIterator.WIND_NON_ZERO; - - /** Initial size if not specified. */ - private static final int INIT_SIZE = 10; - - /** A big number, but not so big it can't survive a few float operations */ - private static final double BIG_VALUE = java.lang.Double.MAX_VALUE / 10.0; - - /** The winding rule. - * This is package-private to avoid an accessor method. - */ - int rule; - - /** - * The path type in points. Note that xpoints[index] and ypoints[index] maps - * to types[index]; the control points of quad and cubic paths map as - * well but are ignored. - * This is package-private to avoid an accessor method. - */ - byte[] types; - - /** - * The list of all points seen. Since you can only append floats, it makes - * sense for these to be float[]. I have no idea why Sun didn't choose to - * allow a general path of double precision points. - * Note: Storing x and y coords seperately makes for a slower transforms, - * But it speeds up and simplifies box-intersection checking a lot. - * These are package-private to avoid accessor methods. - */ - float[] xpoints; - float[] ypoints; - - /** The index of the most recent moveto point, or null. */ - private int subpath = -1; - - /** The next available index into points. - * This is package-private to avoid an accessor method. - */ - int index; - - /** - * Constructs a GeneralPath with the default (NON_ZERO) - * winding rule and initial capacity (20). - */ - public GeneralPath() - { - this(WIND_NON_ZERO, INIT_SIZE); - } - - /** - * Constructs a GeneralPath with a specific winding rule - * and the default initial capacity (20). - * @param rule the winding rule (WIND_NON_ZERO or WIND_EVEN_ODD) - */ - public GeneralPath(int rule) - { - this(rule, INIT_SIZE); - } - - /** - * Constructs a GeneralPath with a specific winding rule - * and the initial capacity. The initial capacity should be - * the approximate number of path segments to be used. - * @param rule the winding rule (WIND_NON_ZERO or WIND_EVEN_ODD) - * @param capacity the inital capacity, in path segments - */ - public GeneralPath(int rule, int capacity) - { - if (rule != WIND_EVEN_ODD && rule != WIND_NON_ZERO) - throw new IllegalArgumentException(); - this.rule = rule; - if (capacity < INIT_SIZE) - capacity = INIT_SIZE; - types = new byte[capacity]; - xpoints = new float[capacity]; - ypoints = new float[capacity]; - } - - /** - * Constructs a GeneralPath from an arbitrary shape object. - * The Shapes PathIterator path and winding rule will be used. - * @param s the shape - */ - public GeneralPath(Shape s) - { - types = new byte[INIT_SIZE]; - xpoints = new float[INIT_SIZE]; - ypoints = new float[INIT_SIZE]; - PathIterator pi = s.getPathIterator(null); - setWindingRule(pi.getWindingRule()); - append(pi, false); - } - - /** - * Adds a new point to a path. - */ - public void moveTo(float x, float y) - { - subpath = index; - ensureSize(index + 1); - types[index] = PathIterator.SEG_MOVETO; - xpoints[index] = x; - ypoints[index++] = y; - } - - /** - * Appends a straight line to the current path. - * @param x x coordinate of the line endpoint. - * @param y y coordinate of the line endpoint. - */ - public void lineTo(float x, float y) - { - ensureSize(index + 1); - types[index] = PathIterator.SEG_LINETO; - xpoints[index] = x; - ypoints[index++] = y; - } - - /** - * Appends a quadratic Bezier curve to the current path. - * @param x1 x coordinate of the control point - * @param y1 y coordinate of the control point - * @param x2 x coordinate of the curve endpoint. - * @param y2 y coordinate of the curve endpoint. - */ - public void quadTo(float x1, float y1, float x2, float y2) - { - ensureSize(index + 2); - types[index] = PathIterator.SEG_QUADTO; - xpoints[index] = x1; - ypoints[index++] = y1; - xpoints[index] = x2; - ypoints[index++] = y2; - } - - /** - * Appends a cubic Bezier curve to the current path. - * @param x1 x coordinate of the first control point - * @param y1 y coordinate of the first control point - * @param x2 x coordinate of the second control point - * @param y2 y coordinate of the second control point - * @param x3 x coordinate of the curve endpoint. - * @param y3 y coordinate of the curve endpoint. - */ - public void curveTo(float x1, float y1, float x2, float y2, float x3, - float y3) - { - ensureSize(index + 3); - types[index] = PathIterator.SEG_CUBICTO; - xpoints[index] = x1; - ypoints[index++] = y1; - xpoints[index] = x2; - ypoints[index++] = y2; - xpoints[index] = x3; - ypoints[index++] = y3; - } - - /** - * Closes the current subpath by drawing a line - * back to the point of the last moveTo. - */ - public void closePath() - { - ensureSize(index + 1); - types[index] = PathIterator.SEG_CLOSE; - xpoints[index] = xpoints[subpath]; - ypoints[index++] = ypoints[subpath]; - } - - /** - * Appends the segments of a Shape to the path. If <code>connect</code> is - * true, the new path segments are connected to the existing one with a line. - * The winding rule of the Shape is ignored. - */ - public void append(Shape s, boolean connect) - { - append(s.getPathIterator(null), connect); - } - - /** - * Appends the segments of a PathIterator to this GeneralPath. - * Optionally, the initial {@link PathIterator#SEG_MOVETO} segment - * of the appended path is changed into a {@link - * PathIterator#SEG_LINETO} segment. - * - * @param iter the PathIterator specifying which segments shall be - * appended. - * - * @param connect <code>true</code> for substituting the initial - * {@link PathIterator#SEG_MOVETO} segment by a {@link - * PathIterator#SEG_LINETO}, or <code>false</code> for not - * performing any substitution. If this GeneralPath is currently - * empty, <code>connect</code> is assumed to be <code>false</code>, - * thus leaving the initial {@link PathIterator#SEG_MOVETO} - * unchanged. - */ - public void append(PathIterator iter, boolean connect) - { - // A bad implementation of this method had caused Classpath bug #6076. - float[] f = new float[6]; - while (! iter.isDone()) - { - switch (iter.currentSegment(f)) - { - case PathIterator.SEG_MOVETO: - if (! connect || (index == 0)) - { - moveTo(f[0], f[1]); - break; - } - if ((index >= 1) && (types[index - 1] == PathIterator.SEG_CLOSE) - && (f[0] == xpoints[index - 1]) - && (f[1] == ypoints[index - 1])) - break; - - // Fall through. - case PathIterator.SEG_LINETO: - lineTo(f[0], f[1]); - break; - case PathIterator.SEG_QUADTO: - quadTo(f[0], f[1], f[2], f[3]); - break; - case PathIterator.SEG_CUBICTO: - curveTo(f[0], f[1], f[2], f[3], f[4], f[5]); - break; - case PathIterator.SEG_CLOSE: - closePath(); - break; - } - - connect = false; - iter.next(); - } - } - - /** - * Returns the path’s current winding rule. - */ - public int getWindingRule() - { - return rule; - } - - /** - * Sets the path’s winding rule, which controls which areas are - * considered ’inside’ or ’outside’ the path - * on drawing. Valid rules are WIND_EVEN_ODD for an even-odd winding rule, - * or WIND_NON_ZERO for a non-zero winding rule. - */ - public void setWindingRule(int rule) - { - if (rule != WIND_EVEN_ODD && rule != WIND_NON_ZERO) - throw new IllegalArgumentException(); - this.rule = rule; - } - - /** - * Returns the current appending point of the path. - */ - public Point2D getCurrentPoint() - { - if (subpath < 0) - return null; - return new Point2D.Float(xpoints[index - 1], ypoints[index - 1]); - } - - /** - * Resets the path. All points and segments are destroyed. - */ - public void reset() - { - subpath = -1; - index = 0; - } - - /** - * Applies a transform to the path. - */ - public void transform(AffineTransform xform) - { - double nx; - double ny; - double[] m = new double[6]; - xform.getMatrix(m); - for (int i = 0; i < index; i++) - { - nx = m[0] * xpoints[i] + m[2] * ypoints[i] + m[4]; - ny = m[1] * xpoints[i] + m[3] * ypoints[i] + m[5]; - xpoints[i] = (float) nx; - ypoints[i] = (float) ny; - } - } - - /** - * Creates a transformed version of the path. - * @param xform the transform to apply - * @return a new transformed GeneralPath - */ - public Shape createTransformedShape(AffineTransform xform) - { - GeneralPath p = new GeneralPath(this); - p.transform(xform); - return p; - } - - /** - * Returns the path’s bounding box. - */ - public Rectangle getBounds() - { - return getBounds2D().getBounds(); - } - - /** - * Returns the path’s bounding box, in <code>float</code> precision - */ - public Rectangle2D getBounds2D() - { - float x1; - float y1; - float x2; - float y2; - - if (index > 0) - { - x1 = x2 = xpoints[0]; - y1 = y2 = ypoints[0]; - } - else - x1 = x2 = y1 = y2 = 0.0f; - - for (int i = 0; i < index; i++) - { - x1 = Math.min(xpoints[i], x1); - y1 = Math.min(ypoints[i], y1); - x2 = Math.max(xpoints[i], x2); - y2 = Math.max(ypoints[i], y2); - } - return (new Rectangle2D.Float(x1, y1, x2 - x1, y2 - y1)); - } - - /** - * Evaluates if a point is within the GeneralPath, - * The NON_ZERO winding rule is used, regardless of the - * set winding rule. - * @param x x coordinate of the point to evaluate - * @param y y coordinate of the point to evaluate - * @return true if the point is within the path, false otherwise - */ - public boolean contains(double x, double y) - { - return (getWindingNumber(x, y) != 0); - } - - /** - * Evaluates if a Point2D is within the GeneralPath, - * The NON_ZERO winding rule is used, regardless of the - * set winding rule. - * @param p The Point2D to evaluate - * @return true if the point is within the path, false otherwise - */ - public boolean contains(Point2D p) - { - return contains(p.getX(), p.getY()); - } - - /** - * Evaluates if a rectangle is completely contained within the path. - * This method will return false in the cases when the box - * intersects an inner segment of the path. - * (i.e.: The method is accurate for the EVEN_ODD winding rule) - */ - public boolean contains(double x, double y, double w, double h) - { - if (! getBounds2D().intersects(x, y, w, h)) - return false; - - /* Does any edge intersect? */ - if (getAxisIntersections(x, y, false, w) != 0 /* top */ - || getAxisIntersections(x, y + h, false, w) != 0 /* bottom */ - || getAxisIntersections(x + w, y, true, h) != 0 /* right */ - || getAxisIntersections(x, y, true, h) != 0) /* left */ - return false; - - /* No intersections, is any point inside? */ - if (getWindingNumber(x, y) != 0) - return true; - - return false; - } - - /** - * Evaluates if a rectangle is completely contained within the path. - * This method will return false in the cases when the box - * intersects an inner segment of the path. - * (i.e.: The method is accurate for the EVEN_ODD winding rule) - * @param r the rectangle - * @return <code>true</code> if the rectangle is completely contained - * within the path, <code>false</code> otherwise - */ - public boolean contains(Rectangle2D r) - { - return contains(r.getX(), r.getY(), r.getWidth(), r.getHeight()); - } - - /** - * Evaluates if a rectangle intersects the path. - * @param x x coordinate of the rectangle - * @param y y coordinate of the rectangle - * @param w width of the rectangle - * @param h height of the rectangle - * @return <code>true</code> if the rectangle intersects the path, - * <code>false</code> otherwise - */ - public boolean intersects(double x, double y, double w, double h) - { - /* Does any edge intersect? */ - if (getAxisIntersections(x, y, false, w) != 0 /* top */ - || getAxisIntersections(x, y + h, false, w) != 0 /* bottom */ - || getAxisIntersections(x + w, y, true, h) != 0 /* right */ - || getAxisIntersections(x, y, true, h) != 0) /* left */ - return true; - - /* No intersections, is any point inside? */ - if (getWindingNumber(x, y) != 0) - return true; - - return false; - } - - /** - * Evaluates if a Rectangle2D intersects the path. - * @param r The rectangle - * @return <code>true</code> if the rectangle intersects the path, - * <code>false</code> otherwise - */ - public boolean intersects(Rectangle2D r) - { - return intersects(r.getX(), r.getY(), r.getWidth(), r.getHeight()); - } - - /** - * A PathIterator that iterates over the segments of a GeneralPath. - * - * @author Sascha Brawer (brawer@dandelis.ch) - */ - private static class GeneralPathIterator implements PathIterator - { - /** - * The number of coordinate values for each segment type. - */ - private static final int[] NUM_COORDS = { - /* 0: SEG_MOVETO */ 1, - /* 1: SEG_LINETO */ 1, - /* 2: SEG_QUADTO */ 2, - /* 3: SEG_CUBICTO */ 3, - /* 4: SEG_CLOSE */ 0}; - - /** - * The GeneralPath whose segments are being iterated. - * This is package-private to avoid an accessor method. - */ - final GeneralPath path; - - /** - * The affine transformation used to transform coordinates. - */ - private final AffineTransform transform; - - /** - * The current position of the iterator. - */ - private int pos; - - /** - * Constructs a new iterator for enumerating the segments of a - * GeneralPath. - * - * @param at an affine transformation for projecting the returned - * points, or <code>null</code> to return the original points - * without any mapping. - */ - GeneralPathIterator(GeneralPath path, AffineTransform transform) - { - this.path = path; - this.transform = transform; - } - - /** - * Returns the current winding rule of the GeneralPath. - */ - public int getWindingRule() - { - return path.rule; - } - - /** - * Determines whether the iterator has reached the last segment in - * the path. - */ - public boolean isDone() - { - return pos >= path.index; - } - - /** - * Advances the iterator position by one segment. - */ - public void next() - { - int seg; - - /* - * Increment pos by the number of coordinate pairs. - */ - seg = path.types[pos]; - if (seg == SEG_CLOSE) - pos++; - else - pos += NUM_COORDS[seg]; - } - - /** - * Returns the current segment in float coordinates. - */ - public int currentSegment(float[] coords) - { - int seg; - int numCoords; - - seg = path.types[pos]; - numCoords = NUM_COORDS[seg]; - if (numCoords > 0) - { - for (int i = 0; i < numCoords; i++) - { - coords[i << 1] = path.xpoints[pos + i]; - coords[(i << 1) + 1] = path.ypoints[pos + i]; - } - - if (transform != null) - transform.transform( /* src */ - coords, /* srcOffset */ - 0, /* dest */ coords, /* destOffset */ - 0, /* numPoints */ numCoords); - } - return seg; - } - - /** - * Returns the current segment in double coordinates. - */ - public int currentSegment(double[] coords) - { - int seg; - int numCoords; - - seg = path.types[pos]; - numCoords = NUM_COORDS[seg]; - if (numCoords > 0) - { - for (int i = 0; i < numCoords; i++) - { - coords[i << 1] = (double) path.xpoints[pos + i]; - coords[(i << 1) + 1] = (double) path.ypoints[pos + i]; - } - if (transform != null) - transform.transform( /* src */ - coords, /* srcOffset */ - 0, /* dest */ coords, /* destOffset */ - 0, /* numPoints */ numCoords); - } - return seg; - } - } - - /** - * Creates a PathIterator for iterating along the segments of the path. - * - * @param at an affine transformation for projecting the returned - * points, or <code>null</code> to let the created iterator return - * the original points without any mapping. - */ - public PathIterator getPathIterator(AffineTransform at) - { - return new GeneralPathIterator(this, at); - } - - /** - * Creates a new FlatteningPathIterator for the path - */ - public PathIterator getPathIterator(AffineTransform at, double flatness) - { - return new FlatteningPathIterator(getPathIterator(at), flatness); - } - - /** - * Creates a new shape of the same run-time type with the same contents - * as this one. - * - * @return the clone - * - * @exception OutOfMemoryError If there is not enough memory available. - * - * @since 1.2 - */ - public Object clone() - { - // This class is final; no need to use super.clone(). - return new GeneralPath(this); - } - - /** - * Helper method - ensure the size of the data arrays, - * otherwise, reallocate new ones twice the size - */ - private void ensureSize(int size) - { - if (subpath < 0) - throw new IllegalPathStateException("need initial moveto"); - if (size <= xpoints.length) - return; - byte[] b = new byte[types.length << 1]; - System.arraycopy(types, 0, b, 0, index); - types = b; - float[] f = new float[xpoints.length << 1]; - System.arraycopy(xpoints, 0, f, 0, index); - xpoints = f; - f = new float[ypoints.length << 1]; - System.arraycopy(ypoints, 0, f, 0, index); - ypoints = f; - } - - /** - * Helper method - Get the total number of intersections from (x,y) along - * a given axis, within a given distance. - */ - private int getAxisIntersections(double x, double y, boolean useYaxis, - double distance) - { - return (evaluateCrossings(x, y, false, useYaxis, distance)); - } - - /** - * Helper method - returns the winding number of a point. - */ - private int getWindingNumber(double x, double y) - { - /* Evaluate the crossings from x,y to infinity on the y axis (arbitrary - choice). Note that we don't actually use Double.INFINITY, since that's - slower, and may cause problems. */ - return (evaluateCrossings(x, y, true, true, BIG_VALUE)); - } - - /** - * Helper method - evaluates the number of intersections on an axis from - * the point (x,y) to the point (x,y+distance) or (x+distance,y). - * @param x x coordinate. - * @param y y coordinate. - * @param neg True if opposite-directed intersections should cancel, - * false to sum all intersections. - * @param useYaxis Use the Y axis, false uses the X axis. - * @param distance Interval from (x,y) on the selected axis to find - * intersections. - */ - private int evaluateCrossings(double x, double y, boolean neg, - boolean useYaxis, double distance) - { - float cx = 0.0f; - float cy = 0.0f; - float firstx = 0.0f; - float firsty = 0.0f; - - int negative = (neg) ? -1 : 1; - double x0; - double x1; - double x2; - double x3; - double y0; - double y1; - double y2; - double y3; - double[] r = new double[4]; - int nRoots; - double epsilon = 0.0; - int pos = 0; - int windingNumber = 0; - boolean pathStarted = false; - - if (index == 0) - return (0); - if (useYaxis) - { - float[] swap1; - swap1 = ypoints; - ypoints = xpoints; - xpoints = swap1; - double swap2; - swap2 = y; - y = x; - x = swap2; - } - - /* Get a value which is hopefully small but not insignificant relative - the path. */ - epsilon = ypoints[0] * 1E-7; - - if(epsilon == 0) - epsilon = 1E-7; - - pos = 0; - while (pos < index) - { - switch (types[pos]) - { - case PathIterator.SEG_MOVETO: - if (pathStarted) // close old path - { - x0 = cx; - y0 = cy; - x1 = firstx; - y1 = firsty; - - if (y0 == 0.0) - y0 -= epsilon; - if (y1 == 0.0) - y1 -= epsilon; - if (Line2D.linesIntersect(x0, y0, x1, y1, - epsilon, 0.0, distance, 0.0)) - windingNumber += (y1 < y0) ? 1 : negative; - - cx = firstx; - cy = firsty; - } - cx = firstx = xpoints[pos] - (float) x; - cy = firsty = ypoints[pos++] - (float) y; - pathStarted = true; - break; - case PathIterator.SEG_CLOSE: - x0 = cx; - y0 = cy; - x1 = firstx; - y1 = firsty; - - if (y0 == 0.0) - y0 -= epsilon; - if (y1 == 0.0) - y1 -= epsilon; - if (Line2D.linesIntersect(x0, y0, x1, y1, - epsilon, 0.0, distance, 0.0)) - windingNumber += (y1 < y0) ? 1 : negative; - - cx = firstx; - cy = firsty; - pos++; - pathStarted = false; - break; - case PathIterator.SEG_LINETO: - x0 = cx; - y0 = cy; - x1 = xpoints[pos] - (float) x; - y1 = ypoints[pos++] - (float) y; - - if (y0 == 0.0) - y0 -= epsilon; - if (y1 == 0.0) - y1 -= epsilon; - if (Line2D.linesIntersect(x0, y0, x1, y1, - epsilon, 0.0, distance, 0.0)) - windingNumber += (y1 < y0) ? 1 : negative; - - cx = xpoints[pos - 1] - (float) x; - cy = ypoints[pos - 1] - (float) y; - break; - case PathIterator.SEG_QUADTO: - x0 = cx; - y0 = cy; - x1 = xpoints[pos] - x; - y1 = ypoints[pos++] - y; - x2 = xpoints[pos] - x; - y2 = ypoints[pos++] - y; - - /* check if curve may intersect X+ axis. */ - if ((x0 > 0.0 || x1 > 0.0 || x2 > 0.0) - && (y0 * y1 <= 0 || y1 * y2 <= 0)) - { - if (y0 == 0.0) - y0 -= epsilon; - if (y2 == 0.0) - y2 -= epsilon; - - r[0] = y0; - r[1] = 2 * (y1 - y0); - r[2] = (y2 - 2 * y1 + y0); - - /* degenerate roots (=tangent points) do not - contribute to the winding number. */ - if ((nRoots = QuadCurve2D.solveQuadratic(r)) == 2) - for (int i = 0; i < nRoots; i++) - { - float t = (float) r[i]; - if (t > 0.0f && t < 1.0f) - { - double crossing = t * t * (x2 - 2 * x1 + x0) - + 2 * t * (x1 - x0) + x0; - if (crossing >= 0.0 && crossing <= distance) - windingNumber += (2 * t * (y2 - 2 * y1 + y0) - + 2 * (y1 - y0) < 0) ? 1 : negative; - } - } - } - - cx = xpoints[pos - 1] - (float) x; - cy = ypoints[pos - 1] - (float) y; - break; - case PathIterator.SEG_CUBICTO: - x0 = cx; - y0 = cy; - x1 = xpoints[pos] - x; - y1 = ypoints[pos++] - y; - x2 = xpoints[pos] - x; - y2 = ypoints[pos++] - y; - x3 = xpoints[pos] - x; - y3 = ypoints[pos++] - y; - - /* check if curve may intersect X+ axis. */ - if ((x0 > 0.0 || x1 > 0.0 || x2 > 0.0 || x3 > 0.0) - && (y0 * y1 <= 0 || y1 * y2 <= 0 || y2 * y3 <= 0)) - { - if (y0 == 0.0) - y0 -= epsilon; - if (y3 == 0.0) - y3 -= epsilon; - - r[0] = y0; - r[1] = 3 * (y1 - y0); - r[2] = 3 * (y2 + y0 - 2 * y1); - r[3] = y3 - 3 * y2 + 3 * y1 - y0; - - if ((nRoots = CubicCurve2D.solveCubic(r)) != 0) - for (int i = 0; i < nRoots; i++) - { - float t = (float) r[i]; - if (t > 0.0 && t < 1.0) - { - double crossing = -(t * t * t) * (x0 - 3 * x1 - + 3 * x2 - x3) - + 3 * t * t * (x0 - 2 * x1 + x2) - + 3 * t * (x1 - x0) + x0; - if (crossing >= 0 && crossing <= distance) - windingNumber += (3 * t * t * (y3 + 3 * y1 - - 3 * y2 - y0) - + 6 * t * (y0 - 2 * y1 + y2) - + 3 * (y1 - y0) < 0) ? 1 : negative; - } - } - } - - cx = xpoints[pos - 1] - (float) x; - cy = ypoints[pos - 1] - (float) y; - break; - } - } - - // swap coordinates back - if (useYaxis) - { - float[] swap; - swap = ypoints; - ypoints = xpoints; - xpoints = swap; - } - return (windingNumber); - } -} // class GeneralPath - diff --git a/libjava/java/awt/geom/IllegalPathStateException.java b/libjava/java/awt/geom/IllegalPathStateException.java deleted file mode 100644 index 4d190c74814..00000000000 --- a/libjava/java/awt/geom/IllegalPathStateException.java +++ /dev/null @@ -1,71 +0,0 @@ -/* IllegalPathStateException.java -- an operation was in an illegal path state - Copyright (C) 2000, 2002 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.awt.geom; - -/** - * Thrown when an operation on a path is in an illegal state, such as appending - * a segment to a <code>GeneralPath</code> without an initial moveto. - * - * @author Tom Tromey (tromey@cygnus.com) - * @see GeneralPath - * @status updated to 1.4 - */ -public class IllegalPathStateException extends RuntimeException -{ - /** - * Compatible with JDK 1.2+. - */ - private static final long serialVersionUID = -5158084205220481094L; - - /** - * Create an exception with no message. - */ - public IllegalPathStateException() - { - } - - /** - * Create an exception with a message. - * - * @param msg the message - */ - public IllegalPathStateException(String msg) - { - super(msg); - } -} diff --git a/libjava/java/awt/geom/Line2D.java b/libjava/java/awt/geom/Line2D.java deleted file mode 100644 index e15e7cfe3f5..00000000000 --- a/libjava/java/awt/geom/Line2D.java +++ /dev/null @@ -1,1182 +0,0 @@ -/* Line2D.java -- represents a line in 2-D space, plus operations on a line - Copyright (C) 2000, 2001, 2002 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.awt.geom; - -import java.awt.Rectangle; -import java.awt.Shape; -import java.util.NoSuchElementException; - -/** - * Represents a directed line bewteen two points in (x,y) Cartesian space. - * Remember, on-screen graphics have increasing x from left-to-right, and - * increasing y from top-to-bottom. The storage is left to subclasses. - * - * @author Tom Tromey (tromey@cygnus.com) - * @author Eric Blake (ebb9@email.byu.edu) - * @author David Gilbert - * @since 1.2 - * @status updated to 1.4 - */ -public abstract class Line2D implements Shape, Cloneable -{ - /** - * The default constructor. - */ - protected Line2D() - { - } - - /** - * Return the x coordinate of the first point. - * - * @return the starting x coordinate - */ - public abstract double getX1(); - - /** - * Return the y coordinate of the first point. - * - * @return the starting y coordinate - */ - public abstract double getY1(); - - /** - * Return the first point. - * - * @return the starting point - */ - public abstract Point2D getP1(); - - /** - * Return the x coordinate of the second point. - * - * @return the ending x coordinate - */ - public abstract double getX2(); - - /** - * Return the y coordinate of the second point. - * - * @return the ending y coordinate - */ - public abstract double getY2(); - - /** - * Return the second point. - * - * @return the ending point - */ - public abstract Point2D getP2(); - - /** - * Set the coordinates of the line to the given coordinates. Loss of - * precision may occur due to rounding issues. - * - * @param x1 the first x coordinate - * @param y1 the first y coordinate - * @param x2 the second x coordinate - * @param y2 the second y coordinate - */ - public abstract void setLine(double x1, double y1, double x2, double y2); - - /** - * Set the coordinates to the given points. - * - * @param p1 the first point - * @param p2 the second point - * @throws NullPointerException if either point is null - */ - public void setLine(Point2D p1, Point2D p2) - { - setLine(p1.getX(), p1.getY(), p2.getX(), p2.getY()); - } - - /** - * Set the coordinates to those of the given line. - * - * @param l the line to copy - * @throws NullPointerException if l is null - */ - public void setLine(Line2D l) - { - setLine(l.getX1(), l.getY1(), l.getX2(), l.getY2()); - } - - /** - * Computes the relative rotation direction needed to pivot the line about - * the first point in order to have the second point colinear with point p. - * Because of floating point rounding, don't expect this to be a perfect - * measure of colinearity. The answer is 1 if the line has a shorter rotation - * in the direction of the positive X axis to the negative Y axis - * (counter-clockwise in the default Java coordinate system), or -1 if the - * shortest rotation is in the opposite direction (clockwise). If p - * is already colinear, the return value is -1 if it lies beyond the first - * point, 0 if it lies in the segment, or 1 if it lies beyond the second - * point. If the first and second point are coincident, this returns 0. - * - * @param x1 the first x coordinate - * @param y1 the first y coordinate - * @param x2 the second x coordinate - * @param y2 the second y coordinate - * @param px the reference x coordinate - * @param py the reference y coordinate - * @return the relative rotation direction - */ - public static int relativeCCW(double x1, double y1, double x2, double y2, - double px, double py) - { - if ((x1 == x2 && y1 == y2) - || (x1 == px && y1 == py)) - return 0; // Coincident points. - // Translate to the origin. - x2 -= x1; - y2 -= y1; - px -= x1; - py -= y1; - double slope2 = y2 / x2; - double slopep = py / px; - if (slope2 == slopep || (x2 == 0 && px == 0)) - return y2 > 0 // Colinear. - ? (py < 0 ? -1 : py > y2 ? 1 : 0) - : (py > 0 ? -1 : py < y2 ? 1 : 0); - if (x2 >= 0 && slope2 >= 0) - return px >= 0 // Quadrant 1. - ? (slope2 > slopep ? 1 : -1) - : (slope2 < slopep ? 1 : -1); - if (y2 > 0) - return px < 0 // Quadrant 2. - ? (slope2 > slopep ? 1 : -1) - : (slope2 < slopep ? 1 : -1); - if (slope2 >= 0.0) - return px >= 0 // Quadrant 3. - ? (slope2 < slopep ? 1 : -1) - : (slope2 > slopep ? 1 : -1); - return px < 0 // Quadrant 4. - ? (slope2 < slopep ? 1 : -1) - : (slope2 > slopep ? 1 : -1); - } - - /** - * Computes the relative rotation direction needed to pivot this line about - * the first point in order to have the second point colinear with point p. - * Because of floating point rounding, don't expect this to be a perfect - * measure of colinearity. The answer is 1 if the line has a shorter rotation - * in the direction of the positive X axis to the negative Y axis - * (counter-clockwise in the default Java coordinate system), or -1 if the - * shortest rotation is in the opposite direction (clockwise). If p - * is already colinear, the return value is -1 if it lies beyond the first - * point, 0 if it lies in the segment, or 1 if it lies beyond the second - * point. If the first and second point are coincident, this returns 0. - * - * @param px the reference x coordinate - * @param py the reference y coordinate - * @return the relative rotation direction - * @see #relativeCCW(double, double, double, double, double, double) - */ - public int relativeCCW(double px, double py) - { - return relativeCCW(getX1(), getY1(), getX2(), getY2(), px, py); - } - - /** - * Computes the relative rotation direction needed to pivot this line about - * the first point in order to have the second point colinear with point p. - * Because of floating point rounding, don't expect this to be a perfect - * measure of colinearity. The answer is 1 if the line has a shorter rotation - * in the direction of the positive X axis to the negative Y axis - * (counter-clockwise in the default Java coordinate system), or -1 if the - * shortest rotation is in the opposite direction (clockwise). If p - * is already colinear, the return value is -1 if it lies beyond the first - * point, 0 if it lies in the segment, or 1 if it lies beyond the second - * point. If the first and second point are coincident, this returns 0. - * - * @param p the reference point - * @return the relative rotation direction - * @throws NullPointerException if p is null - * @see #relativeCCW(double, double, double, double, double, double) - */ - public int relativeCCW(Point2D p) - { - return relativeCCW(getX1(), getY1(), getX2(), getY2(), p.getX(), p.getY()); - } - - /** - * Computes twice the (signed) area of the triangle defined by the three - * points. This method is used for intersection testing. - * - * @param x1 the x-coordinate of the first point. - * @param y1 the y-coordinate of the first point. - * @param x2 the x-coordinate of the second point. - * @param y2 the y-coordinate of the second point. - * @param x3 the x-coordinate of the third point. - * @param y3 the y-coordinate of the third point. - * - * @return Twice the area. - */ - private static double area2(double x1, double y1, - double x2, double y2, - double x3, double y3) - { - return (x2 - x1) * (y3 - y1) - (x3 - x1) * (y2 - y1); - } - - /** - * Returns <code>true</code> if (x3, y3) lies between (x1, y1) and (x2, y2), - * and false otherwise, This test assumes that the three points are - * collinear, and is used for intersection testing. - * - * @param x1 the x-coordinate of the first point. - * @param y1 the y-coordinate of the first point. - * @param x2 the x-coordinate of the second point. - * @param y2 the y-coordinate of the second point. - * @param x3 the x-coordinate of the third point. - * @param y3 the y-coordinate of the third point. - * - * @return A boolean. - */ - private static boolean between(double x1, double y1, - double x2, double y2, - double x3, double y3) - { - if (x1 != x2) { - return (x1 <= x3 && x3 <= x2) || (x1 >= x3 && x3 >= x2); - } - else { - return (y1 <= y3 && y3 <= y2) || (y1 >= y3 && y3 >= y2); - } - } - - /** - * Test if the line segment (x1,y1)->(x2,y2) intersects the line segment - * (x3,y3)->(x4,y4). - * - * @param x1 the first x coordinate of the first segment - * @param y1 the first y coordinate of the first segment - * @param x2 the second x coordinate of the first segment - * @param y2 the second y coordinate of the first segment - * @param x3 the first x coordinate of the second segment - * @param y3 the first y coordinate of the second segment - * @param x4 the second x coordinate of the second segment - * @param y4 the second y coordinate of the second segment - * @return true if the segments intersect - */ - public static boolean linesIntersect(double x1, double y1, - double x2, double y2, - double x3, double y3, - double x4, double y4) - { - double a1, a2, a3, a4; - - // deal with special cases - if ((a1 = area2(x1, y1, x2, y2, x3, y3)) == 0.0) - { - // check if p3 is between p1 and p2 OR - // p4 is collinear also AND either between p1 and p2 OR at opposite ends - if (between(x1, y1, x2, y2, x3, y3)) - { - return true; - } - else - { - if (area2(x1, y1, x2, y2, x4, y4) == 0.0) - { - return between(x3, y3, x4, y4, x1, y1) - || between (x3, y3, x4, y4, x2, y2); - } - else { - return false; - } - } - } - else if ((a2 = area2(x1, y1, x2, y2, x4, y4)) == 0.0) - { - // check if p4 is between p1 and p2 (we already know p3 is not - // collinear) - return between(x1, y1, x2, y2, x4, y4); - } - - if ((a3 = area2(x3, y3, x4, y4, x1, y1)) == 0.0) { - // check if p1 is between p3 and p4 OR - // p2 is collinear also AND either between p1 and p2 OR at opposite ends - if (between(x3, y3, x4, y4, x1, y1)) { - return true; - } - else { - if (area2(x3, y3, x4, y4, x2, y2) == 0.0) { - return between(x1, y1, x2, y2, x3, y3) - || between (x1, y1, x2, y2, x4, y4); - } - else { - return false; - } - } - } - else if ((a4 = area2(x3, y3, x4, y4, x2, y2)) == 0.0) { - // check if p2 is between p3 and p4 (we already know p1 is not - // collinear) - return between(x3, y3, x4, y4, x2, y2); - } - else { // test for regular intersection - return ((a1 > 0.0) ^ (a2 > 0.0)) && ((a3 > 0.0) ^ (a4 > 0.0)); - } - } - - /** - * Test if this line intersects the line given by (x1,y1)->(x2,y2). - * - * @param x1 the first x coordinate of the other segment - * @param y1 the first y coordinate of the other segment - * @param x2 the second x coordinate of the other segment - * @param y2 the second y coordinate of the other segment - * @return true if the segments intersect - * @see #linesIntersect(double, double, double, double, - * double, double, double, double) - */ - public boolean intersectsLine(double x1, double y1, double x2, double y2) - { - return linesIntersect(getX1(), getY1(), getX2(), getY2(), - x1, y1, x2, y2); - } - - /** - * Test if this line intersects the given line. - * - * @param l the other segment - * @return true if the segments intersect - * @throws NullPointerException if l is null - * @see #linesIntersect(double, double, double, double, - * double, double, double, double) - */ - public boolean intersectsLine(Line2D l) - { - return linesIntersect(getX1(), getY1(), getX2(), getY2(), - l.getX1(), l.getY1(), l.getX2(), l.getY2()); - } - - /** - * Measures the square of the shortest distance from the reference point - * to a point on the line segment. If the point is on the segment, the - * result will be 0. - * - * @param x1 the first x coordinate of the segment - * @param y1 the first y coordinate of the segment - * @param x2 the second x coordinate of the segment - * @param y2 the second y coordinate of the segment - * @param px the x coordinate of the point - * @param py the y coordinate of the point - * @return the square of the distance from the point to the segment - * @see #ptSegDist(double, double, double, double, double, double) - * @see #ptLineDistSq(double, double, double, double, double, double) - */ - public static double ptSegDistSq(double x1, double y1, double x2, double y2, - double px, double py) - { - double pd2 = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2); - - double x, y; - if (pd2 == 0) - { - // Points are coincident. - x = x1; - y = y2; - } - else - { - double u = ((px - x1) * (x2 - x1) + (py - y1) * (y2 - y1)) / pd2; - - if (u < 0) - { - // "Off the end" - x = x1; - y = y1; - } - else if (u > 1.0) - { - x = x2; - y = y2; - } - else - { - x = x1 + u * (x2 - x1); - y = y1 + u * (y2 - y1); - } - } - - return (x - px) * (x - px) + (y - py) * (y - py); - } - - /** - * Measures the shortest distance from the reference point to a point on - * the line segment. If the point is on the segment, the result will be 0. - * - * @param x1 the first x coordinate of the segment - * @param y1 the first y coordinate of the segment - * @param x2 the second x coordinate of the segment - * @param y2 the second y coordinate of the segment - * @param px the x coordinate of the point - * @param py the y coordinate of the point - * @return the distance from the point to the segment - * @see #ptSegDistSq(double, double, double, double, double, double) - * @see #ptLineDist(double, double, double, double, double, double) - */ - public static double ptSegDist(double x1, double y1, double x2, double y2, - double px, double py) - { - return Math.sqrt(ptSegDistSq(x1, y1, x2, y2, px, py)); - } - - /** - * Measures the square of the shortest distance from the reference point - * to a point on this line segment. If the point is on the segment, the - * result will be 0. - * - * @param px the x coordinate of the point - * @param py the y coordinate of the point - * @return the square of the distance from the point to the segment - * @see #ptSegDistSq(double, double, double, double, double, double) - */ - public double ptSegDistSq(double px, double py) - { - return ptSegDistSq(getX1(), getY1(), getX2(), getY2(), px, py); - } - - /** - * Measures the square of the shortest distance from the reference point - * to a point on this line segment. If the point is on the segment, the - * result will be 0. - * - * @param p the point - * @return the square of the distance from the point to the segment - * @throws NullPointerException if p is null - * @see #ptSegDistSq(double, double, double, double, double, double) - */ - public double ptSegDistSq(Point2D p) - { - return ptSegDistSq(getX1(), getY1(), getX2(), getY2(), p.getX(), p.getY()); - } - - /** - * Measures the shortest distance from the reference point to a point on - * this line segment. If the point is on the segment, the result will be 0. - * - * @param px the x coordinate of the point - * @param py the y coordinate of the point - * @return the distance from the point to the segment - * @see #ptSegDist(double, double, double, double, double, double) - */ - public double ptSegDist(double px, double py) - { - return ptSegDist(getX1(), getY1(), getX2(), getY2(), px, py); - } - - /** - * Measures the shortest distance from the reference point to a point on - * this line segment. If the point is on the segment, the result will be 0. - * - * @param p the point - * @return the distance from the point to the segment - * @throws NullPointerException if p is null - * @see #ptSegDist(double, double, double, double, double, double) - */ - public double ptSegDist(Point2D p) - { - return ptSegDist(getX1(), getY1(), getX2(), getY2(), p.getX(), p.getY()); - } - - /** - * Measures the square of the shortest distance from the reference point - * to a point on the infinite line extended from the segment. If the point - * is on the segment, the result will be 0. If the segment is length 0, - * the distance is to the common endpoint. - * - * @param x1 the first x coordinate of the segment - * @param y1 the first y coordinate of the segment - * @param x2 the second x coordinate of the segment - * @param y2 the second y coordinate of the segment - * @param px the x coordinate of the point - * @param py the y coordinate of the point - * @return the square of the distance from the point to the extended line - * @see #ptLineDist(double, double, double, double, double, double) - * @see #ptSegDistSq(double, double, double, double, double, double) - */ - public static double ptLineDistSq(double x1, double y1, double x2, double y2, - double px, double py) - { - double pd2 = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2); - - double x, y; - if (pd2 == 0) - { - // Points are coincident. - x = x1; - y = y2; - } - else - { - double u = ((px - x1) * (x2 - x1) + (py - y1) * (y2 - y1)) / pd2; - x = x1 + u * (x2 - x1); - y = y1 + u * (y2 - y1); - } - - return (x - px) * (x - px) + (y - py) * (y - py); - } - - /** - * Measures the shortest distance from the reference point to a point on - * the infinite line extended from the segment. If the point is on the - * segment, the result will be 0. If the segment is length 0, the distance - * is to the common endpoint. - * - * @param x1 the first x coordinate of the segment - * @param y1 the first y coordinate of the segment - * @param x2 the second x coordinate of the segment - * @param y2 the second y coordinate of the segment - * @param px the x coordinate of the point - * @param py the y coordinate of the point - * @return the distance from the point to the extended line - * @see #ptLineDistSq(double, double, double, double, double, double) - * @see #ptSegDist(double, double, double, double, double, double) - */ - public static double ptLineDist(double x1, double y1, - double x2, double y2, - double px, double py) - { - return Math.sqrt(ptLineDistSq(x1, y1, x2, y2, px, py)); - } - - /** - * Measures the square of the shortest distance from the reference point - * to a point on the infinite line extended from this segment. If the point - * is on the segment, the result will be 0. If the segment is length 0, - * the distance is to the common endpoint. - * - * @param px the x coordinate of the point - * @param py the y coordinate of the point - * @return the square of the distance from the point to the extended line - * @see #ptLineDistSq(double, double, double, double, double, double) - */ - public double ptLineDistSq(double px, double py) - { - return ptLineDistSq(getX1(), getY1(), getX2(), getY2(), px, py); - } - - /** - * Measures the square of the shortest distance from the reference point - * to a point on the infinite line extended from this segment. If the point - * is on the segment, the result will be 0. If the segment is length 0, - * the distance is to the common endpoint. - * - * @param p the point - * @return the square of the distance from the point to the extended line - * @throws NullPointerException if p is null - * @see #ptLineDistSq(double, double, double, double, double, double) - */ - public double ptLineDistSq(Point2D p) - { - return ptLineDistSq(getX1(), getY1(), getX2(), getY2(), - p.getX(), p.getY()); - } - - /** - * Measures the shortest distance from the reference point to a point on - * the infinite line extended from this segment. If the point is on the - * segment, the result will be 0. If the segment is length 0, the distance - * is to the common endpoint. - * - * @param px the x coordinate of the point - * @param py the y coordinate of the point - * @return the distance from the point to the extended line - * @see #ptLineDist(double, double, double, double, double, double) - */ - public double ptLineDist(double px, double py) - { - return ptLineDist(getX1(), getY1(), getX2(), getY2(), px, py); - } - - /** - * Measures the shortest distance from the reference point to a point on - * the infinite line extended from this segment. If the point is on the - * segment, the result will be 0. If the segment is length 0, the distance - * is to the common endpoint. - * - * @param p the point - * @return the distance from the point to the extended line - * @throws NullPointerException if p is null - * @see #ptLineDist(double, double, double, double, double, double) - */ - public double ptLineDist(Point2D p) - { - return ptLineDist(getX1(), getY1(), getX2(), getY2(), p.getX(), p.getY()); - } - - /** - * Test if a point is contained inside the line. Since a line has no area, - * this returns false. - * - * @param x the x coordinate - * @param y the y coordinate - * @return false; the line does not contain points - */ - public boolean contains(double x, double y) - { - return false; - } - - /** - * Test if a point is contained inside the line. Since a line has no area, - * this returns false. - * - * @param p the point - * @return false; the line does not contain points - */ - public boolean contains(Point2D p) - { - return false; - } - - /** - * Tests if this line intersects the interior of the specified rectangle. - * - * @param x the x coordinate of the rectangle - * @param y the y coordinate of the rectangle - * @param w the width of the rectangle - * @param h the height of the rectangle - * @return true if the line intersects the rectangle - */ - public boolean intersects(double x, double y, double w, double h) - { - if (w <= 0 || h <= 0) - return false; - double x1 = getX1(); - double y1 = getY1(); - double x2 = getX2(); - double y2 = getY2(); - - if (x1 >= x && x1 <= x + w && y1 >= y && y1 <= y + h) - return true; - if (x2 >= x && x2 <= x + w && y2 >= y && y2 <= y + h) - return true; - - double x3 = x + w; - double y3 = y + h; - - return (linesIntersect(x1, y1, x2, y2, x, y, x, y3) - || linesIntersect(x1, y1, x2, y2, x, y3, x3, y3) - || linesIntersect(x1, y1, x2, y2, x3, y3, x3, y) - || linesIntersect(x1, y1, x2, y2, x3, y, x, y)); - } - - /** - * Tests if this line intersects the interior of the specified rectangle. - * - * @param r the rectangle - * @return true if the line intersects the rectangle - * @throws NullPointerException if r is null - */ - public boolean intersects(Rectangle2D r) - { - return intersects(r.getX(), r.getY(), r.getWidth(), r.getHeight()); - } - - /** - * Tests if the line contains a rectangle. Since lines have no area, this - * always returns false. - * - * @param x the x coordinate of the rectangle - * @param y the y coordinate of the rectangle - * @param w the width of the rectangle - * @param h the height of the rectangle - * @return false; the line does not contain points - */ - public boolean contains(double x, double y, double w, double h) - { - return false; - } - - /** - * Tests if the line contains a rectangle. Since lines have no area, this - * always returns false. - * - * @param r the rectangle - * @return false; the line does not contain points - */ - public boolean contains(Rectangle2D r) - { - return false; - } - - /** - * Gets a bounding box (not necessarily minimal) for this line. - * - * @return the integer bounding box - * @see #getBounds2D() - */ - public Rectangle getBounds() - { - return getBounds2D().getBounds(); - } - - /** - * Return a path iterator, possibly applying a transform on the result. This - * iterator is not threadsafe. - * - * @param at the transform, or null - * @return a new path iterator - */ - public PathIterator getPathIterator(final AffineTransform at) - { - return new PathIterator() - { - /** Current coordinate. */ - private int current = 0; - - public int getWindingRule() - { - return WIND_NON_ZERO; - } - - public boolean isDone() - { - return current >= 2; - } - - public void next() - { - current++; - } - - public int currentSegment(float[] coords) - { - int result; - switch (current) - { - case 0: - coords[0] = (float) getX1(); - coords[1] = (float) getY1(); - result = SEG_MOVETO; - break; - case 1: - coords[0] = (float) getX2(); - coords[1] = (float) getY2(); - result = SEG_LINETO; - break; - default: - throw new NoSuchElementException("line iterator out of bounds"); - } - if (at != null) - at.transform(coords, 0, coords, 0, 1); - return result; - } - - public int currentSegment(double[] coords) - { - int result; - switch (current) - { - case 0: - coords[0] = getX1(); - coords[1] = getY1(); - result = SEG_MOVETO; - break; - case 1: - coords[0] = getX2(); - coords[1] = getY2(); - result = SEG_LINETO; - break; - default: - throw new NoSuchElementException("line iterator out of bounds"); - } - if (at != null) - at.transform(coords, 0, coords, 0, 1); - return result; - } - }; - } - - /** - * Return a flat path iterator, possibly applying a transform on the result. - * This iterator is not threadsafe. - * - * @param at the transform, or null - * @param flatness ignored, since lines are already flat - * @return a new path iterator - * @see #getPathIterator(AffineTransform) - */ - public PathIterator getPathIterator(AffineTransform at, double flatness) - { - return getPathIterator(at); - } - - /** - * Create a new line of the same run-time type with the same contents as - * this one. - * - * @return the clone - * - * @exception OutOfMemoryError If there is not enough memory available. - * - * @since 1.2 - */ - public Object clone() - { - try - { - return super.clone(); - } - catch (CloneNotSupportedException e) - { - throw (Error) new InternalError().initCause(e); // Impossible - } - } - - /** - * This class defines a point in <code>double</code> precision. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.2 - * @status updated to 1.4 - */ - public static class Double extends Line2D - { - /** The x coordinate of the first point. */ - public double x1; - - /** The y coordinate of the first point. */ - public double y1; - - /** The x coordinate of the second point. */ - public double x2; - - /** The y coordinate of the second point. */ - public double y2; - - /** - * Construct the line segment (0,0)->(0,0). - */ - public Double() - { - } - - /** - * Construct the line segment with the specified points. - * - * @param x1 the x coordinate of the first point - * @param y1 the y coordinate of the first point - * @param x2 the x coordinate of the second point - * @param y2 the y coordinate of the second point - */ - public Double(double x1, double y1, double x2, double y2) - { - this.x1 = x1; - this.y1 = y1; - this.x2 = x2; - this.y2 = y2; - } - - /** - * Construct the line segment with the specified points. - * - * @param p1 the first point - * @param p2 the second point - * @throws NullPointerException if either point is null - */ - public Double(Point2D p1, Point2D p2) - { - x1 = p1.getX(); - y1 = p1.getY(); - x2 = p2.getX(); - y2 = p2.getY(); - } - - /** - * Return the x coordinate of the first point. - * - * @return the value of x1 - */ - public double getX1() - { - return x1; - } - - /** - * Return the y coordinate of the first point. - * - * @return the value of y1 - */ - public double getY1() - { - return y1; - } - - /** - * Return the first point. - * - * @return the point (x1,y1) - */ - public Point2D getP1() - { - return new Point2D.Double(x1, y1); - } - - /** - * Return the x coordinate of the second point. - * - * @return the value of x2 - */ - public double getX2() - { - return x2; - } - - /** - * Return the y coordinate of the second point. - * - * @return the value of y2 - */ - public double getY2() - { - return y2; - } - - /** - * Return the second point. - * - * @return the point (x2,y2) - */ - public Point2D getP2() - { - return new Point2D.Double(x2, y2); - } - - /** - * Set this line to the given points. - * - * @param x1 the new x coordinate of the first point - * @param y1 the new y coordinate of the first point - * @param x2 the new x coordinate of the second point - * @param y2 the new y coordinate of the second point - */ - public void setLine(double x1, double y1, double x2, double y2) - { - this.x1 = x1; - this.y1 = y1; - this.x2 = x2; - this.y2 = y2; - } - - /** - * Return the exact bounds of this line segment. - * - * @return the bounding box - */ - public Rectangle2D getBounds2D() - { - double x = Math.min(x1, x2); - double y = Math.min(y1, y2); - double w = Math.abs(x1 - x2); - double h = Math.abs(y1 - y2); - return new Rectangle2D.Double(x, y, w, h); - } - } // class Double - - /** - * This class defines a point in <code>float</code> precision. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.2 - * @status updated to 1.4 - */ - public static class Float extends Line2D - { - /** The x coordinate of the first point. */ - public float x1; - - /** The y coordinate of the first point. */ - public float y1; - - /** The x coordinate of the second point. */ - public float x2; - - /** The y coordinate of the second point. */ - public float y2; - - /** - * Construct the line segment (0,0)->(0,0). - */ - public Float() - { - } - - /** - * Construct the line segment with the specified points. - * - * @param x1 the x coordinate of the first point - * @param y1 the y coordinate of the first point - * @param x2 the x coordinate of the second point - * @param y2 the y coordinate of the second point - */ - public Float(float x1, float y1, float x2, float y2) - { - this.x1 = x1; - this.y1 = y1; - this.x2 = x2; - this.y2 = y2; - } - - /** - * Construct the line segment with the specified points. - * - * @param p1 the first point - * @param p2 the second point - * @throws NullPointerException if either point is null - */ - public Float(Point2D p1, Point2D p2) - { - x1 = (float) p1.getX(); - y1 = (float) p1.getY(); - x2 = (float) p2.getX(); - y2 = (float) p2.getY(); - } - - /** - * Return the x coordinate of the first point. - * - * @return the value of x1 - */ - public double getX1() - { - return x1; - } - - /** - * Return the y coordinate of the first point. - * - * @return the value of y1 - */ - public double getY1() - { - return y1; - } - - /** - * Return the first point. - * - * @return the point (x1,y1) - */ - public Point2D getP1() - { - return new Point2D.Float(x1, y1); - } - - /** - * Return the x coordinate of the second point. - * - * @return the value of x2 - */ - public double getX2() - { - return x2; - } - - /** - * Return the y coordinate of the second point. - * - * @return the value of y2 - */ - public double getY2() - { - return y2; - } - - /** - * Return the second point. - * - * @return the point (x2,y2) - */ - public Point2D getP2() - { - return new Point2D.Float(x2, y2); - } - - /** - * Set this line to the given points. - * - * @param x1 the new x coordinate of the first point - * @param y1 the new y coordinate of the first point - * @param x2 the new x coordinate of the second point - * @param y2 the new y coordinate of the second point - */ - public void setLine(double x1, double y1, double x2, double y2) - { - this.x1 = (float) x1; - this.y1 = (float) y1; - this.x2 = (float) x2; - this.y2 = (float) y2; - } - - /** - * Set this line to the given points. - * - * @param x1 the new x coordinate of the first point - * @param y1 the new y coordinate of the first point - * @param x2 the new x coordinate of the second point - * @param y2 the new y coordinate of the second point - */ - public void setLine(float x1, float y1, float x2, float y2) - { - this.x1 = x1; - this.y1 = y1; - this.x2 = x2; - this.y2 = y2; - } - - /** - * Return the exact bounds of this line segment. - * - * @return the bounding box - */ - public Rectangle2D getBounds2D() - { - float x = Math.min(x1, x2); - float y = Math.min(y1, y2); - float w = Math.abs(x1 - x2); - float h = Math.abs(y1 - y2); - return new Rectangle2D.Float(x, y, w, h); - } - } // class Float -} // class Line2D diff --git a/libjava/java/awt/geom/NoninvertibleTransformException.java b/libjava/java/awt/geom/NoninvertibleTransformException.java deleted file mode 100644 index 7995a52eb61..00000000000 --- a/libjava/java/awt/geom/NoninvertibleTransformException.java +++ /dev/null @@ -1,65 +0,0 @@ -/* NoninvertibleTransformException.java -- a transform can't be inverted - Copyright (C) 2000, 2002 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.awt.geom; - -/** - * Thrown if an operation requires an inverse of an - * <code>AffineTransform</code>, but the transform is in a non-invertible - * state. - * - * @author Tom Tromey (tromey@cygnus.com) - * @see AffineTransform - * @status updated to 1.4 - */ -public class NoninvertibleTransformException extends Exception -{ - /** - * Compatible with JDK 1.2+. - */ - private static final long serialVersionUID = 6137225240503990466L; - - /** - * Create an exception with a message. - * - * @param s the message - */ - public NoninvertibleTransformException(String s) - { - super(s); - } -} diff --git a/libjava/java/awt/geom/PathIterator.java b/libjava/java/awt/geom/PathIterator.java deleted file mode 100644 index 2cd08b9b48b..00000000000 --- a/libjava/java/awt/geom/PathIterator.java +++ /dev/null @@ -1,189 +0,0 @@ -/* PathIterator.java -- describes a shape by iterating over its vertices - Copyright (C) 2000, 2002, 2003 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.awt.geom; - -/** - * This interface provides a directed path over the boundary of a shape. The - * path can contain 1st through 3rd order Bezier curves (lines, and quadratic - * and cubic splines). A shape can have multiple disjoint paths via the - * MOVETO directive, and can close a circular path back to the previos - * MOVETO via the CLOSE directive. - * - * @author Tom Tromey (tromey@cygnus.com) - * @author Eric Blake (ebb9@email.byu.edu) - * @see java.awt.Shape - * @see java.awt.Stroke - * @see FlatteningPathIterator - * @since 1.2 - * @status updated to 1.4 - */ -public interface PathIterator -{ - /** - * The even-odd winding mode: a point is internal to the shape if a ray - * from the point to infinity (in any direction) crosses an odd number of - * segments. - */ - int WIND_EVEN_ODD = 0; - - /** - * The non-zero winding mode: a point is internal to the shape if a ray - * from the point to infinity (in any direction) crosses a different number - * of segments headed clockwise than those headed counterclockwise. - */ - int WIND_NON_ZERO = 1; - - /** - * Starts a new subpath. There is no segment from the previous vertex. - */ - int SEG_MOVETO = 0; - - /** - * The current segment is a line. - */ - int SEG_LINETO = 1; - - /** - * The current segment is a quadratic parametric curve. It is interpolated - * as t varies from 0 to 1 over the current point (CP), first control point - * (P1), and final interpolated control point (P2): - * <pre> - * P(t) = B(2,0)*CP + B(2,1)*P1 + B(2,2)*P2 - * 0 <= t <= 1 - * B(n,m) = mth coefficient of nth degree Bernstein polynomial - * = C(n,m) * t^(m) * (1 - t)^(n-m) - * C(n,m) = Combinations of n things, taken m at a time - * = n! / (m! * (n-m)!) - * </pre> - */ - int SEG_QUADTO = 2; - - /** - * The current segment is a cubic parametric curve (more commonly known as - * a Bezier curve). It is interpolated as t varies from 0 to 1 over the - * current point (CP), first control point (P1), the second control point - * (P2), and final interpolated control point (P3): - * <pre> - * P(t) = B(3,0)*CP + B(3,1)*P1 + B(3,2)*P2 + B(3,3)*P3 - * 0 <= t <= 1 - * B(n,m) = mth coefficient of nth degree Bernstein polynomial - * = C(n,m) * t^(m) * (1 - t)^(n-m) - * C(n,m) = Combinations of n things, taken m at a time - * = n! / (m! * (n-m)!) - * </pre> - */ - int SEG_CUBICTO = 3; - - /** - * The current segment closes a loop by an implicit line to the previous - * SEG_MOVETO coordinate. - */ - int SEG_CLOSE = 4; - - /** - * Returns the winding rule to determine which points are inside this path. - * - * @return the winding rule - * @see #WIND_EVEN_ODD - * @see #WIND_NON_ZERO - */ - int getWindingRule(); - - /** - * Tests if the iterator is exhausted. If this returns true, currentSegment - * and next may throw a NoSuchElementException (although this is not - * required). - * - * @return true if the iteration is complete - */ - boolean isDone(); - - /** - * Advance to the next segment in the iteration. It is not specified what - * this does if called when isDone() returns true. - * - * @throws java.util.NoSuchElementException optional when isDone() is true - */ - void next(); - - /** - * Returns the coordinates of the next point(s), as well as the type of - * line segment. The input array must be at least a float[6], to accomodate - * up to three (x,y) point pairs (although if you know the iterator is - * flat, you can probably get by with a float[2]). If the returned type is - * SEG_MOVETO or SEG_LINETO, the first point in the array is modified; if - * the returned type is SEG_QUADTO, the first two points are modified; if - * the returned type is SEG_CUBICTO, all three points are modified; and if - * the returned type is SEG_CLOSE, the array is untouched. - * - * @param coords the array to place the point coordinates in - * @return the segment type - * @throws NullPointerException if coords is null - * @throws ArrayIndexOutOfBoundsException if coords is too small - * @throws java.util.NoSuchElementException optional when isDone() is true - * @see #SEG_MOVETO - * @see #SEG_LINETO - * @see #SEG_QUADTO - * @see #SEG_CUBICTO - * @see #SEG_CLOSE - */ - int currentSegment(float[] coords); - - /** - * Returns the coordinates of the next point(s), as well as the type of - * line segment. The input array must be at least a double[6], to accomodate - * up to three (x,y) point pairs (although if you know the iterator is - * flat, you can probably get by with a double[2]). If the returned type is - * SEG_MOVETO or SEG_LINETO, the first point in the array is modified; if - * the returned type is SEG_QUADTO, the first two points are modified; if - * the returned type is SEG_CUBICTO, all three points are modified; and if - * the returned type is SEG_CLOSE, the array is untouched. - * - * @param coords the array to place the point coordinates in - * @return the segment type - * @throws NullPointerException if coords is null - * @throws ArrayIndexOutOfBoundsException if coords is too small - * @throws java.util.NoSuchElementException optional when isDone() is true - * @see #SEG_MOVETO - * @see #SEG_LINETO - * @see #SEG_QUADTO - * @see #SEG_CUBICTO - * @see #SEG_CLOSE - */ - int currentSegment(double[] coords); -} // interface PathIterator diff --git a/libjava/java/awt/geom/Point2D.java b/libjava/java/awt/geom/Point2D.java deleted file mode 100644 index 9f22a5a67c9..00000000000 --- a/libjava/java/awt/geom/Point2D.java +++ /dev/null @@ -1,396 +0,0 @@ -/* Point2D.java -- generic point in 2-D space - Copyright (C) 1999, 2000, 2002, 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.geom; - -/** - * This class implements a generic point in 2D Cartesian space. The storage - * representation is left up to the subclass. Point includes two useful - * nested classes, for float and double storage respectively. - * - * @author Per Bothner (bothner@cygnus.com) - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.2 - * @status updated to 1.4 - */ -public abstract class Point2D implements Cloneable -{ - /** - * The default constructor. - * - * @see java.awt.Point - * @see Point2D.Float - * @see Point2D.Double - */ - protected Point2D() - { - } - - /** - * Get the X coordinate, in double precision. - * - * @return the x coordinate - */ - public abstract double getX(); - - /** - * Get the Y coordinate, in double precision. - * - * @return the y coordinate - */ - public abstract double getY(); - - /** - * Set the location of this point to the new coordinates. There may be a - * loss of precision. - * - * @param x the new x coordinate - * @param y the new y coordinate - */ - public abstract void setLocation(double x, double y); - - /** - * Set the location of this point to the new coordinates. There may be a - * loss of precision. - * - * @param p the point to copy - * @throws NullPointerException if p is null - */ - public void setLocation(Point2D p) - { - setLocation(p.getX(), p.getY()); - } - - /** - * Return the square of the distance between two points. - * - * @param x1 the x coordinate of point 1 - * @param y1 the y coordinate of point 1 - * @param x2 the x coordinate of point 2 - * @param y2 the y coordinate of point 2 - * @return (x2 - x1)^2 + (y2 - y1)^2 - */ - public static double distanceSq(double x1, double y1, double x2, double y2) - { - x2 -= x1; - y2 -= y1; - return x2 * x2 + y2 * y2; - } - - /** - * Return the distance between two points. - * - * @param x1 the x coordinate of point 1 - * @param y1 the y coordinate of point 1 - * @param x2 the x coordinate of point 2 - * @param y2 the y coordinate of point 2 - * @return the distance from (x1,y1) to (x2,y2) - */ - public static double distance(double x1, double y1, double x2, double y2) - { - return Math.sqrt(distanceSq(x1, y1, x2, y2)); - } - - /** - * Return the square of the distance from this point to the given one. - * - * @param x the x coordinate of the other point - * @param y the y coordinate of the other point - * @return the square of the distance - */ - public double distanceSq(double x, double y) - { - return distanceSq(getX(), x, getY(), y); - } - - /** - * Return the square of the distance from this point to the given one. - * - * @param p the other point - * @return the square of the distance - * @throws NullPointerException if p is null - */ - public double distanceSq(Point2D p) - { - return distanceSq(getX(), p.getX(), getY(), p.getY()); - } - - /** - * Return the distance from this point to the given one. - * - * @param x the x coordinate of the other point - * @param y the y coordinate of the other point - * @return the distance - */ - public double distance(double x, double y) - { - return distance(getX(), x, getY(), y); - } - - /** - * Return the distance from this point to the given one. - * - * @param p the other point - * @return the distance - * @throws NullPointerException if p is null - */ - public double distance(Point2D p) - { - return distance(getX(), p.getX(), getY(), p.getY()); - } - - /** - * Create a new point of the same run-time type with the same contents as - * this one. - * - * @return the clone - */ - public Object clone() - { - try - { - return super.clone(); - } - catch (CloneNotSupportedException e) - { - throw (Error) new InternalError().initCause(e); // Impossible - } - } - - /** - * Return the hashcode for this point. The formula is not documented, but - * appears to be the same as: - * <pre> - * long l = Double.doubleToLongBits(getY()); - * l = l * 31 ^ Double.doubleToLongBits(getX()); - * return (int) ((l >> 32) ^ l); - * </pre> - * - * @return the hashcode - */ - public int hashCode() - { - // Talk about a fun time reverse engineering this one! - long l = java.lang.Double.doubleToLongBits(getY()); - l = l * 31 ^ java.lang.Double.doubleToLongBits(getX()); - return (int) ((l >> 32) ^ l); - } - - /** - * Compares two points for equality. This returns true if they have the - * same coordinates. - * - * @param o the point to compare - * @return true if it is equal - */ - public boolean equals(Object o) - { - if (! (o instanceof Point2D)) - return false; - Point2D p = (Point2D) o; - return getX() == p.getX() && getY() == p.getY(); - } - - /** - * This class defines a point in <code>double</code> precision. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.2 - * @status updated to 1.4 - */ - public static class Double extends Point2D - { - /** The X coordinate. */ - public double x; - - /** The Y coordinate. */ - public double y; - - /** - * Create a new point at (0,0). - */ - public Double() - { - } - - /** - * Create a new point at (x,y). - * - * @param x the x coordinate - * @param y the y coordinate - */ - public Double(double x, double y) - { - this.x = x; - this.y = y; - } - - /** - * Return the x coordinate. - * - * @return the x coordinate - */ - public double getX() - { - return x; - } - - /** - * Return the y coordinate. - * - * @return the y coordinate - */ - public double getY() - { - return y; - } - - /** - * Sets the location of this point. - * - * @param x the new x coordinate - * @param y the new y coordinate - */ - public void setLocation(double x, double y) - { - this.x = x; - this.y = y; - } - - /** - * Returns a string representation of this object. The format is: - * <code>"Point2D.Double[" + x + ", " + y + ']'</code>. - * - * @return a string representation of this object - */ - public String toString() - { - return "Point2D.Double[" + x + ", " + y + ']'; - } - } // class Double - - /** - * This class defines a point in <code>float</code> precision. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.2 - * @status updated to 1.4 - */ - public static class Float extends Point2D - { - /** The X coordinate. */ - public float x; - - /** The Y coordinate. */ - public float y; - - /** - * Create a new point at (0,0). - */ - public Float() - { - } - - /** - * Create a new point at (x,y). - * - * @param x the x coordinate - * @param y the y coordinate - */ - public Float(float x, float y) - { - this.x = x; - this.y = y; - } - - /** - * Return the x coordinate. - * - * @return the x coordinate - */ - public double getX() - { - return x; - } - - /** - * Return the y coordinate. - * - * @return the y coordinate - */ - public double getY() - { - return y; - } - - /** - * Sets the location of this point. - * - * @param x the new x coordinate - * @param y the new y coordinate - */ - public void setLocation(double x, double y) - { - this.x = (float) x; - this.y = (float) y; - } - - /** - * Sets the location of this point. - * - * @param x the new x coordinate - * @param y the new y coordinate - */ - public void setLocation(float x, float y) - { - this.x = x; - this.y = y; - } - - /** - * Returns a string representation of this object. The format is: - * <code>"Point2D.Float[" + x + ", " + y + ']'</code>. - * - * @return a string representation of this object - */ - public String toString() - { - return "Point2D.Float[" + x + ", " + y + ']'; - } - } // class Float -} // class Point2D diff --git a/libjava/java/awt/geom/QuadCurve2D.java b/libjava/java/awt/geom/QuadCurve2D.java deleted file mode 100644 index 41021dbc683..00000000000 --- a/libjava/java/awt/geom/QuadCurve2D.java +++ /dev/null @@ -1,1467 +0,0 @@ -/* QuadCurve2D.java -- represents a parameterized quadratic curve in 2-D space - Copyright (C) 2002, 2003, 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.awt.geom; - -import java.awt.Rectangle; -import java.awt.Shape; -import java.util.NoSuchElementException; - -/** - * A two-dimensional curve that is parameterized with a quadratic - * function. - * - * <p><img src="doc-files/QuadCurve2D-1.png" width="350" height="180" - * alt="A drawing of a QuadCurve2D" /> - * - * @author Eric Blake (ebb9@email.byu.edu) - * @author Graydon Hoare (graydon@redhat.com) - * @author Sascha Brawer (brawer@dandelis.ch) - * @author Sven de Marothy (sven@physto.se) - * - * @since 1.2 - */ -public abstract class QuadCurve2D implements Shape, Cloneable -{ - private static final double BIG_VALUE = java.lang.Double.MAX_VALUE / 10.0; - private static final double EPSILON = 1E-10; - - /** - * Constructs a new QuadCurve2D. Typical users will want to - * construct instances of a subclass, such as {@link - * QuadCurve2D.Float} or {@link QuadCurve2D.Double}. - */ - protected QuadCurve2D() - { - } - - /** - * Returns the <i>x</i> coordinate of the curve’s start - * point. - */ - public abstract double getX1(); - - /** - * Returns the <i>y</i> coordinate of the curve’s start - * point. - */ - public abstract double getY1(); - - /** - * Returns the curve’s start point. - */ - public abstract Point2D getP1(); - - /** - * Returns the <i>x</i> coordinate of the curve’s control - * point. - */ - public abstract double getCtrlX(); - - /** - * Returns the <i>y</i> coordinate of the curve’s control - * point. - */ - public abstract double getCtrlY(); - - /** - * Returns the curve’s control point. - */ - public abstract Point2D getCtrlPt(); - - /** - * Returns the <i>x</i> coordinate of the curve’s end - * point. - */ - public abstract double getX2(); - - /** - * Returns the <i>y</i> coordinate of the curve’s end - * point. - */ - public abstract double getY2(); - - /** - * Returns the curve’s end point. - */ - public abstract Point2D getP2(); - - /** - * Changes the curve geometry, separately specifying each coordinate - * value. - * - * @param x1 the <i>x</i> coordinate of the curve’s new start - * point. - * - * @param y1 the <i>y</i> coordinate of the curve’s new start - * point. - * - * @param cx the <i>x</i> coordinate of the curve’s new - * control point. - * - * @param cy the <i>y</i> coordinate of the curve’s new - * control point. - * - * @param x2 the <i>x</i> coordinate of the curve’s new end - * point. - * - * @param y2 the <i>y</i> coordinate of the curve’s new end - * point. - */ - public abstract void setCurve(double x1, double y1, double cx, double cy, - double x2, double y2); - - /** - * Changes the curve geometry, passing coordinate values in an - * array. - * - * @param coords an array containing the new coordinate values. The - * <i>x</i> coordinate of the new start point is located at - * <code>coords[offset]</code>, its <i>y</i> coordinate at - * <code>coords[offset + 1]</code>. The <i>x</i> coordinate of the - * new control point is located at <code>coords[offset + 2]</code>, - * its <i>y</i> coordinate at <code>coords[offset + 3]</code>. The - * <i>x</i> coordinate of the new end point is located at - * <code>coords[offset + 4]</code>, its <i>y</i> coordinate at - * <code>coords[offset + 5]</code>. - * - * @param offset the offset of the first coordinate value in - * <code>coords</code>. - */ - public void setCurve(double[] coords, int offset) - { - setCurve(coords[offset++], coords[offset++], coords[offset++], - coords[offset++], coords[offset++], coords[offset++]); - } - - /** - * Changes the curve geometry, specifying coordinate values in - * separate Point objects. - * - * <p><img src="doc-files/QuadCurve2D-1.png" width="350" height="180" - * alt="A drawing of a QuadCurve2D" /> - * - * <p>The curve does not keep any reference to the passed point - * objects. Therefore, a later change to <code>p1</code>, - * <code>c</code> <code>p2</code> will not affect the curve - * geometry. - * - * @param p1 the new start point. - * @param c the new control point. - * @param p2 the new end point. - */ - public void setCurve(Point2D p1, Point2D c, Point2D p2) - { - setCurve(p1.getX(), p1.getY(), c.getX(), c.getY(), p2.getX(), p2.getY()); - } - - /** - * Changes the curve geometry, specifying coordinate values in an - * array of Point objects. - * - * <p><img src="doc-files/QuadCurve2D-1.png" width="350" height="180" - * alt="A drawing of a QuadCurve2D" /> - * - * <p>The curve does not keep references to the passed point - * objects. Therefore, a later change to the <code>pts</code> array - * or any of its elements will not affect the curve geometry. - * - * @param pts an array containing the points. The new start point - * is located at <code>pts[offset]</code>, the new control - * point at <code>pts[offset + 1]</code>, and the new end point - * at <code>pts[offset + 2]</code>. - * - * @param offset the offset of the start point in <code>pts</code>. - */ - public void setCurve(Point2D[] pts, int offset) - { - setCurve(pts[offset].getX(), pts[offset].getY(), pts[offset + 1].getX(), - pts[offset + 1].getY(), pts[offset + 2].getX(), - pts[offset + 2].getY()); - } - - /** - * Changes the geometry of the curve to that of another curve. - * - * @param c the curve whose coordinates will be copied. - */ - public void setCurve(QuadCurve2D c) - { - setCurve(c.getX1(), c.getY1(), c.getCtrlX(), c.getCtrlY(), c.getX2(), - c.getY2()); - } - - /** - * Calculates the squared flatness of a quadratic curve, directly - * specifying each coordinate value. The flatness is the distance of - * the control point to the line between start and end point. - * - * <p><img src="doc-files/QuadCurve2D-4.png" width="350" height="180" - * alt="A drawing that illustrates the flatness" /> - * - * <p>In the above drawing, the straight line connecting start point - * P1 and end point P2 is depicted in gray. The result will be the - * the square of the distance between C and the gray line, i.e. - * the squared length of the red line. - * - * @param x1 the <i>x</i> coordinate of the start point P1. - * @param y1 the <i>y</i> coordinate of the start point P1. - * @param cx the <i>x</i> coordinate of the control point C. - * @param cy the <i>y</i> coordinate of the control point C. - * @param x2 the <i>x</i> coordinate of the end point P2. - * @param y2 the <i>y</i> coordinate of the end point P2. - */ - public static double getFlatnessSq(double x1, double y1, double cx, - double cy, double x2, double y2) - { - return Line2D.ptSegDistSq(x1, y1, x2, y2, cx, cy); - } - - /** - * Calculates the flatness of a quadratic curve, directly specifying - * each coordinate value. The flatness is the distance of the - * control point to the line between start and end point. - * - * <p><img src="doc-files/QuadCurve2D-4.png" width="350" height="180" - * alt="A drawing that illustrates the flatness" /> - * - * <p>In the above drawing, the straight line connecting start point - * P1 and end point P2 is depicted in gray. The result will be the - * the distance between C and the gray line, i.e. the length of - * the red line. - * - * @param x1 the <i>x</i> coordinate of the start point P1. - * @param y1 the <i>y</i> coordinate of the start point P1. - * @param cx the <i>x</i> coordinate of the control point C. - * @param cy the <i>y</i> coordinate of the control point C. - * @param x2 the <i>x</i> coordinate of the end point P2. - * @param y2 the <i>y</i> coordinate of the end point P2. - */ - public static double getFlatness(double x1, double y1, double cx, double cy, - double x2, double y2) - { - return Line2D.ptSegDist(x1, y1, x2, y2, cx, cy); - } - - /** - * Calculates the squared flatness of a quadratic curve, specifying - * the coordinate values in an array. The flatness is the distance - * of the control point to the line between start and end point. - * - * <p><img src="doc-files/QuadCurve2D-4.png" width="350" height="180" - * alt="A drawing that illustrates the flatness" /> - * - * <p>In the above drawing, the straight line connecting start point - * P1 and end point P2 is depicted in gray. The result will be the - * the square of the distance between C and the gray line, i.e. - * the squared length of the red line. - * - * @param coords an array containing the coordinate values. The - * <i>x</i> coordinate of the start point P1 is located at - * <code>coords[offset]</code>, its <i>y</i> coordinate at - * <code>coords[offset + 1]</code>. The <i>x</i> coordinate of the - * control point C is located at <code>coords[offset + 2]</code>, - * its <i>y</i> coordinate at <code>coords[offset + 3]</code>. The - * <i>x</i> coordinate of the end point P2 is located at - * <code>coords[offset + 4]</code>, its <i>y</i> coordinate at - * <code>coords[offset + 5]</code>. - * - * @param offset the offset of the first coordinate value in - * <code>coords</code>. - */ - public static double getFlatnessSq(double[] coords, int offset) - { - return Line2D.ptSegDistSq(coords[offset], coords[offset + 1], - coords[offset + 4], coords[offset + 5], - coords[offset + 2], coords[offset + 3]); - } - - /** - * Calculates the flatness of a quadratic curve, specifying the - * coordinate values in an array. The flatness is the distance of - * the control point to the line between start and end point. - * - * <p><img src="doc-files/QuadCurve2D-4.png" width="350" height="180" - * alt="A drawing that illustrates the flatness" /> - * - * <p>In the above drawing, the straight line connecting start point - * P1 and end point P2 is depicted in gray. The result will be the - * the the distance between C and the gray line, i.e. the length of - * the red line. - * - * @param coords an array containing the coordinate values. The - * <i>x</i> coordinate of the start point P1 is located at - * <code>coords[offset]</code>, its <i>y</i> coordinate at - * <code>coords[offset + 1]</code>. The <i>x</i> coordinate of the - * control point C is located at <code>coords[offset + 2]</code>, - * its <i>y</i> coordinate at <code>coords[offset + 3]</code>. The - * <i>x</i> coordinate of the end point P2 is located at - * <code>coords[offset + 4]</code>, its <i>y</i> coordinate at - * <code>coords[offset + 5]</code>. - * - * @param offset the offset of the first coordinate value in - * <code>coords</code>. - */ - public static double getFlatness(double[] coords, int offset) - { - return Line2D.ptSegDist(coords[offset], coords[offset + 1], - coords[offset + 4], coords[offset + 5], - coords[offset + 2], coords[offset + 3]); - } - - /** - * Calculates the squared flatness of this curve. The flatness is - * the distance of the control point to the line between start and - * end point. - * - * <p><img src="doc-files/QuadCurve2D-4.png" width="350" height="180" - * alt="A drawing that illustrates the flatness" /> - * - * <p>In the above drawing, the straight line connecting start point - * P1 and end point P2 is depicted in gray. The result will be the - * the square of the distance between C and the gray line, i.e. the - * squared length of the red line. - */ - public double getFlatnessSq() - { - return Line2D.ptSegDistSq(getX1(), getY1(), getX2(), getY2(), getCtrlX(), - getCtrlY()); - } - - /** - * Calculates the flatness of this curve. The flatness is the - * distance of the control point to the line between start and end - * point. - * - * <p><img src="doc-files/QuadCurve2D-4.png" width="350" height="180" - * alt="A drawing that illustrates the flatness" /> - * - * <p>In the above drawing, the straight line connecting start point - * P1 and end point P2 is depicted in gray. The result will be the - * the distance between C and the gray line, i.e. the length of the - * red line. - */ - public double getFlatness() - { - return Line2D.ptSegDist(getX1(), getY1(), getX2(), getY2(), getCtrlX(), - getCtrlY()); - } - - /** - * Subdivides this curve into two halves. - * - * <p><img src="doc-files/QuadCurve2D-3.png" width="700" - * height="180" alt="A drawing that illustrates the effects of - * subdividing a QuadCurve2D" /> - * - * @param left a curve whose geometry will be set to the left half - * of this curve, or <code>null</code> if the caller is not - * interested in the left half. - * - * @param right a curve whose geometry will be set to the right half - * of this curve, or <code>null</code> if the caller is not - * interested in the right half. - */ - public void subdivide(QuadCurve2D left, QuadCurve2D right) - { - // Use empty slots at end to share single array. - double[] d = new double[] - { - getX1(), getY1(), getCtrlX(), getCtrlY(), getX2(), getY2(), - 0, 0, 0, 0 - }; - subdivide(d, 0, d, 0, d, 4); - if (left != null) - left.setCurve(d, 0); - if (right != null) - right.setCurve(d, 4); - } - - /** - * Subdivides a quadratic curve into two halves. - * - * <p><img src="doc-files/QuadCurve2D-3.png" width="700" - * height="180" alt="A drawing that illustrates the effects of - * subdividing a QuadCurve2D" /> - * - * @param src the curve to be subdivided. - * - * @param left a curve whose geometry will be set to the left half - * of <code>src</code>, or <code>null</code> if the caller is not - * interested in the left half. - * - * @param right a curve whose geometry will be set to the right half - * of <code>src</code>, or <code>null</code> if the caller is not - * interested in the right half. - */ - public static void subdivide(QuadCurve2D src, QuadCurve2D left, - QuadCurve2D right) - { - src.subdivide(left, right); - } - - /** - * Subdivides a quadratic curve into two halves, passing all - * coordinates in an array. - * - * <p><img src="doc-files/QuadCurve2D-3.png" width="700" - * height="180" alt="A drawing that illustrates the effects of - * subdividing a QuadCurve2D" /> - * - * <p>The left end point and the right start point will always be - * identical. Memory-concious programmers thus may want to pass the - * same array for both <code>left</code> and <code>right</code>, and - * set <code>rightOff</code> to <code>leftOff + 4</code>. - * - * @param src an array containing the coordinates of the curve to be - * subdivided. The <i>x</i> coordinate of the start point is - * located at <code>src[srcOff]</code>, its <i>y</i> at - * <code>src[srcOff + 1]</code>. The <i>x</i> coordinate of the - * control point is located at <code>src[srcOff + 2]</code>, its - * <i>y</i> at <code>src[srcOff + 3]</code>. The <i>x</i> - * coordinate of the end point is located at <code>src[srcOff + - * 4]</code>, its <i>y</i> at <code>src[srcOff + 5]</code>. - * - * @param srcOff an offset into <code>src</code>, specifying - * the index of the start point’s <i>x</i> coordinate. - * - * @param left an array that will receive the coordinates of the - * left half of <code>src</code>. It is acceptable to pass - * <code>src</code>. A caller who is not interested in the left half - * can pass <code>null</code>. - * - * @param leftOff an offset into <code>left</code>, specifying the - * index where the start point’s <i>x</i> coordinate will be - * stored. - * - * @param right an array that will receive the coordinates of the - * right half of <code>src</code>. It is acceptable to pass - * <code>src</code> or <code>left</code>. A caller who is not - * interested in the right half can pass <code>null</code>. - * - * @param rightOff an offset into <code>right</code>, specifying the - * index where the start point’s <i>x</i> coordinate will be - * stored. - */ - public static void subdivide(double[] src, int srcOff, double[] left, - int leftOff, double[] right, int rightOff) - { - double x1; - double y1; - double xc; - double yc; - double x2; - double y2; - - x1 = src[srcOff]; - y1 = src[srcOff + 1]; - xc = src[srcOff + 2]; - yc = src[srcOff + 3]; - x2 = src[srcOff + 4]; - y2 = src[srcOff + 5]; - - if (left != null) - { - left[leftOff] = x1; - left[leftOff + 1] = y1; - } - - if (right != null) - { - right[rightOff + 4] = x2; - right[rightOff + 5] = y2; - } - - x1 = (x1 + xc) / 2; - x2 = (xc + x2) / 2; - xc = (x1 + x2) / 2; - y1 = (y1 + yc) / 2; - y2 = (y2 + yc) / 2; - yc = (y1 + y2) / 2; - - if (left != null) - { - left[leftOff + 2] = x1; - left[leftOff + 3] = y1; - left[leftOff + 4] = xc; - left[leftOff + 5] = yc; - } - - if (right != null) - { - right[rightOff] = xc; - right[rightOff + 1] = yc; - right[rightOff + 2] = x2; - right[rightOff + 3] = y2; - } - } - - /** - * Finds the non-complex roots of a quadratic equation, placing the - * results into the same array as the equation coefficients. The - * following equation is being solved: - * - * <blockquote><code>eqn[2]</code> · <i>x</i><sup>2</sup> - * + <code>eqn[1]</code> · <i>x</i> - * + <code>eqn[0]</code> - * = 0 - * </blockquote> - * - * <p>For some background about solving quadratic equations, see the - * article <a href= - * "http://planetmath.org/encyclopedia/QuadraticFormula.html" - * >“Quadratic Formula”</a> in <a href= - * "http://planetmath.org/">PlanetMath</a>. For an extensive library - * of numerical algorithms written in the C programming language, - * see the <a href="http://www.gnu.org/software/gsl/">GNU Scientific - * Library</a>. - * - * @see #solveQuadratic(double[], double[]) - * @see CubicCurve2D#solveCubic(double[], double[]) - * - * @param eqn an array with the coefficients of the equation. When - * this procedure has returned, <code>eqn</code> will contain the - * non-complex solutions of the equation, in no particular order. - * - * @return the number of non-complex solutions. A result of 0 - * indicates that the equation has no non-complex solutions. A - * result of -1 indicates that the equation is constant (i.e., - * always or never zero). - * - * @author Brian Gough (bjg@network-theory.com) - * (original C implementation in the <a href= - * "http://www.gnu.org/software/gsl/">GNU Scientific Library</a>) - * - * @author Sascha Brawer (brawer@dandelis.ch) - * (adaptation to Java) - */ - public static int solveQuadratic(double[] eqn) - { - return solveQuadratic(eqn, eqn); - } - - /** - * Finds the non-complex roots of a quadratic equation. The - * following equation is being solved: - * - * <blockquote><code>eqn[2]</code> · <i>x</i><sup>2</sup> - * + <code>eqn[1]</code> · <i>x</i> - * + <code>eqn[0]</code> - * = 0 - * </blockquote> - * - * <p>For some background about solving quadratic equations, see the - * article <a href= - * "http://planetmath.org/encyclopedia/QuadraticFormula.html" - * >“Quadratic Formula”</a> in <a href= - * "http://planetmath.org/">PlanetMath</a>. For an extensive library - * of numerical algorithms written in the C programming language, - * see the <a href="http://www.gnu.org/software/gsl/">GNU Scientific - * Library</a>. - * - * @see CubicCurve2D#solveCubic(double[],double[]) - * - * @param eqn an array with the coefficients of the equation. - * - * @param res an array into which the non-complex roots will be - * stored. The results may be in an arbitrary order. It is safe to - * pass the same array object reference for both <code>eqn</code> - * and <code>res</code>. - * - * @return the number of non-complex solutions. A result of 0 - * indicates that the equation has no non-complex solutions. A - * result of -1 indicates that the equation is constant (i.e., - * always or never zero). - * - * @author Brian Gough (bjg@network-theory.com) - * (original C implementation in the <a href= - * "http://www.gnu.org/software/gsl/">GNU Scientific Library</a>) - * - * @author Sascha Brawer (brawer@dandelis.ch) - * (adaptation to Java) - */ - public static int solveQuadratic(double[] eqn, double[] res) - { - // Taken from poly/solve_quadratic.c in the GNU Scientific Library - // (GSL), cvs revision 1.7 of 2003-07-26. For the original source, - // see http://www.gnu.org/software/gsl/ - // - // Brian Gough, the author of that code, has granted the - // permission to use it in GNU Classpath under the GNU Classpath - // license, and has assigned the copyright to the Free Software - // Foundation. - // - // The Java implementation is very similar to the GSL code, but - // not a strict one-to-one copy. For example, GSL would sort the - // result. - double a; - double b; - double c; - double disc; - - c = eqn[0]; - b = eqn[1]; - a = eqn[2]; - - // Check for linear or constant functions. This is not done by the - // GNU Scientific Library. Without this special check, we - // wouldn't return -1 for constant functions, and 2 instead of 1 - // for linear functions. - if (a == 0) - { - if (b == 0) - return -1; - - res[0] = -c / b; - return 1; - } - - disc = b * b - 4 * a * c; - - if (disc < 0) - return 0; - - if (disc == 0) - { - // The GNU Scientific Library returns two identical results here. - // We just return one. - res[0] = -0.5 * b / a; - return 1; - } - - // disc > 0 - if (b == 0) - { - double r; - - r = Math.abs(0.5 * Math.sqrt(disc) / a); - res[0] = -r; - res[1] = r; - } - else - { - double sgnb; - double temp; - - sgnb = (b > 0 ? 1 : -1); - temp = -0.5 * (b + sgnb * Math.sqrt(disc)); - - // The GNU Scientific Library sorts the result here. We don't. - res[0] = temp / a; - res[1] = c / temp; - } - return 2; - } - - /** - * Determines whether a point is inside the area bounded - * by the curve and the straight line connecting its end points. - * - * <p><img src="doc-files/QuadCurve2D-5.png" width="350" height="180" - * alt="A drawing of the area spanned by the curve" /> - * - * <p>The above drawing illustrates in which area points are - * considered “inside” a QuadCurve2D. - */ - public boolean contains(double x, double y) - { - if (! getBounds2D().contains(x, y)) - return false; - - return ((getAxisIntersections(x, y, true, BIG_VALUE) & 1) != 0); - } - - /** - * Determines whether a point is inside the area bounded - * by the curve and the straight line connecting its end points. - * - * <p><img src="doc-files/QuadCurve2D-5.png" width="350" height="180" - * alt="A drawing of the area spanned by the curve" /> - * - * <p>The above drawing illustrates in which area points are - * considered “inside” a QuadCurve2D. - */ - public boolean contains(Point2D p) - { - return contains(p.getX(), p.getY()); - } - - /** - * Determines whether any part of a rectangle is inside the area bounded - * by the curve and the straight line connecting its end points. - * - * <p><img src="doc-files/QuadCurve2D-5.png" width="350" height="180" - * alt="A drawing of the area spanned by the curve" /> - * - * <p>The above drawing illustrates in which area points are - * considered “inside” in a CubicCurve2D. - */ - public boolean intersects(double x, double y, double w, double h) - { - if (! getBounds2D().contains(x, y, w, h)) - return false; - - /* Does any edge intersect? */ - if (getAxisIntersections(x, y, true, w) != 0 /* top */ - || getAxisIntersections(x, y + h, true, w) != 0 /* bottom */ - || getAxisIntersections(x + w, y, false, h) != 0 /* right */ - || getAxisIntersections(x, y, false, h) != 0) /* left */ - return true; - - /* No intersections, is any point inside? */ - if ((getAxisIntersections(x, y, true, BIG_VALUE) & 1) != 0) - return true; - - return false; - } - - /** - * Determines whether any part of a Rectangle2D is inside the area bounded - * by the curve and the straight line connecting its end points. - * @see #intersects(double, double, double, double) - */ - public boolean intersects(Rectangle2D r) - { - return intersects(r.getX(), r.getY(), r.getWidth(), r.getHeight()); - } - - /** - * Determines whether a rectangle is entirely inside the area bounded - * by the curve and the straight line connecting its end points. - * - * <p><img src="doc-files/QuadCurve2D-5.png" width="350" height="180" - * alt="A drawing of the area spanned by the curve" /> - * - * <p>The above drawing illustrates in which area points are - * considered “inside” a QuadCurve2D. - * @see #contains(double, double) - */ - public boolean contains(double x, double y, double w, double h) - { - if (! getBounds2D().intersects(x, y, w, h)) - return false; - - /* Does any edge intersect? */ - if (getAxisIntersections(x, y, true, w) != 0 /* top */ - || getAxisIntersections(x, y + h, true, w) != 0 /* bottom */ - || getAxisIntersections(x + w, y, false, h) != 0 /* right */ - || getAxisIntersections(x, y, false, h) != 0) /* left */ - return false; - - /* No intersections, is any point inside? */ - if ((getAxisIntersections(x, y, true, BIG_VALUE) & 1) != 0) - return true; - - return false; - } - - /** - * Determines whether a Rectangle2D is entirely inside the area that is - * bounded by the curve and the straight line connecting its end points. - * @see #contains(double, double, double, double) - */ - public boolean contains(Rectangle2D r) - { - return contains(r.getX(), r.getY(), r.getWidth(), r.getHeight()); - } - - /** - * Determines the smallest rectangle that encloses the - * curve’s start, end and control point. As the illustration - * below shows, the invisible control point may cause the bounds to - * be much larger than the area that is actually covered by the - * curve. - * - * <p><img src="doc-files/QuadCurve2D-2.png" width="350" height="180" - * alt="An illustration of the bounds of a QuadCurve2D" /> - */ - public Rectangle getBounds() - { - return getBounds2D().getBounds(); - } - - public PathIterator getPathIterator(final AffineTransform at) - { - return new PathIterator() - { - /** Current coordinate. */ - private int current = 0; - - public int getWindingRule() - { - return WIND_NON_ZERO; - } - - public boolean isDone() - { - return current >= 2; - } - - public void next() - { - current++; - } - - public int currentSegment(float[] coords) - { - int result; - switch (current) - { - case 0: - coords[0] = (float) getX1(); - coords[1] = (float) getY1(); - result = SEG_MOVETO; - break; - case 1: - coords[0] = (float) getCtrlX(); - coords[1] = (float) getCtrlY(); - coords[2] = (float) getX2(); - coords[3] = (float) getY2(); - result = SEG_QUADTO; - break; - default: - throw new NoSuchElementException("quad iterator out of bounds"); - } - if (at != null) - at.transform(coords, 0, coords, 0, 2); - return result; - } - - public int currentSegment(double[] coords) - { - int result; - switch (current) - { - case 0: - coords[0] = getX1(); - coords[1] = getY1(); - result = SEG_MOVETO; - break; - case 1: - coords[0] = getCtrlX(); - coords[1] = getCtrlY(); - coords[2] = getX2(); - coords[3] = getY2(); - result = SEG_QUADTO; - break; - default: - throw new NoSuchElementException("quad iterator out of bounds"); - } - if (at != null) - at.transform(coords, 0, coords, 0, 2); - return result; - } - }; - } - - public PathIterator getPathIterator(AffineTransform at, double flatness) - { - return new FlatteningPathIterator(getPathIterator(at), flatness); - } - - /** - * Creates a new curve with the same contents as this one. - * - * @return the clone. - */ - public Object clone() - { - try - { - return super.clone(); - } - catch (CloneNotSupportedException e) - { - throw (Error) new InternalError().initCause(e); // Impossible - } - } - - /** - * Helper method used by contains() and intersects() methods - * Return the number of curve/line intersections on a given axis - * extending from a certain point. useYaxis is true for using the Y axis, - * @param x x coordinate of the origin point - * @param y y coordinate of the origin point - * @param useYaxis axis to follow, if true the positive Y axis is used, - * false uses the positive X axis. - * - * This is an implementation of the line-crossings algorithm, - * Detailed in an article on Eric Haines' page: - * http://www.acm.org/tog/editors/erich/ptinpoly/ - */ - private int getAxisIntersections(double x, double y, boolean useYaxis, - double distance) - { - int nCrossings = 0; - double a0; - double a1; - double a2; - double b0; - double b1; - double b2; - double[] r = new double[3]; - int nRoots; - - a0 = a2 = 0.0; - - if (useYaxis) - { - a0 = getY1() - y; - a1 = getCtrlY() - y; - a2 = getY2() - y; - b0 = getX1() - x; - b1 = getCtrlX() - x; - b2 = getX2() - x; - } - else - { - a0 = getX1() - x; - a1 = getCtrlX() - x; - a2 = getX2() - x; - b0 = getY1() - y; - b1 = getCtrlY() - y; - b2 = getY2() - y; - } - - /* If the axis intersects a start/endpoint, shift it up by some small - amount to guarantee the line is 'inside' - If this is not done,bad behaviour may result for points on that axis. */ - if (a0 == 0.0 || a2 == 0.0) - { - double small = getFlatness() * EPSILON; - if (a0 == 0.0) - a0 -= small; - - if (a2 == 0.0) - a2 -= small; - } - - r[0] = a0; - r[1] = 2 * (a1 - a0); - r[2] = (a2 - 2 * a1 + a0); - - nRoots = solveQuadratic(r); - for (int i = 0; i < nRoots; i++) - { - double t = r[i]; - if (t >= 0.0 && t <= 1.0) - { - double crossing = t * t * (b2 - 2 * b1 + b0) + 2 * t * (b1 - b0) - + b0; - /* single root is always doubly degenerate in quads */ - if (crossing > 0 && crossing < distance) - nCrossings += (nRoots == 1) ? 2 : 1; - } - } - - if (useYaxis) - { - if (Line2D.linesIntersect(b0, a0, b2, a2, EPSILON, 0.0, distance, 0.0)) - nCrossings++; - } - else - { - if (Line2D.linesIntersect(a0, b0, a2, b2, 0.0, EPSILON, 0.0, distance)) - nCrossings++; - } - - return (nCrossings); - } - - /** - * A two-dimensional curve that is parameterized with a quadratic - * function and stores coordinate values in double-precision - * floating-point format. - * - * @see QuadCurve2D.Float - * - * @author Eric Blake (ebb9@email.byu.edu) - * @author Sascha Brawer (brawer@dandelis.ch) - */ - public static class Double extends QuadCurve2D - { - /** - * The <i>x</i> coordinate of the curve’s start point. - */ - public double x1; - - /** - * The <i>y</i> coordinate of the curve’s start point. - */ - public double y1; - - /** - * The <i>x</i> coordinate of the curve’s control point. - */ - public double ctrlx; - - /** - * The <i>y</i> coordinate of the curve’s control point. - */ - public double ctrly; - - /** - * The <i>x</i> coordinate of the curve’s end point. - */ - public double x2; - - /** - * The <i>y</i> coordinate of the curve’s end point. - */ - public double y2; - - /** - * Constructs a new QuadCurve2D that stores its coordinate values - * in double-precision floating-point format. All points are - * initially at position (0, 0). - */ - public Double() - { - } - - /** - * Constructs a new QuadCurve2D that stores its coordinate values - * in double-precision floating-point format, specifying the - * initial position of each point. - * - * @param x1 the <i>x</i> coordinate of the curve’s start - * point. - * - * @param y1 the <i>y</i> coordinate of the curve’s start - * point. - * - * @param cx the <i>x</i> coordinate of the curve’s control - * point. - * - * @param cy the <i>y</i> coordinate of the curve’s control - * point. - * - * @param x2 the <i>x</i> coordinate of the curve’s end - * point. - * - * @param y2 the <i>y</i> coordinate of the curve’s end - * point. - */ - public Double(double x1, double y1, double cx, double cy, double x2, - double y2) - { - this.x1 = x1; - this.y1 = y1; - ctrlx = cx; - ctrly = cy; - this.x2 = x2; - this.y2 = y2; - } - - /** - * Returns the <i>x</i> coordinate of the curve’s start - * point. - */ - public double getX1() - { - return x1; - } - - /** - * Returns the <i>y</i> coordinate of the curve’s start - * point. - */ - public double getY1() - { - return y1; - } - - /** - * Returns the curve’s start point. - */ - public Point2D getP1() - { - return new Point2D.Double(x1, y1); - } - - /** - * Returns the <i>x</i> coordinate of the curve’s control - * point. - */ - public double getCtrlX() - { - return ctrlx; - } - - /** - * Returns the <i>y</i> coordinate of the curve’s control - * point. - */ - public double getCtrlY() - { - return ctrly; - } - - /** - * Returns the curve’s control point. - */ - public Point2D getCtrlPt() - { - return new Point2D.Double(ctrlx, ctrly); - } - - /** - * Returns the <i>x</i> coordinate of the curve’s end - * point. - */ - public double getX2() - { - return x2; - } - - /** - * Returns the <i>y</i> coordinate of the curve’s end - * point. - */ - public double getY2() - { - return y2; - } - - /** - * Returns the curve’s end point. - */ - public Point2D getP2() - { - return new Point2D.Double(x2, y2); - } - - /** - * Changes the geometry of the curve. - * - * @param x1 the <i>x</i> coordinate of the curve’s new - * start point. - * - * @param y1 the <i>y</i> coordinate of the curve’s new - * start point. - * - * @param cx the <i>x</i> coordinate of the curve’s new - * control point. - * - * @param cy the <i>y</i> coordinate of the curve’s new - * control point. - * - * @param x2 the <i>x</i> coordinate of the curve’s new - * end point. - * - * @param y2 the <i>y</i> coordinate of the curve’s new - * end point. - */ - public void setCurve(double x1, double y1, double cx, double cy, - double x2, double y2) - { - this.x1 = x1; - this.y1 = y1; - ctrlx = cx; - ctrly = cy; - this.x2 = x2; - this.y2 = y2; - } - - /** - * Determines the smallest rectangle that encloses the - * curve’s start, end and control point. As the - * illustration below shows, the invisible control point may cause - * the bounds to be much larger than the area that is actually - * covered by the curve. - * - * <p><img src="doc-files/QuadCurve2D-2.png" width="350" height="180" - * alt="An illustration of the bounds of a QuadCurve2D" /> - */ - public Rectangle2D getBounds2D() - { - double nx1 = Math.min(Math.min(x1, ctrlx), x2); - double ny1 = Math.min(Math.min(y1, ctrly), y2); - double nx2 = Math.max(Math.max(x1, ctrlx), x2); - double ny2 = Math.max(Math.max(y1, ctrly), y2); - return new Rectangle2D.Double(nx1, ny1, nx2 - nx1, ny2 - ny1); - } - } - - /** - * A two-dimensional curve that is parameterized with a quadratic - * function and stores coordinate values in single-precision - * floating-point format. - * - * @see QuadCurve2D.Double - * - * @author Eric Blake (ebb9@email.byu.edu) - * @author Sascha Brawer (brawer@dandelis.ch) - */ - public static class Float extends QuadCurve2D - { - /** - * The <i>x</i> coordinate of the curve’s start point. - */ - public float x1; - - /** - * The <i>y</i> coordinate of the curve’s start point. - */ - public float y1; - - /** - * The <i>x</i> coordinate of the curve’s control point. - */ - public float ctrlx; - - /** - * The <i>y</i> coordinate of the curve’s control point. - */ - public float ctrly; - - /** - * The <i>x</i> coordinate of the curve’s end point. - */ - public float x2; - - /** - * The <i>y</i> coordinate of the curve’s end point. - */ - public float y2; - - /** - * Constructs a new QuadCurve2D that stores its coordinate values - * in single-precision floating-point format. All points are - * initially at position (0, 0). - */ - public Float() - { - } - - /** - * Constructs a new QuadCurve2D that stores its coordinate values - * in single-precision floating-point format, specifying the - * initial position of each point. - * - * @param x1 the <i>x</i> coordinate of the curve’s start - * point. - * - * @param y1 the <i>y</i> coordinate of the curve’s start - * point. - * - * @param cx the <i>x</i> coordinate of the curve’s control - * point. - * - * @param cy the <i>y</i> coordinate of the curve’s control - * point. - * - * @param x2 the <i>x</i> coordinate of the curve’s end - * point. - * - * @param y2 the <i>y</i> coordinate of the curve’s end - * point. - */ - public Float(float x1, float y1, float cx, float cy, float x2, float y2) - { - this.x1 = x1; - this.y1 = y1; - ctrlx = cx; - ctrly = cy; - this.x2 = x2; - this.y2 = y2; - } - - /** - * Returns the <i>x</i> coordinate of the curve’s start - * point. - */ - public double getX1() - { - return x1; - } - - /** - * Returns the <i>y</i> coordinate of the curve’s start - * point. - */ - public double getY1() - { - return y1; - } - - /** - * Returns the curve’s start point. - */ - public Point2D getP1() - { - return new Point2D.Float(x1, y1); - } - - /** - * Returns the <i>x</i> coordinate of the curve’s control - * point. - */ - public double getCtrlX() - { - return ctrlx; - } - - /** - * Returns the <i>y</i> coordinate of the curve’s control - * point. - */ - public double getCtrlY() - { - return ctrly; - } - - /** - * Returns the curve’s control point. - */ - public Point2D getCtrlPt() - { - return new Point2D.Float(ctrlx, ctrly); - } - - /** - * Returns the <i>x</i> coordinate of the curve’s end - * point. - */ - public double getX2() - { - return x2; - } - - /** - * Returns the <i>y</i> coordinate of the curve’s end - * point. - */ - public double getY2() - { - return y2; - } - - /** - * Returns the curve’s end point. - */ - public Point2D getP2() - { - return new Point2D.Float(x2, y2); - } - - /** - * Changes the geometry of the curve, specifying coordinate values - * as double-precision floating-point numbers. - * - * @param x1 the <i>x</i> coordinate of the curve’s new - * start point. - * - * @param y1 the <i>y</i> coordinate of the curve’s new - * start point. - * - * @param cx the <i>x</i> coordinate of the curve’s new - * control point. - * - * @param cy the <i>y</i> coordinate of the curve’s new - * control point. - * - * @param x2 the <i>x</i> coordinate of the curve’s new - * end point. - * - * @param y2 the <i>y</i> coordinate of the curve’s new - * end point. - */ - public void setCurve(double x1, double y1, double cx, double cy, - double x2, double y2) - { - this.x1 = (float) x1; - this.y1 = (float) y1; - ctrlx = (float) cx; - ctrly = (float) cy; - this.x2 = (float) x2; - this.y2 = (float) y2; - } - - /** - * Changes the geometry of the curve, specifying coordinate values - * as single-precision floating-point numbers. - * - * @param x1 the <i>x</i> coordinate of the curve’s new - * start point. - * - * @param y1 the <i>y</i> coordinate of the curve’s new - * start point. - * - * @param cx the <i>x</i> coordinate of the curve’s new - * control point. - * - * @param cy the <i>y</i> coordinate of the curve’s new - * control point. - * - * @param x2 the <i>x</i> coordinate of the curve’s new - * end point. - * - * @param y2 the <i>y</i> coordinate of the curve’s new - * end point. - */ - public void setCurve(float x1, float y1, float cx, float cy, float x2, - float y2) - { - this.x1 = x1; - this.y1 = y1; - ctrlx = cx; - ctrly = cy; - this.x2 = x2; - this.y2 = y2; - } - - /** - * Determines the smallest rectangle that encloses the - * curve’s start, end and control point. As the - * illustration below shows, the invisible control point may cause - * the bounds to be much larger than the area that is actually - * covered by the curve. - * - * <p><img src="doc-files/QuadCurve2D-2.png" width="350" height="180" - * alt="An illustration of the bounds of a QuadCurve2D" /> - */ - public Rectangle2D getBounds2D() - { - float nx1 = (float) Math.min(Math.min(x1, ctrlx), x2); - float ny1 = (float) Math.min(Math.min(y1, ctrly), y2); - float nx2 = (float) Math.max(Math.max(x1, ctrlx), x2); - float ny2 = (float) Math.max(Math.max(y1, ctrly), y2); - return new Rectangle2D.Float(nx1, ny1, nx2 - nx1, ny2 - ny1); - } - } -} diff --git a/libjava/java/awt/geom/Rectangle2D.java b/libjava/java/awt/geom/Rectangle2D.java deleted file mode 100644 index 6a255f95391..00000000000 --- a/libjava/java/awt/geom/Rectangle2D.java +++ /dev/null @@ -1,992 +0,0 @@ -/* Rectangle2D.java -- generic rectangles in 2-D space - Copyright (C) 2000, 2001, 2002, 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.geom; - -import java.util.NoSuchElementException; - -/** - * This class describes a rectangle by a point (x,y) and dimension (w x h). - * The actual storage is left up to subclasses. - * - * <p>It is valid for a rectangle to have negative width or height; but it - * is considered to have no area or internal points. Therefore, the behavior - * in methods like <code>contains</code> or <code>intersects</code> is - * undefined unless the rectangle has positive width and height. - * - * @author Tom Tromey (tromey@cygnus.com) - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.2 - * @status updated to 1.4 - */ -public abstract class Rectangle2D extends RectangularShape -{ - /** - * The point lies left of the rectangle (p.x < r.x). - * - * @see #outcode(double, double) - */ - public static final int OUT_LEFT = 1; - - /** - * The point lies above the rectangle (p.y < r.y). - * - * @see #outcode(double, double) - */ - public static final int OUT_TOP = 2; - - /** - * The point lies right of the rectangle (p.x > r.maxX). - * - * @see #outcode(double, double) - */ - public static final int OUT_RIGHT = 4; - - /** - * The point lies below of the rectangle (p.y > r.maxY). - * - * @see #outcode(double, double) - */ - public static final int OUT_BOTTOM = 8; - - /** - * Default constructor. - */ - protected Rectangle2D() - { - } - - /** - * Set the bounding box of this rectangle. - * - * @param x the new X coordinate - * @param y the new Y coordinate - * @param w the new width - * @param h the new height - */ - public abstract void setRect(double x, double y, double w, double h); - - /** - * Set the bounding box of this rectangle from the given one. - * - * @param r rectangle to copy - * @throws NullPointerException if r is null - */ - public void setRect(Rectangle2D r) - { - setRect(r.getX(), r.getY(), r.getWidth(), r.getHeight()); - } - - /** - * Tests if the specified line intersects the interior of this rectangle. - * - * @param x1 the first x coordinate of line segment - * @param y1 the first y coordinate of line segment - * @param x2 the second x coordinate of line segment - * @param y2 the second y coordinate of line segment - * @return true if the line intersects the rectangle - */ - public boolean intersectsLine(double x1, double y1, double x2, double y2) - { - double x = getX(); - double y = getY(); - double w = getWidth(); - double h = getHeight(); - if (w <= 0 || h <= 0) - return false; - - if (x1 >= x && x1 <= x + w && y1 >= y && y1 <= y + h) - return true; - if (x2 >= x && x2 <= x + w && y2 >= y && y2 <= y + h) - return true; - - double x3 = x + w; - double y3 = y + h; - - return (Line2D.linesIntersect(x1, y1, x2, y2, x, y, x, y3) - || Line2D.linesIntersect(x1, y1, x2, y2, x, y3, x3, y3) - || Line2D.linesIntersect(x1, y1, x2, y2, x3, y3, x3, y) - || Line2D.linesIntersect(x1, y1, x2, y2, x3, y, x, y)); - } - - /** - * Tests if the specified line intersects the interior of this rectangle. - * - * @param l the line segment - * @return true if the line intersects the rectangle - * @throws NullPointerException if l is null - */ - public boolean intersectsLine(Line2D l) - { - return intersectsLine(l.getX1(), l.getY1(), l.getX2(), l.getY2()); - } - - /** - * Determine where the point lies with respect to this rectangle. The - * result will be the binary OR of the appropriate bit masks. - * - * @param x the x coordinate to check - * @param y the y coordinate to check - * @return the binary OR of the result - * @see #OUT_LEFT - * @see #OUT_TOP - * @see #OUT_RIGHT - * @see #OUT_BOTTOM - */ - public abstract int outcode(double x, double y); - - /** - * Determine where the point lies with respect to this rectangle. The - * result will be the binary OR of the appropriate bit masks. - * - * @param p the point to check - * @return the binary OR of the result - * @throws NullPointerException if p is null - * @see #OUT_LEFT - * @see #OUT_TOP - * @see #OUT_RIGHT - * @see #OUT_BOTTOM - */ - public int outcode(Point2D p) - { - return outcode(p.getX(), p.getY()); - } - - /** - * Set the bounding box of this rectangle. - * - * @param x the new X coordinate - * @param y the new Y coordinate - * @param w the new width - * @param h the new height - */ - public void setFrame(double x, double y, double w, double h) - { - setRect(x, y, w, h); - } - - /** - * Returns the bounds of this rectangle. A pretty useless method, as this - * is already a rectangle. - * - * @return a copy of this rectangle - */ - public Rectangle2D getBounds2D() - { - return (Rectangle2D) clone(); - } - - /** - * Test if the given point is contained in the rectangle. - * - * @param x the x coordinate of the point - * @param y the y coordinate of the point - * @return true if (x,y) is in the rectangle - */ - public boolean contains(double x, double y) - { - double mx = getX(); - double my = getY(); - double w = getWidth(); - double h = getHeight(); - return w > 0 && h > 0 && x >= mx && x < mx + w && y >= my && y < my + h; - } - - /** - * Tests if the given rectangle intersects this one. In other words, test if - * the two rectangles share at least one internal point. - * - * @param x the x coordinate of the other rectangle - * @param y the y coordinate of the other rectangle - * @param w the width of the other rectangle - * @param h the height of the other rectangle - * @return true if the rectangles intersect - */ - public boolean intersects(double x, double y, double w, double h) - { - double mx = getX(); - double my = getY(); - double mw = getWidth(); - double mh = getHeight(); - return w > 0 && h > 0 && mw > 0 && mh > 0 - && x < mx + mw && x + w > mx && y < my + mh && y + h > my; - } - - /** - * Tests if this rectangle contains the given one. In other words, test if - * this rectangle contains all points in the given one. - * - * @param x the x coordinate of the other rectangle - * @param y the y coordinate of the other rectangle - * @param w the width of the other rectangle - * @param h the height of the other rectangle - * @return true if this rectangle contains the other - */ - public boolean contains(double x, double y, double w, double h) - { - double mx = getX(); - double my = getY(); - double mw = getWidth(); - double mh = getHeight(); - return w > 0 && h > 0 && mw > 0 && mh > 0 - && x >= mx && x + w <= mx + mw && y >= my && y + h <= my + mh; - } - - /** - * Return a new rectangle which is the intersection of this and the given - * one. The result will be empty if there is no intersection. - * - * @param r the rectangle to be intersected - * @return the intersection - * @throws NullPointerException if r is null - */ - public abstract Rectangle2D createIntersection(Rectangle2D r); - - /** - * Intersects a pair of rectangles, and places the result in the - * destination; this can be used to avoid object creation. This method - * even works when the destination is also a source, although you stand - * to lose the original data. - * - * @param src1 the first source - * @param src2 the second source - * @param dest the destination for the intersection - * @throws NullPointerException if any rectangle is null - */ - public static void intersect(Rectangle2D src1, Rectangle2D src2, - Rectangle2D dest) - { - double x = Math.max(src1.getX(), src2.getX()); - double y = Math.max(src1.getY(), src2.getY()); - double maxx = Math.min(src1.getMaxX(), src2.getMaxX()); - double maxy = Math.min(src1.getMaxY(), src2.getMaxY()); - dest.setRect(x, y, maxx - x, maxy - y); - } - - /** - * Return a new rectangle which is the union of this and the given one. - * - * @param r the rectangle to be merged - * @return the union - * @throws NullPointerException if r is null - */ - public abstract Rectangle2D createUnion(Rectangle2D r); - - /** - * Joins a pair of rectangles, and places the result in the destination; - * this can be used to avoid object creation. This method even works when - * the destination is also a source, although you stand to lose the - * original data. - * - * @param src1 the first source - * @param src2 the second source - * @param dest the destination for the union - * @throws NullPointerException if any rectangle is null - */ - public static void union(Rectangle2D src1, Rectangle2D src2, - Rectangle2D dest) - { - double x = Math.min(src1.getX(), src2.getX()); - double y = Math.min(src1.getY(), src2.getY()); - double maxx = Math.max(src1.getMaxX(), src2.getMaxX()); - double maxy = Math.max(src1.getMaxY(), src2.getMaxY()); - dest.setRect(x, y, maxx - x, maxy - y); - } - - /** - * Modifies this rectangle so that it represents the smallest rectangle - * that contains both the existing rectangle and the specified point. - * However, if the point falls on one of the two borders which are not - * inside the rectangle, a subsequent call to <code>contains</code> may - * return false. - * - * @param newx the X coordinate of the point to add to this rectangle - * @param newy the Y coordinate of the point to add to this rectangle - */ - public void add(double newx, double newy) - { - double minx = Math.min(getX(), newx); - double maxx = Math.max(getMaxX(), newx); - double miny = Math.min(getY(), newy); - double maxy = Math.max(getMaxY(), newy); - setRect(minx, miny, maxx - minx, maxy - miny); - } - - /** - * Modifies this rectangle so that it represents the smallest rectangle - * that contains both the existing rectangle and the specified point. - * However, if the point falls on one of the two borders which are not - * inside the rectangle, a subsequent call to <code>contains</code> may - * return false. - * - * @param p the point to add to this rectangle - * @throws NullPointerException if p is null - */ - public void add(Point2D p) - { - add(p.getX(), p.getY()); - } - - /** - * Modifies this rectangle so that it represents the smallest rectangle - * that contains both the existing rectangle and the specified rectangle. - * - * @param r the rectangle to add to this rectangle - * @throws NullPointerException if r is null - * @see #union(Rectangle2D, Rectangle2D, Rectangle2D) - */ - public void add(Rectangle2D r) - { - union(this, r, this); - } - - /** - * Return an iterator along the shape boundary. If the optional transform - * is provided, the iterator is transformed accordingly. Each call returns - * a new object, independent from others in use. This iterator is thread - * safe; modifications to the rectangle do not affect the results of this - * path instance. - * - * @param at an optional transform to apply to the iterator - * @return a new iterator over the boundary - * @since 1.2 - */ - public PathIterator getPathIterator(final AffineTransform at) - { - final double minx = getX(); - final double miny = getY(); - final double maxx = minx + getWidth(); - final double maxy = miny + getHeight(); - return new PathIterator() - { - /** Current coordinate. */ - private int current = (maxx <= minx && maxy <= miny) ? 6 : 0; - - public int getWindingRule() - { - // A test program showed that Sun J2SE 1.3.1 and 1.4.1_01 - // return WIND_NON_ZERO paths. While this does not really - // make any difference for rectangles (because they are not - // self-intersecting), it seems appropriate to behave - // identically. - - return WIND_NON_ZERO; - } - - public boolean isDone() - { - return current > 5; - } - - public void next() - { - current++; - } - - public int currentSegment(float[] coords) - { - switch (current) - { - case 1: - coords[0] = (float) maxx; - coords[1] = (float) miny; - break; - case 2: - coords[0] = (float) maxx; - coords[1] = (float) maxy; - break; - case 3: - coords[0] = (float) minx; - coords[1] = (float) maxy; - break; - case 0: - case 4: - coords[0] = (float) minx; - coords[1] = (float) miny; - break; - case 5: - return SEG_CLOSE; - default: - throw new NoSuchElementException("rect iterator out of bounds"); - } - if (at != null) - at.transform(coords, 0, coords, 0, 1); - return current == 0 ? SEG_MOVETO : SEG_LINETO; - } - - public int currentSegment(double[] coords) - { - switch (current) - { - case 1: - coords[0] = maxx; - coords[1] = miny; - break; - case 2: - coords[0] = maxx; - coords[1] = maxy; - break; - case 3: - coords[0] = minx; - coords[1] = maxy; - break; - case 0: - case 4: - coords[0] = minx; - coords[1] = miny; - break; - case 5: - return SEG_CLOSE; - default: - throw new NoSuchElementException("rect iterator out of bounds"); - } - if (at != null) - at.transform(coords, 0, coords, 0, 1); - return current == 0 ? SEG_MOVETO : SEG_LINETO; - } - }; - } - - /** - * Return an iterator along the shape boundary. If the optional transform - * is provided, the iterator is transformed accordingly. Each call returns - * a new object, independent from others in use. This iterator is thread - * safe; modifications to the rectangle do not affect the results of this - * path instance. As the rectangle is already flat, the flatness parameter - * is ignored. - * - * @param at an optional transform to apply to the iterator - * @param flatness the maximum distance for deviation from the real boundary - * @return a new iterator over the boundary - * @since 1.2 - */ - public PathIterator getPathIterator(AffineTransform at, double flatness) - { - return getPathIterator(at); - } - - /** - * Return the hashcode for this rectangle. The formula is not documented, but - * appears to be the same as: - * <pre> - * long l = Double.doubleToLongBits(getX()) - * + 37 * Double.doubleToLongBits(getY()) - * + 43 * Double.doubleToLongBits(getWidth()) - * + 47 * Double.doubleToLongBits(getHeight()); - * return (int) ((l >> 32) ^ l); - * </pre> - * - * @return the hashcode - */ - public int hashCode() - { - // Talk about a fun time reverse engineering this one! - long l = java.lang.Double.doubleToLongBits(getX()) - + 37 * java.lang.Double.doubleToLongBits(getY()) - + 43 * java.lang.Double.doubleToLongBits(getWidth()) - + 47 * java.lang.Double.doubleToLongBits(getHeight()); - return (int) ((l >> 32) ^ l); - } - - /** - * Tests this rectangle for equality against the specified object. This - * will be true if an only if the specified object is an instance of - * Rectangle2D with the same coordinates and dimensions. - * - * @param obj the object to test against for equality - * @return true if the specified object is equal to this one - */ - public boolean equals(Object obj) - { - if (! (obj instanceof Rectangle2D)) - return false; - Rectangle2D r = (Rectangle2D) obj; - return r.getX() == getX() && r.getY() == getY() - && r.getWidth() == getWidth() && r.getHeight() == getHeight(); - } - - /** - * This class defines a rectangle in <code>double</code> precision. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.2 - * @status updated to 1.4 - */ - public static class Double extends Rectangle2D - { - /** The x coordinate of the lower left corner. */ - public double x; - - /** The y coordinate of the lower left corner. */ - public double y; - - /** The width of the rectangle. */ - public double width; - - /** The height of the rectangle. */ - public double height; - - /** - * Create a rectangle at (0,0) with width 0 and height 0. - */ - public Double() - { - } - - /** - * Create a rectangle with the given values. - * - * @param x the x coordinate - * @param y the y coordinate - * @param w the width - * @param h the height - */ - public Double(double x, double y, double w, double h) - { - this.x = x; - this.y = y; - width = w; - height = h; - } - - /** - * Return the X coordinate. - * - * @return the value of x - */ - public double getX() - { - return x; - } - - /** - * Return the Y coordinate. - * - * @return the value of y - */ - public double getY() - { - return y; - } - - /** - * Return the width. - * - * @return the value of width - */ - public double getWidth() - { - return width; - } - - /** - * Return the height. - * - * @return the value of height - */ - public double getHeight() - { - return height; - } - - /** - * Test if the rectangle is empty. - * - * @return true if width or height is not positive - */ - public boolean isEmpty() - { - return width <= 0 || height <= 0; - } - - /** - * Set the contents of this rectangle to those specified. - * - * @param x the x coordinate - * @param y the y coordinate - * @param w the width - * @param h the height - */ - public void setRect(double x, double y, double w, double h) - { - this.x = x; - this.y = y; - width = w; - height = h; - } - - /** - * Set the contents of this rectangle to those specified. - * - * @param r the rectangle to copy - * @throws NullPointerException if r is null - */ - public void setRect(Rectangle2D r) - { - x = r.getX(); - y = r.getY(); - width = r.getWidth(); - height = r.getHeight(); - } - - /** - * Determine where the point lies with respect to this rectangle. The - * result will be the binary OR of the appropriate bit masks. - * - * @param x the x coordinate to check - * @param y the y coordinate to check - * @return the binary OR of the result - * @see #OUT_LEFT - * @see #OUT_TOP - * @see #OUT_RIGHT - * @see #OUT_BOTTOM - * @since 1.2 - */ - public int outcode(double x, double y) - { - int result = 0; - if (width <= 0) - result |= OUT_LEFT | OUT_RIGHT; - else if (x < this.x) - result |= OUT_LEFT; - else if (x > this.x + width) - result |= OUT_RIGHT; - if (height <= 0) - result |= OUT_BOTTOM | OUT_TOP; - else if (y < this.y) // Remember that +y heads top-to-bottom. - result |= OUT_TOP; - else if (y > this.y + height) - result |= OUT_BOTTOM; - return result; - } - - /** - * Returns the bounds of this rectangle. A pretty useless method, as this - * is already a rectangle. - * - * @return a copy of this rectangle - */ - public Rectangle2D getBounds2D() - { - return new Double(x, y, width, height); - } - - /** - * Return a new rectangle which is the intersection of this and the given - * one. The result will be empty if there is no intersection. - * - * @param r the rectangle to be intersected - * @return the intersection - * @throws NullPointerException if r is null - */ - public Rectangle2D createIntersection(Rectangle2D r) - { - Double res = new Double(); - intersect(this, r, res); - return res; - } - - /** - * Return a new rectangle which is the union of this and the given one. - * - * @param r the rectangle to be merged - * @return the union - * @throws NullPointerException if r is null - */ - public Rectangle2D createUnion(Rectangle2D r) - { - Double res = new Double(); - union(this, r, res); - return res; - } - - /** - * Returns a string representation of this rectangle. This is in the form - * <code>getClass().getName() + "[x=" + x + ",y=" + y + ",w=" + width - * + ",h=" + height + ']'</code>. - * - * @return a string representation of this rectangle - */ - public String toString() - { - return getClass().getName() + "[x=" + x + ",y=" + y + ",w=" + width - + ",h=" + height + ']'; - } - } - - /** - * This class defines a rectangle in <code>float</code> precision. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.2 - * @status updated to 1.4 - */ - public static class Float extends Rectangle2D - { - /** The x coordinate of the lower left corner. */ - public float x; - - /** The y coordinate of the lower left corner. */ - public float y; - - /** The width of the rectangle. */ - public float width; - - /** The height of the rectangle. */ - public float height; - - /** - * Create a rectangle at (0,0) with width 0 and height 0. - */ - public Float() - { - } - - /** - * Create a rectangle with the given values. - * - * @param x the x coordinate - * @param y the y coordinate - * @param w the width - * @param h the height - */ - public Float(float x, float y, float w, float h) - { - this.x = x; - this.y = y; - width = w; - height = h; - } - - /** - * Create a rectangle with the given values. - * - * @param x the x coordinate - * @param y the y coordinate - * @param w the width - * @param h the height - */ - Float(double x, double y, double w, double h) - { - this.x = (float) x; - this.y = (float) y; - width = (float) w; - height = (float) h; - } - - /** - * Return the X coordinate. - * - * @return the value of x - */ - public double getX() - { - return x; - } - - /** - * Return the Y coordinate. - * - * @return the value of y - */ - public double getY() - { - return y; - } - - /** - * Return the width. - * - * @return the value of width - */ - public double getWidth() - { - return width; - } - - /** - * Return the height. - * - * @return the value of height - */ - public double getHeight() - { - return height; - } - - /** - * Test if the rectangle is empty. - * - * @return true if width or height is not positive - */ - public boolean isEmpty() - { - return width <= 0 || height <= 0; - } - - /** - * Set the contents of this rectangle to those specified. - * - * @param x the x coordinate - * @param y the y coordinate - * @param w the width - * @param h the height - */ - public void setRect(float x, float y, float w, float h) - { - this.x = x; - this.y = y; - width = w; - height = h; - } - - /** - * Set the contents of this rectangle to those specified. - * - * @param x the x coordinate - * @param y the y coordinate - * @param w the width - * @param h the height - */ - public void setRect(double x, double y, double w, double h) - { - this.x = (float) x; - this.y = (float) y; - width = (float) w; - height = (float) h; - } - - /** - * Set the contents of this rectangle to those specified. - * - * @param r the rectangle to copy - * @throws NullPointerException if r is null - */ - public void setRect(Rectangle2D r) - { - x = (float) r.getX(); - y = (float) r.getY(); - width = (float) r.getWidth(); - height = (float) r.getHeight(); - } - - /** - * Determine where the point lies with respect to this rectangle. The - * result will be the binary OR of the appropriate bit masks. - * - * @param x the x coordinate to check - * @param y the y coordinate to check - * @return the binary OR of the result - * @see #OUT_LEFT - * @see #OUT_TOP - * @see #OUT_RIGHT - * @see #OUT_BOTTOM - * @since 1.2 - */ - public int outcode(double x, double y) - { - int result = 0; - if (width <= 0) - result |= OUT_LEFT | OUT_RIGHT; - else if (x < this.x) - result |= OUT_LEFT; - else if (x > this.x + width) - result |= OUT_RIGHT; - if (height <= 0) - result |= OUT_BOTTOM | OUT_TOP; - else if (y < this.y) // Remember that +y heads top-to-bottom. - result |= OUT_TOP; - else if (y > this.y + height) - result |= OUT_BOTTOM; - return result; - } - - /** - * Returns the bounds of this rectangle. A pretty useless method, as this - * is already a rectangle. - * - * @return a copy of this rectangle - */ - public Rectangle2D getBounds2D() - { - return new Float(x, y, width, height); - } - - /** - * Return a new rectangle which is the intersection of this and the given - * one. The result will be empty if there is no intersection. - * - * @param r the rectangle to be intersected - * @return the intersection - * @throws NullPointerException if r is null - */ - public Rectangle2D createIntersection(Rectangle2D r) - { - Float res = new Float(); - intersect(this, r, res); - return res; - } - - /** - * Return a new rectangle which is the union of this and the given one. - * - * @param r the rectangle to be merged - * @return the union - * @throws NullPointerException if r is null - */ - public Rectangle2D createUnion(Rectangle2D r) - { - Float res = new Float(); - union(this, r, res); - return res; - } - - /** - * Returns a string representation of this rectangle. This is in the form - * <code>getClass().getName() + "[x=" + x + ",y=" + y + ",w=" + width - * + ",h=" + height + ']'</code>. - * - * @return a string representation of this rectangle - */ - public String toString() - { - return getClass().getName() + "[x=" + x + ",y=" + y + ",w=" + width - + ",h=" + height + ']'; - } - } -} diff --git a/libjava/java/awt/geom/RectangularShape.java b/libjava/java/awt/geom/RectangularShape.java deleted file mode 100644 index 8f66dabf2e7..00000000000 --- a/libjava/java/awt/geom/RectangularShape.java +++ /dev/null @@ -1,385 +0,0 @@ -/* RectangularShape.java -- a rectangular frame for several generic shapes - Copyright (C) 2000, 2002 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.geom; - -import java.awt.Rectangle; -import java.awt.Shape; - -/** - * This class provides a generic framework, and several helper methods, for - * subclasses which represent geometric objects inside a rectangular frame. - * This does not specify any geometry except for the bounding box. - * - * @author Tom Tromey (tromey@cygnus.com) - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.2 - * @see Arc2D - * @see Ellipse2D - * @see Rectangle2D - * @see RoundRectangle2D - * @status updated to 1.4 - */ -public abstract class RectangularShape implements Shape, Cloneable -{ - /** - * Default constructor. - */ - protected RectangularShape() - { - } - - /** - * Get the x coordinate of the upper-left corner of the framing rectangle. - * - * @return the x coordinate - */ - public abstract double getX(); - - /** - * Get the y coordinate of the upper-left corner of the framing rectangle. - * - * @return the y coordinate - */ - public abstract double getY(); - - /** - * Get the width of the framing rectangle. - * - * @return the width - */ - public abstract double getWidth(); - - /** - * Get the height of the framing rectangle. - * - * @return the height - */ - public abstract double getHeight(); - - /** - * Get the minimum x coordinate in the frame. This is misnamed, or else - * Sun has a bug, because the implementation returns getX() even when - * getWidth() is negative. - * - * @return the minimum x coordinate - */ - public double getMinX() - { - return getX(); - } - - /** - * Get the minimum y coordinate in the frame. This is misnamed, or else - * Sun has a bug, because the implementation returns getY() even when - * getHeight() is negative. - * - * @return the minimum y coordinate - */ - public double getMinY() - { - return getY(); - } - - /** - * Get the maximum x coordinate in the frame. This is misnamed, or else - * Sun has a bug, because the implementation returns getX()+getWidth() even - * when getWidth() is negative. - * - * @return the maximum x coordinate - */ - public double getMaxX() - { - return getX() + getWidth(); - } - - /** - * Get the maximum y coordinate in the frame. This is misnamed, or else - * Sun has a bug, because the implementation returns getY()+getHeight() even - * when getHeight() is negative. - * - * @return the maximum y coordinate - */ - public double getMaxY() - { - return getY() + getHeight(); - } - - /** - * Return the x coordinate of the center point of the framing rectangle. - * - * @return the central x coordinate - */ - public double getCenterX() - { - return getX() + getWidth() / 2; - } - - /** - * Return the y coordinate of the center point of the framing rectangle. - * - * @return the central y coordinate - */ - public double getCenterY() - { - return getY() + getHeight() / 2; - } - - /** - * Return the frame around this object. Note that this may be a looser - * bounding box than getBounds2D. - * - * @return the frame, in double precision - * @see #setFrame(double, double, double, double) - */ - public Rectangle2D getFrame() - { - return new Rectangle2D.Double(getX(), getY(), getWidth(), getHeight()); - } - - /** - * Test if the shape is empty, meaning that no points are inside it. - * - * @return true if the shape is empty - */ - public abstract boolean isEmpty(); - - /** - * Set the framing rectangle of this shape to the given coordinate and size. - * - * @param x the new x coordinate - * @param y the new y coordinate - * @param w the new width - * @param h the new height - * @see #getFrame() - */ - public abstract void setFrame(double x, double y, double w, double h); - - /** - * Set the framing rectangle of this shape to the given coordinate and size. - * - * @param p the new point - * @param d the new dimension - * @throws NullPointerException if p or d is null - * @see #getFrame() - */ - public void setFrame(Point2D p, Dimension2D d) - { - setFrame(p.getX(), p.getY(), d.getWidth(), d.getHeight()); - } - - /** - * Set the framing rectangle of this shape to the given rectangle. - * - * @param r the new framing rectangle - * @throws NullPointerException if r is null - * @see #getFrame() - */ - public void setFrame(Rectangle2D r) - { - setFrame(r.getX(), r.getY(), r.getWidth(), r.getHeight()); - } - - /** - * Set the framing rectangle of this shape using two points on a diagonal. - * The area will be positive. - * - * @param x1 the first x coordinate - * @param y1 the first y coordinate - * @param x2 the second x coordinate - * @param y2 the second y coordinate - */ - public void setFrameFromDiagonal(double x1, double y1, double x2, double y2) - { - if (x1 > x2) - { - double t = x2; - x2 = x1; - x1 = t; - } - if (y1 > y2) - { - double t = y2; - y2 = y1; - y1 = t; - } - setFrame(x1, y1, x2 - x1, y2 - y1); - } - - /** - * Set the framing rectangle of this shape using two points on a diagonal. - * The area will be positive. - * - * @param p1 the first point - * @param p2 the second point - * @throws NullPointerException if either point is null - */ - public void setFrameFromDiagonal(Point2D p1, Point2D p2) - { - setFrameFromDiagonal(p1.getX(), p1.getY(), p2.getX(), p2.getY()); - } - - /** - * Set the framing rectangle of this shape using the center of the frame, - * and one of the four corners. The area will be positive. - * - * @param centerX the x coordinate at the center - * @param centerY the y coordinate at the center - * @param cornerX the x coordinate at a corner - * @param cornerY the y coordinate at a corner - */ - public void setFrameFromCenter(double centerX, double centerY, - double cornerX, double cornerY) - { - double halfw = Math.abs(cornerX - centerX); - double halfh = Math.abs(cornerY - centerY); - setFrame(centerX - halfw, centerY - halfh, halfw + halfw, halfh + halfh); - } - - /** - * Set the framing rectangle of this shape using the center of the frame, - * and one of the four corners. The area will be positive. - * - * @param center the center point - * @param corner a corner point - * @throws NullPointerException if either point is null - */ - public void setFrameFromCenter(Point2D center, Point2D corner) - { - setFrameFromCenter(center.getX(), center.getY(), - corner.getX(), corner.getY()); - } - - /** - * Tests if a point is inside the boundary of the shape. - * - * @param p the point to test - * @return true if the point is inside the shape - * @throws NullPointerException if p is null - * @see #contains(double, double) - */ - public boolean contains(Point2D p) - { - return contains(p.getX(), p.getY()); - } - - /** - * Tests if a rectangle and this shape share common internal points. - * - * @param r the rectangle to test - * @return true if the rectangle intersects this shpae - * @throws NullPointerException if r is null - * @see #intersects(double, double, double, double) - */ - public boolean intersects(Rectangle2D r) - { - return intersects(r.getX(), r.getY(), r.getWidth(), r.getHeight()); - } - - /** - * Tests if the shape completely contains the given rectangle. - * - * @param r the rectangle to test - * @return true if r is contained in this shape - * @throws NullPointerException if r is null - * @see #contains(double, double, double, double) - */ - public boolean contains(Rectangle2D r) - { - return contains(r.getX(), r.getY(), r.getWidth(), r.getHeight()); - } - - /** - * Returns a bounding box for this shape, in integer format. Notice that you - * may get a tighter bound with getBounds2D. If the frame is empty, the - * box is the default empty box at the origin. - * - * @return a bounding box - */ - public Rectangle getBounds() - { - if (isEmpty()) - return new Rectangle(); - double x = getX(); - double y = getY(); - double maxx = Math.ceil(x + getWidth()); - double maxy = Math.ceil(y + getHeight()); - x = Math.floor(x); - y = Math.floor(y); - return new Rectangle((int) x, (int) y, (int) (maxx - x), (int) (maxy - y)); - } - - /** - * Return an iterator along the shape boundary. If the optional transform - * is provided, the iterator is transformed accordingly. The path is - * flattened until all segments differ from the curve by at most the value - * of the flatness parameter, within the limits of the default interpolation - * recursion limit of 1024 segments between actual points. Each call - * returns a new object, independent from others in use. The result is - * threadsafe if and only if the iterator returned by - * {@link #getPathIterator(AffineTransform)} is as well. - * - * @param at an optional transform to apply to the iterator - * @param flatness the desired flatness - * @return a new iterator over the boundary - * @throws IllegalArgumentException if flatness is invalid - * @since 1.2 - */ - public PathIterator getPathIterator(AffineTransform at, double flatness) - { - return new FlatteningPathIterator(getPathIterator(at), flatness); - } - - /** - * Create a new shape of the same run-time type with the same contents as - * this one. - * - * @return the clone - */ - public Object clone() - { - try - { - return super.clone(); - } - catch (CloneNotSupportedException e) - { - throw (Error) new InternalError().initCause(e); // Impossible - } - } -} // class RectangularShape diff --git a/libjava/java/awt/geom/RoundRectangle2D.java b/libjava/java/awt/geom/RoundRectangle2D.java deleted file mode 100644 index ac0e6f8128a..00000000000 --- a/libjava/java/awt/geom/RoundRectangle2D.java +++ /dev/null @@ -1,533 +0,0 @@ -/* RoundRectangle2D.java -- represents a rectangle with rounded corners - Copyright (C) 2000, 2002, 2003, 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.awt.geom; - -import java.util.NoSuchElementException; - - -/** This class implements a rectangle with rounded corners. - * @author Tom Tromey (tromey@cygnus.com) - * @date December 3, 2000 - */ -public abstract class RoundRectangle2D extends RectangularShape -{ - /** Return the arc height of this round rectangle. */ - public abstract double getArcHeight(); - - /** Return the arc width of this round rectangle. */ - public abstract double getArcWidth(); - - /** Set the values of this round rectangle - * @param x The x coordinate - * @param y The y coordinate - * @param w The width - * @param h The height - * @param arcWidth The arc width - * @param arcHeight The arc height - */ - public abstract void setRoundRect(double x, double y, double w, double h, - double arcWidth, double arcHeight); - - /** Create a RoundRectangle2D. This is protected because this class - * is abstract and cannot be instantiated. - */ - protected RoundRectangle2D() - { - } - - /** Return true if this object contains the specified point. - * @param x The x coordinate - * @param y The y coordinate - */ - public boolean contains(double x, double y) - { - double mx = getX(); - double mw = getWidth(); - if (x < mx || x >= mx + mw) - return false; - double my = getY(); - double mh = getHeight(); - if (y < my || y >= my + mh) - return false; - - // Now check to see if the point is in range of an arc. - double dy = Math.min(Math.abs(my - y), Math.abs(my + mh - y)); - double dx = Math.min(Math.abs(mx - x), Math.abs(mx + mw - x)); - - // The arc dimensions are that of the corresponding ellipse - // thus a 90 degree segment is half of that. - double aw = getArcWidth() / 2.0; - double ah = getArcHeight() / 2.0; - if (dx > aw || dy > ah) - return true; - - // At this point DX represents the distance from the nearest edge - // of the rectangle. But we want to transform it to represent the - // scaled distance from the center of the ellipse that forms the - // arc. Hence this code: - dy = (ah - dy) / ah; - dx = (aw - dx) / aw; - - return dx * dx + dy * dy <= 1.0; - } - - /** Return true if this object contains the specified rectangle - * @param x The x coordinate - * @param y The y coordinate - * @param w The width - * @param h The height - */ - public boolean contains(double x, double y, double w, double h) - { - // We have to check all four points here (for ordinary rectangles - // we can just check opposing corners). - return (contains(x, y) && contains(x, y + h) && contains(x + w, y + h) - && contains(x + w, y)); - } - - /** Return a new path iterator which iterates over this rectangle. - * @param at An affine transform to apply to the object - */ - public PathIterator getPathIterator(final AffineTransform at) - { - final double minx = getX(); - final double miny = getY(); - final double maxx = minx + getWidth(); - final double maxy = miny + getHeight(); - final double arcwidth = getArcWidth(); - final double archeight = getArcHeight(); - return new PathIterator() - { - /** We iterate counterclockwise around the rectangle, starting in the - * upper right. This variable tracks our current point, which - * can be on either side of a given corner. */ - private int current = 0; - - /** Child path iterator, used for corners. */ - private PathIterator corner; - - /** This is used when rendering the corners. We re-use the arc - * for each corner. */ - private Arc2D arc = new Arc2D.Double(); - - /** Temporary array used by getPoint. */ - private double[] temp = new double[2]; - - public int getWindingRule() - { - return WIND_NON_ZERO; - } - - public boolean isDone() - { - return current > 9; - } - - private void getPoint(int val) - { - switch (val) - { - case 0: - case 8: - temp[0] = maxx; - temp[1] = miny + archeight; - break; - case 7: - temp[0] = maxx; - temp[1] = maxy - archeight; - break; - case 6: - temp[0] = maxx - arcwidth; - temp[1] = maxy; - break; - case 5: - temp[0] = minx + arcwidth; - temp[1] = maxy; - break; - case 4: - temp[0] = minx; - temp[1] = maxy - archeight; - break; - case 3: - temp[0] = minx; - temp[1] = miny + archeight; - break; - case 2: - temp[0] = minx + arcwidth; - temp[1] = miny; - break; - case 1: - temp[0] = maxx - arcwidth; - temp[1] = miny; - break; - } - } - - public void next() - { - if (current >= 8) - ++current; - else if (corner != null) - { - // We're iterating through the corner. Work on the child - // iterator; if it finishes, reset and move to the next - // point along the rectangle. - corner.next(); - if (corner.isDone()) - { - corner = null; - ++current; - } - } - else - { - // Make an arc between this point on the rectangle and - // the next one, and then iterate over this arc. - getPoint(current); - double x1 = temp[0]; - double y1 = temp[1]; - getPoint(current + 1); - Rectangle2D.Double r = new Rectangle2D.Double(Math.min(x1, - temp[0]), - Math.min(y1, - temp[1]), - Math.abs(x1 - - temp[0]), - Math.abs(y1 - - temp[1])); - arc.setArc(r, (current >> 1) * 90.0, 90.0, Arc2D.OPEN); - corner = arc.getPathIterator(at); - } - } - - public int currentSegment(float[] coords) - { - if (corner != null) - { - int r = corner.currentSegment(coords); - if (r == SEG_MOVETO) - r = SEG_LINETO; - return r; - } - - if (current < 9) - { - getPoint(current); - coords[0] = (float) temp[0]; - coords[1] = (float) temp[1]; - } - else if (current == 9) - return SEG_CLOSE; - else - throw new NoSuchElementException("rect iterator out of bounds"); - - if (at != null) - at.transform(coords, 0, coords, 0, 1); - return current == 0 ? SEG_MOVETO : SEG_LINETO; - } - - public int currentSegment(double[] coords) - { - if (corner != null) - { - int r = corner.currentSegment(coords); - if (r == SEG_MOVETO) - r = SEG_LINETO; - return r; - } - - if (current < 9) - { - getPoint(current); - coords[0] = temp[0]; - coords[1] = temp[1]; - } - else if (current == 9) - return SEG_CLOSE; - else - throw new NoSuchElementException("rect iterator out of bounds"); - - if (at != null) - at.transform(coords, 0, coords, 0, 1); - return current == 0 ? SEG_MOVETO : SEG_LINETO; - } - }; - } - - /** Return true if the given rectangle intersects this shape. - * @param x The x coordinate - * @param y The y coordinate - * @param w The width - * @param h The height - */ - public boolean intersects(double x, double y, double w, double h) - { - // Check if any corner is within the rectangle - return (contains(x, y) || contains(x, y + h) || contains(x + w, y + h) - || contains(x + w, y)); - } - - /** Set the boundary of this round rectangle. - * @param x The x coordinate - * @param y The y coordinate - * @param w The width - * @param h The height - */ - public void setFrame(double x, double y, double w, double h) - { - // This is a bit lame. - setRoundRect(x, y, w, h, getArcWidth(), getArcHeight()); - } - - /** Set the values of this round rectangle to be the same as those - * of the argument. - * @param rr The round rectangle to copy - */ - public void setRoundRect(RoundRectangle2D rr) - { - setRoundRect(rr.getX(), rr.getY(), rr.getWidth(), rr.getHeight(), - rr.getArcWidth(), rr.getArcHeight()); - } - - /** A subclass of RoundRectangle which keeps its parameters as - * doubles. */ - public static class Double extends RoundRectangle2D - { - /** The height of the corner arc. */ - public double archeight; - - /** The width of the corner arc. */ - public double arcwidth; - - /** The x coordinate of this object. */ - public double x; - - /** The y coordinate of this object. */ - public double y; - - /** The width of this object. */ - public double width; - - /** The height of this object. */ - public double height; - - /** Construct a new instance, with all parameters set to 0. */ - public Double() - { - } - - /** Construct a new instance with the given arguments. - * @param x The x coordinate - * @param y The y coordinate - * @param w The width - * @param h The height - * @param arcWidth The arc width - * @param arcHeight The arc height - */ - public Double(double x, double y, double w, double h, double arcWidth, - double arcHeight) - { - this.x = x; - this.y = y; - this.width = w; - this.height = h; - this.arcwidth = arcWidth; - this.archeight = arcHeight; - } - - public double getArcHeight() - { - return archeight; - } - - public double getArcWidth() - { - return arcwidth; - } - - public Rectangle2D getBounds2D() - { - return new Rectangle2D.Double(x, y, width, height); - } - - public double getX() - { - return x; - } - - public double getY() - { - return y; - } - - public double getWidth() - { - return width; - } - - public double getHeight() - { - return height; - } - - public boolean isEmpty() - { - return width <= 0 || height <= 0; - } - - public void setRoundRect(double x, double y, double w, double h, - double arcWidth, double arcHeight) - { - this.x = x; - this.y = y; - this.width = w; - this.height = h; - this.arcwidth = arcWidth; - this.archeight = arcHeight; - } - } // class Double - - /** A subclass of RoundRectangle which keeps its parameters as - * floats. */ - public static class Float extends RoundRectangle2D - { - /** The height of the corner arc. */ - public float archeight; - - /** The width of the corner arc. */ - public float arcwidth; - - /** The x coordinate of this object. */ - public float x; - - /** The y coordinate of this object. */ - public float y; - - /** The width of this object. */ - public float width; - - /** The height of this object. */ - public float height; - - /** Construct a new instance, with all parameters set to 0. */ - public Float() - { - } - - /** Construct a new instance with the given arguments. - * @param x The x coordinate - * @param y The y coordinate - * @param w The width - * @param h The height - * @param arcWidth The arc width - * @param arcHeight The arc height - */ - public Float(float x, float y, float w, float h, float arcWidth, - float arcHeight) - { - this.x = x; - this.y = y; - this.width = w; - this.height = h; - this.arcwidth = arcWidth; - this.archeight = arcHeight; - } - - public double getArcHeight() - { - return archeight; - } - - public double getArcWidth() - { - return arcwidth; - } - - public Rectangle2D getBounds2D() - { - return new Rectangle2D.Float(x, y, width, height); - } - - public double getX() - { - return x; - } - - public double getY() - { - return y; - } - - public double getWidth() - { - return width; - } - - public double getHeight() - { - return height; - } - - public boolean isEmpty() - { - return width <= 0 || height <= 0; - } - - public void setRoundRect(float x, float y, float w, float h, - float arcWidth, float arcHeight) - { - this.x = x; - this.y = y; - this.width = w; - this.height = h; - this.arcwidth = arcWidth; - this.archeight = arcHeight; - } - - public void setRoundRect(double x, double y, double w, double h, - double arcWidth, double arcHeight) - { - this.x = (float) x; - this.y = (float) y; - this.width = (float) w; - this.height = (float) h; - this.arcwidth = (float) arcWidth; - this.archeight = (float) arcHeight; - } - } // class Float -} // class RoundRectangle2D diff --git a/libjava/java/awt/im/InputContext.java b/libjava/java/awt/im/InputContext.java deleted file mode 100644 index e289677fe9c..00000000000 --- a/libjava/java/awt/im/InputContext.java +++ /dev/null @@ -1,434 +0,0 @@ -/* InputContext.java -- provides the context for text input - Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.im; - -import gnu.java.util.EmptyEnumeration; - -import java.awt.AWTEvent; -import java.awt.AWTException; -import java.awt.Component; -import java.awt.im.spi.InputMethod; -import java.awt.im.spi.InputMethodDescriptor; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.net.URL; -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.Locale; - -/** - * Provides a context for controlling input methods and keyboard layouts. - * This class provides the communication layer between the client component, - * and the various locale-dependent text entry input methods that can be used - * for the client. By default, there is one instance per Window, shared among - * all components, but this limits text entry to one component at a time. - * Thus, text components can create their own instance to allow text entry - * in multiple components at a time. - * - * <p>By using the interfaces of {@link java.awt.im.spi}, you can install - * extensions which allow additional input methods. Some of these may use - * platform native input methods, or keyboard layouts provided by the platform. - * Input methods are unavailable if none have been installed and the platform - * has no underlying native input methods. Extensions are installed as jar - * files, usually accessed in the default extension location or specified by - * the -extdir VM flag. The jar must contain a file named - * "META_INF/services/java.awt.im.spi.InputMethodDescriptor" which lists, - * one entry per line in UTF-8 encoding, each class in the jar that implements - * java.awt.im.spi.InputMethodDescriptor. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @see Component#getInputContext() - * @see Component#enableInputMethods(boolean) - * @since 1.2 - * @status updated to 1.4, but unverified - */ -public class InputContext -{ - /** - * The list of installed input method descriptors. - */ - private static final ArrayList descriptors = new ArrayList(); - static - { - Enumeration e; - try - { - e = ClassLoader.getSystemResources - ("META_INF/services/java.awt.im.spi.InputMethodDescriptor"); - } - catch (IOException ex) - { - // XXX Should we do something else? - e = EmptyEnumeration.getInstance(); - } - while (e.hasMoreElements()) - { - URL url = (URL) e.nextElement(); - BufferedReader in; - String line; - try - { - in = new BufferedReader - (new InputStreamReader(url.openConnection().getInputStream(), - "UTF-8")); - line = in.readLine().trim(); - } - catch (IOException ignored) - { - continue; - } - outer: - while (line != null) - { - try - { - if (line.charAt(0) != '#') - { - Class c = Class.forName(line); - descriptors.add((InputMethodDescriptor) c.newInstance()); - } - line = in.readLine().trim(); - } - catch (IOException ex) - { - continue outer; - } - catch (Exception ignored) - { - } - } - } - } - - /** The current input method; null if no input methods are installed. */ - private InputMethod im; - - /** Map of locales to the most recently selected input method. */ - private final HashMap recent = new HashMap(); - - /** The list of acceptable character subsets. */ - private Character.Subset[] subsets; - - /** - * Construct an InputContext. This is protected, so clients must use - * {@link #getInstance()} instead. - */ - protected InputContext() - { - } - - /** - * Returns a new InputContext. - * - * @return a new instance, initialized to the default locale if available - */ - public static InputContext getInstance() - { - InputContext ic = new InputContext(); - ic.selectInputMethod(Locale.getDefault()); - return ic; - } - - /** - * Attempts to select an input method or keyboard layout which supports the - * given locale. This returns true if a locale is available and was selected. - * The following steps are taken in choosing an input method:<ul> - * <li>If the currently selected input method or keyboard layout supports - * the requested locale, it remains selected.</li> - * <li>If there is no input method or keyboard layout available that - * supports the requested locale, the current input method or keyboard - * layout remains selected.</li> - * <li>If the user has previously selected an input method or keyboard - * layout for the requested locale from the user interface, then the most - * recently selected such input method or keyboard layout is reselected.</li> - * <li>Otherwise, an input method or keyboard layout that supports the - * requested locale is selected in an implementation dependent way. This - * implementation chooses the first input method which supports the requested - * locale based on the InputMethodDescriptors loaded from the extensions - * installed on the CLASSPATH.</li> - * </ul> - * - * <p>Before switching away from an input method, any currently uncommitted - * text is committed. Not all host operating systems provide API to - * determine the locale of the currently selected native input method or - * keyboard layout, and to select a native input method or keyboard layout - * by locale. For host operating systems that don't provide such API, - * selectInputMethod assumes that native input methods or keyboard layouts - * provided by the host operating system support only the system's default - * locale. - * - * <p>An example of where this may be called is in a multi-language document, - * when moving the insertion point between sections of different locale, so - * that the user may use the input method appropriate to that section of the - * document. - * - * @param locale the desired new locale - * @return true if the new locale is active - * @throws NullPointerException if locale is null - */ - public boolean selectInputMethod(Locale locale) - { - if (im != null && im.setLocale(locale)) - { - recent.put(locale, im); - return true; - } - InputMethod next = (InputMethod) recent.get(locale); - outer: - if (next != null) - for (int i = 0, limit = descriptors.size(); i < limit; i++) - { - InputMethodDescriptor d = (InputMethodDescriptor) descriptors.get(i); - Locale[] list; - try - { - list = d.getAvailableLocales(); - } - catch (AWTException ignored) - { - continue; - } - for (int j = list.length; --j >= 0; ) - if (locale.equals(list[j])) - { - try - { - next = d.createInputMethod(); - recent.put(locale, next); - } - catch (Exception ignored) - { - continue; - } - } - } - if (next == null) - return false; - // XXX I'm not sure if this does all the necessary steps in the switch. - if (im != null) - { - try - { - next.setCompositionEnabled(im.isCompositionEnabled()); - } - catch (UnsupportedOperationException ignored) - { - } - im.endComposition(); - im.deactivate(false); - im.hideWindows(); - } - im = next; - im.setLocale(locale); - im.setCharacterSubsets(subsets); - return true; - } - - /** - * Returns the current locale of the current input method or keyboard - * layout. Returns null if the input context does not have a current input - * method or keyboard layout or if the current input method's - * {@link InputMethod#getLocale()} method returns null. Not all host - * operating systems provide API to determine the locale of the currently - * selected native input method or keyboard layout. For host operating - * systems that don't provide such API, getLocale assumes that the current - * locale of all native input methods or keyboard layouts provided by the - * host operating system is the system's default locale. - * - * @return the locale of the current input method, or null - * @since 1.3 - */ - public Locale getLocale() - { - return im == null ? null : im.getLocale(); - } - - /** - * Sets the subsets of Unicode characters allowed to be input by the current - * input method, as well as subsequent input methods. The value of null - * implies all characters are legal. Applications should not rely on this - * behavior, since native host input methods may not allow restrictions. - * If no current input method is available, this has no immediate effect. - * - * @param subsets the set of Unicode subsets to accept, or null - */ - public void setCharacterSubsets(Character.Subset[] subsets) - { - this.subsets = subsets; - if (im != null) - im.setCharacterSubsets(subsets); - } - - /** - * Changes the enabled status of the current input method. An input method - * that is enabled for composition interprets incoming events for both - * composition and control purposes, while a disabled input method only - * interprets control commands (including commands to enable itself). - * - * @param enable whether to enable the input method - * @throws UnsupportedOperationException if there is no current input method, - * or the input method does not support enabling - * @see #isCompositionEnabled() - * @since 1.3 - */ - public void setCompositionEnabled(boolean enable) - { - if (im == null) - throw new UnsupportedOperationException(); - im.setCompositionEnabled(enable); - } - - /** - * Find out if the current input method is enabled. - * - * @return true if the current input method is enabled - * @throws UnsupportedOperationException if there is no current input method, - * or the input method does not support enabling - * @see #setCompositionEnabled(boolean) - * @since 1.3 - */ - public boolean isCompositionEnabled() - { - if (im == null) - throw new UnsupportedOperationException(); - return im.isCompositionEnabled(); - } - - /** - * Starts a reconversion operation in the current input method. The input - * method gets theh text to reconvert from the client component, using - * {@link InputMethodRequests#getSelectedText(Attribute[])}. Then the - * composed and committed text produced by the operation is sent back to - * the client using a sequence of InputMethodRequests. - * - * @throws UnsupportedOperationException if there is no current input method, - * or the input method does not support reconversion - * @since 1.3 - */ - public void reconvert() - { - if (im == null) - throw new UnsupportedOperationException(); - im.reconvert(); - } - - /** - * Dispatches an event to the current input method. This is called - * automatically by AWT. If no input method is available, then the event - * will never be consumed. - * - * @param event the event to dispatch - * @throws NullPointerException if event is null - */ - public void dispatchEvent(AWTEvent event) - { - if (im != null) - im.dispatchEvent(event); - } - - /** - * Notifies the input context that a client component has been removed from - * its containment hierarchy, or that input method support has been disabled - * for the component. This method is usually called from the client - * component's {@link Component#removeNotify()} method. Potentially pending - * input from input methods for this component is discarded. If no input - * methods are available, then this method has no effect. - * - * @param client the client component - * @throws NullPointerException if client is null - */ - public void removeNotify(Component client) - { - // XXX What to do with client information? - if (im != null) - { - im.deactivate(false); - im.removeNotify(); - } - } - - /** - * Ends any input composition that may currently be going on in this - * context. Depending on the platform and possibly user preferences, this - * may commit or delete uncommitted text. Any changes to the text are - * communicated to the active component using an input method event. If no - * input methods are available, then this method has no effect. This may - * be called for a variety of reasons, such as when the user moves the - * insertion point in the client text outside the range of the composed text, - * or when text is saved to file. - */ - public void endComposition() - { - if (im != null) - im.endComposition(); - } - - /** - * Disposes of the input context and release the resources used by it. - * Called automatically by AWT for the default input context of each - * Window. If no input methods are available, then this method has no - * effect. - */ - public void dispose() - { - if (im != null) - { - im.deactivate(false); - im.dispose(); - } - } - - /** - * Returns a control object from the current input method, or null. A - * control object provides implementation-dependent methods that control - * the behavior of the input method or obtain information from the input - * method. Clients have to compare the result against known input method - * control object types. If no input methods are available or the current - * input method does not provide an input method control object, then null - * is returned. - * - * @return the control object, or null - */ - public Object getInputMethodControlObject() - { - return im == null ? null : im.getControlObject(); - } -} // class InputContext diff --git a/libjava/java/awt/im/InputMethodHighlight.java b/libjava/java/awt/im/InputMethodHighlight.java deleted file mode 100644 index 0d664b19366..00000000000 --- a/libjava/java/awt/im/InputMethodHighlight.java +++ /dev/null @@ -1,185 +0,0 @@ -/* InputMethodHighlight.java -- highlights the current text selection - Copyright (C) 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.awt.im; - -import java.util.Map; - -/** - * This describes the highlight attributes of text composed in an input method. - * The description includes an abstract level (whether text has been converted - * yet, and whether it is selected), and a concrete level (which style - * attributes are used in rendering). If no concrete level is defined, the - * renderer should use - * {@link Toolkit#mapInputMethodHighlight(InputMethodHighlight)}. An example - * of conversion state is kana -> kanji. - * - * <p>Instances of this class are typically used in - * AttributedCharacterIterators, and may be wrapped in Annotations to separate - * text segments. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @see AttributedCharacterIterators - * @see Annotation - * @since 1.2 - * @status updated to 1.4 - */ -public class InputMethodHighlight -{ - /** Raw text state (before conversion). */ - public static final int RAW_TEXT = 0; - - /** Converted text state (after conversion). */ - public static final int CONVERTED_TEXT = 1; - - /** Default do-nothing highlighting for unselected raw text. */ - public static final InputMethodHighlight UNSELECTED_RAW_TEXT_HIGHLIGHT - = new InputMethodHighlight(false, RAW_TEXT); - - /** Default do-nothing highlighting for selected raw text. */ - public static final InputMethodHighlight SELECTED_RAW_TEXT_HIGHLIGHT - = new InputMethodHighlight(true, RAW_TEXT); - - /** Default do-nothing highlighting for unselected converted text. */ - public static final InputMethodHighlight UNSELECTED_CONVERTED_TEXT_HIGHLIGHT - = new InputMethodHighlight(false, CONVERTED_TEXT); - - /** Default do-nothing highlighting for selected converted text. */ - public static final InputMethodHighlight SELECTED_CONVERTED_TEXT_HIGHLIGHT - = new InputMethodHighlight(true, CONVERTED_TEXT); - - /** Whether the highlighting applies to selected text. */ - private final boolean selected; - - /** The state of highlighted text. */ - private final int state; - - /** Any variation on the highlighting style. */ - private final int variation; - - /** The unmodifiable map of rendering styles. */ - private final Map style; - - /** - * Create an input method highlight style, with variation 0 and null style - * mapping. - * - * @param selected whether the text range is selected - * @param state either {@link #RAW_TEXT} or {@link #CONVERTED_TEXT} - * @throws IllegalArgumentException if state is invalid - */ - public InputMethodHighlight(boolean selected, int state) - { - this(selected, state, 0, null); - } - - /** - * Create an input method highlight style, with null style mapping. - * - * @param selected whether the text range is selected - * @param state either {@link #RAW_TEXT} or {@link #CONVERTED_TEXT} - * @param variation the style variation - * @throws IllegalArgumentException if state is invalid - */ - public InputMethodHighlight(boolean selected, int state, int variation) - { - this(selected, state, variation, null); - } - - /** - * Create an input method highlight style. - * - * @param selected whether the text range is selected - * @param state either {@link #RAW_TEXT} or {@link #CONVERTED_TEXT} - * @param variation the style variation - * @param style an unmodifiable map of rendering styles, or null - * @throws IllegalArgumentException if state is invalid - * @since 1.3 - */ - public InputMethodHighlight(boolean selected, int state, int variation, - Map style) - { - if (state != RAW_TEXT && state != CONVERTED_TEXT) - throw new IllegalArgumentException(); - this.selected = selected; - this.state = state; - this.variation = variation; - this.style = style; - } - - /** - * Return whether the highlighting applies to selected text. - * - * @return the selection status - */ - public boolean isSelected() - { - return selected; - } - - /** - * Return the conversion state of the highlighted text. - * - * @return one of {@link #RAW_TEXT} or {@link #CONVERTED_TEXT} - */ - public int getState() - { - return state; - } - - /** - * Return the highlighting style variation. - * - * @return the variation - */ - public int getVariation() - { - return variation; - } - - /** - * Return the rendering style attributes map, or null if it should be the - * default mapping. - * - * @return the style map - * @since 1.3 - */ - public Map getStyle() - { - return style; - } -} // class InputMethodHighlight diff --git a/libjava/java/awt/im/InputMethodRequests.java b/libjava/java/awt/im/InputMethodRequests.java deleted file mode 100644 index d50ec33c5c8..00000000000 --- a/libjava/java/awt/im/InputMethodRequests.java +++ /dev/null @@ -1,153 +0,0 @@ -/* InputMethodRequests.java -- handles text insertion via input methods - Copyright (C) 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.awt.im; - -import java.awt.Rectangle; -import java.awt.font.TextHitInfo; -import java.text.AttributedCharacterIterator; -import java.text.AttributedCharacterIterator.Attribute; - -/** - * This interface handles requests made by input methods on text editing - * components. A component must specify a handler for input methods that - * implements this interface, and which supports one of two user interfaces: - * <ul><li><em>on-the-spot</em>: composed text is shown in place</li> - * <li><em>below-the-spot</em>: composed text is in a separate window, - * usually below the main text window, until it is committed into place at - * the insertion point, overwriting any selected text</li></ul> - * - * @author Eric Blake (ebb9@email.byu.edu) - * @see Component#getInputMethodRequests() - * @see InputMethodListener - * @since 1.2 - * @status updated to 1.4 - */ -public interface InputMethodRequests -{ - /** - * Gets the location of a given offset of the text. This can be used to - * position a composition window near the location of where the composed - * text will be inserted. - * - * <p>If the component has composed text (from the most recent - * InputMethodEvent), then offset 0 indicates the location of the first - * character of this composed text. Otherwise, the offset is ignored, and - * the location should be the beginning of the final line of selected - * text (in horizontal left-to-right text, like English, this would be the - * lower left corner of the selction; in vertical top-to-bottom text, like - * Chinese, this would be the top right corner of the selection). - * - * <p>The location returned is a 0-thickness caret (either horizontal or - * vertical, depending on text flow), mapped to absolute screen coordinates. - * - * @param offset offset within composed text, or null - * @return the screen location of the caret at the offset - */ - Rectangle getTextLocation(TextHitInfo offset); - - /** - * Get the text offset for the given screen coordinate. The offset is - * relative to the composed text, and the return is null if it is outside - * the range of composed text. For example, this can be used to find - * where a mouse click should pop up a text composition window. - * - * @param x the x screen coordinate - * @param y the y screen coordinate - * @return a text hit info describing the composed text offset - */ - TextHitInfo getLocationOffset(int x, int y); - - /** - * Gets the offset where the committed text exists in the text editing - * component. This can be used to examine the text surrounding the insert - * position. - * - * @return the offset of the insert position - */ - int getInsertPositionOffset(); - - /** - * Gets an interator which provides access to the text and its attributes, - * except for the uncommitted text. The input method may provide a list of - * attributes it is interested in; and the iterator need not provide - * information on the remaining attributes. If the attribute list is null, - * the iterator must list all attributes. - * - * @param beginIndex the index of the first character in the iteration - * @param endIndex the index of the last character in the iteration - * @param attributes a list of attributes interested in, or null - * @return an iterator over the region of text with its attributes - */ - AttributedCharacterIterator getCommittedText(int beginIndex, int endIndex, - Attribute[] attributes); - - /** - * Gets the length of committed text. - * - * @return the number of committed characters - */ - int getCommittedTextLength(); - - /** - * Gets the latest committed text, and removes it from the component's text - * body. This allows an input method to provide an "Undo" command. In - * general, this should only be supported immediately after a commit, and - * not when other actions intervene; if not supported, simply return null. - * The input method may provide a list of attributes it is interested in; - * and the iterator need not provide information on the remaining attributes. - * If the attribute list is null, the iterator must list all attributes. - * - * @param attributes a list of attributes interested in, or null - * @return the latest committed text, or null - */ - AttributedCharacterIterator cancelLatestCommittedText - (Attribute[] attributes); - - /** - * Gets the currently selected text. One use of this is to implement a - * "Reconvert" feature in an input method, which modifies the selection - * based on the text in the composition window. The input method may - * provide a list of attributes it is interested in; and the iterator need - * not provide information on the remaining attributes. If the attribute - * list is null, the iterator must list all attributes. - * - * @param attributes a list of attributes interested in, or null - * @return the current selection - */ - AttributedCharacterIterator getSelectedText(Attribute[] attributes); -} // interface InputMethodRequests diff --git a/libjava/java/awt/im/InputSubset.java b/libjava/java/awt/im/InputSubset.java deleted file mode 100644 index 5e7d58e7f42..00000000000 --- a/libjava/java/awt/im/InputSubset.java +++ /dev/null @@ -1,129 +0,0 @@ -/* InputSubset.java -- subsets of Unicode important in text input - Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.awt.im; - -/** - * Defines additional Unicode character blocks for use by input methods. - * These constants encompass several Unicode blocks, or portions thereof, for - * simplification over {@link Character.UnicodeBlock}. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.2 - * @status updated to 1.4 - */ -public final class InputSubset extends Character.Subset -{ - /** - * Constant for all Latin characters, including the characters in the - * BASIC_LATIN, LATIN_1_SUPPLEMENT, LATIN_EXTENDED_A, LATIN_EXTENDED_B - * Unicode character blocks. - */ - public static final InputSubset LATIN = new InputSubset("LATIN"); - - /** - * Constant for the digits included in the BASIC_LATIN Unicode character - * block. - */ - public static final InputSubset LATIN_DIGITS - = new InputSubset("LATIN_DIGITS"); - - /** - * Constant for all Han characters used in writing Traditional Chinese, - * including a subset of the CJK unified ideographs as well as Traditional - * Chinese Han characters that may be defined as surrogate characters. - */ - public static final InputSubset TRADITIONAL_HANZI - = new InputSubset("TRADITIONAL_HANZI"); - - /** - * Constant for all Han characters used in writing Simplified Chinese, - * including a subset of the CJK unified ideographs as well as Simplified - * Chinese Han characters that may be defined as surrogate characters. - */ - public static final InputSubset SIMPLIFIED_HANZI - = new InputSubset("SIMPLIFIED_HANZI"); - - /** - * Constant for all Han characters used in writing Japanese, including a - * subset of the CJK unified ideographs as well as Japanese Han characters - * that may be defined as surrogate characters. - */ - public static final InputSubset KANJI = new InputSubset("KANJI"); - - /** - * Constant for all Han characters used in writing Korean, including a - * subset of the CJK unified ideographs as well as Korean Han characters - * that may be defined as surrogate characters. - */ - public static final InputSubset HANJA = new InputSubset("HANJA"); - - /** - * Constant for the halfwidth katakana subset of the Unicode halfwidth and - * fullwidth forms character block. - */ - public static final InputSubset HALFWIDTH_KATAKANA - = new InputSubset("HALFWIDTH_KATAKANA"); - - /** - * Constant for the fullwidth ASCII variants subset of the Unicode - * halfwidth and fullwidth forms character block. - * - * @since 1.3 - */ - public static final InputSubset FULLWIDTH_LATIN - = new InputSubset("FULLWIDTH_LATIN"); - - /** - * Constant for the fullwidth digits included in the Unicode halfwidth and - * fullwidth forms character block. - * - * @since 1.3 - */ - public static final InputSubset FULLWIDTH_DIGITS - = new InputSubset("FULLWIDTH_DIGITS"); - - /** - * Construct a subset. - * - * @param name the subset name - */ - private InputSubset(String name) - { - super(name); - } -} // class InputSubset diff --git a/libjava/java/awt/im/spi/InputMethod.java b/libjava/java/awt/im/spi/InputMethod.java deleted file mode 100644 index 840d193a8d8..00000000000 --- a/libjava/java/awt/im/spi/InputMethod.java +++ /dev/null @@ -1,240 +0,0 @@ -/* InputMethod.java -- defines an interface for complex text input - Copyright (C) 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.awt.im.spi; - -import java.awt.AWTEvent; -import java.awt.Rectangle; -import java.util.Locale; - -/** - * This interface supports complex text input, often for situations where - * the text is more complex than a keyboard will accomodate. For example, - * this can be used for Chinese, Japanese, and Korean, where multiple - * keystrokes are necessary to compose text. This could also support things - * like phonetic English, or reordering Thai. - * - * <p>These contexts can be loaded by the input method framework, using - * {@link InputContext#selectInputMethod(Locale)}. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.3 - * @status updated to 1.4 - */ -public interface InputMethod -{ - /** - * Set the input method context, which ties the input method to a client - * component. This is called once automatically when creating the input - * method. - * - * @param context the context for this input method - * @throws NullPointerException if context is null - */ - void setInputMethodContext(InputMethodContext context); - - /** - * Sets the input locale. If the input method supports that locale, it - * changes its behavior to be consistent with the locale and returns true. - * Otherwise, it returns false. This is called by - * {@link InputContext#selectInputMethod(Locale)} when the user specifies - * a locale, or when the previously selected input method had a locale. - * - * @param locale the locale to use for input - * @return true if the change is successful - * @throws NullPointerException if locale is null - */ - boolean setLocale(Locale locale); - - /** - * Returns the current input locale, or null if none is defined. This is - * called by {@link InputContext#getLocale()}, or before switching input - * methods. - * - * @return the current input locale, or null - */ - Locale getLocale(); - - /** - * Sets the allowed Unicode subsets that this input method can use. Null - * indicates that all characters are allowed. This is called after creation, - * or when switching to this input method, by - * {@link InputContext#setCharacterSubsets(Character.Subset[])}. - * - * @param subsets the accepted subsets for this input method, or null for all - */ - void setCharacterSubsets(Character.Subset[] subsets); - - /** - * Changes the enabled status of this input method. An enabled input method - * accepts incoming events for composition and control purposes, while a - * disabled input method ignores events (except for control purposes). This - * is called by {@link InputContext#setCompositionEnabled(boolean)} or when - * switching from an input method if the previous input method returned - * without exception on {@link #isCompositionEnabled()}. - * - * @param enable whether to enable this input method - * @throws UnsupportedOperationException if enabling/disabling is unsupported - * @see #isCompositionEnabled() - */ - void setCompositionEnabled(boolean enable); - - /** - * Find out if this input method is enabled. This is called by - * {@link InputContext#isCompositionEnabled()}, or when switching input - * methods via {@link InputContext#selectInputMethod(Locale)}. - * - * @return true if this input method is enabled - * @throws UnsupportedOperationException if enabling/disabling is unsupported - * @see #setCompositionEnabled(boolean) - */ - boolean isCompositionEnabled(); - - /** - * Starts a reconversion operation. The input method gets its text from the - * client, using {@link InputMethodRequests#getSelectedText(Attribute[])}. - * Then the composed and committed text produced by the operation is sent - * back to the client using a sequence of InputMethodEvents. This is called - * by {@link InputContext#reconvert()}. - * - * @throws UnsupportedOperationException if reconversion is unsupported - */ - void reconvert(); - - /** - * Dispatch an event to the input method. If input method support is enabled, - * certain events are dispatched to the input method before the client - * component or event listeners. The input method must either consume the - * event or pass it on to the component. Instances of InputEvent, including - * KeyEvent and MouseEvent, are given to this input method. This method is - * called by {@link InputContext#dispatchEvent(AWTEvent)}. - * - * @param event the event to dispatch - * @throws NullPointerException if event is null - */ - void dispatchEvent(AWTEvent event); - - /** - * Notify this input method of changes in the client window. This is called - * when notifications are enabled (see {@link - * InputMethodContext#enableClientWindowNotification(InputMethod, boolean)}, - * if {@link #removeNotify(Component)} has not been called. The following - * situations trigger a notification:<ul> - * <li>The client window changes in location, size, visibility, - * iconification, or is closed.</li> - * <li>When enabling client notification (or on the first activation after - * enabling if no client existed at the time).</li> - * <li>When activating a new client after <code>removeNotify</code> was - * called on a previous client.</li> - * </ul> - * - * @param bounds the client window's current bounds, or null - */ - void notifyClientWindowChange(Rectangle bounds); - - /** - * Activate this input method for input processing. If the input method - * provides its own windows, it should make them open and visible at this - * time. This method is called when a client component receives a - * FOCUS_GAINED event, or when switching to this input method from another - * one. It is only called when the input method is inactive, assuming that - * new instances begin in an inactive state. - */ - void activate(); - - /** - * Deactivate this input method, either temporarily or permanently for the - * given client. If the input method provides its own windows, it should - * only close those related to the current composition (such as a lookup - * choice panel), while leaving more persistant windows (like a control - * panel) open to avoid screen flicker. Before control is given to another - * input method, {@link #hideWindows()} will be called on this instance. - * This method is called when a client component receives a - * FOCUS_LOST event, when switching to another input method, or before - * {@link #removeNotify()} when the client is removed. - * - * @param isTemporary true if the focus change is temporary - */ - void deactivate(boolean isTemporary); - - /** - * Close or hide all windows opened by this input method. This is called - * before activating a different input method, and before calling - * {@link #dispose()} on this instance. It is only called when the input - * method is inactive. - */ - void hideWindows(); - - /** - * Notify the input method that a client component has been removed from its - * hierarchy, or that input method support has been disabled. This is - * called by {@link InputContext#removeNotify()}, and only when the input - * method is inactive. - */ - void removeNotify(); - - /** - * End any input composition currently taking place. Depending on the - * platform and user preferences, this may commit or delete uncommitted text, - * using input method events. This may be called for a variety of reasons, - * such as when the user moves the insertion point in the client text outside - * the range of the composed text, or when text is saved to file. This is - * called by {@link InputContext#endComposition()}, when switching to a - * new input method, or by {@link InputContext#selectInputMethod(Locale)}. - */ - void endComposition(); - - /** - * Disposes the input method and release any resources it is using. In - * particular, the input method should dispose windows and close files. This - * is called by {@link InputContext#dispose()}, when the input method is - * inactive; and nothing will be called on this instance afterwards. - */ - void dispose(); - - /** - * Returns a control object from this input method, or null. A control object - * provides method to control the behavior of this input method, as well as - * query information about it. The object is implementation dependent, so - * clients must compare the result against known input method control - * object types. This is called by - * {@link InputContext#getInputMethodControlObject()}. - * - * @return the control object, or null - */ - Object getControlObject(); -} // interface InputMethod diff --git a/libjava/java/awt/im/spi/InputMethodContext.java b/libjava/java/awt/im/spi/InputMethodContext.java deleted file mode 100644 index 43bee8d8617..00000000000 --- a/libjava/java/awt/im/spi/InputMethodContext.java +++ /dev/null @@ -1,123 +0,0 @@ -/* InputMethodContext.java -- communication between an input method and client - Copyright (C) 2002, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.im.spi; - -import java.awt.Window; -import java.awt.font.TextHitInfo; -import java.awt.im.InputMethodRequests; -import java.text.AttributedCharacterIterator; - -import javax.swing.JFrame; - -/** - * Provides methods for the communication context between an input method - * and the client component. This should be passed to - * {@link InputMethod#setInputMethodContext(InputMethodContext)}. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.3 - * @status updated to 1.4 - */ -public interface InputMethodContext extends InputMethodRequests -{ - /** - * Create an input method event and dispatch it to the client. - * - * @param id the event type - * @param text an iterator over the text to be committed - * @param count the count of characters to be committed - * @param caret the insertion point of the commit, or null - * @param visiblePosition the best location to make visible, or null - */ - void dispatchInputMethodEvent(int id, AttributedCharacterIterator text, - int count, TextHitInfo caret, - TextHitInfo visiblePosition); - - /** - * Creates a top-level window for use by the input method. This window should - * float above all document windows and dialogs, not receive focus, and have - * lightweight decorations (such as no title, reduced drag regions). But - * this behavior may be modified to meet the platform style. The title may - * or may not be displayed, depending on the platform. - * - * <p>If attachToInputContext is true, the new window will share the input - * context of the input method, so that events in the new window are - * dispatched to the input method. Also, this supresses deactivate and - * activate calls to the input method caused by setVisible. - * - * @param title the window title, if one is displayed; null becomes "" - * @param attachToInputContext true for the window to share context with - * the input method - * @return the new window for use by the input method - * @throws HeadlessException if GraphicsEnvironment.isHeadless is true - */ - Window createInputMethodWindow(String title, boolean attachToInputContext); - - /** - * Creates a top-level Swing JFrame for use by the input method. This frame - * should float above all document windows and dialogs, not receive focus, - * and have lightweight decorations (such as no title, reduced drag - * regions). But this behavior may be modified to meet the platform style. - * The title may or may not be displayed, depending on the platform. - * - * <p>If attachToInputContext is true, the new window will share the input - * context of the input method, so that events in the new window are - * dispatched to the input method. Also, this supresses deactivate and - * activate calls to the input method caused by setVisible. - * - * @param title the window title, if one is displayed; null becomes "" - * @param attachToInputContext true for the window to share context with - * the input method - * @return the new window for use by the input method - * @throws HeadlessException if GraphicsEnvironment.isHeadless is true - * @since 1.4 - */ - JFrame createInputMethodJFrame(String title, boolean attachToInputContext); - - /** - * Sets whether notification of the client window's location and state should - * be enabled for the input method. When enabled, the input method's - * {@link #notifyClientWindowChange(Rectangle)} method is called. - * Notification is automatically disabled when the input method is disposed. - * - * @param inputMethod the method to change status of - * @param enable true to enable notification - */ - void enableClientWindowNotification(InputMethod inputMethod, boolean enable); -} // interface InputMethodContext diff --git a/libjava/java/awt/im/spi/InputMethodDescriptor.java b/libjava/java/awt/im/spi/InputMethodDescriptor.java deleted file mode 100644 index 093d7319217..00000000000 --- a/libjava/java/awt/im/spi/InputMethodDescriptor.java +++ /dev/null @@ -1,113 +0,0 @@ -/* InputMethodDescriptor.java -- enables loading and use of an input method - Copyright (C) 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.awt.im.spi; - -import java.awt.AWTException; -import java.awt.Image; -import java.util.Locale; - -/** - * This interface provides information about an InputMethod before it is - * loaded. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.3 - * @status updated to 1.4 - */ -public interface InputMethodDescriptor -{ - /** - * Returns the locales supported by the input method this describes. This - * allows the selection of input methods by locale (by language only, or - * also by country and variant), via - * {@link InputContext#selectInputMethod(Locale)}. The returned list should - * ignore pass-through locales, so it is usually a subset of locales for - * which {@link InputMethod#setContext(Locale)} returns true. If - * {@link #hasDynamicLocaleList()} returns true, this is called each time - * information is needed, allowing dynamic addition or removal of supported - * locales. - * - * @return the list of supported locales - * @throws AWTException if the input method is not available - */ - Locale[] getAvailableLocales() throws AWTException; - - /** - * Test whether the input method this describes has a static or dynamic - * locale list. For example, this would return true if the list of supported - * locales depends on adapters currently loaded over a network. - * - * @return true if the locale list is dynamic - */ - boolean hasDynamicLocaleList(); - - /** - * Returns a user visible name of the input locale, displayed in the - * specified locale. The inputLocale parameter must be one obtained from - * the list in {@link #getAvailableLocales()}, or null for a - * locale-independent description of the input method. If a translation to - * the desired display language is not available, another language may be - * used. - * - * @param inputLocale the locale of the input method, or null - * @param displayLanguage the language of the result - * @return the name of the input method when using the given inputLocale - */ - String getInputMethodDisplayName(Locale inputLocale, - Locale displayLanguage); - - /** - * Returns a 16x16 icon for the input locale. The inputLocale parameter - * must be one obtained from the list in {@link #getAvailableLocales()}, or - * null for a locale-independent icon for the input method. - * - * @param inputLocale the locale of the input method, or null - * @return a 16x16 icon for the input method when using the given inputLocale - */ - Image getInputMethodIcon(Locale inputLocale); - - /** - * Creates a new instance of the input method. - * - * @return the newly created input method - * @throws Exception if anything goes wrong - */ - InputMethod createInputMethod() throws Exception; - -} // interface InputMethodDescriptor - diff --git a/libjava/java/awt/image/AffineTransformOp.java b/libjava/java/awt/image/AffineTransformOp.java deleted file mode 100644 index f11066e4e3d..00000000000 --- a/libjava/java/awt/image/AffineTransformOp.java +++ /dev/null @@ -1,375 +0,0 @@ -/* AffineTransformOp.java -- This class performs affine - transformation between two images or rasters in 2 dimensions. - Copyright (C) 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.awt.image; - -import java.awt.Graphics2D; -import java.awt.Rectangle; -import java.awt.RenderingHints; -import java.awt.geom.AffineTransform; -import java.awt.geom.NoninvertibleTransformException; -import java.awt.geom.Point2D; -import java.awt.geom.Rectangle2D; -import java.util.Arrays; - -/** - * This class performs affine transformation between two images or - * rasters in 2 dimensions. - * - * @author Olga Rodimina (rodimina@redhat.com) - */ -public class AffineTransformOp implements BufferedImageOp, RasterOp -{ - public static final int TYPE_NEAREST_NEIGHBOR = 1; - - public static final int TYPE_BILINEAR = 2; - - /** - * @since 1.5.0 - */ - public static final int TYPE_BICUBIC = 3; - - private AffineTransform transform; - private RenderingHints hints; - - /** - * Construct AffineTransformOp with the given xform and interpolationType. - * Interpolation type can be TYPE_BILINEAR, TYPE_BICUBIC or - * TYPE_NEAREST_NEIGHBOR. - * - * @param xform AffineTransform that will applied to the source image - * @param interpolationType type of interpolation used - */ - public AffineTransformOp (AffineTransform xform, int interpolationType) - { - this.transform = xform; - if (xform.getDeterminant() == 0) - throw new ImagingOpException(null); - - switch (interpolationType) - { - case TYPE_BILINEAR: - hints = new RenderingHints (RenderingHints.KEY_INTERPOLATION, - RenderingHints.VALUE_INTERPOLATION_BILINEAR); - break; - case TYPE_BICUBIC: - hints = new RenderingHints (RenderingHints.KEY_INTERPOLATION, - RenderingHints.VALUE_INTERPOLATION_BICUBIC); - break; - default: - hints = new RenderingHints (RenderingHints.KEY_INTERPOLATION, - RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR); - } - } - - /** - * Construct AffineTransformOp with the given xform and rendering hints. - * - * @param xform AffineTransform that will applied to the source image - * @param hints rendering hints that will be used during transformation - */ - public AffineTransformOp (AffineTransform xform, RenderingHints hints) - { - this.transform = xform; - this.hints = hints; - if (xform.getDeterminant() == 0) - throw new ImagingOpException(null); - } - - /** - * Creates empty BufferedImage with the size equal to that of the - * transformed image and correct number of bands. The newly created - * image is created with the specified ColorModel. - * If the ColorModel is equal to null, then image is created - * with the ColorModel of the source image. - * - * @param src source image - * @param destCM color model for the destination image - * @return new compatible destination image - */ - public BufferedImage createCompatibleDestImage (BufferedImage src, - ColorModel destCM) - { - - // if destCm is not specified, use color model of the source image - - if (destCM == null) - destCM = src.getColorModel (); - - return new BufferedImage (destCM, - createCompatibleDestRaster (src.getRaster ()), - src.isAlphaPremultiplied (), - null); - - } - - /** - * Creates empty WritableRaster with the size equal to the transformed - * source raster and correct number of bands - * - * @param src source raster - * @throws RasterFormatException if resulting width or height of raster is 0 - * @return new compatible raster - */ - public WritableRaster createCompatibleDestRaster (Raster src) - { - Rectangle rect = (Rectangle) getBounds2D (src); - - // throw RasterFormatException if resulting width or height of the - // transformed raster is 0 - - if (rect.getWidth () == 0 || rect.getHeight () == 0) - throw new RasterFormatException("width or height is 0"); - - return src.createCompatibleWritableRaster ((int) rect.getWidth (), - (int) rect.getHeight ()); - } - - /** - * Transforms source image using transform specified at the constructor. - * The resulting transformed image is stored in the destination image. - * - * @param src source image - * @param dst destination image - * @return transformed source image - */ - public final BufferedImage filter (BufferedImage src, BufferedImage dst) - { - - if (dst == src) - throw new IllegalArgumentException ("src image cannot be the same as the dst image"); - - // If the destination image is null, then BufferedImage is - // created with ColorModel of the source image - - if (dst == null) - dst = createCompatibleDestImage(src, src.getColorModel ()); - - // FIXME: Must check if color models of src and dst images are the same. - // If it is not, then source image should be converted to color model - // of the destination image - - Graphics2D gr = (Graphics2D) dst.createGraphics (); - gr.setRenderingHints (hints); - gr.drawImage (src, transform, null); - return dst; - - } - - /** - * Transforms source raster using transform specified at the constructor. - * The resulting raster is stored in the destination raster. - * - * @param src source raster - * @param dst destination raster - * @return transformed raster - */ - public final WritableRaster filter (Raster src, WritableRaster dst) - { - if (dst == src) - throw new IllegalArgumentException("src image cannot be the same as" - + " the dst image"); - - if (dst == null) - dst = createCompatibleDestRaster(src); - - if (src.getNumBands() != dst.getNumBands()) - throw new IllegalArgumentException("src and dst must have same number" - + " of bands"); - - double[] dpts = new double[dst.getWidth() * 2]; - double[] pts = new double[dst.getWidth() * 2]; - for (int x = 0; x < dst.getWidth(); x++) - { - dpts[2 * x] = x + dst.getMinX(); - dpts[2 * x + 1] = x; - } - Rectangle srcbounds = src.getBounds(); - if (hints.containsValue(RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR)) - { - for (int y = dst.getMinY(); y < dst.getMinY() + dst.getHeight(); y++) - { - try { - transform.inverseTransform(dpts, 0, pts, 0, dst.getWidth() * 2); - } catch (NoninvertibleTransformException e) { - // Can't happen since the constructor traps this - e.printStackTrace(); - } - - for (int x = 0; x < dst.getWidth(); x++) - { - if (!srcbounds.contains(pts[2 * x], pts[2 * x + 1])) - continue; - dst.setDataElements(x + dst.getMinX(), y, - src.getDataElements((int)pts[2 * x], - (int)pts[2 * x + 1], - null)); - } - } - } - else if (hints.containsValue(RenderingHints.VALUE_INTERPOLATION_BILINEAR)) - { - double[] tmp = new double[4 * src.getNumBands()]; - for (int y = dst.getMinY(); y < dst.getMinY() + dst.getHeight(); y++) - { - try { - transform.inverseTransform(dpts, 0, pts, 0, dst.getWidth() * 2); - } catch (NoninvertibleTransformException e) { - // Can't happen since the constructor traps this - e.printStackTrace(); - } - - for (int x = 0; x < dst.getWidth(); x++) - { - if (!srcbounds.contains(pts[2 * x], pts[2 * x + 1])) - continue; - int xx = (int)pts[2 * x]; - int yy = (int)pts[2 * x + 1]; - double dx = (pts[2 * x] - xx); - double dy = (pts[2 * x + 1] - yy); - - // TODO write this more intelligently - if (xx == src.getMinX() + src.getWidth() - 1 || - yy == src.getMinY() + src.getHeight() - 1) - { - // bottom or right edge - Arrays.fill(tmp, 0); - src.getPixel(xx, yy, tmp); - } - else - { - // Normal case - src.getPixels(xx, yy, 2, 2, tmp); - for (int b = 0; b < src.getNumBands(); b++) - tmp[b] = dx * dy * tmp[b] - + (1 - dx) * dy * tmp[b + src.getNumBands()] - + dx * (1 - dy) * tmp[b + 2 * src.getNumBands()] - + (1 - dx) * (1 - dy) * tmp[b + 3 * src.getNumBands()]; - } - dst.setPixel(x, y, tmp); - } - } - } - else - { - // Bicubic - throw new UnsupportedOperationException("not implemented yet"); - } - - return dst; - } - - /** - * Transforms source image using transform specified at the constructor and - * returns bounds of the transformed image. - * - * @param src image to be transformed - * @return bounds of the transformed image. - */ - public final Rectangle2D getBounds2D (BufferedImage src) - { - return getBounds2D (src.getRaster()); - } - - /** - * Returns bounds of the transformed raster. - * - * @param src raster to be transformed - * @return bounds of the transformed raster. - */ - public final Rectangle2D getBounds2D (Raster src) - { - // determine new size for the transformed raster. - // Need to calculate transformed coordinates of the lower right - // corner of the raster. The upper left corner is always (0,0) - - double x2 = (double) src.getWidth () + src.getMinX (); - double y2 = (double) src.getHeight () + src.getMinY (); - Point2D p2 = getPoint2D (new Point2D.Double (x2,y2), null); - - Rectangle2D rect = new Rectangle (0, 0, (int) p2.getX (), (int) p2.getY ()); - return rect.getBounds (); - } - - /** - * Returns interpolation type used during transformations - * - * @return interpolation type - */ - public final int getInterpolationType () - { - if(hints.containsValue (RenderingHints.VALUE_INTERPOLATION_BILINEAR)) - return TYPE_BILINEAR; - else - return TYPE_NEAREST_NEIGHBOR; - } - - /** - * Returns location of the transformed source point. The resulting point - * is stored in the dstPt if one is specified. - * - * @param srcPt point to be transformed - * @param dstPt destination point - * @return the location of the transformed source point. - */ - public Point2D getPoint2D (Point2D srcPt, Point2D dstPt) - { - return transform.transform (srcPt, dstPt); - } - - /** - * Returns rendering hints that are used during transformation. - * - * @return rendering hints - */ - public final RenderingHints getRenderingHints () - { - return hints; - } - - /** - * Returns transform used in transformation between source and destination - * image. - * - * @return transform - */ - public final AffineTransform getTransform () - { - return transform; - } -} diff --git a/libjava/java/awt/image/AreaAveragingScaleFilter.java b/libjava/java/awt/image/AreaAveragingScaleFilter.java deleted file mode 100644 index b9ca1b70758..00000000000 --- a/libjava/java/awt/image/AreaAveragingScaleFilter.java +++ /dev/null @@ -1,127 +0,0 @@ -/* AreaAveragingScaleFilter.java -- Java class for filtering images - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.image; - -/** - * This filter should produce images which do not have image artifacts - * like broken lines which were originally unbroken. The cost is of - * course speed. Using bi-linear interpolation here against 4 pixel - * points should give the desired results although Sun does not - * specify what the exact algorithm should be. - * <br> - * Currently this filter does nothing and needs to be implemented. - * - * @author C. Brian Jones (cbj@gnu.org) - */ -public class AreaAveragingScaleFilter extends ReplicateScaleFilter -{ - /** - * Construct an instance of <code>AreaAveragingScaleFilter</code> which - * should be used in conjunction with a <code>FilteredImageSource</code> - * object. - * - * @param width the width of the destination image - * @param height the height of the destination image - */ - public AreaAveragingScaleFilter(int width, int height) { - super(width, height); - } - - /** - * The <code>ImageProducer</code> should call this method with a - * bit mask of hints from any of <code>RANDOMPIXELORDER</code>, - * <code>TOPDOWNLEFTRIGHT</code>, <code>COMPLETESCANLINES</code>, - * <code>SINGLEPASS</code>, <code>SINGLEFRAME</code> from the - * <code>ImageConsumer</code> interface. - * <br> - * FIXME - more than likely Sun's implementation desires - * <code>TOPDOWNLEFTRIGHT</code> order and this method is overloaded here - * in order to assure that mask is part of the hints added to - * the consumer. - * - * @param flags a bit mask of hints - * @see ImageConsumer - */ - public void setHints(int flags) - { - consumer.setHints(flags); - } - - /** - * This function delivers a rectangle of pixels where any - * pixel(m,n) is stored in the array as a <code>byte</code> at - * index (n * scansize + m + offset). - * - * @param x the x coordinate of the rectangle - * @param y the y coordinate of the rectangle - * @param w the width of the rectangle - * @param h the height of the rectangle - * @param model the <code>ColorModel</code> used to translate the pixels - * @param pixels the array of pixel values - * @param offset the index of the first pixels in the <code>pixels</code> array - * @param scansize the width to use in extracting pixels from the <code>pixels</code> array - */ - public void setPixels(int x, int y, int w, int h, - ColorModel model, byte[] pixels, int offset, int scansize) - { - consumer.setPixels(x, y, w, h, model, pixels, offset, scansize); - } - - /** - * This function delivers a rectangle of pixels where any - * pixel(m,n) is stored in the array as an <code>int</code> at - * index (n * scansize + m + offset). - * - * @param x the x coordinate of the rectangle - * @param y the y coordinate of the rectangle - * @param w the width of the rectangle - * @param h the height of the rectangle - * @param model the <code>ColorModel</code> used to translate the pixels - * @param pixels the array of pixel values - * @param offset the index of the first pixels in the <code>pixels</code> array - * @param scansize the width to use in extracting pixels from the <code>pixels</code> array - */ - public void setPixels(int x, int y, int w, int h, - ColorModel model, int[] pixels, int offset, int scansize) - { - consumer.setPixels(x, y, w, h, model, pixels, offset, scansize); - } - -} - diff --git a/libjava/java/awt/image/BandCombineOp.java b/libjava/java/awt/image/BandCombineOp.java deleted file mode 100644 index 79efb02e713..00000000000 --- a/libjava/java/awt/image/BandCombineOp.java +++ /dev/null @@ -1,168 +0,0 @@ -/* Copyright (C) 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.awt.image; - -import java.awt.Point; -import java.awt.RenderingHints; -import java.awt.geom.Point2D; -import java.awt.geom.Rectangle2D; - -/** - * Filter Raster pixels by applying a matrix. - * - * BandCombineOp applies a matrix to each pixel to produce new pixel values. - * The width of the matrix must be the same or one more than the number of - * bands in the source Raster. If one more, the pixels in the source are - * assumed to contain an implicit 1.0 at the end. - * - * The rows of the matrix are multiplied by the pixel to produce the values - * for the destination. Therefore the destination Raster must contain the - * same number of bands as the number of rows in the filter matrix. - * - * @author Jerry Quinn (jlquinn@optonline.net) - */ -public class BandCombineOp implements RasterOp -{ - private RenderingHints hints; - private float[][] matrix; - - /** - * Construct a BandCombineOp. - * - * @param matrix The matrix to filter pixels with. - * @param hints Rendering hints to apply. Ignored. - */ - public BandCombineOp(float[][] matrix, RenderingHints hints) - { - this.matrix = matrix; - this.hints = hints; - } - - /** - * Filter Raster pixels through a matrix. - * - * Applies the Op matrix to source pixes to produce dest pixels. Each row - * of the matrix is multiplied by the src pixel components to produce the - * dest pixel. If matrix is one more than the number of bands in the src, - * the last element is implicitly multiplied by 1, i.e. added to the sum - * for that dest component. - * - * If dest is null, a suitable Raster is created. This implementation uses - * createCompatibleDestRaster. - * - * @param src The source Raster. - * @param dest The destination Raster, or null. - * @returns The destination Raster or an allocated Raster. - * @see java.awt.image.RasterOp#filter(java.awt.image.Raster, - *java.awt.image.WritableRaster) - */ - public WritableRaster filter(Raster src, WritableRaster dest) { - if (dest == null) - dest = createCompatibleDestRaster(src); - - // Filter the pixels - float[] spix = new float[matrix[0].length]; - float[] dpix = new float[matrix.length]; - for (int y = src.getMinY(); y < src.getHeight() + src.getMinY(); y++) - for (int x = src.getMinX(); x < src.getWidth() + src.getMinX(); x++) - { - // In case matrix rows have implicit translation - spix[spix.length - 1] = 1.0f; - src.getPixel(x, y, spix); - for (int i = 0; i < matrix.length; i++) - { - dpix[i] = 0; - for (int j = 0; j < matrix[0].length; j++) - dpix[i] += spix[j] * matrix[i][j]; - } - dest.setPixel(x, y, dpix); - } - - return dest; - } - - /* (non-Javadoc) - * @see java.awt.image.RasterOp#getBounds2D(java.awt.image.Raster) - */ - public Rectangle2D getBounds2D(Raster src) - { - return src.getBounds(); - } - - /** - * Creates a new WritableRaster that can be used as the destination for this - * Op. This implementation creates a Banded Raster with data type FLOAT. - * @see - *java.awt.image.RasterOp#createCompatibleDestRaster(java.awt.image.Raster) - */ - public WritableRaster createCompatibleDestRaster(Raster src) - { - return Raster.createBandedRaster(DataBuffer.TYPE_FLOAT, src.getWidth(), - src.getHeight(), matrix.length, - new Point(src.getMinX(), src.getMinY())); - } - - /** Return corresponding destination point for source point. - * - * LookupOp will return the value of src unchanged. - * @param src The source point. - * @param dst The destination point. - * @see java.awt.image.RasterOp#getPoint2D(java.awt.geom.Point2D, - *java.awt.geom.Point2D) - */ - public Point2D getPoint2D(Point2D src, Point2D dst) - { - if (dst == null) return (Point2D)src.clone(); - dst.setLocation(src); - return dst; - } - - /* (non-Javadoc) - * @see java.awt.image.RasterOp#getRenderingHints() - */ - public RenderingHints getRenderingHints() - { - return hints; - } - - /** Return the matrix for this Op. */ - public float[][] getMatrix() - { - return matrix; - } - -} diff --git a/libjava/java/awt/image/BandedSampleModel.java b/libjava/java/awt/image/BandedSampleModel.java deleted file mode 100644 index cf7a0c546de..00000000000 --- a/libjava/java/awt/image/BandedSampleModel.java +++ /dev/null @@ -1,537 +0,0 @@ -/* Copyright (C) 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.awt.image; - -/** - * MultiPixelPackedSampleModel provides a single band model that supports - * multiple pixels in a single unit. Pixels have 2^n bits and 2^k pixels fit - * per data element. - * - * @author Jerry Quinn (jlquinn@optonline.net) - */ -public final class BandedSampleModel extends ComponentSampleModel -{ - private int[] bitMasks; - private int[] bitOffsets; - private int[] sampleSize; - private int dataBitOffset; - private int elemBits; - private int numberOfBits; - private int numElems; - - public BandedSampleModel(int dataType, int w, int h, int numBands) - { - super(dataType, w, h, 1, w, new int[numBands]); - } - - public BandedSampleModel(int dataType, int w, int h, int scanlineStride, - int[] bankIndices, int[] bandOffsets) - { - super(dataType, w, h, 1, scanlineStride, bankIndices, bandOffsets); - } - - public SampleModel createCompatibleSampleModel(int w, int h) - { - // NOTE: blackdown 1.4.1 sets all offsets to 0. Sun's 1.4.2 docs - // disagree. - - // Compress offsets so minimum is 0, others w*scanlineStride - int[] newoffsets = new int[bandOffsets.length]; - int[] order = new int[bandOffsets.length]; - for (int i=0; i < bandOffsets.length; i++) - order[i] = i; - // FIXME: This is N^2, but not a big issue, unless there's a lot of - // bands... - for (int i=0; i < bandOffsets.length; i++) - for (int j=i+1; j < bandOffsets.length; i++) - if (bankIndices[order[i]] > bankIndices[order[j]] - || (bankIndices[order[i]] == bankIndices[order[j]] - && bandOffsets[order[i]] > bandOffsets[order[j]])) - { - int t = order[i]; order[i] = order[j]; order[j] = t; - } - int bank = 0; - int offset = 0; - for (int i=0; i < bandOffsets.length; i++) - { - if (bankIndices[order[i]] != bank) - { - bank = bankIndices[order[i]]; - offset = 0; - } - newoffsets[order[i]] = offset; - offset += w * scanlineStride; - } - - return new BandedSampleModel(dataType, w, h, scanlineStride, bankIndices, newoffsets); - } - - - public SampleModel createSubsetSampleModel(int[] bands) - { - int[] newoff = new int[bands.length]; - int[] newbanks = new int[bands.length]; - for (int i=0; i < bands.length; i++) - { - int b = bands[i]; - newoff[i] = bandOffsets[b]; - newbanks[i] = bankIndices[b]; - } - - if (bands.length > bankIndices.length) - throw new - RasterFormatException("BandedSampleModel createSubsetSampleModel too" - +" many bands"); - - return new BandedSampleModel(dataType, width, height, scanlineStride, - newbanks, newoff); - } - - /** - * Extract all samples of one pixel and return in an array of transfer type. - * - * Extracts the pixel at x, y from data and stores samples into the array - * obj. If obj is null, a new array of getTransferType() is created. - * - * @param x The x-coordinate of the pixel rectangle to store in <code>obj</code>. - * @param y The y-coordinate of the pixel rectangle to store in <code>obj</code>. - * @param obj The primitive array to store the pixels into or null to force creation. - * @param data The DataBuffer that is the source of the pixel data. - * @return The primitive array containing the pixel data. - * @see java.awt.image.SampleModel#getDataElements(int, int, java.lang.Object, java.awt.image.DataBuffer) - */ - public Object getDataElements(int x, int y, Object obj, - DataBuffer data) - { - int pixel = getSample(x, y, 0, data); - switch (getTransferType()) - { - case DataBuffer.TYPE_BYTE: - { - byte[] b = (byte[])obj; - if (b == null) b = new byte[numBands]; - for (int i=0; i < numBands; i++) - b[i] = (byte)getSample(x, y, i, data); - return b; - } - case DataBuffer.TYPE_SHORT: - case DataBuffer.TYPE_USHORT: - { - short[] b = (short[])obj; - if (b == null) b = new short[numBands]; - for (int i=0; i < numBands; i++) - b[i] = (short)getSample(x, y, i, data); - return b; - } - case DataBuffer.TYPE_INT: - { - int[] b = (int[])obj; - if (b == null) b = new int[numBands]; - for (int i=0; i < numBands; i++) - b[i] = getSample(x, y, i, data); - return b; - } - case DataBuffer.TYPE_FLOAT: - { - float[] b = (float[])obj; - if (b == null) b = new float[numBands]; - for (int i=0; i < numBands; i++) - b[i] = getSampleFloat(x, y, i, data); - return b; - } - case DataBuffer.TYPE_DOUBLE: - { - double[] b = (double[])obj; - if (b == null) b = new double[numBands]; - for (int i=0; i < numBands; i++) - b[i] = getSample(x, y, i, data); - return b; - } - - default: - // Seems like the only sensible thing to do. - throw new ClassCastException(); - } - } - - public int[] getPixel(int x, int y, int[] iArray, DataBuffer data) - { - if (iArray == null) iArray = new int[numBands]; - for (int i=0; i < numBands; i++) - iArray[i] = getSample(x, y, 0, data); - - return iArray; - } - - /** - * Copy pixels from a region into an array. - * - * Copies the samples of the pixels in the rectangle starting at x, y that - * is w pixels wide and h scanlines high. When there is more than one band, - * the samples stored in order before the next pixel. This ordering isn't - * well specified in Sun's docs as of 1.4.2. - * - * If iArray is null, a new array is allocated, filled, and returned. - * - * @param x The x-coordinate of the pixel rectangle to store in - * <code>iArray</code>. - * @param y The y-coordinate of the pixel rectangle to store in - * <code>iArray</code>. - * @param w The width in pixels of the rectangle. - * @param h The height in pixels of the rectangle. - * @param iArray The int array to store the pixels into or null to force - * creation. - * @param data The DataBuffer that is the source of the pixel data. - * @return The primitive array containing the pixel data. - */ - public int[] getPixels(int x, int y, int w, int h, int[] iArray, - DataBuffer data) - { - if (iArray == null) iArray = new int[w*h*numBands]; - int outOffset = 0; - for (y=0; y<h; y++) - { - for (x=0; x<w;) - { - for (int b=0; b < numBands; b++) - { - int offset = bandOffsets[b] + y * scanlineStride + x; - iArray[outOffset++] = - data.getElem(bankIndices[b], offset); - } - } - } - return iArray; - } - - public int getSample(int x, int y, int b, DataBuffer data) - { - int offset = bandOffsets[b] + y * scanlineStride + x; - return data.getElem(bankIndices[b], offset); - } - - public float getSampleFloat(int x, int y, int b, DataBuffer data) - { - int offset = bandOffsets[b] + y * scanlineStride + x; - return data.getElemFloat(bankIndices[b], offset); - } - - public double getSampleDouble(int x, int y, int b, DataBuffer data) - { - int offset = bandOffsets[b] + y * scanlineStride + x; - return data.getElemDouble(bankIndices[b], offset); - } - - /** - * Copy one band's samples from a region into an array. - * - * Copies from one band the samples of the pixels in the rectangle starting - * at x, y that is w pixels wide and h scanlines high. - * - * If iArray is null, a new array is allocated, filled, and returned. - * - * @param x The x-coordinate of the pixel rectangle to store in - * <code>iArray</code>. - * @param y The y-coordinate of the pixel rectangle to store in - * <code>iArray</code>. - * @param w The width in pixels of the rectangle. - * @param h The height in pixels of the rectangle. - * @param b The band to retrieve. - * @param iArray The int array to store the pixels into or null to force - * creation. - * @param data The DataBuffer that is the source of the pixel data. - * @return The primitive array containing the pixel data. - */ - public int[] getSamples(int x, int y, int w, int h, int b, int[] iArray, - DataBuffer data) - { - if (iArray == null) iArray = new int[w*h]; - int outOffset = 0; - for (y=0; y<h; y++) - { - for (x=0; x<w;) - { - int offset = bandOffsets[b] + y * scanlineStride + x; - iArray[outOffset++] = - data.getElem(bankIndices[b], offset); - } - } - return iArray; - } - - - /** - * Set the pixel at x, y to the value in the first element of the primitive - * array obj. - * - * @param x The x-coordinate of the data elements in <code>obj</code>. - * @param y The y-coordinate of the data elements in <code>obj</code>. - * @param obj The primitive array containing the data elements to set. - * @param data The DataBuffer to store the data elements into. - * @see java.awt.image.SampleModel#setDataElements(int, int, int, int, java.lang.Object, java.awt.image.DataBuffer) - */ - public void setDataElements(int x, int y, Object obj, DataBuffer data) - { - int transferType = getTransferType(); - if (getTransferType() != data.getDataType()) - { - throw new IllegalArgumentException("transfer type ("+ - getTransferType()+"), "+ - "does not match data "+ - "buffer type (" + - data.getDataType() + - ")."); - } - - int offset = y * scanlineStride + x; - - try - { - switch (transferType) - { - case DataBuffer.TYPE_BYTE: - { - DataBufferByte out = (DataBufferByte) data; - byte[] in = (byte[]) obj; - for (int i=0; i < numBands; i++) - out.getData(bankIndices[i])[offset + bandOffsets[i]] = in[0]; - return; - } - case DataBuffer.TYPE_SHORT: - { - DataBufferShort out = (DataBufferShort) data; - short[] in = (short[]) obj; - for (int i=0; i < numBands; i++) - out.getData(bankIndices[i])[offset + bandOffsets[i]] = in[0]; - return; - } - case DataBuffer.TYPE_USHORT: - { - DataBufferUShort out = (DataBufferUShort) data; - short[] in = (short[]) obj; - for (int i=0; i < numBands; i++) - out.getData(bankIndices[i])[offset + bandOffsets[i]] = in[0]; - return; - } - case DataBuffer.TYPE_INT: - { - DataBufferInt out = (DataBufferInt) data; - int[] in = (int[]) obj; - for (int i=0; i < numBands; i++) - out.getData(bankIndices[i])[offset + bandOffsets[i]] = in[0]; - return; - } - case DataBuffer.TYPE_FLOAT: - { - DataBufferFloat out = (DataBufferFloat) data; - float[] in = (float[]) obj; - for (int i=0; i < numBands; i++) - out.getData(bankIndices[i])[offset + bandOffsets[i]] = in[0]; - return; - } - case DataBuffer.TYPE_DOUBLE: - { - DataBufferDouble out = (DataBufferDouble) data; - double[] in = (double[]) obj; - for (int i=0; i < numBands; i++) - out.getData(bankIndices[i])[offset + bandOffsets[i]] = in[0]; - return; - } - default: - throw new ClassCastException("Unsupported data type"); - } - } - catch (ArrayIndexOutOfBoundsException aioobe) - { - String msg = "While writing data elements" + - ", x="+x+", y="+y+ - ", width="+width+", height="+height+ - ", scanlineStride="+scanlineStride+ - ", offset="+offset+ - ", data.getSize()="+data.getSize()+ - ", data.getOffset()="+data.getOffset()+ - ": " + - aioobe; - throw new ArrayIndexOutOfBoundsException(msg); - } - } - - public void setPixel(int x, int y, int[] iArray, DataBuffer data) - { - for (int b=0; b < numBands; b++) - data.setElem(bankIndices[b], bandOffsets[b] + y * scanlineStride + x, - iArray[b]); - } - - public void setPixels(int x, int y, int w, int h, int[] iArray, - DataBuffer data) - { - int inOffset = 0; - for (int hh = 0; hh < h; hh++) - { - for (int ww = 0; ww < w; ww++) - { - int offset = y * scanlineStride + (x + ww); - for (int b=0; b < numBands; b++) - data.setElem(bankIndices[b], bandOffsets[b] + offset, - iArray[inOffset++]); - } - y++; - } - } - - public void setSample(int x, int y, int b, int s, DataBuffer data) - { - data.setElem(bankIndices[b], bandOffsets[b] + y * scanlineStride + x, s); - } - - public void setSample(int x, int y, int b, float s, DataBuffer data) - { - data.setElemFloat(bankIndices[b], bandOffsets[b] + y * scanlineStride + x, s); - } - - public void setSample(int x, int y, int b, double s, DataBuffer data) - { - data.setElemDouble(bankIndices[b], bandOffsets[b] + y * scanlineStride + x, s); - } - - public void setSamples(int x, int y, int w, int h, int b, int[] iArray, - DataBuffer data) - { - int inOffset = 0; - - switch (getTransferType()) - { - case DataBuffer.TYPE_BYTE: - { - DataBufferByte out = (DataBufferByte) data; - byte[] bank = out.getData(bankIndices[b]); - for (int hh = 0; hh < h; hh++) - { - for (int ww = 0; ww < w; ww++) - { - int offset = bandOffsets[b] + y * scanlineStride + (x + ww); - bank[offset] = (byte)iArray[inOffset++]; - } - y++; - } - return; - } - case DataBuffer.TYPE_SHORT: - { - DataBufferShort out = (DataBufferShort) data; - short[] bank = out.getData(bankIndices[b]); - for (int hh = 0; hh < h; hh++) - { - for (int ww = 0; ww < w; ww++) - { - int offset = bandOffsets[b] + y * scanlineStride + (x + ww); - bank[offset] = (short)iArray[inOffset++]; - } - y++; - } - return; - } - case DataBuffer.TYPE_USHORT: - { - DataBufferShort out = (DataBufferShort) data; - short[] bank = out.getData(bankIndices[b]); - for (int hh = 0; hh < h; hh++) - { - for (int ww = 0; ww < w; ww++) - { - int offset = bandOffsets[b] + y * scanlineStride + (x + ww); - bank[offset] = (short)iArray[inOffset++]; - } - y++; - } - return; - } - case DataBuffer.TYPE_INT: - { - DataBufferInt out = (DataBufferInt) data; - int[] bank = out.getData(bankIndices[b]); - for (int hh = 0; hh < h; hh++) - { - for (int ww = 0; ww < w; ww++) - { - int offset = bandOffsets[b] + y * scanlineStride + (x + ww); - bank[offset] = iArray[inOffset++]; - } - y++; - } - return; - } - case DataBuffer.TYPE_FLOAT: - case DataBuffer.TYPE_DOUBLE: - break; - default: - throw new ClassCastException("Unsupported data type"); - } - - // Default implementation probably slower for float and double - for (int hh = 0; hh < h; hh++) - { - for (int ww = 0; ww < w; ww++) - { - int offset = bandOffsets[b] + y * scanlineStride + (x + ww); - data.setElem(bankIndices[b], offset, iArray[inOffset++]); - } - y++; - } - } - - /** - * Creates a String with some information about this SampleModel. - * @return A String describing this SampleModel. - * @see java.lang.Object#toString() - */ - public String toString() - { - StringBuffer result = new StringBuffer(); - result.append(getClass().getName()); - result.append("["); - result.append("scanlineStride=").append(scanlineStride); - for(int i=0; i < bitMasks.length; i+=1) - { - result.append(", mask[").append(i).append("]=0x").append(Integer.toHexString(bitMasks[i])); - } - - result.append("]"); - return result.toString(); - } -} diff --git a/libjava/java/awt/image/BufferStrategy.java b/libjava/java/awt/image/BufferStrategy.java deleted file mode 100644 index e86aad60fe9..00000000000 --- a/libjava/java/awt/image/BufferStrategy.java +++ /dev/null @@ -1,124 +0,0 @@ -/* BufferStrategy.java -- describes image buffering resources - Copyright (C) 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.image; - -import java.awt.BufferCapabilities; -import java.awt.Graphics; - -/** - * This class describes a strategy for managing image buffering - * resources on a Canvas or Window. A given buffer strategy may make - * use of hardware acceleration or take advantage of features of the - * native graphics system. Examples of buffering strategies are - * double or triple buffering using either flipping or blitting. For - * the details of these algorithms see BufferCapabilities. - * - * To use a buffer strategy, you retrieve it from either the current - * GraphicsConfiguration or from the Component on which you'd like to - * draw. Then you can query the strategy's capabilities to make sure - * they're suitable. - * - * If the strategy's capabilities are suitable, you can obtain a - * graphics object and use it to draw with this strategy. Drawing - * with a buffer strategy requires extra care, however. You'll need - * to manually cause the next buffer to be shown on the output device. - * And since buffer strategies are usually implemented with a - * VolatileImage, you must frequently check that the contents of the - * buffer are valid and that the buffer still exists. - * - * A buffer strategy is usually implemented using a VolatileImage. - * - * @see VolatileImage - * @since 1.4 - */ -public abstract class BufferStrategy -{ - /** - * Creates a new buffer strategy. - */ - public BufferStrategy() - { - } - - /** - * Retrieves the capabilities of this buffer strategy. - * - * @return this buffer strategy's capabilities - */ - public abstract BufferCapabilities getCapabilities(); - - /** - * Retrieves a graphics object that can be used to draw using this - * buffer strategy. This method may not be synchronized so be - * careful when calling it from multiple threads. You also must - * manually dispose of this graphics object. - * - * @return a graphics object that can be used to draw using this - * buffer strategy - */ - public abstract Graphics getDrawGraphics(); - - /** - * Returns whether or not the buffer's resources have been reclaimed - * by the native graphics system. If the buffer resources have been - * lost then you'll need to obtain new resources before drawing - * again. For details, see the documentation for VolatileImage. - * - * @return true if the contents were lost, false otherwise - */ - public abstract boolean contentsLost(); - - /** - * Returns whether or not the buffer's resources were re-created and - * cleared to the default background color. If the buffer's - * resources have recently been re-created and initialized then the - * buffer's image may need to be re-rendered. For details, see the - * documentation for VolatileImage. - * - * @return true if the contents were restored, false otherwise - */ - public abstract boolean contentsRestored(); - - /** - * Applies this buffer strategy. In other words, this method brings - * the contents of the back or intermediate buffers to the front - * buffer. - */ - public abstract void show(); -} diff --git a/libjava/java/awt/image/BufferedImage.java b/libjava/java/awt/image/BufferedImage.java deleted file mode 100644 index 40da1b61910..00000000000 --- a/libjava/java/awt/image/BufferedImage.java +++ /dev/null @@ -1,693 +0,0 @@ -/* BufferedImage.java -- - Copyright (C) 2000, 2002, 2003, 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.image; - -import gnu.java.awt.ComponentDataBlitOp; - -import java.awt.Graphics; -import java.awt.Graphics2D; -import java.awt.GraphicsEnvironment; -import java.awt.Image; -import java.awt.Point; -import java.awt.Rectangle; -import java.awt.Transparency; -import java.awt.color.ColorSpace; -import java.util.HashSet; -import java.util.Hashtable; -import java.util.Iterator; -import java.util.Vector; - -/** - * A buffered image always starts at coordinates (0, 0). - * - * The buffered image is not subdivided into multiple tiles. Instead, - * the image consists of one large tile (0,0) with the width and - * height of the image. This tile is always considered to be checked - * out. - * - * @author Rolf W. Rasmussen (rolfwr@ii.uib.no) - */ -public class BufferedImage extends Image - implements WritableRenderedImage -{ - public static final int TYPE_CUSTOM = 0, - TYPE_INT_RGB = 1, - TYPE_INT_ARGB = 2, - TYPE_INT_ARGB_PRE = 3, - TYPE_INT_BGR = 4, - TYPE_3BYTE_BGR = 5, - TYPE_4BYTE_ABGR = 6, - TYPE_4BYTE_ABGR_PRE = 7, - TYPE_USHORT_565_RGB = 8, - TYPE_USHORT_555_RGB = 9, - TYPE_BYTE_GRAY = 10, - TYPE_USHORT_GRAY = 11, - TYPE_BYTE_BINARY = 12, - TYPE_BYTE_INDEXED = 13; - - static final int[] bits3 = { 8, 8, 8 }; - static final int[] bits4 = { 8, 8, 8 }; - static final int[] bits1byte = { 8 }; - static final int[] bits1ushort = { 16 }; - - static final int[] masks_int = { 0x00ff0000, - 0x0000ff00, - 0x000000ff, - DataBuffer.TYPE_INT }; - static final int[] masks_565 = { 0xf800, - 0x07e0, - 0x001f, - DataBuffer.TYPE_USHORT}; - static final int[] masks_555 = { 0x7c00, - 0x03e0, - 0x001f, - DataBuffer.TYPE_USHORT}; - - Vector observers; - - public BufferedImage(int w, int h, int type) - { - ColorModel cm = null; - - boolean alpha = false; - boolean premultiplied = false; - switch (type) - { - case TYPE_4BYTE_ABGR_PRE: - case TYPE_INT_ARGB_PRE: - premultiplied = true; - // fall through - case TYPE_INT_ARGB: - case TYPE_4BYTE_ABGR: - alpha = true; - } - - ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB); - switch (type) - { - case TYPE_INT_RGB: - case TYPE_INT_ARGB: - case TYPE_INT_ARGB_PRE: - case TYPE_USHORT_565_RGB: - case TYPE_USHORT_555_RGB: - int[] masks = null; - switch (type) - { - case TYPE_INT_RGB: - case TYPE_INT_ARGB: - case TYPE_INT_ARGB_PRE: - masks = masks_int; - break; - case TYPE_USHORT_565_RGB: - masks = masks_565; - break; - case TYPE_USHORT_555_RGB: - masks = masks_555; - break; - } - - cm = new DirectColorModel(cs, - 32, // 32 bits in an int - masks[0], // r - masks[1], // g - masks[2], // b - alpha ? 0xff000000 : 0, - premultiplied, - masks[3] // data type - ); - break; - - case TYPE_INT_BGR: - String msg = - "FIXME: Programmer is confused. Why (and how) does a " + - "TYPE_INT_BGR image use ComponentColorModel to store " + - "8-bit values? Is data type TYPE_INT or TYPE_BYTE. What " + - "is the difference between TYPE_INT_BGR and TYPE_3BYTE_BGR?"; - throw new UnsupportedOperationException(msg); - - case TYPE_3BYTE_BGR: - case TYPE_4BYTE_ABGR: - case TYPE_4BYTE_ABGR_PRE: - case TYPE_BYTE_GRAY: - case TYPE_USHORT_GRAY: - int[] bits = null; - int dataType = DataBuffer.TYPE_BYTE; - switch (type) { - case TYPE_3BYTE_BGR: - bits = bits3; - break; - case TYPE_4BYTE_ABGR: - case TYPE_4BYTE_ABGR_PRE: - bits = bits4; - break; - case TYPE_BYTE_GRAY: - bits = bits1byte; - break; - case TYPE_USHORT_GRAY: - bits = bits1ushort; - dataType = DataBuffer.TYPE_USHORT; - break; - } - cm = new ComponentColorModel(cs, bits, alpha, premultiplied, - alpha ? - Transparency.TRANSLUCENT: - Transparency.OPAQUE, - dataType); - break; - case TYPE_BYTE_BINARY: - byte[] vals = { 0, (byte) 0xff }; - cm = new IndexColorModel(8, 2, vals, vals, vals); - break; - case TYPE_BYTE_INDEXED: - String msg2 = "type not implemented yet"; - throw new UnsupportedOperationException(msg2); - // FIXME: build color-cube and create color model - } - - init(cm, - cm.createCompatibleWritableRaster(w, h), - premultiplied, - null, // no properties - type - ); - } - - public BufferedImage(int w, int h, int type, - IndexColorModel indexcolormodel) - { - if ((type != TYPE_BYTE_BINARY) && (type != TYPE_BYTE_INDEXED)) - throw new IllegalArgumentException("type must be binary or indexed"); - - init(indexcolormodel, - indexcolormodel.createCompatibleWritableRaster(w, h), - false, // not premultiplied (guess) - null, // no properties - type); - } - - public BufferedImage(ColorModel colormodel, - WritableRaster writableraster, - boolean premultiplied, - Hashtable properties) - { - init(colormodel, writableraster, premultiplied, properties, - TYPE_CUSTOM); - // TODO: perhaps try to identify type? - } - - WritableRaster raster; - ColorModel colorModel; - Hashtable properties; - boolean isPremultiplied; - int type; - - private void init(ColorModel cm, - WritableRaster writableraster, - boolean premultiplied, - Hashtable properties, - int type) - { - raster = writableraster; - colorModel = cm; - this.properties = properties; - isPremultiplied = premultiplied; - this.type = type; - } - - //public void addTileObserver(TileObserver tileobserver) {} - - public void coerceData(boolean premultiplied) - { - colorModel = colorModel.coerceData(raster, premultiplied); - } - - public WritableRaster copyData(WritableRaster dest) - { - if (dest == null) - dest = raster.createCompatibleWritableRaster(getMinX(), getMinY(), - getWidth(),getHeight()); - - int x = dest.getMinX(); - int y = dest.getMinY(); - int w = dest.getWidth(); - int h = dest.getHeight(); - - // create a src child that has the right bounds... - WritableRaster src = - raster.createWritableChild(x, y, w, h, x, y, - null // same bands - ); - if (src.getSampleModel () instanceof ComponentSampleModel - && dest.getSampleModel () instanceof ComponentSampleModel) - // Refer to ComponentDataBlitOp for optimized data blitting: - ComponentDataBlitOp.INSTANCE.filter(src, dest); - else - { - // slower path - int samples[] = src.getPixels (x, y, w, h, (int [])null); - dest.setPixels (x, y, w, h, samples); - } - return dest; - } - - public Graphics2D createGraphics() - { - GraphicsEnvironment env; - env = GraphicsEnvironment.getLocalGraphicsEnvironment (); - return env.createGraphics (this); - } - - public void flush() { - } - - public WritableRaster getAlphaRaster() - { - return colorModel.getAlphaRaster(raster); - } - - public ColorModel getColorModel() - { - return colorModel; - } - - public Raster getData() - { - return copyData(null); - /* TODO: this might be optimized by returning the same - raster (not writable) as long as image data doesn't change. */ - } - - public Raster getData(Rectangle rectangle) - { - WritableRaster dest = - raster.createCompatibleWritableRaster(rectangle); - return copyData(dest); - } - - public Graphics getGraphics() - { - return createGraphics(); - } - - public int getHeight() - { - return raster.getHeight(); - } - - public int getHeight(ImageObserver imageobserver) - { - return getHeight(); - } - - public int getMinTileX() - { - return 0; - } - - public int getMinTileY() - { - return 0; - } - - public int getMinX() - { - return 0; - } - - public int getMinY() - { - return 0; - } - - public int getNumXTiles() - { - return 1; - } - - public int getNumYTiles() - { - return 1; - } - - public Object getProperty(String string) - { - if (properties == null) - return null; - return properties.get(string); - } - - public Object getProperty(String string, ImageObserver imageobserver) - { - return getProperty(string); - } - - - public String[] getPropertyNames() - { - // FIXME: implement - return null; - } - - public int getRGB(int x, int y) - { - Object rgbElem = raster.getDataElements(x, y, - null // create as needed - ); - return colorModel.getRGB(rgbElem); - } - - public int[] getRGB(int startX, int startY, int w, int h, - int[] rgbArray, - int offset, int scanlineStride) - { - if (rgbArray == null) - { - /* - 000000000000000000 - 00000[#######----- [ = start - -----########----- ] = end - -----#######]00000 - 000000000000000000 */ - int size = (h-1)*scanlineStride + w; - rgbArray = new int[size]; - } - - int endX = startX + w; - int endY = startY + h; - - /* *TODO*: - Opportunity for optimization by examining color models... - - Perhaps wrap the rgbArray up in a WritableRaster with packed - sRGB color model and perform optimized rendering into the - array. */ - - Object rgbElem = null; - for (int y=startY; y<endY; y++) - { - int xoffset = offset; - for (int x=startX; x<endX; x++) - { - int rgb; - rgbElem = raster.getDataElements(x, y, rgbElem); - rgb = colorModel.getRGB(rgbElem); - rgbArray[xoffset++] = rgb; - } - offset += scanlineStride; - } - return rgbArray; - } - - public WritableRaster getRaster() - { - return raster; - } - - public SampleModel getSampleModel() - { - return raster.getSampleModel(); - } - - public ImageProducer getSource() - { - return new ImageProducer() { - - HashSet consumers = new HashSet(); - - public void addConsumer(ImageConsumer ic) - { - consumers.add(ic); - } - - public boolean isConsumer(ImageConsumer ic) - { - return consumers.contains(ic); - } - - public void removeConsumer(ImageConsumer ic) - { - consumers.remove(ic); - } - - public void startProduction(ImageConsumer ic) - { - int x = 0; - int y = 0; - int width = getWidth(); - int height = getHeight(); - int stride = width; - int offset = 0; - int[] pixels = getRGB(x, y, - width, height, - (int[])null, offset, stride); - ColorModel model = getColorModel(); - - consumers.add(ic); - - Iterator i = consumers.iterator(); - while(i.hasNext()) - { - ImageConsumer c = (ImageConsumer) i.next(); - c.setHints(ImageConsumer.SINGLEPASS); - c.setDimensions(getWidth(), getHeight()); - c.setPixels(x, y, width, height, model, pixels, offset, stride); - c.imageComplete(ImageConsumer.STATICIMAGEDONE); - } - } - - public void requestTopDownLeftRightResend(ImageConsumer ic) - { - startProduction(ic); - } - - }; - } - - public Vector getSources() - { - return null; - } - - public BufferedImage getSubimage(int x, int y, int w, int h) - { - WritableRaster subRaster = - getRaster().createWritableChild(x, y, w, h, 0, 0, null); - - return new BufferedImage(getColorModel(), - subRaster, - isPremultiplied, - properties); - } - - public Raster getTile(int tileX, int tileY) - { - return getWritableTile(tileX, tileY); - } - - public int getTileGridXOffset() - { - return 0; // according to javadocs - } - - public int getTileGridYOffset() - { - return 0; // according to javadocs - } - - public int getTileHeight() - { - return getHeight(); // image is one big tile - } - - public int getTileWidth() - { - return getWidth(); // image is one big tile - } - - public int getType() - { - return type; - } - - public int getWidth() - { - return raster.getWidth(); - } - - public int getWidth(ImageObserver imageobserver) - { - return getWidth(); - } - - public WritableRaster getWritableTile(int tileX, int tileY) - { - isTileWritable(tileX, tileY); // for exception - return raster; - } - - private static final Point[] tileIndices = { new Point() }; - - public Point[] getWritableTileIndices() - { - return tileIndices; - } - - public boolean hasTileWriters() - { - return true; - } - - public boolean isAlphaPremultiplied() - { - return isPremultiplied; - } - - public boolean isTileWritable(int tileX, int tileY) - { - if ((tileX != 0) || (tileY != 0)) - throw new ArrayIndexOutOfBoundsException("only tile is (0,0)"); - return true; - } - - public void releaseWritableTile(int tileX, int tileY) - { - isTileWritable(tileX, tileY); // for exception - } - - //public void removeTileObserver(TileObserver tileobserver) {} - - public void setData(Raster src) - { - int x = src.getMinX(); - int y = src.getMinY(); - int w = src.getWidth(); - int h = src.getHeight(); - - // create a dest child that has the right bounds... - WritableRaster dest = - raster.createWritableChild(x, y, w, h, x, y, - null // same bands - ); - - if (src.getSampleModel () instanceof ComponentSampleModel - && dest.getSampleModel () instanceof ComponentSampleModel) - - // Refer to ComponentDataBlitOp for optimized data blitting: - ComponentDataBlitOp.INSTANCE.filter(src, dest); - else - { - // slower path - int samples[] = src.getPixels (x, y, w, h, (int [])null); - dest.setPixels (x, y, w, h, samples); - } - } - - public void setRGB(int x, int y, int argb) - { - Object rgbElem = colorModel.getDataElements(argb, null); - raster.setDataElements(x, y, rgbElem); - } - - public void setRGB(int startX, int startY, int w, int h, - int[] argbArray, int offset, int scanlineStride) - { - int endX = startX + w; - int endY = startY + h; - - Object rgbElem = null; - for (int y=startY; y<endY; y++) - { - int xoffset = offset; - for (int x=startX; x<endX; x++) - { - int argb = argbArray[xoffset++]; - rgbElem = colorModel.getDataElements(argb, rgbElem); - raster.setDataElements(x, y, rgbElem); - } - offset += scanlineStride; - } - } - - public String toString() - { - StringBuffer buf; - - buf = new StringBuffer(/* estimated length */ 120); - buf.append("BufferedImage@"); - buf.append(Integer.toHexString(hashCode())); - buf.append(": type="); - buf.append(type); - buf.append(' '); - buf.append(colorModel); - buf.append(' '); - buf.append(raster); - - return buf.toString(); - } - - - /** - * Adds a tile observer. If the observer is already present, it receives - * multiple notifications. - * - * @param to The TileObserver to add. - */ - public void addTileObserver (TileObserver to) - { - if (observers == null) - observers = new Vector (); - - observers.add (to); - } - - /** - * Removes a tile observer. If the observer was not registered, - * nothing happens. If the observer was registered for multiple - * notifications, it is now registered for one fewer notification. - * - * @param to The TileObserver to remove. - */ - public void removeTileObserver (TileObserver to) - { - if (observers == null) - return; - - observers.remove (to); - } -} diff --git a/libjava/java/awt/image/BufferedImageFilter.java b/libjava/java/awt/image/BufferedImageFilter.java deleted file mode 100644 index 50d627d66a3..00000000000 --- a/libjava/java/awt/image/BufferedImageFilter.java +++ /dev/null @@ -1,110 +0,0 @@ -/* Copyright (C) 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.awt.image; - -import java.awt.Point; - -/** - * The BufferedImageFilter class wraps BufferedImageOp objects in a Filter. - * - * When pixels are pushed through the filter, we create a BufferedImage, - * apply the BufferedImageOp, and pass the filtered pixels to the base class. - * - * @author jlquinn@optonline.net - */ -public class BufferedImageFilter extends ImageFilter implements Cloneable -{ - private BufferedImageOp op; - - /** - * - */ - public BufferedImageFilter(BufferedImageOp op) - { - super(); - if (op == null) - throw new NullPointerException("BufferedImageFilter null" - + " op in constructor"); - this.op = op; - } - - /** - * @return Returns the contained BufferedImageOp. - */ - public BufferedImageOp getBufferedImageOp() - { - return op; - } - - // FIXME: Definitely not sure this is the right thing. I'm not sure how to - // create a compatible sample model that incorporates scansize != w. I - // asume off is handled by the db itself. - public void setPixels(int x, int y, int w, int h, ColorModel model, - byte[] pixels, int off, int scansize) - { - // Create an input BufferedImage - DataBufferByte db = new DataBufferByte(pixels, scansize * h + off, off); - SampleModel sm = model.createCompatibleSampleModel(scansize, h); - WritableRaster wr = new WritableRaster(sm, db, new Point(0, 0)); - BufferedImage in = - new BufferedImage(model, wr, model.isAlphaPremultiplied(), null); - BufferedImage out = op.createCompatibleDestImage(in, model); - op.filter(in, out); - DataBuffer dbout = out.getRaster().getDataBuffer(); - super.setPixels(0, 0, w, h, model, ((DataBufferByte)dbout).getData(), 0, - scansize); - } - - // FIXME: Definitely not sure this is the right thing. I'm not sure how - // to create a compatible sample model that incorporates - // scansize != w. I asume off is handled by the db itself. - public void setPixels(int x, int y, int w, int h, ColorModel model, - int[] pixels, int off, int scansize) - { - // Create an input BufferedImage - DataBufferInt db = new DataBufferInt(pixels, scansize * h + off, off); - SampleModel sm = model.createCompatibleSampleModel(scansize, h); - WritableRaster wr = new WritableRaster(sm, db, new Point(0, 0)); - BufferedImage in = - new BufferedImage(model, wr, model.isAlphaPremultiplied(), null); - BufferedImage out = op.createCompatibleDestImage(in, model); - op.filter(in, out); - DataBuffer dbout = out.getRaster().getDataBuffer(); - super.setPixels(0, 0, w, h, model, ((DataBufferInt)dbout).getData(), 0, - scansize); - } -} diff --git a/libjava/java/awt/image/BufferedImageOp.java b/libjava/java/awt/image/BufferedImageOp.java deleted file mode 100644 index 2ecbec056a0..00000000000 --- a/libjava/java/awt/image/BufferedImageOp.java +++ /dev/null @@ -1,55 +0,0 @@ -/* BufferedImageOp.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.image; - -import java.awt.RenderingHints; -import java.awt.geom.Point2D; -import java.awt.geom.Rectangle2D; - -/** - * NEEDS DOCUMENTATION - */ -public interface BufferedImageOp -{ - BufferedImage filter(BufferedImage src, BufferedImage dst); - Rectangle2D getBounds2D(BufferedImage src); - BufferedImage createCompatibleDestImage(BufferedImage src, ColorModel dstCM); - Point2D getPoint2D(Point2D src, Point2D dst); - RenderingHints getRenderingHints(); -} // interface BufferedImageOp diff --git a/libjava/java/awt/image/ByteLookupTable.java b/libjava/java/awt/image/ByteLookupTable.java deleted file mode 100644 index df02d0a1bf7..00000000000 --- a/libjava/java/awt/image/ByteLookupTable.java +++ /dev/null @@ -1,166 +0,0 @@ -/* ByteLookupTable.java -- Java class for a pixel translation table. - Copyright (C) 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.image; - -/** - * ByteLookupTable represents translation arrays for pixel values. It wraps - * one or more data arrays for each layer (or component) in an image, such as - * Alpha, R, G, and B. When doing translation, the offset is subtracted from - * the pixel values to allow a subset of an array to be used. - * - * @author Jerry Quinn (jlquinn@optonline.net) - * @version 1.0 - */ -public class ByteLookupTable extends LookupTable -{ - // Array of translation tables. - private byte data[][]; - - /** - * Creates a new <code>ByteLookupTable</code> instance. - * - * Offset is subtracted from pixel values when looking up in the translation - * tables. If data.length is one, the same table is applied to all pixel - * components. - * - * @param offset Offset to be subtracted. - * @param data Array of lookup tables. - * @exception IllegalArgumentException if offset < 0 or data.length < 1. - */ - public ByteLookupTable(int offset, byte[][] data) - throws IllegalArgumentException - { - super(offset, data.length); - this.data = data; - } - - /** - * Creates a new <code>ByteLookupTable</code> instance. - * - * Offset is subtracted from pixel values when looking up in the translation - * table. The same table is applied to all pixel components. - * - * @param offset Offset to be subtracted. - * @param data Lookup table for all components. - * @exception IllegalArgumentException if offset < 0. - */ - public ByteLookupTable(int offset, byte[] data) - throws IllegalArgumentException - { - super(offset, 1); - this.data = new byte[][] {data}; - } - - /** - * Return the lookup tables. - * - * @return the tables - */ - public final byte[][] getTable() - { - return data; - } - - /** - * Return translated values for a pixel. - * - * For each value in the pixel src, use the value minus offset as an index - * in the component array and copy the value there to the output for the - * component. If dest is null, the output is a new array, otherwise the - * translated values are written to dest. Dest can be the same array as - * src. - * - * For example, if the pixel src is [2, 4, 3], and offset is 1, the output - * is [comp1[1], comp2[3], comp3[2]], where comp1, comp2, and comp3 are the - * translation arrays. - * - * @param src Component values of a pixel. - * @param dst Destination array for values, or null. - * @return Translated values for the pixel. - */ - public int[] lookupPixel(int[] src, int[] dst) - throws ArrayIndexOutOfBoundsException - { - if (dst == null) - dst = new int[src.length]; - - if (data.length == 1) - for (int i=0; i < src.length; i++) - dst[i] = data[0][src[i] - offset]; - else - for (int i=0; i < src.length; i++) - dst[i] = data[i][src[i] - offset]; - - return dst; - } - - /** - * Return translated values for a pixel. - * - * For each value in the pixel src, use the value minus offset as an index - * in the component array and copy the value there to the output for the - * component. If dest is null, the output is a new array, otherwise the - * translated values are written to dest. Dest can be the same array as - * src. - * - * For example, if the pixel src is [2, 4, 3], and offset is 1, the output - * is [comp1[1], comp2[3], comp3[2]], where comp1, comp2, and comp3 are the - * translation arrays. - * - * @param src Component values of a pixel. - * @param dst Destination array for values, or null. - * @return Translated values for the pixel. - */ - public byte[] lookupPixel(byte[] src, byte[] dst) - throws ArrayIndexOutOfBoundsException - { - if (dst == null) - dst = new byte[src.length]; - - if (data.length == 1) - for (int i=0; i < src.length; i++) - dst[i] = data[0][((int)src[i]) - offset]; - else - for (int i=0; i < src.length; i++) - dst[i] = data[i][((int)src[i]) - offset]; - - return dst; - - } -} diff --git a/libjava/java/awt/image/ColorConvertOp.java b/libjava/java/awt/image/ColorConvertOp.java deleted file mode 100644 index 18609e0c4b0..00000000000 --- a/libjava/java/awt/image/ColorConvertOp.java +++ /dev/null @@ -1,319 +0,0 @@ -/* ColorModel.java -- - Copyright (C) 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.image; - -import java.awt.Graphics2D; -import java.awt.RenderingHints; -import java.awt.color.ColorSpace; -import java.awt.color.ICC_ColorSpace; -import java.awt.color.ICC_Profile; -import java.awt.geom.Point2D; -import java.awt.geom.Rectangle2D; - -/** - * ColorConvertOp is a filter for converting an image from one colorspace to - * another colorspace. The filter can convert the image through a sequence - * of colorspaces or just from source to destination. - * - * Color conversion is done on the color components without alpha. Thus - * if a BufferedImage has alpha premultiplied, this is divided out before - * color conversion, and premultiplication applied if the destination - * requires it. - * - * Color rendering and dithering hints may be applied if specified. This is - * likely platform-dependent. - * - * @author jlquinn@optonline.net - */ -public class ColorConvertOp implements BufferedImageOp, RasterOp -{ - private ColorSpace srccs; - private ColorSpace dstcs; - private RenderingHints hints; - private ICC_Profile[] profiles; - private ColorSpace[] spaces; - private boolean rasterValid; - - - /** - * Convert BufferedImage through a ColorSpace. - * - * This filter version is only valid for BufferedImages. The source image - * is converted to cspace. If the destination is not null, it is then - * converted to the destination colorspace. Normally this filter will only - * be used with a null destination. - * - * @param cspace The target color space. - * @param hints Rendering hints to use in conversion, or null. - */ - public ColorConvertOp(ColorSpace cspace, RenderingHints hints) - { - if (cspace == null) - throw new NullPointerException(); - spaces = new ColorSpace[]{cspace}; - this.hints = hints; - rasterValid = false; - } - - public ColorConvertOp(ColorSpace srcCspace, ColorSpace dstCspace, - RenderingHints hints) - { - if (srcCspace == null || dstCspace == null) - throw new NullPointerException(); - spaces = new ColorSpace[]{srcCspace, dstCspace}; - this.hints = hints; - } - - /** - * Convert from a source image destination image color space. - * - * This constructor builds a ColorConvertOp from an array of ICC_Profiles. - * The source image will be converted through the sequence of color spaces - * defined by the profiles. If the sequence of profiles doesn't give a - * well-defined conversion, throws IllegalArgumentException. - * - * NOTE: Sun's docs don't clearly define what a well-defined conversion is - * - or perhaps someone smarter can come along and sort it out. - * - * For BufferedImages, when the first and last profiles match the - * requirements of the source and destination color space respectively, the - * corresponding conversion is unnecessary. TODO: code this up. I don't - * yet understand how you determine this. - * - * For Rasters, the first and last profiles must have the same number of - * bands as the source and destination Rasters, respectively. If this is - * not the case, or there fewer than 2 profiles, an IllegalArgumentException - * will be thrown. - * - * @param profiles - * @param hints - */ - public ColorConvertOp(ICC_Profile[] profiles, RenderingHints hints) - { - if (profiles == null) - throw new NullPointerException(); - this.hints = hints; - this.profiles = profiles; - // TODO: Determine if this is well-defined. - // Create colorspace array with space for src and dest colorspace - spaces = new ColorSpace[profiles.length]; - for (int i = 0; i < profiles.length; i++) - spaces[i] = new ICC_ColorSpace(profiles[i]); - } - - /** Convert from source image color space to destination image color space. - * - * Only valid for BufferedImage objects, this Op converts from the source - * color space to the destination color space. The destination can't be - * null for this operation. - * - * @param hints Rendering hints to use during conversion, or null. - */ - public ColorConvertOp(RenderingHints hints) - { - this.hints = hints; - srccs = null; - dstcs = null; - rasterValid = false; - } - - /* (non-Javadoc) - * @see java.awt.image.BufferedImageOp#filter(java.awt.image.BufferedImage, - java.awt.image.BufferedImage) - */ - public final BufferedImage filter(BufferedImage src, BufferedImage dst) - { - // TODO: The plan is to create a scanline buffer for intermediate buffers. - // For now we just suck it up and create intermediate buffers. - - if (dst == null && spaces.length == 0) - throw new IllegalArgumentException(); - - // Make sure input isn't premultiplied by alpha - if (src.isAlphaPremultiplied()) - { - BufferedImage tmp = createCompatibleDestImage(src, src.getColorModel()); - copyimage(src, tmp); - tmp.coerceData(false); - src = tmp; - } - - ColorModel scm = src.getColorModel(); - for (int i = 0; i < spaces.length; i++) - { - ColorModel cm = scm.cloneColorModel(spaces[i]); - BufferedImage tmp = createCompatibleDestImage(src, cm); - copyimage(src, tmp); - src = tmp; - } - - // Intermediate conversions leave result in src - if (dst == null) - return src; - - // Apply final conversion - copyimage(src, dst); - return dst; - } - - /* (non-Javadoc) - * @see java.awt.image.BufferedImageOp#createCompatibleDestImage(java.awt.image.BufferedImage, java.awt.image.ColorModel) - */ - public BufferedImage createCompatibleDestImage(BufferedImage src, - ColorModel dstCM) - { - // FIXME: set properties to those in src - return new BufferedImage(dstCM, - src.getRaster().createCompatibleWritableRaster(), - src.isPremultiplied, - null); - } - - public final ICC_Profile[] getICC_Profiles() - { - return profiles; - } - - /** Return the rendering hints for this op. */ - public final RenderingHints getRenderingHints() - { - return hints; - } - - /* (non-Javadoc) - * @see java.awt.image.RasterOp#filter(java.awt.image.Raster, java.awt.image.WritableRaster) - */ - public final WritableRaster filter(Raster src, WritableRaster dest) - { - if (!rasterValid) - throw new IllegalArgumentException(); - - // Need to iterate through each color space - there must be at least 2 - for (int i = 1; i < spaces.length - 1; i++) - { - // FIXME: this is wrong. tmp needs to have the same number of bands as - // spaces[i] has. - WritableRaster tmp = createCompatibleDestRaster(src); - copyraster(src, spaces[i - 1], tmp, spaces[i]); - src = tmp; - } - - // FIXME: this is wrong. dst needs to have the same number of bands as - // spaces[i] has. - if (dest == null) - dest = createCompatibleDestRaster(src); - copyraster(src, spaces[spaces.length - 2], - dest, spaces[spaces.length - 1]); - - return dest; - } - - /* (non-Javadoc) - * @see java.awt.image.RasterOp#createCompatibleDestRaster(java.awt.image.Raster) - */ - public WritableRaster createCompatibleDestRaster(Raster src) - { - return src.createCompatibleWritableRaster(); - } - - /** Return corresponding destination point for source point. - * - * LookupOp will return the value of src unchanged. - * @param src The source point. - * @param dst The destination point. - * @see java.awt.image.RasterOp#getPoint2D(java.awt.geom.Point2D, java.awt.geom.Point2D) - */ - public final Point2D getPoint2D(Point2D src, Point2D dst) - { - if (dst == null) return (Point2D)src.clone(); - dst.setLocation(src); - return dst; - } - - /* (non-Javadoc) - * @see java.awt.image.BufferedImageOp#getBounds2D(java.awt.image.BufferedImage) - */ - public final Rectangle2D getBounds2D(BufferedImage src) - { - return src.getRaster().getBounds(); - } - - /* (non-Javadoc) - * @see java.awt.image.RasterOp#getBounds2D(java.awt.image.Raster) - */ - public final Rectangle2D getBounds2D(Raster src) - { - return src.getBounds(); - } - - // According to Sven de Marothy, we need to copy the src into the dest - // using Graphics2D, in order to use the rendering hints. - private void copyimage(BufferedImage src, BufferedImage dst) - { - Graphics2D gg = dst.createGraphics(); - gg.setRenderingHints(hints); - gg.drawImage(src, 0, 0, null); - gg.dispose(); - } - - private void copyraster(Raster src, ColorSpace scs, WritableRaster dst, - ColorSpace dcs) - { - float[] sbuf = new float[src.getNumBands()]; - - if (hints.get(RenderingHints.KEY_COLOR_RENDERING) == - RenderingHints.VALUE_COLOR_RENDER_QUALITY) - { - // use cie for accuracy - for (int y = src.getMinY(); y < src.getHeight() + src.getMinY(); y++) - for (int x = src.getMinX(); x < src.getWidth() + src.getMinX(); x++) - dst.setPixel(x, y, - dcs.fromCIEXYZ(scs.toCIEXYZ(src.getPixel(x, y, sbuf)))); - } - else - { - // use rgb - it's probably faster - for (int y = src.getMinY(); y < src.getHeight() + src.getMinY(); y++) - for (int x = src.getMinX(); x < src.getWidth() + src.getMinX(); x++) - dst.setPixel(x, y, - dcs.fromRGB(scs.toRGB(src.getPixel(x, y, sbuf)))); - } - } - -} diff --git a/libjava/java/awt/image/ColorModel.java b/libjava/java/awt/image/ColorModel.java deleted file mode 100644 index 1ebcb98a76b..00000000000 --- a/libjava/java/awt/image/ColorModel.java +++ /dev/null @@ -1,758 +0,0 @@ -/* ColorModel.java -- - Copyright (C) 1999, 2000, 2002, 2003, 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.image; - -import gnu.java.awt.Buffers; - -import java.awt.Point; -import java.awt.Transparency; -import java.awt.color.ColorSpace; -import java.lang.reflect.Constructor; -import java.util.Arrays; - -/** - * A color model operates with colors in several formats: - * - * <ul> - * <li>normalized: component samples are in range [0.0, 1.0].</li> - * - * <li>color model pixel value: all the color component samples for a - * sigle pixel packed/encoded in a way natural for the color - * model.</li> - * - * <li>color model pixel int value: only makes sense if the natural - * encoding of a single pixel can fit in a single int value.</li> - * - * <li>array of transferType containing a single pixel: the pixel is - * encoded in the natural way of the color model, taking up as many - * array elements as needed.</li> - * - * <li>sRGB pixel int value: a pixel in sRGB color space, encoded in - * default 0xAARRGGBB format, assumed not alpha premultiplied.</li> - * - * <li>single [0, 255] scaled int samples from default sRGB color - * space. These are always assumed to be alpha non-premultiplied.</li> - * - * <li>arrays of unnormalized component samples of single pixel: these - * samples are scaled and multiplied according to the color model, but - * is otherwise not packed or encoded. Each element of the array is one - * separate component sample. The color model only operate on the - * components from one pixel at a time, but using offsets, allows - * manipulation of arrays that contain the components of more than one - * pixel.</li> - * - * </ul> - * - * @author Rolf W. Rasmussen (rolfwr@ii.uib.no) - * @author C. Brian Jones (cbj@gnu.org) - */ -public abstract class ColorModel implements Transparency -{ - protected int pixel_bits; - protected int transferType; - - int[] bits; - ColorSpace cspace; - int transparency; - boolean hasAlpha; - boolean isAlphaPremultiplied; - - static int[] nArray(int value, int times) - { - int[] array = new int[times]; - java.util.Arrays.fill(array, value); - return array; - } - - static byte[] nArray(byte value, int times) - { - byte[] array = new byte[times]; - java.util.Arrays.fill(array, value); - return array; - } - - /** - * Constructs the default color model. The default color model - * can be obtained by calling <code>getRGBdefault</code> of this - * class. - * @param bits the number of bits wide used for bit size of pixel values - */ - public ColorModel(int bits) - { - this(bits * 4, // total bits, sRGB, four channels - nArray(bits, 4), // bits for each channel - ColorSpace.getInstance(ColorSpace.CS_sRGB), // sRGB - true, // has alpha - false, // not premultiplied - TRANSLUCENT, - Buffers.smallestAppropriateTransferType(bits * 4)); - } - - /** - * Constructs a ColorModel that translates pixel values to - * color/alpha components. - * - * @exception IllegalArgumentException If the length of the bit array is less - * than the number of color or alpha components in this ColorModel, or if the - * transparency is not a valid value, or if the sum of the number of bits in - * bits is less than 1 or if any of the elements in bits is less than 0. - */ - protected ColorModel(int pixel_bits, int[] bits, ColorSpace cspace, - boolean hasAlpha, boolean isAlphaPremultiplied, - int transparency, int transferType) - { - int bits_sum = 0; - for (int i = 0; i < bits.length; i++) - { - if (bits [i] < 0) - throw new IllegalArgumentException (); - - bits_sum |= bits [i]; - } - - if ((bits.length < cspace.getNumComponents()) - || (bits_sum < 1)) - throw new IllegalArgumentException (); - - this.pixel_bits = pixel_bits; - this.bits = bits; - this.cspace = cspace; - this.hasAlpha = hasAlpha; - this.isAlphaPremultiplied = isAlphaPremultiplied; - this.transparency = transparency; - this.transferType = transferType; - } - - // This is a hook for ColorConvertOp to create a colormodel with - // a new colorspace - ColorModel cloneColorModel(ColorSpace cspace) - { - Class cls = this.getClass(); - ColorModel cm; - try { - // This constructor will exist. - Constructor ctor = - cls.getConstructor(new Class[]{int.class, int[].class, - ColorSpace.class, boolean.class, - boolean.class, int.class, int.class}); - cm = (ColorModel)ctor. - newInstance(new Object[]{new Integer(pixel_bits), - bits, cspace, Boolean.valueOf(hasAlpha), - Boolean.valueOf(isAlphaPremultiplied), - new Integer(transparency), - new Integer(transferType)}); - } - catch (Exception e) - { - throw new IllegalArgumentException(); - } - return cm; - } - - public void finalize() - { - // Do nothing here. - } - - /** - * Returns the default color model which in Sun's case is an instance - * of <code>DirectColorModel</code>. - */ - public static ColorModel getRGBdefault() - { - return new DirectColorModel(32, 0xff0000, 0xff00, 0xff, 0xff000000); - } - - public final boolean hasAlpha() - { - return hasAlpha; - } - - public final boolean isAlphaPremultiplied() - { - return isAlphaPremultiplied; - } - - /** - * Get get number of bits wide used for the bit size of pixel values - */ - public int getPixelSize() - { - return pixel_bits; - } - - public int getComponentSize(int componentIdx) - { - return bits[componentIdx]; - } - - public int[] getComponentSize() - { - return bits; - } - - public int getTransparency() - { - return transparency; - } - - public int getNumComponents() - { - return getNumColorComponents() + (hasAlpha ? 1 : 0); - } - - public int getNumColorComponents() - { - return cspace.getNumComponents(); - } - - /** - * Converts pixel value to sRGB and extract red int sample scaled - * to range [0, 255]. - * - * @param pixel pixel value that will be interpreted according to - * the color model, (assumed alpha premultiplied if color model says - * so.) - * - * @return red sample scaled to range [0, 255], from default color - * space sRGB, alpha non-premultiplied. - */ - public abstract int getRed(int pixel); - - /** - * Converts pixel value to sRGB and extract green int sample - * scaled to range [0, 255]. - * - * @see #getRed(int) - */ - public abstract int getGreen(int pixel); - - /** - * Converts pixel value to sRGB and extract blue int sample - * scaled to range [0, 255]. - * - * @see #getRed(int) - */ - public abstract int getBlue(int pixel); - - /** - * Extract alpha int sample from pixel value, scaled to [0, 255]. - * - * @param pixel pixel value that will be interpreted according to - * the color model. - * - * @return alpha sample, scaled to range [0, 255]. - */ - public abstract int getAlpha(int pixel); - - /** - * Converts a pixel int value of the color space of the color - * model to a sRGB pixel int value. - * - * This method is typically overriden in subclasses to provide a - * more efficient implementation. - * - * @param pixel pixel value that will be interpreted according to - * the color model. - * - * @return a pixel in sRGB color space, encoded in default - * 0xAARRGGBB format. */ - public int getRGB(int pixel) - { - return - ((getAlpha(pixel) & 0xff) << 24) | - (( getRed(pixel) & 0xff) << 16) | - ((getGreen(pixel) & 0xff) << 8) | - (( getBlue(pixel) & 0xff) << 0); - } - - - /** - * In this color model we know that the whole pixel value will - * always be contained within the first element of the pixel - * array. - */ - final int getPixelFromArray(Object inData) { - DataBuffer data = - Buffers.createBufferFromData(transferType, inData, 1); - Object da = Buffers.getData(data); - - return data.getElem(0); - } - - /** - * Converts pixel in the given array to sRGB and extract blue int - * sample scaled to range [0-255]. - * - * This method is typically overriden in subclasses to provide a - * more efficient implementation. - * - * @param inData array of transferType containing a single pixel. The - * pixel should be encoded in the natural way of the color model. - */ - public int getRed(Object inData) - { - return getRed(getPixelFromArray(inData)); - } - - /** - * @see #getRed(Object) - */ - public int getGreen(Object inData) - { - return getGreen(getPixelFromArray(inData)); - } - - /** - * @see #getRed(Object) - */ - public int getBlue(Object inData) { - return getBlue(getPixelFromArray(inData)); - } - - /** - * @see #getRed(Object) - */ - public int getAlpha(Object inData) { - return getAlpha(getPixelFromArray(inData)); - } - - /** - * Converts a pixel in the given array of the color space of the - * color model to an sRGB pixel int value. - * - * <p>This method performs the inverse function of - * <code>getDataElements(int rgb, Object pixel)</code>. - * I.e. <code>(rgb == cm.getRGB(cm.getDataElements(rgb, - * null)))</code>. - * - * @param inData array of transferType containing a single pixel. The - * pixel should be encoded in the natural way of the color model. - * - * @return a pixel in sRGB color space, encoded in default - * 0xAARRGGBB format. - * - * @see #getDataElements(int, Object) - */ - public int getRGB(Object inData) - { - return - ((getAlpha(inData) & 0xff) << 24) | - (( getRed(inData) & 0xff) << 16) | - ((getGreen(inData) & 0xff) << 8) | - (( getBlue(inData) & 0xff) << 0); - } - - /** - * Converts an sRGB pixel int value to an array containing a - * single pixel of the color space of the color model. - * - * <p>This method performs the inverse function of - * <code>getRGB(Object inData)</code>. - * - * Outline of conversion process: - * - * <ol> - * - * <li>Convert rgb to normalized [0.0, 1.0] sRGB values.</li> - * - * <li>Convert to color space components using fromRGB in - * ColorSpace.</li> - * - * <li>If color model has alpha and should be premultiplied, - * multiply color space components with alpha value</li> - * - * <li>Scale the components to the correct number of bits.</li> - * - * <li>Arrange the components in the output array</li> - * - * </ol> - * - * @param rgb The color to be converted to dataElements. A pixel - * in sRGB color space, encoded in default 0xAARRGGBB format, - * assumed not alpha premultiplied. - * - * @param pixel to avoid needless creation of arrays, an array to - * use to return the pixel can be given. If null, a suitable array - * will be created. - * - * @return An array of transferType values representing the color, - * in the color model format. The color model defines whether the - * - * @see #getRGB(Object) - */ - public Object getDataElements(int rgb, Object pixel) - { - // subclasses has to implement this method. - throw new UnsupportedOperationException(); - } - - /** - * Fills an array with the unnormalized component samples from a - * pixel value. I.e. decompose the pixel, but not perform any - * color conversion. - * - * This method is typically overriden in subclasses to provide a - * more efficient implementation. - * - * @param pixel pixel value encoded according to the color model. - * - * @return arrays of unnormalized component samples of single - * pixel. The scale and multiplication state of the samples are - * according to the color model. Each component sample is stored - * as a separate element in the array. - */ - public int[] getComponents(int pixel, int[] components, int offset) - { - // subclasses has to implement this method. - throw new UnsupportedOperationException(); - } - - /** - * Fills an array with the unnormalized component samples from an - * array of transferType containing a single pixel. I.e. decompose - * the pixel, but not perform any color conversion. - * - * This method is typically overriden in subclasses to provide a - * more efficient implementation. - * - * @param array of transferType containing a single pixel. The - * pixel should be encoded in the natural way of the color model. - * - * @return arrays of unnormalized component samples of single - * pixel. The scale and multiplication state of the samples are - * according to the color model. Each component sample is stored - * as a separate element in the array. - */ - public int[] getComponents(Object pixel, int[] components, int offset) - { - // subclasses has to implement this method. - throw new UnsupportedOperationException(); - } - - /** - * Convert normalized components to unnormalized components. - */ - public int[] getUnnormalizedComponents(float[] normComponents, - int normOffset, - int[] components, - int offset) - { - int numComponents = getNumComponents(); - if (components == null) - { - components = new int[offset + numComponents]; - } - - for (int i=0; i<numComponents; i++) - { - float in = normComponents[normOffset++]; - int out = (int) (in * ((1<<getComponentSize(i)) - 1)); - components[offset++] = out; - } - return components; - } - - /** - * Convert unnormalized components to normalized components. - */ - public float[] getNormalizedComponents(int[] components, - int offset, - float[] normComponents, - int normOffset) - { - int numComponents = getNumComponents(); - if (normComponents == null) - { - normComponents = new float[normOffset + numComponents]; - } - - for (int i=0; i<numComponents; i++) - { - float in = components[offset++]; - float out = in / ((1<<getComponentSize(i)) - 1); - normComponents[normOffset++] = out; - } - return normComponents; - } - - /** - * Convert unnormalized components to normalized components. - * - * @since 1.4 - */ - public float[] getNormalizedComponents (Object pixel, - float[] normComponents, - int normOffset) - { - // subclasses has to implement this method. - throw new UnsupportedOperationException(); - } - - /** - * Converts the unnormalized component samples from an array to a - * pixel value. I.e. composes the pixel from component samples, but - * does not perform any color conversion or scaling of the samples. - * - * This method performs the inverse function of - * <code>getComponents(int pixel, int[] components, - * int offset)</code>. I.e. - * - * <code>(pixel == cm.getDataElement(cm.getComponents(pixel, null, - * 0), 0))</code>. - * - * This method is overriden in subclasses since this abstract class throws - * UnsupportedOperationException(). - * - * @param components Array of unnormalized component samples of single - * pixel. The scale and multiplication state of the samples are according - * to the color model. Each component sample is stored as a separate element - * in the array. - * @param offset Position of the first value of the pixel in components. - * - * @return pixel value encoded according to the color model. - */ - public int getDataElement(int[] components, int offset) - { - // subclasses have to implement this method. - throw new UnsupportedOperationException(); - } - - /** - * Converts the normalized component samples from an array to a pixel - * value. I.e. composes the pixel from component samples, but does not - * perform any color conversion or scaling of the samples. - * - * This method is typically overriden in subclasses to provide a - * more efficient implementation. The method provided by this abstract - * class converts the components to unnormalized form and returns - * getDataElement(int[], int). - * - * @param components Array of normalized component samples of single pixel. - * The scale and multiplication state of the samples are according to the - * color model. Each component sample is stored as a separate element in the - * array. - * @param offset Position of the first value of the pixel in components. - * - * @return pixel value encoded according to the color model. - * @since 1.4 - */ - public int getDataElement (float[] components, int offset) - { - return - getDataElement(getUnnormalizedComponents(components, offset, null, 0), - 0); - } - - public Object getDataElements(int[] components, int offset, Object obj) - { - // subclasses have to implement this method. - throw new UnsupportedOperationException(); - } - - /** - * Converts the normalized component samples from an array to an array of - * TransferType values. I.e. composes the pixel from component samples, but - * does not perform any color conversion or scaling of the samples. - * - * If obj is null, a new array of TransferType is allocated and returned. - * Otherwise the results are stored in obj and obj is returned. If obj is - * not long enough, ArrayIndexOutOfBounds is thrown. If obj is not an array - * of primitives, ClassCastException is thrown. - * - * This method is typically overriden in subclasses to provide a - * more efficient implementation. The method provided by this abstract - * class converts the components to unnormalized form and returns - * getDataElement(int[], int, Object). - * - * @param components Array of normalized component samples of single pixel. - * The scale and multiplication state of the samples are according to the - * color model. Each component sample is stored as a separate element in the - * array. - * @param offset Position of the first value of the pixel in components. - * @param obj Array of TransferType or null. - * - * @return pixel value encoded according to the color model. - * @throws ArrayIndexOutOfBounds - * @throws ClassCastException - * @since 1.4 - */ - public Object getDataElements(float[] components, int offset, Object obj) - { - return - getDataElements(getUnnormalizedComponents(components, offset, null, 0), - 0, obj); - } - - public boolean equals(Object obj) - { - if (!(obj instanceof ColorModel)) return false; - - ColorModel o = (ColorModel) obj; - return - (pixel_bits == o.pixel_bits) && - (transferType == o.transferType) && - (transparency == o.transparency) && - (hasAlpha == o.hasAlpha) && - (isAlphaPremultiplied == o.isAlphaPremultiplied) && - Arrays.equals(bits, o.bits) && - (cspace.equals(o.cspace)); - } - - public final ColorSpace getColorSpace() - { - return cspace; - } - - // Typically overridden - public ColorModel coerceData(WritableRaster raster, - boolean isAlphaPremultiplied) - { - if (this.isAlphaPremultiplied == isAlphaPremultiplied) - return this; - - int w = raster.getWidth(); - int h = raster.getHeight(); - int x = raster.getMinX(); - int y = raster.getMinY(); - int size = w*h; - int numColors = getNumColorComponents(); - int numComponents = getNumComponents(); - int alphaScale = (1<<getComponentSize(numColors)) - 1; - double[] pixels = raster.getPixels(x, y, w, h, (double[]) null); - - for (int i=0; i<size; i++) - { - double alpha = pixels[i*numComponents+numColors]*alphaScale; - for (int c=0; c<numColors; c++) - { - int offset = i*numComponents+c; - if (isAlphaPremultiplied) - pixels[offset] = pixels[offset]/alpha; - else - pixels[offset] = pixels[offset]*alpha; - } - } - - raster.setPixels(0, 0, w, h, pixels); - - // FIXME: what can we return? - return null; - } - - /** - * Checks if the given raster has a compatible data-layout (SampleModel). - * @param raster The Raster to test. - * @return true if raster is compatible. - */ - public boolean isCompatibleRaster(Raster raster) - { - SampleModel sampleModel = raster.getSampleModel(); - return isCompatibleSampleModel(sampleModel); - } - - // Typically overridden - public WritableRaster createCompatibleWritableRaster(int w, int h) - { - return new WritableRaster(createCompatibleSampleModel(w, h), - new Point(0, 0)); - } - - // Typically overridden - public SampleModel createCompatibleSampleModel(int w, int h) - { - throw new UnsupportedOperationException(); - } - - // Typically overridden - public boolean isCompatibleSampleModel(SampleModel sm) - { - return sm.getTransferType() == transferType; - } - - public final int getTransferType () - { - return transferType; - } - - /** - * Subclasses must override this method if it is possible for the - * color model to have an alpha channel. - * - * @return null, as per JDK 1.3 doc. Subclasses will only return - * null if no alpha raster exists. - */ - public WritableRaster getAlphaRaster(WritableRaster raster) - { - return null; - - /* It is a mystery to me why we couldn't use the following code... - - - if (!hasAlpha()) return null; - - SampleModel sm = raster.getSampleModel(); - int[] alphaBand = { sm.getNumBands() - 1 }; - SampleModel alphaModel = sm.createSubsetSampleModel(alphaBand); - DataBuffer buffer = raster.getDataBuffer(); - Point origin = new Point(0, 0); - return Raster.createWritableRaster(alphaModel, buffer, origin); - - - ...here, and avoided overriding the method in subclasses, - but the Sun docs state that this method always will return - null, and that overriding is required. Oh, well. - */ - } - - String stringParam() - { - return "pixel_bits=" + pixel_bits + - ", cspace=" + cspace + - ", transferType=" + transferType + - ", transparency=" + transparency + - ", hasAlpha=" + hasAlpha + - ", isAlphaPremultiplied=" + isAlphaPremultiplied; - } - - public String toString() - { - return getClass().getName() + "[" + stringParam() + "]"; - } -} diff --git a/libjava/java/awt/image/ComponentColorModel.java b/libjava/java/awt/image/ComponentColorModel.java deleted file mode 100644 index f56688f9362..00000000000 --- a/libjava/java/awt/image/ComponentColorModel.java +++ /dev/null @@ -1,391 +0,0 @@ -/* ComponentColorModel.java -- - Copyright (C) 2000, 2002, 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.image; - -import gnu.java.awt.Buffers; - -import java.awt.Point; -import java.awt.color.ColorSpace; - -public class ComponentColorModel extends ColorModel -{ - private static int sum(int[] values) - { - int sum = 0; - for (int i=0; i<values.length; i++) - sum += values[i]; - return sum; - } - - public ComponentColorModel(ColorSpace colorSpace, int[] bits, - boolean hasAlpha, - boolean isAlphaPremultiplied, - int transparency, int transferType) - { - super(sum(bits), bits, colorSpace, hasAlpha, isAlphaPremultiplied, - transparency, transferType); - } - - /** - * Construct a new ComponentColorModel. - * - * This constructor makes all bits of each sample significant, so for a - * transferType of DataBuffer.BYTE, the bits per sample is 8, etc. If - * both hasAlpha and isAlphaPremultiplied are true, color samples are - * assumed to be premultiplied by the alpha component. Transparency may be - * one of OPAQUE, BITMASK, or TRANSLUCENT. - * - * @param colorSpace The colorspace for this color model. - * @param hasAlpha True if there is an alpha component. - * @param isAlphaPremultiplied True if colors are already multiplied by - * alpha. - * @param transparency The type of alpha values. - * @param transferType Data type of pixel sample values. - * @since 1.4 - */ - public ComponentColorModel(ColorSpace colorSpace, - boolean hasAlpha, - boolean isAlphaPremultiplied, - int transparency, int transferType) - { - this(colorSpace, null, hasAlpha, isAlphaPremultiplied, - transparency, transferType); - } - - public int getRed(int pixel) - { - if (getNumComponents()>1) throw new IllegalArgumentException(); - return (int) getRGBFloat(pixel)[0]; - } - - public int getGreen(int pixel) - { - if (getNumComponents()>1) throw new IllegalArgumentException(); - return (int) getRGBFloat(pixel)[0]; - } - - public int getBlue(int pixel) - { - if (getNumComponents()>1) throw new IllegalArgumentException(); - return (int) getRGBFloat(pixel)[0]; - } - - public int getAlpha(int pixel) - { - if (getNumComponents()>1) throw new IllegalArgumentException(); - int shift = 8 - getComponentSize(getNumColorComponents()); - if (shift >= 0) return pixel << shift; - return pixel >> (-shift); - } - - public int getRGB(int pixel) - { - float[] rgb = getRGBFloat(pixel); - int ret = getRGB(rgb); - if (hasAlpha()) ret |= getAlpha(pixel) << 24; - return ret; - } - - - /* Note, it's OK to pass a to large array to toRGB(). Extra - elements are ignored. */ - - private float[] getRGBFloat(int pixel) - { - float[] data = { pixel }; - return cspace.toRGB(data); - } - - private float[] getRGBFloat(Object inData) - { - DataBuffer buffer = - Buffers.createBufferFromData(transferType, inData, - getNumComponents()); - int colors = getNumColorComponents(); - float[] data = new float[colors]; - - // FIXME: unpremultiply data that is premultiplied - for (int i=0; i<colors; i++) - { - float maxValue = (1<<getComponentSize(i))-1; - data[i] = buffer.getElemFloat(i)/maxValue; - } - float[] rgb = cspace.toRGB(data); - return rgb; - } - - public int getRed(Object inData) - { - return (int) getRGBFloat(inData)[0]*255; - } - - public int getGreen(Object inData) - { - return (int) getRGBFloat(inData)[1]*255; - } - - public int getBlue(Object inData) - { - return (int) getRGBFloat(inData)[2]*255; - } - - public int getAlpha(Object inData) - { - DataBuffer buffer = - Buffers.createBufferFromData(transferType, inData, - getNumComponents()); - int shift = 8 - getComponentSize(getNumColorComponents()); - int alpha = buffer.getElem(getNumColorComponents()); - if (shift >= 0) return alpha << shift; - return alpha >> (-shift); - } - - private int getRGB(float[] rgb) - { - /* NOTE: We could cast to byte instead of int here. This would - avoid bits spilling over from one bit field to - another. But, if we assume that floats are in the [0.0, - 1.0] range, this will never happen anyway. */ - - /* Remember to multiply BEFORE casting to int, otherwise, decimal - point data will be lost. */ - int ret = - (((int) (rgb[0]*255F)) << 16) | - (((int) (rgb[1]*255F)) << 8) | - (((int) (rgb[2]*255F)) << 0); - return ret; - } - - /** - * @param inData pixel data of transferType, as returned by the - * getDataElements method in SampleModel. - */ - public int getRGB(Object inData) - { - float[] rgb = getRGBFloat(inData); - int ret = getRGB(rgb); - if (hasAlpha()) ret |= getAlpha(inData) << 24; - return ret; - } - - public Object getDataElements(int rgb, Object pixel) - { - // Convert rgb to [0.0, 1.0] sRGB values. - float[] rgbFloats = { - ((rgb >> 16)&0xff)/255.0F, - ((rgb >> 8)&0xff)/255.0F, - ((rgb >> 0)&0xff)/255.0F - }; - - // Convert from rgb to color space components. - float[] data = cspace.fromRGB(rgbFloats); - DataBuffer buffer = Buffers.createBuffer(transferType, pixel, - getNumComponents()); - int numColors = getNumColorComponents(); - - if (hasAlpha()) - { - float alpha = ((rgb >> 24)&0xff)/255.0F; - - /* If color model has alpha and should be premultiplied, multiply - color space components with alpha value. */ - if (isAlphaPremultiplied()) { - for (int i=0; i<numColors; i++) - data[i] *= alpha; - } - // Scale the alpha sample to the correct number of bits. - alpha *= (1<<(bits[numColors]-1)); - // Arrange the alpha sample in the output array. - buffer.setElemFloat(numColors, alpha); - } - for (int i=0; i<numColors; i++) - { - // Scale the color samples to the correct number of bits. - float value = data[i]*(1<<(bits[i]-1)); - // Arrange the color samples in the output array. - buffer.setElemFloat(i, value); - } - return Buffers.getData(buffer); - } - - public int[] getComponents(int pixel, int[] components, int offset) - { - if (getNumComponents()>1) throw new IllegalArgumentException(); - if (components == null) - components = new int[getNumComponents() + offset]; - components[offset] = pixel; - return components; - } - - public int[] getComponents(Object pixel, int[] components, int offset) - { - DataBuffer buffer = Buffers.createBuffer(transferType, pixel, - getNumComponents()); - int numComponents = getNumComponents(); - - if (components == null) - components = new int[numComponents + offset]; - - for (int i=0; i<numComponents; i++) - components[offset++] = buffer.getElem(i); - - return components; - } - - public int getDataElement(int[] components, int offset) - { - if (getNumComponents()>1) throw new IllegalArgumentException(); - return components[offset]; - } - - public Object getDataElements(int[] components, int offset, Object obj) - { - DataBuffer buffer = Buffers.createBuffer(transferType, obj, - getNumComponents()); - int numComponents = getNumComponents(); - - for (int i=0; i<numComponents; i++) - buffer.setElem(i, components[offset++]); - - return Buffers.getData(buffer); - } - - public ColorModel coerceData(WritableRaster raster, - boolean isAlphaPremultiplied) { - if (this.isAlphaPremultiplied == isAlphaPremultiplied) - return this; - - /* TODO: provide better implementation based on the - assumptions we can make due to the specific type of the - color model. */ - super.coerceData(raster, isAlphaPremultiplied); - - return new ComponentColorModel(cspace, bits, hasAlpha(), - isAlphaPremultiplied, // argument - transparency, transferType); - } - - public boolean isCompatibleRaster(Raster raster) - { - return super.isCompatibleRaster(raster); - // FIXME: Should we test something more here? (Why override?) - } - - public WritableRaster createCompatibleWritableRaster(int w, int h) - { - SampleModel sm = createCompatibleSampleModel(w, h); - Point origin = new Point(0, 0); - return Raster.createWritableRaster(sm, origin); - } - - - /** - * Creates a <code>SampleModel</code> whose arrangement of pixel - * data is compatible to this <code>ColorModel</code>. - * - * @param w the number of pixels in the horizontal direction. - * @param h the number of pixels in the vertical direction. - */ - public SampleModel createCompatibleSampleModel(int w, int h) - { - int pixelStride, scanlineStride; - int[] bandOffsets; - - pixelStride = getNumComponents(); - scanlineStride = pixelStride * w; - - /* We might be able to re-use the same bandOffsets array among - * multiple calls to this method. However, this optimization does - * not seem worthwile because setting up descriptive data - * structures (such as SampleModels) is neglectible in comparision - * to shuffling around masses of pixel data. - */ - bandOffsets = new int[pixelStride]; - for (int i = 0; i < pixelStride; i++) - bandOffsets[i] = i; - - /* FIXME: Think about whether it would make sense to return the - * possibly more efficient PixelInterleavedSampleModel for other - * transferTypes as well. It seems unlikely that this would break - * any user applications, so the Mauve tests on this method - * might be too restrictive. - */ - switch (transferType) - { - case DataBuffer.TYPE_BYTE: - case DataBuffer.TYPE_USHORT: - return new PixelInterleavedSampleModel(transferType, w, h, - pixelStride, - scanlineStride, - bandOffsets); - - default: - return new ComponentSampleModel(transferType, w, h, - pixelStride, - scanlineStride, - bandOffsets); - } - } - - - public boolean isCompatibleSampleModel(SampleModel sm) - { - return - (sm instanceof ComponentSampleModel) && - super.isCompatibleSampleModel(sm); - } - - public WritableRaster getAlphaRaster(WritableRaster raster) - { - if (!hasAlpha()) return null; - - SampleModel sm = raster.getSampleModel(); - int[] alphaBand = { sm.getNumBands() - 1 }; - SampleModel alphaModel = sm.createSubsetSampleModel(alphaBand); - DataBuffer buffer = raster.getDataBuffer(); - Point origin = new Point(0, 0); - return Raster.createWritableRaster(alphaModel, buffer, origin); - } - - public boolean equals(Object obj) - { - if (!(obj instanceof ComponentColorModel)) return false; - return super.equals(obj); - } -} diff --git a/libjava/java/awt/image/ComponentSampleModel.java b/libjava/java/awt/image/ComponentSampleModel.java deleted file mode 100644 index 953f63c1ea1..00000000000 --- a/libjava/java/awt/image/ComponentSampleModel.java +++ /dev/null @@ -1,544 +0,0 @@ -/* Copyright (C) 2000, 2002 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.awt.image; - -import gnu.java.awt.Buffers; - -/* FIXME: This class does not yet support data type TYPE_SHORT */ - -/** - * ComponentSampleModel supports a flexible organization of pixel samples in - * memory, permitting pixel samples to be interleaved by band, by scanline, - * and by pixel. - * - * A DataBuffer for this sample model has K banks of data. Pixels have N - * samples, so there are N bands in the DataBuffer. Each band is completely - * contained in one bank of data, but a bank may contain more than one band. - * Each pixel sample is stored in a single data element. - * - * Within a bank, each band begins at an offset stored in bandOffsets. The - * banks containing the band is given by bankIndices. Within the bank, there - * are three dimensions - band, pixel, and scanline. The dimension ordering - * is controlled by bandOffset, pixelStride, and scanlineStride, which means - * that any combination of interleavings is supported. - * - * @author Rolf W. Rasmussen (rolfwr@ii.uib.no) - */ -public class ComponentSampleModel extends SampleModel -{ - protected int[] bandOffsets; - protected int[] bankIndices; - - // FIXME: Should we really shadow the numBands in the superclass? - //protected int numBands; - - /** Used when creating data buffers. */ - protected int numBanks; - - protected int scanlineStride; - - protected int pixelStride; - - private boolean tightPixelPacking = false; - - public ComponentSampleModel(int dataType, - int w, int h, - int pixelStride, - int scanlineStride, - int[] bandOffsets) - { - this(dataType, w, h, pixelStride, scanlineStride, - new int[bandOffsets.length], bandOffsets); - } - - public ComponentSampleModel(int dataType, - int w, int h, - int pixelStride, - int scanlineStride, - int[] bankIndices, - int[] bandOffsets) - { - super(dataType, w, h, bandOffsets.length); - if ((pixelStride<0) || (scanlineStride<0) || - (bandOffsets.length<1) || - (bandOffsets.length != bankIndices.length)) - throw new IllegalArgumentException(); - - this.bandOffsets = bandOffsets; - this.bankIndices = bankIndices; - - this.numBanks = 0; - for (int b=0; b<bankIndices.length; b++) - this.numBanks = Math.max(this.numBanks, bankIndices[b]+1); - - this.scanlineStride = scanlineStride; - this.pixelStride = pixelStride; - - // See if we can use some speedups - - /* FIXME: May these checks should be reserved for the - PixelInterleavedSampleModel? */ - - if (pixelStride == numBands) - { - tightPixelPacking = true; - for (int b=0; b<numBands; b++) { - if ((bandOffsets[b] != b) || (bankIndices[b] !=0)) - { - tightPixelPacking = false; - break; - } - } - } - } - - public SampleModel createCompatibleSampleModel(int w, int h) - { - return new ComponentSampleModel(dataType, w, h, pixelStride, - scanlineStride, bankIndices, - bandOffsets); - } - - public SampleModel createSubsetSampleModel(int[] bands) - { - int numBands = bands.length; - - int[] bankIndices = new int[numBands]; - int[] bandOffsets = new int[numBands]; - for (int b=0; b<numBands; b++) - { - bankIndices[b] = this.bankIndices[bands[b]]; - bandOffsets[b] = this.bandOffsets[bands[b]]; - } - - return new ComponentSampleModel(dataType, width, height, pixelStride, - scanlineStride, bankIndices, - bandOffsets); - } - - public DataBuffer createDataBuffer() - { - // Maybe this value should be precalculated in the constructor? - int highestOffset = 0; - for (int b=0; b<numBands; b++) - { - highestOffset = Math.max(highestOffset, bandOffsets[b]); - } - int size = pixelStride*(width-1) + scanlineStride*(height-1) + - highestOffset + 1; - - return Buffers.createBuffer(getDataType(), size, numBanks); - } - - public int getOffset(int x, int y) - { - return getOffset(x, y, 0); - } - - public int getOffset(int x, int y, int b) - { - return bandOffsets[b] + pixelStride*x + scanlineStride*y; - } - - public final int[] getSampleSize() - { - int size = DataBuffer.getDataTypeSize(getDataType()); - int[] sizes = new int[numBands]; - - java.util.Arrays.fill(sizes, size); - return sizes; - } - - public final int getSampleSize(int band) - { - return DataBuffer.getDataTypeSize(getDataType()); - } - - public final int[] getBankIndices() - { - return bankIndices; - } - - public final int[] getBandOffsets() - { - return bandOffsets; - } - - public final int getScanlineStride() - { - return scanlineStride; - } - - public final int getPixelStride() - { - return pixelStride; - } - - public final int getNumDataElements() - { - return numBands; - } - - public Object getDataElements(int x, int y, Object obj, DataBuffer data) - { - int xyOffset = pixelStride*x + scanlineStride*y; - - int[] totalBandDataOffsets = new int[numBands]; - - /* Notice that band and bank offsets are different. Band offsets - are managed by the sample model, and bank offsets are managed - by the data buffer. Both must be accounted for. */ - - /* FIXME: For single pixels, it is probably easier to simple - call getElem instead of calculating the bank offset ourself. - - On the other hand, then we need to push the value through - the int type returned by the getElem method. */ - - int[] bankOffsets = data.getOffsets(); - - for (int b=0; b<numBands; b++) - { - totalBandDataOffsets[b] = - bandOffsets[b]+bankOffsets[bankIndices[b]] + xyOffset; - } - - try - { - switch (getTransferType()) - { - case DataBuffer.TYPE_BYTE: - DataBufferByte inByte = (DataBufferByte) data; - byte[] outByte = (byte[]) obj; - if (outByte == null) outByte = new byte[numBands]; - - for (int b=0; b<numBands; b++) - { - int dOffset = totalBandDataOffsets[b]; - outByte[b] = inByte.getData(bankIndices[b])[dOffset]; - } - return outByte; - - case DataBuffer.TYPE_USHORT: - DataBufferUShort inUShort = (DataBufferUShort) data; - short[] outUShort = (short[]) obj; - if (outUShort == null) outUShort = new short[numBands]; - - for (int b=0; b<numBands; b++) - { - int dOffset = totalBandDataOffsets[b]; - outUShort[b] = inUShort.getData(bankIndices[b])[dOffset]; - } - return outUShort; - - case DataBuffer.TYPE_SHORT: - DataBufferShort inShort = (DataBufferShort) data; - short[] outShort = (short[]) obj; - if (outShort == null) outShort = new short[numBands]; - - for (int b=0; b<numBands; b++) - { - int dOffset = totalBandDataOffsets[b]; - outShort[b] = inShort.getData(bankIndices[b])[dOffset]; - } - return outShort; - - case DataBuffer.TYPE_INT: - DataBufferInt inInt = (DataBufferInt) data; - int[] outInt = (int[]) obj; - if (outInt == null) outInt = new int[numBands]; - - for (int b=0; b<numBands; b++) - { - int dOffset = totalBandDataOffsets[b]; - outInt[b] = inInt.getData(bankIndices[b])[dOffset]; - } - return outInt; - - case DataBuffer.TYPE_FLOAT: - DataBufferFloat inFloat = (DataBufferFloat) data; - float[] outFloat = (float[]) obj; - if (outFloat == null) outFloat = new float[numBands]; - - for (int b=0; b<numBands; b++) - { - int dOffset = totalBandDataOffsets[b]; - outFloat[b] = inFloat.getData(bankIndices[b])[dOffset]; - } - return outFloat; - - case DataBuffer.TYPE_DOUBLE: - DataBufferDouble inDouble = (DataBufferDouble) data; - double[] outDouble = (double[]) obj; - if (outDouble == null) outDouble = new double[numBands]; - - for (int b=0; b<numBands; b++) - { - int dOffset = totalBandDataOffsets[b]; - outDouble[b] = inDouble.getData(bankIndices[b])[dOffset]; - } - return outDouble; - - default: - throw new IllegalStateException("unknown transfer type " + - getTransferType()); - } - } - catch (ArrayIndexOutOfBoundsException aioobe) - { - String msg = "While reading data elements, " + - "x=" + x + ", y=" + y +", " + ", xyOffset=" + xyOffset + - ", data.getSize()=" + data.getSize() + ": " + aioobe; - throw new ArrayIndexOutOfBoundsException(msg); - } - } - - public Object getDataElements(int x, int y, int w, int h, Object obj, - DataBuffer data) - { - if (!tightPixelPacking) - { - return super.getDataElements(x, y, w, h, obj, data); - } - - // using get speedup - - // We can copy whole rows - int rowSize = w*numBands; - int dataSize = rowSize*h; - - DataBuffer transferBuffer = - Buffers.createBuffer(getTransferType(), obj, dataSize); - obj = Buffers.getData(transferBuffer); - - int inOffset = - pixelStride*x + - scanlineStride*y + - data.getOffset(); // Assumes only one band is used - - /* We don't add band offsets since we assume that bands have - offsets 0, 1, 2, ... */ - - // See if we can copy everything in one go - if (scanlineStride == rowSize) - { - // Collapse scan lines: - rowSize *= h; - // We ignore scanlineStride since it won't be of any use - h = 1; - } - - int outOffset = 0; - Object inArray = Buffers.getData(data); - for (int yd = 0; yd<h; yd++) - { - System.arraycopy(inArray, inOffset, obj, outOffset, rowSize); - inOffset += scanlineStride; - outOffset += rowSize; - } - return obj; - } - - public void setDataElements(int x, int y, int w, int h, - Object obj, DataBuffer data) - { - if (!tightPixelPacking) - { - super.setDataElements(x, y, w, h, obj, data); - return; - } - - // using set speedup, we can copy whole rows - int rowSize = w*numBands; - int dataSize = rowSize*h; - - DataBuffer transferBuffer = - Buffers.createBufferFromData(getTransferType(), obj, dataSize); - - int[] bankOffsets = data.getOffsets(); - - int outOffset = - pixelStride*x + - scanlineStride*y + - bankOffsets[0]; // same assuptions as in get... - - // See if we can copy everything in one go - if (scanlineStride == rowSize) - { - // Collapse scan lines: - rowSize *= h; - h = 1; - } - - int inOffset = 0; - Object outArray = Buffers.getData(data); - for (int yd = 0; yd<h; yd++) - { - System.arraycopy(obj, inOffset, outArray, outOffset, rowSize); - outOffset += scanlineStride; - inOffset += rowSize; - } - } - - public int[] getPixel(int x, int y, int[] iArray, DataBuffer data) - { - int offset = pixelStride*x + scanlineStride*y; - if (iArray == null) iArray = new int[numBands]; - for (int b=0; b<numBands; b++) - { - iArray[b] = data.getElem(bankIndices[b], offset+bandOffsets[b]); - } - return iArray; - } - - public int[] getPixels(int x, int y, int w, int h, int[] iArray, - DataBuffer data) - { - int offset = pixelStride*x + scanlineStride*y; - if (iArray == null) iArray = new int[numBands*w*h]; - int outOffset = 0; - for (y=0; y<h; y++) - { - int lineOffset = offset; - for (x=0; x<w; x++) - { - for (int b=0; b<numBands; b++) - { - iArray[outOffset++] = - data.getElem(bankIndices[b], lineOffset+bandOffsets[b]); - } - lineOffset += pixelStride; - } - offset += scanlineStride; - } - return iArray; - } - - public int getSample(int x, int y, int b, DataBuffer data) - { - return data.getElem(bankIndices[b], getOffset(x, y, b)); - } - - public void setDataElements(int x, int y, Object obj, DataBuffer data) - { - int offset = pixelStride*x + scanlineStride*y; - int[] totalBandDataOffsets = new int[numBands]; - int[] bankOffsets = data.getOffsets(); - for (int b=0; b<numBands; b++) - totalBandDataOffsets[b] = - bandOffsets[b]+bankOffsets[bankIndices[b]] + offset; - - switch (getTransferType()) - { - case DataBuffer.TYPE_BYTE: - { - DataBufferByte out = (DataBufferByte) data; - byte[] in = (byte[]) obj; - - for (int b=0; b<numBands; b++) - out.getData(bankIndices[b])[totalBandDataOffsets[b]] = in[b]; - - return; - } - case DataBuffer.TYPE_USHORT: - { - DataBufferUShort out = (DataBufferUShort) data; - short[] in = (short[]) obj; - - for (int b=0; b<numBands; b++) - out.getData(bankIndices[b])[totalBandDataOffsets[b]] = in[b]; - - return; - } - case DataBuffer.TYPE_SHORT: - { - DataBufferShort out = (DataBufferShort) data; - short[] in = (short[]) obj; - - for (int b=0; b<numBands; b++) - out.getData(bankIndices[b])[totalBandDataOffsets[b]] = in[b]; - - return; - } - case DataBuffer.TYPE_INT: - { - DataBufferInt out = (DataBufferInt) data; - int[] in = (int[]) obj; - - for (int b=0; b<numBands; b++) - out.getData(bankIndices[b])[totalBandDataOffsets[b]] = in[b]; - - return; - } - case DataBuffer.TYPE_FLOAT: - { - DataBufferFloat out = (DataBufferFloat) data; - float[] in = (float[]) obj; - - for (int b=0; b<numBands; b++) - out.getData(bankIndices[b])[totalBandDataOffsets[b]] = in[b]; - - return; - } - case DataBuffer.TYPE_DOUBLE: - { - DataBufferDouble out = (DataBufferDouble) data; - double[] in = (double[]) obj; - - for (int b=0; b<numBands; b++) - out.getData(bankIndices[b])[totalBandDataOffsets[b]] = in[b]; - - return; - } - default: - throw new UnsupportedOperationException("transfer type not " + - "implemented"); - } - } - - public void setPixel(int x, int y, int[] iArray, DataBuffer data) - { - int offset = pixelStride*x + scanlineStride*y; - for (int b=0; b<numBands; b++) - data.setElem(bankIndices[b], offset+bandOffsets[b], iArray[b]); - } - - public void setSample(int x, int y, int b, int s, DataBuffer data) - { - data.setElem(bankIndices[b], getOffset(x, y, b), s); - } -} diff --git a/libjava/java/awt/image/ConvolveOp.java b/libjava/java/awt/image/ConvolveOp.java deleted file mode 100644 index f841c13557f..00000000000 --- a/libjava/java/awt/image/ConvolveOp.java +++ /dev/null @@ -1,337 +0,0 @@ -/* ConvolveOp.java -- - Copyright (C) 2004 Free Software Foundation -- ConvolveOp - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.image; - -import java.awt.Graphics2D; -import java.awt.RenderingHints; -import java.awt.geom.Point2D; -import java.awt.geom.Rectangle2D; -import java.util.Arrays; - -/** - * Convolution filter. - * - * ConvolveOp convolves the source image with a Kernel to generate a - * destination image. This involves multiplying each pixel and its neighbors - * with elements in the kernel to compute a new pixel. - * - * Each band in a Raster is convolved and copied to the destination Raster. - * - * For BufferedImages, convolution is applied to all components. If the - * source is not premultiplied, the data will be premultiplied before - * convolving. Premultiplication will be undone if the destination is not - * premultiplied. Color conversion will be applied if needed. - * - * @author jlquinn@optonline.net - */ -public class ConvolveOp implements BufferedImageOp, RasterOp -{ - /** Edge pixels are set to 0. */ - public static final int EDGE_ZERO_FILL = 0; - - /** Edge pixels are copied from the source. */ - public static final int EDGE_NO_OP = 1; - - private Kernel kernel; - private int edge; - private RenderingHints hints; - - /** - * Construct a ConvolveOp. - * - * The edge condition specifies that pixels outside the area that can be - * filtered are either set to 0 or copied from the source image. - * - * @param kernel The kernel to convolve with. - * @param edgeCondition Either EDGE_ZERO_FILL or EDGE_NO_OP. - * @param hints Rendering hints for color conversion, or null. - */ - public ConvolveOp(Kernel kernel, - int edgeCondition, - RenderingHints hints) - { - this.kernel = kernel; - edge = edgeCondition; - this.hints = hints; - } - - /** - * Construct a ConvolveOp. - * - * The edge condition defaults to EDGE_ZERO_FILL. - * - * @param kernel The kernel to convolve with. - */ - public ConvolveOp(Kernel kernel) - { - this.kernel = kernel; - edge = EDGE_ZERO_FILL; - hints = null; - } - - - /* (non-Javadoc) - * @see java.awt.image.BufferedImageOp#filter(java.awt.image.BufferedImage, - * java.awt.image.BufferedImage) - */ - public BufferedImage filter(BufferedImage src, BufferedImage dst) - { - if (src == dst) - throw new IllegalArgumentException(); - - if (dst == null) - dst = createCompatibleDestImage(src, src.getColorModel()); - - // Make sure source image is premultiplied - BufferedImage src1 = src; - if (!src.isPremultiplied) - { - src1 = createCompatibleDestImage(src, src.getColorModel()); - src.copyData(src1.getRaster()); - src1.coerceData(true); - } - - BufferedImage dst1 = dst; - if (!src.getColorModel().equals(dst.getColorModel())) - dst1 = createCompatibleDestImage(src, src.getColorModel()); - - filter(src1.getRaster(), dst1.getRaster()); - - if (dst1 != dst) - { - // Convert between color models. - // TODO Check that premultiplied alpha is handled correctly here. - Graphics2D gg = dst.createGraphics(); - gg.setRenderingHints(hints); - gg.drawImage(dst1, 0, 0, null); - gg.dispose(); - } - - return dst; - } - - /* (non-Javadoc) - * @see - * java.awt.image.BufferedImageOp#createCompatibleDestImage(java.awt.image.BufferedImage, - * java.awt.image.ColorModel) - */ - public BufferedImage createCompatibleDestImage(BufferedImage src, - ColorModel dstCM) - { - // FIXME: set properties to those in src - return new BufferedImage(dstCM, - src.getRaster().createCompatibleWritableRaster(), - src.isPremultiplied, null); - } - - /* (non-Javadoc) - * @see java.awt.image.RasterOp#getRenderingHints() - */ - public RenderingHints getRenderingHints() - { - return hints; - } - - /** - * @return The edge condition. - */ - public int getEdgeCondition() - { - return edge; - } - - /** - * @return The convolution kernel. - */ - public Kernel getKernel() - { - return kernel; - } - - /* (non-Javadoc) - * @see java.awt.image.RasterOp#filter(java.awt.image.Raster, - * java.awt.image.WritableRaster) - */ - public WritableRaster filter(Raster src, WritableRaster dest) { - if (src.numBands != dest.numBands) - throw new ImagingOpException(null); - if (src == dest) - throw new IllegalArgumentException(); - if (src.getWidth() < kernel.getWidth() || - src.getHeight() < kernel.getHeight()) - throw new ImagingOpException(null); - - if (dest == null) - dest = createCompatibleDestRaster(src); - - // Deal with bottom edge - if (edge == EDGE_ZERO_FILL) - { - float[] zeros = new float[src.getNumBands() * src.getWidth() - * (kernel.getYOrigin() - 1)]; - Arrays.fill(zeros, 0); - dest.setPixels(src.getMinX(), src.getMinY(), src.getWidth(), - kernel.getYOrigin() - 1, zeros); - } - else - { - float[] vals = new float[src.getNumBands() * src.getWidth() - * (kernel.getYOrigin() - 1)]; - src.getPixels(src.getMinX(), src.getMinY(), src.getWidth(), - kernel.getYOrigin() - 1, vals); - dest.setPixels(src.getMinX(), src.getMinY(), src.getWidth(), - kernel.getYOrigin() - 1, vals); - } - - // Handle main section - float[] kvals = kernel.getKernelData(null); - - float[] tmp = new float[kernel.getWidth() * kernel.getHeight()]; - for (int y = src.getMinY() + kernel.getYOrigin(); - y < src.getMinY() + src.getHeight() - kernel.getYOrigin() / 2; y++) - { - // Handle unfiltered edge pixels at start of line - float[] t1 = new float[(kernel.getXOrigin() - 1) * src.getNumBands()]; - if (edge == EDGE_ZERO_FILL) - Arrays.fill(t1, 0); - else - src.getPixels(src.getMinX(), y, kernel.getXOrigin() - 1, 1, t1); - dest.setPixels(src.getMinX(), y, kernel.getXOrigin() - 1, 1, t1); - - for (int x = src.getMinX(); x < src.getWidth() + src.getMinX(); x++) - { - // FIXME: This needs a much more efficient implementation - for (int b = 0; b < src.getNumBands(); b++) - { - float v = 0; - src.getSamples(x, y, kernel.getWidth(), kernel.getHeight(), b, tmp); - for (int i=0; i < tmp.length; i++) - v += tmp[i] * kvals[i]; - dest.setSample(x, y, b, v); - } - } - - // Handle unfiltered edge pixels at end of line - float[] t2 = new float[(kernel.getWidth() / 2) * src.getNumBands()]; - if (edge == EDGE_ZERO_FILL) - Arrays.fill(t2, 0); - else - src.getPixels(src.getMinX() + src.getWidth() - - (kernel.getWidth() / 2), - y, kernel.getWidth() / 2, 1, t2); - dest.setPixels(src.getMinX() + src.getWidth() - (kernel.getWidth() / 2), - y, kernel.getWidth() / 2, 1, t2); - } - for (int y = src.getMinY(); y < src.getHeight() + src.getMinY(); y++) - for (int x = src.getMinX(); x< src.getWidth() + src.getMinX(); x++) - { - - } - for (int y = src.getMinY(); y < src.getHeight() + src.getMinY(); y++) - for (int x = src.getMinX(); x< src.getWidth() + src.getMinX(); x++) - { - - } - - // Handle top edge - if (edge == EDGE_ZERO_FILL) - { - float[] zeros = new float[src.getNumBands() * src.getWidth() * - (kernel.getHeight() / 2)]; - Arrays.fill(zeros, 0); - dest.setPixels(src.getMinX(), - src.getHeight() + src.getMinY() - (kernel.getHeight() / 2), - src.getWidth(), kernel.getHeight() / 2, zeros); - } - else - { - float[] vals = new float[src.getNumBands() * src.getWidth() * - (kernel.getHeight() / 2)]; - src.getPixels(src.getMinX(), - src.getHeight() + src.getMinY() - - (kernel.getHeight() / 2), - src.getWidth(), kernel.getHeight() / 2, vals); - dest.setPixels(src.getMinX(), - src.getHeight() + src.getMinY() - - (kernel.getHeight() / 2), - src.getWidth(), kernel.getHeight() / 2, vals); - } - - return dest; - } - - /* (non-Javadoc) - * @see java.awt.image.RasterOp#createCompatibleDestRaster(java.awt.image.Raster) - */ - public WritableRaster createCompatibleDestRaster(Raster src) - { - return src.createCompatibleWritableRaster(); - } - - /* (non-Javadoc) - * @see java.awt.image.BufferedImageOp#getBounds2D(java.awt.image.BufferedImage) - */ - public Rectangle2D getBounds2D(BufferedImage src) - { - return src.getRaster().getBounds(); - } - - /* (non-Javadoc) - * @see java.awt.image.RasterOp#getBounds2D(java.awt.image.Raster) - */ - public Rectangle2D getBounds2D(Raster src) - { - return src.getBounds(); - } - - /** Return corresponding destination point for source point. - * - * ConvolveOp will return the value of src unchanged. - * @param src The source point. - * @param dst The destination point. - * @see java.awt.image.RasterOp#getPoint2D(java.awt.geom.Point2D, - * java.awt.geom.Point2D) - */ - public Point2D getPoint2D(Point2D src, Point2D dst) - { - if (dst == null) return (Point2D)src.clone(); - dst.setLocation(src); - return dst; - } -} diff --git a/libjava/java/awt/image/CropImageFilter.java b/libjava/java/awt/image/CropImageFilter.java deleted file mode 100644 index 490f43cd728..00000000000 --- a/libjava/java/awt/image/CropImageFilter.java +++ /dev/null @@ -1,180 +0,0 @@ -/* CropImageFilter.java -- Java class for cropping image filter - Copyright (C) 1999, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.image; - -import java.awt.Rectangle; -import java.util.Hashtable; - -/** - * Currently this filter does almost nothing and needs to be implemented. - * - * @author C. Brian Jones (cbj@gnu.org) - */ -public class CropImageFilter extends ImageFilter -{ - int x; - int y; - int width; - int height; - - /** - * Construct a new <code>CropImageFilter</code> instance. - * - * @param x the x-coordinate location of the top-left of the cropped rectangle - * @param y the y-coordinate location of the top-left of the cropped rectangle - * @param width the width of the cropped rectangle - * @param height the height of the cropped rectangle - */ - public CropImageFilter(int x, int y, int width, int height) { - this.x = x; - this.y = y; - this.width = width; - this.height = height; - } - - /** - * An <code>ImageProducer</code> indicates the size of the image - * being produced using this method. This filter overrides this - * method in order to set the dimentions to the size of the - * cropped rectangle instead of the size of the image. - * - * @param width the width of the image - * @param height the height of the image - */ - public void setDimensions(int width, int height) - { - consumer.setDimensions(this.width, this.height); - } - - /** - * An <code>ImageProducer</code> can set a list of properties - * associated with this image by using this method. - * <br> - * FIXME - What property is set for this class? - * - * @param props the list of properties associated with this image - */ - public void setProperties(Hashtable props) - { - props.put("filters", "CropImageFilter"); - consumer.setProperties(props); - } - - /** - * This function delivers a rectangle of pixels where any - * pixel(m,n) is stored in the array as a <code>byte</code> at - * index (n * scansize + m + offset). - * - * @param x the x coordinate of the rectangle - * @param y the y coordinate of the rectangle - * @param w the width of the rectangle - * @param h the height of the rectangle - * @param model the <code>ColorModel</code> used to translate the pixels - * @param pixels the array of pixel values - * @param offset the index of the first pixels in the <code>pixels</code> array - * @param scansize the width to use in extracting pixels from the <code>pixels</code> array - */ - public void setPixels(int x, int y, int w, int h, - ColorModel model, byte[] pixels, int offset, int scansize) - { - Rectangle filterBounds = new Rectangle(this.x, this.y, - this.width, this.height); - Rectangle pixelBounds = new Rectangle(x, y, w, h); - - if (filterBounds.intersects(pixelBounds)) - { - Rectangle bounds = filterBounds.intersection(pixelBounds); - - byte[] cropped = new byte[bounds.width * bounds.height]; - for (int i = 0; i < bounds.height; i++) - { - int start = (bounds.y - pixelBounds.y + i) * scansize + offset; - - for (int j = 0; j < bounds.width; j++) - cropped[i * bounds.width + j] = pixels[start + bounds.x + j]; - } - - consumer.setPixels(bounds.x, bounds.y, - bounds.width, bounds.height, - model, cropped, 0, bounds.width); - } - } - - /** - * This function delivers a rectangle of pixels where any - * pixel(m,n) is stored in the array as an <code>int</code> at - * index (n * scansize + m + offset). - * - * @param x the x coordinate of the rectangle - * @param y the y coordinate of the rectangle - * @param w the width of the rectangle - * @param h the height of the rectangle - * @param model the <code>ColorModel</code> used to translate the pixels - * @param pixels the array of pixel values - * @param offset the index of the first pixels in the <code>pixels</code> array - * @param scansize the width to use in extracting pixels from the <code>pixels</code> array - */ - public void setPixels(int x, int y, int w, int h, - ColorModel model, int[] pixels, int offset, int scansize) - { - Rectangle filterBounds = new Rectangle(this.x, this.y, - this.width, this.height); - Rectangle pixelBounds = new Rectangle(x, y, w, h); - - if (filterBounds.intersects(pixelBounds)) - { - Rectangle bounds = filterBounds.intersection(pixelBounds); - - int[] cropped = new int[bounds.width * bounds.height]; - for (int i = 0; i < bounds.height; i++) - { - int start = (bounds.y - pixelBounds.y + i) * scansize + offset; - - for (int j = 0; j < bounds.width; j++) - cropped[i * bounds.width + j] = pixels[start + bounds.x + j]; - } - - consumer.setPixels(bounds.x, bounds.y, - bounds.width, bounds.height, - model, cropped, 0, bounds.width); - } - } - -} - diff --git a/libjava/java/awt/image/DataBuffer.java b/libjava/java/awt/image/DataBuffer.java deleted file mode 100644 index 5bff6901e64..00000000000 --- a/libjava/java/awt/image/DataBuffer.java +++ /dev/null @@ -1,436 +0,0 @@ -/* Copyright (C) 2000, 2002 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.awt.image; - -/** - * Class that manages arrays of data elements. A data buffer consists - * of one or more banks. A bank is a continuous region of data - * elements. - * - * @author Rolf W. Rasmussen (rolfwr@ii.uib.no) - */ -public abstract class DataBuffer -{ - /** - * A constant representng a data type that uses <code>byte</code> primitives - * as the storage unit. - */ - public static final int TYPE_BYTE = 0; - - /** - * A constant representng a data type that uses <code>short</code> - * primitives as the storage unit. - */ - public static final int TYPE_USHORT = 1; - - /** - * A constant representng a data type that uses <code>short</code> - * primitives as the storage unit. - */ - public static final int TYPE_SHORT = 2; - - /** - * A constant representng a data type that uses <code>int</code> - * primitives as the storage unit. - */ - public static final int TYPE_INT = 3; - - /** - * A constant representng a data type that uses <code>float</code> - * primitives as the storage unit. - */ - public static final int TYPE_FLOAT = 4; - - /** - * A constant representng a data type that uses <code>double</code> - * primitives as the storage unit. - */ - public static final int TYPE_DOUBLE = 5; - - /** - * A constant representng an undefined data type. - */ - public static final int TYPE_UNDEFINED = 32; - - /** The type of the data elements stored in the data buffer. */ - protected int dataType; - - /** The number of banks in this buffer. */ - protected int banks = 1; - - /** Offset into the default (0'th) bank). */ - protected int offset; // FIXME: Is offsets[0] always mirrored in offset? - - /** The size of the banks. */ - protected int size; - - /** Offset into each bank. */ - protected int[] offsets; - - /** - * Creates a new <code>DataBuffer</code> with the specified data type and - * size. The <code>dataType</code> should be one of the constants - * {@link #TYPE_BYTE}, {@link #TYPE_SHORT}, {@link #TYPE_USHORT}, - * {@link #TYPE_INT}, {@link #TYPE_FLOAT} and {@link #TYPE_DOUBLE}. - * <p> - * The physical (array-based) storage is allocated by a subclass. - * - * @param dataType the data type. - * @param size the number of elements in the buffer. - */ - protected DataBuffer(int dataType, int size) - { - this.dataType = dataType; - this.size = size; - } - - /** - * Creates a new <code>DataBuffer</code> with the specified data type, - * size and number of banks. The <code>dataType</code> should be one of - * the constants {@link #TYPE_BYTE}, {@link #TYPE_SHORT}, - * {@link #TYPE_USHORT}, {@link #TYPE_INT}, {@link #TYPE_FLOAT} and - * {@link #TYPE_DOUBLE}. - * <p> - * The physical (array-based) storage is allocated by a subclass. - * - * @param dataType the data type. - * @param size the number of elements in the buffer. - * @param numBanks the number of data banks. - */ - protected DataBuffer(int dataType, int size, int numBanks) { - this(dataType, size); - banks = numBanks; - offsets = new int[numBanks]; - } - - /** - * Creates a new <code>DataBuffer</code> with the specified data type, - * size and number of banks. An offset (which applies to all banks) is - * also specified. The <code>dataType</code> should be one of - * the constants {@link #TYPE_BYTE}, {@link #TYPE_SHORT}, - * {@link #TYPE_USHORT}, {@link #TYPE_INT}, {@link #TYPE_FLOAT} and - * {@link #TYPE_DOUBLE}. - * <p> - * The physical (array-based) storage is allocated by a subclass. - * - * @param dataType the data type. - * @param size the number of elements in the buffer. - * @param numBanks the number of data banks. - * @param offset the offset to the first element for all banks. - */ - protected DataBuffer(int dataType, int size, int numBanks, int offset) { - this(dataType, size, numBanks); - - java.util.Arrays.fill(offsets, offset); - - this.offset = offset; - } - - /** - * Creates a new <code>DataBuffer</code> with the specified data type, - * size and number of banks. An offset (which applies to all banks) is - * also specified. The <code>dataType</code> should be one of - * the constants {@link #TYPE_BYTE}, {@link #TYPE_SHORT}, - * {@link #TYPE_USHORT}, {@link #TYPE_INT}, {@link #TYPE_FLOAT} and - * {@link #TYPE_DOUBLE}. - * <p> - * The physical (array-based) storage is allocated by a subclass. - * - * @param dataType the data type. - * @param size the number of elements in the buffer. - * @param numBanks the number of data banks. - * @param offsets the offsets to the first element for all banks. - * - * @throws ArrayIndexOutOfBoundsException if - * <code>numBanks != offsets.length</code>. - */ - protected DataBuffer(int dataType, int size, int numBanks, int[] offsets) { - this(dataType, size); - if (numBanks != offsets.length) - throw new ArrayIndexOutOfBoundsException(); - - banks = numBanks; - this.offsets = offsets; - - offset = offsets[0]; - } - - /** - * Returns the size (number of bits) of the specified data type. Valid types - * are defined by the constants {@link #TYPE_BYTE}, {@link #TYPE_SHORT}, - * {@link #TYPE_USHORT}, {@link #TYPE_INT}, {@link #TYPE_FLOAT} and - * {@link #TYPE_DOUBLE}. - * - * @param dataType the data type. - * @return The number of bits for the specified data type. - * @throws IllegalArgumentException if <code>dataType < 0</code> or - * <code>dataType > TYPE_DOUBLE</code>. - */ - public static int getDataTypeSize(int dataType) { - // Maybe this should be a lookup table instead. - switch (dataType) - { - case TYPE_BYTE: - return 8; - case TYPE_USHORT: - case TYPE_SHORT: - return 16; - case TYPE_INT: - case TYPE_FLOAT: - return 32; - case TYPE_DOUBLE: - return 64; - default: - throw new IllegalArgumentException(); - } - } - - /** - * Returns the type of the data elements in the data buffer. Valid types - * are defined by the constants {@link #TYPE_BYTE}, {@link #TYPE_SHORT}, - * {@link #TYPE_USHORT}, {@link #TYPE_INT}, {@link #TYPE_FLOAT} and - * {@link #TYPE_DOUBLE}. - * - * @return The type. - */ - public int getDataType() - { - return dataType; - } - - /** - * Returns the size of the data buffer. - * - * @return The size. - */ - public int getSize() - { - return size; - } - - /** - * Returns the element offset for the first data bank. - * - * @return The element offset. - */ - public int getOffset() - { - return offset; - } - - /** - * Returns the offsets for all the data banks used by this - * <code>DataBuffer</code>. - * - * @return The offsets. - */ - public int[] getOffsets() - { - if (offsets == null) - { - // is this necessary? - offsets = new int[1]; - offsets[0] = offset; - } - return offsets; - } - - /** - * Returns the number of data banks for this <code>DataBuffer</code>. - * @return The number of data banks. - */ - public int getNumBanks() - { - return banks; - } - - /** - * Returns an element from the first data bank. The offset (specified in - * the constructor) is added to <code>i</code> before accessing the - * underlying data array. - * - * @param i the element index. - * @return The element. - */ - public int getElem(int i) - { - return getElem(0, i); - } - - /** - * Returns an element from a particular data bank. The offset (specified in - * the constructor) is added to <code>i</code> before accessing the - * underlying data array. - * - * @param bank the bank index. - * @param i the element index. - * @return The element. - */ - public abstract int getElem(int bank, int i); - - /** - * Sets an element in the first data bank. The offset (specified in the - * constructor) is added to <code>i</code> before updating the underlying - * data array. - * - * @param i the element index. - * @param val the new element value. - */ - public void setElem(int i, int val) - { - setElem(0, i, val); - } - - /** - * Sets an element in a particular data bank. The offset (specified in the - * constructor) is added to <code>i</code> before updating the underlying - * data array. - * - * @param bank the data bank index. - * @param i the element index. - * @param val the new element value. - */ - public abstract void setElem(int bank, int i, int val); - - /** - * Returns an element from the first data bank, converted to a - * <code>float</code>. The offset (specified in the constructor) is added - * to <code>i</code> before accessing the underlying data array. - * - * @param i the element index. - * @return The element. - */ - public float getElemFloat(int i) - { - return getElem(i); - } - - /** - * Returns an element from a particular data bank, converted to a - * <code>float</code>. The offset (specified in the constructor) is - * added to <code>i</code> before accessing the underlying data array. - * - * @param bank the bank index. - * @param i the element index. - * @return The element. - */ - public float getElemFloat(int bank, int i) - { - return getElem(bank, i); - } - - /** - * Sets an element in the first data bank. The offset (specified in the - * constructor) is added to <code>i</code> before updating the underlying - * data array. - * - * @param i the element index. - * @param val the new element value. - */ - public void setElemFloat(int i, float val) - { - setElem(i, (int) val); - } - - /** - * Sets an element in a particular data bank. The offset (specified in the - * constructor) is added to <code>i</code> before updating the underlying - * data array. - * - * @param bank the data bank index. - * @param i the element index. - * @param val the new element value. - */ - public void setElemFloat(int bank, int i, float val) - { - setElem(bank, i, (int) val); - } - - /** - * Returns an element from the first data bank, converted to a - * <code>double</code>. The offset (specified in the constructor) is added - * to <code>i</code> before accessing the underlying data array. - * - * @param i the element index. - * @return The element. - */ - public double getElemDouble(int i) - { - return getElem(i); - } - - /** - * Returns an element from a particular data bank, converted to a - * <code>double</code>. The offset (specified in the constructor) is - * added to <code>i</code> before accessing the underlying data array. - * - * @param bank the bank index. - * @param i the element index. - * @return The element. - */ - public double getElemDouble(int bank, int i) - { - return getElem(bank, i); - } - - /** - * Sets an element in the first data bank. The offset (specified in the - * constructor) is added to <code>i</code> before updating the underlying - * data array. - * - * @param i the element index. - * @param val the new element value. - */ - public void setElemDouble(int i, double val) - { - setElem(i, (int) val); - } - - /** - * Sets an element in a particular data bank. The offset (specified in the - * constructor) is added to <code>i</code> before updating the underlying - * data array. - * - * @param bank the data bank index. - * @param i the element index. - * @param val the new element value. - */ - public void setElemDouble(int bank, int i, double val) - { - setElem(bank, i, (int) val); - } -} diff --git a/libjava/java/awt/image/DataBufferByte.java b/libjava/java/awt/image/DataBufferByte.java deleted file mode 100644 index ceed50832ff..00000000000 --- a/libjava/java/awt/image/DataBufferByte.java +++ /dev/null @@ -1,242 +0,0 @@ -/* Copyright (C) 2000, 2002 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.awt.image; - -/* This is one of several classes that are nearly identical. Maybe we - should have a central template and generate all these files. This - is one of the cases where templates or macros would have been - useful to have in Java. - - This file has been created using search-replace. My only fear is - that these classes will grow out-of-sync as of a result of changes - that are not propagated to the other files. As always, mirroring - code is a maintenance nightmare. */ - -/** - * @author Rolf W. Rasmussen (rolfwr@ii.uib.no) - */ -public final class DataBufferByte extends DataBuffer -{ - private byte[] data; - private byte[][] bankData; - - /** - * Creates a new data buffer with a single data bank containing the - * specified number of <code>byte</code> elements. - * - * @param size the number of elements in the data bank. - */ - public DataBufferByte(int size) - { - super(TYPE_BYTE, size, 1, 0); - bankData = new byte[1][]; - data = new byte[size]; - bankData[0] = data; - } - - /** - * Creates a new data buffer with the specified number of data banks, - * each containing the specified number of <code>byte</code> elements. - * - * @param size the number of elements in the data bank. - * @param numBanks the number of data banks. - */ - public DataBufferByte(int size, int numBanks) - { - super(TYPE_BYTE, size, numBanks); - bankData = new byte[numBanks][size]; - data = bankData[0]; - } - - /** - * Creates a new data buffer backed by the specified data bank. - * <p> - * Note: there is no exception when <code>dataArray</code> is - * <code>null</code>, but in that case an exception will be thrown - * later if you attempt to access the data buffer. - * - * @param dataArray the data bank. - * @param size the number of elements in the data bank. - */ - public DataBufferByte(byte[] dataArray, int size) - { - super(TYPE_BYTE, size, 1, 0); - bankData = new byte[1][]; - data = dataArray; - bankData[0] = data; - } - - /** - * Creates a new data buffer backed by the specified data bank, with - * the specified offset to the first element. - * <p> - * Note: there is no exception when <code>dataArray</code> is - * <code>null</code>, but in that case an exception will be thrown - * later if you attempt to access the data buffer. - * - * @param dataArray the data bank. - * @param size the number of elements in the data bank. - * @param offset the offset to the first element in the array. - */ - public DataBufferByte(byte[] dataArray, int size, int offset) - { - super(TYPE_BYTE, size, 1, offset); - bankData = new byte[1][]; - data = dataArray; - bankData[0] = data; - } - - /** - * Creates a new data buffer backed by the specified data banks. - * - * @param dataArray the data banks. - * @param size the number of elements in the data bank. - * - * @throws NullPointerException if <code>dataArray</code> is - * <code>null</code>. - */ - public DataBufferByte(byte[][] dataArray, int size) - { - super(TYPE_BYTE, size, dataArray.length); - bankData = dataArray; - data = bankData[0]; - } - - /** - * Creates a new data buffer backed by the specified data banks, with - * the specified offsets to the first element in each bank. - * - * @param dataArray the data banks. - * @param size the number of elements in the data bank. - * @param offsets the offsets to the first element in each data bank. - * - * @throws NullPointerException if <code>dataArray</code> is - * <code>null</code>. - */ - public DataBufferByte(byte[][] dataArray, int size, int[] offsets) - { - super(TYPE_BYTE, size, dataArray.length, offsets); - bankData = dataArray; - data = bankData[0]; - } - - /** - * Returns the first data bank. - * - * @return The first data bank. - */ - public byte[] getData() - { - return data; - } - - /** - * Returns a data bank. - * - * @param bank the bank index. - * @return A data bank. - */ - public byte[] getData(int bank) - { - return bankData[bank]; - } - - /** - * Returns the array underlying this <code>DataBuffer</code>. - * - * @return The data banks. - */ - public byte[][] getBankData() - { - return bankData; - } - - /** - * Returns an element from the first data bank. The offset (specified in - * the constructor) is added to <code>i</code> before accessing the - * underlying data array. - * - * @param i the element index. - * @return The element. - */ - public int getElem(int i) - { - return data[i+offset] & 0xff; // get unsigned byte as int - } - - /** - * Returns an element from a particular data bank. The offset (specified in - * the constructor) is added to <code>i</code> before accessing the - * underlying data array. - * - * @param bank the bank index. - * @param i the element index. - * @return The element. - */ - public int getElem(int bank, int i) - { - // get unsigned byte as int - return bankData[bank][i+offsets[bank]] & 0xff; - } - - /** - * Sets an element in the first data bank. The offset (specified in the - * constructor) is added to <code>i</code> before updating the underlying - * data array. - * - * @param i the element index. - * @param val the new element value. - */ - public void setElem(int i, int val) - { - data[i+offset] = (byte) val; - } - - /** - * Sets an element in a particular data bank. The offset (specified in the - * constructor) is added to <code>i</code> before updating the underlying - * data array. - * - * @param bank the data bank index. - * @param i the element index. - * @param val the new element value. - */ - public void setElem(int bank, int i, int val) - { - bankData[bank][i+offsets[bank]] = (byte) val; - } -} diff --git a/libjava/java/awt/image/DataBufferDouble.java b/libjava/java/awt/image/DataBufferDouble.java deleted file mode 100644 index eba4a7c3c68..00000000000 --- a/libjava/java/awt/image/DataBufferDouble.java +++ /dev/null @@ -1,285 +0,0 @@ -/* Copyright (C) 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.awt.image; - -/* This is one of several classes that are nearly identical. Maybe we - should have a central template and generate all these files. This - is one of the cases where templates or macros would have been - useful to have in Java. - - This file has been created using search-replace. My only fear is - that these classes will grow out-of-sync as of a result of changes - that are not propagated to the other files. As always, mirroring - code is a maintenance nightmare. */ - -/** - * @since 1.4 - * - * @author Rolf W. Rasmussen (rolfwr@ii.uib.no) - * @author Sascha Brawer (brawer@dandelis.ch) - */ -public final class DataBufferDouble - extends DataBuffer -{ - private double[] data; - private double[][] bankData; - - /** - * Creates a new data buffer with a single data bank containing the - * specified number of <code>double</code> elements. - * - * @param size the number of elements in the data bank. - */ - public DataBufferDouble(int size) - { - super(TYPE_DOUBLE, size, 1, 0); - bankData = new double[1][]; - data = new double[size]; - bankData[0] = data; - } - - /** - * Creates a new data buffer with the specified number of data banks, - * each containing the specified number of <code>double</code> elements. - * - * @param size the number of elements in the data bank. - * @param numBanks the number of data banks. - */ - public DataBufferDouble(int size, int numBanks) - { - super(TYPE_DOUBLE, size, numBanks); - bankData = new double[numBanks][size]; - data = bankData[0]; - } - - /** - * Creates a new data buffer backed by the specified data bank. - * <p> - * Note: there is no exception when <code>dataArray</code> is - * <code>null</code>, but in that case an exception will be thrown - * later if you attempt to access the data buffer. - * - * @param dataArray the data bank. - * @param size the number of elements in the data bank. - */ - public DataBufferDouble(double[] dataArray, int size) - { - super(TYPE_DOUBLE, size, 1, 0); - bankData = new double[1][]; - data = dataArray; - bankData[0] = data; - } - - /** - * Creates a new data buffer backed by the specified data bank, with - * the specified offset to the first element. - * <p> - * Note: there is no exception when <code>dataArray</code> is - * <code>null</code>, but in that case an exception will be thrown - * later if you attempt to access the data buffer. - * - * @param dataArray the data bank. - * @param size the number of elements in the data bank. - * @param offset the offset to the first element in the array. - */ - public DataBufferDouble(double[] dataArray, int size, int offset) - { - super(TYPE_DOUBLE, size, 1, offset); - bankData = new double[1][]; - data = dataArray; - bankData[0] = data; - } - - /** - * Creates a new data buffer backed by the specified data banks. - * - * @param dataArray the data banks. - * @param size the number of elements in the data bank. - * - * @throws NullPointerException if <code>dataArray</code> is - * <code>null</code>. - */ - public DataBufferDouble(double[][] dataArray, int size) - { - super(TYPE_DOUBLE, size, dataArray.length); - bankData = dataArray; - data = bankData[0]; - } - - /** - * Creates a new data buffer backed by the specified data banks, with - * the specified offsets to the first element in each bank. - * - * @param dataArray the data banks. - * @param size the number of elements in the data bank. - * @param offsets the offsets to the first element in each data bank. - * - * @throws NullPointerException if <code>dataArray</code> is - * <code>null</code>. - */ - public DataBufferDouble(double[][] dataArray, int size, int[] offsets) - { - super(TYPE_DOUBLE, size, dataArray.length, offsets); - bankData = dataArray; - data = bankData[0]; - } - - /** - * Returns the first data bank. - * - * @return The first data bank. - */ - public double[] getData() - { - return data; - } - - /** - * Returns a data bank. - * - * @param bank the bank index. - * @return A data bank. - */ - public double[] getData(int bank) - { - return bankData[bank]; - } - - /** - * Returns the array underlying this <code>DataBuffer</code>. - * - * @return The data banks. - */ - public double[][] getBankData() - { - return bankData; - } - - /** - * Returns an element from the first data bank. The offset (specified in - * the constructor) is added to <code>i</code> before accessing the - * underlying data array. - * - * @param i the element index. - * @return The element. - */ - public int getElem(int i) - { - return (int) data[i+offset]; - } - - /** - * Returns an element from a particular data bank. The offset (specified in - * the constructor) is added to <code>i</code> before accessing the - * underlying data array. - * - * @param bank the bank index. - * @param i the element index. - * @return The element. - */ - public int getElem(int bank, int i) - { - return (int) bankData[bank][i+offsets[bank]]; - } - - /** - * Sets an element in the first data bank. The offset (specified in the - * constructor) is added to <code>i</code> before updating the underlying - * data array. - * - * @param i the element index. - * @param val the new element value. - */ - public void setElem(int i, int val) - { - data[i+offset] = (double) val; - } - - /** - * Sets an element in a particular data bank. The offset (specified in the - * constructor) is added to <code>i</code> before updating the underlying - * data array. - * - * @param bank the data bank index. - * @param i the element index. - * @param val the new element value. - */ - public void setElem(int bank, int i, int val) - { - bankData[bank][i+offsets[bank]] = (double) val; - } - - public float getElemFloat(int i) - { - return (float) data[i+offset]; - } - - public float getElemFloat(int bank, int i) - { - return (float) bankData[bank][i+offsets[bank]]; - } - - public void setElemFloat(int i, float val) - { - data[i+offset] = val; - } - - public void setElemFloat(int bank, int i, float val) - { - bankData[bank][i+offsets[bank]] = val; - } - - public double getElemDouble(int i) - { - return data[i + offset]; - } - - public double getElemDouble(int bank, int i) - { - return bankData[bank][i + offsets[bank]]; - } - - public void setElemDouble(int i, double val) - { - data[i + offset] = val; - } - - public void setElemDouble(int bank, int i, double val) - { - bankData[bank][i + offsets[bank]] = val; - } -} diff --git a/libjava/java/awt/image/DataBufferFloat.java b/libjava/java/awt/image/DataBufferFloat.java deleted file mode 100644 index 1d4c55b5004..00000000000 --- a/libjava/java/awt/image/DataBufferFloat.java +++ /dev/null @@ -1,283 +0,0 @@ -/* Copyright (C) 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.awt.image; - -/* This is one of several classes that are nearly identical. Maybe we - should have a central template and generate all these files. This - is one of the cases where templates or macros would have been - useful to have in Java. - - This file has been created using search-replace. My only fear is - that these classes will grow out-of-sync as of a result of changes - that are not propagated to the other files. As always, mirroring - code is a maintenance nightmare. */ - -/** - * @author Rolf W. Rasmussen (rolfwr@ii.uib.no) - * @author Sascha Brawer (brawer@dandelis.ch) - */ -public final class DataBufferFloat - extends DataBuffer -{ - private float[] data; - private float[][] bankData; - - /** - * Creates a new data buffer with a single data bank containing the - * specified number of <code>float</code> elements. - * - * @param size the number of elements in the data bank. - */ - public DataBufferFloat(int size) - { - super(TYPE_FLOAT, size, 1, 0); - bankData = new float[1][]; - data = new float[size]; - bankData[0] = data; - } - - /** - * Creates a new data buffer with the specified number of data banks, - * each containing the specified number of <code>float</code> elements. - * - * @param size the number of elements in the data bank. - * @param numBanks the number of data banks. - */ - public DataBufferFloat(int size, int numBanks) - { - super(TYPE_FLOAT, size, numBanks); - bankData = new float[numBanks][size]; - data = bankData[0]; - } - - /** - * Creates a new data buffer backed by the specified data bank. - * <p> - * Note: there is no exception when <code>dataArray</code> is - * <code>null</code>, but in that case an exception will be thrown - * later if you attempt to access the data buffer. - * - * @param dataArray the data bank. - * @param size the number of elements in the data bank. - */ - public DataBufferFloat(float[] dataArray, int size) - { - super(TYPE_FLOAT, size, 1, 0); - bankData = new float[1][]; - data = dataArray; - bankData[0] = data; - } - - /** - * Creates a new data buffer backed by the specified data bank, with - * the specified offset to the first element. - * <p> - * Note: there is no exception when <code>dataArray</code> is - * <code>null</code>, but in that case an exception will be thrown - * later if you attempt to access the data buffer. - * - * @param dataArray the data bank. - * @param size the number of elements in the data bank. - * @param offset the offset to the first element in the array. - */ - public DataBufferFloat(float[] dataArray, int size, int offset) - { - super(TYPE_FLOAT, size, 1, offset); - bankData = new float[1][]; - data = dataArray; - bankData[0] = data; - } - - /** - * Creates a new data buffer backed by the specified data banks. - * - * @param dataArray the data banks. - * @param size the number of elements in the data bank. - * - * @throws NullPointerException if <code>dataArray</code> is - * <code>null</code>. - */ - public DataBufferFloat(float[][] dataArray, int size) - { - super(TYPE_FLOAT, size, dataArray.length); - bankData = dataArray; - data = bankData[0]; - } - - /** - * Creates a new data buffer backed by the specified data banks, with - * the specified offsets to the first element in each bank. - * - * @param dataArray the data banks. - * @param size the number of elements in the data bank. - * @param offsets the offsets to the first element in each data bank. - * - * @throws NullPointerException if <code>dataArray</code> is - * <code>null</code>. - */ - public DataBufferFloat(float[][] dataArray, int size, int[] offsets) - { - super(TYPE_FLOAT, size, dataArray.length, offsets); - bankData = dataArray; - data = bankData[0]; - } - - /** - * Returns the first data bank. - * - * @return The first data bank. - */ - public float[] getData() - { - return data; - } - - /** - * Returns a data bank. - * - * @param bank the bank index. - * @return A data bank. - */ - public float[] getData(int bank) - { - return bankData[bank]; - } - - /** - * Returns the array underlying this <code>DataBuffer</code>. - * - * @return The data banks. - */ - public float[][] getBankData() - { - return bankData; - } - - /** - * Returns an element from the first data bank. The offset (specified in - * the constructor) is added to <code>i</code> before accessing the - * underlying data array. - * - * @param i the element index. - * @return The element. - */ - public int getElem(int i) - { - return (int) data[i+offset]; - } - - /** - * Returns an element from a particular data bank. The offset (specified in - * the constructor) is added to <code>i</code> before accessing the - * underlying data array. - * - * @param bank the bank index. - * @param i the element index. - * @return The element. - */ - public int getElem(int bank, int i) - { - return (int) bankData[bank][i+offsets[bank]]; - } - - /** - * Sets an element in the first data bank. The offset (specified in the - * constructor) is added to <code>i</code> before updating the underlying - * data array. - * - * @param i the element index. - * @param val the new element value. - */ - public void setElem(int i, int val) - { - data[i+offset] = (float) val; - } - - /** - * Sets an element in a particular data bank. The offset (specified in the - * constructor) is added to <code>i</code> before updating the underlying - * data array. - * - * @param bank the data bank index. - * @param i the element index. - * @param val the new element value. - */ - public void setElem(int bank, int i, int val) - { - bankData[bank][i+offsets[bank]] = (float) val; - } - - public float getElemFloat(int i) - { - return data[i+offset]; - } - - public float getElemFloat(int bank, int i) - { - return bankData[bank][i+offsets[bank]]; - } - - public void setElemFloat(int i, float val) - { - data[i+offset] = val; - } - - public void setElemFloat(int bank, int i, float val) - { - bankData[bank][i+offsets[bank]] = val; - } - - public double getElemDouble(int i) - { - return getElemFloat(i); - } - - public double getElemDouble(int bank, int i) - { - return getElemFloat(bank, i); - } - - public void setElemDouble(int i, double val) - { - setElemFloat(i, (float) val); - } - - public void setElemDouble(int bank, int i, double val) - { - setElemFloat(bank, i, (float) val); - } -} diff --git a/libjava/java/awt/image/DataBufferInt.java b/libjava/java/awt/image/DataBufferInt.java deleted file mode 100644 index d4636caf346..00000000000 --- a/libjava/java/awt/image/DataBufferInt.java +++ /dev/null @@ -1,241 +0,0 @@ -/* Copyright (C) 2000, 2002 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.awt.image; - -/* This is one of several classes that are nearly identical. Maybe we - should have a central template and generate all these files. This - is one of the cases where templates or macros would have been - useful to have in Java. - - This file has been created using search-replace. My only fear is - that these classes will grow out-of-sync as of a result of changes - that are not propagated to the other files. As always, mirroring - code is a maintenance nightmare. */ - -/** - * @author Rolf W. Rasmussen (rolfwr@ii.uib.no) - */ -public final class DataBufferInt extends DataBuffer -{ - private int[] data; - private int[][] bankData; - - /** - * Creates a new data buffer with a single data bank containing the - * specified number of <code>int</code> elements. - * - * @param size the number of elements in the data bank. - */ - public DataBufferInt(int size) - { - super(TYPE_INT, size, 1, 0); - bankData = new int[1][]; - data = new int[size]; - bankData[0] = data; - } - - /** - * Creates a new data buffer with the specified number of data banks, - * each containing the specified number of <code>int</code> elements. - * - * @param size the number of elements in the data bank. - * @param numBanks the number of data banks. - */ - public DataBufferInt(int size, int numBanks) - { - super(TYPE_INT, size, numBanks); - bankData = new int[numBanks][size]; - data = bankData[0]; - } - - /** - * Creates a new data buffer backed by the specified data bank. - * <p> - * Note: there is no exception when <code>dataArray</code> is - * <code>null</code>, but in that case an exception will be thrown - * later if you attempt to access the data buffer. - * - * @param dataArray the data bank. - * @param size the number of elements in the data bank. - */ - public DataBufferInt(int[] dataArray, int size) - { - super(TYPE_INT, size, 1, 0); - bankData = new int[1][]; - data = dataArray; - bankData[0] = data; - } - - /** - * Creates a new data buffer backed by the specified data bank, with - * the specified offset to the first element. - * <p> - * Note: there is no exception when <code>dataArray</code> is - * <code>null</code>, but in that case an exception will be thrown - * later if you attempt to access the data buffer. - * - * @param dataArray the data bank. - * @param size the number of elements in the data bank. - * @param offset the offset to the first element in the array. - */ - public DataBufferInt(int[] dataArray, int size, int offset) - { - super(TYPE_INT, size, 1, offset); - bankData = new int[1][]; - data = dataArray; - bankData[0] = data; - } - - /** - * Creates a new data buffer backed by the specified data banks. - * - * @param dataArray the data banks. - * @param size the number of elements in the data bank. - * - * @throws NullPointerException if <code>dataArray</code> is - * <code>null</code>. - */ - public DataBufferInt(int[][] dataArray, int size) - { - super(TYPE_INT, size, dataArray.length); - bankData = dataArray; - data = bankData[0]; - } - - /** - * Creates a new data buffer backed by the specified data banks, with - * the specified offsets to the first element in each bank. - * - * @param dataArray the data banks. - * @param size the number of elements in the data bank. - * @param offsets the offsets to the first element in each data bank. - * - * @throws NullPointerException if <code>dataArray</code> is - * <code>null</code>. - */ - public DataBufferInt(int[][] dataArray, int size, int[] offsets) - { - super(TYPE_INT, size, dataArray.length, offsets); - bankData = dataArray; - data = bankData[0]; - } - - /** - * Returns the first data bank. - * - * @return The first data bank. - */ - public int[] getData() - { - return data; - } - - /** - * Returns a data bank. - * - * @param bank the bank index. - * @return A data bank. - */ - public int[] getData(int bank) - { - return bankData[bank]; - } - - /** - * Returns the array underlying this <code>DataBuffer</code>. - * - * @return The data banks. - */ - public int[][] getBankData() - { - return bankData; - } - - /** - * Returns an element from the first data bank. The <code>offset</code> is - * added to the specified index before accessing the underlying data array. - * - * @param i the element index. - * @return The element. - */ - public int getElem(int i) - { - return data[i+offset]; - } - - /** - * Returns an element from a particular data bank. The <code>offset</code> - * is added to the specified index before accessing the underlying data - * array. - * - * @param bank the bank index. - * @param i the element index. - * @return The element. - */ - public int getElem(int bank, int i) - { - // get unsigned int as int - return bankData[bank][i+offsets[bank]]; - } - - /** - * Sets an element in the first data bank. The offset (specified in the - * constructor) is added to <code>i</code> before updating the underlying - * data array. - * - * @param i the element index. - * @param val the new element value. - */ - public void setElem(int i, int val) - { - data[i+offset] = val; - } - - /** - * Sets an element in a particular data bank. The offset (specified in the - * constructor) is added to <code>i</code> before updating the underlying - * data array. - * - * @param bank the data bank index. - * @param i the element index. - * @param val the new element value. - */ - public void setElem(int bank, int i, int val) - { - bankData[bank][i+offsets[bank]] = val; - } -} diff --git a/libjava/java/awt/image/DataBufferShort.java b/libjava/java/awt/image/DataBufferShort.java deleted file mode 100644 index 3135dbaa721..00000000000 --- a/libjava/java/awt/image/DataBufferShort.java +++ /dev/null @@ -1,242 +0,0 @@ -/* DataBufferShort.java -- - Copyright (C) 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.awt.image; - -/* This is one of several classes that are nearly identical. Maybe we - should have a central template and generate all these files. This - is one of the cases where templates or macros would have been - useful to have in Java. - - This file has been created using search-replace. My only fear is - that these classes will grow out-of-sync as of a result of changes - that are not propagated to the other files. As always, mirroring - code is a maintenance nightmare. */ - -/** - * @author Rolf W. Rasmussen (rolfwr@ii.uib.no) - */ -public final class DataBufferShort extends DataBuffer -{ - private short[] data; - private short[][] bankData; - - /** - * Creates a new data buffer with a single data bank containing the - * specified number of <code>short</code> elements. - * - * @param size the number of elements in the data bank. - */ - public DataBufferShort(int size) - { - super(TYPE_SHORT, size, 1, 0); - bankData = new short[1][]; - data = new short[size]; - bankData[0] = data; - } - - /** - * Creates a new data buffer with the specified number of data banks, - * each containing the specified number of <code>short</code> elements. - * - * @param size the number of elements in the data bank. - * @param numBanks the number of data banks. - */ - public DataBufferShort(int size, int numBanks) - { - super(TYPE_SHORT, size, numBanks); - bankData = new short[numBanks][size]; - data = bankData[0]; - } - - /** - * Creates a new data buffer backed by the specified data bank. - * <p> - * Note: there is no exception when <code>dataArray</code> is - * <code>null</code>, but in that case an exception will be thrown - * later if you attempt to access the data buffer. - * - * @param dataArray the data bank. - * @param size the number of elements in the data bank. - */ - public DataBufferShort(short[] dataArray, int size) - { - super(TYPE_SHORT, size, 1, 0); - bankData = new short[1][]; - data = dataArray; - bankData[0] = data; - } - - /** - * Creates a new data buffer backed by the specified data bank, with - * the specified offset to the first element. - * <p> - * Note: there is no exception when <code>dataArray</code> is - * <code>null</code>, but in that case an exception will be thrown - * later if you attempt to access the data buffer. - * - * @param dataArray the data bank. - * @param size the number of elements in the data bank. - * @param offset the offset to the first element in the array. - */ - public DataBufferShort(short[] dataArray, int size, int offset) - { - super(TYPE_SHORT, size, 1, offset); - bankData = new short[1][]; - data = dataArray; - bankData[0] = data; - } - - /** - * Creates a new data buffer backed by the specified data banks. - * - * @param dataArray the data banks. - * @param size the number of elements in the data bank. - * - * @throws NullPointerException if <code>dataArray</code> is - * <code>null</code>. - */ - public DataBufferShort(short[][] dataArray, int size) - { - super(TYPE_SHORT, size, dataArray.length); - bankData = dataArray; - data = bankData[0]; - } - - /** - * Creates a new data buffer backed by the specified data banks, with - * the specified offsets to the first element in each bank. - * - * @param dataArray the data banks. - * @param size the number of elements in the data bank. - * @param offsets the offsets to the first element in each data bank. - * - * @throws NullPointerException if <code>dataArray</code> is - * <code>null</code>. - */ - public DataBufferShort(short[][] dataArray, int size, int[] offsets) - { - super(TYPE_SHORT, size, dataArray.length, offsets); - bankData = dataArray; - data = bankData[0]; - } - - /** - * Returns the first data bank. - * - * @return The first data bank. - */ - public short[] getData() - { - return data; - } - - /** - * Returns a data bank. - * - * @param bank the bank index. - * @return A data bank. - */ - public short[] getData(int bank) - { - return bankData[bank]; - } - - /** - * Returns the array underlying this <code>DataBuffer</code>. - * - * @return The data banks. - */ - public short[][] getBankData() - { - return bankData; - } - - /** - * Returns an element from the first data bank. The offset (specified in - * the constructor) is added to <code>i</code> before accessing the - * underlying data array. - * - * @param i the element index. - * @return The element. - */ - public int getElem(int i) - { - return data[i+offset]; - } - - /** - * Returns an element from a particular data bank. The offset (specified in - * the constructor) is added to <code>i</code> before accessing the - * underlying data array. - * - * @param bank the bank index. - * @param i the element index. - * @return The element. - */ - public int getElem(int bank, int i) - { - return bankData[bank][i+offsets[bank]]; - } - - /** - * Sets an element in the first data bank. The offset (specified in the - * constructor) is added to <code>i</code> before updating the underlying - * data array. - * - * @param i the element index. - * @param val the new element value. - */ - public void setElem(int i, int val) - { - data[i+offset] = (short) val; - } - - /** - * Sets an element in a particular data bank. The offset (specified in the - * constructor) is added to <code>i</code> before updating the underlying - * data array. - * - * @param bank the data bank index. - * @param i the element index. - * @param val the new element value. - */ - public void setElem(int bank, int i, int val) - { - bankData[bank][i+offsets[bank]] = (short) val; - } -} diff --git a/libjava/java/awt/image/DataBufferUShort.java b/libjava/java/awt/image/DataBufferUShort.java deleted file mode 100644 index d42dadf86a7..00000000000 --- a/libjava/java/awt/image/DataBufferUShort.java +++ /dev/null @@ -1,243 +0,0 @@ -/* DataBufferUShort.java -- - Copyright (C) 2000, 2002, 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.awt.image; - -/* This is one of several classes that are nearly identical. Maybe we - should have a central template and generate all these files. This - is one of the cases where templates or macros would have been - useful to have in Java. - - This file has been created using search-replace. My only fear is - that these classes will grow out-of-sync as of a result of changes - that are not propagated to the other files. As always, mirroring - code is a maintenance nightmare. */ - -/** - * @author Rolf W. Rasmussen (rolfwr@ii.uib.no) - */ -public final class DataBufferUShort extends DataBuffer -{ - private short[] data; - private short[][] bankData; - - /** - * Creates a new data buffer with a single data bank containing the - * specified number of <code>short</code> elements. - * - * @param size the number of elements in the data bank. - */ - public DataBufferUShort(int size) - { - super(TYPE_USHORT, size, 1, 0); - bankData = new short[1][]; - data = new short[size]; - bankData[0] = data; - } - - /** - * Creates a new data buffer with the specified number of data banks, - * each containing the specified number of <code>short</code> elements. - * - * @param size the number of elements in the data bank. - * @param numBanks the number of data banks. - */ - public DataBufferUShort(int size, int numBanks) - { - super(TYPE_USHORT, size, numBanks); - bankData = new short[numBanks][size]; - data = bankData[0]; - } - - /** - * Creates a new data buffer backed by the specified data bank. - * - * @param dataArray the data bank. - * @param size the number of elements in the data bank. - * - * @throws NullPointerException if dataArray is null - */ - public DataBufferUShort(short[] dataArray, int size) - { - super(TYPE_USHORT, size, 1, 0); - if (dataArray == null) - throw new NullPointerException(); - bankData = new short[1][]; - data = dataArray; - bankData[0] = data; - } - - /** - * Creates a new data buffer backed by the specified data bank, with - * the specified offset to the first element. - * - * @param dataArray the data bank. - * @param size the number of elements in the data bank. - * @param offset the offset to the first element in the array. - * - * @throws NullPointerException if dataArray is null - */ - public DataBufferUShort(short[] dataArray, int size, int offset) - { - super(TYPE_USHORT, size, 1, offset); - if (dataArray == null) - throw new NullPointerException(); - bankData = new short[1][]; - data = dataArray; - bankData[0] = data; - } - - /** - * Creates a new data buffer backed by the specified data banks. - * - * @param dataArray the data banks. - * @param size the number of elements in the data bank. - * - * @throws NullPointerException if <code>dataArray</code> is - * <code>null</code>. - */ - public DataBufferUShort(short[][] dataArray, int size) - { - super(TYPE_USHORT, size, dataArray.length); - bankData = dataArray; - data = bankData[0]; - } - - /** - * Creates a new data buffer backed by the specified data banks, with - * the specified offsets to the first element in each bank. - * - * @param dataArray the data banks. - * @param size the number of elements in the data bank. - * @param offsets the offsets to the first element in each data bank. - * - * @throws NullPointerException if <code>dataArray</code> is - * <code>null</code>. - */ - public DataBufferUShort(short[][] dataArray, int size, int[] offsets) - { - super(TYPE_USHORT, size, dataArray.length, offsets); - bankData = dataArray; - data = bankData[0]; - } - - /** - * Returns the first data bank. - * - * @return The first data bank. - */ - public short[] getData() - { - return data; - } - - /** - * Returns a data bank. - * - * @param bank the bank index. - * @return A data bank. - */ - public short[] getData(int bank) - { - return bankData[bank]; - } - - /** - * Returns the array underlying this <code>DataBuffer</code>. - * - * @return The data banks. - */ - public short[][] getBankData() - { - return bankData; - } - - /** - * Returns an element from the first data bank. The offset (specified in - * the constructor) is added to <code>i</code> before accessing the - * underlying data array. - * - * @param i the element index. - * @return The element. - */ - public int getElem(int i) - { - return data[i+offset] & 0xffff; // get unsigned short as int - } - - /** - * Returns an element from a particular data bank. The offset (specified in - * the constructor) is added to <code>i</code> before accessing the - * underlying data array. - * - * @param bank the bank index. - * @param i the element index. - * @return The element. - */ - public int getElem(int bank, int i) - { - // get unsigned short as int - return bankData[bank][i+offsets[bank]] & 0xffff; - } - - /** - * Sets an element in the first data bank. The offset (specified in the - * constructor) is added to <code>i</code> before updating the underlying - * data array. - * - * @param i the element index. - * @param val the new element value. - */ - public void setElem(int i, int val) - { - data[i+offset] = (short) val; - } - - /** - * Sets an element in a particular data bank. The offset (specified in the - * constructor) is added to <code>i</code> before updating the underlying - * data array. - * - * @param bank the data bank index. - * @param i the element index. - * @param val the new element value. - */ - public void setElem(int bank, int i, int val) - { - bankData[bank][i+offsets[bank]] = (short) val; - } -} diff --git a/libjava/java/awt/image/DirectColorModel.java b/libjava/java/awt/image/DirectColorModel.java deleted file mode 100644 index cd391da77ec..00000000000 --- a/libjava/java/awt/image/DirectColorModel.java +++ /dev/null @@ -1,420 +0,0 @@ -/* DirectColorModel.java -- - Copyright (C) 1999, 2000, 2002, 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.image; - -import gnu.java.awt.Buffers; - -import java.awt.Point; -import java.awt.Transparency; -import java.awt.color.ColorSpace; - -/** - * @author Rolf W. Rasmussen (rolfwr@ii.uib.no) - * @author C. Brian Jones (cbj@gnu.org) - * @author Mark Benvenuto (mcb54@columbia.edu) - */ -public class DirectColorModel extends PackedColorModel -{ - /** - * For the color model created with this constructor the pixels - * will have fully opaque alpha components with a value of 255. - * Each mask should describe a fully contiguous set of bits in the - * most likely order of alpha, red, green, blue from the most significant - * byte to the least significant byte. - * - * @param pixelBits the number of bits wide used for bit size of pixel values - * @param rmask the bits describing the red component of a pixel - * @param gmask the bits describing the green component of a pixel - * @param bmask the bits describing the blue component of a pixel - */ - public DirectColorModel(int pixelBits, int rmask, int gmask, int bmask) - { - this(ColorSpace.getInstance(ColorSpace.CS_sRGB), pixelBits, - rmask, gmask, bmask, 0, - false, // not alpha premultiplied - Buffers.smallestAppropriateTransferType(pixelBits) // find type - ); - } - - /** - * For the color model created with this constructor the pixels - * will have fully opaque alpha components with a value of 255. - * Each mask should describe a fully contiguous set of bits in the - * most likely order of red, green, blue from the most significant - * byte to the least significant byte. - * - * @param pixelBits the number of bits wide used for bit size of pixel values - * @param rmask the bits describing the red component of a pixel - * @param gmask the bits describing the green component of a pixel - * @param bmask the bits describing the blue component of a pixel - * @param amask the bits describing the alpha component of a pixel - */ - public DirectColorModel(int pixelBits, - int rmask, int gmask, int bmask, int amask) - { - this(ColorSpace.getInstance(ColorSpace.CS_sRGB), pixelBits, - rmask, gmask, bmask, amask, - false, // not alpha premultiplied - Buffers.smallestAppropriateTransferType(pixelBits) // find type - ); - } - - public DirectColorModel(ColorSpace cspace, int pixelBits, - int rmask, int gmask, int bmask, int amask, - boolean isAlphaPremultiplied, - int transferType) - { - super(cspace, pixelBits, - rmask, gmask, bmask, amask, isAlphaPremultiplied, - ((amask == 0) ? Transparency.OPAQUE : Transparency.TRANSLUCENT), - transferType); - } - - public final int getRedMask() - { - return getMask(0); - } - - public final int getGreenMask() - { - return getMask(1); - } - - public final int getBlueMask() - { - return getMask(2); - } - - public final int getAlphaMask() - { - return hasAlpha() ? getMask(3) : 0; - } - - /** - * Get the red component of the given pixel. - * <br> - */ - public final int getRed(int pixel) - { - return extractAndNormalizeSample(pixel, 0); - } - - /** - * Get the green component of the given pixel. - * <br> - */ - public final int getGreen(int pixel) - { - return extractAndNormalizeSample(pixel, 1); - } - - /** - * Get the blue component of the given pixel. - * <br> - */ - public final int getBlue(int pixel) - { - return extractAndNormalizeSample(pixel, 2); - } - - /** - * Get the alpha component of the given pixel. - * <br> - */ - public final int getAlpha(int pixel) - { - if (!hasAlpha()) - return 0; - return extractAndScaleSample(pixel, 3); - } - - private int extractAndNormalizeSample(int pixel, int component) - { - int value = extractAndScaleSample(pixel, component); - if (hasAlpha() && isAlphaPremultiplied()) - value = value*255/getAlpha(pixel); - return value; - } - - private int extractAndScaleSample(int pixel, int component) - { - int field = pixel & getMask(component); - int to8BitShift = - 8 - shifts[component] - getComponentSize(component); - return (to8BitShift>0) ? - (field << to8BitShift) : - (field >>> (-to8BitShift)); - } - - /** - * Get the RGB color value of the given pixel using the default - * RGB color model. - * <br> - * - * @param pixel a pixel value - */ - public final int getRGB(int pixel) - { - /* FIXME: The Sun docs show that this method is overridden, but I - don't see any way to improve on the superclass - implementation. */ - return super.getRGB(pixel); - } - - public int getRed(Object inData) - { - return getRed(getPixelFromArray(inData)); - } - - public int getGreen(Object inData) - { - return getGreen(getPixelFromArray(inData)); - } - - public int getBlue(Object inData) - { - return getBlue(getPixelFromArray(inData)); - } - - public int getAlpha(Object inData) - { - return getAlpha(getPixelFromArray(inData)); - } - - public int getRGB(Object inData) - { - return getRGB(getPixelFromArray(inData)); - } - - /** - * Converts a normalized pixel int value in the sRGB color - * space to an array containing a single pixel of the color space - * of the color model. - * - * <p>This method performs the inverse function of - * <code>getRGB(Object inData)</code>. - * - * @param rgb pixel as a normalized sRGB, 0xAARRGGBB value. - * - * @param pixel to avoid needless creation of arrays, an array to - * use to return the pixel can be given. If null, a suitable array - * will be created. - * - * @return array of transferType containing a single pixel. The - * pixel should be encoded in the natural way of the color model. - * - * @see #getRGB(Object) - */ - public Object getDataElements(int rgb, Object pixel) - { - // FIXME: handle alpha multiply - - int pixelValue = 0; - int a = 0; - if (hasAlpha()) { - a = (rgb >>> 24) & 0xff; - pixelValue = valueToField(a, 3, 8); - } - - if (hasAlpha() && isAlphaPremultiplied()) - { - int r, g, b; - /* if r=0xff and a=0xff, then resulting - value will be (r*a)>>>8 == 0xfe... This seems wrong. - We should divide by 255 rather than shifting >>>8 after - multiplying. - - Too bad, shifting is probably less expensive. - r = ((rgb >>> 16) & 0xff)*a; - g = ((rgb >>> 8) & 0xff)*a; - b = ((rgb >>> 0) & 0xff)*a; */ - /* The r, g, b values we calculate are 16 bit. This allows - us to avoid discarding the lower 8 bits obtained if - multiplying with the alpha band. */ - - // using 16 bit values - r = ((rgb >>> 8) & 0xff00)*a/255; - g = ((rgb >>> 0) & 0xff00)*a/255; - b = ((rgb << 8) & 0xff00)*a/255; - pixelValue |= - valueToField(r, 0, 16) | // Red - valueToField(g, 1, 16) | // Green - valueToField(b, 2, 16); // Blue - } - else - { - int r, g, b; - // using 8 bit values - r = (rgb >>> 16) & 0xff; - g = (rgb >>> 8) & 0xff; - b = (rgb >>> 0) & 0xff; - - pixelValue |= - valueToField(r, 0, 8) | // Red - valueToField(g, 1, 8) | // Green - valueToField(b, 2, 8); // Blue - } - - /* In this color model, the whole pixel fits in the first element - of the array. */ - DataBuffer buffer = Buffers.createBuffer(transferType, pixel, 1); - buffer.setElem(0, pixelValue); - return Buffers.getData(buffer); - } - - /** - * Converts a value to the correct field bits based on the - * information derived from the field masks. - * - * @param highBit the position of the most significant bit in the - * val parameter. - */ - private int valueToField(int val, int component, int highBit) - { - int toFieldShift = - getComponentSize(component) + shifts[component] - highBit; - int ret = (toFieldShift>0) ? - (val << toFieldShift) : - (val >>> (-toFieldShift)); - return ret & getMask(component); - } - - /** - * Converts a 16 bit value to the correct field bits based on the - * information derived from the field masks. - */ - private int value16ToField(int val, int component) - { - int toFieldShift = getComponentSize(component) + shifts[component] - 16; - return (toFieldShift>0) ? - (val << toFieldShift) : - (val >>> (-toFieldShift)); - } - - /** - * Fills an array with the unnormalized component samples from a - * pixel value. I.e. decompose the pixel, but not perform any - * color conversion. - */ - public final int[] getComponents(int pixel, int[] components, int offset) - { - int numComponents = getNumComponents(); - if (components == null) components = new int[offset + numComponents]; - - for (int b=0; b<numComponents; b++) - components[offset++] = (pixel&getMask(b)) >>> shifts[b]; - - return components; - } - - public final int[] getComponents(Object pixel, int[] components, - int offset) - { - return getComponents(getPixelFromArray(pixel), components, offset); - } - - public final WritableRaster createCompatibleWritableRaster(int w, int h) - { - SampleModel sm = createCompatibleSampleModel(w, h); - Point origin = new Point(0, 0); - return Raster.createWritableRaster(sm, origin); - } - - public int getDataElement(int[] components, int offset) - { - int numComponents = getNumComponents(); - int pixelValue = 0; - - for (int c=0; c<numComponents; c++) - pixelValue |= (components[offset++] << shifts[c]) & getMask(c); - - return pixelValue; - } - - public Object getDataElements(int[] components, int offset, Object obj) - { - /* In this color model, the whole pixel fits in the first element - of the array. */ - int pixelValue = getDataElement(components, offset); - - DataBuffer buffer = Buffers.createBuffer(transferType, obj, 1); - buffer.setElem(0, pixelValue); - return Buffers.getData(buffer); - } - - public final ColorModel coerceData (WritableRaster raster, - boolean isAlphaPremultiplied) - { - if (this.isAlphaPremultiplied == isAlphaPremultiplied) - return this; - - /* TODO: provide better implementation based on the - assumptions we can make due to the specific type of the - color model. */ - super.coerceData(raster, isAlphaPremultiplied); - - return new ComponentColorModel(cspace, bits, hasAlpha(), - isAlphaPremultiplied, // argument - transparency, transferType); - } - - public boolean isCompatibleRaster(Raster raster) - { - /* FIXME: the Sun docs say this method is overridden here, - but I don't see any way to improve upon the implementation - in ColorModel. */ - return super.isCompatibleRaster(raster); - } - - String stringParam() - { - return super.stringParam() + - ", redMask=" + Integer.toHexString(getRedMask()) + - ", greenMask=" + Integer.toHexString(getGreenMask()) + - ", blueMask=" + Integer.toHexString(getBlueMask()) + - ", alphaMask=" + Integer.toHexString(getAlphaMask()); - } - - public String toString() - { - /* FIXME: Again, docs say override, but how do we improve upon the - superclass implementation? */ - return super.toString(); - } -} diff --git a/libjava/java/awt/image/FilteredImageSource.java b/libjava/java/awt/image/FilteredImageSource.java deleted file mode 100644 index 8893e86a625..00000000000 --- a/libjava/java/awt/image/FilteredImageSource.java +++ /dev/null @@ -1,125 +0,0 @@ -/* FilteredImageSource.java -- Java class for providing image data - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.image; - -import java.util.Hashtable; - -/** - * - * @see ImageConsumer - * @author C. Brian Jones (cbj@gnu.org) - */ -public class FilteredImageSource implements ImageProducer -{ - ImageProducer ip; - ImageFilter filter; - Hashtable consumers = new Hashtable(); - - /** - * The given filter is applied to the given image producer - * to create a new image producer. - */ - public FilteredImageSource(ImageProducer ip, ImageFilter filter) { - this.ip = ip; - this.filter = filter; - } - - /** - * Used to register an <code>ImageConsumer</code> with this - * <code>ImageProducer</code>. - */ - public synchronized void addConsumer(ImageConsumer ic) { - if (consumers.containsKey(ic)) - return; - - ImageFilter f = filter.getFilterInstance(ic); - consumers.put(ic, f); - ip.addConsumer(f); - } - - /** - * Used to determine if the given <code>ImageConsumer</code> is - * already registered with this <code>ImageProducer</code>. - */ - public synchronized boolean isConsumer(ImageConsumer ic) { - ImageFilter f = (ImageFilter)consumers.get(ic); - if (f != null) - return ip.isConsumer(f); - return false; - } - - /** - * Used to remove an <code>ImageConsumer</code> from the list of - * registered consumers for this <code>ImageProducer</code>. - */ - public synchronized void removeConsumer(ImageConsumer ic) { - ImageFilter f = (ImageFilter)consumers.remove(ic); - if (f != null) - ip.removeConsumer(f); - } - - /** - * Used to register an <code>ImageConsumer</code> with this - * <code>ImageProducer</code> and then immediately start - * reconstruction of the image data to be delivered to all - * registered consumers. - */ - public void startProduction(ImageConsumer ic) { - ImageFilter f; - if (!(consumers.containsKey(ic))) { - f = filter.getFilterInstance(ic); - consumers.put(ic, f); - ip.addConsumer(f); - } else { - f = (ImageFilter)consumers.get( ic ); - } - ip.startProduction(f); - } - - /** - * Used to register an <code>ImageConsumer</code> with this - * <code>ImageProducer</code> and then request that this producer - * resend the image data in the order top-down, left-right. - */ - public void requestTopDownLeftRightResend(ImageConsumer ic) { - ImageFilter f = (ImageFilter)consumers.get(ic); - ip.requestTopDownLeftRightResend(f); - } -} - diff --git a/libjava/java/awt/image/ImageConsumer.java b/libjava/java/awt/image/ImageConsumer.java deleted file mode 100644 index e1834c3978f..00000000000 --- a/libjava/java/awt/image/ImageConsumer.java +++ /dev/null @@ -1,216 +0,0 @@ -/* ImageConsumer.java -- Java interface for image consumption - Copyright (C) 1999, 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.image; - -import java.util.Hashtable; - -/** - * An object implementing the <code>ImageProducer</code> interface can - * use objects implementing this interface to deliver the image data. - * - * @author C. Brian Jones (cbj@gnu.org) - */ -public interface ImageConsumer -{ - /** - * The pixel order may be random. This should be - * the default assumption of the <code>ImageConsumer</code>. - * - * @see #setHints - */ - int RANDOMPIXELORDER = 1; - - /** - * The pixel order is top-down, left-right. - * - * @see #setHints - */ - int TOPDOWNLEFTRIGHT = 2; - - /** - * The pixel order is in multiples of complete scanlines. - * - * @see #setHints - */ - int COMPLETESCANLINES = 4; - - /** - * The pixels will be delivered in a single pass. There is at - * most one call to <code>setPixels</code> for any single pixel. - * - * @see #setHints - * @see #setPixels - */ - int SINGLEPASS = 8; - - /** - * The pixels will be delivered with multiple calls to - * <code>setPixels</code>. The image contains a single frame - * which ends when <code>imageComplete</code> is called with the - * <code>STATICIMAGEDONE</code> flag. If the image is constantly - * changing such as with video then the end of each frame is - * marked by a similar call to <code>imageComplete</code> with the - * <code>SINGLEFRAMEDONE</code> flag. - * - * @see #setHints - * @see #imageComplete - */ - int SINGLEFRAME = 16; - - /** - * Indicates an error occurred while producing an image. - * - * @see #imageComplete - */ - int IMAGEERROR = 1; - - /** - * A single frame is complete but more will follow. - * - * @see #imageComplete - */ - int SINGLEFRAMEDONE = 2; - - /** - * The image is complete and no more pixels or frames will follow. - * - * @see #imageComplete - */ - int STATICIMAGEDONE = 3; - - /** - * Production of the image has been aborted. - * - * @see #imageComplete - */ - int IMAGEABORTED = 4; - - /** - * An <code>ImageProducer</code> indicates the size of the image - * being produced using this method. - * - * @param width the width of the image - * @param height the height of the image - */ - void setDimensions(int width, int height); - - /** - * An <code>ImageProducer</code> can set a list of properties - * associated with this image by using this method. - * - * @param props the list of properties associated with this image - */ - void setProperties(Hashtable props); - - /** - * This <code>ColorModel</code> should indicate the model used by - * the majority of calls to <code>setPixels</code>. Each call to - * <code>setPixels</code> could however indicate a different - * <code>ColorModel</code>. - * - * @param model the color model to be used most often by setPixels - * @see ColorModel - */ - void setColorModel(ColorModel model); - - /** - * The <code>ImageProducer</code> should call this method with a - * bit mask of hints from any of <code>RANDOMPIXELORDER</code>, - * <code>TOPDOWNLEFTRIGHT</code>, <code>COMPLETESCANLINES</code>, - * <code>SINGLEPASS</code>, <code>SINGLEFRAME</code>. - * - * @param flags a bit mask of hints - */ - void setHints(int flags); - - /** - * Deliver a subset of an ImageProducer's pixels to this ImageConsumer. - * - * Each element of the pixels array represents one pixel. The - * pixel data is formatted according to the color model model. - * The x and y parameters are the coordinates of the block of - * pixels being delivered to this ImageConsumer. They are - * specified relative to the top left corner of the image being - * produced. Likewise, w and h are the pixel block's dimensions. - * - * @param x x coordinate of pixel block - * @param y y coordinate of pixel block - * @param w width of pixel block - * @param h height of pixel block - * @param model color model used to interpret pixel data - * @param pixels pixel block data - * @param offset offset into pixels array - * @param scansize width of one row in the pixel block - */ - void setPixels(int x, int y, int w, int h, - ColorModel model, byte[] pixels, int offset, int scansize); - - /** - * Deliver a subset of an ImageProducer's pixels to this ImageConsumer. - * - * Each element of the pixels array represents one pixel. The - * pixel data is formatted according to the color model model. - * The x and y parameters are the coordinates of the rectangular - * region of pixels being delivered to this ImageConsumer, - * specified relative to the top left corner of the image being - * produced. Likewise, w and h are the pixel region's dimensions. - * - * @param x x coordinate of pixel block - * @param y y coordinate of pixel block - * @param w width of pixel block - * @param h height of pixel block - * @param model color model used to interpret pixel data - * @param pixels pixel block data - * @param offset offset into pixels array - * @param scansize width of one row in the pixel block - */ - void setPixels(int x, int y, int w, int h, - ColorModel model, int[] pixels, int offset, int scansize); - - /** - * The <code>ImageProducer</code> calls this method to indicate a - * single frame or the entire image is complete. The method is - * also used to indicate an error in loading or producing the - * image. - * - * @param status the status of image production, represented by a - * bitwise OR of ImageConsumer flags - */ - void imageComplete(int status); -} diff --git a/libjava/java/awt/image/ImageFilter.java b/libjava/java/awt/image/ImageFilter.java deleted file mode 100644 index 9940a2b1b91..00000000000 --- a/libjava/java/awt/image/ImageFilter.java +++ /dev/null @@ -1,221 +0,0 @@ -/* ImageFilter.java -- Java class for filtering images - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.image; - -import java.util.Hashtable; - -/** - * The <code>ImageFilter</code> class is a base class which can be - * extended to provide different types of filters for an image. By - * default this class does nothing to an image passing through it. - * - * @author C. Brian Jones (cbj@gnu.org) - */ -public class ImageFilter implements ImageConsumer, Cloneable -{ - /** - * The consumer this filter is filtering an image data stream for. - * It is initialized in the method <code>getFilterInstance</code>. - */ - protected ImageConsumer consumer = null; - - /** - * The <code>ImageConsumer</code> can use this method to request - * the pixels be delivered in top-down, left-right order. - * <br> - * The filter can respond in three different ways. - * <ul> - * <li>The default behavior is to forward the request to the - * <code>ImageProducer</code> - * using the method <code>requestTopDownLeftRightResend</code> - * and using the filter as the consumer.</li> - * <li>The filter has the pixels and can retransmit them in the - * top-down, left-right order.</li> - * <li>The filter can do nothing when this method is called.</li> - * </ul> - */ - public void resendTopDownLeftRight(ImageProducer ip) - { - ip.requestTopDownLeftRightResend(this); - } - - /** - * By default, returns a shallow copy of the object created by - * <code>Object.clone()</code> - * - * @see java.lang.Object#clone () - */ - public Object clone() - { - try - { - return super.clone(); - } - catch (CloneNotSupportedException e) - { - // This should never happen as this class implements the - // Cloneable interface. - throw new InternalError (); - } - } - - /** - * This is the only method which can set the - * <code>ImageConsumer</code> for this filter. By default a clone - * of this filter with the appropriate consumer set is returned. - * - * @see #clone () - */ - public ImageFilter getFilterInstance(ImageConsumer ic) - { - if ( ic == null ) - throw new IllegalArgumentException("null argument for ImageFilter.getFilterInstance(ImageConsumer)"); - - consumer = ic; - ImageFilter f = (ImageFilter)clone(); - consumer = null; - return f; - } - - /** - * An <code>ImageProducer</code> indicates the size of the image - * being produced using this method. A filter can override this - * method to intercept these calls from the producer in order to - * change either the width or the height before in turn calling - * the consumer's <code>setDimensions</code> method. - * - * @param width the width of the image - * @param height the height of the image - */ - public void setDimensions(int width, int height) - { - consumer.setDimensions(width, height); - } - - /** - * An <code>ImageProducer</code> can set a list of properties - * associated with this image by using this method. - * - * @param props the list of properties associated with this image - */ - public void setProperties(Hashtable props) - { - props.put("filters", "ImageFilter"); - consumer.setProperties(props); - } - - /** - * Override this method to process calls to this method from the - * <code>ImageProducer</code>. By default the <code>setColorModel</code> - * method of the consumer is called with the specified <code>model</code>. - * - * @param model the color model to be used most often by setPixels - * @see ColorModel */ - public void setColorModel(ColorModel model) - { - consumer.setColorModel(model); - } - - /** - * The <code>ImageProducer</code> should call this method with a - * bit mask of hints from any of <code>RANDOMPIXELORDER</code>, - * <code>TOPDOWNLEFTRIGHT</code>, <code>COMPLETESCANLINES</code>, - * <code>SINGLEPASS</code>, <code>SINGLEFRAME</code> from the - * <code>ImageConsumer</code> interface. - * - * @param flags a bit mask of hints - * @see ImageConsumer - */ - public void setHints(int flags) - { - consumer.setHints(flags); - } - - /** - * This function delivers a rectangle of pixels where any - * pixel(m,n) is stored in the array as a <code>byte</code> at - * index (n * scansize + m + offset). - * - * @param x the x coordinate of the rectangle - * @param y the y coordinate of the rectangle - * @param w the width of the rectangle - * @param h the height of the rectangle - * @param model the <code>ColorModel</code> used to translate the pixels - * @param pixels the array of pixel values - * @param offset the index of the first pixels in the <code>pixels</code> array - * @param scansize the width to use in extracting pixels from the <code>pixels</code> array - */ - public void setPixels(int x, int y, int w, int h, - ColorModel model, byte[] pixels, int offset, int scansize) - { - consumer.setPixels(x, y, w, h, model, pixels, offset, scansize); - } - - /** - * This function delivers a rectangle of pixels where any - * pixel(m,n) is stored in the array as an <code>int</code> at - * index (n * scansize + m + offset). - * - * @param x the x coordinate of the rectangle - * @param y the y coordinate of the rectangle - * @param w the width of the rectangle - * @param h the height of the rectangle - * @param model the <code>ColorModel</code> used to translate the pixels - * @param pixels the array of pixel values - * @param offset the index of the first pixels in the <code>pixels</code> array - * @param scansize the width to use in extracting pixels from the <code>pixels</code> array - */ - public void setPixels(int x, int y, int w, int h, - ColorModel model, int[] pixels, int offset, int scansize) - { - consumer.setPixels(x, y, w, h, model, pixels, offset, scansize); - } - - /** - * The <code>ImageProducer</code> calls this method to indicate a - * single frame or the entire image is complete. The method is - * also used to indicate an error in loading or producing the - * image. - */ - public void imageComplete(int status) - { - consumer.imageComplete(status); - } -} - diff --git a/libjava/java/awt/image/ImageObserver.java b/libjava/java/awt/image/ImageObserver.java deleted file mode 100644 index 36dd013f4e9..00000000000 --- a/libjava/java/awt/image/ImageObserver.java +++ /dev/null @@ -1,129 +0,0 @@ -/* ImageObserver.java -- Java interface for asynchronous updates to an image - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.image; - -import java.awt.Image; - -/** - * An object implementing the <code>ImageObserver</code> interface can - * receive updates on image construction from an - * <code>ImageProducer</code> asynchronously. - * - * @see ImageProducer - * @author C. Brian Jones (cbj@gnu.org) - */ -public interface ImageObserver -{ - /** - * The width of the image has been provided as the - * <code>width</code> argument to <code>imageUpdate</code>. - * - * @see #imageUpdate - */ - int WIDTH = 1; - - /** - * The height of the image has been provided as the - * <code>height</code> argument to <code>imageUpdate</code>. - * - * @see #imageUpdate - */ - int HEIGHT = 2; - - /** - * The properties of the image have been provided. - * - * @see #imageUpdate - * @see java.awt.Image#getProperty (java.lang.String, java.awt.image.ImageObserver) - */ - int PROPERTIES = 4; - - /** - * More pixels are now available for drawing a scaled variation of - * the image. - * - * @see #imageUpdate - */ - int SOMEBITS = 8; - - /** - * All the pixels needed to draw a complete frame of a multi-frame - * image are available. - * - * @see #imageUpdate - */ - int FRAMEBITS = 16; - - /** - * An image with a single frame, a static image, is complete. - * - * @see #imageUpdate - */ - int ALLBITS = 32; - - /** - * An error was encountered while producing the image. - * - * @see #imageUpdate - */ - int ERROR = 64; - - /** - * Production of the image was aborted. - * - * @see #imageUpdate - */ - int ABORT = 128; - - /** - * This is a callback method for an asynchronous image producer to - * provide updates on the production of the image as it happens. - * - * @param image the image the update refers to - * @param flags a bit mask indicating what is provided with this update - * @param x the x coordinate of the image - * @param y the y coordinate of the image - * @param width the width of the image - * @param height the height of the image - * - * @see java.awt.Image - */ - boolean imageUpdate(Image image, int flags, int x, - int y, int width, int height); -} diff --git a/libjava/java/awt/image/ImageProducer.java b/libjava/java/awt/image/ImageProducer.java deleted file mode 100644 index 49846685a3e..00000000000 --- a/libjava/java/awt/image/ImageProducer.java +++ /dev/null @@ -1,85 +0,0 @@ -/* ImageProducer.java -- Java interface for image production - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.image; - -/** - * An object implementing the <code>ImageProducer</code> interface can - * produce data for images. Each image has a corresponding - * <code>ImageProducer</code> which is needed for things such as - * resizing the image. - * - * @see ImageConsumer - * @author C. Brian Jones (cbj@gnu.org) - */ -public interface ImageProducer -{ - /** - * Used to register an <code>ImageConsumer</code> with this - * <code>ImageProducer</code>. - */ - void addConsumer(ImageConsumer ic); - - /** - * Used to determine if the given <code>ImageConsumer</code> is - * already registered with this <code>ImageProducer</code>. - */ - boolean isConsumer(ImageConsumer ic); - - /** - * Used to remove an <code>ImageConsumer</code> from the list of - * registered consumers for this <code>ImageProducer</code>. - */ - void removeConsumer(ImageConsumer ic); - - /** - * Used to register an <code>ImageConsumer</code> with this - * <code>ImageProducer</code> and then immediately start - * reconstruction of the image data to be delivered to all - * registered consumers. - */ - void startProduction(ImageConsumer ic); - - /** - * Used to register an <code>ImageConsumer</code> with this - * <code>ImageProducer</code> and then request that this producer - * resend the image data in the order top-down, left-right. - */ - void requestTopDownLeftRightResend(ImageConsumer ic); -} - diff --git a/libjava/java/awt/image/ImagingOpException.java b/libjava/java/awt/image/ImagingOpException.java deleted file mode 100644 index ca40e9ed365..00000000000 --- a/libjava/java/awt/image/ImagingOpException.java +++ /dev/null @@ -1,66 +0,0 @@ -/* ImagingOpException.java -- indicates an imaging filter failure - Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.image; - -/** - * This exception is thrown when <code>BufferedImageOp</code> or - * <code>RasterOp</code> filters cannot process an image. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @see BufferedImageOp - * @see RasterOp - * @status updated to 1.4 - */ -public class ImagingOpException extends RuntimeException -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = 8026288481846276658L; - - /** - * Create a new instance with a descriptive error message. - * - * @param message the descriptive error message - */ - public ImagingOpException(String message) - { - super(message); - } -} // class ImagingOpException diff --git a/libjava/java/awt/image/IndexColorModel.java b/libjava/java/awt/image/IndexColorModel.java deleted file mode 100644 index 6783f733e0a..00000000000 --- a/libjava/java/awt/image/IndexColorModel.java +++ /dev/null @@ -1,516 +0,0 @@ -/* IndexColorModel.java -- Java class for interpreting Pixel objects - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.image; - -import java.awt.color.ColorSpace; -import java.math.BigInteger; - -/** - * Color model similar to pseudo visual in X11. - * - * This color model maps linear pixel values to actual RGB and alpha colors. - * Thus, pixel values are indexes into the color map. Each color component is - * an 8-bit unsigned value. - * - * The IndexColorModel supports a map of valid pixels, allowing the - * representation of holes in the the color map. The valid map is represented - * as a BigInteger where each bit indicates the validity of the map entry with - * the same index. - * - * Colors can have alpha components for transparency support. If alpha - * component values aren't given, color values are opaque. The model also - * supports a reserved pixel value to represent completely transparent colors, - * no matter what the actual color component values are. - * - * IndexColorModel supports anywhere from 1 to 16 bit index values. The - * allowed transfer types are DataBuffer.TYPE_BYTE and DataBuffer.TYPE_USHORT. - * - * @author C. Brian Jones (cbj@gnu.org) - */ -public class IndexColorModel extends ColorModel -{ - private int map_size; - private boolean opaque; - private int trans = -1; - private int[] rgb; - private BigInteger validBits = BigInteger.ZERO; - - /** - * Each array much contain <code>size</code> elements. For each - * array, the i-th color is described by reds[i], greens[i], - * blues[i], alphas[i], unless alphas is not specified, then all the - * colors are opaque except for the transparent color. - * - * @param bits the number of bits needed to represent <code>size</code> colors - * @param size the number of colors in the color map - * @param reds the red component of all colors - * @param greens the green component of all colors - * @param blues the blue component of all colors - */ - public IndexColorModel(int bits, int size, byte[] reds, byte[] greens, - byte[] blues) - { - this (bits, size, reds, greens, blues, (byte[]) null); - } - - /** - * Each array much contain <code>size</code> elements. For each - * array, the i-th color is described by reds[i], greens[i], - * blues[i], alphas[i], unless alphas is not specified, then all the - * colors are opaque except for the transparent color. - * - * @param bits the number of bits needed to represent <code>size</code> colors - * @param size the number of colors in the color map - * @param reds the red component of all colors - * @param greens the green component of all colors - * @param blues the blue component of all colors - * @param trans the index of the transparent color - */ - public IndexColorModel(int bits, int size, byte[] reds, byte[] greens, - byte[] blues, int trans) - { - this (bits, size, reds, greens, blues, (byte[]) null); - this.trans = trans; - } - - /** - * Each array much contain <code>size</code> elements. For each - * array, the i-th color is described by reds[i], greens[i], - * blues[i], alphas[i], unless alphas is not specified, then all the - * colors are opaque except for the transparent color. - * - * @param bits the number of bits needed to represent <code>size</code> colors - * @param size the number of colors in the color map - * @param reds the red component of all colors - * @param greens the green component of all colors - * @param blues the blue component of all colors - * @param alphas the alpha component of all colors - */ - public IndexColorModel(int bits, int size, byte[] reds, byte[] greens, - byte[] blues, byte[] alphas) - { - // FIXME: This super() constructor should not be used since it can give - // the wrong value for hasAlpha() which is final and cannot be overloaded - super(bits); - map_size = size; - opaque = (alphas == null); - - rgb = new int[size]; - if (alphas == null) - { - for (int i = 0; i < size; i++) - { - rgb[i] = (0xff000000 - | ((reds[i] & 0xff) << 16) - | ((greens[i] & 0xff) << 8) - | (blues[i] & 0xff)); - } - } - else - { - for (int i = 0; i < size; i++) - { - rgb[i] = ((alphas[i] & 0xff) << 24 - | ((reds[i] & 0xff) << 16) - | ((greens[i] & 0xff) << 8) - | (blues[i] & 0xff)); - } - } - - // Generate a bigint with 1's for every pixel - validBits = validBits.setBit(size).subtract(BigInteger.ONE); - } - - /** - * Each array much contain <code>size</code> elements. For each - * array, the i-th color is described by reds[i], greens[i], - * blues[i], alphas[i], unless alphas is not specified, then all the - * colors are opaque except for the transparent color. - * - * @param bits the number of bits needed to represent <code>size</code> colors - * @param size the number of colors in the color map - * @param cmap packed color components - * @param start the offset of the first color component in <code>cmap</code> - * @param hasAlpha <code>cmap</code> has alpha values - * @throws IllegalArgumentException if bits < 1, bits > 16, or size < 1. - */ - public IndexColorModel (int bits, int size, byte[] cmap, int start, - boolean hasAlpha) - { - this (bits, size, cmap, start, hasAlpha, -1); - } - - /** - * Construct an IndexColorModel from an array of red, green, blue, and - * optional alpha components. The component values are interleaved as RGB(A). - * - * @param bits the number of bits needed to represent <code>size</code> colors - * @param size the number of colors in the color map - * @param cmap interleaved color components - * @param start the offset of the first color component in <code>cmap</code> - * @param hasAlpha <code>cmap</code> has alpha values - * @param trans the index of the transparent color - * @throws IllegalArgumentException if bits < 1, bits > 16, or size < 1. - */ - public IndexColorModel (int bits, int size, byte[] cmap, int start, - boolean hasAlpha, int trans) - { - super (bits); - if (bits > 16) - throw new IllegalArgumentException("bits > 16"); - if (size < 1) - throw new IllegalArgumentException("size < 1"); - map_size = size; - opaque = !hasAlpha; - this.trans = trans; - - rgb = new int[size]; - if (hasAlpha) - { - for (int i = 0; i < size; i++) - rgb[i] = - // alpha - ((cmap[4 * i + 3 + start] & 0xff) << 24 - // red - | ((cmap[4 * i + start] & 0xff) << 16) - // green - | ((cmap[4 * i + 1 + start] & 0xff) << 8) - // blue - | (cmap[4 * i + 2 + start] & 0xff)); - } - else - { - for (int i = 0; i < size; i++) - rgb[i] = (0xff000000 - // red - | ((cmap[3 * i + start] & 0xff) << 16) - // green - | ((cmap[3 * i + 1 + start] & 0xff) << 8) - // blue - | (cmap[3 * i + 2 + start] & 0xff)); - } - - // Generate a bigint with 1's for every pixel - validBits = validBits.setBit(size).subtract(BigInteger.ONE); - } - - /** - * Construct an IndexColorModel from an array of <code>size</code> packed - * colors. Each int element contains 8-bit red, green, blue, and optional - * alpha values packed in order. If hasAlpha is false, then all the colors - * are opaque except for the transparent color. - * - * @param bits the number of bits needed to represent <code>size</code> colors - * @param size the number of colors in the color map - * @param cmap packed color components - * @param start the offset of the first color component in <code>cmap</code> - * @param hasAlpha <code>cmap</code> has alpha values - * @param trans the index of the transparent color - * @param transferType DataBuffer.TYPE_BYTE or DataBuffer.TYPE_USHORT - * @throws IllegalArgumentException if bits < 1, bits > 16, or size < 1. - * @throws IllegalArgumentException if transferType is something other than - * TYPE_BYTE or TYPE_USHORT. - */ - public IndexColorModel (int bits, int size, int[] cmap, int start, - boolean hasAlpha, int trans, int transferType) - { - super(bits * 4, // total bits, sRGB, four channels - nArray(bits, 4), // bits for each channel - ColorSpace.getInstance(ColorSpace.CS_sRGB), // sRGB - true, // has alpha - false, // not premultiplied - TRANSLUCENT, transferType); - if (transferType != DataBuffer.TYPE_BYTE - && transferType != DataBuffer.TYPE_USHORT) - throw new IllegalArgumentException(); - if (bits > 16) - throw new IllegalArgumentException("bits > 16"); - if (size < 1) - throw new IllegalArgumentException("size < 1"); - map_size = size; - opaque = !hasAlpha; - this.trans = trans; - - rgb = new int[size]; - if (!hasAlpha) - for (int i = 0; i < size; i++) - rgb[i] = cmap[i + start] | 0xff000000; - else - System.arraycopy(cmap, start, rgb, 0, size); - - // Generate a bigint with 1's for every pixel - validBits = validBits.setBit(size).subtract(BigInteger.ONE); - } - - /** - * Construct an IndexColorModel using a colormap with holes. - * - * The IndexColorModel is built from the array of ints defining the - * colormap. Each element contains red, green, blue, and alpha - * components. The ColorSpace is sRGB. The transparency value is - * automatically determined. - * - * This constructor permits indicating which colormap entries are valid, - * using the validBits argument. Each entry in cmap is valid if the - * corresponding bit in validBits is set. - * - * @param bits the number of bits needed to represent <code>size</code> colors - * @param size the number of colors in the color map - * @param cmap packed color components - * @param start the offset of the first color component in <code>cmap</code> - * @param transferType DataBuffer.TYPE_BYTE or DataBuffer.TYPE_USHORT - * @throws IllegalArgumentException if bits < 1, bits > 16, or size < 1. - * @throws IllegalArgumentException if transferType is something other than - * TYPE_BYTE or TYPE_USHORT. - */ - public IndexColorModel (int bits, int size, int[] cmap, int start, - int transferType, BigInteger validBits) - { - super(bits * 4, // total bits, sRGB, four channels - nArray(bits, 4), // bits for each channel - ColorSpace.getInstance(ColorSpace.CS_sRGB), // sRGB - true, // has alpha - false, // not premultiplied - TRANSLUCENT, transferType); - if (transferType != DataBuffer.TYPE_BYTE - && transferType != DataBuffer.TYPE_USHORT) - throw new IllegalArgumentException(); - if (bits > 16) - throw new IllegalArgumentException("bits > 16"); - if (size < 1) - throw new IllegalArgumentException("size < 1"); - map_size = size; - opaque = false; - this.trans = -1; - this.validBits = validBits; - - rgb = new int[size]; - if (!hasAlpha) - for (int i = 0; i < size; i++) - rgb[i] = cmap[i + start] | 0xff000000; - else - System.arraycopy(cmap, start, rgb, 0, size); - } - - public final int getMapSize () - { - return map_size; - } - - /** - * Get the index of the transparent color in this color model - */ - public final int getTransparentPixel () - { - return trans; - } - - /** - * <br> - */ - public final void getReds (byte[] r) - { - getComponents (r, 2); - } - - /** - * <br> - */ - public final void getGreens (byte[] g) - { - getComponents (g, 1); - } - - /** - * <br> - */ - public final void getBlues (byte[] b) - { - getComponents (b, 0); - } - - /** - * <br> - */ - public final void getAlphas (byte[] a) - { - getComponents (a, 3); - } - - private void getComponents (byte[] c, int ci) - { - int i, max = (map_size < c.length) ? map_size : c.length; - for (i = 0; i < max; i++) - c[i] = (byte) ((generateMask (ci) & rgb[i]) >> (ci * pixel_bits)); - } - - /** - * Get the red component of the given pixel. - */ - public final int getRed (int pixel) - { - if (pixel < map_size) - return (int) ((generateMask (2) & rgb[pixel]) >> (2 * pixel_bits)); - - return 0; - } - - /** - * Get the green component of the given pixel. - */ - public final int getGreen (int pixel) - { - if (pixel < map_size) - return (int) ((generateMask (1) & rgb[pixel]) >> (1 * pixel_bits)); - - return 0; - } - - /** - * Get the blue component of the given pixel. - */ - public final int getBlue (int pixel) - { - if (pixel < map_size) - return (int) (generateMask (0) & rgb[pixel]); - - return 0; - } - - /** - * Get the alpha component of the given pixel. - */ - public final int getAlpha (int pixel) - { - if (opaque || pixel >= map_size) - return 255; - - return (int) ((generateMask (3) & rgb[pixel]) >> (3 * pixel_bits)); - } - - /** - * Get the RGB color value of the given pixel using the default - * RGB color model. - * - * @param pixel a pixel value - */ - public final int getRGB (int pixel) - { - if (pixel >= 0 && pixel < map_size) - return rgb[pixel]; - - return 0; - } - - /** - * Get the RGB color values of all pixels in the map using the default - * RGB color model. - * - * @param rgb The destination array. - */ - public final void getRGBs (int[] rgb) - { - System.arraycopy(this.rgb, 0, rgb, 0, map_size); - } - - //pixel_bits is number of bits to be in generated mask - private int generateMask (int offset) - { - return (((2 << pixel_bits ) - 1) << (pixel_bits * offset)); - } - - /** Return true if pixel is valid, false otherwise. */ - public boolean isValid(int pixel) - { - return validBits.testBit(pixel); - } - - /** Return true if all pixels are valid, false otherwise. */ - public boolean isValid() - { - // Generate a bigint with 1's for every pixel - BigInteger allbits = new BigInteger("0"); - allbits.setBit(map_size); - allbits.subtract(new BigInteger("1")); - return allbits.equals(validBits); - } - - /** - * Returns a BigInteger where each bit represents an entry in the color - * model. If the bit is on, the entry is valid. - */ - public BigInteger getValidPixels() - { - return validBits; - } - - /** - * Construct a BufferedImage with rgb pixel values from a Raster. - * - * Constructs a new BufferedImage in which each pixel is an RGBA int from - * a Raster with index-valued pixels. If this model has no alpha component - * or transparent pixel, the type of the new BufferedImage is TYPE_INT_RGB. - * Otherwise the type is TYPE_INT_ARGB. If forceARGB is true, the type is - * forced to be TYPE_INT_ARGB no matter what. - * - * @param raster The source of pixel values. - * @param forceARGB True if type must be TYPE_INT_ARGB. - * @return New BufferedImage with RBGA int pixel values. - */ - public BufferedImage convertToIntDiscrete(Raster raster, boolean forceARGB) - { - int type = forceARGB ? BufferedImage.TYPE_INT_ARGB - : ((opaque && trans == -1) ? BufferedImage.TYPE_INT_RGB : - BufferedImage.TYPE_INT_ARGB); - - // FIXME: assuming that raster has only 1 band since pixels are supposed - // to be int indexes. - // FIXME: it would likely be more efficient to fetch a complete array, - // but it would take much more memory. - // FIXME: I'm not sure if transparent pixels or alpha values need special - // handling here. - BufferedImage im = new BufferedImage(raster.width, raster.height, type); - for (int x = raster.minX; x < raster.width + raster.minX; x++) - for (int y = raster.minY; y < raster.height + raster.minY; y++) - im.setRGB(x, y, rgb[raster.getSample(x, y, 0)]); - - return im; - } -} - diff --git a/libjava/java/awt/image/Kernel.java b/libjava/java/awt/image/Kernel.java deleted file mode 100644 index f7c29c3cde9..00000000000 --- a/libjava/java/awt/image/Kernel.java +++ /dev/null @@ -1,143 +0,0 @@ -/* Kernel.java -- Java class for an image processing kernel - Copyright (C) 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.image; - -/** - * Kernel represents an image processing kernel. It gets used to hold - * convolution filters among other purposes. It stores an array of float - * values representing a 2-dimensional array in row-major order. - * - * @author Jerry Quinn (jlquinn@optonline.net) - * @version 1.0 - */ -public class Kernel implements Cloneable -{ - private final int width; - private final int height; - private final float[] data; - - /** - * Creates a new <code>Kernel</code> instance. - * - * @param width The 2D width of data. - * @param height The 2D height of data. - * @param data The source data array. - * @exception IllegalArgumentException if width * height < data.length. - */ - public Kernel(int width, int height, float[] data) - throws IllegalArgumentException - { - this.width = width; - this.height = height; - if (data.length < width * height || width < 0 || height < 0) - throw new IllegalArgumentException(); - this.data = new float[width * height]; - System.arraycopy(data, 0, this.data, 0, width * height); - } - - /** - * Return the X origin: (width - 1) / 2 - */ - public final int getXOrigin() - { - return (width - 1) / 2; - } - - /** - * Return the Y origin: (height - 1) / 2 - */ - public final int getYOrigin() - { - return (height - 1) / 2; - } - - /** - * @return The kernel width. - */ - public final int getWidth() - { - return width; - } - - /** - * @return The kernel height. - */ - public final int getHeight() - { - return height; - } - - /** - * Return the kernel data. - * - * If data is null, allocates a new array and returns it. Otherwise, the - * kernel values are copied into data. - * - * @param data Array to copy values into, or null. - * @return The array with copied values. - * @exception IllegalArgumentException if data != null and too small. - */ - public final float[] getKernelData(float[] data) - throws IllegalArgumentException - { - if (data == null) - return (float[])this.data.clone(); - - if (data.length < this.data.length) - throw new IllegalArgumentException(); - - System.arraycopy(this.data, 0, data, 0, this.data.length); - return data; - } - - /** - * @return a clone of this Kernel. - */ - public Object clone() - { - try - { - return super.clone(); - } - catch (CloneNotSupportedException e) - { - throw (Error) new InternalError().initCause(e); // Impossible - } - } -} diff --git a/libjava/java/awt/image/LookupOp.java b/libjava/java/awt/image/LookupOp.java deleted file mode 100644 index f131daabae3..00000000000 --- a/libjava/java/awt/image/LookupOp.java +++ /dev/null @@ -1,252 +0,0 @@ -/* LookupOp.java -- Filter that converts each pixel using a lookup table. - Copyright (C) 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.image; - -import java.awt.Graphics2D; -import java.awt.RenderingHints; -import java.awt.geom.Point2D; -import java.awt.geom.Rectangle2D; - -/** - * LookupOp is a filter that converts each pixel using a lookup table. - * - * For filtering Rasters, the lookup table must have either one component - * that is applied to all bands, or one component for every band in the - * Rasters. - * - * For BufferedImages, the lookup table may apply to both color and alpha - * components. If the lookup table contains one component, or if there are - * the same number of components as color components in the source, the table - * applies to all color components. Otherwise the table applies to all - * components including alpha. Alpha premultiplication is ignored during the - * lookup filtering. - * - * After filtering, if color conversion is necessary, the conversion happens, - * taking alpha premultiplication into account. - * - * @author jlquinn - */ -public class LookupOp implements BufferedImageOp, RasterOp -{ - private LookupTable lut; - private RenderingHints hints; - - /** Construct a new LookupOp. - * - * @param lookup LookupTable to use. - * @param hints Rendering hints (can be null). - */ - public LookupOp(LookupTable lookup, RenderingHints hints) - { - lut = lookup; - this.hints = hints; - } - - /* (non-Javadoc) - * @see java.awt.image.BufferedImageOp#filter(java.awt.image.BufferedImage, java.awt.image.BufferedImage) - */ - public BufferedImage filter(BufferedImage src, BufferedImage dst) - { - if (src.getColorModel() instanceof IndexColorModel) - throw new IllegalArgumentException("LookupOp.filter: IndexColorModel " - + "not allowed"); - if (dst == null) - dst = createCompatibleDestImage(src, src.getColorModel()); - - // Set up for potential colormodel mismatch - BufferedImage tgt; - if (dst.getColorModel().equals(src.getColorModel())) - tgt = dst; - else - tgt = createCompatibleDestImage(src, src.getColorModel()); - - Raster sr = src.getRaster(); - WritableRaster dr = tgt.getRaster(); - - if (src.getColorModel().hasAlpha() && - (lut.getNumComponents() == 1 || - lut.getNumComponents() == src.getColorModel().getNumColorComponents())) - { - // Need to ignore alpha for lookup - int[] dbuf = new int[src.getColorModel().getNumComponents()]; - int tmpBands = src.getColorModel().getNumColorComponents(); - int[] tmp = new int[tmpBands]; - - // Filter the pixels - for (int y = src.getMinY(); y < src.getHeight() + src.getMinY(); y++) - for (int x = src.getMinX(); x < src.getWidth() + src.getMinX(); x++) - { - // Filter only color components, but also copy alpha - sr.getPixel(x, y, dbuf); - System.arraycopy(dbuf, 0, tmp, 0, tmpBands); - dr.setPixel(x, y, lut.lookupPixel(tmp, dbuf)); - } - } - else if (lut.getNumComponents() != 1 - && - lut.getNumComponents() != src.getColorModel().getNumComponents()) - throw new IllegalArgumentException("LookupOp.filter: " - + "Incompatible lookup " - + "table and source image"); - - // No alpha to ignore - int[] dbuf = new int[src.getColorModel().getNumComponents()]; - - // Filter the pixels - for (int y = src.getMinY(); y < src.getHeight() + src.getMinY(); y++) - for (int x = src.getMinX(); x < src.getWidth() + src.getMinX(); x++) - dr.setPixel(x, y, lut.lookupPixel(sr.getPixel(x, y, dbuf), dbuf)); - - if (tgt != dst) - { - // Convert between color models. - // TODO Check that premultiplied alpha is handled correctly here. - Graphics2D gg = dst.createGraphics(); - gg.setRenderingHints(hints); - gg.drawImage(tgt, 0, 0, null); - gg.dispose(); - } - - return dst; - } - - /* (non-Javadoc) - * @see java.awt.image.BufferedImageOp#getBounds2D(java.awt.image.BufferedImage) - */ - public Rectangle2D getBounds2D(BufferedImage src) - { - return src.getRaster().getBounds(); - } - - /* (non-Javadoc) - * @see java.awt.image.BufferedImageOp#createCompatibleDestImage(java.awt.image.BufferedImage, java.awt.image.ColorModel) - */ - public BufferedImage createCompatibleDestImage(BufferedImage src, - ColorModel dstCM) - { - // FIXME: set properties to those in src - return new BufferedImage(dstCM, - src.getRaster().createCompatibleWritableRaster(), - src.isPremultiplied, null); - } - - /** Return corresponding destination point for source point. - * - * LookupOp will return the value of src unchanged. - * @param src The source point. - * @param dst The destination point. - * @see java.awt.image.RasterOp#getPoint2D(java.awt.geom.Point2D, java.awt.geom.Point2D) - */ - public Point2D getPoint2D(Point2D src, Point2D dst) - { - if (dst == null) - return (Point2D) src.clone(); - - dst.setLocation(src); - return dst; - } - - /** Return the LookupTable for this op. */ - public LookupTable getTable() - { - return lut; - } - - /* (non-Javadoc) - * @see java.awt.image.RasterOp#getRenderingHints() - */ - public RenderingHints getRenderingHints() - { - return hints; - } - - /** Filter a raster through a lookup table. - * - * Applies the lookup table for this Rasterop to each pixel of src and - * puts the results in dest. If dest is null, a new Raster is created and - * returned. - * - * @param src The source raster. - * @param dest The destination raster. - * @return The WritableRaster with the filtered pixels. - * @throws IllegalArgumentException if lookup table has more than one - * component but not the same as src and dest. - * @see java.awt.image.RasterOp#filter(java.awt.image.Raster, java.awt.image.WritableRaster) - */ - public WritableRaster filter(Raster src, WritableRaster dest) - { - if (dest == null) - // Allocate a raster if needed - dest = createCompatibleDestRaster(src); - else - if (src.getNumBands() != dest.getNumBands()) - throw new IllegalArgumentException(); - - if (lut.getNumComponents() != 1 - && lut.getNumComponents() != src.getNumBands()) - throw new IllegalArgumentException(); - - - // Allocate pixel storage. - int[] tmp = new int[src.getNumBands()]; - - // Filter the pixels - for (int y = src.getMinY(); y < src.getHeight() + src.getMinY(); y++) - for (int x = src.getMinX(); x < src.getWidth() + src.getMinX(); x++) - dest.setPixel(x, y, lut.lookupPixel(src.getPixel(x, y, tmp), tmp)); - return dest; - } - - /* (non-Javadoc) - * @see java.awt.image.RasterOp#getBounds2D(java.awt.image.Raster) - */ - public Rectangle2D getBounds2D(Raster src) - { - return src.getBounds(); - } - - /* (non-Javadoc) - * @see java.awt.image.RasterOp#createCompatibleDestRaster(java.awt.image.Raster) - */ - public WritableRaster createCompatibleDestRaster(Raster src) - { - return src.createCompatibleWritableRaster(); - } - -} diff --git a/libjava/java/awt/image/LookupTable.java b/libjava/java/awt/image/LookupTable.java deleted file mode 100644 index f814b8e090b..00000000000 --- a/libjava/java/awt/image/LookupTable.java +++ /dev/null @@ -1,109 +0,0 @@ -/* LookupTable.java -- Java class for a pixel translation table. - Copyright (C) 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.image; - -/** - * LookupTable represents translation arrays for pixel values. It wraps one - * or more data arrays for each layer (or component) in an image, such as - * Alpha, R, G, and B. When doing translation, the offset is subtracted from - * the pixel values to allow a subset of an array to be used. - * - * @see ByteLookupTable - * @see ShortLookupTable - * - * @author Jerry Quinn (jlquinn@optonline.net) - * @version 1.0 - */ -public abstract class LookupTable -{ - // Not protected since that's part of the public API. - int offset; - int numComponents; - - /** - * Creates a new <code>LookupTable</code> instance. - * - * If numComponents is 1, the same translation table is used for all pixel - * components. - * - * @param offset Offset to be subtracted. - * @param numComponents Number of image components. - * @exception IllegalArgumentException if offset < 0 or numComponents < 1. - */ - protected LookupTable(int offset, int numComponents) - throws IllegalArgumentException - { - if (offset < 0 || numComponents < 1) - throw new IllegalArgumentException(); - this.offset = offset; - this.numComponents = numComponents; - } - - /** Return the number of components. */ - public int getNumComponents() - { - return numComponents; - } - - /** Return the offset. */ - public int getOffset() - { - return offset; - } - - - /** - * Return translated values for a pixel. - * - * For each value in the pixel src, use the value minus offset as an index - * in the component array and copy the value there to the output for the - * component. If dest is null, the output is a new array, otherwise the - * translated values are written to dest. Dest can be the same array as - * src. - * - * For example, if the pixel src is [2, 4, 3], and offset is 1, the output - * is [comp1[1], comp2[3], comp3[2]], where comp1, comp2, and comp3 are the - * translation arrays. - * - * @param src Component values of a pixel. - * @param dest Destination array for values, or null. - * @return Translated values for the pixel. - */ - public abstract int[] lookupPixel(int[] src, int[] dest); -} diff --git a/libjava/java/awt/image/MemoryImageSource.java b/libjava/java/awt/image/MemoryImageSource.java deleted file mode 100644 index c27e0bf7317..00000000000 --- a/libjava/java/awt/image/MemoryImageSource.java +++ /dev/null @@ -1,373 +0,0 @@ -/* MemoryImageSource.java -- Java class for providing image data - Copyright (C) 1999, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.image; - -import java.util.Hashtable; -import java.util.Vector; - -public class MemoryImageSource implements ImageProducer -{ - private boolean animated = false; - private boolean fullbuffers = false; - private int[] pixeli; - private int width; - private int height; - private int offset; - private int scansize; - private byte[] pixelb; - private ColorModel cm; - private Hashtable props = new Hashtable(); - private Vector consumers = new Vector(); - - /** - * Construct an image producer that reads image data from a byte - * array. - * - * @param w width of image - * @param h height of image - * @param cm the color model used to represent pixel values - * @param pix a byte array of pixel values - * @param off the offset into the array at which the first pixel is stored - * @param scan the number of array elements that represents a single pixel row - */ - public MemoryImageSource(int w, int h, ColorModel cm, byte[] pix, int off, - int scan) - { - this(w, h, cm, pix, off, scan, null); - } - - /** - * Constructs an ImageProducer from memory - */ - public MemoryImageSource(int w, int h, ColorModel cm, byte[] pix, int off, - int scan, Hashtable props) - { - width = w; - height = h; - this.cm = cm; - offset = off; - scansize = scan; - this.props = props; - int max = ((scansize > width) ? scansize : width); - pixelb = pix; - } - - /** - * Construct an image producer that reads image data from an - * integer array. - * - * @param w width of image - * @param h height of image - * @param cm the color model used to represent pixel values - * @param pix an integer array of pixel values - * @param off the offset into the array at which the first pixel is stored - * @param scan the number of array elements that represents a single pixel row - */ - public MemoryImageSource(int w, int h, ColorModel cm, int[] pix, int off, - int scan) - { - this(w, h, cm, pix, off, scan, null); - } - - /** - Constructs an ImageProducer from memory - */ - public MemoryImageSource(int w, int h, ColorModel cm, int[] pix, int off, - int scan, Hashtable props) - { - width = w; - height = h; - this.cm = cm; - offset = off; - scansize = scan; - this.props = props; - int max = ((scansize > width) ? scansize : width); - pixeli = pix; - } - - /** - * Constructs an ImageProducer from memory using the default RGB ColorModel - */ - public MemoryImageSource(int w, int h, int[] pix, int off, int scan, - Hashtable props) - { - this(w, h, ColorModel.getRGBdefault(), pix, off, scan, props); - } - - /** - * Constructs an ImageProducer from memory using the default RGB ColorModel - */ - public MemoryImageSource(int w, int h, int[] pix, int off, int scan) - { - this(w, h, ColorModel.getRGBdefault(), pix, off, scan, null); - } - - /** - * Used to register an <code>ImageConsumer</code> with this - * <code>ImageProducer</code>. - */ - public synchronized void addConsumer(ImageConsumer ic) - { - if (consumers.contains(ic)) - return; - - consumers.addElement(ic); - } - - /** - * Used to determine if the given <code>ImageConsumer</code> is - * already registered with this <code>ImageProducer</code>. - */ - public synchronized boolean isConsumer(ImageConsumer ic) - { - if (consumers.contains(ic)) - return true; - return false; - } - - /** - * Used to remove an <code>ImageConsumer</code> from the list of - * registered consumers for this <code>ImageProducer</code>. - */ - public synchronized void removeConsumer(ImageConsumer ic) - { - consumers.removeElement(ic); - } - - /** - * Used to register an <code>ImageConsumer</code> with this - * <code>ImageProducer</code> and then immediately start - * reconstruction of the image data to be delivered to all - * registered consumers. - */ - public void startProduction(ImageConsumer ic) - { - if (! (consumers.contains(ic))) - consumers.addElement(ic); - - Vector list = (Vector) consumers.clone(); - for (int i = 0; i < list.size(); i++) - { - ic = (ImageConsumer) list.elementAt(i); - sendPicture(ic); - if (animated) - ic.imageComplete(ImageConsumer.SINGLEFRAME); - else - ic.imageComplete(ImageConsumer.STATICIMAGEDONE); - } - } - - /** - * Used to register an <code>ImageConsumer</code> with this - * <code>ImageProducer</code> and then request that this producer - * resend the image data in the order top-down, left-right. - */ - public void requestTopDownLeftRightResend(ImageConsumer ic) - { - startProduction(ic); - } - - /** - * Changes a flag to indicate whether this MemoryImageSource supports - * animations. - * - * @param animated A flag indicating whether this class supports animations - */ - public synchronized void setAnimated(boolean animated) - { - this.animated = animated; - } - - /** - * A flag to indicate whether or not to send full buffer updates when - * sending animation. If this flag is set then full buffers are sent - * in the newPixels methods instead of just regions. - * - * @param fullbuffers - a flag indicating whether to send the full buffers - */ - public synchronized void setFullBufferUpdates(boolean fullbuffers) - { - this.fullbuffers = fullbuffers; - } - - /** - * Send an animation frame to the image consumers. - */ - public void newPixels() - { - if (animated == true) - { - ImageConsumer ic; - Vector list = (Vector) consumers.clone(); - for (int i = 0; i < list.size(); i++) - { - ic = (ImageConsumer) list.elementAt(i); - sendPicture(ic); - ic.imageComplete(ImageConsumer.SINGLEFRAME); - } - } - } - - private void sendPicture(ImageConsumer ic) - { - ic.setHints(ImageConsumer.TOPDOWNLEFTRIGHT); - if (props != null) - ic.setProperties(props); - ic.setDimensions(width, height); - ic.setColorModel(cm); - if (pixeli != null) - ic.setPixels(0, 0, width, height, cm, pixeli, offset, scansize); - else - ic.setPixels(0, 0, width, height, cm, pixelb, offset, scansize); - } - - /** - * Send an animation frame to the image consumers containing the specified - * pixels unless setFullBufferUpdates is set. - */ - public synchronized void newPixels(int x, int y, int w, int h) - { - if (animated == true) - { - if (fullbuffers) - newPixels(); - else - { - ImageConsumer ic; - Vector list = (Vector) consumers.clone(); - for (int i = 0; i < list.size(); i++) - { - ic = (ImageConsumer) list.elementAt(i); - ic.setHints(ImageConsumer.TOPDOWNLEFTRIGHT); - if (props != null) - ic.setProperties(props); - if (pixeli != null) - { - int[] pixelbuf = new int[w * h]; - for (int row = y; row < y + h; row++) - System.arraycopy(pixeli, row * scansize + x + offset, - pixelbuf, 0, w * h); - ic.setPixels(x, y, w, h, cm, pixelbuf, 0, w); - } - else - { - byte[] pixelbuf = new byte[w * h]; - for (int row = y; row < y + h; row++) - System.arraycopy(pixelb, row * scansize + x + offset, - pixelbuf, 0, w * h); - - ic.setPixels(x, y, w, h, cm, pixelbuf, 0, w); - } - ic.imageComplete(ImageConsumer.SINGLEFRAME); - } - } - } - } - - /** - * Send an animation frame to the image consumers containing the specified - * pixels unless setFullBufferUpdates is set. - * - * If framenotify is set then a notification is sent when the frame - * is sent otherwise no status is sent. - */ - public synchronized void newPixels(int x, int y, int w, int h, - boolean framenotify) - { - if (animated == true) - { - if (fullbuffers) - newPixels(); - else - { - ImageConsumer ic; - Vector list = (Vector) consumers.clone(); - for (int i = 0; i < list.size(); i++) - { - ic = (ImageConsumer) list.elementAt(i); - ic.setHints(ImageConsumer.TOPDOWNLEFTRIGHT); - if (props != null) - ic.setProperties(props); - if (pixeli != null) - { - int[] pixelbuf = new int[w * h]; - for (int row = y; row < y + h; row++) - System.arraycopy(pixeli, row * scansize + x + offset, - pixelbuf, 0, w * h); - ic.setPixels(x, y, w, h, cm, pixelbuf, 0, w); - } - else - { - byte[] pixelbuf = new byte[w * h]; - for (int row = y; row < y + h; row++) - System.arraycopy(pixelb, row * scansize + x + offset, - pixelbuf, 0, w * h); - ic.setPixels(x, y, w, h, cm, pixelbuf, 0, w); - } - if (framenotify == true) - ic.imageComplete(ImageConsumer.SINGLEFRAME); - } - } - } - } - - public synchronized void newPixels(byte[] newpix, ColorModel newmodel, - int offset, int scansize) - { - pixeli = null; - pixelb = newpix; - cm = newmodel; - this.offset = offset; - this.scansize = scansize; - if (animated == true) - newPixels(); - } - - public synchronized void newPixels(int[] newpix, ColorModel newmodel, - int offset, int scansize) - { - pixelb = null; - pixeli = newpix; - cm = newmodel; - this.offset = offset; - this.scansize = scansize; - if (animated == true) - newPixels(); - } -} diff --git a/libjava/java/awt/image/MultiPixelPackedSampleModel.java b/libjava/java/awt/image/MultiPixelPackedSampleModel.java deleted file mode 100644 index 18a6e555205..00000000000 --- a/libjava/java/awt/image/MultiPixelPackedSampleModel.java +++ /dev/null @@ -1,388 +0,0 @@ -/* Copyright (C) 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.awt.image; - -import gnu.java.awt.Buffers; - -/** - * MultiPixelPackedSampleModel provides a single band model that supports - * multiple pixels in a single unit. Pixels have 2^n bits and 2^k pixels fit - * per data element. - * - * @author Jerry Quinn (jlquinn@optonline.net) - */ -public class MultiPixelPackedSampleModel extends SampleModel -{ - private int scanlineStride; - private int[] bitMasks; - private int[] bitOffsets; - private int[] sampleSize; - private int dataBitOffset; - private int elemBits; - private int numberOfBits; - private int numElems; - - public MultiPixelPackedSampleModel(int dataType, int w, int h, - int numberOfBits) - { - this(dataType, w, h, numberOfBits, 0, 0); - } - - public MultiPixelPackedSampleModel(int dataType, int w, int h, - int numberOfBits, int scanlineStride, - int dataBitOffset) - { - super(dataType, w, h, 1); - - switch (dataType) - { - case DataBuffer.TYPE_BYTE: - elemBits = 8; - break; - case DataBuffer.TYPE_USHORT: - elemBits = 16; - break; - case DataBuffer.TYPE_INT: - elemBits = 32; - break; - default: - throw new IllegalArgumentException("MultiPixelPackedSampleModel" - + " unsupported dataType"); - } - - this.dataBitOffset = dataBitOffset; - - this.numberOfBits = numberOfBits; - if (numberOfBits > elemBits) - throw new RasterFormatException("MultiPixelPackedSampleModel pixel size" - + " larger than dataType"); - switch (numberOfBits) - { - case 1: case 2: case 4: case 8: case 16: case 32: break; - default: - throw new RasterFormatException("MultiPixelPackedSampleModel pixel" - + " size not 2^n bits"); - } - numElems = elemBits / numberOfBits; - - // Compute scan line large enough for w pixels. - if (scanlineStride == 0) - scanlineStride = ((dataBitOffset + w * numberOfBits) / elemBits); - this.scanlineStride = scanlineStride; - - - sampleSize = new int[1]; - sampleSize[0] = numberOfBits; - - bitMasks = new int[numElems]; - bitOffsets = new int[numElems]; - for (int i=0; i < numElems; i++) - { - bitOffsets[numElems - i- 1] = numberOfBits * i; - bitMasks[numElems - i - 1] = ((1 << numberOfBits) - 1) << - bitOffsets[numElems - i - 1]; - } - } - - public SampleModel createCompatibleSampleModel(int w, int h) - { - /* FIXME: We can avoid recalculation of bit offsets and sample - sizes here by passing these from the current instance to a - special private constructor. */ - return new MultiPixelPackedSampleModel(dataType, w, h, numberOfBits); - } - - - /** - * Creates a DataBuffer for holding pixel data in the format and - * layout described by this SampleModel. The returned buffer will - * consist of one single bank. - */ - public DataBuffer createDataBuffer() - { - int size; - - // FIXME: The comment refers to SinglePixelPackedSampleModel. See if the - // same can be done for MultiPixelPackedSampleModel. - // We can save (scanlineStride - width) pixels at the very end of - // the buffer. The Sun reference implementation (J2SE 1.3.1 and - // 1.4.1_01) seems to do this; tested with Mauve test code. - size = scanlineStride * height; - - return Buffers.createBuffer(getDataType(), size); - } - - - public int getNumDataElements() - { - return 1; - } - - public int[] getSampleSize() - { - return sampleSize; - } - - public int getSampleSize(int band) - { - return sampleSize[0]; - } - - public int getOffset(int x, int y) - { - return scanlineStride * y + ((dataBitOffset + x*numberOfBits) / elemBits); - } - - public int getBitOffset(int x) - { - return (dataBitOffset + x*numberOfBits) % elemBits; - } - - public int getDataBitOffset() - { - return dataBitOffset; - } - - public int getScanlineStride() - { - return scanlineStride; - } - - public int getPixelBitStride() - { - return numberOfBits; - } - - - public SampleModel createSubsetSampleModel(int[] bands) - { - int numBands = bands.length; - if (numBands != 1) - throw new RasterFormatException("MultiPixelPackedSampleModel only" - + " supports one band"); - - return new MultiPixelPackedSampleModel(dataType, width, height, - numberOfBits, scanlineStride, - dataBitOffset); - } - - /** - * Extract one pixel and return in an array of transfer type. - * - * Extracts the pixel at x, y from data and stores into the 0th index of the - * array obj, since there is only one band. If obj is null, a new array of - * getTransferType() is created. - * - * @param x The x-coordinate of the pixel rectangle to store in <code>obj</code>. - * @param y The y-coordinate of the pixel rectangle to store in <code>obj</code>. - * @param obj The primitive array to store the pixels into or null to force creation. - * @param data The DataBuffer that is the source of the pixel data. - * @return The primitive array containing the pixel data. - * @see java.awt.image.SampleModel#getDataElements(int, int, java.lang.Object, java.awt.image.DataBuffer) - */ - public Object getDataElements(int x, int y, Object obj, - DataBuffer data) - { - int pixel = getSample(x, y, 0, data); - switch (getTransferType()) - { - case DataBuffer.TYPE_BYTE: - if (obj == null) obj = new byte[1]; - ((byte[])obj)[0] = (byte)pixel; - return obj; - case DataBuffer.TYPE_USHORT: - if (obj == null) obj = new short[1]; - ((short[])obj)[0] = (short)pixel; - return obj; - case DataBuffer.TYPE_INT: - if (obj == null) obj = new int[1]; - ((int[])obj)[0] = pixel; - return obj; - default: - // Seems like the only sensible thing to do. - throw new ClassCastException(); - } - } - - public int[] getPixel(int x, int y, int[] iArray, DataBuffer data) - { - if (iArray == null) iArray = new int[1]; - iArray[0] = getSample(x, y, 0, data); - - return iArray; - } - - public int[] getPixels(int x, int y, int w, int h, int[] iArray, - DataBuffer data) - { - int offset = getOffset(x, y); - if (iArray == null) iArray = new int[w*h]; - int outOffset = 0; - for (y=0; y<h; y++) - { - int lineOffset = offset; - for (x=0; x<w;) - { - int samples = data.getElem(lineOffset++); - for (int b=0; b<numElems && x<w; b++) - { - iArray[outOffset++] = (samples & bitMasks[b]) >>> bitOffsets[b]; - x++; - } - } - offset += scanlineStride; - } - return iArray; - } - - public int getSample(int x, int y, int b, DataBuffer data) - { - int pos = - ((dataBitOffset + x * numberOfBits) % elemBits) / numberOfBits; - int offset = getOffset(x, y); - int samples = data.getElem(offset); - return (samples & bitMasks[pos]) >>> bitOffsets[pos]; - } - - /** - * Set the pixel at x, y to the value in the first element of the primitive - * array obj. - * - * @param x The x-coordinate of the data elements in <code>obj</code>. - * @param y The y-coordinate of the data elements in <code>obj</code>. - * @param obj The primitive array containing the data elements to set. - * @param data The DataBuffer to store the data elements into. - * @see java.awt.image.SampleModel#setDataElements(int, int, int, int, java.lang.Object, java.awt.image.DataBuffer) - */ - public void setDataElements(int x, int y, Object obj, DataBuffer data) - { - int transferType = getTransferType(); - if (getTransferType() != data.getDataType()) - { - throw new IllegalArgumentException("transfer type ("+ - getTransferType()+"), "+ - "does not match data "+ - "buffer type (" + - data.getDataType() + - ")."); - } - - int offset = getOffset(x, y); - - try - { - switch (transferType) - { - case DataBuffer.TYPE_BYTE: - { - DataBufferByte out = (DataBufferByte) data; - byte[] in = (byte[]) obj; - out.getData()[offset] = in[0]; - return; - } - case DataBuffer.TYPE_USHORT: - { - DataBufferUShort out = (DataBufferUShort) data; - short[] in = (short[]) obj; - out.getData()[offset] = in[0]; - return; - } - case DataBuffer.TYPE_INT: - { - DataBufferInt out = (DataBufferInt) data; - int[] in = (int[]) obj; - out.getData()[offset] = in[0]; - return; - } - default: - throw new ClassCastException("Unsupported data type"); - } - } - catch (ArrayIndexOutOfBoundsException aioobe) - { - String msg = "While writing data elements" + - ", x="+x+", y="+y+ - ", width="+width+", height="+height+ - ", scanlineStride="+scanlineStride+ - ", offset="+offset+ - ", data.getSize()="+data.getSize()+ - ", data.getOffset()="+data.getOffset()+ - ": " + - aioobe; - throw new ArrayIndexOutOfBoundsException(msg); - } - } - - public void setPixel(int x, int y, int[] iArray, DataBuffer data) - { - setSample(x, y, 0, iArray[0], data); - } - - public void setSample(int x, int y, int b, int s, DataBuffer data) - { - int bitpos = - ((dataBitOffset + x * numberOfBits) % elemBits) / numberOfBits; - int offset = getOffset(x, y); - - s = s << bitOffsets[bitpos]; - s = s & bitMasks[bitpos]; - - int sample = data.getElem(offset); - sample |= s; - data.setElem(offset, sample); - } - - /** - * Creates a String with some information about this SampleModel. - * @return A String describing this SampleModel. - * @see java.lang.Object#toString() - */ - public String toString() - { - StringBuffer result = new StringBuffer(); - result.append(getClass().getName()); - result.append("["); - result.append("scanlineStride=").append(scanlineStride); - for(int i=0; i < bitMasks.length; i+=1) - { - result.append(", mask[").append(i).append("]=0x").append(Integer.toHexString(bitMasks[i])); - } - - result.append("]"); - return result.toString(); - } -} diff --git a/libjava/java/awt/image/PackedColorModel.java b/libjava/java/awt/image/PackedColorModel.java deleted file mode 100644 index 894e6e66fda..00000000000 --- a/libjava/java/awt/image/PackedColorModel.java +++ /dev/null @@ -1,192 +0,0 @@ -/* Copyright (C) 2000, 2002, 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.image; - -import gnu.java.awt.BitMaskExtent; - -import java.awt.Point; -import java.awt.color.ColorSpace; - -/** - * @author Rolf W. Rasmussen (rolfwr@ii.uib.no) - */ -public abstract class PackedColorModel extends ColorModel -{ - private int masks[]; - - /* Package accessibility, the DirectColorModel needs this array */ - int shifts[]; - - public PackedColorModel(ColorSpace cspace, int pixelBits, - int[] colorMaskArray, int alphaMask, - boolean isAlphaPremultiplied, - int transparency, - int transferType) - { - super(pixelBits, calcBitsPerComponent(colorMaskArray, alphaMask), - cspace, (alphaMask != 0), isAlphaPremultiplied, transparency, - transferType); - initMasks(colorMaskArray, alphaMask); - if ((pixelBits<1) || (pixelBits>32)) { - throw new IllegalArgumentException("pixels per bits must be " + - "in the range [1, 32]"); - } - } - - private static int[] calcBitsPerComponent(int[] colorMaskArray, - int alphaMask) - { - int numComponents = colorMaskArray.length; - if (alphaMask != 0) numComponents++; - - int[] bitsPerComponent = new int[numComponents]; - - BitMaskExtent extent = new BitMaskExtent(); - for (int b=0; b<colorMaskArray.length; b++) - { - extent.setMask(colorMaskArray[b]); - bitsPerComponent[b] = extent.bitWidth; - } - if (alphaMask != 0) - { - extent.setMask(alphaMask); - bitsPerComponent[numComponents-1] = extent.bitWidth; - } - return bitsPerComponent; - } - - /** Initializes the masks. - * - * @return an array containing the number of bits per color - * component. - */ - private void initMasks(int[] colorMaskArray, int alphaMask) - { - int numComponents = colorMaskArray.length; - if (alphaMask == 0) - { - masks = colorMaskArray; - } - else - { - masks = new int[numComponents+1]; - System.arraycopy(colorMaskArray, 0, - masks, 0, - numComponents); - masks[numComponents++] = alphaMask; - } - - shifts = new int[numComponents]; - - // Bit field handling have been moved to a utility class - BitMaskExtent extent = new BitMaskExtent(); - for (int b=0; b<numComponents; b++) - { - extent.setMask(masks[b]); - shifts[b] = extent.leastSignificantBit; - } - } - - public PackedColorModel(ColorSpace cspace, int pixelBits, - int rmask, int gmask, int bmask, - int amask, boolean isAlphaPremultiplied, - int transparency, - int transferType) - { - this(cspace, pixelBits, makeColorMaskArray(rmask, gmask, bmask), - amask, isAlphaPremultiplied, transparency, transferType); - } - - /* TODO: If there is a alpha mask, it is inefficient to create a - color mask array that will be discarded when the alpha mask is - appended. We should probably create a private constructor that - takes a complete array of masks (color+alpha) as an - argument. */ - - private static int[] makeColorMaskArray(int rmask, int gmask, int bmask) - { - int[] colorMaskArray = { rmask, gmask, bmask }; - return colorMaskArray; - } - - public final int getMask(int index) - { - return masks[index]; - } - - public final int[] getMasks() - { - return masks; - } - - public SampleModel createCompatibleSampleModel(int w, int h) - { - return new SinglePixelPackedSampleModel(transferType, w, h, masks); - } - - public boolean isCompatibleSampleModel(SampleModel sm) - { - if (!super.isCompatibleSampleModel(sm)) return false; - if (!(sm instanceof SinglePixelPackedSampleModel)) return false; - - SinglePixelPackedSampleModel sppsm = - (SinglePixelPackedSampleModel) sm; - return java.util.Arrays.equals(sppsm.getBitMasks(), masks); - } - - public WritableRaster getAlphaRaster(WritableRaster raster) { - if (!hasAlpha()) return null; - - SampleModel sm = raster.getSampleModel(); - int[] alphaBand = { sm.getNumBands() - 1 }; - SampleModel alphaModel = sm.createSubsetSampleModel(alphaBand); - DataBuffer buffer = raster.getDataBuffer(); - Point origin = new Point(0, 0); - return Raster.createWritableRaster(alphaModel, buffer, origin); - } - - public boolean equals(Object obj) - { - if (!super.equals(obj)) return false; - if (!(obj instanceof PackedColorModel)) return false; - - PackedColorModel other = (PackedColorModel) obj; - - return java.util.Arrays.equals(masks, other.masks); - } -} diff --git a/libjava/java/awt/image/PixelGrabber.java b/libjava/java/awt/image/PixelGrabber.java deleted file mode 100644 index 3e3ecf81e19..00000000000 --- a/libjava/java/awt/image/PixelGrabber.java +++ /dev/null @@ -1,624 +0,0 @@ -/* PixelGrabber.java -- retrieve a subset of an image's data - Copyright (C) 1999, 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.image; - -import java.awt.Image; -import java.util.Hashtable; - -/** - * PixelGrabber is an ImageConsumer that extracts a rectangular region - * of pixels from an Image. - */ -public class PixelGrabber implements ImageConsumer -{ - int x, y, offset; - int width = -1; - int height = -1; - int scansize = -1; - boolean forceRGB = true; - - ColorModel model = ColorModel.getRGBdefault(); - int hints; - Hashtable props; - - int int_pixel_buffer[]; - boolean ints_delivered = false; - byte byte_pixel_buffer[]; - boolean bytes_delivered = false; - - ImageProducer ip; - int observerStatus; - int consumerStatus; - - private Thread grabberThread; - boolean grabbing = false; - - /** - * Construct a PixelGrabber that will retrieve RGB data from a given - * Image. - * - * The RGB data will be retrieved from a rectangular region - * <code>(x, y, w, h)</code> within the image. The data will be - * stored in the provided <code>pix</code> array, which must have - * been initialized to a size of at least <code>w * h</code>. The - * data for a pixel (m, n) in the grab rectangle will be stored at - * <code>pix[(n - y) * scansize + (m - x) + off]</code>. - * - * @param img the Image from which to grab pixels - * @param x the x coordinate, relative to <code>img</code>'s - * top-left corner, of the grab rectangle's top-left pixel - * @param y the y coordinate, relative to <code>img</code>'s - * top-left corner, of the grab rectangle's top-left pixel - * @param w the width of the grab rectangle, in pixels - * @param h the height of the grab rectangle, in pixels - * @param pix the array in which to store grabbed RGB pixel data - * @param off the offset into the <code>pix</code> array at which to - * start storing RGB data - * @param scansize a set of <code>scansize</code> consecutive - * elements in the <code>pix</code> array represents one row of - * pixels in the grab rectangle - */ - public PixelGrabber(Image img, int x, int y, int w, int h, - int pix[], int off, int scansize) - { - this (img.getSource(), x, y, w, h, pix, off, scansize); - } - - /** - * Construct a PixelGrabber that will retrieve RGB data from a given - * ImageProducer. - * - * The RGB data will be retrieved from a rectangular region - * <code>(x, y, w, h)</code> within the image produced by - * <code>ip</code>. The data will be stored in the provided - * <code>pix</code> array, which must have been initialized to a - * size of at least <code>w * h</code>. The data for a pixel (m, n) - * in the grab rectangle will be stored at - * <code>pix[(n - y) * scansize + (m - x) + off]</code>. - * - * @param ip the ImageProducer from which to grab pixels - * @param x the x coordinate of the grab rectangle's top-left pixel, - * specified relative to the top-left corner of the image produced - * by <code>ip</code> - * @param y the y coordinate of the grab rectangle's top-left pixel, - * specified relative to the top-left corner of the image produced - * by <code>ip</code> - * @param w the width of the grab rectangle, in pixels - * @param h the height of the grab rectangle, in pixels - * @param pix the array in which to store grabbed RGB pixel data - * @param off the offset into the <code>pix</code> array at which to - * start storing RGB data - * @param scansize a set of <code>scansize</code> consecutive - * elements in the <code>pix</code> array represents one row of - * pixels in the grab rectangle - */ - public PixelGrabber(ImageProducer ip, int x, int y, int w, int h, - int pix[], int off, int scansize) - { - this.ip = ip; - this.x = x; - this.y = y; - this.width = w; - this.height = h; - this.offset = off; - this.scansize = scansize; - - int_pixel_buffer = pix; - // Initialize the byte array in case ip sends us byte-formatted - // pixel data. - byte_pixel_buffer = new byte[pix.length * 4]; - } - - /** - * Construct a PixelGrabber that will retrieve data from a given - * Image. - * - * The RGB data will be retrieved from a rectangular region - * <code>(x, y, w, h)</code> within the image. The data will be - * stored in an internal array which can be accessed by calling - * <code>getPixels</code>. The data for a pixel (m, n) in the grab - * rectangle will be stored in the returned array at index - * <code>(n - y) * scansize + (m - x) + off</code>. - * If forceRGB is false, then the returned data will be not be - * converted to RGB from its format in <code>img</code>. - * - * If <code>w</code> is negative, the width of the grab region will - * be from x to the right edge of the image. Likewise, if - * <code>h</code> is negative, the height of the grab region will be - * from y to the bottom edge of the image. - * - * @param img the Image from which to grab pixels - * @param x the x coordinate, relative to <code>img</code>'s - * top-left corner, of the grab rectangle's top-left pixel - * @param y the y coordinate, relative to <code>img</code>'s - * top-left corner, of the grab rectangle's top-left pixel - * @param w the width of the grab rectangle, in pixels - * @param h the height of the grab rectangle, in pixels - * @param forceRGB true to force conversion of the rectangular - * region's pixel data to RGB - */ - public PixelGrabber(Image img, - int x, int y, - int w, int h, - boolean forceRGB) - { - this.ip = img.getSource(); - this.x = x; - this.y = y; - width = w; - height = h; - // If width or height is negative, postpone pixel buffer - // initialization until setDimensions is called back by ip. - if (width >= 0 && height >= 0) - { - int_pixel_buffer = new int[width * height]; - byte_pixel_buffer = new byte[width * height]; - } - this.forceRGB = forceRGB; - } - - /** - * Start grabbing pixels. - * - * Spawns an image production thread that calls back to this - * PixelGrabber's ImageConsumer methods. - */ - public synchronized void startGrabbing() - { - // Make sure we're not already grabbing. - if (grabbing == false) - { - grabbing = true; - grabberThread = new Thread () - { - public void run () - { - ip.startProduction (PixelGrabber.this); - } - }; - grabberThread.start (); - } - } - - /** - * Abort pixel grabbing. - */ - public synchronized void abortGrabbing() - { - if (grabbing) - { - // Interrupt the grabbing thread. - Thread moribund = grabberThread; - grabberThread = null; - moribund.interrupt(); - - imageComplete (ImageConsumer.IMAGEABORTED); - } - } - - /** - * Have our Image or ImageProducer start sending us pixels via our - * ImageConsumer methods and wait for all pixels in the grab - * rectangle to be delivered. - * - * @return true if successful, false on abort or error - * - * @throws InterruptedException if interrupted by another thread. - */ - public synchronized boolean grabPixels() throws InterruptedException - { - return grabPixels(0); - } - - /** - * grabPixels's behavior depends on the value of <code>ms</code>. - * - * If ms < 0, return true if all pixels from the source image have - * been delivered, false otherwise. Do not wait. - * - * If ms >= 0 then we request that our Image or ImageProducer start - * delivering pixels to us via our ImageConsumer methods. - * - * If ms > 0, wait at most <code>ms</code> milliseconds for - * delivery of all pixels within the grab rectangle. - * - * If ms == 0, wait until all pixels have been delivered. - * - * @return true if all pixels from the source image have been - * delivered, false otherwise - * - * @throws InterruptedException if this thread is interrupted while - * we are waiting for pixels to be delivered - */ - public synchronized boolean grabPixels(long ms) throws InterruptedException - { - if (ms < 0) - return ((observerStatus & (ImageObserver.FRAMEBITS - | ImageObserver.ALLBITS)) != 0); - - // Spawn a new ImageProducer thread to send us the image data via - // our ImageConsumer methods. - startGrabbing(); - - if (ms > 0) - { - long stop_time = System.currentTimeMillis() + ms; - long time_remaining; - while (grabbing) - { - time_remaining = stop_time - System.currentTimeMillis(); - if (time_remaining <= 0) - break; - wait (time_remaining); - } - abortGrabbing (); - } - else - wait (); - - // If consumerStatus is non-zero then the image is done loading or - // an error has occurred. - if (consumerStatus != 0) - return setObserverStatus (); - - return ((observerStatus & (ImageObserver.FRAMEBITS - | ImageObserver.ALLBITS)) != 0); - } - - // Set observer status flags based on the current consumer status - // flags. Return true if the consumer flags indicate that the - // image was loaded successfully, or false otherwise. - private synchronized boolean setObserverStatus () - { - boolean retval = false; - - if ((consumerStatus & IMAGEERROR) != 0) - observerStatus |= ImageObserver.ERROR; - - if ((consumerStatus & IMAGEABORTED) != 0) - observerStatus |= ImageObserver.ABORT; - - if ((consumerStatus & STATICIMAGEDONE) != 0) - { - observerStatus |= ImageObserver.ALLBITS; - retval = true; - } - - if ((consumerStatus & SINGLEFRAMEDONE) != 0) - { - observerStatus |= ImageObserver.FRAMEBITS; - retval = true; - } - - return retval; - } - - /** - * @return the status of the pixel grabbing thread, represented by a - * bitwise OR of ImageObserver flags - */ - public synchronized int getStatus() - { - return observerStatus; - } - - /** - * @return the width of the grab rectangle in pixels, or a negative - * number if the ImageProducer has not yet called our setDimensions - * method - */ - public synchronized int getWidth() - { - return width; - } - - /** - * @return the height of the grab rectangle in pixels, or a negative - * number if the ImageProducer has not yet called our setDimensions - * method - */ - public synchronized int getHeight() - { - return height; - } - - /** - * @return a byte array of pixel data if ImageProducer delivered - * pixel data using the byte[] variant of setPixels, or an int array - * otherwise - */ - public synchronized Object getPixels() - { - if (ints_delivered) - return int_pixel_buffer; - else if (bytes_delivered) - return byte_pixel_buffer; - else - return null; - } - - /** - * @return the ColorModel currently being used for the majority of - * pixel data conversions - */ - public synchronized ColorModel getColorModel() - { - return model; - } - - /** - * Our <code>ImageProducer</code> calls this method to indicate the - * size of the image being produced. - * - * setDimensions is an ImageConsumer method. None of PixelGrabber's - * ImageConsumer methods should be called by code that instantiates - * a PixelGrabber. They are only made public so they can be called - * by the PixelGrabber's ImageProducer. - * - * @param width the width of the image - * @param height the height of the image - */ - public synchronized void setDimensions(int width, int height) - { - // Our width wasn't set when we were constructed. Set our width - // so that the grab region includes all pixels from x to the right - // edge of the source image. - if (this.width < 0) - this.width = width - x; - - // Our height wasn't set when we were constructed. Set our height - // so that the grab region includes all pixels from y to the - // bottom edge of the source image. - if (this.height < 0) - this.height = height - y; - - if (scansize < 0) - scansize = this.width; - - if (int_pixel_buffer == null) - int_pixel_buffer = new int[this.width * this.height]; - - if (byte_pixel_buffer == null) - byte_pixel_buffer = new byte[this.width * this.height]; - } - - /** - * Our <code>ImageProducer</code> may call this method to send us a - * list of its image's properties. - * - * setProperties is an ImageConsumer method. None of PixelGrabber's - * ImageConsumer methods should be called by code that instantiates - * a PixelGrabber. They are only made public so they can be called - * by the PixelGrabber's ImageProducer. - * - * @param props a list of properties associated with the image being - * produced - */ - public synchronized void setProperties(Hashtable props) - { - this.props = props; - } - - /** - * Our ImageProducer will call <code>setColorModel</code> to - * indicate the model used by the majority of calls to - * <code>setPixels</code>. Each call to <code>setPixels</code> - * could however indicate a different <code>ColorModel</code>. - * - * setColorModel is an ImageConsumer method. None of PixelGrabber's - * ImageConsumer methods should be called by code that instantiates - * a PixelGrabber. They are only made public so they can be called - * by the PixelGrabber's ImageProducer. - * - * @param model the color model to be used most often by setPixels - * - * @see ColorModel - */ - public synchronized void setColorModel(ColorModel model) - { - this.model = model; - } - - /** - * Our <code>ImageProducer</code> may call this method with a - * bit mask of hints from any of <code>RANDOMPIXELORDER</code>, - * <code>TOPDOWNLEFTRIGHT</code>, <code>COMPLETESCANLINES</code>, - * <code>SINGLEPASS</code>, <code>SINGLEFRAME</code>. - * - * setHints is an ImageConsumer method. None of PixelGrabber's - * ImageConsumer methods should be called by code that instantiates - * a PixelGrabber. They are only made public so they can be called - * by the PixelGrabber's ImageProducer. - * - * @param flags a bit mask of hints - */ - public synchronized void setHints(int flags) - { - hints = flags; - } - - /** - * Our ImageProducer calls setPixels to deliver a subset of its - * pixels. - * - * Each element of the pixels array represents one pixel. The - * pixel data is formatted according to the color model model. - * The x and y parameters are the coordinates of the rectangular - * region of pixels being delivered to this ImageConsumer, - * specified relative to the top left corner of the image being - * produced. Likewise, w and h are the pixel region's dimensions. - * - * @param x x coordinate of pixel block - * @param y y coordinate of pixel block - * @param w width of pixel block - * @param h height of pixel block - * @param model color model used to interpret pixel data - * @param pixels pixel block data - * @param offset offset into pixels array - * @param scansize width of one row in the pixel block - */ - public synchronized void setPixels(int x, int y, int w, int h, - ColorModel model, byte[] pixels, - int offset, int scansize) - { - ColorModel currentModel; - if (model != null) - currentModel = model; - else - currentModel = this.model; - - for(int yp = y; yp < (y + h); yp++) - { - for(int xp = x; xp < (x + w); xp++) - { - // Check if the coordinates (xp, yp) are within the - // pixel block that we are grabbing. - if(xp >= this.x - && yp >= this.y - && xp < (this.x + this.width) - && yp < (this.y + this.height)) - { - int i = (yp - this.y) * this.scansize + (xp - this.x) + this.offset; - int p = (yp - y) * scansize + (xp - x) + offset; - if (forceRGB) - { - ints_delivered = true; - - assert (i >= 0 && i < int_pixel_buffer.length); - assert (p >= 0 && p < pixels.length); - int_pixel_buffer[i] = currentModel.getRGB (pixels[p] & 0xFF); - } - else - { - bytes_delivered = true; - - assert (i >= 0 && i < byte_pixel_buffer.length); - assert (p >= 0 && p < pixels.length); - byte_pixel_buffer[i] = pixels[p]; - } - } - } - } - } - - /** - * Our ImageProducer calls setPixels to deliver a subset of its - * pixels. - * - * Each element of the pixels array represents one pixel. The - * pixel data is formatted according to the color model model. - * The x and y parameters are the coordinates of the rectangular - * region of pixels being delivered to this ImageConsumer, - * specified relative to the top left corner of the image being - * produced. Likewise, w and h are the pixel region's dimensions. - * - * @param x x coordinate of pixel block - * @param y y coordinate of pixel block - * @param w width of pixel block - * @param h height of pixel block - * @param model color model used to interpret pixel data - * @param pixels pixel block data - * @param offset offset into pixels array - * @param scansize width of one row in the pixel block - */ - public synchronized void setPixels(int x, int y, int w, int h, - ColorModel model, int[] pixels, - int offset, int scansize) - { - ColorModel currentModel; - if (model != null) - currentModel = model; - else - currentModel = this.model; - - ints_delivered = true; - - for(int yp = y; yp < (y + h); yp++) - { - for(int xp = x; xp < (x + w); xp++) - { - // Check if the coordinates (xp, yp) are within the - // pixel block that we are grabbing. - if(xp >= this.x - && yp >= this.y - && xp < (this.x + this.width) - && yp < (this.y + this.height)) - { - int i = (yp - this.y) * this.scansize + (xp - this.x) + this.offset; - int p = (yp - y) * scansize + (xp - x) + offset; - assert (i >= 0 && i < int_pixel_buffer.length); - assert (p >= 0 && p < pixels.length); - if (forceRGB) - int_pixel_buffer[i] = currentModel.getRGB (pixels[p]); - else - int_pixel_buffer[i] = pixels[p]; - } - } - } - } - - /** - * Our <code>ImageProducer</code> calls this method to inform us - * that a single frame or the entire image is complete. The method - * is also used to inform us of an error in loading or producing the - * image. - * - * @param status the status of image production, represented by a - * bitwise OR of ImageConsumer flags - */ - public synchronized void imageComplete(int status) - { - consumerStatus = status; - setObserverStatus (); - grabbing = false; - ip.removeConsumer (this); - - notifyAll (); - } - - /** - * @return the return value of getStatus - * - * @specnote The newer getStatus should be used in place of status. - */ - public synchronized int status() - { - return getStatus(); - } -} diff --git a/libjava/java/awt/image/PixelInterleavedSampleModel.java b/libjava/java/awt/image/PixelInterleavedSampleModel.java deleted file mode 100644 index 4c5c436edfc..00000000000 --- a/libjava/java/awt/image/PixelInterleavedSampleModel.java +++ /dev/null @@ -1,98 +0,0 @@ -/* PixelInterleavedSampleModel.java - Copyright (C) 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.awt.image; - - -/** - * A <code>SampleModel</code> that uses exactly one element of the - * raster’s {@link DataBuffer} per pixel, holds all bands in a - * single bank, and stores band data in pixel-interleaved manner. - * - * @since 1.2 - * - * @author Sascha Brawer (brawer@dandelis.ch) - */ -public class PixelInterleavedSampleModel - extends ComponentSampleModel -{ - public PixelInterleavedSampleModel(int dataType, int width, int height, - int pixelStride, int scanlineStride, - int[] bandOffsets) - { - super(dataType, width, height, pixelStride, scanlineStride, - bandOffsets); - } - - - /** - * Creates a new <code>SampleModel</code> that is like this one, but - * uses the specified width and height. - * - * @param width the number of pixels in the horizontal direction. - * - * @param height the number of pixels in the vertical direction. - */ - public SampleModel createCompatibleSampleModel(int width, int height) - { - return new PixelInterleavedSampleModel(dataType, width, height, - pixelStride, scanlineStride, - bandOffsets); - } - - - /** - * Creates a new <code>SampleModel</code> that is like this one, but - * uses only a subset of its bands. - * - * @param bands an array whose elements indicate which bands shall - * be part of the subset. For example, <code>[0, 2, 3]</code> would - * create a SampleModel containing bands #0, #2 and #3. - */ - public SampleModel createSubsetSampleModel(int[] bands) - { - int[] subOffsets; - - subOffsets = new int[bands.length]; - for (int i = 0; i < bands.length; i++) - subOffsets[i] = bandOffsets[bands[i]]; - - return new PixelInterleavedSampleModel(dataType, width, height, - pixelStride, scanlineStride, - subOffsets); - } -} diff --git a/libjava/java/awt/image/RGBImageFilter.java b/libjava/java/awt/image/RGBImageFilter.java deleted file mode 100644 index f55ebd1f99e..00000000000 --- a/libjava/java/awt/image/RGBImageFilter.java +++ /dev/null @@ -1,265 +0,0 @@ -/* RGBImageFilter.java -- Java class for filtering Pixels by RGB values - Copyright (C) 1999, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.image; - -/** - * A filter designed to filter images in the default RGBColorModel regardless of - * the ImageProducer's ColorModel. - * - * @author Mark Benvenuto (mcb54@columbia.edu) - */ -public abstract class RGBImageFilter extends ImageFilter -{ - protected ColorModel origmodel; - - protected ColorModel newmodel; - - /** - Specifies whether to apply the filter to the index entries of the - IndexColorModel. Subclasses should set this to true if the filter - does not depend on the pixel's coordinate. - */ - protected boolean canFilterIndexColorModel = false; - - /** - Construct new RGBImageFilter. - */ - public RGBImageFilter() - { - } - - /** - * Sets the ColorModel used to filter with. If the specified ColorModel is IndexColorModel - * and canFilterIndexColorModel is true, we subsitute the ColorModel for a filtered one - * here and in setPixels whenever the original one appears. Otherwise overrides the default - * ColorModel of ImageProducer and specifies the default RGBColorModel - * - * @param model the color model to be used most often by setPixels - * @see ColorModel */ - public void setColorModel(ColorModel model) - { - origmodel = model; - newmodel = model; - - if( ( model instanceof IndexColorModel) && canFilterIndexColorModel ) { - newmodel = filterIndexColorModel( (IndexColorModel) model ); - consumer.setColorModel(newmodel); - } - else { - consumer.setColorModel(ColorModel.getRGBdefault()); - } - } - - /** - Registers a new ColorModel to subsitute for the old ColorModel when - setPixels encounters the a pixel with the old ColorModel. The pixel - remains unchanged except for a new ColorModel. - - @param oldcm the old ColorModel - @param newcm the new ColorModel - */ - public void substituteColorModel(ColorModel oldcm, - ColorModel newcm) - { - origmodel = oldcm; - newmodel = newcm; - } - - /** - Filters an IndexColorModel through the filterRGB function. Uses - coordinates of -1 to indicate its filtering an index and not a pixel. - - @param icm an IndexColorModel to filter - */ - public IndexColorModel filterIndexColorModel(IndexColorModel icm) - { - int len = icm.getMapSize(), rgb; - byte reds[] = new byte[len], greens[] = new byte[len], blues[] = new byte[len], alphas[] = new byte[len]; - - icm.getAlphas( alphas ); - icm.getReds( reds ); - icm.getGreens( greens ); - icm.getBlues( blues ); - - for( int i = 0; i < len; i++ ) - { - rgb = filterRGB( -1, -1, makeColor ( alphas[i], reds[i], greens[i], blues[i] ) ); - alphas[i] = (byte)(( 0xff000000 & rgb ) >> 24); - reds[i] = (byte)(( 0xff0000 & rgb ) >> 16); - greens[i] = (byte)(( 0xff00 & rgb ) >> 8); - blues[i] = (byte)(0xff & rgb); - } - return new IndexColorModel( icm.getPixelSize(), len, reds, greens, blues, alphas ); - } - - private int makeColor( byte a, byte r, byte g, byte b ) - { - return ( 0xff000000 & (a << 24) | 0xff0000 & (r << 16) | 0xff00 & (g << 8) | 0xff & b ); - } - - /** - This functions filters a set of RGB pixels through filterRGB. - - @param x the x coordinate of the rectangle - @param y the y coordinate of the rectangle - @param w the width of the rectangle - @param h the height of the rectangle - @param pixels the array of pixel values - @param offset the index of the first pixels in the <code>pixels</code> array - @param scansize the width to use in extracting pixels from the <code>pixels</code> array - */ - public void filterRGBPixels(int x, int y, int w, int h, int[] pixels, - int offset, int scansize) - { - for (int xp = x; xp < (x + w); xp++) - for (int yp = y; yp < (y + h); yp++) - { - pixels[offset] = filterRGB(xp, yp, pixels[offset]); - offset++; - } - } - - - /** - * If the ColorModel is the same ColorModel which as already converted - * then it converts it the converted ColorModel. Otherwise it passes the - * array of pixels through filterRGBpixels. - * - * @param x the x coordinate of the rectangle - * @param y the y coordinate of the rectangle - * @param w the width of the rectangle - * @param h the height of the rectangle - * @param model the <code>ColorModel</code> used to translate the pixels - * @param pixels the array of pixel values - * @param offset the index of the first pixels in the <code>pixels</code> array - * @param scansize the width to use in extracting pixels from the <code>pixels</code> array - */ - public void setPixels(int x, int y, int w, int h, - ColorModel model, byte[] pixels, - int offset, int scansize) - { - if(model == origmodel && (model instanceof IndexColorModel) && canFilterIndexColorModel) - { - consumer.setPixels(x, y, w, h, newmodel, pixels, offset, scansize); - } - else - { - int intPixels[] = - convertColorModelToDefault( x, y, w, h, model, pixels, offset, scansize ); - filterRGBPixels( x, y, w, h, intPixels, offset, scansize ); - consumer.setPixels(x, y, w, h, ColorModel.getRGBdefault(), intPixels, offset, scansize); - } - } - - /** - * This function delivers a rectangle of pixels where any - * pixel(m,n) is stored in the array as an <code>int</code> at - * index (n * scansize + m + offset). - * - * @param x the x coordinate of the rectangle - * @param y the y coordinate of the rectangle - * @param w the width of the rectangle - * @param h the height of the rectangle - * @param model the <code>ColorModel</code> used to translate the pixels - * @param pixels the array of pixel values - * @param offset the index of the first pixels in the <code>pixels</code> array - * @param scansize the width to use in extracting pixels from the <code>pixels</code> array - */ - public void setPixels(int x, int y, int w, int h, - ColorModel model, int[] pixels, - int offset, int scansize) - { - if(model == origmodel && (model instanceof IndexColorModel) && canFilterIndexColorModel) - { - consumer.setPixels(x, y, w, h, newmodel, pixels, offset, scansize); - } - else - { - //FIXME: Store the filtered pixels in a separate temporary buffer? - convertColorModelToDefault( x, y, w, h, model, pixels, offset, scansize ); - filterRGBPixels( x, y, w, h, pixels, offset, scansize ); - consumer.setPixels(x, y, w, h, ColorModel.getRGBdefault(), pixels, offset, scansize); - } - } - - private int[] convertColorModelToDefault(int x, int y, int w, int h, - ColorModel model, byte pixels[], - int offset, int scansize) - { - int intPixels[] = new int[pixels.length]; - for (int i = 0; i < pixels.length; i++) - intPixels[i] = makeColorbyDefaultCM(model, pixels[i]); - return intPixels; - } - - private void convertColorModelToDefault(int x, int y, int w, int h, - ColorModel model, int pixels[], - int offset, int scansize) - { - for (int i = 0; i < pixels.length; i++) - pixels[i] = makeColorbyDefaultCM(model, pixels[i]); - } - - private int makeColorbyDefaultCM(ColorModel model, byte rgb) - { - return makeColor( model.getAlpha( rgb ) * 4, model.getRed( rgb ) * 4, model.getGreen( rgb ) * 4, model.getBlue( rgb ) * 4 ); - } - - private int makeColorbyDefaultCM(ColorModel model, int rgb) - { - return makeColor( model.getAlpha( rgb ), model.getRed( rgb ), model.getGreen( rgb ), model.getBlue( rgb ) ); - } - - private int makeColor( int a, int r, int g, int b ) - { - return (int)( 0xff000000 & (a << 24) | 0xff0000 & (r << 16) | 0xff00 & (g << 8) | 0xff & b ); - } - - - /** - Filters a single pixel from the default ColorModel. - - @param x x-coordinate - @param y y-coordinate - @param rgb color - */ - public abstract int filterRGB(int x, - int y, - int rgb); -} diff --git a/libjava/java/awt/image/Raster.java b/libjava/java/awt/image/Raster.java deleted file mode 100644 index 4af958a17c7..00000000000 --- a/libjava/java/awt/image/Raster.java +++ /dev/null @@ -1,546 +0,0 @@ -/* Copyright (C) 2000, 2002, 2003 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.image; - -import java.awt.Point; -import java.awt.Rectangle; - -/** - * @author Rolf W. Rasmussen (rolfwr@ii.uib.no) - */ -public class Raster -{ - protected SampleModel sampleModel; - protected DataBuffer dataBuffer; - protected int minX; - protected int minY; - protected int width; - protected int height; - protected int sampleModelTranslateX; - protected int sampleModelTranslateY; - protected int numBands; - protected int numDataElements; - protected Raster parent; - - protected Raster(SampleModel sampleModel, Point origin) - { - this(sampleModel, sampleModel.createDataBuffer(), origin); - } - - protected Raster(SampleModel sampleModel, DataBuffer dataBuffer, - Point origin) - { - this(sampleModel, dataBuffer, - new Rectangle(origin.x, origin.y, - sampleModel.getWidth(), sampleModel.getHeight()), - origin, null); - } - - protected Raster(SampleModel sampleModel, DataBuffer dataBuffer, - Rectangle aRegion, - Point sampleModelTranslate, Raster parent) - { - this.sampleModel = sampleModel; - this.dataBuffer = dataBuffer; - this.minX = aRegion.x; - this.minY = aRegion.y; - this.width = aRegion.width; - this.height = aRegion.height; - - // If sampleModelTranslate is null, use (0,0). Methods such as - // Raster.createRaster are specified to allow for a null argument. - if (sampleModelTranslate != null) - { - this.sampleModelTranslateX = sampleModelTranslate.x; - this.sampleModelTranslateY = sampleModelTranslate.y; - } - - this.numBands = sampleModel.getNumBands(); - this.numDataElements = sampleModel.getNumDataElements(); - this.parent = parent; - } - - public static WritableRaster createInterleavedRaster(int dataType, - int w, int h, - int bands, - Point location) - { - int[] bandOffsets = new int[bands]; - // TODO: Maybe not generate this every time. - for (int b=0; b<bands; b++) bandOffsets[b] = b; - - int scanlineStride = bands*w; - return createInterleavedRaster(dataType, w, h, scanlineStride, bands, - bandOffsets, location); - } - - public static WritableRaster createInterleavedRaster(int dataType, - int w, int h, - int scanlineStride, - int pixelStride, - int[] bandOffsets, - Point location) - { - SampleModel sm = new ComponentSampleModel(dataType, - w, h, - pixelStride, - scanlineStride, - bandOffsets); - return createWritableRaster(sm, location); - } - - public static WritableRaster createBandedRaster(int dataType, - int w, int h, int bands, - Point location) - { - SampleModel sm = new BandedSampleModel(dataType, w, h, bands); - return createWritableRaster(sm, location); - } - - public static WritableRaster createBandedRaster(int dataType, - int w, int h, - int scanlineStride, - int[] bankIndices, - int[] bandOffsets, - Point location) - { - SampleModel sm = new BandedSampleModel(dataType, w, h, scanlineStride, - bankIndices, bandOffsets); - return createWritableRaster(sm, location); - } - - public static WritableRaster createPackedRaster(int dataType, - int w, int h, - int[] bandMasks, - Point location) - { - SampleModel sm = new SinglePixelPackedSampleModel(dataType, - w, h, - bandMasks); - return createWritableRaster(sm, location); - } - - public static WritableRaster createPackedRaster(int dataType, - int w, int h, - int bands, int bitsPerBand, - Point location) - { - if (bands <= 0 || (bands * bitsPerBand > getTypeBits(dataType))) - throw new IllegalArgumentException(); - - SampleModel sm; - - if (bands == 1) - sm = new MultiPixelPackedSampleModel(dataType, w, h, bitsPerBand); - else - { - int[] bandMasks = new int[bands]; - int mask = 0x1; - for (int bits = bitsPerBand; --bits != 0;) - mask = (mask << 1) | 0x1; - for (int i = 0; i < bands; i++) - { - bandMasks[i] = mask; - mask <<= bitsPerBand; - } - - sm = new SinglePixelPackedSampleModel(dataType, w, h, bandMasks); - } - return createWritableRaster(sm, location); - } - - public static WritableRaster - createInterleavedRaster(DataBuffer dataBuffer, int w, int h, - int scanlineStride, int pixelStride, - int[] bandOffsets, Point location) - { - SampleModel sm = new ComponentSampleModel(dataBuffer.getDataType(), - w, h, - scanlineStride, - pixelStride, - bandOffsets); - return createWritableRaster(sm, dataBuffer, location); - } - - public static - WritableRaster createBandedRaster(DataBuffer dataBuffer, - int w, int h, - int scanlineStride, - int[] bankIndices, - int[] bandOffsets, - Point location) - { - SampleModel sm = new BandedSampleModel(dataBuffer.getDataType(), - w, h, scanlineStride, - bankIndices, bandOffsets); - return createWritableRaster(sm, dataBuffer, location); - } - - public static WritableRaster - createPackedRaster(DataBuffer dataBuffer, - int w, int h, - int scanlineStride, - int[] bandMasks, - Point location) - { - SampleModel sm = - new SinglePixelPackedSampleModel(dataBuffer.getDataType(), - w, h, - scanlineStride, - bandMasks); - return createWritableRaster(sm, dataBuffer, location); - } - - public static WritableRaster - createPackedRaster(DataBuffer dataBuffer, - int w, int h, - int bitsPerPixel, - Point location) - { - SampleModel sm = - new MultiPixelPackedSampleModel(dataBuffer.getDataType(), - w, h, - bitsPerPixel); - return createWritableRaster(sm, dataBuffer, location); - } - - public static Raster createRaster(SampleModel sm, DataBuffer db, - Point location) - { - return new Raster(sm, db, location); - } - - public static WritableRaster createWritableRaster(SampleModel sm, - Point location) - { - return new WritableRaster(sm, location); - } - - public static WritableRaster createWritableRaster(SampleModel sm, - DataBuffer db, - Point location) - { - return new WritableRaster(sm, db, location); - } - - public Raster getParent() - { - return parent; - } - - public final int getSampleModelTranslateX() - { - return sampleModelTranslateX; - } - - public final int getSampleModelTranslateY() - { - return sampleModelTranslateY; - } - - public WritableRaster createCompatibleWritableRaster() - { - return new WritableRaster(getSampleModel(), new Point(minX, minY)); - } - - public WritableRaster createCompatibleWritableRaster(int w, int h) - { - return createCompatibleWritableRaster(minX, minY, w, h); - } - - public WritableRaster createCompatibleWritableRaster(Rectangle rect) - { - return createCompatibleWritableRaster(rect.x, rect.y, - rect.width, rect.height); - } - - public WritableRaster createCompatibleWritableRaster(int x, int y, - int w, int h) - { - SampleModel sm = getSampleModel().createCompatibleSampleModel(w, h); - return new WritableRaster(sm, sm.createDataBuffer(), - new Point(x, y)); - } - - public Raster createTranslatedChild(int childMinX, int childMinY) { - int tcx = sampleModelTranslateX - minX + childMinX; - int tcy = sampleModelTranslateY - minY + childMinY; - - return new Raster(sampleModel, dataBuffer, - new Rectangle(childMinX, childMinY, - width, height), - new Point(tcx, tcy), - this); - } - - public Raster createChild(int parentX, int parentY, int width, - int height, int childMinX, int childMinY, - int[] bandList) - { - /* FIXME: Throw RasterFormatException if child bounds extends - beyond the bounds of this raster. */ - - SampleModel sm = (bandList == null) ? - sampleModel : - sampleModel.createSubsetSampleModel(bandList); - - /* - data origin - / - +------------------------- - |\. __ parent trans - | \`. - | \ `. parent origin - | \ `. / - | /\ +-------- - - - |trans\ /<\-- deltaTrans - |child +-+-\---- - - - | /|`| \__ parent [x, y] - |child | |`. \ - |origin| : `.\ - | | / `\ - | : / + - | child [x, y] - - parent_xy - parent_trans = child_xy - child_trans - - child_trans = parent_trans + child_xy - parent_xy - */ - - return new Raster(sm, dataBuffer, - new Rectangle(childMinX, childMinY, - width, height), - new Point(sampleModelTranslateX+childMinX-parentX, - sampleModelTranslateY+childMinY-parentY), - this); - } - - public Rectangle getBounds() - { - return new Rectangle(minX, minY, width, height); - } - - public final int getMinX() - { - return minX; - } - - public final int getMinY() - { - return minY; - } - - public final int getWidth() - { - return width; - } - - public final int getHeight() - { - return height; - } - - public final int getNumBands() - { - return numBands; - } - - public final int getNumDataElements() - { - return numDataElements; - } - - public final int getTransferType() - { - return sampleModel.getTransferType(); - } - - public DataBuffer getDataBuffer() - { - return dataBuffer; - } - - public SampleModel getSampleModel() - { - return sampleModel; - } - - public Object getDataElements(int x, int y, Object outData) - { - return sampleModel.getDataElements(x-sampleModelTranslateX, - y-sampleModelTranslateY, - outData, dataBuffer); - } - - public Object getDataElements(int x, int y, int w, int h, - Object outData) - { - return sampleModel.getDataElements(x-sampleModelTranslateX, - y-sampleModelTranslateY, - w, h, outData, dataBuffer); - } - - public int[] getPixel(int x, int y, int[] iArray) - { - return sampleModel.getPixel(x-sampleModelTranslateX, - y-sampleModelTranslateY, - iArray, dataBuffer); - } - - public float[] getPixel(int x, int y, float[] fArray) - { - return sampleModel.getPixel(x-sampleModelTranslateX, - y-sampleModelTranslateY, - fArray, dataBuffer); - } - - public double[] getPixel(int x, int y, double[] dArray) - { - return sampleModel.getPixel(x-sampleModelTranslateX, - y-sampleModelTranslateY, - dArray, dataBuffer); - } - - public int[] getPixels(int x, int y, int w, int h, int[] iArray) - { - return sampleModel.getPixels(x-sampleModelTranslateX, - y-sampleModelTranslateY, - w, h, iArray, dataBuffer); - } - - public float[] getPixels(int x, int y, int w, int h, - float[] fArray) - { - return sampleModel.getPixels(x-sampleModelTranslateX, - y-sampleModelTranslateY, - w, h, fArray, dataBuffer); - } - - public double[] getPixels(int x, int y, int w, int h, - double[] dArray) - { - return sampleModel.getPixels(x-sampleModelTranslateX, - y-sampleModelTranslateY, - w, h, dArray, dataBuffer); - } - - public int getSample(int x, int y, int b) - { - return sampleModel.getSample(x-sampleModelTranslateX, - y-sampleModelTranslateY, - b, dataBuffer); - } - - public float getSampleFloat(int x, int y, int b) - { - return sampleModel.getSampleFloat(x-sampleModelTranslateX, - y-sampleModelTranslateY, - b, dataBuffer); - } - - public double getSampleDouble(int x, int y, int b) - { - return sampleModel.getSampleDouble(x-sampleModelTranslateX, - y-sampleModelTranslateY, - b, dataBuffer); - } - - public int[] getSamples(int x, int y, int w, int h, int b, - int[] iArray) - { - return sampleModel.getSamples(x-sampleModelTranslateX, - y-sampleModelTranslateY, - w, h, b, iArray, dataBuffer); - } - - public float[] getSamples(int x, int y, int w, int h, int b, - float[] fArray) - { - return sampleModel.getSamples(x-sampleModelTranslateX, - y-sampleModelTranslateY, - w, h, b, fArray, dataBuffer); - } - - public double[] getSamples(int x, int y, int w, int h, int b, - double[] dArray) - { - return sampleModel.getSamples(x-sampleModelTranslateX, - y-sampleModelTranslateY, - w, h, b, dArray, dataBuffer); - } - - /** - * Create a String representing the stat of this Raster. - * @return A String representing the stat of this Raster. - * @see java.lang.Object#toString() - */ - public String toString() - { - StringBuffer result = new StringBuffer(); - - result.append(getClass().getName()); - result.append("[("); - result.append(minX).append(",").append(minY).append("), "); - result.append(width).append(" x ").append(height).append(","); - result.append(sampleModel).append(","); - result.append(dataBuffer); - result.append("]"); - - return result.toString(); - } - - // Map from datatype to bits - private static int getTypeBits(int dataType) - { - switch (dataType) - { - case DataBuffer.TYPE_BYTE: - return 8; - case DataBuffer.TYPE_USHORT: - case DataBuffer.TYPE_SHORT: - return 16; - case DataBuffer.TYPE_INT: - case DataBuffer.TYPE_FLOAT: - return 32; - case DataBuffer.TYPE_DOUBLE: - return 64; - default: - return 0; - } - } -} diff --git a/libjava/java/awt/image/RasterFormatException.java b/libjava/java/awt/image/RasterFormatException.java deleted file mode 100644 index 582c2ae5ab2..00000000000 --- a/libjava/java/awt/image/RasterFormatException.java +++ /dev/null @@ -1,65 +0,0 @@ -/* RasterFormatException.java -- indicates invalid layout in Raster - Copyright (C) 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.image; - -/** - * This exception is thrown when there is invalid layout information in - * <code>Raster</code> - * - * @author Eric Blake (ebb9@email.byu.edu) - * @see Raster - * @status updated to 1.4 - */ -public class RasterFormatException extends RuntimeException -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = 96598996116164315L; - - /** - * Create a new instance with a descriptive error message. - * - * @param message the descriptive error message - */ - public RasterFormatException(String message) - { - super(message); - } -} // class RasterFormatException diff --git a/libjava/java/awt/image/RasterOp.java b/libjava/java/awt/image/RasterOp.java deleted file mode 100644 index e081ca3d2ad..00000000000 --- a/libjava/java/awt/image/RasterOp.java +++ /dev/null @@ -1,57 +0,0 @@ -/* RasterOp.java -- - Copyright (C) 2000, 2002, 2004, 2005 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.image; - -import java.awt.RenderingHints; -import java.awt.geom.Point2D; -import java.awt.geom.Rectangle2D; - -public interface RasterOp -{ - WritableRaster filter(Raster src, WritableRaster dest); - - Rectangle2D getBounds2D(Raster src); - - WritableRaster createCompatibleDestRaster(Raster src); - - Point2D getPoint2D(Point2D srcPoint, Point2D destPoint); - - RenderingHints getRenderingHints(); -} - diff --git a/libjava/java/awt/image/RenderedImage.java b/libjava/java/awt/image/RenderedImage.java deleted file mode 100644 index b35f8602129..00000000000 --- a/libjava/java/awt/image/RenderedImage.java +++ /dev/null @@ -1,70 +0,0 @@ -/* RenderedImage.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.image; - -import java.awt.Rectangle; -import java.util.Vector; - -/** - * NEEDS DOCUMENTATION - */ -public interface RenderedImage -{ - Vector getSources(); - Object getProperty(String name); - String[] getPropertyNames(); - ColorModel getColorModel(); - SampleModel getSampleModel(); - int getWidth(); - int getHeight(); - int getMinX(); - int getMinY(); - int getNumXTiles(); - int getNumYTiles(); - int getMinTileX(); - int getMinTileY(); - int getTileWidth(); - int getTileHeight(); - int getTileGridXOffset(); - int getTileGridYOffset(); - Raster getTile(int x, int y); - Raster getData(); - Raster getData(Rectangle r); - WritableRaster copyData(WritableRaster raster); -} // interface RenderedImage diff --git a/libjava/java/awt/image/ReplicateScaleFilter.java b/libjava/java/awt/image/ReplicateScaleFilter.java deleted file mode 100644 index 3841e49d538..00000000000 --- a/libjava/java/awt/image/ReplicateScaleFilter.java +++ /dev/null @@ -1,244 +0,0 @@ -/* ReplicateScaleFilter.java -- Java class for filtering images - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.image; - -import java.util.Hashtable; - -/** - * This filter should be used for fast scaling of images where the result - * does not need to ensure straight lines are still straight, etc. The - * exact method is not defined by Sun but some sort of fast Box filter should - * probably be correct. - * <br> - * Currently this filter does nothing and needs to be implemented. - * - * @author C. Brian Jones (cbj@gnu.org) - */ -public class ReplicateScaleFilter extends ImageFilter -{ - public ReplicateScaleFilter(int width, int height) { - destHeight = height; - destWidth = width; - } - - /** - * The height of the destination image. - */ - protected int destHeight; - - /** - * The width of the destination image. - */ - protected int destWidth; - - /** - * The height of the source image. - */ - protected int srcHeight; - - /** - * The width of the source image. - */ - protected int srcWidth; - - /** - * - */ - protected int srcrows[]; - - /** - * - */ - protected int srccols[]; - - /** - * - */ - protected Object outpixbuf; - - /** - * An <code>ImageProducer</code> indicates the size of the image - * being produced using this method. A filter can override this - * method to intercept these calls from the producer in order to - * change either the width or the height before in turn calling - * the consumer's <code>setDimensions</code> method. - * - * @param width the width of the image - * @param height the height of the image - */ - public void setDimensions(int width, int height) - { - srcWidth = width; - srcHeight = height; - - /* If either destHeight or destWidth is < 0, the image should - maintain its original aspect ratio. When both are < 0, - just maintain the original width and height. */ - if (destWidth < 0 && destHeight < 0) - { - destWidth = width; - destHeight = height; - } - else if (destWidth < 0) - { - destWidth = (int) (width * ((double) destHeight / srcHeight)); - } - else if (destHeight < 0) - { - destHeight = (int) (height * ((double) destWidth / srcWidth)); - } - - consumer.setDimensions(destWidth, destHeight); - } - - /** - * An <code>ImageProducer</code> can set a list of properties - * associated with this image by using this method. - * - * @param props the list of properties associated with this image - */ - public void setProperties(Hashtable props) - { - props.put("filters", "ReplicateScaleFilter"); - consumer.setProperties(props); - } - - /** - * This function delivers a rectangle of pixels where any - * pixel(m,n) is stored in the array as a <code>byte</code> at - * index (n * scansize + m + offset). - * - * @param x the x coordinate of the rectangle - * @param y the y coordinate of the rectangle - * @param w the width of the rectangle - * @param h the height of the rectangle - * @param model the <code>ColorModel</code> used to translate the pixels - * @param pixels the array of pixel values - * @param offset the index of the first pixels in the <code>pixels</code> array - * @param scansize the width to use in extracting pixels from the <code>pixels</code> array - */ - public void setPixels(int x, int y, int w, int h, - ColorModel model, byte[] pixels, int offset, int scansize) - { - double rx = ((double) srcWidth) / destWidth; - double ry = ((double) srcHeight) / destHeight; - - int destScansize = (int) Math.round(scansize / rx); - - byte[] destPixels = replicatePixels(x, y, w, h, - model, pixels, offset, scansize, - rx, ry, destScansize); - - consumer.setPixels((int) Math.floor(x/rx), (int) Math.floor(y/ry), - (int) Math.ceil(w/rx), (int) Math.ceil(h/ry), - model, destPixels, 0, destScansize); - } - - /** - * This function delivers a rectangle of pixels where any - * pixel(m,n) is stored in the array as an <code>int</code> at - * index (n * scansize + m + offset). - * - * @param x the x coordinate of the rectangle - * @param y the y coordinate of the rectangle - * @param w the width of the rectangle - * @param h the height of the rectangle - * @param model the <code>ColorModel</code> used to translate the pixels - * @param pixels the array of pixel values - * @param offset the index of the first pixels in the <code>pixels</code> array - * @param scansize the width to use in extracting pixels from the <code>pixels</code> array - */ - public void setPixels(int x, int y, int w, int h, - ColorModel model, int[] pixels, int offset, int scansize) - { - double rx = ((double) srcWidth) / destWidth; - double ry = ((double) srcHeight) / destHeight; - - int destScansize = (int) Math.round(scansize / rx); - - int[] destPixels = replicatePixels(x, y, w, h, - model, pixels, offset, scansize, - rx, ry, destScansize); - - consumer.setPixels((int) Math.floor(x/rx), (int) Math.floor(y/ry), - (int) Math.ceil(w/rx), (int) Math.ceil(h/ry), - model, destPixels, 0, destScansize); - } - - private byte[] replicatePixels(int srcx, int srcy, int srcw, int srch, - ColorModel model, byte[] srcPixels, - int srcOffset, int srcScansize, - double rx, double ry, int destScansize) - { - byte[] destPixels = - new byte[(int) Math.ceil(srcw/rx) * (int) Math.ceil(srch/ry)]; - - int a, b; - for (int i = 0; i < destPixels.length; i++) - { - a = (int) ((int) ( ((double) i) / destScansize) * ry) * srcScansize; - b = (int) ((i % destScansize) * rx); - if ((a + b + srcOffset) < srcPixels.length) - destPixels[i] = srcPixels[a + b + srcOffset]; - } - - return destPixels; - } - - private int[] replicatePixels(int srcx, int srcy, int srcw, int srch, - ColorModel model, int[] srcPixels, - int srcOffset, int srcScansize, - double rx, double ry, int destScansize) - { - int[] destPixels = - new int[(int) Math.ceil(srcw/rx) * (int) Math.ceil(srch/ry)]; - - int a, b; - for (int i = 0; i < destPixels.length; i++) - { - a = (int) ((int) ( ((double) i) / destScansize) * ry) * srcScansize; - b = (int) ((i % destScansize) * rx); - if ((a + b + srcOffset) < srcPixels.length) - destPixels[i] = srcPixels[a + b + srcOffset]; - } - - return destPixels; - } -} - diff --git a/libjava/java/awt/image/RescaleOp.java b/libjava/java/awt/image/RescaleOp.java deleted file mode 100644 index 35b42f79ccd..00000000000 --- a/libjava/java/awt/image/RescaleOp.java +++ /dev/null @@ -1,218 +0,0 @@ -/* Copyright (C) 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.image; - -import java.awt.RenderingHints; -import java.awt.geom.Point2D; -import java.awt.geom.Rectangle2D; -import java.util.Arrays; - -/** - * @author Jerry Quinn (jlquinn@optonline.net) - */ -public class RescaleOp implements BufferedImageOp, RasterOp -{ - private float[] scale; - private float[] offsets; - private RenderingHints hints = null; - - public RescaleOp(float[] scaleFactors, - float[] offsets, - RenderingHints hints) - { - this.scale = scaleFactors; - this.offsets = offsets; - this.hints = hints; - } - - public RescaleOp(float scaleFactor, - float offset, - RenderingHints hints) - { - scale = new float[]{ scaleFactor }; - offsets = new float[]{offset}; - this.hints = hints; - } - - public final float[] getScaleFactors(float[] scaleFactors) - { - if (scaleFactors == null) - scaleFactors = new float[scale.length]; - System.arraycopy(scale, 0, scaleFactors, 0, scale.length); - return scaleFactors; - } - - public final float[] getOffsets(float[] offsets) - { - if (offsets == null) - offsets = new float[this.offsets.length]; - System.arraycopy(this.offsets, 0, offsets, 0, this.offsets.length); - return offsets; - } - - public final int getNumFactors() - { - return scale.length; - } - - /* (non-Javadoc) - * @see java.awt.image.BufferedImageOp#getRenderingHints() - */ - public RenderingHints getRenderingHints() - { - return hints; - } - - /* (non-Javadoc) - * @see java.awt.image.BufferedImageOp#filter(java.awt.image.BufferedImage, java.awt.image.BufferedImage) - */ - public final BufferedImage filter(BufferedImage src, BufferedImage dst) - { - // TODO Make sure premultiplied alpha is handled correctly. - // TODO See that color conversion is handled. - // TODO figure out how to use rendering hints. - if (scale.length != offsets.length) - throw new IllegalArgumentException(); - - ColorModel scm = src.getColorModel(); - if (dst == null) dst = createCompatibleDestImage(src, null); - - WritableRaster wsrc = src.getRaster(); - WritableRaster wdst = dst.getRaster(); - - // Share constant across colors except alpha - if (scale.length == 1 || scale.length == scm.getNumColorComponents()) - { - // Construct a raster that doesn't include an alpha band. - int[] subbands = new int[scm.getNumColorComponents()]; - for (int i=0; i < subbands.length; i++) subbands[i] = i; - wsrc = - wsrc.createWritableChild(wsrc.minX, wsrc.minY, wsrc.width, wsrc.height, - wsrc.minX, wsrc.minY, subbands); - } - // else all color bands - - filter(wsrc, wdst); - return dst; - } - - /* (non-Javadoc) - * @see java.awt.image.RasterOp#filter(java.awt.image.Raster, java.awt.image.WritableRaster) - */ - public final WritableRaster filter(Raster src, WritableRaster dest) - { - if (dest == null) dest = src.createCompatibleWritableRaster(); - - // Required sanity checks - if (src.numBands != dest.numBands || scale.length != offsets.length) - throw new IllegalArgumentException(); - if (scale.length != 1 && scale.length != src.numBands) - throw new IllegalArgumentException(); - - // Create scaling arrays if needed - float[] lscale = scale; - float[] loff = offsets; - if (scale.length == 1) - { - lscale = new float[src.numBands]; - Arrays.fill(lscale, scale[0]); - loff = new float[src.numBands]; - Arrays.fill(loff, offsets[0]); - } - - // TODO The efficiency here can be improved for various data storage - // patterns, aka SampleModels. - float[] pixel = new float[src.numBands]; - for (int y = src.minY; y < src.height + src.minY; y++) - for (int x = src.minX; x < src.width + src.minX; x++) - { - src.getPixel(x, y, pixel); - for (int b = 0; b < src.numBands; b++) - pixel[b] = pixel[b] * lscale[b] + loff[b]; - dest.setPixel(x, y, pixel); - } - return dest; - } - - /* (non-Javadoc) - * @see java.awt.image.BufferedImageOp#createCompatibleDestImage(java.awt.image.BufferedImage, java.awt.image.ColorModel) - */ - public BufferedImage createCompatibleDestImage(BufferedImage src, - ColorModel dstCM) - { - if (dstCM == null) dstCM = src.getColorModel(); - WritableRaster wr = src.getRaster().createCompatibleWritableRaster(); - BufferedImage image - = new BufferedImage(dstCM, wr, src.isPremultiplied, null); - return image; - } - - /* (non-Javadoc) - * @see java.awt.image.RasterOp#createCompatibleDestRaster(java.awt.image.Raster) - */ - public WritableRaster createCompatibleDestRaster(Raster src) - { - return src.createCompatibleWritableRaster(); - } - - /* (non-Javadoc) - * @see java.awt.image.BufferedImageOp#getBounds2D(java.awt.image.BufferedImage) - */ - public final Rectangle2D getBounds2D(BufferedImage src) - { - return src.getRaster().getBounds(); - } - - /* (non-Javadoc) - * @see java.awt.image.RasterOp#getBounds2D(java.awt.image.Raster) - */ - public final Rectangle2D getBounds2D(Raster src) - { - return src.getBounds(); - } - - /* (non-Javadoc) - * @see java.awt.image.BufferedImageOp#getPoint2D(java.awt.geom.Point2D, java.awt.geom.Point2D) - */ - public final Point2D getPoint2D(Point2D src, Point2D dst) { - if (dst == null) dst = (Point2D) src.clone(); - else dst.setLocation(src); - return dst; - } - -} diff --git a/libjava/java/awt/image/SampleModel.java b/libjava/java/awt/image/SampleModel.java deleted file mode 100644 index 0c625291b64..00000000000 --- a/libjava/java/awt/image/SampleModel.java +++ /dev/null @@ -1,477 +0,0 @@ -/* Copyright (C) 2000, 2001, 2002 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.awt.image; - -/** - * @author Rolf W. Rasmussen (rolfwr@ii.uib.no) - */ -public abstract class SampleModel -{ - /** Width of image described. */ - protected int width; - - /** Height of image described. */ - protected int height; - - /** Number of bands in the image described. */ - protected int numBands; - - /** - * The DataBuffer type that is used to store the data of the image - * described. - */ - protected int dataType; - - public SampleModel(int dataType, int w, int h, int numBands) - { - if ((w <= 0) || (h <= 0)) - throw new IllegalArgumentException((w <= 0 ? " width<=0" : " width is ok") - +(h <= 0 ? " height<=0" : " height is ok")); - - // FIXME: How can an int be greater than Integer.MAX_VALUE? - // FIXME: How do we identify an unsupported data type? - - this.dataType = dataType; - this.width = w; - this.height = h; - this.numBands = numBands; - } - - public final int getWidth() - { - return width; - } - - public final int getHeight() - { - return height; - } - - public final int getNumBands() - { - return numBands; - } - - public abstract int getNumDataElements(); - - public final int getDataType() - { - return dataType; - } - - public int getTransferType() - { - // FIXME: Is this a reasonable default implementation? - return dataType; - } - - public int[] getPixel(int x, int y, int[] iArray, DataBuffer data) - { - if (iArray == null) iArray = new int[numBands]; - for (int b=0; b<numBands; b++) iArray[b] = getSample(x, y, b, data); - return iArray; - } - - /** - * - * This method is provided as a faster alternative to getPixel(), - * that can be used when there is no need to decode the pixel into - * separate sample values. - * - * @param obj An array to return the pixel data in. If null, an - * array of the right type and size will be created. - * - * @return A single pixel as an array object of a primitive type, - * based on the transfer type. Eg. if transfer type is - * DataBuffer.TYPE_USHORT, then a short[] object is returned. - */ - public abstract Object getDataElements(int x, int y, Object obj, - DataBuffer data); - - - public Object getDataElements(int x, int y, int w, int h, Object obj, - DataBuffer data) - { - int size = w*h; - int numDataElements = getNumDataElements(); - int dataSize = numDataElements*size; - - if (obj == null) - { - switch (getTransferType()) - { - case DataBuffer.TYPE_BYTE: - obj = new byte[dataSize]; - break; - case DataBuffer.TYPE_USHORT: - obj = new short[dataSize]; - break; - case DataBuffer.TYPE_INT: - obj = new int[dataSize]; - break; - default: - // Seems like the only sensible thing to do. - throw new ClassCastException(); - } - } - Object pixelData = null; - int outOffset = 0; - for (int yy = y; yy<(y+h); yy++) - { - for (int xx = x; xx<(x+w); xx++) - { - pixelData = getDataElements(xx, yy, pixelData, data); - System.arraycopy(pixelData, 0, obj, outOffset, - numDataElements); - outOffset += numDataElements; - } - } - return obj; - } - - public abstract void setDataElements(int x, int y, Object obj, - DataBuffer data); - - public void setDataElements(int x, int y, int w, int h, - Object obj, DataBuffer data) - { - int size = w*h; - int numDataElements = getNumDataElements(); - int dataSize = numDataElements*size; - - Object pixelData; - switch (getTransferType()) - { - case DataBuffer.TYPE_BYTE: - pixelData = new byte[numDataElements]; - break; - case DataBuffer.TYPE_USHORT: - pixelData = new short[numDataElements]; - break; - case DataBuffer.TYPE_INT: - pixelData = new int[numDataElements]; - break; - default: - // Seems like the only sensible thing to do. - throw new ClassCastException(); - } - int inOffset = 0; - - for (int yy=y; yy<(y+h); yy++) - { - for (int xx=x; xx<(x+w); xx++) - { - System.arraycopy(obj, inOffset, pixelData, 0, - numDataElements); - setDataElements(xx, yy, pixelData, data); - inOffset += numDataElements; - } - } - } - - public float[] getPixel(int x, int y, float[] fArray, DataBuffer data) - { - if (fArray == null) fArray = new float[numBands]; - - for (int b=0; b<numBands; b++) - { - fArray[b] = getSampleFloat(x, y, b, data); - } - return fArray; - } - - public double[] getPixel(int x, int y, double[] dArray, DataBuffer data) { - if (dArray == null) dArray = new double[numBands]; - for (int b=0; b<numBands; b++) - { - dArray[b] = getSampleDouble(x, y, b, data); - } - return dArray; - } - - /* FIXME: Should it return a banded or pixel interleaved array of - samples? (Assume interleaved.) */ - public int[] getPixels(int x, int y, int w, int h, int[] iArray, - DataBuffer data) - { - int size = w*h; - int outOffset = 0; - int[] pixel = null; - if (iArray == null) iArray = new int[w*h*numBands]; - for (int yy=y; yy<(y+h); yy++) - { - for (int xx=x; xx<(x+w); xx++) - { - getPixel(xx, yy, pixel, data); - System.arraycopy(pixel, 0, iArray, outOffset, numBands); - outOffset += numBands; - } - } - return iArray; - } - - /* FIXME: Should it return a banded or pixel interleaved array of - samples? (Assume interleaved.) */ - public float[] getPixels(int x, int y, int w, int h, float[] fArray, - DataBuffer data) - { - int size = w*h; - int outOffset = 0; - float[] pixel = null; - if (fArray == null) fArray = new float[w*h*numBands]; - for (int yy=y; yy<(y+h); yy++) - { - for (int xx=x; xx<(x+w); xx++) - { - getPixel(xx, yy, pixel, data); - System.arraycopy(pixel, 0, fArray, outOffset, numBands); - outOffset += numBands; - } - } - return fArray; - } - - /* FIXME: Should it return a banded or pixel interleaved array of - samples? (Assume interleaved.) */ - public double[] getPixels(int x, int y, int w, int h, double[] dArray, - DataBuffer data) - { - int size = w*h; - int outOffset = 0; - double[] pixel = null; - if (dArray == null) dArray = new double[w*h*numBands]; - for (int yy=y; yy<(y+h); yy++) - { - for (int xx=x; xx<(x+w); xx++) - { - getPixel(xx, yy, pixel, data); - System.arraycopy(pixel, 0, dArray, outOffset, numBands); - outOffset += numBands; - } - } - return dArray; - } - - public abstract int getSample(int x, int y, int b, DataBuffer data); - - public float getSampleFloat(int x, int y, int b, DataBuffer data) - { - return getSample(x, y, b, data); - } - - public double getSampleDouble(int x, int y, int b, DataBuffer data) - { - return getSampleFloat(x, y, b, data); - } - - public int[] getSamples(int x, int y, int w, int h, int b, - int[] iArray, DataBuffer data) - { - int size = w*h; - int outOffset = 0; - if (iArray == null) iArray = new int[size]; - for (int yy=y; yy<(y+h); yy++) - { - for (int xx=x; xx<(x+w); xx++) - { - iArray[outOffset++] = getSample(xx, yy, b, data); - } - } - return iArray; - } - - public float[] getSamples(int x, int y, int w, int h, int b, - float[] fArray, DataBuffer data) - { - int size = w*h; - int outOffset = 0; - if (fArray == null) fArray = new float[size]; - for (int yy=y; yy<(y+h); yy++) - { - for (int xx=x; xx<(x+w); xx++) - { - fArray[outOffset++] = getSampleFloat(xx, yy, b, data); - } - } - return fArray; - } - - public double[] getSamples(int x, int y, int w, int h, int b, - double[] dArray, DataBuffer data) - { - int size = w*h; - int outOffset = 0; - if (dArray == null) dArray = new double[size]; - for (int yy=y; yy<(y+h); yy++) - { - for (int xx=x; xx<(x+w); xx++) - { - dArray[outOffset++] = getSampleDouble(xx, yy, b, data); - } - } - return dArray; - } - - public void setPixel(int x, int y, int[] iArray, DataBuffer data) - { - for (int b=0; b<numBands; b++) setSample(x, y, b, iArray[b], data); - } - - public void setPixel(int x, int y, float[] fArray, DataBuffer data) - { - for (int b=0; b<numBands; b++) setSample(x, y, b, fArray[b], data); - } - - public void setPixel(int x, int y, double[] dArray, DataBuffer data) - { - for (int b=0; b<numBands; b++) setSample(x, y, b, dArray[b], data); - } - - public void setPixels(int x, int y, int w, int h, int[] iArray, - DataBuffer data) - { - int inOffset = 0; - int[] pixel = new int[numBands]; - for (int yy=y; yy<(y+h); yy++) - { - for (int xx=x; xx<(x+w); xx++) - { - System.arraycopy(iArray, inOffset, pixel, 0, numBands); - setPixel(xx, yy, pixel, data); - inOffset += numBands; - } - } - } - - public void setPixels(int x, int y, int w, int h, float[] fArray, - DataBuffer data) - { - int inOffset = 0; - float[] pixel = new float[numBands]; - for (int yy=y; yy<(y+h); yy++) - { - for (int xx=x; xx<(x+w); xx++) - { - System.arraycopy(fArray, inOffset, pixel, 0, numBands); - setPixel(xx, yy, pixel, data); - inOffset += numBands; - } - } - } - - public void setPixels(int x, int y, int w, int h, double[] dArray, - DataBuffer data) - { - int inOffset = 0; - double[] pixel = new double[numBands]; - for (int yy=y; yy<(y+h); yy++) - { - for (int xx=x; xx<(x+w); xx++) - { - System.arraycopy(dArray, inOffset, pixel, 0, numBands); - setPixel(xx, yy, pixel, data); - inOffset += numBands; - } - } - } - - public abstract void setSample(int x, int y, int b, int s, - DataBuffer data); - - public void setSample(int x, int y, int b, float s, - DataBuffer data) - { - setSample(x, y, b, (int) s, data); - } - - public void setSample(int x, int y, int b, double s, - DataBuffer data) - { - setSample(x, y, b, (float) s, data); - } - - public void setSamples(int x, int y, int w, int h, int b, - int[] iArray, DataBuffer data) - { - int size = w*h; - int inOffset = 0; - for (int yy=y; yy<(y+h); yy++) - for (int xx=x; xx<(x+w); xx++) - setSample(xx, yy, b, iArray[inOffset++], data); - } - - public void setSamples(int x, int y, int w, int h, int b, - float[] fArray, DataBuffer data) - { - int size = w*h; - int inOffset = 0; - for (int yy=y; yy<(y+h); yy++) - for (int xx=x; xx<(x+w); xx++) - setSample(xx, yy, b, fArray[inOffset++], data); - - } - - public void setSamples(int x, int y, int w, int h, int b, - double[] dArray, DataBuffer data) { - int size = w*h; - int inOffset = 0; - for (int yy=y; yy<(y+h); yy++) - for (int xx=x; xx<(x+w); xx++) - setSample(xx, yy, b, dArray[inOffset++], data); - } - - public abstract SampleModel createCompatibleSampleModel(int w, int h); - - /** - * Return a SampleModel with a subset of the bands in this model. - * - * Selects bands.length bands from this sample model. The bands chosen - * are specified in the indices of bands[]. This also permits permuting - * the bands as well as taking a subset. Thus, giving an array with - * 1, 2, 3, ..., numbands, will give an identical sample model. - * - * @param bands Array with band indices to include. - * @return A new sample model - */ - public abstract SampleModel createSubsetSampleModel(int[] bands); - - public abstract DataBuffer createDataBuffer(); - - public abstract int[] getSampleSize(); - - public abstract int getSampleSize(int band); -} diff --git a/libjava/java/awt/image/ShortLookupTable.java b/libjava/java/awt/image/ShortLookupTable.java deleted file mode 100644 index 5915a7939a3..00000000000 --- a/libjava/java/awt/image/ShortLookupTable.java +++ /dev/null @@ -1,162 +0,0 @@ -/* ShortLookupTable.java -- Java class for a pixel translation table. - Copyright (C) 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.image; - -/** - * ShortLookupTable represents translation arrays for pixel values. It wraps - * one or more data arrays for each layer (or component) in an image, such as - * Alpha, R, G, and B. When doing translation, the offset is subtracted from - * the pixel values to allow a subset of an array to be used. - * - * @author Jerry Quinn (jlquinn@optonline.net) - * @version 1.0 - */ -public class ShortLookupTable extends LookupTable -{ - // Array of translation tables. - private short data[][]; - - /** - * Creates a new <code>ShortLookupTable</code> instance. - * - * Offset is subtracted from pixel values when looking up in the translation - * tables. If data.length is one, the same table is applied to all pixel - * components. - * - * @param offset Offset to be subtracted. - * @param data Array of lookup tables. - * @exception IllegalArgumentException if offset < 0 or data.length < 1. - */ - public ShortLookupTable(int offset, short[][] data) - throws IllegalArgumentException - { - super(offset, data.length); - this.data = data; - } - - /** - * Creates a new <code>ShortLookupTable</code> instance. - * - * Offset is subtracted from pixel values when looking up in the translation - * table. The same table is applied to all pixel components. - * - * @param offset Offset to be subtracted. - * @param data Lookup table for all components. - * @exception IllegalArgumentException if offset < 0. - */ - public ShortLookupTable(int offset, short[] data) - throws IllegalArgumentException - { - super(offset, 1); - this.data = new short[][] {data}; - } - - /** Return the lookup tables. */ - public final short[][] getTable() - { - return data; - } - - /** - * Return translated values for a pixel. - * - * For each value in the pixel src, use the value minus offset as an index - * in the component array and copy the value there to the output for the - * component. If dest is null, the output is a new array, otherwise the - * translated values are written to dest. Dest can be the same array as - * src. - * - * For example, if the pixel src is [2, 4, 3], and offset is 1, the output - * is [comp1[1], comp2[3], comp3[2]], where comp1, comp2, and comp3 are the - * translation arrays. - * - * @param src Component values of a pixel. - * @param dst Destination array for values, or null. - * @return Translated values for the pixel. - */ - public int[] lookupPixel(int[] src, int[] dst) - throws ArrayIndexOutOfBoundsException - { - if (dst == null) - dst = new int[src.length]; - - if (data.length == 1) - for (int i=0; i < src.length; i++) - dst[i] = data[0][src[i] - offset]; - else - for (int i=0; i < src.length; i++) - dst[i] = data[i][src[i] - offset]; - - return dst; - } - - /** - * Return translated values for a pixel. - * - * For each value in the pixel src, use the value minus offset as an index - * in the component array and copy the value there to the output for the - * component. If dest is null, the output is a new array, otherwise the - * translated values are written to dest. Dest can be the same array as - * src. - * - * For example, if the pixel src is [2, 4, 3], and offset is 1, the output - * is [comp1[1], comp2[3], comp3[2]], where comp1, comp2, and comp3 are the - * translation arrays. - * - * @param src Component values of a pixel. - * @param dst Destination array for values, or null. - * @return Translated values for the pixel. - */ - public short[] lookupPixel(short[] src, short[] dst) - throws ArrayIndexOutOfBoundsException - { - if (dst == null) - dst = new short[src.length]; - - if (data.length == 1) - for (int i=0; i < src.length; i++) - dst[i] = data[0][((int)src[i]) - offset]; - else - for (int i=0; i < src.length; i++) - dst[i] = data[i][((int)src[i]) - offset]; - - return dst; - - } -} diff --git a/libjava/java/awt/image/SinglePixelPackedSampleModel.java b/libjava/java/awt/image/SinglePixelPackedSampleModel.java deleted file mode 100644 index 6ccce753bd3..00000000000 --- a/libjava/java/awt/image/SinglePixelPackedSampleModel.java +++ /dev/null @@ -1,449 +0,0 @@ -/* Copyright (C) 2000, 2002, 2003, 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.awt.image; - -import gnu.java.awt.BitMaskExtent; -import gnu.java.awt.Buffers; - -/** - * @author Rolf W. Rasmussen (rolfwr@ii.uib.no) - */ -public class SinglePixelPackedSampleModel extends SampleModel -{ - private int scanlineStride; - private int[] bitMasks; - private int[] bitOffsets; - private int[] sampleSize; - - public SinglePixelPackedSampleModel(int dataType, int w, int h, - int[] bitMasks) - { - this(dataType, w, h, w, bitMasks); - } - - public SinglePixelPackedSampleModel(int dataType, int w, int h, - int scanlineStride, int[] bitMasks) - { - super(dataType, w, h, bitMasks.length); - - switch (dataType) - { - case DataBuffer.TYPE_BYTE: - case DataBuffer.TYPE_USHORT: - case DataBuffer.TYPE_INT: - break; - default: - throw new IllegalArgumentException("SinglePixelPackedSampleModel unsupported dataType"); - } - - this.scanlineStride = scanlineStride; - this.bitMasks = bitMasks; - - bitOffsets = new int[numBands]; - sampleSize = new int[numBands]; - - BitMaskExtent extent = new BitMaskExtent(); - for (int b=0; b<numBands; b++) - { - extent.setMask(bitMasks[b]); - sampleSize[b] = extent.bitWidth; - bitOffsets[b] = extent.leastSignificantBit; - } - } - - public int getNumDataElements() - { - return 1; - } - - public SampleModel createCompatibleSampleModel(int w, int h) - { - /* FIXME: We can avoid recalculation of bit offsets and sample - sizes here by passing these from the current instance to a - special private constructor. */ - return new SinglePixelPackedSampleModel(dataType, w, h, bitMasks); - } - - - /** - * Creates a DataBuffer for holding pixel data in the format and - * layout described by this SampleModel. The returned buffer will - * consist of one single bank. - */ - public DataBuffer createDataBuffer() - { - int size; - - // We can save (scanlineStride - width) pixels at the very end of - // the buffer. The Sun reference implementation (J2SE 1.3.1 and - // 1.4.1_01) seems to do this; tested with Mauve test code. - size = scanlineStride * (height - 1) + width; - - return Buffers.createBuffer(getDataType(), size); - } - - - public int[] getSampleSize() - { - return sampleSize; - } - - public int getSampleSize(int band) - { - return sampleSize[band]; - } - - public int getOffset(int x, int y) - { - return scanlineStride*y + x; - } - - public int[] getBitOffsets() - { - return bitOffsets; - } - - public int[] getBitMasks() - { - return bitMasks; - } - - public int getScanlineStride() - { - return scanlineStride; - } - - public SampleModel createSubsetSampleModel(int[] bands) - { - // FIXME: Is this the right way to interpret bands? - - int numBands = bands.length; - - int[] bitMasks = new int[numBands]; - - for (int b=0; b<numBands; b++) - bitMasks[b] = this.bitMasks[bands[b]]; - - return new SinglePixelPackedSampleModel(dataType, width, height, - scanlineStride, bitMasks); - } - - public Object getDataElements(int x, int y, Object obj, - DataBuffer data) - { - int offset = scanlineStride*y + x + data.getOffset(); - - return Buffers.getData(data, offset, obj, - 0, // destination offset, - 1 // length - ); - } - - /** - * This is a more efficient implementation of the default implementation in the super - * class. - * @param x The x-coordinate of the pixel rectangle to store in <code>obj</code>. - * @param y The y-coordinate of the pixel rectangle to store in <code>obj</code>. - * @param w The width of the pixel rectangle to store in <code>obj</code>. - * @param h The height of the pixel rectangle to store in <code>obj</code>. - * @param obj The primitive array to store the pixels into or null to force creation. - * @param data The DataBuffer that is the source of the pixel data. - * @return The primitive array containing the pixel data. - * @see java.awt.image.SampleModel#getDataElements(int, int, int, int, java.lang.Object, java.awt.image.DataBuffer) - */ - public Object getDataElements(int x, int y, int w, int h, Object obj, - DataBuffer data) - { - int size = w*h; - int dataSize = size; - Object pixelData = null; - switch (getTransferType()) - { - case DataBuffer.TYPE_BYTE: - pixelData = ((DataBufferByte) data).getData(); - if (obj == null) obj = new byte[dataSize]; - break; - case DataBuffer.TYPE_USHORT: - pixelData = ((DataBufferUShort) data).getData(); - if (obj == null) obj = new short[dataSize]; - break; - case DataBuffer.TYPE_INT: - pixelData = ((DataBufferInt) data).getData(); - if (obj == null) obj = new int[dataSize]; - break; - default: - // Seems like the only sensible thing to do. - throw new ClassCastException(); - } - if(x==0 && scanlineStride == w) - { - // The full width need to be copied therefore we can copy in one shot. - System.arraycopy(pixelData, scanlineStride*y + data.getOffset(), obj, 0, size); - } - else - { - // Since we do not need the full width we need to copy line by line. - int outOffset = 0; - int dataOffset = scanlineStride*y + x + data.getOffset(); - for (int yy = y; yy<(y+h); yy++) - { - System.arraycopy(pixelData, dataOffset, obj, outOffset, w); - dataOffset += scanlineStride; - outOffset += w; - } - } - return obj; - } - - - public int[] getPixel(int x, int y, int[] iArray, DataBuffer data) - { - int offset = scanlineStride*y + x; - if (iArray == null) iArray = new int[numBands]; - int samples = data.getElem(offset); - - for (int b=0; b<numBands; b++) - iArray[b] = (samples & bitMasks[b]) >>> bitOffsets[b]; - - return iArray; - } - - public int[] getPixels(int x, int y, int w, int h, int[] iArray, - DataBuffer data) - { - int offset = scanlineStride*y + x; - if (iArray == null) iArray = new int[numBands*w*h]; - int outOffset = 0; - for (y=0; y<h; y++) - { - int lineOffset = offset; - for (x=0; x<w; x++) - { - int samples = data.getElem(lineOffset++); - for (int b=0; b<numBands; b++) - iArray[outOffset++] = (samples & bitMasks[b]) >>> bitOffsets[b]; - } - offset += scanlineStride; - } - return iArray; - } - - public int getSample(int x, int y, int b, DataBuffer data) - { - int offset = scanlineStride*y + x; - int samples = data.getElem(offset); - return (samples & bitMasks[b]) >>> bitOffsets[b]; - } - - /** - * This method implements a more efficient way to set data elements than the default - * implementation of the super class. It sets the data elements line by line instead - * of pixel by pixel. - * @param x The x-coordinate of the data elements in <code>obj</code>. - * @param y The y-coordinate of the data elements in <code>obj</code>. - * @param w The width of the data elements in <code>obj</code>. - * @param h The height of the data elements in <code>obj</code>. - * @param obj The primitive array containing the data elements to set. - * @param data The DataBuffer to store the data elements into. - * @see java.awt.image.SampleModel#setDataElements(int, int, int, int, java.lang.Object, java.awt.image.DataBuffer) - */ - public void setDataElements(int x, int y, int w, int h, - Object obj, DataBuffer data) - { - - Object pixelData; - switch (getTransferType()) - { - case DataBuffer.TYPE_BYTE: - pixelData = ((DataBufferByte) data).getData(); - break; - case DataBuffer.TYPE_USHORT: - pixelData = ((DataBufferUShort) data).getData(); - break; - case DataBuffer.TYPE_INT: - pixelData = ((DataBufferInt) data).getData(); - break; - default: - // Seems like the only sensible thing to do. - throw new ClassCastException(); - } - - int inOffset = 0; - int dataOffset = scanlineStride*y + x + data.getOffset(); - for (int yy=y; yy<(y+h); yy++) - { - System.arraycopy(obj,inOffset,pixelData,dataOffset,w); - dataOffset += scanlineStride; - inOffset += w; - } - } - - - public void setDataElements(int x, int y, Object obj, DataBuffer data) - { - int offset = scanlineStride*y + x + data.getOffset(); - - int transferType = getTransferType(); - if (getTransferType() != data.getDataType()) - { - throw new IllegalArgumentException("transfer type ("+ - getTransferType()+"), "+ - "does not match data "+ - "buffer type (" + - data.getDataType() + - ")."); - } - - try - { - switch (transferType) - { - case DataBuffer.TYPE_BYTE: - { - DataBufferByte out = (DataBufferByte) data; - byte[] in = (byte[]) obj; - out.getData()[offset] = in[0]; - return; - } - case DataBuffer.TYPE_USHORT: - { - DataBufferUShort out = (DataBufferUShort) data; - short[] in = (short[]) obj; - out.getData()[offset] = in[0]; - return; - } - case DataBuffer.TYPE_INT: - { - DataBufferInt out = (DataBufferInt) data; - int[] in = (int[]) obj; - out.getData()[offset] = in[0]; - return; - } - // FIXME: Fill in the other possible types. - default: - throw new InternalError(); - } - } - catch (ArrayIndexOutOfBoundsException aioobe) - { - String msg = "While writing data elements" + - ", x="+x+", y="+y+ - ", width="+width+", height="+height+ - ", scanlineStride="+scanlineStride+ - ", offset="+offset+ - ", data.getSize()="+data.getSize()+ - ", data.getOffset()="+data.getOffset()+ - ": " + - aioobe; - throw new ArrayIndexOutOfBoundsException(msg); - } - } - - public void setPixel(int x, int y, int[] iArray, DataBuffer data) - { - int offset = scanlineStride*y + x; - - int samples = 0; - for (int b=0; b<numBands; b++) - samples |= (iArray[b] << bitOffsets[b]) & bitMasks[b]; - - data.setElem(offset, samples); - } - - /** - * This method implements a more efficient way to set pixels than the default - * implementation of the super class. It copies the pixel components directly - * from the input array instead of creating a intermediate buffer. - * @param x The x-coordinate of the pixel rectangle in <code>obj</code>. - * @param y The y-coordinate of the pixel rectangle in <code>obj</code>. - * @param w The width of the pixel rectangle in <code>obj</code>. - * @param h The height of the pixel rectangle in <code>obj</code>. - * @param iArray The primitive array containing the pixels to set. - * @param data The DataBuffer to store the pixels into. - * @see java.awt.image.SampleModel#setPixels(int, int, int, int, int[], java.awt.image.DataBuffer) - */ - public void setPixels(int x, int y, int w, int h, int[] iArray, - DataBuffer data) - { - int inOffset = 0; - int[] pixel = new int[numBands]; - for (int yy=y; yy<(y+h); yy++) - { - int offset = scanlineStride*yy + x; - for (int xx=x; xx<(x+w); xx++) - { - int samples = 0; - for (int b=0; b<numBands; b++) - samples |= (iArray[inOffset+b] << bitOffsets[b]) & bitMasks[b]; - data.setElem(0, offset, samples); - inOffset += numBands; - offset += 1; - } - } - } - - - public void setSample(int x, int y, int b, int s, DataBuffer data) - { - int offset = scanlineStride*y + x; - int samples = data.getElem(offset); - int bitMask = bitMasks[b]; - samples &= ~bitMask; - samples |= (s << bitOffsets[b]) & bitMask; - data.setElem(offset, samples); - } - - /** - * Creates a String with some information about this SampleModel. - * @return A String describing this SampleModel. - * @see java.lang.Object#toString() - */ - public String toString() - { - StringBuffer result = new StringBuffer(); - result.append(getClass().getName()); - result.append("["); - result.append("scanlineStride=").append(scanlineStride); - for(int i=0; i < bitMasks.length; i+=1) - { - result.append(", mask[").append(i).append("]=0x").append(Integer.toHexString(bitMasks[i])); - } - - result.append("]"); - return result.toString(); - } -} diff --git a/libjava/java/awt/image/TileObserver.java b/libjava/java/awt/image/TileObserver.java deleted file mode 100644 index 99aafbce81c..00000000000 --- a/libjava/java/awt/image/TileObserver.java +++ /dev/null @@ -1,47 +0,0 @@ -/* TileObserver.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.image; - -/** - * NEEDS DOCUMENTATION - */ -public interface TileObserver -{ - void tileUpdate(WritableRenderedImage src, int x, int y, boolean writable); -} // interface TileObserver diff --git a/libjava/java/awt/image/VolatileImage.java b/libjava/java/awt/image/VolatileImage.java deleted file mode 100644 index 308654162ae..00000000000 --- a/libjava/java/awt/image/VolatileImage.java +++ /dev/null @@ -1,253 +0,0 @@ -/* VolatileImage.java -- a hardware-accelerated image buffer - Copyright (C) 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.image; - -import java.awt.Graphics; -import java.awt.Graphics2D; -import java.awt.GraphicsConfiguration; -import java.awt.Image; -import java.awt.Transparency; -import java.awt.ImageCapabilities; - -/** - * VolatileImage represents a hardware-accelerated graphics buffer. - * The native graphics system may free or damage the resources - * occupied by a VolatileImage at any time. As such, one must - * frequently check the "validity" of the image buffer's resources. - * - * A volatile image's "validity" depends on multiple factors. Its - * resources may have become unavailble in which case you must - * reallocate them. If you move the image from one output device to - * another, you may need to recreate the image's resources if the new - * output device's capabilities don't match the old one's. Finally, - * if the contents of the image's buffer have been damaged you must - * re-render the image. - * - * VolatileImages should always be created using either - * Component.createVolatileImage or - * GraphicsConfiguration.createCompatibleVolatileImage. - */ -public abstract class VolatileImage extends Image - implements Transparency -{ - /** - * One of validate's possible return values. Indicates that the - * image buffer matches its graphics configuration's capabilities - * and that its resources are initialized and ready to be drawn - * into. Also implies that any existing image rendered to the - * buffer is intact and need not be re-rendered. - */ - public static final int IMAGE_OK = 0; - - /** - * One of validate's possible return values. Indicates that the - * image buffer has been restored, meaning that it is valid and - * ready-to-use but that its previous contents have been lost. This - * return value implies that the image needs to be re-rendered. - */ - public static final int IMAGE_RESTORED = 1; - - /** - * One of validate's possible return values. Indicates that the - * image buffer type is unsupported by the current graphics - * configuration. The graphics configuration may have changed, for - * example if the image moved from one output device to another. - * This return value implies that the image buffer's resources - * should be re-acquired. - */ - public static final int IMAGE_INCOMPATIBLE = 2; - - /** - * This image's transparency type. One of Transparency.BITMASK, - * Transparency.OPAQUE or Transparency.TRANSLUCENT. - * - * @since 1.5 - */ - protected int transparency; - - /** - * Default constructor. VolatileImages should not be created - * directly. Rather, you should use Component.createVolatileImage - * or GraphicsConfiguration.createCompatibleVolatileImage. - */ - public VolatileImage() - { - } - - /** - * Returns an image representing the current state of the volatile - * image buffer. The returned image is static meaning that it is - * not updated after being created. It is a snapshot of the - * volatile image buffer at the time getSnapshot is called. - * - * This method, which reads pixels from the volatile image buffer, - * may be less-performant than methods that write pixels since - * VolatileImages are typically optimized for writing. - * - * @return a BufferedImage representing this VolatileImage - */ - public abstract BufferedImage getSnapshot(); - - /** - * Returns the width of this image buffer. - * - * @return the width of this VolatileImage - */ - public abstract int getWidth(); - - /** - * Returns the height of this image buffer. - * - * @return the height of this VolatileImage - */ - public abstract int getHeight(); - - /** - * Calling this method is equivalent to calling - * getSnapshot().getSource(). The ImageProducer produces pixels - * from the BufferedImage snapshot and not from the VolatileImage - * itself. Thus, changes to the VolatileImage that occur after this - * ImageProducer has been retrieved will not be reflected in the - * produced pixels. - * - * This method, which reads pixels from the volatile image buffer, - * may be less-performant than methods that write pixels since - * VolatileImages are typically optimized for writing. - * - * @return an ImageProducer for a static BufferedImage snapshot of - * this image buffer - */ - public ImageProducer getSource() - { - return getSnapshot().getSource(); - } - - /** - * Releases the system resources taken by this image. - */ - public void flush() - { - } - - /** - * Returns a Graphics2D object that can be used to draw onto this - * image. This method is present for backwards-compatibility. It - * simply returns the result of createGraphics. - * - * @return a Graphics2D object that can be used to draw onto this - * image - */ - public Graphics getGraphics() - { - return createGraphics(); - } - - /** - * Returns a Graphics2D object that can be used to draw onto this - * image. - * - * @return a Graphics2D object that can be used to draw onto this - * image - */ - public abstract Graphics2D createGraphics(); - - /** - * Validates and restores this image. If the image buffer has - * become unavailable for further use since the last call to - * validate, validate will allocate a new image buffer. The image - * is also "validated" against the GraphicsConfiguration parameter. - * - * "Validating" the image means checking that the capabilities it - * requires of the output device are indeed supported by the given - * output device. If the image's characteristics, which can be - * highly output device-specific, are not supported by the graphics - * configuration, then IMAGE_INCOMPATIBLE will be returned. This - * can happen, for example, if this image was created on one output - * device, then validated against a different output device with - * different capabilities. Calling validate with a NULL gc argument - * causes validate to skip the validation test. - * - * @param gc graphics configuration against which to validate or - * NULL - * - * @return a code indicating the result of validation. One of: - * <ul> - * <li><code>IMAGE_OK</code> if the image did not need to be - * validated and didn't need to be restored</li> - * <li><code>IMAGE_RESTORED</code> if the image may need to be - * re-rendered.</li> - * <li><code>IMAGE_INCOMPATIBLE</code> if this image's - * requirements are not fulfilled by the graphics configuration - * parameter. This implies that you need to create a new - * VolatileImage for the different GraphicsConfiguration or - * Component. This return value implies nothing about whether the - * image is valid or needs to be re-rendered.</li> - * </ul> - */ - public abstract int validate(GraphicsConfiguration gc); - - /** - * Returns true if the contents of the image buffer have been - * damaged or if the image buffer's resources have been reclaimed by - * the graphics system. You should call this method after a series - * of rendering operations to or from the image, to see if the image - * buffer needs to be revalidated or the image re-rendered. - * - * @return true if the validate should be called, false otherwise - */ - public abstract boolean contentsLost(); - - /** - * Returns the capabilities of this image buffer. - * - * @return the capabilities of this image buffer - */ - public abstract ImageCapabilities getCapabilities(); - - /** - * Returns the transparency type of this image. - * - * @return Transparency.OPAQUE, Transparency.BITMASK or - * Transparency.TRANSLUCENT - */ - public int getTransparency() - { - return transparency; - } -} diff --git a/libjava/java/awt/image/WritableRaster.java b/libjava/java/awt/image/WritableRaster.java deleted file mode 100644 index 2e5462fd92e..00000000000 --- a/libjava/java/awt/image/WritableRaster.java +++ /dev/null @@ -1,265 +0,0 @@ -/* Copyright (C) 2000, 2002, 2003 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.image; - -import java.awt.Point; -import java.awt.Rectangle; - -/** - * @author Rolf W. Rasmussen (rolfwr@ii.uib.no) - */ -public class WritableRaster extends Raster -{ - protected WritableRaster(SampleModel sampleModel, Point origin) - { - this(sampleModel, sampleModel.createDataBuffer(), origin); - } - - protected WritableRaster(SampleModel sampleModel, - DataBuffer dataBuffer, Point origin) - { - this(sampleModel, dataBuffer, - new Rectangle(origin != null ? origin.x : 0, - origin != null ? origin.y : 0, - sampleModel.getWidth(), sampleModel.getHeight()), - origin, - null); - } - - protected WritableRaster(SampleModel sampleModel, - DataBuffer dataBuffer, - Rectangle aRegion, - Point sampleModelTranslate, - WritableRaster parent) - { - super(sampleModel, dataBuffer, aRegion, sampleModelTranslate, - parent); - } - - public WritableRaster getWritableParent() - { - return (WritableRaster) getParent(); - } - - public WritableRaster createWritableTranslatedChild(int childMinX, - int childMinY) - { - // This mirrors the code from the super class - int tcx = sampleModelTranslateX - minX + childMinX; - int tcy = sampleModelTranslateY - minY + childMinY; - - return new WritableRaster(sampleModel, dataBuffer, - new Rectangle(childMinX, childMinY, - width, height), - new Point(tcx, tcy), - this); - } - - public WritableRaster createWritableChild(int parentX, - int parentY, - int w, int h, - int childMinX, - int childMinY, - int[] bandList) - { - // This mirrors the code from the super class - - // FIXME: Throw RasterFormatException if child bounds extends - // beyond the bounds of this raster. - - SampleModel sm = (bandList == null) ? - sampleModel : - sampleModel.createSubsetSampleModel(bandList); - - return new - WritableRaster(sm, dataBuffer, - new Rectangle(childMinX, childMinY, - w, h), - new Point(sampleModelTranslateX+childMinX-parentX, - sampleModelTranslateY+childMinY-parentY), - this); - } - - public void setDataElements(int x, int y, Object inData) - { - sampleModel.setDataElements(x-sampleModelTranslateX, - y-sampleModelTranslateY, - inData, dataBuffer); - } - - public void setDataElements(int x, int y, Raster inRaster) - { - Object dataElements = getDataElements(0, 0, - inRaster.getWidth(), - inRaster.getHeight(), - null); - setDataElements(x, y, dataElements); - } - - public void setDataElements(int x, int y, int w, int h, - Object inData) - { - sampleModel.setDataElements(x-sampleModelTranslateX, - y-sampleModelTranslateY, - w, h, inData, dataBuffer); - } - - public void setRect(Raster srcRaster) - { - setRect(0, 0, srcRaster); - } - - public void setRect(int dx, int dy, Raster srcRaster) - { - Rectangle targetUnclipped = new Rectangle(srcRaster.getMinX()+dx, - srcRaster.getMinY()+dy, - srcRaster.getWidth(), - srcRaster.getHeight()); - - Rectangle target = getBounds().intersection(targetUnclipped); - - if (target.isEmpty()) return; - - int sx = target.x - dx; - int sy = target.y - dy; - - // FIXME: Do tests on rasters and use get/set data instead. - - /* The JDK documentation seems to imply this implementation. - (the trucation of higher bits), but an implementation using - get/setDataElements would be more efficient. None of the - implementations would do anything sensible when the sample - models don't match. - - But this is probably not the place to consider such - optimizations.*/ - - int[] pixels = srcRaster.getPixels(sx, sy, - target.width, target.height, - (int[]) null); - - setPixels(target.x, target.y, target.width, target.height, pixels); - } - - public void setPixel(int x, int y, int[] iArray) - { - sampleModel.setPixel(x-sampleModelTranslateX, - y-sampleModelTranslateY, - iArray, dataBuffer); - } - - public void setPixel(int x, int y, float[] fArray) - { - sampleModel.setPixel(x-sampleModelTranslateX, - y-sampleModelTranslateY, - fArray, dataBuffer); - } - - public void setPixel(int x, int y, double[] dArray) - { - sampleModel.setPixel(x-sampleModelTranslateX, - y-sampleModelTranslateY, - dArray, dataBuffer); - } - - public void setPixels(int x, int y, int w, int h, int[] iArray) - { - sampleModel.setPixels(x-sampleModelTranslateX, - y-sampleModelTranslateY, - w, h, iArray, dataBuffer); - } - - public void setPixels(int x, int y, int w, int h, float[] fArray) - { - sampleModel.setPixels(x-sampleModelTranslateX, - y-sampleModelTranslateY, - w, h, fArray, dataBuffer); - } - - public void setPixels(int x, int y, int w, int h, double[] dArray) - { - sampleModel.setPixels(x-sampleModelTranslateX, - y-sampleModelTranslateY, - w, h, dArray, dataBuffer); - } - - public void setSample(int x, int y, int b, int s) - { - sampleModel.setSample(x-sampleModelTranslateX, - y-sampleModelTranslateY, - b, s, dataBuffer); - } - - public void setSample(int x, int y, int b, float s) - { - sampleModel.setSample(x-sampleModelTranslateX, - y-sampleModelTranslateY, - b, s, dataBuffer); - } - - public void setSample(int x, int y, int b, double s) - { - sampleModel.setSample(x-sampleModelTranslateX, - y-sampleModelTranslateY, - b, s, dataBuffer); - } - - public void setSamples(int x, int y, int w, int h, int b, - int[] iArray) - { - sampleModel.setSamples(x-sampleModelTranslateX, - y-sampleModelTranslateY, - w, h, b, iArray, dataBuffer); - } - - public void setSamples(int x, int y, int w, int h, int b, - float[] fArray) - { - sampleModel.setSamples(x-sampleModelTranslateX, - y-sampleModelTranslateY, - w, h, b, fArray, dataBuffer); - } - - public void setSamples(int x, int y, int w, int h, int b, - double[] dArray) - { - sampleModel.setSamples(x-sampleModelTranslateX, - y-sampleModelTranslateY, - w, h, b, dArray, dataBuffer); - } -} diff --git a/libjava/java/awt/image/WritableRenderedImage.java b/libjava/java/awt/image/WritableRenderedImage.java deleted file mode 100644 index 4ed9f101371..00000000000 --- a/libjava/java/awt/image/WritableRenderedImage.java +++ /dev/null @@ -1,56 +0,0 @@ -/* WritableRenderedImage.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.image; - -import java.awt.Point; - -/** - * NEEDS DOCUMENTATION - */ -public interface WritableRenderedImage extends RenderedImage -{ - void addTileObserver(TileObserver to); - void removeTileObserver(TileObserver to); - WritableRaster getWritableTile(int x, int y); - void releaseWritableTile(int x, int y); - boolean isTileWritable(int x, int y); - Point[] getWritableTileIndices(); - boolean hasTileWriters(); - void setData(Raster r); -} // interface WritableRenderedImage diff --git a/libjava/java/awt/image/renderable/ContextualRenderedImageFactory.java b/libjava/java/awt/image/renderable/ContextualRenderedImageFactory.java deleted file mode 100644 index 729d857ac89..00000000000 --- a/libjava/java/awt/image/renderable/ContextualRenderedImageFactory.java +++ /dev/null @@ -1,56 +0,0 @@ -/* ContextualRenderedImageFactory.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.image.renderable; - -import java.awt.geom.Rectangle2D; -import java.awt.image.RenderedImage; - -/** - * STUBBED - */ -public interface ContextualRenderedImageFactory extends RenderedImageFactory -{ - RenderContext mapRenderContext(int i, RenderContext context, - ParameterBlock block, RenderableImage image); - RenderedImage create(RenderContext context, ParameterBlock block); - Rectangle2D getBounds2D(ParameterBlock block); - Object getProperty(ParameterBlock block, String name); - String[] getPropertyNames(); - boolean isDynamic(); -} // interface ContextualRenderedImageFactory diff --git a/libjava/java/awt/image/renderable/ParameterBlock.java b/libjava/java/awt/image/renderable/ParameterBlock.java deleted file mode 100644 index 879d3c4fb90..00000000000 --- a/libjava/java/awt/image/renderable/ParameterBlock.java +++ /dev/null @@ -1,308 +0,0 @@ -/* ParameterBlock.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.image.renderable; - -import java.awt.image.RenderedImage; -import java.io.Serializable; -import java.util.Vector; - -public class ParameterBlock implements Cloneable, Serializable -{ - private static final long serialVersionUID = -7577115551785240750L; - protected Vector sources; - protected Vector parameters; - - public ParameterBlock() - { - this(new Vector(), new Vector()); - } - - public ParameterBlock(Vector sources) - { - this(sources, new Vector()); - } - - public ParameterBlock(Vector sources, Vector parameters) - { - this.sources = sources; - this.parameters = parameters; - } - - public Object shallowClone() - { - try - { - return super.clone(); - } - catch (CloneNotSupportedException e) - { - throw (Error) new InternalError().initCause(e); // impossible - } - } - - public Object clone() - { - ParameterBlock pb = (ParameterBlock) shallowClone(); - if (sources != null) - pb.sources = (Vector) sources.clone(); - if (parameters != null) - pb.parameters = (Vector) parameters.clone(); - return pb; - } - - public ParameterBlock addSource(Object source) - { - sources.add(source); - return this; - } - - public Object getSource(int index) - { - return sources.get(index); - } - - public ParameterBlock setSource(Object source, int index) - { - sources.ensureCapacity(index); - sources.set(index, source); - return this; - } - - public RenderedImage getRenderedSource(int index) - { - return (RenderedImage) sources.get(index); - } - - public RenderableImage getRenderableSource(int index) - { - return (RenderableImage) sources.get(index); - } - - public int getNumSources() - { - return sources.size(); - } - - public Vector getSources() - { - return sources; - } - - public void setSources(Vector sources) - { - this.sources = sources; - } - - public void removeSources() - { - if (sources != null) - sources.clear(); - } - - public int getNumParameters() - { - return parameters.size(); - } - - public Vector getParameters() - { - return parameters; - } - - public void setParameters(Vector parameters) - { - this.parameters = parameters; - } - - public void removeParameters() - { - if (parameters != null) - parameters.clear(); - } - - public ParameterBlock add(Object o) - { - parameters.add(o); - return this; - } - - public ParameterBlock add(byte b) - { - return add(new Byte(b)); - } - - public ParameterBlock add(char c) - { - return add(new Character(c)); - } - - public ParameterBlock add(short s) - { - return add(new Short(s)); - } - - public ParameterBlock add(int i) - { - return add(new Integer(i)); - } - - public ParameterBlock add(long l) - { - return add(new Long(l)); - } - - public ParameterBlock add(float f) - { - return add(new Float(f)); - } - - public ParameterBlock add(double d) - { - return add(new Double(d)); - } - - public ParameterBlock set(Object o, int index) - { - parameters.ensureCapacity(index); - parameters.set(index, o); - return this; - } - - public ParameterBlock set(byte b, int index) - { - return set(new Byte(b), index); - } - - public ParameterBlock set(char c, int index) - { - return set(new Character(c), index); - } - - public ParameterBlock set(short s, int index) - { - return set(new Short(s), index); - } - - public ParameterBlock set(int i, int index) - { - return set(new Integer(i), index); - } - - public ParameterBlock set(long l, int index) - { - return set(new Long(l), index); - } - - public ParameterBlock set(float f, int index) - { - return set(new Float(f), index); - } - - public ParameterBlock set(double d, int index) - { - return set(new Double(d), index); - } - - public Object getObjectParameter(int index) - { - return parameters.get(index); - } - - public byte getByteParameter(int index) - { - return ((Byte) parameters.get(index)).byteValue(); - } - - public char getCharParameter(int index) - { - return ((Character) parameters.get(index)).charValue(); - } - - public short getShortParameter(int index) - { - return ((Short) parameters.get(index)).shortValue(); - } - - public int getIntParameter(int index) - { - return ((Integer) parameters.get(index)).intValue(); - } - - public long getLongParameter(int index) - { - return ((Long) parameters.get(index)).longValue(); - } - - public float getFloatParameter(int index) - { - return ((Float) parameters.get(index)).floatValue(); - } - - public double getDoubleParameter(int index) - { - return ((Double) parameters.get(index)).doubleValue(); - } - - public Class[] getParamClasses() - { - int i = parameters.size(); - Class[] result = new Class[i]; - while (--i >= 0) - { - Class c = parameters.get(i).getClass(); - if (c == Byte.class) - result[i] = byte.class; - else if (c == Character.class) - result[i] = char.class; - else if (c == Short.class) - result[i] = short.class; - else if (c == Integer.class) - result[i] = int.class; - else if (c == Long.class) - result[i] = long.class; - else if (c == Float.class) - result[i] = float.class; - else if (c == Double.class) - result[i] = double.class; - else - result[i] = c; - } - return result; - } -} // class ParameterBlock diff --git a/libjava/java/awt/image/renderable/RenderContext.java b/libjava/java/awt/image/renderable/RenderContext.java deleted file mode 100644 index 67f0b8adb23..00000000000 --- a/libjava/java/awt/image/renderable/RenderContext.java +++ /dev/null @@ -1,141 +0,0 @@ -/* RenderContext.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.image.renderable; - -import java.awt.RenderingHints; -import java.awt.Shape; -import java.awt.geom.AffineTransform; - -public class RenderContext implements Cloneable -{ - private AffineTransform xform; - private Shape aoi; - private RenderingHints hints; - - public RenderContext(AffineTransform xform, Shape aoi, RenderingHints hints) - { - this.xform = xform; - this.aoi = aoi; - this.hints = hints; - } - - public RenderContext(AffineTransform xform) - { - this(xform, null, null); - } - - public RenderContext(AffineTransform xform, RenderingHints hints) - { - this(xform, null, hints); - } - - public RenderContext(AffineTransform xform, Shape aoi) - { - this(xform, aoi, null); - } - - public RenderingHints getRenderingHints() - { - return hints; - } - - public void setRenderingHints(RenderingHints hints) - { - this.hints = hints; - } - - public void setTransform(AffineTransform xform) - { - this.xform = xform; - } - - public void preConcatenateTransform(AffineTransform pre) - { - preConcetenateTransform (pre); - } - - /** @deprecated */ - public void preConcetenateTransform(AffineTransform pre) - { - xform.preConcatenate (pre); - } - - public void concatenateTransform(AffineTransform post) - { - concetenateTransform (post); - } - - /** @deprecated */ - public void concetenateTransform(AffineTransform post) - { - xform.concatenate (post); - } - - public AffineTransform getTransform() - { - return xform; - } - - public void setAreaOfInterest(Shape aoi) - { - this.aoi = aoi; - } - - public Shape getAreaOfInterest() - { - return aoi; - } - - public Object clone() - { - try - { - RenderContext copy = (RenderContext) super.clone(); - if (xform != null) - copy.xform = (AffineTransform) xform.clone(); - if (hints != null) - copy.hints = (RenderingHints) hints.clone(); - return copy; - } - catch (CloneNotSupportedException e) - { - throw (Error) new InternalError().initCause(e); // impossible - } - } -} // class RenderContext diff --git a/libjava/java/awt/image/renderable/RenderableImage.java b/libjava/java/awt/image/renderable/RenderableImage.java deleted file mode 100644 index 45d2eb7ebf0..00000000000 --- a/libjava/java/awt/image/renderable/RenderableImage.java +++ /dev/null @@ -1,62 +0,0 @@ -/* RenderableImage.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.image.renderable; - -import java.awt.RenderingHints; -import java.awt.image.RenderedImage; -import java.util.Vector; - -public interface RenderableImage -{ - String HINTS_OBSERVED = "HINTS_OBSERVED"; - - Vector getSources(); - Object getProperty(String name); - String[] getPropertyNames(); - boolean isDynamic(); - float getWidth(); - float getHeight(); - float getMinX(); - float getMinY(); - RenderedImage createScaledRendering(int w, int h, RenderingHints hints); - RenderedImage createDefaultRendering(); - RenderedImage createRendering(RenderContext context); - -} // interface RenderableImage - diff --git a/libjava/java/awt/image/renderable/RenderableImageOp.java b/libjava/java/awt/image/renderable/RenderableImageOp.java deleted file mode 100644 index 5385a82a317..00000000000 --- a/libjava/java/awt/image/renderable/RenderableImageOp.java +++ /dev/null @@ -1,157 +0,0 @@ -/* RenderableImageOp.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.image.renderable; - -import java.awt.RenderingHints; -import java.awt.geom.AffineTransform; -import java.awt.image.RenderedImage; -import java.util.Vector; - -public class RenderableImageOp implements RenderableImage -{ - private final ContextualRenderedImageFactory crif; - private ParameterBlock block; - - public RenderableImageOp(ContextualRenderedImageFactory crif, - ParameterBlock block) - { - this.crif = crif; - this.block = (ParameterBlock) block.clone(); - } - - public Vector getSources() - { - if (block.sources == null) - return null; - int size = block.sources.size(); - Vector v = new Vector(); - for (int i = 0; i < size; i++) - { - Object o = block.sources.get(i); - if (o instanceof RenderableImage) - v.add(o); - } - return v; - } - - public Object getProperty(String name) - { - return crif.getProperty(block, name); - } - - public String[] getPropertyNames() - { - return crif.getPropertyNames(); - } - - public boolean isDynamic() - { - return crif.isDynamic(); - } - - public float getWidth() - { - return (float) crif.getBounds2D(block).getWidth(); - } - - public float getHeight() - { - return (float) crif.getBounds2D(block).getHeight(); - } - - public float getMinX() - { - return (float) crif.getBounds2D(block).getX(); - } - - public float getMinY() - { - return (float) crif.getBounds2D(block).getY(); - } - - public ParameterBlock setParameterBlock(ParameterBlock block) - { - ParameterBlock result = this.block; - this.block = (ParameterBlock) block.clone(); - return result; - } - - public ParameterBlock getParameterBlock() - { - return block; - } - - public RenderedImage createScaledRendering(int w, int h, - RenderingHints hints) - { - if (w == 0) - if (h == 0) - throw new IllegalArgumentException(); - else - w = Math.round(h * getWidth() / getHeight()); - if (h == 0) - h = Math.round(w * getHeight() / getWidth()); - AffineTransform xform = AffineTransform.getScaleInstance(w * getWidth(), - h * getHeight()); - return createRendering(new RenderContext(xform, hints)); - } - - public RenderedImage createDefaultRendering() - { - return createRendering(new RenderContext(new AffineTransform())); - } - - public RenderedImage createRendering(RenderContext context) - { - ParameterBlock copy = (ParameterBlock) block.clone(); - int i = block.sources.size(); - while (--i >= 0) - { - Object o = block.sources.get(i); - if (o instanceof RenderableImage) - { - RenderableImage ri = (RenderableImage) o; - RenderContext rc = crif.mapRenderContext(i, context, block, ri); - copy.sources.set(i, ri.createRendering(rc)); - } - } - // Now copy.sources should be only RenderedImages. - return crif.create(context, copy); - } -} // class RenderableImageOp diff --git a/libjava/java/awt/image/renderable/RenderableImageProducer.java b/libjava/java/awt/image/renderable/RenderableImageProducer.java deleted file mode 100644 index 78f3051ea99..00000000000 --- a/libjava/java/awt/image/renderable/RenderableImageProducer.java +++ /dev/null @@ -1,79 +0,0 @@ -/* RenderableImageProducer.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.image.renderable; - -import java.awt.image.ImageConsumer; -import java.awt.image.ImageProducer; - -public class RenderableImageProducer implements ImageProducer, Runnable -{ - public RenderableImageProducer(RenderableImage image, RenderContext context) - { - throw new Error("not implemented"); - } - - public void setRenderContext(RenderContext context) - { - } - - public void addConsumer(ImageConsumer consumer) - { - } - - public boolean isConsumer(ImageConsumer consumer) - { - return false; - } - - public void removeConsumer(ImageConsumer consumer) - { - } - - public void startProduction(ImageConsumer consumer) - { - } - - public void requestTopDownLeftRightResend(ImageConsumer consumer) - { - } - - public void run() - { - } -} // class RenderableImageProducer diff --git a/libjava/java/awt/image/renderable/RenderedImageFactory.java b/libjava/java/awt/image/renderable/RenderedImageFactory.java deleted file mode 100644 index 6ff4cb03176..00000000000 --- a/libjava/java/awt/image/renderable/RenderedImageFactory.java +++ /dev/null @@ -1,47 +0,0 @@ -/* RenderedImageFactory.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.image.renderable; - -import java.awt.RenderingHints; -import java.awt.image.RenderedImage; - -public interface RenderedImageFactory -{ - RenderedImage create(ParameterBlock block, RenderingHints hints); -} // interface RenderedImageFactory diff --git a/libjava/java/awt/peer/ButtonPeer.java b/libjava/java/awt/peer/ButtonPeer.java deleted file mode 100644 index a55fc2236db..00000000000 --- a/libjava/java/awt/peer/ButtonPeer.java +++ /dev/null @@ -1,46 +0,0 @@ -/* ButtonPeer.java -- Peer interface for buttons - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.peer; - -public interface ButtonPeer extends ComponentPeer -{ - void setLabel (String label); - -} // interface ButtonPeer - diff --git a/libjava/java/awt/peer/CanvasPeer.java b/libjava/java/awt/peer/CanvasPeer.java deleted file mode 100644 index 4b33835a455..00000000000 --- a/libjava/java/awt/peer/CanvasPeer.java +++ /dev/null @@ -1,45 +0,0 @@ -/* CanvasPeer.java -- Peer interface for a canvas - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.peer; - -public interface CanvasPeer extends ComponentPeer -{ - -} // interface CanvasPeer - diff --git a/libjava/java/awt/peer/CheckboxMenuItemPeer.java b/libjava/java/awt/peer/CheckboxMenuItemPeer.java deleted file mode 100644 index 5213dc90693..00000000000 --- a/libjava/java/awt/peer/CheckboxMenuItemPeer.java +++ /dev/null @@ -1,46 +0,0 @@ -/* CheckboxMenuItemPeer.java -- Peer interface for checkbox menu items - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.peer; - -public interface CheckboxMenuItemPeer extends MenuItemPeer -{ - void setState (boolean state); - -} // interface CheckboxMenuItemPeer - diff --git a/libjava/java/awt/peer/CheckboxPeer.java b/libjava/java/awt/peer/CheckboxPeer.java deleted file mode 100644 index 8b23b3f6f33..00000000000 --- a/libjava/java/awt/peer/CheckboxPeer.java +++ /dev/null @@ -1,52 +0,0 @@ -/* CheckboxPeer.java -- Interface for checkbox peer - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.peer; - -import java.awt.CheckboxGroup; - -public interface CheckboxPeer extends ComponentPeer -{ - void setCheckboxGroup (CheckboxGroup group); - - void setLabel (String label); - - void setState (boolean state); - -} // interface CheckboxPeer - diff --git a/libjava/java/awt/peer/ChoicePeer.java b/libjava/java/awt/peer/ChoicePeer.java deleted file mode 100644 index 8ed11072e15..00000000000 --- a/libjava/java/awt/peer/ChoicePeer.java +++ /dev/null @@ -1,54 +0,0 @@ -/* ChoicePeer.java -- Peer for choice box - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.peer; - -public interface ChoicePeer extends ComponentPeer -{ - void add (String item, int index); - - void addItem (String item, int index); - - void remove (int index); - - void removeAll(); - - void select (int index); - -} // interface ChoicePeer - diff --git a/libjava/java/awt/peer/ComponentPeer.java b/libjava/java/awt/peer/ComponentPeer.java deleted file mode 100644 index 7ed8f6051db..00000000000 --- a/libjava/java/awt/peer/ComponentPeer.java +++ /dev/null @@ -1,187 +0,0 @@ -/* ComponentPeer.java -- Toplevel component peer - Copyright (C) 1999, 2000, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.peer; - -import java.awt.AWTEvent; -import java.awt.AWTException; -import java.awt.BufferCapabilities; -import java.awt.Color; -import java.awt.Component; -import java.awt.Cursor; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.FontMetrics; -import java.awt.Graphics; -import java.awt.GraphicsConfiguration; -import java.awt.Image; -import java.awt.Point; -import java.awt.Toolkit; -import java.awt.event.PaintEvent; -import java.awt.image.ColorModel; -import java.awt.image.ImageObserver; -import java.awt.image.ImageProducer; -import java.awt.image.VolatileImage; - -public interface ComponentPeer -{ - int checkImage(Image img, int width, int height, - ImageObserver ob); - Image createImage(ImageProducer prod); - Image createImage(int width, int height); - void disable(); - void dispose(); - void enable(); - ColorModel getColorModel(); - FontMetrics getFontMetrics(Font f); - Graphics getGraphics(); - Point getLocationOnScreen(); - Dimension getMinimumSize(); - Dimension getPreferredSize(); - Toolkit getToolkit(); - void handleEvent(AWTEvent e); - void hide(); - - /** - * Part of the earlier 1.1 API, replaced by isFocusable(). - */ - boolean isFocusTraversable(); - boolean isFocusable(); - Dimension minimumSize(); - Dimension preferredSize(); - void paint(Graphics graphics); - boolean prepareImage(Image img, int width, int height, - ImageObserver ob); - void print(Graphics graphics); - void repaint(long tm, int x, int y, int width, int height); - - /** - * Part of the earlier 1.1 API, apparently replaced by argument - * form of the same method. - */ - void requestFocus(); - boolean requestFocus (Component source, boolean bool1, boolean bool2, long x); - - void reshape(int x, int y, int width, int height); - void setBackground(Color color); - void setBounds(int x, int y, int width, int height); - - /** - * Part of the earlier 1.1 API, apparently no longer needed. - */ - void setCursor(Cursor cursor); - - void setEnabled(boolean enabled); - void setFont(Font font); - void setForeground(Color color); - void setVisible(boolean visible); - void show(); - - /** - * Get the graphics configuration of the component. The color model - * of the component can be derived from the configuration. - */ - GraphicsConfiguration getGraphicsConfiguration(); - - /** - * Part of an older API, no longer needed. - */ - void setEventMask (long mask); - - // Methods below are introduced since 1.1 - boolean isObscured(); - boolean canDetermineObscurity(); - void coalescePaintEvent(PaintEvent e); - void updateCursorImmediately(); - boolean handlesWheelScrolling(); - - /** - * A convenience method that creates a volatile image. The volatile - * image is created on the screen device on which this component is - * displayed, in the device's current graphics configuration. - * - * @param width width of the image - * @param height height of the image - * - * @see VolatileImage - * - * @since 1.2 - */ - VolatileImage createVolatileImage(int width, int height); - - /** - * Create a number of image buffers that implement a buffering - * strategy according to the given capabilities. - * - * @param numBuffers the number of buffers - * @param caps the buffering capabilities - * - * @throws AWTException if the specified buffering strategy is not - * implemented - * - * @since 1.2 - */ - void createBuffers(int numBuffers, BufferCapabilities caps) - throws AWTException; - - /** - * Return the back buffer of this component. - * - * @return the back buffer of this component. - * - * @since 1.2 - */ - Image getBackBuffer(); - - /** - * Perform a page flip, leaving the contents of the back buffer in - * the specified state. - * - * @param contents the state in which to leave the back buffer - * - * @since 1.2 - */ - void flip(BufferCapabilities.FlipContents contents); - - /** - * Destroy the resources created by createBuffers. - * - * @since 1.2 - */ - void destroyBuffers(); -} diff --git a/libjava/java/awt/peer/ContainerPeer.java b/libjava/java/awt/peer/ContainerPeer.java deleted file mode 100644 index f1373a16472..00000000000 --- a/libjava/java/awt/peer/ContainerPeer.java +++ /dev/null @@ -1,59 +0,0 @@ -/* ContainerPeer.java -- Interface for container peers - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.awt.peer; - -import java.awt.Insets; - -public interface ContainerPeer extends ComponentPeer -{ - Insets insets(); - - Insets getInsets(); - - void beginValidate(); - - void endValidate(); - - void beginLayout(); - - void endLayout(); - - boolean isPaintPending(); - -} // interface ContainerPeer - diff --git a/libjava/java/awt/peer/DialogPeer.java b/libjava/java/awt/peer/DialogPeer.java deleted file mode 100644 index e26d64ff96a..00000000000 --- a/libjava/java/awt/peer/DialogPeer.java +++ /dev/null @@ -1,48 +0,0 @@ -/* DialogPeer.java -- Interface for dialog box peer - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.peer; - -public interface DialogPeer extends WindowPeer -{ - void setResizable (boolean resizeable); - - void setTitle (String title); - -} // interface DialogPeer - diff --git a/libjava/java/awt/peer/FileDialogPeer.java b/libjava/java/awt/peer/FileDialogPeer.java deleted file mode 100644 index 7db1798162a..00000000000 --- a/libjava/java/awt/peer/FileDialogPeer.java +++ /dev/null @@ -1,52 +0,0 @@ -/* FileDialogPeer.java -- Interface for file selection dialog box peer - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.peer; - -import java.io.FilenameFilter; - -public interface FileDialogPeer extends DialogPeer -{ - void setFile (String file); - - void setDirectory (String dir); - - void setFilenameFilter (FilenameFilter ff); - -} // interface FileDialogPeer - diff --git a/libjava/java/awt/peer/FontPeer.java b/libjava/java/awt/peer/FontPeer.java deleted file mode 100644 index f0ba6d830c8..00000000000 --- a/libjava/java/awt/peer/FontPeer.java +++ /dev/null @@ -1,45 +0,0 @@ -/* FontPeer.java -- Interface for font peers - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.peer; - -public interface FontPeer -{ - -} // interface FontPeer - diff --git a/libjava/java/awt/peer/FramePeer.java b/libjava/java/awt/peer/FramePeer.java deleted file mode 100644 index 13498ff2f67..00000000000 --- a/libjava/java/awt/peer/FramePeer.java +++ /dev/null @@ -1,55 +0,0 @@ -/* FramePeer.java -- Interface for frame peers - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.peer; - -import java.awt.Image; -import java.awt.MenuBar; -import java.awt.Rectangle; - -public interface FramePeer extends WindowPeer -{ - void setIconImage(Image image); - void setMenuBar(MenuBar mb); - void setResizable(boolean resizable); - void setTitle(String title); - int getState(); - void setState(int state); - void setMaximizedBounds(Rectangle r); -} // interface FramePeer - diff --git a/libjava/java/awt/peer/LabelPeer.java b/libjava/java/awt/peer/LabelPeer.java deleted file mode 100644 index d0fca462fdc..00000000000 --- a/libjava/java/awt/peer/LabelPeer.java +++ /dev/null @@ -1,46 +0,0 @@ -/* LabelPeer.java -- Interface for simple text lable peer - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.peer; - -public interface LabelPeer extends ComponentPeer -{ - void setAlignment(int alignment); - void setText(String text); -} // interface LabelPeer - diff --git a/libjava/java/awt/peer/LightweightPeer.java b/libjava/java/awt/peer/LightweightPeer.java deleted file mode 100644 index 93cad7a0318..00000000000 --- a/libjava/java/awt/peer/LightweightPeer.java +++ /dev/null @@ -1,45 +0,0 @@ -/* LightweightPeer.java -- Interface for lightweight peers - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.peer; - -public interface LightweightPeer extends ComponentPeer -{ - -} // interface LightweightPeer - diff --git a/libjava/java/awt/peer/ListPeer.java b/libjava/java/awt/peer/ListPeer.java deleted file mode 100644 index c0f765d1655..00000000000 --- a/libjava/java/awt/peer/ListPeer.java +++ /dev/null @@ -1,61 +0,0 @@ -/* ListPeer.java -- Interface for list box peer - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.peer; - -import java.awt.Dimension; - -public interface ListPeer extends ComponentPeer -{ - void add(String item, int index); - void addItem(String item, int index); - void clear(); - void delItems(int start_index, int end_index); - void deselect(int index); - int[] getSelectedIndexes(); - void makeVisible(int index); - Dimension minimumSize(int s); - Dimension preferredSize(int s); - void removeAll(); - void select(int index); - void setMultipleMode(boolean multi); - void setMultipleSelections(boolean multi); - Dimension getPreferredSize(int s); - Dimension getMinimumSize(int s); -} // interface ListPeer - diff --git a/libjava/java/awt/peer/MenuBarPeer.java b/libjava/java/awt/peer/MenuBarPeer.java deleted file mode 100644 index c5f7c581ff5..00000000000 --- a/libjava/java/awt/peer/MenuBarPeer.java +++ /dev/null @@ -1,48 +0,0 @@ -/* MenuBarPeer.java -- Interface for menu bar peer - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.peer; - -import java.awt.Menu; - -public interface MenuBarPeer extends MenuComponentPeer -{ - void addHelpMenu(Menu menu); - void delMenu(int index); -} // interface MenuBarPeer - diff --git a/libjava/java/awt/peer/MenuComponentPeer.java b/libjava/java/awt/peer/MenuComponentPeer.java deleted file mode 100644 index 1b10ca1f4c7..00000000000 --- a/libjava/java/awt/peer/MenuComponentPeer.java +++ /dev/null @@ -1,45 +0,0 @@ -/* MenuComponentPeer.java -- - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.peer; - -public interface MenuComponentPeer -{ - void dispose(); -} // interface MenuComponentPeer - diff --git a/libjava/java/awt/peer/MenuItemPeer.java b/libjava/java/awt/peer/MenuItemPeer.java deleted file mode 100644 index 3ba1027e501..00000000000 --- a/libjava/java/awt/peer/MenuItemPeer.java +++ /dev/null @@ -1,48 +0,0 @@ -/* MenuItemPeer.java -- Interface for menu item peers - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.peer; - -public interface MenuItemPeer extends MenuComponentPeer -{ - void disable(); - void enable(); - void setEnabled(boolean enabled); - void setLabel(String text); -} // interface MenuItemPeer - diff --git a/libjava/java/awt/peer/MenuPeer.java b/libjava/java/awt/peer/MenuPeer.java deleted file mode 100644 index c51ea73bb6c..00000000000 --- a/libjava/java/awt/peer/MenuPeer.java +++ /dev/null @@ -1,48 +0,0 @@ -/* MenuPeer.java -- Interface for menu peers - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.peer; - -import java.awt.MenuItem; - -public interface MenuPeer extends MenuItemPeer -{ - void addItem (MenuItem item); - void delItem (int index); -} - diff --git a/libjava/java/awt/peer/PanelPeer.java b/libjava/java/awt/peer/PanelPeer.java deleted file mode 100644 index 192632e46b3..00000000000 --- a/libjava/java/awt/peer/PanelPeer.java +++ /dev/null @@ -1,45 +0,0 @@ -/* PanelPeer.java -- Interface for panel peers - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.peer; - -public interface PanelPeer extends ContainerPeer -{ - -} // interface PanelPeer - diff --git a/libjava/java/awt/peer/PopupMenuPeer.java b/libjava/java/awt/peer/PopupMenuPeer.java deleted file mode 100644 index 2e8f4bbedc5..00000000000 --- a/libjava/java/awt/peer/PopupMenuPeer.java +++ /dev/null @@ -1,53 +0,0 @@ -/* PopupMenuPeer.java -- Interface for popup menu peers - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.peer; - -import java.awt.Component; -import java.awt.Event; - -public interface PopupMenuPeer extends MenuPeer -{ - /** - * Part of the older API, replaced by event version instead. - */ - void show (Component origin, int x, int y); - - void show (Event e); -} // interface PopupMenuPeer - diff --git a/libjava/java/awt/peer/RobotPeer.java b/libjava/java/awt/peer/RobotPeer.java deleted file mode 100644 index db81c809d72..00000000000 --- a/libjava/java/awt/peer/RobotPeer.java +++ /dev/null @@ -1,54 +0,0 @@ -/* RobotPeer.java -- Interface for programatically driving GUI - Copyright (C) 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.peer; - -import java.awt.Rectangle; - -public interface RobotPeer -{ - void mouseMove (int x, int y); - void mousePress (int buttons); - void mouseRelease (int buttons); - void mouseWheel (int wheelAmt); - void keyPress (int keycode); - void keyRelease (int keycode); - int getRGBPixel (int x, int y); - int[] getRGBPixels (Rectangle screen); -} // interface RobotPeer - diff --git a/libjava/java/awt/peer/ScrollPanePeer.java b/libjava/java/awt/peer/ScrollPanePeer.java deleted file mode 100644 index de4331e04d1..00000000000 --- a/libjava/java/awt/peer/ScrollPanePeer.java +++ /dev/null @@ -1,52 +0,0 @@ -/* ScrollPanePeer.java -- Interface for scrollable panes - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.peer; - -import java.awt.Adjustable; - -public interface ScrollPanePeer extends ContainerPeer -{ - int getHScrollbarHeight(); - int getVScrollbarWidth(); - void setScrollPosition(int h, int v); - void childResized(int width, int height); - void setUnitIncrement(Adjustable item, int inc); - void setValue(Adjustable item, int value); -} // interface ScollPanePeer - diff --git a/libjava/java/awt/peer/ScrollbarPeer.java b/libjava/java/awt/peer/ScrollbarPeer.java deleted file mode 100644 index fe4f24d649f..00000000000 --- a/libjava/java/awt/peer/ScrollbarPeer.java +++ /dev/null @@ -1,47 +0,0 @@ -/* ScrollbarPeer.java -- Interface for scrollbar peers - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.peer; - -public interface ScrollbarPeer extends ComponentPeer -{ - void setLineIncrement(int inc); - void setPageIncrement(int inc); - void setValues(int value, int visible, int min, int max); -} // interface ScrollbarPeer - diff --git a/libjava/java/awt/peer/TextAreaPeer.java b/libjava/java/awt/peer/TextAreaPeer.java deleted file mode 100644 index 354e46d9cc6..00000000000 --- a/libjava/java/awt/peer/TextAreaPeer.java +++ /dev/null @@ -1,53 +0,0 @@ -/* TextAreaPeer.java -- Interface for text area peers - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.peer; - -import java.awt.Dimension; - -public interface TextAreaPeer extends TextComponentPeer -{ - void insert(String text, int pos); - void insertText(String text, int pos); - Dimension minimumSize(int rows, int cols); - Dimension getMinimumSize(int rows, int cols); - Dimension preferredSize(int rows, int cols); - Dimension getPreferredSize(int rows, int cols); - void replaceRange(String text, int start_pos, int end_pos); - void replaceText(String text, int start_pos, int end_pos); -} // interface TextAreaPeer diff --git a/libjava/java/awt/peer/TextComponentPeer.java b/libjava/java/awt/peer/TextComponentPeer.java deleted file mode 100644 index cacc7d8de4e..00000000000 --- a/libjava/java/awt/peer/TextComponentPeer.java +++ /dev/null @@ -1,57 +0,0 @@ -/* TextComponentPeer.java -- Superclass interface for text components - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.peer; - -import java.awt.Rectangle; - -public interface TextComponentPeer extends ComponentPeer -{ - int getSelectionEnd(); - int getSelectionStart(); - String getText(); - void setText(String text); - void select(int start_pos, int end_pos); - void setEditable(boolean editable); - int getCaretPosition(); - void setCaretPosition(int pos); - int getIndexAtPoint(int x, int y); - Rectangle getCharacterBounds(int pos); - long filterEvents(long filter); -} // interface TextComponentPeer - diff --git a/libjava/java/awt/peer/TextFieldPeer.java b/libjava/java/awt/peer/TextFieldPeer.java deleted file mode 100644 index e68d6663fdc..00000000000 --- a/libjava/java/awt/peer/TextFieldPeer.java +++ /dev/null @@ -1,52 +0,0 @@ -/* TextFieldPeer.java -- Interface for text field peers - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.peer; - -import java.awt.Dimension; - -public interface TextFieldPeer extends TextComponentPeer -{ - Dimension minimumSize(int len); - Dimension preferredSize(int len); - Dimension getMinimumSize(int len); - Dimension getPreferredSize(int len); - void setEchoChar(char echo_char); - void setEchoCharacter(char echo_char); -} // interface TextFieldPeer - diff --git a/libjava/java/awt/peer/WindowPeer.java b/libjava/java/awt/peer/WindowPeer.java deleted file mode 100644 index 8f136dd2d85..00000000000 --- a/libjava/java/awt/peer/WindowPeer.java +++ /dev/null @@ -1,46 +0,0 @@ -/* WindowPeer.java -- Interface for window peers - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.peer; - -public interface WindowPeer extends ContainerPeer -{ - void toBack(); - void toFront(); -} // interface WindowPeer - diff --git a/libjava/java/awt/print/Book.java b/libjava/java/awt/print/Book.java deleted file mode 100644 index b084a1723f1..00000000000 --- a/libjava/java/awt/print/Book.java +++ /dev/null @@ -1,159 +0,0 @@ -/* Book.java -- A mixed group of pages to print. - Copyright (C) 1999, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.print; - -import java.util.Vector; - -/** - * This class allows documents to be created with different paper types, - * page formatters, and painters. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public class Book implements Pageable -{ - /** - * Painter objects for the book. - */ - Vector printables = new Vector(); - - /** - * Page formats for the book. - */ - Vector page_formats = new Vector(); - - /** - * Initializes a new instance of <code>Book</code> that is empty. - */ - public Book() - { - } - - /** - * Returns the number of pages in this book. - * - * @return The number of pages in this book. - */ - public int getNumberOfPages() - { - return printables.size(); - } - - /** - * This method returns the <code>PageFormat</code> object for the - * specified page. - * - * @param page_number The number of the page to get information for, where - * page numbers start at 0. - * - * @return The <code>PageFormat</code> object for the specified page. - * - * @exception IndexOutOfBoundsException If the page number is not valid. - */ - public PageFormat getPageFormat(int page_number) - { - return (PageFormat) page_formats.elementAt(page_number); - } - - /** - * This method returns the <code>Printable</code> object for the - * specified page. - * - * @param page_number The number of the page to get information for, where - * page numbers start at 0. - * - * @return The <code>Printable</code> object for the specified page. - * - * @exception IndexOutOfBoundsException If the page number is not valid. - */ - public Printable getPrintable(int page_number) - { - return (Printable) printables.elementAt(page_number); - } - - /** - * This method appends a page to the end of the book. - * - * @param printable The <code>Printable</code> for this page. - * @param page_format The <code>PageFormat</code> for this page. - * - * @exception NullPointerException If either argument is <code>null</code>. - */ - public void append(Printable printable, PageFormat page_format) - { - append(printable, page_format, 1); - } - - /** - * This method appends the specified number of pages to the end of the book. - * Each one will be associated with the specified <code>Printable</code> - * and <code>PageFormat</code>. - * - * @param printable The <code>Printable</code> for this page. - * @param page_format The <code>PageFormat</code> for this page. - * @param num_pages The number of pages to append. - * - * @exception NullPointerException If any argument is <code>null</code>. - */ - public void append(Printable printable, PageFormat page_format, int num_pages) - { - for (int i = 0; i < num_pages; i++) - { - printables.addElement(printable); - page_formats.addElement(page_format); - } - } - - /** - * This method changes the <code>Printable</code> and <code>PageFormat</code> - * for the specified page. The page must already exist or an exception - * will be thrown. - * - * @param page_num The page number to alter. - * @param printable The new <code>Printable</code> for the page. - * @param page_format The new <code>PageFormat</code> for the page. - * - * @throws IndexOutOfBoundsException If the specified page does not exist. - */ - public void setPage(int page_num, Printable printable, PageFormat page_format) - { - printables.setElementAt(printable, page_num); - page_formats.setElementAt(page_format, page_num); - } -} diff --git a/libjava/java/awt/print/PageFormat.java b/libjava/java/awt/print/PageFormat.java deleted file mode 100644 index 6399552de44..00000000000 --- a/libjava/java/awt/print/PageFormat.java +++ /dev/null @@ -1,292 +0,0 @@ -/* PageFormat.java -- Information about the page format - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.print; - -/** - * This class contains information about the desired page format to - * use for printing a particular set of pages. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public class PageFormat implements Cloneable -{ - -/* - * Static Variables - */ - -/** - * A constant for a landscaped page orientation. Used by - * <code>getOrientation</code> and <code>setOrientation</code>. - */ -public static final int LANDSCAPE = 0; - -/** - * A constant for a portrait page orientation. Used by - * <code>getOrientation</code> and <code>setOrientation</code>. - */ -public static final int PORTRAIT = 1; - -/** - * A constant for a reversed landscaped page orientation. This is - * the orientation used by Macintosh's for landscape. The origin is - * in the upper right hand corner instead of the upper left. The - * X and Y axes are reversed. Used by <code>getOrientation</code> and - * <code>setOrientation</code>. - */ -public static final int REVERSE_LANDSCAPE = 2; - -/*************************************************************************/ - -/* - * Instance Variables - */ - -// The page orientation -private int orientation; - -// The paper type -private Paper paper; - -/*************************************************************************/ - -/* - * Constructors - */ - -/** - * This method creates a default page layout, which will be in portrait - * format. - */ -public -PageFormat() -{ - this.paper = new Paper(); - this.orientation = PORTRAIT; -} - -/*************************************************************************/ - -/* - * Instance Methods - */ - -/** - * This method returns the width of the page, in 1/72nd's of an inch. The - * "width" measured depends on orientation. - * - * @return The width of the page. - */ -public double -getWidth() -{ - return(paper.getWidth()); -} - -/*************************************************************************/ - -/** - * This method returns the height of the page, in 1/72nd's of an inch. - * The "height" measured depends on the orientation. - * - * @return The height of the page. - */ -public double -getHeight() -{ - return(paper.getHeight()); -} - -/*************************************************************************/ - -/** - * This method returns the X coordinate value of the upper leftmost - * drawable area of the paper. - * - * @return The upper leftmost imageable X coordinate. - */ -public double -getImageableX() -{ - return(paper.getImageableX()); -} - -/*************************************************************************/ - -/** - * This method returns the Y coordinate value of the upper leftmost - * drawable area of the paper. - * - * @return The upper leftmost imageable Y coordinate. - */ -public double -getImageableY() -{ - return(paper.getImageableY()); -} - -/*************************************************************************/ - -/** - * This method returns the imageable width of the paper, in 1/72nd's of - * an inch. - * - * @return The imageable width of the paper. - */ -public double -getImageableWidth() -{ - return(paper.getImageableWidth()); -} - -/*************************************************************************/ - -/** - * This method returns the imageable height of the paper, in 1/72nd's of - * an inch. - * - * @return The imageable height of the paper. - */ -public double getImageableHeight() -{ - return(paper.getImageableHeight()); -} - -/*************************************************************************/ - -/** - * Returns a copy of the <code>paper</code> object being used for this - * page format. - * - * @return A copy of the <code>Paper</code> object for this format. - */ -public Paper -getPaper() -{ - return((Paper)paper.clone()); -} - -/*************************************************************************/ - -/** - * Sets the <code>Paper</code> object to be used by this page format. - * - * @param paper The new <code>Paper</code> object for this page format. - */ -public void -setPaper(Paper paper) -{ - this.paper = paper; -} - -/*************************************************************************/ - -/** - * This method returns the current page orientation. The value returned - * will be one of the page orientation constants from this class. - * - * @return The current page orientation. - */ -public int -getOrientation() -{ - return(orientation); -} - -/*************************************************************************/ - -/** - * This method sets the page orientation for this format to the - * specified value. It must be one of the page orientation constants - * from this class or an exception will be thrown. - * - * @param orientation The new page orientation. - * - * @exception IllegalArgumentException If the specified page orientation - * value is not one of the constants from this class. - */ -public void -setOrientation(int orientation) throws IllegalArgumentException -{ - if ((orientation != PORTRAIT) && - (orientation != LANDSCAPE) && - (orientation != REVERSE_LANDSCAPE)) - throw new IllegalArgumentException("Bad page orientation value: " + - orientation); - - this.orientation = orientation; -} - -/*************************************************************************/ - -/** - * This method returns a matrix used for transforming user space - * coordinates to page coordinates. The value returned will be six - * doubles as described in <code>java.awt.geom.AffineTransform</code>. - * - * @return The transformation matrix for this page format. - */ -public double[] -getMatrix() -{ - throw new RuntimeException("Not implemented since I don't know what to do"); -} - -/*************************************************************************/ - -/** - * This method returns a copy of this object. - * - * @return A copy of this object. - */ -public Object -clone() -{ - try - { - return(super.clone()); - } - catch(CloneNotSupportedException e) - { - return(null); - } -} - -} // class PageFormat - diff --git a/libjava/java/awt/print/Pageable.java b/libjava/java/awt/print/Pageable.java deleted file mode 100644 index 12fa542a8c6..00000000000 --- a/libjava/java/awt/print/Pageable.java +++ /dev/null @@ -1,113 +0,0 @@ -/* Pageable.java -- Pages to be printed - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.print; - -/** - * This interface represents pages that are to be printed. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public interface Pageable -{ - -/* - * Static Variables - */ - -/** - * This constant is returned when <code>getNumberOfPages()</code> - * cannot determine the number of pages available for printing. - */ -int UNKNOWN_NUMBER_OF_PAGES = -1; - -/*************************************************************************/ - -/* - * Instance Methods - */ - -/** - * This method returns the number of pages this object contains, or - * <code>UNKNOWN_NUMBER_OF_PAGES</code> if it cannot determine the number - * of pages to be printed. - * - * @return The number of pages to be printed, or - * <code>UNKNOWN_NUMBER_OF_PAGES</code> if this is unknown. - */ -int -getNumberOfPages(); - -/*************************************************************************/ - -/** - * This method returns the <code>PageFormat</code> instance for the - * specified page. Page numbers start at zero. An exception is thrown if - * the requested page does not exist. - * - * @param pageIndex The index of the page to return the - * <code>PageFormat</code> for. - * - * @return The <code>PageFormat</code> for the requested page. - * - * @exception IndexOutOfBoundsException If the requested page number does - * not exist. - */ -PageFormat -getPageFormat(int pageIndex) throws IndexOutOfBoundsException; - -/*************************************************************************/ - -/** - * This method returns the <code>Printable</code> instance for the - * specified page. Page numbers start at zero. An exception is thrown if - * the requested page does not exist. - * - * @param pageIndex The index of the page to return the - * <code>Printable</code> for. - * - * @return The <code>Printable</code> for the requested page. - * - * @exception IndexOutOfBoundsException If the requested page number does - * not exist. - */ -Printable -getPrintable(int pageIndex) throws IndexOutOfBoundsException; - -} // interface Pageable - diff --git a/libjava/java/awt/print/Paper.java b/libjava/java/awt/print/Paper.java deleted file mode 100644 index 4579da3ea3c..00000000000 --- a/libjava/java/awt/print/Paper.java +++ /dev/null @@ -1,236 +0,0 @@ -/* Paper.java -- Information about a paper type. - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.print; - -/** - * This class describes a particular type of paper. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public class Paper implements Cloneable -{ - -/* - * Instance Variables - */ - -// Height of the paper -private double height; - -// Width of the paper -private double width; - -// Upper left imageable X coordinate -private double imageableX; - -// Upper left imageable Y coordinate -private double imageableY; - -// Imageable width of the page -private double imageableWidth; - -// Imageable height of the page -private double imageableHeight; - -/*************************************************************************/ - -/* - * Constructor - */ - -/** - * This method creates a letter sized paper with one inch margins - */ -public -Paper() -{ - width = 8.5 * 72; - height = 11 * 72; - imageableX = 72; - imageableY = 72; - imageableWidth = width - (2 * 72); - imageableHeight = height - (2 * 72); -} - -/*************************************************************************/ - -/** - * This method returns the height of the paper in 1/72nds of an inch. - * - * @return The height of the paper in 1/72nds of an inch. - */ -public double -getHeight() -{ - return(height); -} - -/*************************************************************************/ - -/** - * Returns the width of the paper in 1/72nds of an inch. - * - * @return The width of the paper in 1/72nds of an inch. - */ -public double -getWidth() -{ - return(width); -} - -/*************************************************************************/ - -/** - * This method returns the X coordinate of the upper left hand corner - * of the imageable area of the paper. - * - * @return The X coordinate of the upper left hand corner of the imageable - * area of the paper. - */ -public double -getImageableX() -{ - return(imageableX); -} - -/*************************************************************************/ - -/** - * This method returns the Y coordinate of the upper left hand corner - * of the imageable area of the paper. - * - * @return The Y coordinate of the upper left hand corner of the imageable - * area of the paper. - */ -public double -getImageableY() -{ - return(imageableY); -} - -/*************************************************************************/ - -/** - * Returns the width of the imageable area of the paper. - * - * @return The width of the imageable area of the paper. - */ -public double -getImageableWidth() -{ - return(imageableWidth); -} - -/*************************************************************************/ - -/** - * Returns the height of the imageable area of the paper. - * - * @return The height of the imageable area of the paper. - */ -public double -getImageableHeight() -{ - return(imageableHeight); -} - -/*************************************************************************/ - -/** - * This method sets the size of the paper to the specified width and - * height, which are specified in 1/72nds of an inch. - * - * @param width The width of the paper in 1/72nds of an inch. - * @param height The height of the paper in 1/72nds of an inch. - */ -public void -setSize(double width, double height) -{ - this.width = width; - this.height = height; -} - -/*************************************************************************/ - -/** - * This method sets the imageable area of the paper by specifying the - * coordinates of the upper left hand corner of that area, and its - * length and height. All values are in 1/72nds of an inch. - * - * @param imageableX The X coordinate of the upper left hand corner of - * the imageable area, in 1/72nds of an inch. - * @param imageableY The Y coordinate of the upper left hand corner of - * the imageable area, in 1/72nds of an inch. - * @param imageableWidth The width of the imageable area of the paper, - * in 1/72nds of an inch. - * @param imageableHeight The heigth of the imageable area of the paper, - * in 1/72nds of an inch. - */ -public void -setImageableArea(double imageableX, double imageableY, - double imageableWidth, double imageableHeight) -{ - this.imageableX = imageableX; - this.imageableY = imageableY; - this.imageableWidth = imageableWidth; - this.imageableHeight = imageableHeight; -} - -/*************************************************************************/ - -/** - * This method creates a copy of this object. - * - * @return A copy of this object. - */ -public Object -clone() -{ - try - { - return(super.clone()); - } - catch(CloneNotSupportedException e) - { - return(null); - } -} - -} // class Paper - diff --git a/libjava/java/awt/print/Printable.java b/libjava/java/awt/print/Printable.java deleted file mode 100644 index 775167e669d..00000000000 --- a/libjava/java/awt/print/Printable.java +++ /dev/null @@ -1,80 +0,0 @@ -/* Printable.java -- Renders a page to the print device - Copyright (C) 1999, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.awt.print; - -import java.awt.Graphics; - - -/** - * This interface provides a mechanism for the actual printing of pages to the - * printer. The object implementing this interface performs the page - * rendering. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public interface Printable -{ - /** - * This value is returned by the <code>print()</code> method to indicate - * that the requested page exists and has been printed. - */ - int PAGE_EXISTS = 0; - - /** - * This value is returned by the <code>print()</code> method to indicate - * that the requested page number does not exist. - */ - int NO_SUCH_PAGE = 1; - - /** - * This method prints the specified page to the specified graphics - * context in the specified format. The pages are numbered starting - * from zero. - * - * @param graphics The graphics context to render the pages on. - * @param format The format in which to print the page. - * @param page_number The page number to print, where numbers start at zero. - * - * @return <code>PAGE_EXISTS</code> if the requested page exists and was - * successfully printed, <code>NO_SUCH_PAGE</code> otherwise. - * - * @exception PrinterException If an error occurs during printing. - */ - int print(Graphics graphics, PageFormat format, int page_number) - throws PrinterException; -} diff --git a/libjava/java/awt/print/PrinterAbortException.java b/libjava/java/awt/print/PrinterAbortException.java deleted file mode 100644 index 4580630790d..00000000000 --- a/libjava/java/awt/print/PrinterAbortException.java +++ /dev/null @@ -1,71 +0,0 @@ -/* PrinterAbortException.java -- Indicates the print job was aborted - Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.print; - -/** - * This exception is thrown when the print job is aborted, either by the - * user or by the application. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @status updated to 1.4 - */ -public class PrinterAbortException extends PrinterException -{ - /** - * Compatible with JDK 1.2+. - */ - private static final long serialVersionUID = 4725169026278854136L; - - /** - * Create a new instance with no detailed error message. - */ - public PrinterAbortException() - { - } - - /** - * Create a new instance with a descriptive error message. - * - * @param message the descriptive error message - */ - public PrinterAbortException(String message) - { - super(message); - } -} // class PrinterAbortException diff --git a/libjava/java/awt/print/PrinterException.java b/libjava/java/awt/print/PrinterException.java deleted file mode 100644 index c105f549de4..00000000000 --- a/libjava/java/awt/print/PrinterException.java +++ /dev/null @@ -1,71 +0,0 @@ -/* PrinterException.java -- generic problem in the printing subsystem - Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.print; - -/** - * This is the generic toplevel exception for printing errors. Subclasses - * provide more detailed descriptions of the problem. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @status updated to 1.4 - */ -public class PrinterException extends Exception -{ - /** - * Compatible with JDK 1.2+. - */ - private static final long serialVersionUID = -3757589981158265819L; - - /** - * Create a new instance with no detailed error message. - */ - public PrinterException() - { - } - - /** - * Create a new instance with a descriptive error message. - * - * @param message the descriptive error message - */ - public PrinterException(String message) - { - super(message); - } -} // class PrinterException diff --git a/libjava/java/awt/print/PrinterGraphics.java b/libjava/java/awt/print/PrinterGraphics.java deleted file mode 100644 index 5ca64190424..00000000000 --- a/libjava/java/awt/print/PrinterGraphics.java +++ /dev/null @@ -1,61 +0,0 @@ -/* PrinterGraphics.java -- Hook to return print job controller. - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.print; - -/** - * This interface is implemented by the <code>Graphics</code> instance - * that is used for rendering pages. It provides a hook to return the - * object that is controlling the print job. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public interface PrinterGraphics -{ - -/** - * This method returns the instance of <code>PrinterJob</code> that is - * controlling this print job. - * - * @return The <code>PrinterJob</code> that is controlling this print job. - */ -PrinterJob -getPrinterJob(); - -} // interface PrinterGraphics - diff --git a/libjava/java/awt/print/PrinterIOException.java b/libjava/java/awt/print/PrinterIOException.java deleted file mode 100644 index c646acdec3a..00000000000 --- a/libjava/java/awt/print/PrinterIOException.java +++ /dev/null @@ -1,98 +0,0 @@ -/* PrinterIOException.java -- The print job encountered an I/O error - Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.print; - -import java.io.IOException; - -/** - * This exception is thrown when the print job encounters an I/O problem - * of some kind. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Eric Blake (ebb9@email.byu.edu) - * @status updated to 1.4 - */ -public class PrinterIOException extends PrinterException -{ - /** - * Compatible with JDK 1.2+. - */ - private static final long serialVersionUID = 5850870712125932846L; - - /** - * The exception that caused this (duplicates Throwable). - * - * @serial the I/O exception that terminated the job - */ - private final IOException mException; - - /** - * Initializes a new instance with the given cause. - * - * @param mException the cause - */ - public PrinterIOException(IOException mException) - { - super(mException == null ? null : mException.toString()); - initCause(mException); - this.mException = mException; - } - - /** - * Gets the underlying <code>IOException</code> that caused this exception. - * This legacy method has been replaced by {@link #getCause()}. - * - * @return the cause - */ - public IOException getIOException() - { - return mException; - } - - /** - * Gets the cause. - * - * @return the cause - */ - public Throwable getCause() - { - return mException; - } -} // class PrinterIOException - diff --git a/libjava/java/awt/print/PrinterJob.java b/libjava/java/awt/print/PrinterJob.java deleted file mode 100644 index e61ab61bc77..00000000000 --- a/libjava/java/awt/print/PrinterJob.java +++ /dev/null @@ -1,299 +0,0 @@ -/* PrinterJob.java -- This job is the printer control class - Copyright (C) 1999, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.print; - -import java.awt.HeadlessException; - -import javax.print.PrintService; -import javax.print.attribute.PrintRequestAttributeSet; - -/** - * This class controls printing. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public abstract class PrinterJob -{ - // The print service associated with this job - private PrintService printer = null; - - /** - * Creates a new print job. - * - * @return A <code>PrinterJob</code> object for the newly created print job. - */ - public static PrinterJob getPrinterJob() - { - // FIXME: Need to fix this to load a default implementation instance. - return null; - } - - /** - * Initializes a new instance of <code>PrinterJob</code>. - */ - public PrinterJob() - { - } - - /** - * Returns the number of copies to be printed. - * - * @return The number of copies to be printed. - */ - public abstract int getCopies(); - - /** - * Sets the number of copies to be printed. - * - * @param copies The number of copies to be printed. - */ - public abstract void setCopies(int copies); - - /** - * Returns the name of the print job. - * - * @return The name of the print job. - */ - public abstract String getJobName(); - - /** - * Sets the name of the print job. - * - * @param job_name The name of the print job. - */ - public abstract void setJobName(String job_name); - - /** - * Returns the printing user name. - * - * @return The printing username. - */ - public abstract String getUserName(); - - /** - * Cancels an in progress print job. - */ - public abstract void cancel(); - - /** - * Tests whether or not this job has been cancelled. - * - * @return <code>true</code> if this job has been cancelled, <code>false</code> - * otherwise. - */ - public abstract boolean isCancelled(); - - /** - * Returns an instance of the default page which will have the default - * paper and orientation. - * - * @return A default instance of <code>PageFormat</code>. - */ - public PageFormat defaultPage() - { - return new PageFormat(); - } - - /** - * Clones the specified <code>PageFormat</code> object then alters the - * clone so that it represents the default page format. - * - * @param page_format The <code>PageFormat</code> to clone. - * - * @return A new default page format. - */ - public abstract PageFormat defaultPage(PageFormat page_format); - - /** - * Displays a dialog box to the user which allows the page format - * attributes to be modified. - * - * @param page_format The <code>PageFormat</code> object to modify. - * - * @return The modified <code>PageFormat</code>. - */ - public abstract PageFormat pageDialog(PageFormat page_format) - throws HeadlessException; - - /** - * @since 1.4 - */ - public PageFormat pageDialog(PrintRequestAttributeSet attributes) - throws HeadlessException - { - // FIXME: Implement this for real. - return pageDialog((PageFormat) null); - } - - /** - * Prints the pages. - */ - public abstract void print () throws PrinterException; - - /** - * Prints the page with given attributes. - */ - public abstract void print (PrintRequestAttributeSet attributes) - throws PrinterException; - - /** - * Displays a dialog box to the user which allows the print job - * attributes to be modified. - * - * @return <code>false</code> if the user cancels the dialog box, - * <code>true</code> otherwise. - */ - public abstract boolean printDialog() - throws HeadlessException; - - /** - * Displays a dialog box to the user which allows the print job - * attributes to be modified. - * - * @return <code>false</code> if the user cancels the dialog box, - * <code>true</code> otherwise. - */ - public boolean printDialog(PrintRequestAttributeSet attributes) - throws HeadlessException - { - // FIXME: Implement this for real. - return printDialog(); - } - - /** - * This sets the pages that are to be printed. - * - * @param pageable The pages to be printed, which may not be <code>null</code>. - */ - public abstract void setPageable(Pageable pageable); - - /** - * Sets this specified <code>Printable</code> as the one to use for - * rendering the pages on the print device. - * - * @param printable The <code>Printable</code> for the print job. - */ - public abstract void setPrintable(Printable printable); - - /** - * Sets the <code>Printable</code> and the page format for the pages - * to be printed. - * - * @param printable The <code>Printable</code> for the print job. - * @param page_format The <code>PageFormat</code> for the print job. - */ - public abstract void setPrintable(Printable printable, PageFormat page_format); - - /** - * Makes any alterations to the specified <code>PageFormat</code> - * necessary to make it work with the current printer. The alterations - * are made to a clone of the input object, which is then returned. - * - * @param page_format The <code>PageFormat</code> to validate. - * - * @return The validated <code>PageFormat</code>. - */ - public abstract PageFormat validatePage(PageFormat page_format); - - /** - * Find and return 2D image print services. - * - * This is the same as calling PrintServiceLookup.lookupPrintServices() - * with Pageable service-specified DocFlavor. - * @return Array of PrintService objects, could be empty. - * @since 1.4 - */ - public static PrintService[] lookupPrintServices() - { - return new PrintService[0]; - // FIXME: - // Enable this when javax.print has this implemented. -// return PrintServiceLookup.lookupPrintServices( -// new DocFlavor("application/x-java-jvm-local-objectref", -// "java.awt.print.Pageable"), -// null); - } - - /** - * Find and return 2D image stream print services. - * - * This is the same as calling - * StreamPrintServiceFactory.lookupStreamPrintServices() - * with Pageable service-specified DocFlavor. - * @param mimeType The output format mime type, or null for any type. - * @return Array of stream print services, could be empty. - * @since 1.4 - */ - // FIXME: - // Enable when javax.print has StreamPrintServiceFactory -// public static StreamPrintServiceFactory[] lookupStreamPrintServices(String mimeType) -// { -// return StreamPrintServiceFactory.lookupStreamServiceFactories( -// new DocFlavor("application/x-java-jvm-local-objectref", -// "java.awt.print.Pageable"), -// mimeType); -// } - - /** - * Return the printer for this job. If print services aren't supported by - * the subclass, returns null. - * - * @return The associated PrintService. - * @since 1.4 - */ - public PrintService getPrintService() - { - return null; - } - - /** - * Change the printer for this print job to service. Subclasses that - * support setting the print service override this method. Throws - * PrinterException when the class doesn't support setting the printer, - * the service doesn't support Pageable or Printable interfaces for 2D - * print output. - * @param service The new printer to use. - * @throws PrinterException if service is not valid. - */ - public void setPrintService(PrintService service) - throws PrinterException - { - throw new PrinterException(); - } -} diff --git a/libjava/java/beans/AppletInitializer.java b/libjava/java/beans/AppletInitializer.java deleted file mode 100644 index 69dc2cae50e..00000000000 --- a/libjava/java/beans/AppletInitializer.java +++ /dev/null @@ -1,61 +0,0 @@ -/* java.beans.AppletInitializer - Copyright (C) 2001, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.beans; - -import java.applet.Applet; -import java.beans.beancontext.BeanContext; - - -/** This interface is a mechanism for the initialization of a Java - * Bean that is also an Applet. It is used by - * <code>Beans.instantiate()</code>. - * - * @author Tom Tromey (tromey@redhat.com) - * @since 1.2 - */ -public interface AppletInitializer -{ - /** Activate the applet. */ - void activate (Applet applet); - - /** This method will be called by <code>Beans.instantiate()</code> - * to associated the new Applet with its AppletContext, AppletStub, - * and Container. - */ - void initialize (Applet applet, BeanContext context); -} diff --git a/libjava/java/beans/BeanDescriptor.java b/libjava/java/beans/BeanDescriptor.java deleted file mode 100644 index 21227b2fee0..00000000000 --- a/libjava/java/beans/BeanDescriptor.java +++ /dev/null @@ -1,89 +0,0 @@ -/* java.beans.BeanDescriptor - Copyright (C) 1998, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.beans; - -/** - ** BeanDescriptor describes general information about a Bean, plus - ** stores the Bean's Class and it's customizer's Class.<P> - ** - ** @author John Keiser - ** @since JDK1.1 - ** @version 1.1.0, 31 May 1998 - **/ - -public class BeanDescriptor extends FeatureDescriptor { - Class beanClass; - Class customizerClass; - - /** Create a new BeanDescriptor with the given beanClass and - ** no customizer class. - ** @param beanClass the class of the Bean. - **/ - public BeanDescriptor(Class beanClass) { - this(beanClass,null); - } - - /** Create a new BeanDescriptor with the given bean class and - ** customizer class. - ** @param beanClass the class of the Bean. - ** @param customizerClass the class of the Bean's Customizer. - **/ - public BeanDescriptor(Class beanClass, Class customizerClass) { - this.beanClass = beanClass; - this.customizerClass = customizerClass; - - // Set the FeatureDescriptor programmatic name. - String name = beanClass.getName(); - int lastInd = name.lastIndexOf('.'); - if (lastInd != -1) - name = name.substring(lastInd + 1); - - setName(name); - } - - /** Get the Bean's class. **/ - public Class getBeanClass() { - return beanClass; - } - - /** Get the Bean's customizer's class. **/ - public Class getCustomizerClass() { - return customizerClass; - } -} diff --git a/libjava/java/beans/BeanInfo.java b/libjava/java/beans/BeanInfo.java deleted file mode 100644 index 525500a389c..00000000000 --- a/libjava/java/beans/BeanInfo.java +++ /dev/null @@ -1,181 +0,0 @@ -/* java.beans.BeanInfo - Copyright (C) 1998 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.beans; - -/** - ** BeanInfo can be implemented in order to provide explicit information to the Introspector. - ** - ** When you write a BeanInfo class, you implement this interface - ** and provide explicit information by returning a non-null - ** value from the appropriate method. If you wish the - ** Introspector to determine certain information in the normal - ** way, just return null (or in the case of int methods, return - ** -1). There is a class called SimpleBeanInfo which returns - ** null from all methods, which you may extend and only - ** override the methods you wish to override.<P> - ** - ** When you have written the class, give it the name - ** <CODE><Bean Class Name>BeanInfo</CODE> and place it in - ** the same package as the Bean, or in the bean info search path - ** (see Introspector for information on search paths).<P> - ** - ** A simple note about the way the Introspector interacts with - ** BeanInfo. Introspectors look at a Bean class and determine - ** if there is a BeanInfo class with it. If there is not a - ** BeanInfo class, it will behave as if the BeanInfo class - ** provided was a SimpleBeanInfo class (i.e. it will determine - ** all information automatically).<P>If there is a BeanInfo - ** class, then any methods that do *not* return null are - ** regarded as providing definitive information about the class - ** and all of its superclasses for those information types. - ** Even if a parent BeanInfo class explicitly returns that - ** information, it will not be used. - ** - ** @author John Keiser - ** @since JDK1.1 - ** @version 1.1.0, 28 Jul 1998 - **/ - -public interface BeanInfo { - /** Use this as a parameter for the getIcon() command to retrieve a certain type of icon. **/ - int ICON_COLOR_16x16 = 1; - /** Use this as a parameter for the getIcon() command to retrieve a certain type of icon. **/ - int ICON_COLOR_32x32 = 2; - /** Use this as a parameter for the getIcon() command to retrieve a certain type of icon. **/ - int ICON_MONO_16x16 = 3; - /** Use this as a parameter for the getIcon() command to retrieve a certain type of icon. **/ - int ICON_MONO_32x32 = 4; - - /** Get the general description of this Bean type. - ** @return the BeanDescriptor for the Bean, or null if - ** the BeanDescriptor should be obtained by - ** Introspection. - **/ - BeanDescriptor getBeanDescriptor(); - - /** Get the events this Bean type fires. - ** @return the EventDescriptors representing events this - ** Bean fires. Returns <CODE>null</CODE> if the - ** events are to be acquired by Introspection. - **/ - EventSetDescriptor[] getEventSetDescriptors(); - - /** Get the "default" event, basically the one a RAD tool - ** user is most likely to select. - ** @return the index into the getEventSetDescriptors() - ** that the user is most likely to use. Returns - ** <CODE>-1</CODE> if there is no default event. - **/ - int getDefaultEventIndex(); - - /** Get the properties (get/set method pairs) this Bean - ** type supports. - ** @return the PropertyDescriptors representing the - ** properties this Bean type supports. - ** Returns <CODE>null</CODE> if the properties - ** are to be obtained by Introspection. - **/ - PropertyDescriptor[] getPropertyDescriptors(); - - /** Get the "default" property, basically the one a RAD - ** tool user is most likely to select. - ** @return the index into the getPropertyDescriptors() - ** that the user is most likely to use. Returns - ** <CODE>-1</CODE> if there is no default event. - **/ - int getDefaultPropertyIndex(); - - /** Get the methods this Bean type supports. - ** @return the MethodDescriptors representing the - ** methods this Bean type supports. Returns - ** <CODE>null</CODE> if the methods are to be - ** obtained by Introspection. - **/ - MethodDescriptor[] getMethodDescriptors(); - - /** Get additional BeanInfos representing this Bean. - ** In this version of JavaBeans, this method is used so - ** that space and time can be saved by reading a BeanInfo - ** for each class in the hierarchy (super, super(super), - ** and so on).<P> - ** - ** The order of precedence when two pieces of BeanInfo - ** conflict (such as two PropertyDescriptors that have - ** the same name), in order from highest precedence to - ** lowest, is: - ** <OL> - ** <LI>This BeanInfo object.</LI> - ** <LI><CODE>getAdditionalBeanInfo()[getAdditionalBeanInfo().length]</CODE></LI> - ** <LI> ... </LI> - ** <LI><CODE>getAdditionalBeanInfo()[1]</CODE></LI> - ** <LI><CODE>getAdditionalBeanInfo()[0]</CODE></LI> - ** </OL><P> - ** - ** <STRONG>Spec Note:</STRONG> It is possible that - ** returning <CODE>null</CODE> from this method could - ** stop Introspection in its tracks, but it is unclear - ** from the spec whether this is the case. - ** - ** @return additional BeanInfos representing this Bean. - ** <CODE>null</CODE> may be returned (see Spec - ** Note, above). - **/ - BeanInfo[] getAdditionalBeanInfo(); - - /** Get a visual icon for this Bean. - ** A Bean does not have to support icons, and if it does - ** support icons, it does not have to support every single - ** type. Sun recommends that if you only support one - ** type, you support 16x16 color. Sun also notes that you - ** should try to use a type (like GIF) that allows for - ** transparent pixels, so that the background of the RAD - ** tool can show through.<P> - ** - ** <STRONG>Spec Note:</STRONG> If you do not support the - ** type of icon that is being asked for, but you do - ** support another type, it is unclear whether you should - ** return the other type or not. I would presume not. - ** - ** @param iconType the type of icon to get (see the - ** ICON_* constants in this class). - ** @return the icon, or null if that type of icon is - ** unsupported by this Bean. - **/ - java.awt.Image getIcon(int iconType); -} diff --git a/libjava/java/beans/Beans.java b/libjava/java/beans/Beans.java deleted file mode 100644 index ffcb83fc1f3..00000000000 --- a/libjava/java/beans/Beans.java +++ /dev/null @@ -1,368 +0,0 @@ -/* java.beans.Beans - Copyright (C) 1998, 1999, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.beans; - -import gnu.java.beans.DummyAppletStub; -import gnu.java.io.ClassLoaderObjectInputStream; - -import java.applet.Applet; -import java.beans.beancontext.BeanContext; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.net.URL; - -/** - * <code>Beans</code> provides some helper methods that allow the basic - * operations of Bean-ness. - * - * @author John Keiser - * @author Robert Schuster - * - * @since 1.1 - * @status updated to 1.4 - * - */ -public class Beans -{ - static boolean designTime = false; - static boolean guiAvailable = true; - - /** - * Once again, we have a java.beans class with only - * static methods that can be instantiated. When - * will the madness end? :) - */ - public Beans() - { - // Does intentionally nothing here. - } - - /** Creates a bean. - * <p>This is a convenience method that calls <code>instantiate(cl, beanName, null, null)</code>.</p> - * - * @see instantiate(ClassLoader, String, BeanContext, AppletInitializer) - * @param cl ClassLoader to be used or <code>null</code> for the system classloader. - * @param beanName Name of a serialized bean or class name. - * @return A newly created bean. - * @throws IOException If access of an IO resource failed. - * @throws ClassNotFoundException If the class name is not known or does not lead to a proper bean class. - */ - public static Object instantiate(ClassLoader cl, String beanName) - throws IOException, ClassNotFoundException - { - return instantiate(cl, beanName, null, null); - } - - /** Creates a bean. - * - * <p>This is a convenience method that calls <code>instantiate(cl, beanName, beanContext, null)</code>.</p> - * - * @see instantiate(ClassLoader, String, BeanContext, AppletInitializer) - * @param cl ClassLoader to be used or <code>null</code> for the system classloader. - * @param beanName Name of a serialized bean or class name. - * @param beanContext Context to which the newly created Bean should be added. - * @return A newly created bean. - * @throws IOException If access of an IO resource failed. - * @throws ClassNotFoundException If the class name is not known or does not lead to a proper bean class. - */ - public static Object instantiate( - ClassLoader cl, - String beanName, - BeanContext beanContext) - throws IOException, ClassNotFoundException - { - return instantiate(cl, beanName, beanContext, null); - } - - /** Instantiates a bean according to Beans 1.0. - * - * <p>In Beans 1.0 the instantiation scheme is as follows:</p> - * <p>The name should be dot-separated (e.g "place.for.beans.myBean") and indicate either a - * serialized object or a class name. In the first case all dots in the name are replaced with - * slashes ('/') and ".ser" is appended ("place.for.beans.myBean" becomes "place/for/beans/myBean.ser"). - * The bean is then loaded as an application or system resource depending on whether a - * <code>ClassLoader</code> was provided.</p> - * - * <p>If no such resource exists or if it contains no bean the name is interpreted as a class name of - * which an instance is then created.</p> - * - * <p>If a <code>BeanContext</code> instance is available the created bean is added to it.</p> - * - * <p>If the created Bean is an <code>Applet</code> or subclass and an <code>AppletInitializer</code> - * instance is available the applet is initialized and afterwards activated using the initializer. Additionally - * every instantiated <code>Applet</code> bean is initialized using the {@link Applet.init} method. - * Furthermore every applet gets a default <code>AppletStub</code>. The <code>Applet</code>'s - * document base is the location of the ".ser" file if it was deserialized or the location of its class - * file if it was instantiated.</p> - * - * <p>A <code>ClassNotFoundException</code> is not only thrown when a class name was unknown - * but even when the class has public no-argument constructor - * (<code>IllegalAccessException</code> is wrapped) or an exception is thrown while - * invoking such a constructor (causing exception is wrapped).</p> - * - * @param cl ClassLoader to be used or <code>null</code> for the system classloader. - * @param beanName Name of a serialized bean or class name. - * @param beanContext Context to which the newly created Bean should be added. - * @param initializer The AppletInitializer which is used for initializing <code>Applet</code> beans. - * @return A newly created bean. - * @throws IOException If access of an IO resource failed. - * @throws ClassNotFoundException If the class name is not known or does not lead to a proper bean class. - */ - public static Object instantiate( - ClassLoader cl, - String beanName, - BeanContext beanContext, - AppletInitializer initializer) - throws IOException, ClassNotFoundException - { - Object bean = null; - URL beanLocation = null; - URL classLocation = null; - - // Converts bean name into a resource name (eg. "a.b.c" -> "a/b/c"). - String resourceName = beanName.replace('.', '/'); - - /* Tries to get an input stream of the Bean, reading it as a system resource - * if no ClassLoader is present or as an application resource if a classloader - * is given. - */ - beanLocation = - (cl == null) - ? ClassLoader.getSystemResource(resourceName + ".ser") - : cl.getResource(resourceName + ".ser"); - - // Reads the serialized Bean from the returned URL. - if (beanLocation != null) - { - // Deserializes the bean instance. - ObjectInputStream ois = - (cl == null) - ? new ObjectInputStream(beanLocation.openStream()) - : new ClassLoaderObjectInputStream( - beanLocation.openStream(), - cl); - - bean = ois.readObject(); - - /* Implementation note: The result of ObjectInputStream.readObject() - * may have been null at this point (its a valid value to deserialize) - * and we explicitly want to try instantiation in such a case - * (this is important for compatibility). - */ - } - - // Instantiates the Bean using reflective instantiation if it has not been created yet. - if (bean == null) - { - // Makes sure that the deserialization was NOT done. - beanLocation = null; - - Class beanClass; - if (cl == null) - { - beanClass = Class.forName(beanName); - classLocation = - ClassLoader.getSystemResource(resourceName + ".class"); - } - else - { - beanClass = cl.loadClass(beanName); - classLocation = cl.getResource(resourceName + ".class"); - } - - // Instantiates and optionally registers the new bean. - try - { - bean = beanClass.newInstance(); - } - catch(Exception e) { - /* Wraps all kinds of Exceptions in a ClassNotFoundException (this behavior - * matches with official >= 1.5, this was different for <=1.4) - */ - throw new ClassNotFoundException(null, e); - } - } - - /* Applet beans are treated in the following way: - * - all AppletS get a default AppletStub - * - all AppletS are initialized using the AppletInitializer instance (if it is available) - * - as every other Bean Applets are added to a BeanContext if one is available - * - each instantiated Applet is initialized using Applet.init() (this is not done for deserialized ones) - * - finally AppletS get activated using the AppletInitializerS activate-Method - * - * The order of operations is important for compatibility. - */ - Applet applet = null; - if (bean instanceof Applet) - { - // Makes a second instanceof call unneccessary (instanceof is expensive). - applet = (Applet) bean; - - /* The AppletStub's code and document base is set as follows: - * The code base is always the URL from where the class data originated - * (without the package name). - * If the Applet was deserialized the document base is the location of - * the serialized instance (usually the ".ser" file) otherwise its the URL - * from where the class data originated (usually the absolute directory - * location of the ".class" file). - */ - applet.setStub( - new DummyAppletStub( - applet - .getClass() - .getProtectionDomain() - .getCodeSource() - .getLocation(), - (beanLocation == null) ? classLocation : beanLocation)); - - // Runs the Applet's initialization using an AppletInitializer. - if (initializer != null) - { - initializer.initialize(applet, beanContext); - } - } - - // Adds the new bean to its BeanContext. - if (beanContext != null) - { - beanContext.add(bean); - } - - if (applet != null) - { - - // Initializes an instantiated (not deserialized) Applet using its own method. - if (beanLocation == null) - { - applet.init(); - } - - // Runs the Applet's activation using an AppletInitializer. - if (initializer != null) - { - initializer.activate(applet); - } - } - - return bean; - } - - /** - * Returns the Bean as a different class type. - * This should be used instead of casting to get a new - * type view of a Bean, because in the future there may - * be new types of Bean, even Beans spanning multiple - * Objects. - * - * @param bean the Bean to cast. - * @param newClass the Class to cast it to. - * - * @return the Bean as a new view, or if the operation - * could not be performed, the Bean itself. - */ - public static Object getInstanceOf(Object bean, Class newClass) - { - return bean; - } - - /** - * Determines whether the Bean can be cast to a different - * class type. - * This should be used instead of instanceof to determine - * a Bean's castability, because in the future there may - * be new types of Bean, even Beans spanning multiple - * Objects. - * - * @param bean the Bean to cast. - * @param newClass the Class to cast it to. - * - * @return whether the Bean can be cast to the class type - * in question. - */ - public static boolean isInstanceOf(Object bean, Class newBeanClass) - { - return newBeanClass.isInstance(bean); - } - - /** - * Returns whether the GUI is available to use. - * <p>Defaults to true.</p> - * - * @return whether the GUI is available to use. - */ - public static boolean isGuiAvailable() - { - return guiAvailable; - } - - /** - * Returns whether it is design time. Design time means - * we are in a RAD tool. - * <p>Defaults to false.</p> - * - * @return whether it is design time. - */ - public static boolean isDesignTime() - { - return designTime; - } - - /** - * Sets whether the GUI is available to use. - * - * @param guiAvailable whether the GUI is available to use. - */ - public static void setGuiAvailable(boolean guiAvailable) - throws SecurityException - { - Beans.guiAvailable = guiAvailable; - } - - /** - * Sets whether it is design time. Design time means we - * are in a RAD tool. - * - * @param designTime whether it is design time. - */ - public static void setDesignTime(boolean designTime) - throws SecurityException - { - Beans.designTime = designTime; - } - -} diff --git a/libjava/java/beans/Customizer.java b/libjava/java/beans/Customizer.java deleted file mode 100644 index b36c89f8846..00000000000 --- a/libjava/java/beans/Customizer.java +++ /dev/null @@ -1,86 +0,0 @@ -/* java.beans.Customizer - Copyright (C) 1998 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.beans; - -/** - ** You may explicitly provide a Customizer for your Bean - ** class, which allows you complete control of the editing - ** of the Bean.<P> - ** - ** A Customizer is meant to be embedded in an RAD tool, - ** and thus must be a descendant of <CODE>java.awt.Component</CODE>.<P> - ** - ** It must also have a constructor with no arguments. This - ** is the constructor that will be called by the RAD tool to - ** instantiate the Customizer.<P> - ** - ** Over its lifetime, an instance of a Customizer will only - ** customize one single Bean. A new instance of the - ** Customizer will be instantiated to edit any other Beans.<P> - ** - ** The Customizer is responsible for notifying its - ** PropertyChangeListeners of any changes that are made, - ** according to the rules of PropertyChangeListeners (i.e. - ** notify the clients <EM>after</EM> the property has - ** changed). - ** - ** @author John Keiser - ** @since JDK1.1 - ** @version 1.1.0, 29 Jul 1998 - ** @see java.beans.BeanDescriptor.getCustomizerClass() - **/ - -public interface Customizer { - /** Set the object to Customize. This will always be a - ** Bean that had a BeanDescriptor indicating this - ** Customizer. - ** @param bean the Bean to customize. - **/ - void setObject(Object bean); - - /** Add a PropertyChangeListener. - ** @param l the PropertyChangeListener to add. - **/ - void addPropertyChangeListener(PropertyChangeListener l); - - /** Remove a PropertyChangeListener. - ** @param l the PropertyChangeListener to remove. - **/ - void removePropertyChangeListener(PropertyChangeListener l); -} diff --git a/libjava/java/beans/DesignMode.java b/libjava/java/beans/DesignMode.java deleted file mode 100644 index 39805d50c18..00000000000 --- a/libjava/java/beans/DesignMode.java +++ /dev/null @@ -1,93 +0,0 @@ -/* java.beans.DesignMode - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.beans; - -/** - * <code>BeanContextChild</code> implementors implement this to get information about whether they are in a design time or runtime environment. - * The reason this is restricted to <code>BeanContextChild</code>ren is that - * only things in the <code>BeanContext</code> hierarchy are given this - * information in the first place. - * - * @author John Keiser - * @since JDK1.2 - * @see java.beans.beancontext.BeanContextChild - */ - -public interface DesignMode { - /** - * Use this name when firing <code>PropertyChangeEvent</code>s from your Bean. - * @fixme Check whether PROPERTYNAME is set to same value as Sun. - */ - String PROPERTYNAME = "designTime"; - - /** - * The environment will call this method on your - * <code>BeanContextChild</code> when it is registered in a parent - * <code>BeanContext</code> or when behavior needs to switch from - * design time to runtime behavior (or vice versa). - * <P> - * - * <code>BeanContext</code>s are required to fire - * <code>PropertyChangeEvent</code>s when properties change. - * <code>designTime</code> is a property, and therefore when you - * implement <code>setDesignTime()</code>, you need to fire a - * <code>PropertyChangeEvent</code> with the old value, the new - * value and using <code>PROPERTYNAME</code> as the property name. - * - * @param designTime the new value of design time, - * <code>true</code> if it is design time, - * <code>false</code> if it is runtime. - * - * @fixme I'm frankly not really sure whether it's the case that - * the BeanContext can <em>change</em> the status of the Bean from - * design time to runtime. But it appears that it may be so. - * - * @see java.util.PropertyChangeEvent - * @see java.beans.beancontext.BeanContext - * @see #PROPERTYNAME - */ - void setDesignTime(boolean designTime); - - /** - * This method should tell whether it is design time or runtime. - * @return <code>true</code> if design time, <code>false</code> if - * runtime. - */ - boolean isDesignTime(); -} diff --git a/libjava/java/beans/EventHandler.java b/libjava/java/beans/EventHandler.java deleted file mode 100644 index 9c85893e0f3..00000000000 --- a/libjava/java/beans/EventHandler.java +++ /dev/null @@ -1,606 +0,0 @@ -/* java.beans.EventHandler - Copyright (C) 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.beans; - -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; - -/** - * <p>EventHandler forms a bridge between dynamically created listeners and - * arbitrary properties and methods.</p> - * - * <p>You can use this class to easily create listener implementations for - * some basic interactions between an event source and its target. Using - * the three static methods named <code>create</code> you can create - * these listener implementations.</p> - * - * <p>See the documentation of each method for usage examples.</p> - * - * @author Jerry Quinn (jlquinn@optonline.net) - * @author Robert Schuster (thebohemian@gmx.net) - * @since 1.4 - */ -public class EventHandler implements InvocationHandler -{ - // The name of the method that will be implemented. If null, any method. - private String listenerMethod; - - // The object to call action on. - private Object target; - - // The name of the method or property setter in target. - private String action; - - // The property to extract from an event passed to listenerMethod. - private String property; - - // The target objects Class. - private Class targetClass; - - // String class doesn't already have a capitalize routine. - private String capitalize(String s) - { - return s.substring(0, 1).toUpperCase() + s.substring(1); - } - - /** - * Creates a new <code>EventHandler</code> instance. - * - * <p>Typical creation is done with the create method, not by knewing an - * EventHandler.</p> - * - * <p>This constructs an EventHandler that will connect the method - * listenerMethodName to target.action, extracting eventPropertyName from - * the first argument of listenerMethodName. and sending it to action.</p> - * - * <p>Throws a <code>NullPointerException</code> if the <code>target</code> - * argument is <code>null</code>. - * - * @param target Object that will perform the action. - * @param action A property or method of the target. - * @param eventPropertyName A readable property of the inbound event. - * @param listenerMethodName The listener method name triggering the action. - */ - public EventHandler(Object target, String action, String eventPropertyName, - String listenerMethodName) - { - this.target = target; - - // Retrieving the class is done for two reasons: - // 1) The class object is needed very frequently in the invoke() method. - // 2) The constructor should throw a NullPointerException if target is null. - targetClass = target.getClass(); - - this.action = action; // Turn this into a method or do we wait till - // runtime - property = eventPropertyName; - listenerMethod = listenerMethodName; - } - - /** - * Returns the event property name. - */ - public String getEventPropertyName() - { - return property; - } - - /** - * Returns the listener's method name. - */ - public String getListenerMethodName() - { - return listenerMethod; - } - - /** - * Returns the target object. - */ - public Object getTarget() - { - return target; - } - - /** - * Returns the action method name. - */ - public String getAction() - { - return action; - } - - // Fetch a qualified property like a.b.c from object o. The properties can - // be boolean isProp or object getProp properties. - // - // Returns a length 2 array with the first entry containing the value - // extracted from the property, and the second entry contains the class of - // the method return type. - // - // We play this game because if the method returns a native type, the return - // value will be a wrapper. If we then take the type of the wrapper and use - // it to locate the action method that takes the native type, it won't match. - private Object[] getProperty(Object o, String prop) - { - // Isolate the first property name from a.b.c. - int pos; - String rest = null; - if ((pos = prop.indexOf('.')) != -1) - { - rest = prop.substring(pos + 1); - prop = prop.substring(0, pos); - } - - // Find a method named getProp. It could be isProp instead. - Method getter; - try - { - // Look for boolean property getter isProperty - getter = o.getClass().getMethod("is" + capitalize(prop), - null); - } - catch (NoSuchMethodException nsme1) - { - try { - // Look for regular property getter getProperty - getter = o.getClass().getMethod("get" + capitalize(prop), - null); - } catch(NoSuchMethodException nsme2) { - try { - // Finally look for a method of the name prop - getter = o.getClass().getMethod(prop, null); - } catch(NoSuchMethodException nsme3) { - // Ok, give up with an intelligent hint for the user. - throw new RuntimeException("Method not called: Could not find a property or method '" + prop - + "' in " + o.getClass() + " while following the property argument '" + property + "'."); - } - } - } - try { - Object val = getter.invoke(o, null); - - if (rest != null) - return getProperty(val, rest); - - return new Object[] {val, getter.getReturnType()}; - } catch(InvocationTargetException ite) { - throw new RuntimeException("Method not called: Property or method '" + prop + "' has thrown an exception.", ite); - } catch(IllegalAccessException iae) { - // This cannot happen because we looked up method with Class.getMethod() - // which returns public methods only. - throw (InternalError) new InternalError("Non-public method was invoked.").initCause(iae); - } - } - - /** - * Invokes the <code>EventHandler</code>. - * - * <p>This method is normally called by the listener's proxy implementation.</p> - * - * @param proxy The listener interface that is implemented using - * the proxy mechanism. - * @param method The method that was called on the proxy instance. - * @param arguments The arguments which where given to the method. - * @throws Throwable <code>NoSuchMethodException</code> is thrown when the EventHandler's - * action method or property cannot be found. - */ - public Object invoke(Object proxy, Method method, Object[] arguments) - { - try { - // The method instance of the target object. We have to find out which - // one we have to invoke. - Method actionMethod = null; - - // Listener methods that weren't specified are ignored. If listenerMethod - // is null, then all listener methods are processed. - if (listenerMethod != null && !method.getName().equals(listenerMethod)) - return null; - - // If a property is defined we definitely need a valid object at - // arguments[0] that can be used to retrieve a value to which the - // property of the target gets set. - if(property != null) { - // Extracts the argument. We will let it fail with a NullPointerException - // the caller used a listener method that has no arguments. - Object event = arguments[0]; - - // Obtains the property XXX propertyType keeps showing up null - why? - // because the object inside getProperty changes, but the ref variable - // can't change this way, dolt! need a better way to get both values out - // - need method and object to do the invoke and get return type - Object v[] = getProperty(event, property); - Object[] args = new Object[] { v[0] }; - - // Changes the class array that controls which method signature we are going - // to look up in the target object. - Class[] argTypes = new Class[] { initClass((Class) v[1]) }; - - // Tries to find a setter method to which we can apply the - while(argTypes[0] != null) { - try - { - // Look for a property setter for action. - actionMethod = targetClass.getMethod("set" + capitalize(action), argTypes); - - return actionMethod.invoke(target, args); - } - catch (NoSuchMethodException e) - { - // If action as property didn't work, try as method later. - } - - argTypes[0] = nextClass(argTypes[0]); - } - - // We could not find a suitable setter method. Now we try again interpreting - // action as the method name itself. - // Since we probably have changed the block local argTypes array - // we need to rebuild it. - argTypes = new Class[] { initClass((Class) v[1]) }; - - // Tries to find a setter method to which we can apply the - while(argTypes[0] != null) { - try - { - actionMethod = targetClass.getMethod(action, argTypes); - - return actionMethod.invoke(target, args); - } - catch (NoSuchMethodException e) - { - } - - argTypes[0] = nextClass(argTypes[0]); - } - - throw new RuntimeException("Method not called: Could not find a public method named '" - + action + "' in target " + targetClass + " which takes a '" - + v[1] + "' argument or a property of this type."); - } - - // If property was null we will search for a no-argument method here. - // Note: The ordering of method lookups is important because we want to prefer no-argument - // calls like the JDK does. This means if we have actionMethod() and actionMethod(Event) we will - // call the first *EVEN* if we have a valid argument for the second method. This is behavior compliant - // to the JDK. - // If actionMethod() is not available but there is a actionMethod(Event) we take this. That makes us - // more specification compliant than the JDK itself because this one will fail in such a case. - try - { - actionMethod = targetClass.getMethod(action, null); - } - catch(NoSuchMethodException nsme) - { - // Note: If we want to be really strict the specification says that a no-argument method should - // accept an EventObject (or subclass I guess). However since the official implementation is broken - // anyways, it's more flexible without the EventObject restriction and we are compatible on everything - // else this can stay this way. - if(arguments != null && arguments.length >= 1/* && arguments[0] instanceof EventObject*/) { - Class[] targetArgTypes = new Class[] { initClass(arguments[0].getClass()) }; - - while(targetArgTypes[0] != null) { - try - { - // If no property exists we expect the first element of the arguments to be - // an EventObject which is then applied to the target method. - - actionMethod = targetClass.getMethod(action, targetArgTypes); - - return actionMethod.invoke(target, new Object[] { arguments[0] }); - } - catch(NoSuchMethodException nsme2) - { - - } - - targetArgTypes[0] = nextClass(targetArgTypes[0]); - } - - } - } - - // If we do not have a Method instance at this point this means that all our tries - // failed. The JDK throws an ArrayIndexOutOfBoundsException in this case. - if(actionMethod == null) - throw new ArrayIndexOutOfBoundsException(0); - - // Invoke target.action(property) - return actionMethod.invoke(target, null); - } catch(InvocationTargetException ite) { - throw new RuntimeException(ite.getCause()); - } catch(IllegalAccessException iae) { - // Cannot happen because we always use getMethod() which returns public - // methods only. Otherwise there is something seriously broken in - // GNU Classpath. - throw (InternalError) new InternalError("Non-public method was invoked.").initCause(iae); - } - } - - /** - * <p>Returns the primitive type for every wrapper class or the - * class itself if it is no wrapper class.</p> - * - * <p>This is needed because to be able to find both kinds of methods: - * One that takes a wrapper class as the first argument and one that - * accepts a primitive instead.</p> - */ - private Class initClass(Class klass) { - if(klass == Boolean.class) { - return Boolean.TYPE; - } else if(klass == Byte.class) { - return Byte.TYPE; - } else if(klass == Short.class) { - return Short.TYPE; - } else if(klass == Integer.class) { - return Integer.TYPE; - } else if(klass == Long.class) { - return Long.TYPE; - } else if(klass == Float.class) { - return Float.TYPE; - } else if(klass == Double.class) { - return Double.TYPE; - } else { - return klass; - } - } - - /** - * - * - * @param klass - * @return - */ - private Class nextClass(Class klass) { - if(klass == Boolean.TYPE) { - return Boolean.class; - } else if(klass == Byte.TYPE) { - return Byte.class; - } else if(klass == Short.TYPE) { - return Short.class; - } else if(klass == Integer.TYPE) { - return Integer.class; - } else if(klass == Long.TYPE) { - return Long.class; - } else if(klass == Float.TYPE) { - return Float.class; - } else if(klass == Double.TYPE) { - return Double.class; - } else { - return klass.getSuperclass(); - } - } - - /** - * <p>Constructs an implementation of <code>listenerInterface</code> - * to dispatch events.</p> - * - * <p>You can use such an implementation to simply call a public - * no-argument method of an arbitrary target object or to forward - * the first argument of the listener method to the target method.</p> - * - * <p>Call this method like:</p> - * <code> - * button.addActionListener((ActionListener) - * EventHandler.create(ActionListener.class, target, "dispose")); - * </code> - * - * <p>to achieve the following behavior:</p> - * <code> - * button.addActionListener(new ActionListener() { - * public void actionPerformed(ActionEvent ae) { - * target.dispose(); - * } - * }); - * </code> - * - * <p>That means if you need a listener implementation that simply calls a - * a no-argument method on a given instance for <strong>each</strong> - * method of the listener interface.</p> - * - * <p>Note: The <code>action</code> is interpreted as a method name. If your target object - * has no no-argument method of the given name the EventHandler tries to find - * a method with the same name but which can accept the first argument of the - * listener method. Usually this will be an event object but any other object - * will be forwarded, too. Keep in mind that using a property name instead of a - * real method here is wrong and will throw an <code>ArrayIndexOutOfBoundsException</code> - * whenever one of the listener methods is called.<p/> - * - * <p>The <code>EventHandler</code> will automatically convert primitives - * to their wrapper class and vice versa. Furthermore it will call - * a target method if it accepts a superclass of the type of the - * first argument of the listener method.</p> - * - * <p>In case that the method of the target object throws an exception - * it will be wrapped in a <code>RuntimeException</code> and thrown out - * of the listener method.</p> - * - * <p>In case that the method of the target object cannot be found an - * <code>ArrayIndexOutOfBoundsException</code> will be thrown when the - * listener method is invoked.</p> - * - * <p>A call to this method is equivalent to: - * <code>create(listenerInterface, target, action, null, null)</code></p> - * - * @param listenerInterface Listener interface to implement. - * @param target Object to invoke action on. - * @param action Target property or method to invoke. - * @return A constructed proxy object. - */ - public static Object create(Class listenerInterface, Object target, String action) - { - return create(listenerInterface, target, action, null, null); - } - - /** - * <p>Constructs an implementation of <code>listenerInterface</code> - * to dispatch events.</p> - * - * <p>Use this method if you want to create an implementation that retrieves - * a property value from the <b>first</b> argument of the listener method - * and applies it to the target's property or method. This first argument - * of the listener is usually an event object but any other object is - * valid, too.</p> - * - * <p>You can set the value of <code>eventPropertyName</code> to "prop" - * to denote the retrieval of a property named "prop" from the event - * object. In case that no such property exists the <code>EventHandler</code> - * will try to find a method with that name.</p> - * - * <p>If you set <code>eventPropertyName</code> to a value like this "a.b.c" - * <code>EventHandler</code> will recursively evaluate the properties "a", "b" - * and "c". Again if no property can be found the <code>EventHandler</code> - * tries a method name instead. This allows mixing the names, too: "a.toString" - * will retrieve the property "a" from the event object and will then call - * the method "toString" on it.</p> - * - * <p>An exception thrown in any of these methods will provoke a - * <code>RuntimeException</code> to be thrown which contains an - * <code>InvocationTargetException</code> containing the triggering exception.</p> - * - * <p>If you set <code>eventPropertyName</code> to a non-null value the - * <code>action</code> parameter will be interpreted as a property name - * or a method name of the target object.</p> - * - * <p>Any object retrieved from the event object and applied to the - * target will converted from primitives to their wrapper class or - * vice versa or applied to a method that accepts a superclass - * of the object.</p> - * - * <p>Examples:</p> - * <p>The following code:</p><code> - * button.addActionListener( - * new ActionListener() { - * public void actionPerformed(ActionEvent ae) { - * Object o = ae.getSource().getClass().getName(); - * textField.setText((String) o); - * } - * }); - * </code> - * - * <p>Can be expressed using the <code>EventHandler</code> like this:</p> - * <p> - * <code>button.addActionListener((ActionListener) - * EventHandler.create(ActionListener.class, textField, "text", "source.class.name"); - * <code> - * </p> - * - * <p>As said above you can specify the target as a method, too:</p> - * <p> - * <code>button.addActionListener((ActionListener) - * EventHandler.create(ActionListener.class, textField, "setText", "source.class.name"); - * <code> - * </p> - * - * <p>Furthermore you can use method names in the property:</p> - * <p> - * <code>button.addActionListener((ActionListener) - * EventHandler.create(ActionListener.class, textField, "setText", "getSource.getClass.getName"); - * <code> - * </p> - * - * <p>Finally you can mix names:</p> - * <p> - * <code>button.addActionListener((ActionListener) - * EventHandler.create(ActionListener.class, textField, "setText", "source.getClass.name"); - * <code> - * </p> - * - * <p>A call to this method is equivalent to: - * <code>create(listenerInterface, target, action, null, null)</code> - * </p> - * - * @param listenerInterface Listener interface to implement. - * @param target Object to invoke action on. - * @param action Target property or method to invoke. - * @param eventPropertyName Name of property to extract from event. - * @return A constructed proxy object. - */ - public static Object create(Class listenerInterface, Object target, - String action, String eventPropertyName) - { - return create(listenerInterface, target, action, eventPropertyName, null); - } - - /** - * <p>Constructs an implementation of <code>listenerInterface</code> - * to dispatch events.</p> - * - * <p>Besides the functionality described for {@link create(Class, Object, String)} - * and {@link create(Class, Object, String, String)} this method allows you - * to filter the listener method that should have an effect. Look at these - * method's documentation for more information about the <code>EventHandler</code>'s - * usage.</p> - * - * <p>If you want to call <code>dispose</code> on a <code>JFrame</code> instance - * when the <code>WindowListener.windowClosing()</code> method was invoked use - * the following code:</p> - * <p> - * <code> - * EventHandler.create(WindowListener.class, jframeInstance, "dispose", null, "windowClosing"); - * </code> - * </p> - * - * <p>A <code>NullPointerException</code> is thrown if the <code>listenerInterface</code> - * or <code>target</code> argument are <code>null</code>. - * - * @param listenerInterface Listener interface to implement. - * @param target Object to invoke action on. - * @param action Target method name to invoke. - * @param eventPropertyName Name of property to extract from event. - * @param listenerMethodName Listener method to implement. - * @return A constructed proxy object. - */ - public static Object create(Class listenerInterface, Object target, - String action, String eventPropertyName, - String listenerMethodName) - { - // Create EventHandler instance - EventHandler eh = new EventHandler(target, action, eventPropertyName, - listenerMethodName); - - // Create proxy object passing in the event handler - Object proxy = Proxy.newProxyInstance(listenerInterface.getClassLoader(), - new Class[] {listenerInterface}, - eh); - - return proxy; - } - -} diff --git a/libjava/java/beans/EventSetDescriptor.java b/libjava/java/beans/EventSetDescriptor.java deleted file mode 100644 index 8624e643476..00000000000 --- a/libjava/java/beans/EventSetDescriptor.java +++ /dev/null @@ -1,442 +0,0 @@ -/* java.beans.EventSetDescriptor - Copyright (C) 1998 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.beans; - -import gnu.java.lang.ClassHelper; - -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.util.Vector; - -/** - ** EventSetDescriptor describes the hookup between an event source - ** class and an event listener class. - ** - ** EventSets have several attributes: the listener class, the events - ** that can be fired to the listener (methods in the listener class), and - ** an add and remove listener method from the event firer's class.<P> - ** - ** The methods have these constraints on them:<P> - ** <UL> - ** <LI>event firing methods: must have <CODE>void</CODE> return value. Any - ** parameters and exceptions are allowed. May be public, protected or - ** package-protected. (Don't ask me why that is, I'm just following the spec. - ** The only place it is even mentioned is in the Java Beans white paper, and - ** there it is only implied.)</LI> - ** <LI>add listener method: must have <CODE>void</CODE> return value. Must - ** take exactly one argument, of the listener class's type. May fire either - ** zero exceptions, or one exception of type <CODE>java.util.TooManyListenersException</CODE>. - ** Must be public.</LI> - ** <LI>remove listener method: must have <CODE>void</CODE> return value. - ** Must take exactly one argument, of the listener class's type. May not - ** fire any exceptions. Must be public.</LI> - ** </UL> - ** - ** A final constraint is that event listener classes must extend from EventListener.<P> - ** - ** There are also various design patterns associated with some of the methods - ** of construction. Those are explained in more detail in the appropriate - ** constructors.<P> - ** - ** <STRONG>Documentation Convention:</STRONG> for proper - ** Internalization of Beans inside an RAD tool, sometimes there - ** are two names for a property or method: a programmatic, or - ** locale-independent name, which can be used anywhere, and a - ** localized, display name, for ease of use. In the - ** documentation I will specify different String values as - ** either <EM>programmatic</EM> or <EM>localized</EM> to - ** make this distinction clear. - ** - ** @author John Keiser - ** @since JDK1.1 - ** @version 1.1.0, 31 May 1998 - **/ - -public class EventSetDescriptor extends FeatureDescriptor { - private Method addListenerMethod; - private Method removeListenerMethod; - private Class listenerType; - private MethodDescriptor[] listenerMethodDescriptors; - private Method[] listenerMethods; - - private boolean unicast; - private boolean inDefaultEventSet = true; - - /** Create a new EventSetDescriptor. - ** This version of the constructor enforces the rules imposed on the methods - ** described at the top of this class, as well as searching for:<P> - ** <OL> - ** <LI>The event-firing method must be non-private with signature - ** <CODE>void <listenerMethodName>(<eventSetName>Event)</CODE> - ** (where <CODE><eventSetName></CODE> has its first character capitalized - ** by the constructor and the Event is a descendant of - ** <CODE>java.util.EventObject</CODE>) in class <CODE>listenerType</CODE> - ** (any exceptions may be thrown). - ** <B>Implementation note:</B> Note that there could conceivably be multiple - ** methods with this type of signature (example: java.util.MouseEvent vs. - ** my.very.own.MouseEvent). In this implementation, all methods fitting the - ** description will be put into the <CODE>EventSetDescriptor</CODE>, even - ** though the spec says only one should be chosen (they probably weren't thinking as - ** pathologically as I was). I don't like arbitrarily choosing things. - ** If your class has only one such signature, as most do, you'll have no problems.</LI> - ** <LI>The add and remove methods must be public and named - ** <CODE>void add<eventSetName>Listener(<listenerType>)</CODE> and - ** <CODE>void remove<eventSetName>Listener(<listenerType>)</CODE> in - ** in class <CODE>eventSourceClass</CODE>, where - ** <CODE><eventSetName></CODE> will have its first letter capitalized. - ** Standard exception rules (see class description) apply.</LI> - ** </OL> - ** @param eventSourceClass the class containing the add/remove listener methods. - ** @param eventSetName the programmatic name of the event set, generally starting - ** with a lowercase letter (i.e. fooManChu instead of FooManChu). This will be used - ** to generate the name of the event object as well as the names of the add and - ** remove methods. - ** @param listenerType the class containing the event firing method. - ** @param listenerMethodName the name of the event firing method. - ** @exception IntrospectionException if listenerType is not an EventListener, - ** or if methods are not found or are invalid. - **/ - public EventSetDescriptor(Class eventSourceClass, - String eventSetName, - Class listenerType, - String listenerMethodName) throws IntrospectionException { - setName(eventSetName); - if(!java.util.EventListener.class.isAssignableFrom(listenerType)) { - throw new IntrospectionException("Listener type is not an EventListener."); - } - - String[] names = new String[1]; - names[0] = listenerMethodName; - - try { - eventSetName = Character.toUpperCase(eventSetName.charAt(0)) + eventSetName.substring(1); - } catch(StringIndexOutOfBoundsException e) { - eventSetName = ""; - } - - findMethods(eventSourceClass,listenerType,names,"add"+eventSetName+"Listener","remove"+eventSetName+"Listener",eventSetName+"Event"); - this.listenerType = listenerType; - checkAddListenerUnicast(); - if(this.removeListenerMethod.getExceptionTypes().length > 0) { - throw new IntrospectionException("Listener remove method throws exceptions."); - } - } - - /** Create a new EventSetDescriptor. - ** This form of the constructor allows you to specify the names of the methods and adds - ** no new constraints on top of the rules already described at the top of the class.<P> - ** - ** @param eventSourceClass the class containing the add and remove listener methods. - ** @param eventSetName the programmatic name of the event set, generally starting - ** with a lowercase letter (i.e. fooManChu instead of FooManChu). - ** @param listenerType the class containing the event firing methods. - ** @param listenerMethodNames the names of the even firing methods. - ** @param addListenerMethodName the name of the add listener method. - ** @param removeListenerMethodName the name of the remove listener method. - ** @exception IntrospectionException if listenerType is not an EventListener - ** or if methods are not found or are invalid. - **/ - public EventSetDescriptor(Class eventSourceClass, - String eventSetName, - Class listenerType, - String[] listenerMethodNames, - String addListenerMethodName, - String removeListenerMethodName) throws IntrospectionException { - setName(eventSetName); - if(!java.util.EventListener.class.isAssignableFrom(listenerType)) { - throw new IntrospectionException("Listener type is not an EventListener."); - } - - findMethods(eventSourceClass,listenerType,listenerMethodNames,addListenerMethodName,removeListenerMethodName,null); - this.listenerType = listenerType; - checkAddListenerUnicast(); - if(this.removeListenerMethod.getExceptionTypes().length > 0) { - throw new IntrospectionException("Listener remove method throws exceptions."); - } - } - - /** Create a new EventSetDescriptor. - ** This form of constructor allows you to explicitly say which methods do what, and - ** no reflection is done by the EventSetDescriptor. The methods are, however, - ** checked to ensure that they follow the rules set forth at the top of the class. - ** @param eventSetName the programmatic name of the event set, generally starting - ** with a lowercase letter (i.e. fooManChu instead of FooManChu). - ** @param listenerType the class containing the listenerMethods. - ** @param listenerMethods the event firing methods. - ** @param addListenerMethod the add listener method. - ** @param removeListenerMethod the remove listener method. - ** @exception IntrospectionException if the listenerType is not an EventListener, - ** or any of the methods are invalid. - **/ - public EventSetDescriptor(String eventSetName, - Class listenerType, - Method[] listenerMethods, - Method addListenerMethod, - Method removeListenerMethod) throws IntrospectionException { - setName(eventSetName); - if(!java.util.EventListener.class.isAssignableFrom(listenerType)) { - throw new IntrospectionException("Listener type is not an EventListener."); - } - - this.listenerMethods = listenerMethods; - this.addListenerMethod = addListenerMethod; - this.removeListenerMethod = removeListenerMethod; - this.listenerType = listenerType; - checkMethods(); - checkAddListenerUnicast(); - if(this.removeListenerMethod.getExceptionTypes().length > 0) { - throw new IntrospectionException("Listener remove method throws exceptions."); - } - } - - /** Create a new EventSetDescriptor. - ** This form of constructor allows you to explicitly say which methods do what, and - ** no reflection is done by the EventSetDescriptor. The methods are, however, - ** checked to ensure that they follow the rules set forth at the top of the class. - ** @param eventSetName the programmatic name of the event set, generally starting - ** with a lowercase letter (i.e. fooManChu instead of FooManChu). - ** @param listenerType the class containing the listenerMethods. - ** @param listenerMethodDescriptors the event firing methods. - ** @param addListenerMethod the add listener method. - ** @param removeListenerMethod the remove listener method. - ** @exception IntrospectionException if the listenerType is not an EventListener, - ** or any of the methods are invalid. - **/ - public EventSetDescriptor(String eventSetName, - Class listenerType, - MethodDescriptor[] listenerMethodDescriptors, - Method addListenerMethod, - Method removeListenerMethod) throws IntrospectionException { - setName(eventSetName); - if(!java.util.EventListener.class.isAssignableFrom(listenerType)) { - throw new IntrospectionException("Listener type is not an EventListener."); - } - - this.listenerMethodDescriptors = listenerMethodDescriptors; - this.listenerMethods = new Method[listenerMethodDescriptors.length]; - for(int i=0;i<this.listenerMethodDescriptors.length;i++) { - this.listenerMethods[i] = this.listenerMethodDescriptors[i].getMethod(); - } - - this.addListenerMethod = addListenerMethod; - this.removeListenerMethod = removeListenerMethod; - this.listenerType = listenerType; - checkMethods(); - checkAddListenerUnicast(); - if(this.removeListenerMethod.getExceptionTypes().length > 0) { - throw new IntrospectionException("Listener remove method throws exceptions."); - } - } - - /** Get the class that contains the event firing methods. **/ - public Class getListenerType() { - return listenerType; - } - - /** Get the event firing methods. **/ - public Method[] getListenerMethods() { - return listenerMethods; - } - - /** Get the event firing methods as MethodDescriptors. **/ - public MethodDescriptor[] getListenerMethodDescriptors() { - if(listenerMethodDescriptors == null) { - listenerMethodDescriptors = new MethodDescriptor[listenerMethods.length]; - for(int i=0;i<listenerMethods.length;i++) { - listenerMethodDescriptors[i] = new MethodDescriptor(listenerMethods[i]); - } - } - return listenerMethodDescriptors; - } - - /** Get the add listener method. **/ - public Method getAddListenerMethod() { - return addListenerMethod; - } - - /** Get the remove listener method. **/ - public Method getRemoveListenerMethod() { - return removeListenerMethod; - } - - /** Set whether or not multiple listeners may be added. - ** @param unicast whether or not multiple listeners may be added. - **/ - public void setUnicast(boolean unicast) { - this.unicast = unicast; - } - - /** Get whether or not multiple listeners may be added. (Defaults to false.) **/ - public boolean isUnicast() { - return unicast; - } - - /** Set whether or not this is in the default event set. - ** @param inDefaultEventSet whether this is in the default event set. - **/ - public void setInDefaultEventSet(boolean inDefaultEventSet) { - this.inDefaultEventSet = inDefaultEventSet; - } - - /** Get whether or not this is in the default event set. (Defaults to true.)**/ - public boolean isInDefaultEventSet() { - return inDefaultEventSet; - } - - private void checkAddListenerUnicast() throws IntrospectionException { - Class[] addListenerExceptions = this.addListenerMethod.getExceptionTypes(); - if(addListenerExceptions.length > 1) { - throw new IntrospectionException("Listener add method throws too many exceptions."); - } else if(addListenerExceptions.length == 1 - && !java.util.TooManyListenersException.class.isAssignableFrom(addListenerExceptions[0])) { - throw new IntrospectionException("Listener add method throws too many exceptions."); - } - } - - private void checkMethods() throws IntrospectionException { - if(!addListenerMethod.getDeclaringClass().isAssignableFrom(removeListenerMethod.getDeclaringClass()) - && !removeListenerMethod.getDeclaringClass().isAssignableFrom(addListenerMethod.getDeclaringClass())) { - throw new IntrospectionException("add and remove listener methods do not come from the same class. This is bad."); - } - if(!addListenerMethod.getReturnType().equals(java.lang.Void.TYPE) - || addListenerMethod.getParameterTypes().length != 1 - || !listenerType.equals(addListenerMethod.getParameterTypes()[0]) - || !Modifier.isPublic(addListenerMethod.getModifiers())) { - throw new IntrospectionException("Add Listener Method invalid."); - } - if(!removeListenerMethod.getReturnType().equals(java.lang.Void.TYPE) - || removeListenerMethod.getParameterTypes().length != 1 - || !listenerType.equals(removeListenerMethod.getParameterTypes()[0]) - || removeListenerMethod.getExceptionTypes().length > 0 - || !Modifier.isPublic(removeListenerMethod.getModifiers())) { - throw new IntrospectionException("Remove Listener Method invalid."); - } - - for(int i=0;i<listenerMethods.length;i++) { - if(!listenerMethods[i].getReturnType().equals(java.lang.Void.TYPE) - || Modifier.isPrivate(listenerMethods[i].getModifiers())) { - throw new IntrospectionException("Event Method " + listenerMethods[i].getName() + " non-void or private."); - } - if(!listenerMethods[i].getDeclaringClass().isAssignableFrom(listenerType)) { - throw new IntrospectionException("Event Method " + listenerMethods[i].getName() + " not from class " + listenerType.getName()); - } - } - } - - private void findMethods(Class eventSourceClass, - Class listenerType, - String listenerMethodNames[], - String addListenerMethodName, - String removeListenerMethodName, - String absurdEventClassCheckName) throws IntrospectionException { - - /* Find add listener method and remove listener method. */ - Class[] listenerArgList = new Class[1]; - listenerArgList[0] = listenerType; - try { - this.addListenerMethod = eventSourceClass.getMethod(addListenerMethodName,listenerArgList); - } catch(SecurityException E) { - throw new IntrospectionException("SecurityException trying to access method " + addListenerMethodName + "."); - } catch(NoSuchMethodException E) { - throw new IntrospectionException("Could not find method " + addListenerMethodName + "."); - } - - if(this.addListenerMethod == null || !this.addListenerMethod.getReturnType().equals(java.lang.Void.TYPE)) { - throw new IntrospectionException("Add listener method does not exist, is not public, or is not void."); - } - - try { - this.removeListenerMethod = eventSourceClass.getMethod(removeListenerMethodName,listenerArgList); - } catch(SecurityException E) { - throw new IntrospectionException("SecurityException trying to access method " + removeListenerMethodName + "."); - } catch(NoSuchMethodException E) { - throw new IntrospectionException("Could not find method " + removeListenerMethodName + "."); - } - if(this.removeListenerMethod == null || !this.removeListenerMethod.getReturnType().equals(java.lang.Void.TYPE)) { - throw new IntrospectionException("Remove listener method does not exist, is not public, or is not void."); - } - - /* Find the listener methods. */ - Method[] methods; - try { - methods = ClassHelper.getAllMethods(listenerType); - } catch(SecurityException E) { - throw new IntrospectionException("Security: You cannot access fields in this class."); - } - - Vector chosenMethods = new Vector(); - boolean[] listenerMethodFound = new boolean[listenerMethodNames.length]; - for(int i=0;i<methods.length;i++) { - if(Modifier.isPrivate(methods[i].getModifiers())) { - continue; - } - Method currentMethod = methods[i]; - Class retval = currentMethod.getReturnType(); - if(retval.equals(java.lang.Void.TYPE)) { - for(int j=0;j<listenerMethodNames.length;j++) { - if(currentMethod.getName().equals(listenerMethodNames[j]) - && (absurdEventClassCheckName == null - || (currentMethod.getParameterTypes().length == 1 - && ((currentMethod.getParameterTypes()[0]).getName().equals(absurdEventClassCheckName) - || (currentMethod.getParameterTypes()[0]).getName().endsWith("."+absurdEventClassCheckName) - ) - ) - ) - ) { - chosenMethods.addElement(currentMethod); - listenerMethodFound[j] = true; - } - } - } - } - - /* Make sure we found all the methods we were looking for. */ - for(int i=0;i<listenerMethodFound.length;i++) { - if(!listenerMethodFound[i]) { - throw new IntrospectionException("Could not find event method " + listenerMethodNames[i]); - } - } - - /* Now that we've chosen the listener methods we want, store them. */ - this.listenerMethods = new Method[chosenMethods.size()]; - for(int i=0;i<chosenMethods.size();i++) { - this.listenerMethods[i] = (Method)chosenMethods.elementAt(i); - } - } -} diff --git a/libjava/java/beans/ExceptionListener.java b/libjava/java/beans/ExceptionListener.java deleted file mode 100644 index 0eeb8a9561f..00000000000 --- a/libjava/java/beans/ExceptionListener.java +++ /dev/null @@ -1,57 +0,0 @@ -/* ExceptionListener.java -- listen for recoverable internal exceptions - Copyright (C) 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.beans; - -/** - * This interface allows a class to monitor internal exceptions, to try to - * recover from them. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.4 - * @status updated to 1.4 - */ -public interface ExceptionListener -{ - /** - * Fired after an exception occurs. - * - * @param e the trapped exception - */ - void exceptionThrown(Exception e); -} // interface ExceptionListener diff --git a/libjava/java/beans/Expression.java b/libjava/java/beans/Expression.java deleted file mode 100644 index 20b04f1c190..00000000000 --- a/libjava/java/beans/Expression.java +++ /dev/null @@ -1,133 +0,0 @@ -/* java.beans.Expression - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.beans; - -/** - * class Expression - * - * An Expression captures the execution of an object method that - * returns a value. It stores an object, the method to call, and the - * arguments to pass to the method. - * - * @since 1.4 - */ -public class Expression extends Statement -{ - // This is a placeholder to indicate that value hasn't been set - // yet; - private static final Object unset = new Object(); - - // The value to return. This is equal to unset until getValue is called. - private Object value; - - - /** - * Constructor - * - * Constructs an Expression representing the invocation of - * object.methodName(arg[0], arg[1], ...); However, it will never - * be executed. Instead, value will always be returned. - * - * @param value The value to return. - * @param target The object to invoke the method on. - * @param methodName The object method to invoke. - * @param arguments An array of arguments to pass to the method. - */ - public Expression(Object value, Object target, String methodName, - Object[] arguments) - { - super(target, methodName, arguments); - this.value = value; - } - - /** - * Constructor - * - * Constructs an Expression representing the invocation of - * object.methodName(arg[0], arg[1], ...); - * - * @param target The object to invoke the method on. - * @param methodName The object method to invoke. - * @param arguments An array of arguments to pass to the method. - */ - public Expression(Object target, String methodName, Object[] arguments) - { - super(target, methodName, arguments); - this.value = unset; - } - - /** - * Return the result of executing the method. - * - * If the cached value has not yet been set, the method is - * executed in the same way as Statement.execute(), except that - * the value is cached, and then returned. If the value has been - * set, it is returned without executing the method again. - * - * @return the result of executing the method. - * @exception Exception if an error occurs - */ - public Object getValue() throws Exception - { - if (value == unset) - value = doExecute(); - return value; - } - - /** - * Set the cached value to be returned by getValue() - * - * @param value the value to cache and return. - */ - public void setValue(Object value) - { - this.value = value; - } - - /** - * Return a string representation of this expression. - */ - public String toString() - { - String result = super.toString(); - if (value != unset) - return value.getClass().getName() + " " + result; - return result; - } -} diff --git a/libjava/java/beans/FeatureDescriptor.java b/libjava/java/beans/FeatureDescriptor.java deleted file mode 100644 index aeb40949099..00000000000 --- a/libjava/java/beans/FeatureDescriptor.java +++ /dev/null @@ -1,232 +0,0 @@ -/* java.beans.FeatureDescriptor - Copyright (C) 1998, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.beans; - -import java.util.Enumeration; -import java.util.Hashtable; - -/** - * FeatureDescriptor is the common superclass for all JavaBeans Descriptor - * classes. JavaBeans descriptors are abstract descriptors of properties, - * events, methods, beans, etc.<P> - * - * <STRONG>Documentation Convention:</STRONG> for proper - * Internalization of Beans inside an RAD tool, sometimes there - * are two names for a property or method: a programmatic, or - * locale-independent name, which can be used anywhere, and a - * localized, display name, for ease of use. In the - * documentation I will specify different String values as - * either <EM>programmatic</EM> or <EM>localized</EM> to - * make this distinction clear. - * - * @author John Keiser - * @since 1.1 - */ - -public class FeatureDescriptor -{ - String name; - String displayName; - String shortDescription; - boolean expert; - boolean hidden; - boolean preferred; - - Hashtable valueHash; - - /** - * Instantiate this FeatureDescriptor with appropriate default values. - */ - public FeatureDescriptor() - { - valueHash = new Hashtable(); - } - - /** - * Get the programmatic name of this feature. - */ - public String getName() - { - return name; - } - - /** - * Set the programmatic name of this feature. - * - * @param name the new name for this feature. - */ - public void setName(String name) - { - this.name = name; - } - - /** - * Get the localized (display) name of this feature. - * - * @returns The localized display name of this feature or falls - * back to the programmatic name. - */ - public String getDisplayName() - { - return (displayName == null) ? name : displayName; - } - - /** - * Set the localized (display) name of this feature. - * - * @param displayName the new display name for this feature. - */ - public void setDisplayName(String displayName) - { - this.displayName = displayName; - } - - /** - * Get the localized short description for this feature. - * - * @returns A short localized description of this feature or - * what <code>getDisplayName</code> returns in case, that no short description - * is available. - */ - public String getShortDescription() - { - return (shortDescription == null) ? getDisplayName() : shortDescription; - } - - /** - * Set the localized short description for this feature. - * - * @param shortDescription the new short description for this feature. - */ - public void setShortDescription(String shortDescription) - { - this.shortDescription = shortDescription; - } - - /** - * Indicates whether this feature is for expert use only. - * - * @return true if for use by experts only, - * or false if anyone can use it. - */ - public boolean isExpert() - { - return expert; - } - - /** - * Set whether this feature is for expert use only. - * - * @param expert true if for use by experts only, - * or false if anyone can use it. - */ - public void setExpert(boolean expert) - { - this.expert = expert; - } - - /** - * Indicates whether this feature is for use by tools only. - * If it is for use by tools only, then it should not be displayed. - * - * @return true if tools only should use it, - * or false if anyone can see it. - */ - public boolean isHidden() - { - return hidden; - } - - /** - * Set whether this feature is for use by tools only. - * If it is for use by tools only, then it should not be displayed. - * - * @param hidden true if tools only should use it, - * or false if anyone can see it. - */ - public void setHidden(boolean hidden) - { - this.hidden = hidden; - } - - public boolean isPreferred () - { - return preferred; - } - - public void setPreferred (boolean preferred) - { - this.preferred = preferred; - } - - /** - * Get an arbitrary value set with setValue(). - * - * @param name the programmatic name of the key. - * - * @return the value associated with this name, - * or null if there is none. - */ - public Object getValue(String name) - { - return valueHash.get(name); - } - - /** - * Set an arbitrary string-value pair with this feature. - * - * @param name the programmatic name of the key. - * @param value the value to associate with the name. - */ - public void setValue(String name, Object value) - { - valueHash.put(name, value); - } - - /** - * Get a list of the programmatic key names set with setValue(). - * - * @return an Enumerator over all the programmatic key names associated - * with this feature. - */ - public Enumeration attributeNames() - { - return valueHash.keys(); - } -} diff --git a/libjava/java/beans/IndexedPropertyDescriptor.java b/libjava/java/beans/IndexedPropertyDescriptor.java deleted file mode 100644 index efdc7b40238..00000000000 --- a/libjava/java/beans/IndexedPropertyDescriptor.java +++ /dev/null @@ -1,307 +0,0 @@ -/* java.beans.IndexedPropertyDescriptor - Copyright (C) 1998, 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.beans; - -import java.lang.reflect.Array; -import java.lang.reflect.Method; - -/** - ** IndexedPropertyDescriptor describes information about a JavaBean - ** indexed property, by which we mean an array-like property that - ** has been exposed via a pair of get and set methods and another - ** pair that allows you to get to the property by an index.<P> - ** - ** An example property would have four methods like this:<P> - ** <CODE>FooBar[] getFoo()</CODE><BR> - ** <CODE>void setFoo(FooBar[])</CODE><BR> - ** <CODE>FooBar getFoo(int)</CODE><BR> - ** <CODE>void setFoo(int,FooBar)</CODE><P> - ** - ** The constraints put on get and set methods are:<P> - ** <OL> - ** <LI>There must be at least a get(int) or a set(int,...) method. - ** Nothing else is required. <B>Spec note:</B>One nice restriction - ** would be that if there is a get() there must be a get(int), same - ** with set, but that is not in the spec and is fairly harmless.)</LI> - ** <LI>A get array method must have signature - ** <CODE><propertyType>[] <getMethodName>()</CODE></LI> - ** <LI>A set array method must have signature - ** <CODE>void <setMethodName>(<propertyType>[])</CODE></LI> - ** <LI>A get index method must have signature - ** <CODE><propertyType> <getMethodName>(int)</CODE></LI> - ** <LI>A set index method must have signature - ** <CODE>void <setMethodName>(int,<propertyType>)</CODE></LI> - ** <LI>All these methods may throw any exception.</LI> - ** <LI>All these methods must be public.</LI> - ** </OL> - ** - ** @author John Keiser - ** @since JDK1.1 - ** @version 1.1.0, 26 Jul 1998 - **/ - -public class IndexedPropertyDescriptor extends PropertyDescriptor { - private Class indexedPropertyType; - private Method setIndex; - private Method getIndex; - - /** Create a new IndexedPropertyDescriptor by introspection. - ** This form of constructor creates the PropertyDescriptor by - ** looking for getter methods named <CODE>get<name>()</CODE> - ** and setter methods named - ** <CODE>set<name>()</CODE> in class - ** <CODE><beanClass></CODE>, where <name> has its - ** first letter capitalized by the constructor.<P> - ** - ** <B>Implementation note:</B> If there is a get(int) method, - ** then the return type of that method is used to find the - ** remaining methods. If there is no get method, then the - ** set(int) method is searched for exhaustively and that type - ** is used to find the others.<P> - ** - ** <B>Spec note:</B> - ** If there is no get(int) method and multiple set(int) methods with - ** the same name and the correct parameters (different type of course), - ** then an IntrospectionException is thrown. While Sun's spec - ** does not state this, it can make Bean behavior different on - ** different systems (since method order is not guaranteed) and as - ** such, can be treated as a bug in the spec. I am not aware of - ** whether Sun's implementation catches this. - ** - ** @param name the programmatic name of the property, usually - ** starting with a lowercase letter (e.g. fooManChu - ** instead of FooManChu). - ** @param beanClass the class the get and set methods live in. - ** @exception IntrospectionException if the methods are not found or invalid. - **/ - public IndexedPropertyDescriptor(String name, Class beanClass) throws IntrospectionException { - super(name); - String capitalized; - try { - capitalized = Character.toUpperCase(name.charAt(0)) + name.substring(1); - } catch(StringIndexOutOfBoundsException e) { - capitalized = ""; - } - findMethods(beanClass, "get" + capitalized, "set" + capitalized, "get" + capitalized, "set" + capitalized); - } - - /** Create a new IndexedPropertyDescriptor by introspection. - ** This form of constructor allows you to specify the - ** names of the get and set methods to search for.<P> - ** - ** <B>Implementation note:</B> If there is a get(int) method, - ** then the return type of that method is used to find the - ** remaining methods. If there is no get method, then the - ** set(int) method is searched for exhaustively and that type - ** is used to find the others.<P> - ** - ** <B>Spec note:</B> - ** If there is no get(int) method and multiple set(int) methods with - ** the same name and the correct parameters (different type of course), - ** then an IntrospectionException is thrown. While Sun's spec - ** does not state this, it can make Bean behavior different on - ** different systems (since method order is not guaranteed) and as - ** such, can be treated as a bug in the spec. I am not aware of - ** whether Sun's implementation catches this. - ** - ** @param name the programmatic name of the property, usually - ** starting with a lowercase letter (e.g. fooManChu - ** instead of FooManChu). - ** @param beanClass the class the get and set methods live in. - ** @param getMethodName the name of the get array method. - ** @param setMethodName the name of the set array method. - ** @param getIndexName the name of the get index method. - ** @param setIndexName the name of the set index method. - ** @exception IntrospectionException if the methods are not found or invalid. - **/ - public IndexedPropertyDescriptor(String name, Class beanClass, String getMethodName, String setMethodName, String getIndexName, String setIndexName) throws IntrospectionException { - super(name); - findMethods(beanClass, getMethodName, setMethodName, getIndexName, setIndexName); - } - - /** Create a new PropertyDescriptor using explicit Methods. - ** Note that the methods will be checked for conformance to standard - ** Property method rules, as described above at the top of this class. - ** - ** @param name the programmatic name of the property, usually - ** starting with a lowercase letter (e.g. fooManChu - ** instead of FooManChu). - ** @param getMethod the get array method. - ** @param setMethod the set array method. - ** @param getIndex the get index method. - ** @param setIndex the set index method. - ** @exception IntrospectionException if the methods are not found or invalid. - **/ - public IndexedPropertyDescriptor(String name, Method getMethod, Method setMethod, Method getIndex, Method setIndex) throws IntrospectionException { - super(name); - if(getMethod != null && getMethod.getParameterTypes().length > 0) { - throw new IntrospectionException("get method has parameters"); - } - if(getMethod != null && setMethod.getParameterTypes().length != 1) { - throw new IntrospectionException("set method does not have exactly one parameter"); - } - if(getMethod != null && setMethod != null) { - if(!getMethod.getReturnType().equals(setMethod.getParameterTypes()[0])) { - throw new IntrospectionException("set and get methods do not share the same type"); - } - if(!getMethod.getDeclaringClass().isAssignableFrom(setMethod.getDeclaringClass()) - && !setMethod.getDeclaringClass().isAssignableFrom(getMethod.getDeclaringClass())) { - throw new IntrospectionException("set and get methods are not in the same class."); - } - } - - if(getIndex != null && (getIndex.getParameterTypes().length != 1 - || !(getIndex.getParameterTypes()[0]).equals(java.lang.Integer.TYPE))) { - throw new IntrospectionException("get index method has wrong parameters"); - } - if(setIndex != null && (setIndex.getParameterTypes().length != 2 - || !(setIndex.getParameterTypes()[0]).equals(java.lang.Integer.TYPE))) { - throw new IntrospectionException("set index method has wrong parameters"); - } - if(getIndex != null && setIndex != null) { - if(!getIndex.getReturnType().equals(setIndex.getParameterTypes()[1])) { - throw new IntrospectionException("set index methods do not share the same type"); - } - if(!getIndex.getDeclaringClass().isAssignableFrom(setIndex.getDeclaringClass()) - && !setIndex.getDeclaringClass().isAssignableFrom(getIndex.getDeclaringClass())) { - throw new IntrospectionException("get and set index methods are not in the same class."); - } - } - - if(getIndex != null && getMethod != null && !getIndex.getDeclaringClass().isAssignableFrom(getMethod.getDeclaringClass()) - && !getMethod.getDeclaringClass().isAssignableFrom(getIndex.getDeclaringClass())) { - throw new IntrospectionException("methods are not in the same class."); - } - - if(getIndex != null && getMethod != null && !Array.newInstance(getIndex.getReturnType(),0).getClass().equals(getMethod.getReturnType())) { - throw new IntrospectionException("array methods do not match index methods."); - } - - this.getMethod = getMethod; - this.setMethod = setMethod; - this.getIndex = getIndex; - this.setIndex = setIndex; - this.indexedPropertyType = getIndex != null ? getIndex.getReturnType() : setIndex.getParameterTypes()[1]; - this.propertyType = getMethod != null ? getMethod.getReturnType() : (setMethod != null ? setMethod.getParameterTypes()[0] : Array.newInstance(this.indexedPropertyType,0).getClass()); - } - - public Class getIndexedPropertyType() { - return indexedPropertyType; - } - - public Method getIndexedReadMethod() { - return getIndex; - } - - public Method getIndexedWriteMethod() { - return setIndex; - } - - private void findMethods(Class beanClass, String getMethodName, String setMethodName, String getIndexName, String setIndexName) throws IntrospectionException { - try { - if(getIndexName != null) { - try { - Class[] getArgs = new Class[1]; - getArgs[0] = java.lang.Integer.TYPE; - getIndex = beanClass.getMethod(getIndexName,getArgs); - indexedPropertyType = getIndex.getReturnType(); - } catch(NoSuchMethodException E) { - } - } - if(getIndex != null) { - if(setIndexName != null) { - try { - Class[] setArgs = new Class[2]; - setArgs[0] = java.lang.Integer.TYPE; - setArgs[1] = indexedPropertyType; - setIndex = beanClass.getMethod(setIndexName,setArgs); - if(!setIndex.getReturnType().equals(java.lang.Void.TYPE)) { - throw new IntrospectionException(setIndexName + " has non-void return type"); - } - } catch(NoSuchMethodException E) { - } - } - } else if(setIndexName != null) { - Method[] m = beanClass.getMethods(); - for(int i=0;i<m.length;i++) { - Method current = m[i]; - if(current.getName().equals(setIndexName) - && current.getParameterTypes().length == 2 - && (current.getParameterTypes()[0]).equals(java.lang.Integer.TYPE) - && current.getReturnType().equals(java.lang.Void.TYPE)) { - if(setIndex != null) { - throw new IntrospectionException("Multiple, different set methods found that fit the bill!"); - } else { - setIndex = current; - indexedPropertyType = current.getParameterTypes()[1]; - } - } - } - if(setIndex == null) { - throw new IntrospectionException("Cannot find get or set methods."); - } - } else { - throw new IntrospectionException("Cannot find get or set methods."); - } - - Class arrayType = Array.newInstance(indexedPropertyType,0).getClass(); - - Class[] setArgs = new Class[1]; - setArgs[0] = arrayType; - try { - setMethod = beanClass.getMethod(setMethodName,setArgs); - if(!setMethod.getReturnType().equals(java.lang.Void.TYPE)) { - setMethod = null; - } - } catch(NoSuchMethodException E) { - } - - Class[] getArgs = new Class[0]; - try { - getMethod = beanClass.getMethod(getMethodName,getArgs); - if(!getMethod.getReturnType().equals(arrayType)) { - getMethod = null; - } - } catch(NoSuchMethodException E) { - } - } catch(SecurityException E) { - throw new IntrospectionException("SecurityException while trying to find methods."); - } - } -} diff --git a/libjava/java/beans/IntrospectionException.java b/libjava/java/beans/IntrospectionException.java deleted file mode 100644 index 7bb83dac5b3..00000000000 --- a/libjava/java/beans/IntrospectionException.java +++ /dev/null @@ -1,67 +0,0 @@ -/* IntrospectionException -- thrown when an exception occurs in introspection - Copyright (C) 1998, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.beans; - -/** - * IntrospectionException is thrown when the Introspector fails. Typical - * causes are the inability to map a name to its Class, or specifying a - * wrong type signature. - * - * @author John Keiser - * @see Introspector - * @since 1.1 - * @status updated to 1.4 - */ -public class IntrospectionException extends Exception -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = -3728150539969542619L; - - /** - * Instantiate this exception with the given message. - * - * @param msg the message for the exception - */ - public IntrospectionException(String msg) - { - super(msg); - } -} diff --git a/libjava/java/beans/Introspector.java b/libjava/java/beans/Introspector.java deleted file mode 100644 index 02781b46e0d..00000000000 --- a/libjava/java/beans/Introspector.java +++ /dev/null @@ -1,608 +0,0 @@ -/* java.beans.Introspector - Copyright (C) 1998, 2002, 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.beans; - -import gnu.java.beans.BeanInfoEmbryo; -import gnu.java.beans.ExplicitBeanInfo; -import gnu.java.beans.IntrospectionIncubator; -import gnu.java.lang.ClassHelper; - -import java.util.Hashtable; -import java.util.Vector; - -/** - * Introspector is the class that does the bulk of the - * design-time work in Java Beans. Every class must have - * a BeanInfo in order for an RAD tool to use it; but, as - * promised, you don't have to write the BeanInfo class - * yourself if you don't want to. All you have to do is - * call getBeanInfo() in the Introspector and it will use - * standard JavaBeans-defined method signatures to - * determine the information about your class.<P> - * - * Don't worry about it too much, though: you can provide - * JavaBeans with as much customized information as you - * want, or as little as you want, using the BeanInfo - * interface (see BeanInfo for details).<P> - * - * <STRONG>Order of Operations</STRONG><P> - * - * When you call getBeanInfo(class c), the Introspector - * first searches for BeanInfo class to see if you - * provided any explicit information. It searches for a - * class named <bean class name>BeanInfo in different - * packages, first searching the bean class's package - * and then moving on to search the beanInfoSearchPath.<P> - * - * If it does not find a BeanInfo class, it acts as though - * it had found a BeanInfo class returning null from all - * methods (meaning it should discover everything through - * Introspection). If it does, then it takes the - * information it finds in the BeanInfo class to be - * canonical (that is, the information speaks for its - * class as well as all superclasses).<P> - * - * When it has introspected the class, calls - * getBeanInfo(c.getSuperclass) and adds that information - * to the information it has, not adding to any information - * it already has that is canonical.<P> - * - * <STRONG>Introspection Design Patterns</STRONG><P> - * - * When the Introspector goes in to read the class, it - * follows a well-defined order in order to not leave any - * methods unaccounted for. Its job is to step over all - * of the public methods in a class and determine whether - * they are part of a property, an event, or a method (in - * that order). - * - * - * <STRONG>Properties:</STRONG><P> - * - * <OL> - * <LI>If there is a <CODE>public boolean isXXX()</CODE> - * method, then XXX is a read-only boolean property. - * <CODE>boolean getXXX()</CODE> may be supplied in - * addition to this method, although isXXX() is the - * one that will be used in this case and getXXX() - * will be ignored. If there is a - * <CODE>public void setXXX(boolean)</CODE> method, - * it is part of this group and makes it a read-write - * property.</LI> - * <LI>If there is a - * <CODE>public <type> getXXX(int)</CODE> - * method, then XXX is a read-only indexed property of - * type <type>. If there is a - * <CODE>public void setXXX(int,<type>)</CODE> - * method, then it is a read-write indexed property of - * type <type>. There may also be a - * <CODE>public <type>[] getXXX()</CODE> and a - * <CODE>public void setXXX(<type>)</CODE> - * method as well.</LI> - * <LI>If there is a - * <CODE>public void setXXX(int,<type>)</CODE> - * method, then it is a write-only indexed property of - * type <type>. There may also be a - * <CODE>public <type>[] getXXX()</CODE> and a - * <CODE>public void setXXX(<type>)</CODE> - * method as well.</LI> - * <LI>If there is a - * <CODE>public <type> getXXX()</CODE> method, - * then XXX is a read-only property of type - * <type>. If there is a - * <CODE>public void setXXX(<type>)</CODE> - * method, then it will be used for the property and - * the property will be considered read-write.</LI> - * <LI>If there is a - * <CODE>public void setXXX(<type>)</CODE> - * method, then as long as XXX is not already used as - * the name of a property, XXX is assumed to be a - * write-only property of type <type>.</LI> - * <LI>In all of the above cases, if the setXXX() method - * throws <CODE>PropertyVetoException</CODE>, then the - * property in question is assumed to be constrained. - * No properties are ever assumed to be bound - * (<STRONG>Spec Note:</STRONG> this is not in the - * spec, it just makes sense). See PropertyDescriptor - * for a description of bound and constrained - * properties.</LI> - * </OL> - * - * <STRONG>Events:</STRONG><P> - * - * If there is a pair of methods, - * <CODE>public void addXXX(<type>)</CODE> and - * <CODE>public void removeXXX(<type>)</CODE>, where - * <type> is a descendant of - * <CODE>java.util.EventListener</CODE>, then the pair of - * methods imply that this Bean will fire events to - * listeners of type <type>.<P> - * - * If the addXXX() method throws - * <CODE>java.util.TooManyListenersException</CODE>, then - * the event set is assumed to be <EM>unicast</EM>. See - * EventSetDescriptor for a discussion of unicast event - * sets.<P> - * - * <STRONG>Spec Note:</STRONG> the spec seems to say that - * the listener type's classname must be equal to the XXX - * part of addXXX() and removeXXX(), but that is not the - * case in Sun's implementation, so I am assuming it is - * not the case in general.<P> - * - * <STRONG>Methods:</STRONG><P> - * - * Any public methods (including those which were used - * for Properties or Events) are used as Methods. - * - * @author John Keiser - * @since JDK1.1 - * @see java.beans.BeanInfo - */ -public class Introspector { - - public static final int USE_ALL_BEANINFO = 1; - public static final int IGNORE_IMMEDIATE_BEANINFO = 2; - public static final int IGNORE_ALL_BEANINFO = 3; - - static String[] beanInfoSearchPath = {"gnu.java.beans.info"}; - static Hashtable beanInfoCache = new Hashtable(); - - private Introspector() {} - - /** - * Get the BeanInfo for class <CODE>beanClass</CODE>, - * first by looking for explicit information, next by - * using standard design patterns to determine - * information about the class. - * - * @param beanClass the class to get BeanInfo about. - * @return the BeanInfo object representing the class. - */ - public static BeanInfo getBeanInfo(Class beanClass) - throws IntrospectionException - { - BeanInfo cachedInfo; - synchronized(beanClass) - { - cachedInfo = (BeanInfo)beanInfoCache.get(beanClass); - if(cachedInfo != null) - { - return cachedInfo; - } - cachedInfo = getBeanInfo(beanClass,null); - beanInfoCache.put(beanClass,cachedInfo); - return cachedInfo; - } - } - - /** - * Flush all of the Introspector's internal caches. - * - * @since 1.2 - */ - public static void flushCaches() - { - beanInfoCache.clear(); - - // Clears all the intermediate ExplicitInfo instances which - // have been created. - // This makes sure we have to retrieve stuff like BeanDescriptors - // again. (Remember that FeatureDescriptor can be modified by the user.) - ExplicitInfo.flushCaches(); - } - - /** - * Flush the Introspector's internal cached information for a given - * class. - * - * @param clz the class to be flushed. - * @throws NullPointerException if clz is null. - * @since 1.2 - */ - public static void flushFromCaches(Class clz) - { - synchronized (clz) - { - beanInfoCache.remove(clz); - } - } - - /** - * Get the BeanInfo for class <CODE>beanClass</CODE>, - * first by looking for explicit information, next by - * using standard design patterns to determine - * information about the class. It crawls up the - * inheritance tree until it hits <CODE>topClass</CODE>. - * - * @param beanClass the Bean class. - * @param stopClass the class to stop at. - * @return the BeanInfo object representing the class. - */ - public static BeanInfo getBeanInfo(Class beanClass, Class stopClass) - throws IntrospectionException - { - ExplicitInfo explicit = new ExplicitInfo(beanClass, stopClass); - - IntrospectionIncubator ii = new IntrospectionIncubator(); - ii.setPropertyStopClass(explicit.propertyStopClass); - ii.setEventStopClass(explicit.eventStopClass); - ii.setMethodStopClass(explicit.methodStopClass); - ii.addMethods(beanClass.getMethods()); - - BeanInfoEmbryo currentInfo = ii.getBeanInfoEmbryo(); - PropertyDescriptor[] p = explicit.explicitPropertyDescriptors; - if(p!=null) - { - for(int i=0;i<p.length;i++) - { - if(!currentInfo.hasProperty(p[i])) - { - currentInfo.addProperty(p[i]); - } - } - if(explicit.defaultProperty != -1) - { - currentInfo.setDefaultPropertyName(p[explicit.defaultProperty].getName()); - } - } - EventSetDescriptor[] e = explicit.explicitEventSetDescriptors; - if(e!=null) - { - for(int i=0;i<e.length;i++) - { - if(!currentInfo.hasEvent(e[i])) - { - currentInfo.addEvent(e[i]); - } - } - if(explicit.defaultEvent != -1) - { - currentInfo.setDefaultEventName(e[explicit.defaultEvent].getName()); - } - } - MethodDescriptor[] m = explicit.explicitMethodDescriptors; - if(m!=null) - { - for(int i=0;i<m.length;i++) - { - if(!currentInfo.hasMethod(m[i])) - { - currentInfo.addMethod(m[i]); - } - } - } - - // Sets the info's BeanDescriptor to the one we extracted from the - // explicit BeanInfo instance(s) if they contained one. Otherwise we - // create the BeanDescriptor from scratch. - // Note: We do not create a copy the retrieved BeanDescriptor which will allow - // the user to modify the instance while it is cached. However this is how - // the RI does it. - currentInfo.setBeanDescriptor( - (explicit.explicitBeanDescriptor == null ? - new BeanDescriptor(beanClass, null) : - explicit.explicitBeanDescriptor)); - - currentInfo.setAdditionalBeanInfo(explicit.explicitBeanInfo); - currentInfo.setIcons(explicit.im); - - return currentInfo.getBeanInfo(); - } - - /** - * Get the search path for BeanInfo classes. - * - * @return the BeanInfo search path. - */ - public static String[] getBeanInfoSearchPath() - { - return beanInfoSearchPath; - } - - /** - * Set the search path for BeanInfo classes. - * @param beanInfoSearchPath the new BeanInfo search - * path. - */ - public static void setBeanInfoSearchPath(String[] beanInfoSearchPath) - { - Introspector.beanInfoSearchPath = beanInfoSearchPath; - } - - /** - * A helper method to convert a name to standard Java - * naming conventions: anything with two capitals as the - * first two letters remains the same, otherwise the - * first letter is decapitalized. URL = URL, I = i, - * MyMethod = myMethod. - * - * @param name the name to decapitalize. - * @return the decapitalized name. - */ - public static String decapitalize(String name) - { - try - { - if(!Character.isUpperCase(name.charAt(0))) - { - return name; - } - else - { - try - { - if(Character.isUpperCase(name.charAt(1))) - { - return name; - } - else - { - char[] c = name.toCharArray(); - c[0] = Character.toLowerCase(c[0]); - return new String(c); - } - } - catch(StringIndexOutOfBoundsException E) - { - char[] c = new char[1]; - c[0] = Character.toLowerCase(name.charAt(0)); - return new String(c); - } - } - } - catch(StringIndexOutOfBoundsException E) - { - return name; - } - catch(NullPointerException E) - { - return null; - } - } - - static BeanInfo copyBeanInfo(BeanInfo b) - { - java.awt.Image[] icons = new java.awt.Image[4]; - for(int i=1;i<=4;i++) - { - icons[i-1] = b.getIcon(i); - } - - return new ExplicitBeanInfo(b.getBeanDescriptor(), - b.getAdditionalBeanInfo(), - b.getPropertyDescriptors(), - b.getDefaultPropertyIndex(), - b.getEventSetDescriptors(), - b.getDefaultEventIndex(), - b.getMethodDescriptors(), - icons); - } -} - -class ExplicitInfo -{ - BeanDescriptor explicitBeanDescriptor; - BeanInfo[] explicitBeanInfo; - - PropertyDescriptor[] explicitPropertyDescriptors; - EventSetDescriptor[] explicitEventSetDescriptors; - MethodDescriptor[] explicitMethodDescriptors; - - int defaultProperty; - int defaultEvent; - - java.awt.Image[] im = new java.awt.Image[4]; - - Class propertyStopClass; - Class eventStopClass; - Class methodStopClass; - - static Hashtable explicitBeanInfos = new Hashtable(); - static Vector emptyBeanInfos = new Vector(); - - ExplicitInfo(Class beanClass, Class stopClass) - { - while(beanClass != null && !beanClass.equals(stopClass)) - { - - BeanInfo explicit = findExplicitBeanInfo(beanClass); - - - if(explicit != null) - { - - if(explicitBeanDescriptor == null) - { - explicitBeanDescriptor = explicit.getBeanDescriptor(); - } - - if(explicitBeanInfo == null) - { - explicitBeanInfo = explicit.getAdditionalBeanInfo(); - } - - if(explicitPropertyDescriptors == null) - { - if(explicit.getPropertyDescriptors() != null) - { - explicitPropertyDescriptors = explicit.getPropertyDescriptors(); - defaultProperty = explicit.getDefaultPropertyIndex(); - propertyStopClass = beanClass; - } - } - - if(explicitEventSetDescriptors == null) - { - if(explicit.getEventSetDescriptors() != null) - { - explicitEventSetDescriptors = explicit.getEventSetDescriptors(); - defaultEvent = explicit.getDefaultEventIndex(); - eventStopClass = beanClass; - } - } - - if(explicitMethodDescriptors == null) - { - if(explicit.getMethodDescriptors() != null) - { - explicitMethodDescriptors = explicit.getMethodDescriptors(); - methodStopClass = beanClass; - } - } - - if(im[0] == null && im[1] == null - && im[2] == null && im[3] == null) - { - im[0] = explicit.getIcon(0); - im[1] = explicit.getIcon(1); - im[2] = explicit.getIcon(2); - im[3] = explicit.getIcon(3); - } - } - beanClass = beanClass.getSuperclass(); - } - - if(propertyStopClass == null) - { - propertyStopClass = stopClass; - } - - if(eventStopClass == null) - { - eventStopClass = stopClass; - } - - if(methodStopClass == null) - { - methodStopClass = stopClass; - } - } - - /** Throws away all cached data and makes sure we re-instantiate things - * like BeanDescriptors again. - */ - static void flushCaches() { - explicitBeanInfos.clear(); - emptyBeanInfos.clear(); - } - - static BeanInfo findExplicitBeanInfo(Class beanClass) - { - BeanInfo retval = (BeanInfo)explicitBeanInfos.get(beanClass); - if(retval != null) - { - return retval; - } - else if(emptyBeanInfos.indexOf(beanClass) != -1) - { - return null; - } - else - { - retval = reallyFindExplicitBeanInfo(beanClass); - if(retval != null) - { - explicitBeanInfos.put(beanClass,retval); - } - else - { - emptyBeanInfos.addElement(beanClass); - } - return retval; - } - } - - static BeanInfo reallyFindExplicitBeanInfo(Class beanClass) - { - ClassLoader beanClassLoader = beanClass.getClassLoader(); - BeanInfo beanInfo; - - beanInfo = getBeanInfo(beanClassLoader, beanClass.getName() + "BeanInfo"); - if (beanInfo == null) - { - String newName; - newName = ClassHelper.getTruncatedClassName(beanClass) + "BeanInfo"; - - for(int i = 0; i < Introspector.beanInfoSearchPath.length; i++) - { - if (Introspector.beanInfoSearchPath[i].equals("")) - beanInfo = getBeanInfo(beanClassLoader, newName); - else - beanInfo = getBeanInfo(beanClassLoader, - Introspector.beanInfoSearchPath[i] + "." - + newName); - - // Returns the beanInfo if it exists and the described class matches - // the one we searched. - if (beanInfo != null && beanInfo.getBeanDescriptor() != null && - beanInfo.getBeanDescriptor().getBeanClass() == beanClass) - - return beanInfo; - } - } - - return beanInfo; - } - - /** - * Returns an instance of the given class name when it can be loaded - * through the given class loader, or null otherwise. - */ - private static BeanInfo getBeanInfo(ClassLoader cl, String infoName) - { - try - { - return (BeanInfo) Class.forName(infoName, true, cl).newInstance(); - } - catch (ClassNotFoundException cnfe) - { - return null; - } - catch (IllegalAccessException iae) - { - return null; - } - catch (InstantiationException ie) - { - return null; - } - } - -} diff --git a/libjava/java/beans/MethodDescriptor.java b/libjava/java/beans/MethodDescriptor.java deleted file mode 100644 index 123dba60cc9..00000000000 --- a/libjava/java/beans/MethodDescriptor.java +++ /dev/null @@ -1,88 +0,0 @@ -/* java.beans.MethodDescriptor - Copyright (C) 1998 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.beans; - -import java.lang.reflect.Method; - -/** MethodDescriptor describes information about a JavaBeans method. - ** It's a fairly straightforward class (at least something in this - ** package is straightforward!). - ** - ** @author John Keiser - ** @since JDK1.1 - ** @version 1.1.0, 26 Jul 1998 - **/ -public class MethodDescriptor extends FeatureDescriptor { - private Method m; - private ParameterDescriptor[] parameterDescriptors; - - /** Create a new MethodDescriptor. - ** This method sets the name to the name of the method (Method.getName()). - ** @param m the method it will represent. - **/ - public MethodDescriptor(Method m) { - setName(m.getName()); - this.m = m; - } - - /** Create a new MethodDescriptor. - ** This method sets the name to the name of the method (Method.getName()). - ** @param m the method it will represent. - ** @param parameterDescriptors descriptions of the parameters (especially names). - **/ - public MethodDescriptor(Method m, ParameterDescriptor[] parameterDescriptors) { - setName(m.getName()); - this.m = m; - this.parameterDescriptors = parameterDescriptors; - } - - /** Get the parameter descriptors from this method. - ** Since MethodDescriptor has no way of determining what - ** the parameter names were, this defaults to null. - **/ - public ParameterDescriptor[] getParameterDescriptors() { - return parameterDescriptors; - } - - /** Get the method this MethodDescriptor represents. **/ - public Method getMethod() { - return m; - } -} - diff --git a/libjava/java/beans/ParameterDescriptor.java b/libjava/java/beans/ParameterDescriptor.java deleted file mode 100644 index 8ea93a9bd8d..00000000000 --- a/libjava/java/beans/ParameterDescriptor.java +++ /dev/null @@ -1,52 +0,0 @@ -/* java.beans.MethodDescriptor - Copyright (C) 1998 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.beans; - -/** ParameterDescriptor represents a single parameter to a method. - ** As it turns out, FeatureDescriptor is sufficient to hold all - ** the information. Use its constructor and methods to set - ** the appropriate values. - ** - ** @author John Keiser - ** @since JDK1.1 - ** @version 1.1.0, 26 Jul 1998 - **/ -public class ParameterDescriptor extends FeatureDescriptor { - -} diff --git a/libjava/java/beans/PropertyChangeEvent.java b/libjava/java/beans/PropertyChangeEvent.java deleted file mode 100644 index 3e3f948e32a..00000000000 --- a/libjava/java/beans/PropertyChangeEvent.java +++ /dev/null @@ -1,189 +0,0 @@ -/* PropertyChangeEvent.java -- describes a change in a property - Copyright (C) 1998, 2000, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.beans; - -import java.util.EventObject; - -/** - * PropertyChangeEvents are fired in the PropertyChange and VetoableChange - * event classes. They represent the old and new values as well as the - * source Bean. If the old or new value is a primitive type, it must be - * wrapped in the appropriate wrapper type (java.lang.Integer for int, etc., - * etc.). - * - * <p>If the old or new values are unknown (although why that would be I do - * not know), they may be null. Also, if the set of properties itself has - * changed, the name should be null, and the old and new values may also be - * null. Right now Sun put in a propagationId, reserved for future use. Read - * the comments on the constructor and on setPropagationId for more - * information. - * - * @author John Keiser - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.1 - * @status udpated to 1.4 - */ -public class PropertyChangeEvent extends EventObject -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = 7042693688939648123L; - - /** - * The name of the property that changed, may be null. Package visible for - * use by PropertyChangeSupport. - * - * @serial the changed property name - */ - final String propertyName; - - /** - * The new value of the property, may be null. Package visible for use by - * PropertyChangeSupport. - * - * @serial the new property value - */ - final Object newValue; - - /** - * The old value of the property, may be null. Package visible for use by - * PropertyChangeSupport. - * - * @serial the old property value - */ - final Object oldValue; - - /** - * The propagation ID, reserved for future use. May be null. - * - * @see #getPropagationId() - * @serial the Propagation ID - */ - private Object propagationId; - - /** - * Create a new PropertyChangeEvent. Remember that if you received a - * PropertyChangeEvent and are sending a new one, you should also set the - * propagation ID from the old PropertyChangeEvent. - * - * @param source the Bean containing the property - * @param propertyName the property's name - * @param oldVal the old value of the property - * @param newVal the new value of the property - * @throws IllegalArgumentException if source is null - */ - public PropertyChangeEvent(Object source, String propertyName, - Object oldVal, Object newVal) - { - super(source); - this.propertyName = propertyName; - oldValue = oldVal; - newValue = newVal; - } - - /** - * Get the property name. May be null if multiple properties changed. - * - * @return the property name - */ - public String getPropertyName() - { - return propertyName; - } - - /** - * Get the property's new value. May be null if multiple properties changed. - * - * @return the property's new value - */ - public Object getNewValue() - { - return newValue; - } - - /** - * Get the property's old value. May be null if multiple properties changed. - * - * @return the property's old value - */ - public Object getOldValue() - { - return oldValue; - } - - /** - * Set the propagation ID. This is a way for the event to be passed from - * hand to hand and retain a little extra state. Right now it is unused, - * but it should be propagated anyway so that future versions of JavaBeans - * can use it, for God knows what. - * - * @param propagationId the propagation ID - * @see #getPropagationId() - */ - public void setPropagationId(Object propagationId) - { - this.propagationId = propagationId; - } - - /** - * Get the propagation ID. Right now, it is not used for anything. - * - * @return the propagation ID - * @see #setPropagationId(Object) - */ - public Object getPropagationId() - { - return propagationId; - } - - /** - * Utility method to rollback a change. - * - * @param event the event to rollback - * @return a new event with old and new swapped - */ - PropertyChangeEvent rollback() - { - PropertyChangeEvent result - = new PropertyChangeEvent(source, propertyName, newValue, oldValue); - result.propagationId = propagationId; - return result; - } -} // class PropertyChangeEvent diff --git a/libjava/java/beans/PropertyChangeListener.java b/libjava/java/beans/PropertyChangeListener.java deleted file mode 100644 index a97e6e1c2e9..00000000000 --- a/libjava/java/beans/PropertyChangeListener.java +++ /dev/null @@ -1,61 +0,0 @@ -/* PropertyChangeListener.java -- listen for changes in a bound property - Copyright (C) 1998, 2000, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.beans; - -import java.util.EventListener; - -/** - * PropertyChangeListener allows a class to monitor properties of a Bean for - * changes. A propertyChange() event will only be fired <em>after</em> the - * property has changed. - * - * @author John Keiser - * @see PropertyChangeSupport - * @since 1.1 - * @status updated to 1.4 - */ -public interface PropertyChangeListener extends EventListener -{ - /** - * Fired after a Bean's property has changed. - * - * @param e the change (containing the old and new values) - */ - void propertyChange(PropertyChangeEvent e); -} // interface PropertyChangeListener diff --git a/libjava/java/beans/PropertyChangeListenerProxy.java b/libjava/java/beans/PropertyChangeListenerProxy.java deleted file mode 100644 index 68a8153032b..00000000000 --- a/libjava/java/beans/PropertyChangeListenerProxy.java +++ /dev/null @@ -1,102 +0,0 @@ -/* PropertyChangeListenerProxy.java -- adds a name to a property listener - Copyright (C) 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.beans; - -import java.util.EventListenerProxy; - -/** - * This class provides an extension to <code>PropertyChangeListener</code> - - * associating a name with the listener. This can be used to filter the - * changes that one is interested in. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.4 - * @status udpated to 1.4 - */ -public class PropertyChangeListenerProxy extends EventListenerProxy - implements PropertyChangeListener -{ - /** - * The name of the property to listen for. Package visible for use by - * PropertyChangeSupport. - */ - final String propertyName; - - /** - * Create a new proxy which filters property change events and only passes - * changes to the named property on to the delegate. A null propertyName - * or listener does not fail now, but may cause a NullPointerException down - * the road. - * - * @param propertyName the property's name to filter on - * @param listener the delegate listener - */ - public PropertyChangeListenerProxy(String propertyName, - PropertyChangeListener listener) - { - super(listener); - this.propertyName = propertyName; - } - - /** - * Forwards the event on to the delegate if the property name matches. - * - * @param event the event to pass on, if it meets the filter - * @throws NullPointerException if the delegate this was created with is null - */ - public void propertyChange(PropertyChangeEvent event) - { - // Note: Sun does not filter, under the assumption that since - // PropertyChangeSupport unwraps proxys, this method should never be - // called by normal use of listeners. - String name = event == null ? null : event.getPropertyName(); - if (name == null ? propertyName == null : name.equals(propertyName)) - ((PropertyChangeListener) getListener()).propertyChange(event); - } - - /** - * Gets the name of the property this proxy is filtering on. - * - * @return the property name - */ - public String getPropertyName() - { - return propertyName; - } -} // class PropertyChangeListenerProxy diff --git a/libjava/java/beans/PropertyChangeSupport.java b/libjava/java/beans/PropertyChangeSupport.java deleted file mode 100644 index a0e64af4d29..00000000000 --- a/libjava/java/beans/PropertyChangeSupport.java +++ /dev/null @@ -1,488 +0,0 @@ -/* PropertyChangeSupport.java -- support to manage property change listeners - Copyright (C) 1998, 1999, 2000, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.beans; - -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Hashtable; -import java.util.Iterator; -import java.util.Map.Entry; -import java.util.Vector; - -/** - * PropertyChangeSupport makes it easy to fire property change events and - * handle listeners. It allows chaining of listeners, as well as filtering - * by property name. In addition, it will serialize only those listeners - * which are serializable, ignoring the others without problem. This class - * is thread-safe. - * - * @author John Keiser - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.1 - * @status updated to 1.4 - */ -public class PropertyChangeSupport implements Serializable -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = 6401253773779951803L; - - /** - * Maps property names (String) to named listeners (PropertyChangeSupport). - * If this is a child instance, this field will be null. - * - * @serial the map of property names to named listener managers - * @since 1.2 - */ - private Hashtable children; - - /** - * The non-null source object for any generated events. - * - * @serial the event source - */ - private final Object source; - - /** - * A field to compare serialization versions - this class uses version 2. - * - * @serial the serialization format - */ - private static final int propertyChangeSupportSerializedDataVersion = 2; - - /** - * The list of all registered property listeners. If this instance was - * created by user code, this only holds the global listeners (ie. not tied - * to a name), and may be null. If it was created by this class, as a - * helper for named properties, then this vector will be non-null, and this - * instance appears as a value in the <code>children</code> hashtable of - * another instance, so that the listeners are tied to the key of that - * hashtable entry. - */ - private transient Vector listeners; - - /** - * Create a PropertyChangeSupport to work with a specific source bean. - * - * @param source the source bean to use - * @throws NullPointerException if source is null - */ - public PropertyChangeSupport(Object source) - { - this.source = source; - if (source == null) - throw new NullPointerException(); - } - - /** - * Adds a PropertyChangeListener to the list of global listeners. All - * property change events will be sent to this listener. The listener add - * is not unique: that is, <em>n</em> adds with the same listener will - * result in <em>n</em> events being sent to that listener for every - * property change. Adding a null listener may cause a NullPointerException - * down the road. This method will unwrap a PropertyChangeListenerProxy, - * registering the underlying delegate to the named property list. - * - * @param l the listener to add - */ - public synchronized void addPropertyChangeListener(PropertyChangeListener l) - { - if (l instanceof PropertyChangeListenerProxy) - { - PropertyChangeListenerProxy p = (PropertyChangeListenerProxy) l; - addPropertyChangeListener(p.propertyName, - (PropertyChangeListener) p.getListener()); - } - else - { - if (listeners == null) - listeners = new Vector(); - listeners.add(l); - } - } - - /** - * Removes a PropertyChangeListener from the list of global listeners. If - * any specific properties are being listened on, they must be deregistered - * by themselves; this will only remove the general listener to all - * properties. If <code>add()</code> has been called multiple times for a - * particular listener, <code>remove()</code> will have to be called the - * same number of times to deregister it. This method will unwrap a - * PropertyChangeListenerProxy, removing the underlying delegate from the - * named property list. - * - * @param l the listener to remove - */ - public synchronized void - removePropertyChangeListener(PropertyChangeListener l) - { - if (l instanceof PropertyChangeListenerProxy) - { - PropertyChangeListenerProxy p = (PropertyChangeListenerProxy) l; - removePropertyChangeListener(p.propertyName, - (PropertyChangeListener) p.getListener()); - } - else if (listeners != null) - { - listeners.remove(l); - if (listeners.isEmpty()) - listeners = null; - } - } - - /** - * Returns an array of all registered property change listeners. Those that - * were registered under a name will be wrapped in a - * <code>PropertyChangeListenerProxy</code>, so you must check whether the - * listener is an instance of the proxy class in order to see what name the - * real listener is registered under. If there are no registered listeners, - * this returns an empty array. - * - * @return the array of registered listeners - * @see PropertyChangeListenerProxy - * @since 1.4 - */ - public synchronized PropertyChangeListener[] getPropertyChangeListeners() - { - ArrayList list = new ArrayList(); - if (listeners != null) - list.addAll(listeners); - if (children != null) - { - int i = children.size(); - Iterator iter = children.entrySet().iterator(); - while (--i >= 0) - { - Entry e = (Entry) iter.next(); - String name = (String) e.getKey(); - Vector v = ((PropertyChangeSupport) e.getValue()).listeners; - int j = v.size(); - while (--j >= 0) - list.add(new PropertyChangeListenerProxy - (name, (PropertyChangeListener) v.get(j))); - } - } - return (PropertyChangeListener[]) - list.toArray(new PropertyChangeListener[list.size()]); - } - - /** - * Adds a PropertyChangeListener listening on the specified property. Events - * will be sent to the listener only if the property name matches. The - * listener add is not unique; that is, <em>n</em> adds on a particular - * property for a particular listener will result in <em>n</em> events - * being sent to that listener when that property is changed. The effect is - * cumulative, too; if you are registered to listen to receive events on - * all property changes, and then you register on a particular property, - * you will receive change events for that property twice. Adding a null - * listener may cause a NullPointerException down the road. This method - * will unwrap a PropertyChangeListenerProxy, registering the underlying - * delegate to the named property list if the names match, and discarding - * it otherwise. - * - * @param propertyName the name of the property to listen on - * @param l the listener to add - * @throws NullPointerException if propertyName is null - */ - public synchronized void addPropertyChangeListener(String propertyName, - PropertyChangeListener l) - { - while (l instanceof PropertyChangeListenerProxy) - { - PropertyChangeListenerProxy p = (PropertyChangeListenerProxy) l; - if (propertyName == null ? p.propertyName != null - : ! propertyName.equals(p.propertyName)) - return; - l = (PropertyChangeListener) p.getListener(); - } - PropertyChangeSupport s = null; - if (children == null) - children = new Hashtable(); - else - s = (PropertyChangeSupport) children.get(propertyName); - if (s == null) - { - s = new PropertyChangeSupport(source); - s.listeners = new Vector(); - children.put(propertyName, s); - } - s.listeners.add(l); - } - - /** - * Removes a PropertyChangeListener from listening to a specific property. - * If <code>add()</code> has been called multiple times for a particular - * listener on a property, <code>remove()</code> will have to be called the - * same number of times to deregister it. This method will unwrap a - * PropertyChangeListenerProxy, removing the underlying delegate from the - * named property list if the names match. - * - * @param propertyName the property to stop listening on - * @param l the listener to remove - * @throws NullPointerException if propertyName is null - */ - public synchronized void - removePropertyChangeListener(String propertyName, PropertyChangeListener l) - { - if (children == null) - return; - PropertyChangeSupport s - = (PropertyChangeSupport) children.get(propertyName); - if (s == null) - return; - while (l instanceof PropertyChangeListenerProxy) - { - PropertyChangeListenerProxy p = (PropertyChangeListenerProxy) l; - if (propertyName == null ? p.propertyName != null - : ! propertyName.equals(p.propertyName)) - return; - l = (PropertyChangeListener) p.getListener(); - } - s.listeners.remove(l); - if (s.listeners.isEmpty()) - { - children.remove(propertyName); - if (children.isEmpty()) - children = null; - } - } - - /** - * Returns an array of all property change listeners registered under the - * given property name. If there are no registered listeners, this returns - * an empty array. - * - * @return the array of registered listeners - * @throws NullPointerException if propertyName is null - * @since 1.4 - */ - public synchronized PropertyChangeListener[] - getPropertyChangeListeners(String propertyName) - { - if (children == null) - return new PropertyChangeListener[0]; - PropertyChangeSupport s - = (PropertyChangeSupport) children.get(propertyName); - if (s == null) - return new PropertyChangeListener[0]; - return (PropertyChangeListener[]) - s.listeners.toArray(new PropertyChangeListener[s.listeners.size()]); - } - - /** - * Fire a PropertyChangeEvent containing the old and new values of the - * property to all the global listeners, and to all the listeners for the - * specified property name. This does nothing if old and new are non-null - * and equal. - * - * @param propertyName the name of the property that changed - * @param oldVal the old value - * @param newVal the new value - */ - public void firePropertyChange(String propertyName, - Object oldVal, Object newVal) - { - firePropertyChange(new PropertyChangeEvent(source, propertyName, - oldVal, newVal)); - } - - /** - * Fire a PropertyChangeEvent containing the old and new values of the - * property to all the global listeners, and to all the listeners for the - * specified property name. This does nothing if old and new are equal. - * - * @param propertyName the name of the property that changed - * @param oldVal the old value - * @param newVal the new value - */ - public void firePropertyChange(String propertyName, int oldVal, int newVal) - { - if (oldVal != newVal) - firePropertyChange(new PropertyChangeEvent(source, propertyName, - new Integer(oldVal), - new Integer(newVal))); - } - - /** - * Fire a PropertyChangeEvent containing the old and new values of the - * property to all the global listeners, and to all the listeners for the - * specified property name. This does nothing if old and new are equal. - * - * @param propertyName the name of the property that changed - * @param oldVal the old value - * @param newVal the new value - */ - public void firePropertyChange(String propertyName, - boolean oldVal, boolean newVal) - { - if (oldVal != newVal) - firePropertyChange(new PropertyChangeEvent(source, propertyName, - Boolean.valueOf(oldVal), - Boolean.valueOf(newVal))); - } - - /** - * Fire a PropertyChangeEvent to all the global listeners, and to all the - * listeners for the specified property name. This does nothing if old and - * new values of the event are equal. - * - * @param event the event to fire - * @throws NullPointerException if event is null - */ - public void firePropertyChange(PropertyChangeEvent event) - { - if (event.oldValue != null && event.oldValue.equals(event.newValue)) - return; - Vector v = listeners; // Be thread-safe. - if (v != null) - { - int i = v.size(); - while (--i >= 0) - ((PropertyChangeListener) v.get(i)).propertyChange(event); - } - Hashtable h = children; // Be thread-safe. - if (h != null && event.propertyName != null) - { - PropertyChangeSupport s - = (PropertyChangeSupport) h.get(event.propertyName); - if (s != null) - { - v = s.listeners; // Be thread-safe. - int i = v == null ? 0 : v.size(); - while (--i >= 0) - ((PropertyChangeListener) v.get(i)).propertyChange(event); - } - } - } - - /** - * Tell whether the specified property is being listened on or not. This - * will only return <code>true</code> if there are listeners on all - * properties or if there is a listener specifically on this property. - * - * @param propertyName the property that may be listened on - * @return whether the property is being listened on - * @throws NullPointerException if propertyName is null - */ - public synchronized boolean hasListeners(String propertyName) - { - return listeners != null || (children != null - && children.get(propertyName) != null); - } - - /** - * Saves the state of the object to the stream. - * - * @param s the stream to write to - * @throws IOException if anything goes wrong - * @serialData this writes out a null-terminated list of serializable - * global property change listeners (the listeners for a named - * property are written out as the global listeners of the - * children, when the children hashtable is saved) - */ - private synchronized void writeObject(ObjectOutputStream s) - throws IOException - { - s.defaultWriteObject(); - if (listeners != null) - { - int i = listeners.size(); - while (--i >= 0) - if (listeners.get(i) instanceof Serializable) - s.writeObject(listeners.get(i)); - } - s.writeObject(null); - } - - /** - * Reads the object back from stream (deserialization). - * - * XXX Since serialization for 1.1 streams was not documented, this may - * not work if propertyChangeSupportSerializedDataVersion is 1. - * - * @param s the stream to read from - * @throws IOException if reading the stream fails - * @throws ClassNotFoundException if deserialization fails - * @serialData this reads in a null-terminated list of serializable - * global property change listeners (the listeners for a named - * property are written out as the global listeners of the - * children, when the children hashtable is saved) - */ - private void readObject(ObjectInputStream s) - throws IOException, ClassNotFoundException - { - s.defaultReadObject(); - PropertyChangeListener l = (PropertyChangeListener) s.readObject(); - while (l != null) - { - addPropertyChangeListener(l); - l = (PropertyChangeListener) s.readObject(); - } - // Sun is not as careful with children as we are, and lets some proxys - // in that can never receive events. So, we clean up anything that got - // serialized, to make sure our invariants hold. - if (children != null) - { - int i = children.size(); - Iterator iter = children.entrySet().iterator(); - while (--i >= 0) - { - Entry e = (Entry) iter.next(); - String name = (String) e.getKey(); - PropertyChangeSupport pcs = (PropertyChangeSupport) e.getValue(); - if (pcs.listeners == null) - pcs.listeners = new Vector(); - if (pcs.children != null) - pcs.listeners.addAll - (Arrays.asList(pcs.getPropertyChangeListeners(name))); - if (pcs.listeners.size() == 0) - iter.remove(); - else - pcs.children = null; - } - if (children.size() == 0) - children = null; - } - } -} // class PropertyChangeSupport diff --git a/libjava/java/beans/PropertyDescriptor.java b/libjava/java/beans/PropertyDescriptor.java deleted file mode 100644 index 416d468576f..00000000000 --- a/libjava/java/beans/PropertyDescriptor.java +++ /dev/null @@ -1,583 +0,0 @@ -/* java.beans.PropertyDescriptor - Copyright (C) 1998, 2001, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.beans; - -import java.lang.reflect.Method; - -/** - ** PropertyDescriptor describes information about a JavaBean property, - ** by which we mean a property that has been exposed via a pair of - ** get and set methods. (There may be no get method, which means - ** the property is write-only, or no set method, which means the - ** the property is read-only.)<P> - ** - ** The constraints put on get and set methods are:<P> - ** <OL> - ** <LI>A get method must have signature - ** <CODE><propertyType> <getMethodName>()</CODE></LI> - ** <LI>A set method must have signature - ** <CODE>void <setMethodName>(<propertyType>)</CODE></LI> - ** <LI>Either method type may throw any exception.</LI> - ** <LI>Both methods must be public.</LI> - ** </OL> - ** - ** @author John Keiser - ** @author Robert Schuster (thebohemian@gmx.net) - ** @since 1.1 - ** @status updated to 1.4 - **/ - -public class PropertyDescriptor extends FeatureDescriptor -{ - Class propertyType; - Method getMethod; - Method setMethod; - - Class propertyEditorClass; - boolean bound; - boolean constrained; - - PropertyDescriptor(String name) - { - setName(name); - } - - /** Create a new PropertyDescriptor by introspection. - ** This form of constructor creates the PropertyDescriptor by - ** looking for a getter method named <CODE>get<name>()</CODE> - ** (or, optionally, if the property is boolean, - ** <CODE>is<name>()</CODE>) and - ** <CODE>set<name>()</CODE> in class - ** <CODE><beanClass></CODE>, where <name> has its - ** first letter capitalized by the constructor.<P> - ** - ** Note that using this constructor the given property must be read- <strong>and</strong> - ** writeable. If the implementation does not both, a read and a write method, an - ** <code>IntrospectionException</code> is thrown. - ** - ** <B>Implementation note:</B> If there is both are both isXXX and - ** getXXX methods, the former is used in preference to the latter. - ** We do not check that an isXXX method returns a boolean. In both - ** cases, this matches the behaviour of JDK 1.4<P> - ** - ** @param name the programmatic name of the property, usually - ** starting with a lowercase letter (e.g. fooManChu - ** instead of FooManChu). - ** @param beanClass the class the get and set methods live in. - ** @exception IntrospectionException if the methods are not found - ** or invalid. - **/ - public PropertyDescriptor(String name, Class beanClass) - throws IntrospectionException - { - setName(name); - if (name.length() == 0) - { - throw new IntrospectionException("empty property name"); - } - String caps = Character.toUpperCase(name.charAt(0)) + name.substring(1); - findMethods(beanClass, "is" + caps, "get" + caps, "set" + caps); - - if (getMethod == null) - { - throw new IntrospectionException( - "Cannot find a is" + caps + " or get" + caps + " method"); - } - - if (setMethod == null) - { - throw new IntrospectionException( - "Cannot find a " + caps + " method"); - } - - // finally check the methods compatibility - propertyType = checkMethods(getMethod, setMethod); - } - - /** Create a new PropertyDescriptor by introspection. - ** This form of constructor allows you to specify the - ** names of the get and set methods to search for.<P> - ** - ** <B>Implementation note:</B> If there is a get method (or - ** boolean isXXX() method), then the return type of that method - ** is used to find the set method. If there is no get method, - ** then the set method is searched for exhaustively.<P> - ** - ** <B>Spec note:</B> - ** If there is no get method and multiple set methods with - ** the same name and a single parameter (different type of course), - ** then an IntrospectionException is thrown. While Sun's spec - ** does not state this, it can make Bean behavior different on - ** different systems (since method order is not guaranteed) and as - ** such, can be treated as a bug in the spec. I am not aware of - ** whether Sun's implementation catches this. - ** - ** @param name the programmatic name of the property, usually - ** starting with a lowercase letter (e.g. fooManChu - ** instead of FooManChu). - ** @param beanClass the class the get and set methods live in. - ** @param getMethodName the name of the get method or <code>null</code> if the property is write-only. - ** @param setMethodName the name of the set method or <code>null</code> if the property is read-only. - ** @exception IntrospectionException if the methods are not found - ** or invalid. - **/ - public PropertyDescriptor( - String name, - Class beanClass, - String getMethodName, - String setMethodName) - throws IntrospectionException - { - setName(name); - findMethods(beanClass, getMethodName, null, setMethodName); - - if (getMethod == null && getMethodName != null) - { - throw new IntrospectionException( - "Cannot find a getter method called " + getMethodName); - } - - if (setMethod == null && setMethodName != null) - { - throw new IntrospectionException( - "Cannot find a setter method called " + setMethodName); - } - - propertyType = checkMethods(getMethod, setMethod); - } - - /** Create a new PropertyDescriptor using explicit Methods. - ** Note that the methods will be checked for conformance to standard - ** Property method rules, as described above at the top of this class. - **<br> - ** It is possible to call this method with both <code>Method</code> arguments - ** being <code>null</code>. In such a case the property type is <code>null</code>. - ** - ** @param name the programmatic name of the property, usually - ** starting with a lowercase letter (e.g. fooManChu - ** instead of FooManChu). - ** @param readMethod the read method or <code>null</code> if the property is write-only. - ** @param writeMethod the write method or <code>null</code> if the property is read-only. - ** @exception IntrospectionException if the methods are not found - ** or invalid. - **/ - public PropertyDescriptor( - String name, - Method readMethod, - Method writeMethod) - throws IntrospectionException - { - setName(name); - getMethod = readMethod; - setMethod = writeMethod; - propertyType = checkMethods(getMethod, setMethod); - } - - /** Get the property type. - ** This is the type the get method returns and the set method - ** takes in. - **/ - public Class getPropertyType() - { - return propertyType; - } - - /** Get the get method. Why they call it readMethod here and - ** get everywhere else is beyond me. - **/ - public Method getReadMethod() - { - return getMethod; - } - - /** Sets the read method.<br/> - * The read method is used to retrieve the value of a property. A legal - * read method must have no arguments. Its return type must not be - * <code>void</code>. If this methods succeeds the property type - * is adjusted to the return type of the read method.<br/> - * <br/> - * It is legal to set the read and the write method to <code>null</code> - * or provide method which have been declared in distinct classes. - * - * @param readMethod The new method to be used or <code>null</code>. - * @throws IntrospectionException If the given method is invalid. - * @since 1.2 - */ - public void setReadMethod(Method readMethod) throws IntrospectionException - { - propertyType = checkMethods(readMethod, setMethod); - - getMethod = readMethod; - } - - /** Get the set method. Why they call it writeMethod here and - ** set everywhere else is beyond me. - **/ - public Method getWriteMethod() - { - return setMethod; - } - - /** Sets the write method.<br/> - * The write method is used to set the value of a property. A legal write method - * must have a single argument which can be assigned to the property. If no - * read method exists the property type changes to the argument type of the - * write method.<br/> - * <br/> - * It is legal to set the read and the write method to <code>null</code> - * or provide method which have been declared in distinct classes. - * - * @param writeMethod The new method to be used or <code>null</code>. - * @throws IntrospectionException If the given method is invalid. - * @since 1.2 - */ - public void setWriteMethod(Method writeMethod) - throws IntrospectionException - { - propertyType = checkMethods(getMethod, writeMethod); - - setMethod = writeMethod; - } - - /** Get whether the property is bound. Defaults to false. **/ - public boolean isBound() - { - return bound; - } - - /** Set whether the property is bound. - ** As long as the the bean implements addPropertyChangeListener() and - ** removePropertyChangeListener(), setBound(true) may safely be called.<P> - ** If these things are not true, then the behavior of the system - ** will be undefined.<P> - ** - ** When a property is bound, its set method is required to fire the - ** <CODE>PropertyChangeListener.propertyChange())</CODE> event - ** after the value has changed. - ** @param bound whether the property is bound or not. - **/ - public void setBound(boolean bound) - { - this.bound = bound; - } - - /** Get whether the property is constrained. Defaults to false. **/ - public boolean isConstrained() - { - return constrained; - } - - /** Set whether the property is constrained. - ** If the set method throws <CODE>java.beans.PropertyVetoException</CODE> - ** (or subclass thereof) and the bean implements addVetoableChangeListener() - ** and removeVetoableChangeListener(), then setConstrained(true) may safely - ** be called. Otherwise, the system behavior is undefined. - ** <B>Spec note:</B> given those strict parameters, it would be nice if it - ** got set automatically by detection, but oh well.<P> - ** When a property is constrained, its set method is required to:<P> - ** <OL> - ** <LI>Fire the <CODE>VetoableChangeListener.vetoableChange()</CODE> - ** event notifying others of the change and allowing them a chance to - ** say it is a bad thing.</LI> - ** <LI>If any of the listeners throws a PropertyVetoException, then - ** it must fire another vetoableChange() event notifying the others - ** of a reversion to the old value (though, of course, the change - ** was never made). Then it rethrows the PropertyVetoException and - ** exits.</LI> - ** <LI>If all has gone well to this point, the value may be changed.</LI> - ** </OL> - ** @param constrained whether the property is constrained or not. - **/ - public void setConstrained(boolean constrained) - { - this.constrained = constrained; - } - - /** Get the PropertyEditor class. Defaults to null. **/ - public Class getPropertyEditorClass() - { - return propertyEditorClass; - } - - /** Set the PropertyEditor class. If the class does not implement - ** the PropertyEditor interface, you will likely get an exception - ** late in the game. - ** @param propertyEditorClass the PropertyEditor class for this - ** class to use. - **/ - public void setPropertyEditorClass(Class propertyEditorClass) - { - this.propertyEditorClass = propertyEditorClass; - } - - private void findMethods( - Class beanClass, - String getMethodName1, - String getMethodName2, - String setMethodName) - throws IntrospectionException - { - try - { - // Try the first get method name - if (getMethodName1 != null) - { - try - { - getMethod = - beanClass.getMethod(getMethodName1, new Class[0]); - } - catch (NoSuchMethodException e) - {} - } - - // Fall back to the second get method name - if (getMethod == null && getMethodName2 != null) - { - try - { - getMethod = - beanClass.getMethod(getMethodName2, new Class[0]); - } - catch (NoSuchMethodException e) - {} - } - - // Try the set method name - if (setMethodName != null) - { - if (getMethod != null) - { - // If there is a get method, use its return type to help - // select the corresponding set method. - Class propertyType = getMethod.getReturnType(); - if (propertyType == Void.TYPE) - { - String msg = - "The property's read method has return type 'void'"; - throw new IntrospectionException(msg); - } - - Class[] setArgs = new Class[] { propertyType }; - try - { - setMethod = beanClass.getMethod(setMethodName, setArgs); - } - catch (NoSuchMethodException e) - {} - } - else if (getMethodName1 == null && getMethodName2 == null) - { - // If this is a write-only property, choose the first set method - // with the required name, one parameter and return type 'void' - Method[] methods = beanClass.getMethods(); - for (int i = 0; i < methods.length; i++) - { - if (methods[i].getName().equals(setMethodName) - && methods[i].getParameterTypes().length == 1 - && methods[i].getReturnType() == Void.TYPE) - { - setMethod = methods[i]; - break; - } - } - } - } - } - catch (SecurityException e) - { - // FIXME -- shouldn't we just allow SecurityException to propagate? - String msg = - "SecurityException thrown on attempt to access methods."; - throw new IntrospectionException(msg); - } - } - - /** Checks whether the given <code>Method</code> instances are legal read and - * write methods. The following requirements must be met:<br/> - * <ul> - * <li>the read method must not have an argument</li> - * <li>the read method must have a non void return type</li> - * <li>the read method may not exist</li> - * <li>the write method must have a single argument</li> - * <li>the property type and the read method's return type must be assignable from the - * write method's argument type</li> - * <li>the write method may not exist</li> - * </ul> - * While checking the methods a common new property type is calculated. If the method - * succeeds this property type is returned.<br/> - * <br/> - * For compatibility this has to be noted:<br/> - * The two methods are allowed to be defined in two distinct classes and may both be null. - * - * @param readMethod The new read method to check. - * @param writeMethod The new write method to check. - * @return The common property type of the two method. - * @throws IntrospectionException If any of the above requirements are not met. - */ - private Class checkMethods(Method readMethod, Method writeMethod) - throws IntrospectionException - { - Class newPropertyType = propertyType; - - // a valid read method has zero arguments and a non-void return type. - if (readMethod != null) - { - if (readMethod.getParameterTypes().length > 0) - { - throw new IntrospectionException("read method has unexpected parameters"); - } - - newPropertyType = readMethod.getReturnType(); - - if (newPropertyType == Void.TYPE) - { - throw new IntrospectionException("read method return type is void"); - } - } - - // a valid write method has one argument which can be assigned to the property - if (writeMethod != null) - { - if (writeMethod.getParameterTypes().length != 1) - { - String msg = "write method does not have exactly one parameter"; - throw new IntrospectionException(msg); - } - - if (readMethod == null) - { - // changes the property type if there is no read method - newPropertyType = writeMethod.getParameterTypes()[0]; - } - else - { - // checks whether the write method can be assigned to the return type of the read - // method (if this is not the case, the methods are not compatible) - // note: newPropertyType may be null if no methods or method names have been - // delivered in the constructor. - if (newPropertyType != null - && !newPropertyType.isAssignableFrom( - writeMethod.getParameterTypes()[0])) - { - // note: newPropertyType is the same as readMethod.getReturnType() at this point - throw new IntrospectionException("read and write method are not compatible"); - } - - /* note: the check whether both method are defined in related classes makes sense but is not - * done in the JDK. - * I leave this code here in case someone at Sun decides to add that functionality in later versions (rschuster) - if ((!readMethod - .getDeclaringClass() - .isAssignableFrom(writeMethod.getDeclaringClass())) - && (!writeMethod - .getDeclaringClass() - .isAssignableFrom(readMethod.getDeclaringClass()))) - { - String msg = - "set and get methods are not in the same class."; - throw new IntrospectionException(msg); - } - */ - - } - } - - return newPropertyType; - } - - /** Compares this <code>PropertyDescriptor</code> against the - * given object. - * Two PropertyDescriptors are equals if - * <ul> - * <li>the read methods are equal</li> - * <li>the write methods are equal</li> - * <li>the property types are equals</li> - * <li>the property editor classes are equal</li> - * <li>the flags (constrained and bound) are equal</li> - * </ul> - * @return Whether both objects are equal according to the rules given above. - * @since 1.4 - */ - public boolean equals(Object o) - { - if (o instanceof PropertyDescriptor) - { - PropertyDescriptor that = (PropertyDescriptor) o; - - // compares the property types and checks the case where both are null - boolean samePropertyType = - (propertyType == null) - ? that.propertyType == null - : propertyType.equals(that.propertyType); - - // compares the property editor classes and checks the case where both are null - boolean samePropertyEditorClass = - (propertyEditorClass == null) - ? that.propertyEditorClass == null - : propertyEditorClass.equals(that.propertyEditorClass); - - // compares the flags for equality - boolean sameFlags = - bound == that.bound && constrained == that.constrained; - - // compares the read methods and checks the case where both are null - boolean sameReadMethod = - (getMethod == null) - ? that.getMethod == null - : getMethod.equals(that.getMethod); - - boolean sameWriteMethod = - (setMethod == null) - ? that.setMethod == null - : setMethod.equals(that.setMethod); - - return samePropertyType - && sameFlags - && sameReadMethod - && sameWriteMethod - && samePropertyEditorClass; - } - else - { - return false; - } - - } - -} diff --git a/libjava/java/beans/PropertyEditor.java b/libjava/java/beans/PropertyEditor.java deleted file mode 100644 index d1c5103419f..00000000000 --- a/libjava/java/beans/PropertyEditor.java +++ /dev/null @@ -1,209 +0,0 @@ -/* java.beans.PropertyEditor - Copyright (C) 1998 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.beans; - -/** - ** PropertyEditors are custom GUI editors for specific types of values. - ** - ** A PropertyEditor can be used, for example, if you are editing a type of value - ** that can be more easily represented graphically, such as a Point, or one that - ** can be more easily represented by a list, such as a boolean (true/false).<P> - ** - ** A PropertyEditor must be able to display its contents when asked to and - ** be able to allow the user to change its underlying field value. However, it - ** is not the PropertyEditor's responsibility to make the change to the - ** underlying Object; in fact, the PropertyEditor does not even know about the - ** Object it is actually editing--only about the property it is currently - ** editing. When a change is made to the property, the PropertyEditor must - ** simply fire a PropertyChangeEvent and allow the RAD tool to actually set - ** the property in the underlying Bean.<P> - ** - ** PropertyEditors should not change the Objects they are given by setValue(). - ** These Objects may or may not be the actual Objects which are properties of - ** the Bean being edited. Instead, PropertyEditors should create a new Object - ** and fire a PropertyChangeEvent with the old and new values.<P> - ** - ** PropertyEditors also must support the ability to return a Java - ** initialization string. See the getJavaInitializationString() method for - ** details.<P> - ** - ** There are several different ways a PropertyEditor may display and control - ** editing of its value. When multiple types of input and display are - ** given by a single PropertyEditor, the RAD tool may decide which of the call - ** to support. Some RAD tools may even be text-only, so even if you support - ** a graphical set and get, it may choose the text set and get whenever it can. - ** <OL> - ** <LI>Every PropertyEditor must support getValue() and setValue(). For - ** setValue(), the component must only support it when the argument is - ** the same type that the PropertyEditor supports.</LI> - ** <LI>Every PropertyEditor must support getJavaInitializationString().</LI> - ** <LI>You may support painting the value yourself if you wish. To do this, - ** have isPaintable() return true and implement the paintValue() method. - ** This method does not determine in any way how the value is edited; - ** merely how it is displayed.</LI> - ** <LI>Let the caller of the PropertyEditor give the user a text input. Do - ** this by returning a non-null String from getAsText(). If you support - ** text input, you *must* support setAsText().</LI> - ** <LI>Give the caller a set of possible values, such as "true"/"false", that - ** the user must select from. To do this, return the list of Strings - ** from the getTags() method. The RAD tool may choose to implement the - ** user input any way it wishes, and only guarantees that setAsText() will - ** only be called with one of the Strings returned from getTags().</LI> - ** <LI>You may support a whole custom editing control by supporting - ** getCustomEditor(). To do this, return true from supportsCustomEditor() - ** and return a Component that does the job. It is the component's job, - ** or the PropertyEditor's job, to make sure that when the editor changes - ** its value, the PropertyChangeEvent is thrown.</LI> - ** </OL> - ** - ** The PropertyEditor for a particular Bean can be found using the - ** PropertyEditorManager class, which goes through a series of different - ** checks to find the appropriate class.<P> - ** - ** A PropertyChangeEvent should be thrown from the PropertyEditor whenever a - ** bound property (a property PropertyDescriptor.isBound() set to true) - ** changes. When this happens, the editor itself should *not* change the value - ** itself, but rather allow the RAD tool to call setValue() or setAsText(). - ** - ** @author John Keiser - ** @since JDK1.1 - ** @version 1.1.0, 30 June 1998 - ** @see java.beans.PropertyEditorManager - ** @see java.beans.PropertyEditorSupport - **/ - -public interface PropertyEditor { - /** Called by the RAD tool to set the value of this property for the PropertyEditor. - ** If the property type is native, it should be wrapped in the appropriate - ** wrapper type. - ** @param value the value to set this property to. - **/ - void setValue(Object value); - - /** Accessor method to get the current value the PropertyEditor is working with. - ** If the property type is native, it will be wrapped in the appropriate - ** wrapper type. - ** @return the current value of the PropertyEditor. - **/ - Object getValue(); - - - /** Set the value of this property using a String. - ** Whether or not this PropertyEditor is editing a String type, this converts - ** the String into the type of the PropertyEditor. - ** @param text the text to set it to. - ** @exception IllegalArgumentException if the String is in the wrong format or setAsText() is not supported. - **/ - void setAsText(String text) throws IllegalArgumentException; - - /** Get the value of this property in String format. - ** Many times this can simply use Object.toString().<P> - ** Return null if you do not support getAsText()/setAsText(). - ** <code>setAsText(getAsText())</code> should be valid; i.e. the stuff you spit out in - ** getAsText() should be able to go into setAsText(). - ** @return the value of this property in String format. - **/ - String getAsText(); - - /** Get a list of possible Strings which this property type can have. - ** The value of these will be used by the RAD tool to construct some sort - ** of list box or to check text box input, and the resulting String passed - ** to setAsText() should be one of these. Note, however, that like most things - ** with this mammoth, unwieldy interface, this is not guaranteed. Thus, you - ** must check the value in setAsText() anyway. - ** @return the list of possible String values for this property type. - **/ - String[] getTags(); - - - /** The RAD tool calls this to find out whether the PropertyEditor can paint itself. - ** @return true if it can paint itself graphically, false if it cannot. - **/ - boolean isPaintable(); - - /** The RAD tool calls this to paint the actual value of the property. - ** The Graphics context will have the same current font, color, etc. as the - ** parent Container. You may safely change the font, color, etc. and not - ** change them back.<P> - ** This method should do a silent no-op if isPaintable() is false. - ** @param g the Graphics context to paint on - ** @param bounds the rectangle you have reserved to work in - **/ - void paintValue(java.awt.Graphics g, java.awt.Rectangle bounds); - - - /** The RAD tool calls this to find out whether the PropertyEditor supports a custom component to edit and display itself. - ** @return true if getCustomEditor() will return a component, false if not. - **/ - boolean supportsCustomEditor(); - - /** The RAD tool calls this to grab the component that can edit this type. - ** The component may be painted anywhere the RAD tool wants to paint it-- - ** even in its own window.<P> - ** The component must hook up with the PropertyEditor and, whenever a - ** change to the value is made, fire a PropertyChangeEvent to the source.<P> - ** @return the custom editor for this property type. - **/ - java.awt.Component getCustomEditor(); - - - /** Adds a property change listener to this PropertyEditor. - ** @param listener the listener to add - **/ - void addPropertyChangeListener(PropertyChangeListener listener); - - /** Removes a property change listener from this PropertyEditor. - ** @param listener the listener to remove - **/ - void removePropertyChangeListener(PropertyChangeListener listener); - - /** Get a Java language-specific String which could be used to create an Object - ** of the specified type. Every PropertyEditor must support this.<P> - ** The reason for this is that while most RAD tools will serialize the Beans - ** and deserialize them at runtime, some RAD tools will generate code that - ** creates the Beans. Examples of Java initialization strings would be:<P> - ** <OL> - ** <LI><CODE>2</CODE></LI> - ** <LI><CODE>"I am a String"</CODE></LI> - ** <LI><CODE>new MyObject(2, "String", new StringBuffer())</CODE></LI> - ** </OL> - ** @return the initialization string for this object in Java. - **/ - String getJavaInitializationString(); -} diff --git a/libjava/java/beans/PropertyEditorManager.java b/libjava/java/beans/PropertyEditorManager.java deleted file mode 100644 index da2a5678c5c..00000000000 --- a/libjava/java/beans/PropertyEditorManager.java +++ /dev/null @@ -1,215 +0,0 @@ -/* java.beans.PropertyEditorManager - Copyright (C) 1998 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.beans; - -import gnu.java.beans.editors.ColorEditor; -import gnu.java.beans.editors.FontEditor; -import gnu.java.beans.editors.NativeBooleanEditor; -import gnu.java.beans.editors.NativeByteEditor; -import gnu.java.beans.editors.NativeDoubleEditor; -import gnu.java.beans.editors.NativeFloatEditor; -import gnu.java.beans.editors.NativeIntEditor; -import gnu.java.beans.editors.NativeLongEditor; -import gnu.java.beans.editors.NativeShortEditor; -import gnu.java.beans.editors.StringEditor; -import gnu.java.lang.ClassHelper; - -import java.awt.Color; -import java.awt.Font; - -/** - * PropertyEditorManager is used to find property editors - * for various types (not necessarily Beans).<P> - * - * It first checks to see if the property editor is - * already registered; if it is, that property editor is - * used. Next it takes the type's classname and appends - * "Editor" to it, and searches first in the class's - * package and then in the property editor search path. - * - * <p>Default property editors are provided for:</p> - * - * <ol> - * <li>boolean, byte, short, int, long, float, and double</li> - * <li>java.lang.String</li> - * <li>java.awt.Color</li> - * <li>java.awt.Font</li> - * </ol> - * - * <p><strong>Spec Suggestion:</strong> Perhaps an editor for - * Filename or something like it should be provided. As well - * as char.</p> - * - * @author John Keiser - * @since 1.1 - * @version 1.1.0, 29 Jul 1998 - */ - -public class PropertyEditorManager -{ - static java.util.Hashtable editors = new java.util.Hashtable(); - static String[] editorSearchPath = { "gnu.java.beans.editors", - "sun.beans.editors" }; - - static - { - registerEditor(Boolean.TYPE, NativeBooleanEditor.class); - registerEditor(Byte.TYPE, NativeByteEditor.class); - registerEditor(Short.TYPE, NativeShortEditor.class); - registerEditor(Integer.TYPE, NativeIntEditor.class); - registerEditor(Long.TYPE, NativeLongEditor.class); - registerEditor(Float.TYPE, NativeFloatEditor.class); - registerEditor(Double.TYPE, NativeDoubleEditor.class); - registerEditor(String.class, StringEditor.class); - registerEditor(Color.class, ColorEditor.class); - registerEditor(Font.class, FontEditor.class); - } - - /** - * Beats me why this class can be instantiated, but there - * you have it. - */ - public PropertyEditorManager() - { - // Do nothing here - } - - /** - * Register an editor for a class. Replaces old editor - * if there was one registered before. - * - * @param editedClass the class that the property editor - * will edit. - * @param editorClass the PropertyEditor class. - */ - public static void registerEditor(Class editedClass, Class editorClass) - { - editors.put(editedClass, editorClass); - } - - /** - * Returns a new instance of the property editor for the - * specified class. - * - * @param editedClass the class that the property editor - * will edit. - * @return a PropertyEditor instance that can edit the - * specified class. - */ - public static PropertyEditor findEditor(Class editedClass) - { - try - { - Class found = (Class)editors.get(editedClass); - if(found != null) - { - return (PropertyEditor)found.newInstance(); - } - - ClassLoader contextClassLoader - = Thread.currentThread().getContextClassLoader(); - - try - { - found = Class.forName(editedClass.getName()+"Editor", true, - contextClassLoader); - registerEditor(editedClass,found); - return (PropertyEditor)found.newInstance(); - } - catch(ClassNotFoundException E) - { - } - - String appendName - = "." - + ClassHelper.getTruncatedClassName(editedClass) - + "Editor"; - synchronized(editorSearchPath) - { - for(int i=0;i<editorSearchPath.length;i++) - { - try - { - found = Class.forName(editorSearchPath[i] + appendName, - true, contextClassLoader); - registerEditor(editedClass,found); - return (PropertyEditor)found.newInstance(); - } - catch(ClassNotFoundException E) - { - } - } - } - } - catch(InstantiationException E) - { - } - catch(IllegalAccessException E) - { - } - - return null; - } - - /** - * Get the editor search path. - * As a minor departure from the spec, the default value - * for the editor search path is "gnu.java.beans.editors", - * "sun.beans.editors". - * - * @return the editor search path. - */ - public static String[] getEditorSearchPath() - { - return editorSearchPath; - } - - /** - * Set the editor search path. - * - * @param editorSearchPath the new value for the editor search path. - */ - public static void setEditorSearchPath(String[] editorSearchPath) - { - synchronized(editorSearchPath) - { - PropertyEditorManager.editorSearchPath = editorSearchPath; - } - } -} diff --git a/libjava/java/beans/PropertyEditorSupport.java b/libjava/java/beans/PropertyEditorSupport.java deleted file mode 100644 index bb68e0e3145..00000000000 --- a/libjava/java/beans/PropertyEditorSupport.java +++ /dev/null @@ -1,265 +0,0 @@ -/* java.beans.PropertyEditorSupport - Copyright (C) 1998, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.beans; - - -/** - * PropertyEditorSupport helps with PropertyEditors, - * implementing base functionality that they usually must - * have but which is a pain to implement. You may extend - * from this class or use it as a standalone.<P> - * - * This class does not do any painting or actual editing. - * For that, you must use or extend it. See the - * PropertyEditor class for better descriptions of what - * the various methods do. - * - * @author John Keiser - * @author Robert Schuster - * @since 1.1 - * @status updated to 1.5 - */ -public class PropertyEditorSupport implements PropertyEditor -{ - Object eventSource; - Object value; - PropertyChangeSupport pSupport; - - /** Call this constructor when you are deriving from - * PropertyEditorSupport. - * - * Using this constructor the event source is this PropertyEditorSupport - * instance itself. - * - * @since 1.5 - * @specnote this was <code>protected</code> prior to 1.5 - */ - public PropertyEditorSupport() - { - eventSource = this; - pSupport = new PropertyChangeSupport(this); - } - - /** Call this constructor when you are using - * PropertyEditorSupport as a helper object. - * - * This constructor throws a NullPointerException when <code>source</code> is <code>null</code>, - * for compatibility reasons with J2SDK 1.5.0 . - * - * @param source The source to use when firing - * property change events. - * @since 1.5 - * @specnote this was <code>protected</code> prior to 1.5 - */ - public PropertyEditorSupport(Object source) - { - // note: constructor rejects source being null for the sake of compatibility - // with official 1.5.0 implementation - if (source == null) - throw new NullPointerException("Event source must not be null."); - - eventSource = source; - pSupport = new PropertyChangeSupport(eventSource); - } - - /** Sets the current value of the property and a property change - * event is fired to all registered PropertyChangeListener instances. - * - * @param newValue The new value for the property. - */ - public void setValue(Object newValue) - { - value = newValue; - - // specification in java.beans.PropertyChangeEvent says - // that without a property name (first argument) the - // new and the old value should always be null - pSupport.firePropertyChange(null, null, null); - } - - /** Gets the current value of the property. - * - * @return the current value of the property. - */ - public Object getValue() - { - return value; - } - - /** Gets whether this object is paintable or not. - * - * @return <CODE>false</CODE> - */ - public boolean isPaintable() - { - return false; - } - - /** Paints this object. This class does nothing in - * this method. - */ - public void paintValue(java.awt.Graphics g, java.awt.Rectangle r) - { - } - - /** Gets the Java initialization String for the current - * value of the Object. This class returns gibberish or - * null (though the spec does not say which).<P> - * <STRONG>Implementation Note:</STRONG> This class - * returns the string "@$#^" to make sure the code will - * be broken, so that you will know to override it when - * you create your own property editor. - * - * @return the Java initialization string. - */ - public String getJavaInitializationString() - { - return "@$#^"; - } - - /** Gets the value as text. - * In this class, you cannot count on getAsText() doing - * anything useful, although in this implementation I - * do toString(). - * - * @return the value as text. - */ - public String getAsText() - { - return value != null ? value.toString() : "null"; - } - - /** Sets the value as text. - * In this class, you cannot count on setAsText() doing - * anything useful across implementations. - * <STRONG>Implementation Note:</STRONG> In this - * implementation it checks if the String is "null", and - * if it is, sets the value to null, otherwise it throws - * an IllegalArgumentException. - * - * @param s the text to convert to a new value. - * @exception IllegalArgumentException if the text is - * malformed. - */ - public void setAsText(String s) throws IllegalArgumentException - { - if (s.equals("null")) - setValue(null); - else - throw new IllegalArgumentException(); - } - - /** Returns a list of possible choices for the value. - * - * @return <CODE>null</CODE> - */ - public String[] getTags() - { - return null; - } - - /** Returns a custom component to edit the value. - * - * @return <CODE>null</CODE> in this class. - */ - public java.awt.Component getCustomEditor() - { - return null; - } - - /** Finds out whether this property editor supports a - * custom component to edit its value. - * - * @return <CODE>false</CODE> in this class. - */ - public boolean supportsCustomEditor() - { - return false; - } - - /** Adds a property change listener to this property editor. - * - * @param l the listener to add. - */ - public void addPropertyChangeListener(PropertyChangeListener l) - { - pSupport.addPropertyChangeListener(l); - } - - /** Removes a property change listener from this property editor. - * - * @param l the listener to remove. - */ - public void removePropertyChangeListener(PropertyChangeListener l) - { - pSupport.removePropertyChangeListener(l); - } - - /** Notifies people that we've changed, although we don't - * tell them just how. - */ - public void firePropertyChange() - { - pSupport.firePropertyChange(null, null, null); - } - - /** Returns the bean that is used as the source of events. - * - * @return The event source object - * @since 1.5 - */ - public Object getSource() - { - return eventSource; - } - - /** Sets the bean that is used as the source of events - * when property changes occur. - * - * The event source bean is for informational purposes only - * and should not be changed by the <code>PropertyEditor</code>. - * - * @param source - * @since 1.5 - */ - public void setSource(Object source) - { - eventSource = source; - } -} diff --git a/libjava/java/beans/PropertyVetoException.java b/libjava/java/beans/PropertyVetoException.java deleted file mode 100644 index 1f0399b4bfb..00000000000 --- a/libjava/java/beans/PropertyVetoException.java +++ /dev/null @@ -1,85 +0,0 @@ -/* PropertyVetoException.java -- thrown to veto a proposed property change - Copyright (C) 1998, 2000, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.beans; - -/** - * PropertyVetoException is thrown when a VetoableChangeListener doesn't - * like the proposed change. - * - * @author John Keiser - * @see VetoableChangeListener - * @since 1.1 - * @status updated to 1.4 - */ -public class PropertyVetoException extends Exception -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = 129596057694162164L; - - /** - * The vetoed change. - * - * @serial the event that was vetoed - */ - private final PropertyChangeEvent evt; - - /** - * Instantiate this exception with the given message and property change. - * - * @param msg the reason for the veto - * @param changeEvent the PropertyChangeEvent that was thrown - */ - public PropertyVetoException(String msg, PropertyChangeEvent changeEvent) - { - super(msg); - evt = changeEvent; - } - - /** - * Get the PropertyChange event that was vetoed. - * - * @return the vetoed change - */ - public PropertyChangeEvent getPropertyChangeEvent() - { - return evt; - } -} diff --git a/libjava/java/beans/SimpleBeanInfo.java b/libjava/java/beans/SimpleBeanInfo.java deleted file mode 100644 index cfb96048498..00000000000 --- a/libjava/java/beans/SimpleBeanInfo.java +++ /dev/null @@ -1,139 +0,0 @@ -/* java.beans.SimpleBeanInfo - Copyright (C) 1998 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.beans; - -import java.awt.Image; -import java.awt.Toolkit; - -/** - ** SimpleBeanInfo is a class you may extend to more easily - ** provide select information to the Introspector. It - ** implements all of the methods in BeanInfo by returning - ** null and forces the Introspector to behave exactly as - ** if there were no BeanInfo class at all (Introspecting - ** everything).<P> - ** - ** Overriding one or two of these functions - ** to give explicit information on only those things you - ** wish to give explicit information is perfectly safe, - ** and even desirable.<P> - ** - ** See the BeanInfo class for information on what the - ** various methods actually do. - ** - ** @author John Keiser - ** @since JDK1.1 - ** @version 1.1.0, 29 Jul 1998 - ** @see java.beans.BeanInfo - **/ - -public class SimpleBeanInfo implements BeanInfo { - /** Force Introspection of the general bean info. - ** @return <CODE>null</CODE>. - **/ - public BeanDescriptor getBeanDescriptor() { - return null; - } - - /** Force Introspection of the events this Bean type - ** fires. - ** @return <CODE>null</CODE> - **/ - public EventSetDescriptor[] getEventSetDescriptors() { - return null; - } - - /** Say that there is no "default" event set. - ** @return <CODE>-1</CODE>. - **/ - public int getDefaultEventIndex() { - return -1; - } - - /** Force Introspection of the Bean properties. - ** @return <CODE>null</CODE>. - **/ - public PropertyDescriptor[] getPropertyDescriptors() { - return null; - } - - /** Say that there is no "default" property. - ** @return <CODE>-1</CODE>. - **/ - public int getDefaultPropertyIndex() { - return -1; - } - - /** Force Introspection of the Bean's methods. - ** @return <CODE>null</CODE>. - **/ - public MethodDescriptor[] getMethodDescriptors() { - return null; - } - - /** Tell the Introspector to go look for other BeanInfo - ** itself. - ** @return <CODE>null</CODE>. - **/ - public BeanInfo[] getAdditionalBeanInfo() { - return null; - } - - /** Say that this Bean has no icons. - ** @param iconType the type of icon - ** @return <CODE>null</CODE>. - **/ - public Image getIcon(int iconType) { - return null; - } - - /** Helper method to load an image using the Bean class - ** getResource() method on the BeanInfo class (using - ** getClass(), since you'll extend this class to get - ** the BeanInfo). Basically it's assumed that the Bean - ** and its BeanInfo are both loaded by the same - ** ClassLoader, generally a reasonable assumption. - ** @param location the URL relative - ** @return the Image in question. - **/ - public Image loadImage(String location) { - return Toolkit.getDefaultToolkit().getImage(getClass().getResource(location)); - } -} - diff --git a/libjava/java/beans/Statement.java b/libjava/java/beans/Statement.java deleted file mode 100644 index 01f86dd286f..00000000000 --- a/libjava/java/beans/Statement.java +++ /dev/null @@ -1,326 +0,0 @@ -/* java.beans.Statement - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.beans; - -import java.lang.reflect.Array; -import java.lang.reflect.Constructor; -import java.lang.reflect.Method; - -/** - * class Statement - * - * A Statement captures the execution of an object method. It stores - * the object, the method to call, and the arguments to the method and - * provides the ability to execute the method on the object, using the - * provided arguments. - * - * @since 1.4 - */ -public class Statement -{ - private Object target; - private String methodName; - private Object[] arguments; - - // One or the other of these will get a value after execute is - // called once, but not both. - private transient Method method; - private transient Constructor ctor; - - /** - * Constructs a statement representing the invocation of - * object.methodName(arg[0], arg[1], ...); - * - * @param target The object to invoke the method on. - * @param methodName The object method to invoke. - * @param arguments An array of arguments to pass to the method. - */ - public Statement(Object target, String methodName, Object[] arguments) - { - this.target = target; - this.methodName = methodName; - this.arguments = arguments; - } - - /** - * Execute the statement. - * - * Finds the specified method in the target object and calls it with - * the arguments given in the constructor. - * - * The most specific method according to the JLS(15.11) is used when - * there are multiple methods with the same name. - * - * Execute performs some special handling for methods and - * parameters: - * - * Static methods can be executed by providing the class as a - * target. - * - * The method name new is reserved to call the constructor - * new() will construct an object and return it. Not useful unless - * an expression :-) - * - * If the target is an array, get and set as defined in - * java.util.List are recognized as valid methods and mapped to the - * methods of the same name in java.lang.reflect.Array. - * - * The native datatype wrappers Boolean, Byte, Character, Double, - * Float, Integer, Long, and Short will map to methods that have - * native datatypes as parameters, in the same way as Method.invoke. - * However, these wrappers also select methods that actually take - * the wrapper type as an argument. - * - * The Sun spec doesn't deal with overloading between int and - * Integer carefully. If there are two methods, one that takes an - * Integer and the other taking an int, the method chosen is not - * specified, and can depend on the order in which the methods are - * declared in the source file. - * - * @throws Exception if an exception occurs while locating or - * invoking the method. - */ - public void execute() throws Exception - { - doExecute(); - } - - private static Class wrappers[] = - { - Boolean.class, Byte.class, Character.class, Double.class, Float.class, - Integer.class, Long.class, Short.class - }; - - private static Class natives[] = - { - Boolean.TYPE, Byte.TYPE, Character.TYPE, Double.TYPE, Float.TYPE, - Integer.TYPE, Long.TYPE, Short.TYPE - }; - - // Given a wrapper class, return the native class for it. For - // example, if c is Integer, Integer.TYPE is returned. - private Class unwrap(Class c) - { - for (int i = 0; i < wrappers.length; i++) - if (c == wrappers[i]) - return natives[i]; - return null; - } - - // Return true if all args can be assigned to params, false - // otherwise. Arrays are guaranteed to be the same length. - private boolean compatible(Class[] params, Class[] args) - { - for (int i = 0; i < params.length; i++) - { - // Treat Integer like int if appropriate - Class nativeType = unwrap(args[i]); - if (nativeType != null && params[i].isPrimitive() - && params[i].isAssignableFrom(nativeType)) - continue; - if (params[i].isAssignableFrom(args[i])) - continue; - - return false; - } - return true; - } - - /** - * Return true if the method arguments in first are more specific - * than the method arguments in second, i.e. all args in first can - * be assigned to those in second. - * - * A method is more specific if all parameters can also be fed to - * the less specific method, because, e.g. the less specific method - * accepts a base class of the equivalent argument for the more - * specific one. - * - * @param first a <code>Class[]</code> value - * @param second a <code>Class[]</code> value - * @return a <code>boolean</code> value - */ - private boolean moreSpecific(Class[] first, Class[] second) - { - for (int j=0; j < first.length; j++) - { - if (second[j].isAssignableFrom(first[j])) - continue; - return false; - } - return true; - } - - final Object doExecute() throws Exception - { - Class klazz = (target instanceof Class) - ? (Class) target : target.getClass(); - Object args[] = (arguments == null) ? new Object[0] : arguments; - Class argTypes[] = new Class[args.length]; - for (int i = 0; i < args.length; i++) - argTypes[i] = args[i].getClass(); - - if (target.getClass().isArray()) - { - // FIXME: invoke may have to be used. For now, cast to Number - // and hope for the best. If caller didn't behave, we go boom - // and throw the exception. - if (methodName.equals("get") && argTypes.length == 1) - return Array.get(target, ((Number)args[0]).intValue()); - if (methodName.equals("set") && argTypes.length == 2) - { - Object obj = Array.get(target, ((Number)args[0]).intValue()); - Array.set(target, ((Number)args[0]).intValue(), args[1]); - return obj; - } - throw new NoSuchMethodException("No matching method for statement " + toString()); - } - - // If we already cached the method, just use it. - if (method != null) - return method.invoke(target, args); - else if (ctor != null) - return ctor.newInstance(args); - - // Find a matching method to call. JDK seems to go through all - // this to find the method to call. - - // if method name or length don't match, skip - // Need to go through each arg - // If arg is wrapper - check if method arg is matchable builtin - // or same type or super - // - check that method arg is same or super - - if (methodName.equals("new") && target instanceof Class) - { - Constructor ctors[] = klazz.getConstructors(); - for (int i = 0; i < ctors.length; i++) - { - // Skip methods with wrong number of args. - Class ptypes[] = ctors[i].getParameterTypes(); - System.out.println("ptypeslen = " + ptypes.length); - System.out.println("ptypes = " + ptypes); - System.out.println("ctor = " + ctors[i].getName()); - for (int j=0; j < ptypes.length; j++) { - System.out.println("param = " + ptypes[i].getName()); - - } - - - if (ptypes.length != args.length) - continue; - - // Check if method matches - if (!compatible(ptypes, argTypes)) - continue; - - // Use method[i] if it is more specific. - // FIXME: should this check both directions and throw if - // neither is more specific? - if (ctor == null) - { - ctor = ctors[i]; - continue; - } - Class mptypes[] = ctor.getParameterTypes(); - if (moreSpecific(ptypes, mptypes)) - ctor = ctors[i]; - } - if (ctor == null) - throw new InstantiationException("No matching constructor for statement " + toString()); - return ctor.newInstance(args); - } - - Method methods[] = klazz.getMethods(); - - for (int i = 0; i < methods.length; i++) - { - // Skip methods with wrong name or number of args. - if (!methods[i].getName().equals(methodName)) - continue; - Class ptypes[] = methods[i].getParameterTypes(); - if (ptypes.length != args.length) - continue; - - // Check if method matches - if (!compatible(ptypes, argTypes)) - continue; - - // Use method[i] if it is more specific. - // FIXME: should this check both directions and throw if - // neither is more specific? - if (method == null) - { - method = methods[i]; - continue; - } - Class mptypes[] = method.getParameterTypes(); - if (moreSpecific(ptypes, mptypes)) - method = methods[i]; - } - if (method == null) - throw new NoSuchMethodException("No matching method for statement " + toString()); - return method.invoke(target, args); - } - - - - /** Return the statement arguments. */ - public Object[] getArguments() { return arguments; } - - /** Return the statement method name. */ - public String getMethodName() { return methodName; } - - /** Return the statement object. */ - public Object getTarget() { return target; } - - /** Return a string representation. */ - public String toString() - { - String result = target.getClass().getName() + "." + methodName + "("; - String sep = ""; - for (int i = 0; i < arguments.length; i++) - { - result = result + sep + arguments[i].getClass().getName(); - sep = ", "; - } - result = result + ")"; - return result; - } -} diff --git a/libjava/java/beans/VetoableChangeListener.java b/libjava/java/beans/VetoableChangeListener.java deleted file mode 100644 index 5107954b033..00000000000 --- a/libjava/java/beans/VetoableChangeListener.java +++ /dev/null @@ -1,73 +0,0 @@ -/* VetoableChangeListener.java -- listen for a change which can be vetoed - Copyright (C) 1998, 2000, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.beans; - -import java.util.EventListener; - -/** - * VetoableChangeListener allows a class to monitor proposed changes to - * properties of a Bean and, if desired, prevent them from occurring. A - * vetoableChange() event will be fired <em>after</em> the property change has - * been requested, but before it is permanent. If any listener rejects the - * change by throwing the PropertyChangeException, a new vetoableChange() - * event will be fired to all listeners who received a vetoableChange() event - * in the first place, informing them to revert back to the old value. Thus, - * the listener that threw the exception the first time should be prepared - * to rethrow it the second time. The value, of course, never actually changed. - * - * <p><strong>Note:</strong> This class may not be reliably used to determine - * whether a property has actually changed. Use the PropertyChangeListener - * interface for that instead. - * - * @author John Keiser - * @see java.beans.PropertyChangeListener - * @see java.beans.VetoableChangeSupport - * @since 1.1 - * @status updated to 1.4 - */ -public interface VetoableChangeListener extends EventListener -{ - /** - * Fired before a Bean's property changes. - * - * @param e the change (containing the old and new values) - * @throws PropertyVetoException if the change is vetoed by the listener - */ - void vetoableChange(PropertyChangeEvent e) throws PropertyVetoException; -} // interface VetoableChangeListener diff --git a/libjava/java/beans/VetoableChangeListenerProxy.java b/libjava/java/beans/VetoableChangeListenerProxy.java deleted file mode 100644 index 56ca5a38c7f..00000000000 --- a/libjava/java/beans/VetoableChangeListenerProxy.java +++ /dev/null @@ -1,102 +0,0 @@ -/* VetoableChangeListenerProxy.java -- adds a name to a vetoable listener - Copyright (C) 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.beans; - -import java.util.EventListenerProxy; - -/** - * This class provides an extension to <code>VetoableChangeListener</code> - - * associating a name with the listener. This can be used to filter the - * changes that one is interested in. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.4 - * @status udpated to 1.4 - */ -public class VetoableChangeListenerProxy extends EventListenerProxy - implements VetoableChangeListener -{ - /** - * The name of the property to listen for. Package visible for use by - * VetoableChangeSupport. - */ - final String propertyName; - - /** - * Create a new proxy which filters property change events and only passes - * changes to the named property on to the delegate. - * - * @param propertyName the property's name to filter on - * @param listener the delegate listener - */ - public VetoableChangeListenerProxy(String propertyName, - VetoableChangeListener listener) - { - super(listener); - this.propertyName = propertyName; - } - - /** - * Forwards the event on to the delegate if the property name matches. - * - * @param event the event to pass on, if it meets the filter - * @throws NullPointerException if the delegate this was created with is null - * @throws PropertyVetoException if the change is vetoed by the listener - */ - public void vetoableChange(PropertyChangeEvent event) - throws PropertyVetoException - { - // Note: Sun does not filter, under the assumption that since - // VetoableChangeSupport unwraps proxys, this method should never be - // called by normal use of listeners. - String name = event == null ? null : event.getPropertyName(); - if (name == null ? propertyName == null : name.equals(propertyName)) - ((VetoableChangeListener) getListener()).vetoableChange(event); - } - - /** - * Gets the name of the property this proxy is filtering on. - * - * @return the property name - */ - public String getPropertyName() - { - return propertyName; - } -} // class VetoableChangeListenerProxy diff --git a/libjava/java/beans/VetoableChangeSupport.java b/libjava/java/beans/VetoableChangeSupport.java deleted file mode 100644 index dce8dffd341..00000000000 --- a/libjava/java/beans/VetoableChangeSupport.java +++ /dev/null @@ -1,530 +0,0 @@ -/* VetoableChangeSupport.java -- support to manage vetoable change listeners - Copyright (C) 1998, 1999, 2000, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.beans; - -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Hashtable; -import java.util.Iterator; -import java.util.Map.Entry; -import java.util.Vector; - -/** - * VetoableChangeSupport makes it easy to fire vetoable change events and - * handle listeners. It allows chaining of listeners, as well as filtering - * by property name. In addition, it will serialize only those listeners - * which are serializable, ignoring the others without problem. This class - * is thread-safe. - * - * @author John Keiser - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.1 - * @status updated to 1.4 - */ -public class VetoableChangeSupport implements Serializable -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = -5090210921595982017L; - - /** - * Maps property names (String) to named listeners (VetoableChangeSupport). - * If this is a child instance, this field will be null. - * - * @serial the map of property names to named listener managers - * @since 1.2 - */ - private Hashtable children; - - /** - * The non-null source object for any generated events. - * - * @serial the event source - */ - private final Object source; - - /** - * A field to compare serialization versions - this class uses version 2. - * - * @serial the serialization format - */ - private static final int vetoableChangeSupportSerializedDataVersion = 2; - - /** - * The list of all registered vetoable listeners. If this instance was - * created by user code, this only holds the global listeners (ie. not tied - * to a name), and may be null. If it was created by this class, as a - * helper for named properties, then this vector will be non-null, and this - * instance appears as a value in the <code>children</code> hashtable of - * another instance, so that the listeners are tied to the key of that - * hashtable entry. - */ - private transient Vector listeners; - - /** - * Create a VetoableChangeSupport to work with a specific source bean. - * - * @param source the source bean to use - * @throws NullPointerException if source is null - */ - public VetoableChangeSupport(Object source) - { - this.source = source; - if (source == null) - throw new NullPointerException(); - } - - /** - * Adds a VetoableChangeListener to the list of global listeners. All - * vetoable change events will be sent to this listener. The listener add - * is not unique: that is, <em>n</em> adds with the same listener will - * result in <em>n</em> events being sent to that listener for every - * vetoable change. Adding a null listener may cause a NullPointerException - * down the road. This method will unwrap a VetoableChangeListenerProxy, - * registering the underlying delegate to the named property list. - * - * @param l the listener to add - */ - public synchronized void addVetoableChangeListener(VetoableChangeListener l) - { - if (l instanceof VetoableChangeListenerProxy) - { - VetoableChangeListenerProxy p = (VetoableChangeListenerProxy) l; - addVetoableChangeListener(p.propertyName, - (VetoableChangeListener) p.getListener()); - } - else - { - if (listeners == null) - listeners = new Vector(); - listeners.add(l); - } - } - - /** - * Removes a VetoableChangeListener from the list of global listeners. If - * any specific properties are being listened on, they must be deregistered - * by themselves; this will only remove the general listener to all - * properties. If <code>add()</code> has been called multiple times for a - * particular listener, <code>remove()</code> will have to be called the - * same number of times to deregister it. This method will unwrap a - * VetoableChangeListenerProxy, removing the underlying delegate from the - * named property list. - * - * @param l the listener to remove - */ - public synchronized void - removeVetoableChangeListener(VetoableChangeListener l) - { - if (l instanceof VetoableChangeListenerProxy) - { - VetoableChangeListenerProxy p = (VetoableChangeListenerProxy) l; - removeVetoableChangeListener(p.propertyName, - (VetoableChangeListener) p.getListener()); - } - else if (listeners != null) - { - listeners.remove(l); - if (listeners.isEmpty()) - listeners = null; - } - } - - /** - * Returns an array of all registered vetoable change listeners. Those that - * were registered under a name will be wrapped in a - * <code>VetoableChangeListenerProxy</code>, so you must check whether the - * listener is an instance of the proxy class in order to see what name the - * real listener is registered under. If there are no registered listeners, - * this returns an empty array. - * - * @return the array of registered listeners - * @see VetoableChangeListenerProxy - * @since 1.4 - */ - public synchronized VetoableChangeListener[] getVetoableChangeListeners() - { - ArrayList list = new ArrayList(); - if (listeners != null) - list.addAll(listeners); - if (children != null) - { - int i = children.size(); - Iterator iter = children.entrySet().iterator(); - while (--i >= 0) - { - Entry e = (Entry) iter.next(); - String name = (String) e.getKey(); - Vector v = ((VetoableChangeSupport) e.getValue()).listeners; - int j = v.size(); - while (--j >= 0) - list.add(new VetoableChangeListenerProxy - (name, (VetoableChangeListener) v.get(j))); - } - } - return (VetoableChangeListener[]) - list.toArray(new VetoableChangeListener[list.size()]); - } - - /** - * Adds a VetoableChangeListener listening on the specified property. Events - * will be sent to the listener only if the property name matches. The - * listener add is not unique; that is, <em>n</em> adds on a particular - * property for a particular listener will result in <em>n</em> events - * being sent to that listener when that property is changed. The effect is - * cumulative, too; if you are registered to listen to receive events on - * all vetoable changes, and then you register on a particular property, - * you will receive change events for that property twice. Adding a null - * listener may cause a NullPointerException down the road. This method - * will unwrap a VetoableChangeListenerProxy, registering the underlying - * delegate to the named property list if the names match, and discarding - * it otherwise. - * - * @param propertyName the name of the property to listen on - * @param l the listener to add - * @throws NullPointerException if propertyName is null - */ - public synchronized void addVetoableChangeListener(String propertyName, - VetoableChangeListener l) - { - while (l instanceof VetoableChangeListenerProxy) - { - VetoableChangeListenerProxy p = (VetoableChangeListenerProxy) l; - if (propertyName == null ? p.propertyName != null - : ! propertyName.equals(p.propertyName)) - return; - l = (VetoableChangeListener) p.getListener(); - } - VetoableChangeSupport s = null; - if (children == null) - children = new Hashtable(); - else - s = (VetoableChangeSupport) children.get(propertyName); - if (s == null) - { - s = new VetoableChangeSupport(source); - s.listeners = new Vector(); - children.put(propertyName, s); - } - s.listeners.add(l); - } - - /** - * Removes a VetoableChangeListener from listening to a specific property. - * If <code>add()</code> has been called multiple times for a particular - * listener on a property, <code>remove()</code> will have to be called the - * same number of times to deregister it. This method will unwrap a - * VetoableChangeListenerProxy, removing the underlying delegate from the - * named property list if the names match. - * - * @param propertyName the property to stop listening on - * @param l the listener to remove - * @throws NullPointerException if propertyName is null - */ - public synchronized void - removeVetoableChangeListener(String propertyName, VetoableChangeListener l) - { - if (children == null) - return; - VetoableChangeSupport s - = (VetoableChangeSupport) children.get(propertyName); - if (s == null) - return; - while (l instanceof VetoableChangeListenerProxy) - { - VetoableChangeListenerProxy p = (VetoableChangeListenerProxy) l; - if (propertyName == null ? p.propertyName != null - : ! propertyName.equals(p.propertyName)) - return; - l = (VetoableChangeListener) p.getListener(); - } - s.listeners.remove(l); - if (s.listeners.isEmpty()) - { - children.remove(propertyName); - if (children.isEmpty()) - children = null; - } - } - - /** - * Returns an array of all vetoable change listeners registered under the - * given property name. If there are no registered listeners, this returns - * an empty array. - * - * @return the array of registered listeners - * @throws NullPointerException if propertyName is null - * @since 1.4 - */ - public synchronized VetoableChangeListener[] - getVetoableChangeListeners(String propertyName) - { - if (children == null) - return new VetoableChangeListener[0]; - VetoableChangeSupport s - = (VetoableChangeSupport) children.get(propertyName); - if (s == null) - return new VetoableChangeListener[0]; - return (VetoableChangeListener[]) - s.listeners.toArray(new VetoableChangeListener[s.listeners.size()]); - } - - /** - * Fire a PropertyChangeEvent containing the old and new values of the - * property to all the global listeners, and to all the listeners for the - * specified property name. This does nothing if old and new are non-null - * and equal. If the change is vetoed, a new event is fired to notify - * listeners about the rollback before the exception is thrown. - * - * @param propertyName the name of the property that changed - * @param oldVal the old value - * @param newVal the new value - * @throws PropertyVetoException if the change is vetoed by a listener - */ - public void fireVetoableChange(String propertyName, - Object oldVal, Object newVal) - throws PropertyVetoException - { - fireVetoableChange(new PropertyChangeEvent(source, propertyName, - oldVal, newVal)); - } - - /** - * Fire a PropertyChangeEvent containing the old and new values of the - * property to all the global listeners, and to all the listeners for the - * specified property name. This does nothing if old and new are equal. - * If the change is vetoed, a new event is fired to notify listeners about - * the rollback before the exception is thrown. - * - * @param propertyName the name of the property that changed - * @param oldVal the old value - * @param newVal the new value - * @throws PropertyVetoException if the change is vetoed by a listener - */ - public void fireVetoableChange(String propertyName, int oldVal, int newVal) - throws PropertyVetoException - { - if (oldVal != newVal) - fireVetoableChange(new PropertyChangeEvent(source, propertyName, - new Integer(oldVal), - new Integer(newVal))); - } - - /** - * Fire a PropertyChangeEvent containing the old and new values of the - * property to all the global listeners, and to all the listeners for the - * specified property name. This does nothing if old and new are equal. - * If the change is vetoed, a new event is fired to notify listeners about - * the rollback before the exception is thrown. - * - * @param propertyName the name of the property that changed - * @param oldVal the old value - * @param newVal the new value - * @throws PropertyVetoException if the change is vetoed by a listener - */ - public void fireVetoableChange(String propertyName, - boolean oldVal, boolean newVal) - throws PropertyVetoException - { - if (oldVal != newVal) - fireVetoableChange(new PropertyChangeEvent(source, propertyName, - Boolean.valueOf(oldVal), - Boolean.valueOf(newVal))); - } - - /** - * Fire a PropertyChangeEvent to all the global listeners, and to all the - * listeners for the specified property name. This does nothing if old and - * new values of the event are equal. If the change is vetoed, a new event - * is fired to notify listeners about the rollback before the exception is - * thrown. - * - * @param event the event to fire - * @throws NullPointerException if event is null - * @throws PropertyVetoException if the change is vetoed by a listener - */ - public void fireVetoableChange(PropertyChangeEvent event) - throws PropertyVetoException - { - if (event.oldValue != null && event.oldValue.equals(event.newValue)) - return; - Vector v = listeners; // Be thread-safe. - if (v != null) - { - int i = v.size(); - try - { - while (--i >= 0) - ((VetoableChangeListener) v.get(i)).vetoableChange(event); - } - catch (PropertyVetoException e) - { - event = event.rollback(); - int limit = i; - i = v.size(); - while (--i >= limit) - ((VetoableChangeListener) v.get(i)).vetoableChange(event); - throw e; - } - } - Hashtable h = children; // Be thread-safe. - if (h != null && event.propertyName != null) - { - VetoableChangeSupport s - = (VetoableChangeSupport) h.get(event.propertyName); - if (s != null) - { - Vector v1 = s.listeners; // Be thread-safe. - int i = v1 == null ? 0 : v1.size(); - try - { - while (--i >= 0) - ((VetoableChangeListener) v1.get(i)).vetoableChange(event); - } - catch (PropertyVetoException e) - { - event = event.rollback(); - int limit = i; - i = v.size(); - while (--i >= 0) - ((VetoableChangeListener) v.get(i)).vetoableChange(event); - i = v1.size(); - while (--i >= limit) - ((VetoableChangeListener) v1.get(i)).vetoableChange(event); - throw e; - } - } - } - } - - /** - * Tell whether the specified property is being listened on or not. This - * will only return <code>true</code> if there are listeners on all - * properties or if there is a listener specifically on this property. - * - * @param propertyName the property that may be listened on - * @return whether the property is being listened on - * @throws NullPointerException if propertyName is null - */ - public synchronized boolean hasListeners(String propertyName) - { - return listeners != null || (children != null - && children.get(propertyName) != null); - } - - /** - * Saves the state of the object to the stream. - * - * @param s the stream to write to - * @throws IOException if anything goes wrong - * @serialData this writes out a null-terminated list of serializable - * global vetoable change listeners (the listeners for a named - * property are written out as the global listeners of the - * children, when the children hashtable is saved) - */ - private synchronized void writeObject(ObjectOutputStream s) - throws IOException - { - s.defaultWriteObject(); - if (listeners != null) - { - int i = listeners.size(); - while (--i >= 0) - if (listeners.get(i) instanceof Serializable) - s.writeObject(listeners.get(i)); - } - s.writeObject(null); - } - - /** - * Reads the object back from stream (deserialization). - * - * XXX Since serialization for 1.1 streams was not documented, this may - * not work if vetoableChangeSupportSerializedDataVersion is 1. - * - * @param s the stream to read from - * @throws IOException if reading the stream fails - * @throws ClassNotFoundException if deserialization fails - * @serialData this reads in a null-terminated list of serializable - * global vetoable change listeners (the listeners for a named - * property are written out as the global listeners of the - * children, when the children hashtable is saved) - */ - private void readObject(ObjectInputStream s) - throws IOException, ClassNotFoundException - { - s.defaultReadObject(); - VetoableChangeListener l = (VetoableChangeListener) s.readObject(); - while (l != null) - { - addVetoableChangeListener(l); - l = (VetoableChangeListener) s.readObject(); - } - // Sun is not as careful with children as we are, and lets some proxys - // in that can never receive events. So, we clean up anything that got - // serialized, to make sure our invariants hold. - if (children != null) - { - int i = children.size(); - Iterator iter = children.entrySet().iterator(); - while (--i >= 0) - { - Entry e = (Entry) iter.next(); - String name = (String) e.getKey(); - VetoableChangeSupport vcs = (VetoableChangeSupport) e.getValue(); - if (vcs.listeners == null) - vcs.listeners = new Vector(); - if (vcs.children != null) - vcs.listeners.addAll - (Arrays.asList(vcs.getVetoableChangeListeners(name))); - if (vcs.listeners.size() == 0) - iter.remove(); - else - vcs.children = null; - } - if (children.size() == 0) - children = null; - } - } -} // class VetoableChangeSupport diff --git a/libjava/java/beans/Visibility.java b/libjava/java/beans/Visibility.java deleted file mode 100644 index 428f3a2073b..00000000000 --- a/libjava/java/beans/Visibility.java +++ /dev/null @@ -1,85 +0,0 @@ -/* java.beans.Visibility - Copyright (C) 1998, 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.beans; - -/** - * Visibility is an interface a Bean may implement so that the environment - * can tell the Bean whether there is a GUI or not, and so that the Bean - * can tell the environment whether it needs one or can run without one. - * <P> - * - * Sun decided not to use standard Introspection patterns so that these - * methods did not get included when the Introspector made its sweep on - * the class. - * - * @author John Keiser - * @since JDK1.1 - * @version 1.1.0, 29 Jul 1998 - */ - -public interface Visibility { - /** - * Tells whether the Bean can run without a GUI or not. - * @return false if Bean can run without a GUI, else true. - */ - boolean needsGui(); - - /** - * Tells whether Bean is trying not to use the GUI. - * If needsGui() is true, this method should always return false. - * @return true if definitely not using GUI, otherwise false. - */ - boolean avoidingGui(); - - /** - * Tells the Bean not to use GUI methods. - * If needsGUI() is false, then after this method is called, - * avoidingGui() should return true. - */ - void dontUseGui(); - - /** - * Tells the Bean it may use the GUI. - * The Bean is not required to use the GUI in this case, it is - * merely being <EM>permitted</EM> to use it. If needsGui() is - * false, avoidingGui() may return true or false after this method - * is called. - */ - void okToUseGui(); -} diff --git a/libjava/java/beans/XMLDecoder.java b/libjava/java/beans/XMLDecoder.java deleted file mode 100644 index 238fd6bed91..00000000000 --- a/libjava/java/beans/XMLDecoder.java +++ /dev/null @@ -1,307 +0,0 @@ -/* java.beans.XMLDecoder -- - Copyright (C) 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.beans; - -import gnu.java.beans.decoder.DefaultExceptionListener; -import gnu.java.beans.decoder.PersistenceParser; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Iterator; -import java.util.NoSuchElementException; - -/** - * The XMLDecoder reads XML data that is structured according to - * <a href="http://java.sun.com/products/jfc/tsc/articles/persistence3/javabeans.dtd">this</a> DTD - * and creates objects according to the content. Usually such data is generated using the - * {@link XMLEncoder} class. - * <p> - * An example XML document might look like this: - * <code> - * <java> - * <string>Hello World</string> - * <int>200</int> - * </java> - * </code> - * <p>To read the <code>String</code> and the <code>Integer</code> instance the following can be used (assume - * the XML data can be obtained from the InputStream):</p> - * <code> - * XMLDecoder decoder = new XMLDecoder(inputStreamContainingXMLData); - * String message = (String) decoder.readObject(); - * Integer number = (Integer) decoder.readObject(); - * </code> - * <p>Besides this basic functionality the <code>XMLDecoder</code> has some more features that might come - * handy in certain situations:</p> - * <p>An owner object can be set using the <code>setOwner</code> method which can then be accessed when - * decoding. This feature is only useful if the XML data is aware of the owner object. Such data may - * look like this (assume that the owner object is a JFrame instance):</p> - * <code> - * <java> - * <void method="getOwner"> - * <void method="setVisible"> - * <boolean>true<boolean> - * </void> - * </void> - * </java> - * </code> - * This accesses the <code>JFrame</code> and makes it visible using the <code>setVisible</code> method. - * <p>Please note that changing the owner <b>after</b> the having read the first object has no effect, - * because all object have been decoded then.</p> - * <p>If the <code>XMLDecoder</code> is created with no {@link ExceptionListener} instance a default one - * is used that prints an error message to <code>System.err</code> whenever a recoverable exception - * is thrown. Recovarable exceptions occur when the XML data cannot be interpreted correctly (e.g - * unknown classes or methods, invocation on null, ...). In general be very careful when the - * <code>XMLDecoder</code> provoked such exceptions because the resulting object(s) may be in an - * undesirable state.</p> - * <p>Note that changing the ExceptionListener instance after <code>readObject</code> has been called - * once has no effect because the decoding is completed then.</p> - * <p>At last one can provide a specific <code>ClassLoader</code> which is then used when <code>Class</code> - * objects are accessed. See {@link java.lang.Class#forName(String, boolean, ClassLoader)} for details - * on this.</p> - * <p>Note: If the <code>InputStream</code> instance given to any of the constructors is <code>null</code> - * the resulting <code>XMLDecoder</code> will be silently (without any exception) useless. Each call - * to <code>readObject</code> will return <code>null</code> and never throws an - * <code>ArrayIndexOutOfBoundsException</code>.</p> - * - * @author Robert Schuster - * @since 1.4 - * @status updated to 1.5 - */ -public class XMLDecoder -{ - private Object owner; - - private ExceptionListener exceptionListener; - - private InputStream inputStream; - - private boolean isStreamClosed; - - private ClassLoader classLoader; - - private Iterator iterator; - - /** Creates a XMLDecoder instance that parses the XML data of the given input stream. - * Using this constructor no special ClassLoader, a default ExceptionListener - * and no owner object is used. - * - * @param in InputStream to read XML data from. - */ - public XMLDecoder(InputStream in) - { - this(in, null); - } - - /** Creates a XMLDecoder instance that parses the XML data of the given input stream. - * Using this constructor no special ClassLoader and a default ExceptionListener - * is used. - * - * @param in InputStream to read XML data from. - * @param owner Owner object which can be accessed and modified while parsing. - */ - public XMLDecoder(InputStream in, Object owner) - { - this(in, owner, null); - } - - /** Creates a XMLDecoder instance that parses the XML data of the given input stream. - * If the ExceptionListener argument is null a default implementation is used. - * - * @param in InputStream to read XML data from. - * @param owner Owner object which can be accessed and modified while parsing. - * @param exceptionListener ExceptionListener instance to which exception notifications are send. - */ - public XMLDecoder( - InputStream in, - Object owner, - ExceptionListener exceptionListener) - { - this( - in, - owner, - exceptionListener, - Thread.currentThread().getContextClassLoader()); - } - - /** Creates a XMLDecoder instance that parses the XML data of the given input stream. - * If the ExceptionListener argument is null a default implementation is used. - * - * @param in InputStream to read XML data from. - * @param owner Owner object which can be accessed and modified while parsing. - * @param exceptionListener ExceptionListener instance to which exception notifications are send. - * @param cl ClassLoader instance that is used for calls to <code>Class.forName(String, boolean, ClassLoader)</code> - * @since 1.5 - */ - public XMLDecoder( - InputStream in, - Object owner, - ExceptionListener listener, - ClassLoader cl) - { - // initially here was a check for the validity of the InputStream argument but some - // great engineers decided that this API should silently discard this and behave rather - // odd: readObject will always return null ... - inputStream = in; - - setExceptionListener(listener); - - // validity of this object is checked in Class.forName() and therefore may be null - classLoader = cl; - - this.owner = owner; - } - - /** Closes the stream associated with this decoder. This should be done after having read all - * decoded objects. - * <p>See the description of the {@link #readObject()} for the effect caused by <code>close</code>.</p> - */ - public void close() - { - if (isStreamClosed) - { - return; - } - - try - { - inputStream.close(); - isStreamClosed = true; - } - catch (IOException e) - { - // bad style forced by original API design ... - } - } - - /** Returns the ExceptionListener instance associated with this decoder. - * <p>See the description of {@link XMLDecoder} class for more information on the ExceptionListener.</p> - * - * @return Current ExceptionListener of the decoder. - */ - public ExceptionListener getExceptionListener() - { - return exceptionListener; - } - - /** Returns the owner object of the decoder. This method is usually called - * from within the parsed XML data. - * <p>See the description of {@link XMLDecoder} class for more information on the owner object.</p> - * - * @return The owner object of this decoder. - */ - public Object getOwner() - { - return owner; - } - - /** Returns the next available decoded object. - * <p>Note that the actual decoding takes place when the method is called for the first time.</p> - * <p>If the <code>close</code> method was already called a <code>NoSuchElementException</code> - * is thrown.</p> - * <p>If the InputStream instance used in the constructors was <code>null</code> this method - * will always return <code>null</code> itself.</p> - * - * @return The next object in a sequence decoded from XML data. - * @throws ArrayIndexOutOfBoundsException When no more objects are available. - */ - public Object readObject() throws ArrayIndexOutOfBoundsException - { - // note: the RI does it this way ... - if(inputStream == null) { - return null; - } - - // note: the original API documentation says nothing on what to do - // when the stream was closed before readObject is called but it actually - // throws a NoSuchElementException - this behaviour is imitated here - if (isStreamClosed) - { - throw new NoSuchElementException("Cannot read any objects - XMLDecoder was already closed."); - } - - // creates the PersistenceParser (doing the parsing and decoding) and returns its - // Iterator on first invocation - if (iterator == null) - { - iterator = - new PersistenceParser( - inputStream, - exceptionListener, - classLoader, - this) - .iterator(); - } - - // note: done according to the official documentation - if (!iterator.hasNext()) - { - throw new ArrayIndexOutOfBoundsException("No more objects available from this XMLDecoder."); - } - - // returns just the next object if there was no problem - return iterator.next(); - } - - /** Sets the ExceptionListener instance to which notifications of exceptions are send - * while parsing the XML data. - * <p>See the description of {@link XMLDecoder} class for more information on the ExceptionListener.</p> - * - * @param listener - */ - public void setExceptionListener(ExceptionListener listener) - { - // uses a default implementation when null - if (listener == null) - { - listener = new DefaultExceptionListener(); - } - exceptionListener = listener; - } - - /** Sets the owner object which can be accessed from the parsed XML data. - * <p>See the description of {@link XMLDecoder} class for more information on the owner object.</p> - * - * @param newOwner - */ - public void setOwner(Object newOwner) - { - owner = newOwner; - } - -} diff --git a/libjava/java/beans/beancontext/BeanContext.java b/libjava/java/beans/beancontext/BeanContext.java deleted file mode 100644 index 3d1be7fc8e9..00000000000 --- a/libjava/java/beans/beancontext/BeanContext.java +++ /dev/null @@ -1,272 +0,0 @@ -/* java.beans.beancontext.BeanContext - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.beans.beancontext; - -import java.beans.DesignMode; -import java.beans.Visibility; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.util.Collection; - -/** - * Acts as a container for sub-beans and as a sub-bean, - * so that an entire hierarchy of beans can be made up of - * <code>BeanContext</code>s. - * <P> - * - * Since I can't sprinkle the <code>Collections</code> interface - * documentation with special information for <code>BeanContext</code> - * implementors, I'll have to document special requirements for - * implementors of those functions here. - * <P> - * - * <code><strong>add()</strong></code> or <code>addAll()</code>: - * <br> - * <OL> - * <LI> - * May add any <code>Object</code> into the hierarchy as well as a - * <code>BeanContextChild</code>, <code>BeanContext</code> or - * <code>BeanContextProxy</code> object. - * This way, any Bean can be in the hierarchy. - * </LI> - * <LI> - * Must synchronize on <code>BeanContext.globalHierarchyLock</code>. - * </LI> - * <LI> - * Don't add the <code>Object</code> if it's already there (only once - * per <code>BeanContext</code>). - * </LI> - * <LI> - * If it is a <code>BeanContextChild</code> implementor, call - * <code>setBeanContext()</code> on it. If it's a - * <code>BeanContextProxy</code> implementor, call - * <code>getBeanContextProxy().setBeanContext()</code> on it. - * If <code>setBeanContext()</code> vetoes the change, back out - * all changes so far and throw <code>IllegalStateException</code>. - * </LI> - * <LI> - * If it (or its proxy) implements <code>Visibility</code>, call - * <code>dontUseGui()</code> or <code>okToUseGui()</code> on it, - * depending on whether you (the <code>BeanContext</code>) feel like - * allowing it to use the GUI or not. - * </LI> - * <LI> - * If it implements <code>BeanContextChild</code> or - * <code>BeanContextProxy</code>, register yourself (the - * <code>BeanContext</code>) as both a - * <code>PropertyChangeListener</code> and - * <code>VetoableChangeListener</code> on the "beanContext" - * property (it may also add itself on any other properties it wishes - * to). - * </LI> - * <LI> - * If it is a listener or event source that you (the - * <code>BeanContext</code>) are interested in, you may register - * yourself to it or register it to you. - * </LI> - * <LI> - * Fire a <code>java.beans.beancontext.BeanContextMembershipEvent</code> - * before exiting. <code>addAll()</code> should wait until everything - * is done changing before firing the event (or events) so that if a - * failure occurs, the backing-out process can proceed without any - * events being fired at all. - * </LI> - * </OL> - * <P> - * - * <code><strong>remove()</strong></code> or <code>removeAll()</code>: - * <br> - * <OL> - * <LI> - * Must synchronize on <code>BeanContext.globalHierarchyLock</code>. - * </LI> - * <LI> - * If the specified <code>Object</code> is not a child of this - * <code>BeanContext</code>, just exit without performing any actions. - * </LI> - * <LI> - * Remove the <code>Object</code> from your collection of children. - * </LI> - * <LI> - * If it is a <code>BeanContextChild</code> implementor, call - * <code>setBeanContext(null)</code> on it. If it's a - * <code>BeanContextProxy</code> implementor, call - * <code>getBeanContextProxy().setBeanContext(null)</code> on it. - * If <code>setBeanContext()</code> vetoes the change, back out - * all changes so far and throw <code>IllegalStateException</code>. - * </LI> - * <LI> - * If you registered the <code>Object</code> to listen to you or - * registered yourself as a listener on the <code>Object</code> during - * <code>add()</code> or <code>addAll()</code>, undo the registration - * bycalling the appropriate <code>removeListener()</code> method. - * </LI> - * <LI> - * Fire a <code>java.beans.beancontext.BeanContextMembershipEvent</code> - * before exiting. <code>removeAll()</code> should wait until - * everything is done changing before firing the event (or events) so - * that if a failure occurs, the backing-out process can proceed - * without any events being fired at all. - * </LI> - * </OL> - * <P> - * - * <code>addAll()</code>, <code>removeAll()</code>, - * <code>retainAll()</code> and <code>clear()</code> do not need to be - * implemented, but may be if so desired. - * <P> - * - * Similarly, <code>Visibility</code> and <code>DesignMode</code> methods - * should propagate changed values to children that implement interfaces - * of the same name. - * <P> - * - * A hierarchy of beans is mainly useful so that different sets of beans - * can be established, each with their own set of resources. - * - * @author John Keiser - * @since JDK1.2 - */ - -public interface BeanContext - extends Collection, BeanContextChild, Visibility, DesignMode { - - /** - * The global lock on changing any BeanContext hierarchy. - * It kinda sucks that there is only one lock, since there can be - * multiple hierarchies. Oh well, I didn't design, I just code. - * <P> - * - * Methods that must (or do) synchronize on the global lock: - * <BR> - * <UL> - * <LI> - * Implementors of <CODE>BeanContext.add()</CODE> and <code>addAll()</code> - * </LI> - * </UL> - * @fixme fill in the rest of the methods which use the global lock. - */ - Object globalHierarchyLock = new Object(); - - /** - * Instantiate a Bean using this Bean's <code>ClassLoader</code> - * and this <code>BeanContext</code> as the parent. - * <P> - * - * This method exists mainly so that <code>BeanContext</code> - * implementations can perform extra actions on Beans that are - * created within them. - * - * @param beanName the name of the bean to instantiate - * @return the created Bean - * - * @see java.beans.Beans#instantiate(java.lang.ClassLoader,java.lang.String) - * @see java.beans.Beans#instantiate(java.lang.ClassLoader,java.lang.String,java.lang.BeanContext) - * @exception IOException if there is an I/O problem during - * instantiation. - * @exception ClassNotFoundException if a serialized Bean's class - * is not found. - */ - Object instantiateChild(String beanName) - throws IOException, - ClassNotFoundException; - - /** - * Get a resource. The <code>BeanContext</code> will typically - * call <code>ClassLoader.getResource()</code>, but may do it any - * way it wants to. This allows a <code>BeanContext</code> to - * have its own set of resources separate from the rest of the - * system. - * <P> - * - * Beans should call this method on their parent rather than the - * associated <code>ClassLoader</code> method. - * <P> - * - * I am assuming, but am not entirely sure, that if a - * <code>BeanContext</code> cannot find a resource, its - * responsibility is to call the <code>getResource</code> method - * of its parent <code>BeanContext</code>. - * - * @return a URL to the requested resource. - * @param resourceName the name of the resource requested. - * @param requestor a reference to the child requesting the resource. - * @see java.lang.ClassLoader#getResource(java.lang.String) - */ - URL getResource(String resourceName, BeanContextChild requestor); - - /** - * Get a resource as a stream. The <code>BeanContext</code> will - * typically call <code>ClassLoader.getResourceAsStream()</code>, - * but may do it any way it wants to. This allows a - * <code>BeanContext</code>'s children to have their own set of - * resources separate from the rest of the system. - * <P> - * - * Beans should call this method on their parent rather than the - * associated <code>ClassLoader</code> method. - * <P> - * - * I am assuming, but am not entirely sure, that if a - * <code>BeanContext</code> cannot find a resource, its - * responsibility is to call the <code>getResourceAsStream</code> - * method of its parent <code>BeanContext</code>. - * - * @return the requested resource as a stream. - * @param resourceName the name of the resource requested. - * @param requestor a reference to the child requesting the resource. - * @see java.lang.ClassLoader#getResourceAsStream(java.lang.String) - */ - InputStream getResourceAsStream(String resourceName, BeanContextChild requestor); - - /** - * Add a listener on changes to the membership of this - * <code>BeanContext</code> object. - * @param listener the listener to add. - */ - void addBeanContextMembershipListener(BeanContextMembershipListener listener); - - /** - * Remove a listener on changes to the membership of this - * <code>BeanContext</code> object. - * @param listener the listener to remove. - */ - void removeBeanContextMembershipListener(BeanContextMembershipListener listener); -} diff --git a/libjava/java/beans/beancontext/BeanContextChild.java b/libjava/java/beans/beancontext/BeanContextChild.java deleted file mode 100644 index d1115efac85..00000000000 --- a/libjava/java/beans/beancontext/BeanContextChild.java +++ /dev/null @@ -1,174 +0,0 @@ -/* java.beans.beancontext.BeanContextChild - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.beans.beancontext; - -import java.beans.PropertyChangeListener; -import java.beans.PropertyVetoException; -import java.beans.VetoableChangeListener; - -/** - * Beans implement this to get information about the execution environment and - * its services and to be placed in the hierarchy. - * <P> - * - * The difference between a <code>BeanContext</code> and a - * <code>BeanContextChild</code>, mainly, is that a - * <code>BeanContext</code> may be a parent. - * <P> - * - * <code>BeanContextChild</code> instances will be serialized at some - * point in their life, but you need to make sure your bean context does - * not contain a serializable reference (directly or indirectly) to the - * parent <code>BeanContext</code>, to any of the other - * <code>BeanContext</code>s in the tree, or to any resources obtained - * via the <code>BeanContextServices</code> interface. One way to do this - * is to mark any fields that contain such references as - * <code>transient</code>. Another way is to use a custom serializer. - * <P> - * - * If you do not do this, when the <code>BeanContext</code> is serialized, - * all the other <code>BeanContext</code>s and other unnecessary things - * will be serialized along with it. - * <P> - * - * Before dying, a <code>BeanContextChild</code> should call - * <code>getBeanContext().remove(this)</code> to detach from the - * hierarchy and exit cleanly. - * - * @author John Keiser - * @since JDK1.2 - * @see java.beans.beancontext.BeanContext - */ - -public interface BeanContextChild { - /** - * Set the parent <code>BeanContext</code>. - * <P> - * - * This method is called from <code>BeanContext.add()</code> and - * should not be called directly. - * <P> - * - * When this Object is being added to a new BeanContext or moved - * from an old one, a non-null value will be passed in. - * <P> - * - * When this Object is being removed from the current - * <code>BeanContext</code>, <code>setBeanContext()</code> will - * receive the parameter <code>null</code>. - * <P> - * - * When being removed from the current <code>BeanContext</code>, - * it is the <code>BeanContextChild</code>'s responsibility to - * release all services it has obtained. - * <P> - * - * This change should generate <code>PropertyChangeEvent</code> - * and <code>VetoableChangeEvent</code>s with the property name - * "beanContext". If the change is vetoed, it must re-throw the - * exception and not change anything. In this way, the parent - * <code>BeanContextChild</code>, who has registered himself with - * you, will have a chance to remove this child from its - * collection. - * <P> - * - * If the Bean does not wish to change the parent or be removed - * from one, it may throw the <code>PropertyVetoException</code>. - * If you veto a <code>setBeanContext(null)</code> call, then you - * should try your hardest to remedy whatever problem is keeping - * you from being removed from the <code>BeanContext</code> so - * that you can <em>not</em> veto it the next time. - * Otherwise, nasty pathological recursion stuff could occur in - * certain situations. - * <P> - * - * If you do veto the change, you must first back out any changes - * you made prior to the veto. Best not to make any such changes - * prior to the veto in the first place. - * <P> - * - * This method is called from <code>BeanContext.add()</code> and - * should not be called directly. - * - * @param parent the new parent for the <code>BeanContextChild</code>, - * or <code>null</code> to signify removal from a tree. - * @exception PropertyVetoException if the - * <code>BeanContextChild</code> implementor does not - * wish to have its parent changed. - */ - void setBeanContext(BeanContext parent) - throws PropertyVetoException; - - /** - * Get the parent <code>BeanContext</code>. - * @return the parent <code>BeanContext</code>. - */ - BeanContext getBeanContext(); - - /** - * Add a listener that will be notified when a specific property changes. - * @param prop the name of the property to listen on - * @param listener the listener to listen on the property. - */ - void addPropertyChangeListener(String prop, PropertyChangeListener listener); - - /** - * Remove a listener to a certain property. - * @param prop the name of the property being listened on - * @param listener the listener listening on the property. - */ - void removePropertyChangeListener(String prop, PropertyChangeListener listener); - - /** - * Add a listener that will be notified when a specific property - * change is requested (a PropertyVetoException may be thrown) as - * well as after the change is successfully made. - * - * @param prop the name of the property to listen on - * @param listener the listener to listen on the property. - */ - void addVetoableChangeListener(String prop, VetoableChangeListener listener); - - /** - * Remove a listener to a certain property. - * @param prop the name of the property being listened on - * @param listener the listener listening on the property. - */ - void removeVetoableChangeListener(String prop, VetoableChangeListener listener); -} diff --git a/libjava/java/beans/beancontext/BeanContextChildComponentProxy.java b/libjava/java/beans/beancontext/BeanContextChildComponentProxy.java deleted file mode 100644 index a8d6e34045e..00000000000 --- a/libjava/java/beans/beancontext/BeanContextChildComponentProxy.java +++ /dev/null @@ -1,60 +0,0 @@ -/* java.beans.beancontext.BeanContextChildComponentProxy - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.beans.beancontext; - -import java.awt.Component; - -/** - * Interface for <code>BeanContextChild</code>s which wish to associate an - * AWT component with them. The proxy is provided because the - * <code>addPropertyChangeListener()</code> method would conflict with - * <code>Component</code> if you tried to extend. - * - * @author John Keiser - * @since JDK1.2 - */ - -public interface BeanContextChildComponentProxy { - /** - * Get the <code>Component</code> associated with this <code>BeanContextChild</code>. - * @return the <code>Component</code> associated with this - * <code>BeanContextChild</code>. - */ - Component getComponent(); -} diff --git a/libjava/java/beans/beancontext/BeanContextChildSupport.java b/libjava/java/beans/beancontext/BeanContextChildSupport.java deleted file mode 100644 index 4444ad71377..00000000000 --- a/libjava/java/beans/beancontext/BeanContextChildSupport.java +++ /dev/null @@ -1,381 +0,0 @@ -/* java.beans.beancontext.BeanContextChildSupport - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.beans.beancontext; - -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; -import java.beans.PropertyVetoException; -import java.beans.VetoableChangeListener; -import java.beans.VetoableChangeSupport; -import java.io.Serializable; - -/** - * Support for creating a <code>BeanContextChild</code>. - * This class contains the most common implementations of the methods in - * the <code>BeanContextChild</code> - * - * @specnote This class is not very well specified. I had to "fill in the - * blanks" in most places with what I thought was reasonable - * behavior. If there are problems, let me know. - * - * @author John Keiser - * @since 1.2 - * @see java.beans.beancontext.BeanContextChild - */ -public class BeanContextChildSupport - implements BeanContextChild, BeanContextServicesListener, Serializable -{ - static final long serialVersionUID = 6328947014421475877L; - - /** - * The peer on which to perform <code>set</code> actions. - * This is here so that this class can be used as a peer. - * <P> - * - * When extending this class, this variable will be set to - * <code>this</code>. - */ - public BeanContextChild beanContextChildPeer; - - /** - * The parent <code>BeanContext</code>. - */ - protected transient BeanContext beanContext; - - /** - * If <code>setBeanContext()</code> was vetoed once before, this - * is set to <code>true</code> so that the next time, vetoes will - * be ignored. - */ - protected transient boolean rejectedSetBCOnce; - - /** - * Listeners are registered here and events are fired through here. - */ - protected PropertyChangeSupport pcSupport; - - /** - * Listeners are registered here and events are fired through here. - */ - protected VetoableChangeSupport vcSupport; - - /** - * Create a new <code>BeanContextChildSupport</code> with itself as the peer. - * This is meant to be used when you subclass - * <code>BeanContextChildSupport</code> to create your child. - */ - public BeanContextChildSupport() - { - this (null); - } - - /** - * Create a new <code>BeanContextChildSupport</code> with the specified peer. - * @param peer the peer to use, or <code>null</code> to specify - * <code>this</code>. - */ - public BeanContextChildSupport (BeanContextChild peer) - { - if (peer == null) - { - peer = this; - } - - beanContextChildPeer = peer; - pcSupport = new PropertyChangeSupport (peer); - vcSupport = new VetoableChangeSupport (peer); - } - - /** - * Set the parent <code>BeanContext</code>. - * <P> - * - * When this Object is being added to a new BeanContext or moved - * from an old one, a non-null value will be passed in. - * <P> - * - * When this Object is being removed from the current - * <code>BeanContext</code>, <code>setBeanContext()</code> will - * receive the parameter <code>null</code>. - * <P> - * - * Order of events: - * <OL> - * <LI> - * If the new <code>BeanContext</code> is the same as the old - * one, nothing happens. - * </LI> - * <LI> - * If the change has not been rejected or vetoed before, call - * <code>validatePendingSetBeanContext()</code>. If this call - * returns <code>false</code>, the change is rejected and a - * <code>PropertyVetoException</code> is thrown. - * </LI> - * <LI> - * If the change has not been rejected or vetoed before, - * <code>VetoableChangeEvent</code>s are fired with the name - * <code>"beanContext"</code>, using the - * <code>fireVetoableChange()</code> method. If a veto - * occurs, reversion events are fired using the same method, - * the change is rejected, and the veto is rethrown. - * </LI> - * <LI> - * <code>releaseBeanContextResources()</code> is called. - * </LI> - * <LI> - * The change is made. - * </LI> - * <LI> - * <code>PropertyChangeEvent</code>s are fired using the - * <code>firePropertyChange()</code> method. - * </LI> - * <LI> - * <code>initializeBeanContextResources()</code> is called. - * </LI> - * </OL> - * <P> - * - * @param newBeanContext the new parent for the - * <code>BeanContextChild</code>, or <code>null</code> to - * signify removal from a tree. - * @exception PropertyVetoException if the - * <code>BeanContextChild</code> implementor does not - * wish to have its parent changed. - */ - public void setBeanContext(BeanContext newBeanContext) - throws PropertyVetoException - { - synchronized (beanContextChildPeer) - { - if (newBeanContext == beanContext) - return; - - if (!rejectedSetBCOnce) - { - if (!validatePendingSetBeanContext (newBeanContext)) - { - rejectedSetBCOnce = true; - throw new PropertyVetoException ("validatePendingSetBeanContext() rejected change", - new PropertyChangeEvent(beanContextChildPeer, "beanContext", beanContext, newBeanContext)); - } - - try - { - fireVetoableChange ("beanContext", beanContext, newBeanContext); - } - catch (PropertyVetoException e) - { - rejectedSetBCOnce = true; - throw e; - } - } - - releaseBeanContextResources (); - - beanContext = newBeanContext; - rejectedSetBCOnce = false; - - firePropertyChange ("beanContext", beanContext, newBeanContext); - - initializeBeanContextResources (); - } - } - - /** - * Get the parent <code>BeanContext</code>. - * @return the parent <code>BeanContext</code>. - */ - public BeanContext getBeanContext() - { - return beanContext; - } - - /** - * Get the peer (or <code>this</code> if there is no peer). - * @return the peer, or <code>this</code> if there is no peer. - */ - public BeanContextChild getBeanContextChildPeer() { - return beanContextChildPeer; - } - - /** - * Determine whether there is a peer. - * This is true iff <code>getBeanContextChildPeer() == this</code>. - * @return whether there is a peer. - */ - public boolean isDelegated() { - return beanContextChildPeer == this; - } - - /** - * Add a listener that will be notified when a specific property changes. - * @param propertyName the name of the property to listen on. - * @param listener the listener to listen on the property. - */ - public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) { - pcSupport.addPropertyChangeListener(propertyName, listener); - } - - /** - * Remove a listener to a certain property. - * - * @param propertyName the name of the property being listened on. - * @param listener the listener listening on the property. - */ - public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) { - pcSupport.removePropertyChangeListener(propertyName, listener); - } - - /** - * Add a listener that will be notified when a specific property - * change is requested (a PropertyVetoException may be thrown) as - * well as after the change is successfully made. - * - * @param propertyName the name of the property to listen on. - * @param listener the listener to listen on the property. - */ - public void addVetoableChangeListener(String propertyName, VetoableChangeListener listener) { - vcSupport.addVetoableChangeListener(propertyName, listener); - } - - /** - * Remove a listener to a certain property. - * - * @param propertyName the name of the property being listened on - * @param listener the listener listening on the property. - */ - public void removeVetoableChangeListener(String propertyName, VetoableChangeListener listener) { - vcSupport.removeVetoableChangeListener(propertyName, listener); - } - - /** - * Fire a property change. - * - * @param propertyName the name of the property that changed - * @param oldVal the old value of the property - * @param newVal the new value of the property - */ - public void firePropertyChange(String propertyName, Object oldVal, Object newVal) { - pcSupport.firePropertyChange(propertyName, oldVal, newVal); - } - - /** - * Fire a vetoable property change. - * - * @param propertyName the name of the property that changed - * @param oldVal the old value of the property - * @param newVal the new value of the property - * @exception PropertyVetoException if the change is vetoed. - */ - public void fireVetoableChange(String propertyName, Object oldVal, Object newVal) - throws PropertyVetoException { - vcSupport.fireVetoableChange(propertyName, oldVal, newVal); - } - - /** - * Called by <code>BeanContextServices.revokeService()</code> to indicate that a service has been revoked. - * If you have a reference to such a service, it should be - * discarded and may no longer function properly. - * <code>getService()</code> will no longer work on the specified - * service class after this event has been fired. - * <P> - * - * <EM>This method is meant to be overriden.</EM> - * <code>BeanContextChildSupport</code>'s implementation does - * nothing. - * - * @param event the service revoked event. - * @see java.beans.beancontext.BeanContextServices#revokeService(java.lang.Class,java.beans.beancontext.BeanContextServiceProvider,boolean) - */ - public void serviceRevoked(BeanContextServiceRevokedEvent event) { - } - - /** - * Called by <code>BeanContextServices</code> whenever a service is made available. - * <P> - * - * <EM>This method is meant to be overriden.</EM> - * <code>BeanContextChildSupport</code>'s implementation does - * nothing. - * - * @param event the service revoked event, with useful information - * about the new service. - */ - public void serviceAvailable(BeanContextServiceAvailableEvent event) { - } - - /** - * Called by <code>setBeanContext()</code> to determine whether the set should be rejected. - * <P> - * - * <EM>This method is meant to be overriden.</EM> - * <code>BeanContextChildSupport</code>'s implementation simply - * returns <code>true</code>. - * - * @param newBeanContext the new parent. - * @return whether to allow the parent to be changed to the new - * value. - */ - public boolean validatePendingSetBeanContext(BeanContext newBeanContext) { - return true; - } - - /** - * Called by <code>setBeanContext()</code> to release resources of a what will soon no longer be the parent. - * <P> - * - * <EM>This method is meant to be overriden.</EM> - * <code>BeanContextChildSupport</code>'s implementation does - * nothing. - */ - protected void releaseBeanContextResources() { - } - - /** - * Called by <code>setBeanContext()</code> to grab resources when the parent has been set. - * <P> - * - * <EM>This method is meant to be overriden.</EM> - * <code>BeanContextChildSupport</code>'s implementation does - * nothing. - */ - protected void initializeBeanContextResources() { - } -} diff --git a/libjava/java/beans/beancontext/BeanContextContainerProxy.java b/libjava/java/beans/beancontext/BeanContextContainerProxy.java deleted file mode 100644 index 3df91038bfe..00000000000 --- a/libjava/java/beans/beancontext/BeanContextContainerProxy.java +++ /dev/null @@ -1,63 +0,0 @@ -/* java.beans.beancontext.BeanContextContainerProxy - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.beans.beancontext; - -import java.awt.Container; - -/** - * Interface for <code>BeanContext</code>s which wish to associate an - * AWT container with them. The proxy is provided because the - * <code>addPropertyChangeListener()</code> and <code>add()</code> methods - * would conflict with <code>Component</code> and <code>Container</code> - * if you tried to extend. - * - * @specnote It is unclear whether anything besides <code>BeanContext</code>s - * are allowed to implement this interface. - * @author John Keiser - * @since JDK1.2 - */ - -public interface BeanContextContainerProxy { - /** - * Get the <code>Container</code> associated with this <code>BeanContext</code>. - * @return the <code>Container</code> associated with this - * <code>BeanContext</code>. - */ - Container getContainer(); -} diff --git a/libjava/java/beans/beancontext/BeanContextEvent.java b/libjava/java/beans/beancontext/BeanContextEvent.java deleted file mode 100644 index f326541b034..00000000000 --- a/libjava/java/beans/beancontext/BeanContextEvent.java +++ /dev/null @@ -1,110 +0,0 @@ -/* java.beans.beancontext.BeanContextEvent - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.beans.beancontext; - -import java.util.EventObject; - -/** - * Generic superclass for events fired by <code>BeanContext</code>s. - * - * @author John Keiser - * @since 1.2 - */ - -public abstract class BeanContextEvent extends EventObject -{ - private static final long serialVersionUID = 7267998073569045052L; - - /** - * The <code>BeanContext</code> that most recently passed this - * event on. - */ - protected BeanContext propagatedFrom; - - /** - * Create a new event, from the specified <code>BeanContext</code>. - * <code>propagatedFrom</code> will be initialized to - * <code>null</code>. - * - * @param source the source of the event. - */ - protected BeanContextEvent(BeanContext source) - { - super(source); - } - - /** - * Get the <code>BeanContext</code> that originated this event. - * @return the originator of this event. - */ - public BeanContext getBeanContext() - { - return (BeanContext)getSource(); - } - - /** - * Get the most recent propagator of this event. - * If this value is <code>null</code>, you have received the event - * straight from the source. - * - * @return the most recent propagator of this event. - */ - public BeanContext getPropagatedFrom() - { - return propagatedFrom; - } - - /** - * Tell whether this event has been propagated. - * @return <code>true</code> iff <code>getPropagatedFrom() != null</code>. - */ - public boolean isPropagated() - { - return propagatedFrom != null; - } - - /** - * Set the most recent propagator of this event. - * @param propagator the most recent propagator of this event. - */ - public void setPropagatedFrom(BeanContext propagator) - { - propagatedFrom = propagator; - } -} diff --git a/libjava/java/beans/beancontext/BeanContextMembershipEvent.java b/libjava/java/beans/beancontext/BeanContextMembershipEvent.java deleted file mode 100644 index 31765426622..00000000000 --- a/libjava/java/beans/beancontext/BeanContextMembershipEvent.java +++ /dev/null @@ -1,112 +0,0 @@ -/* java.beans.beancontext.BeanContextMembershipEvent - Copyright (C) 1999, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.beans.beancontext; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Iterator; - -/** - * Event fired when children are added to or removed from a <code>BeanContext</code>. - * Whether they were added or removed depends entirely on which method - * of the listener interface was called. - * - * @author John Keiser - * @since 1.2 - * @see java.beans.beancontext.BeanContextMembershipListener - */ -public class BeanContextMembershipEvent extends BeanContextEvent { - /** - * The children that were added or removed. - */ - protected Collection children; - - /** - * Create a new membership event. - * @param context the event source. - * @param children the children added to or removed from the source. - */ - public BeanContextMembershipEvent(BeanContext context, Collection children) { - super(context); - this.children = children; - } - - /** - * Create a new membership event. - * @param context the event source. - * @param children the children added to or removed from the source. - */ - public BeanContextMembershipEvent(BeanContext context, Object[] children) { - super(context); - this.children = Arrays.asList(children); - } - - /** - * The number of children removed or added. - * @return the number of children removed or added. - */ - public int size() { - return children.size(); - } - - /** - * An iterator that will step through all the children. - * @return an iterator over all the children. - */ - public Iterator iterator() { - return children.iterator(); - } - - /** - * An array of the children. - * @return an array of the children. - */ - public Object[] toArray() { - return children.toArray(); - } - - /** - * Tell whether the <code>Object</code> is one of the children added or removed. - * @param child the child to check. - * @return whether the <code>Object</code> is added or removed. - */ - public boolean contains(Object child) { - return children.contains(child); - } -} diff --git a/libjava/java/beans/beancontext/BeanContextMembershipListener.java b/libjava/java/beans/beancontext/BeanContextMembershipListener.java deleted file mode 100644 index d39c36c4b12..00000000000 --- a/libjava/java/beans/beancontext/BeanContextMembershipListener.java +++ /dev/null @@ -1,70 +0,0 @@ -/* java.beans.beancontext.BeanContextMembershipListener - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.beans.beancontext; - -import java.util.EventListener; - -/** - * This is the interface to which <code>BeanContextMembershipEvent</code>s are sent. - * This happens when children are added to or removed from a - * <code>BeanContext</code>. - * - * @author John Keiser - * @since JDK1.2 - */ - -public interface BeanContextMembershipListener extends EventListener { - /** - * When beans are added to a <code>BeanContext</code>, - * this method is called to fire the event. - * - * @param event the event, including which children were added. - * @see java.beans.beancontext.BeanContext#add(java.lang.Object) - */ - void childrenAdded(BeanContextMembershipEvent event); - - /** - * When beans are removed from a <code>BeanContext</code>, - * this method is called to fire the event. - * - * @param event the event, including which children were removed. - * @see java.beans.beancontext.BeanContext#remove(java.lang.Object) - */ - void childrenRemoved(BeanContextMembershipEvent event); -} diff --git a/libjava/java/beans/beancontext/BeanContextProxy.java b/libjava/java/beans/beancontext/BeanContextProxy.java deleted file mode 100644 index 49dd7a77f30..00000000000 --- a/libjava/java/beans/beancontext/BeanContextProxy.java +++ /dev/null @@ -1,65 +0,0 @@ -/* java.beans.beancontext.BeanContextProxy - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.beans.beancontext; - -/** - * Beans that wish to have a <code>BeanContextChild</code> or <code>BeanContext</code> associated with them - * but do not wish to implement those interfaces directly, can implement this interface. - * <P> - * - * Don't shoot yourself in the foot: if you already implement - * <code>BeanContextChild</code>, directly or indirectly, the whole - * workings of this package will be unpredictable because it is - * indeterminate as to whether the <code>BeanContextChild</code> is used - * in preference to its proxy or vice versa. - * - * @author John Keiser - * @since JDK1.2 - */ - -public interface BeanContextProxy { - /** - * Return the <code>BeanContextChild</code> associated with this - * <code>Object</code>. - * - * @return the <code>BeanContextChild</code> associated with this - * <code>Object</code>. - */ - BeanContextChild getBeanContextProxy(); -} diff --git a/libjava/java/beans/beancontext/BeanContextServiceAvailableEvent.java b/libjava/java/beans/beancontext/BeanContextServiceAvailableEvent.java deleted file mode 100644 index eea10f261b6..00000000000 --- a/libjava/java/beans/beancontext/BeanContextServiceAvailableEvent.java +++ /dev/null @@ -1,95 +0,0 @@ -/* java.beans.beancontext.BeanContextServiceAvailableEvent - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.beans.beancontext; - -import java.util.Iterator; - -/** - * Event fired when new services become available through a <code>BeanContextServices</code>. - * - * @author John Keiser - * @since JDK1.2 - * @see java.beans.beancontext.BeanContextServicesListener - */ - -public class BeanContextServiceAvailableEvent extends BeanContextEvent { - /** - * The <code>Class</code> representing the service which is now - * available. - */ - protected Class serviceClass; - - /** - * Create a new service available event. - * @param services the <code>BeanContextServices</code> through - * which the service is available. This is also the source - * of the event. - * @param serviceClass the service class that is now available. - */ - public BeanContextServiceAvailableEvent(BeanContextServices services, Class serviceClass) { - super(services); - this.serviceClass = serviceClass; - } - - /** - * Get the current service selectors of the service class. - * This is identical to <code>getSourceAsBeanContextServices().getCurrentServiceSelectors(getServiceClass())</code> - * @return the current service selectors of the service class. - */ - public Iterator getCurrentServiceSelectors() { - return getSourceAsBeanContextServices().getCurrentServiceSelectors(serviceClass); - } - - /** - * Get the newly available service class. - * @return the service class. - */ - public Class getServiceClass() { - return serviceClass; - } - - /** - * Get the <code>BeanContextServices</code> through which the new service is available. - * @return the <code>BeanContextServices</code> through which the - * new service is available. - */ - public BeanContextServices getSourceAsBeanContextServices() { - return (BeanContextServices)getSource(); - } -} diff --git a/libjava/java/beans/beancontext/BeanContextServiceProvider.java b/libjava/java/beans/beancontext/BeanContextServiceProvider.java deleted file mode 100644 index c09b5815fd7..00000000000 --- a/libjava/java/beans/beancontext/BeanContextServiceProvider.java +++ /dev/null @@ -1,138 +0,0 @@ -/* java.beans.beancontext.BeanContextServiceProvider - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.beans.beancontext; - -import java.util.Iterator; - -/** - * An actual factory for services. - * <P> - * - * It is the <code>BeanContextServiceProvider</code>'s responsibility to - * register itself with whatever <code>BeanContextServices</code> object - * it wishes to provide services through using the - * <code>addService()</code> method. - * <P> - * - * If for some reason it can no longer provide services for a particular - * class, this class must invoke - * <code>BeanContextServices.revokeService(serviceClass,this,true)</code> - * for all the places it has registered the service. - * - * @author John Keiser - * @since JDK1.2 - */ - -public interface BeanContextServiceProvider { - /** - * Get a service. - * Called from <code>BeanContextServices.getService()</code>. - * - * <p>If the requested service class is not available, or if this - * <code>BeanContextServiceProvider</code> chooses not honor the - * request for some reason, then this method will return - * <code>null</code>.</p> - * - * This method may throw unchecked exceptions, so watch out. - * - * @param services the <code>BeanContextServices</code> that wants - * to get the service. Only weak references to this will - * be retained, and it will never be changed, only queried - * in a read-only manner. - * @param requestor the actual requestor of the service. Only - * weak references to this will be retained, and it will - * never be changed, only queried in a read-only manner. - * @param serviceClass the <code>Class</code> of the service being - * requested. - * @param serviceSelector a parameter to customize the service - * returned with. - * @return an instance of <code>serviceClass</code> (such that - * <code>instanceof</code> serviceClass is true), or - * <code>null</code>. - * @see java.beans.beancontext.BeanContextServices#getService(java.beans.beancontext.BeanContextChild,java.lang.Object,java.lang.Class,java.lang.Object,java.beans.beancontext.BeanContextServiceRevokedListener) - */ - Object getService(BeanContextServices services, Object requestor, Class serviceClass, Object serviceSelector); - - /** - * Release the service. - * <P> - * - * Called by <code>BeanContextServices.releaseService()</code>. - * <P> - * - * Most <code>BeanContextServiceProvider</code>s won't have to do - * anything here. - * - * @param services the <code>BeanContextServices</code> that wants - * to release the service. Only weak references to this will - * be retained, and it will never be changed, only queried - * in a read-only manner. - * @param requestor the original requestor of the service. - * @param service the service to relinquish - * @see java.beans.beancontext.BeanContextServices#releaseService(java.beans.beancontext.BeanContextChild,java.lang.Object,java.lang.Object) - */ - void releaseService(BeanContextServices services, Object requestor, Object service); - - /** - * Get a list of valid service selectors for the specified service class. - * This method is called from - * <code>BeanContextServices.getCurrentServiceSelectors()</code>. - * <P> - * - * If the specified service class does not have a finite number of - * valid service selectors, it should return <code>null</code>. - * If it takes a general <code>Integer</code> parameter, for - * example, you may as well return <code>null</code> or the poor - * soul who called this method will be iterating all day. - * <P> - * - * If it has no valid service selectors, it should still return an empty - * <code>Iterator</code>. - * - * @param services the <code>BeanContextServices</code> that wants - * to get the service selectors. Only weak references to this will - * be retained, and it will never be changed, only queried - * in a read-only manner. - * @param serviceClass the service class to get selectors for. - * @return a list of valid service selectors for the service - * class, or <code>null</code>. - * @see java.beans.beancontext.BeanContextServices#getCurrentServiceSelectors(java.lang.Class) - */ - Iterator getCurrentServiceSelectors(BeanContextServices services, Class serviceClass); -} diff --git a/libjava/java/beans/beancontext/BeanContextServiceProviderBeanInfo.java b/libjava/java/beans/beancontext/BeanContextServiceProviderBeanInfo.java deleted file mode 100644 index 690b94e2cc7..00000000000 --- a/libjava/java/beans/beancontext/BeanContextServiceProviderBeanInfo.java +++ /dev/null @@ -1,60 +0,0 @@ -/* java.beans.beancontext.BeanContextServiceProviderBeanInfo - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.beans.beancontext; - -import java.beans.BeanInfo; - -/** - * <code>BeanContextServiceProvider</code>s implement this to provide information about all of the services they provide. - * <P> - * - * This is apparently so that you can import a bunch of services into a - * RAD tool and it will know about all of them and export them to the - * user in a readable manner. - * - * @author John Keiser - * @since JDK1.2 - */ -public interface BeanContextServiceProviderBeanInfo extends BeanInfo { - /** - * Get <code>BeanInfo</code>s for all of the service classes of this <code>BeanInfoServiceProvider</code>. - * @return <code>BeanInfo</code>s for all provided service classes. - */ - BeanInfo[] getServicesBeanInfo(); -} diff --git a/libjava/java/beans/beancontext/BeanContextServiceRevokedEvent.java b/libjava/java/beans/beancontext/BeanContextServiceRevokedEvent.java deleted file mode 100644 index dfa2b89b3ae..00000000000 --- a/libjava/java/beans/beancontext/BeanContextServiceRevokedEvent.java +++ /dev/null @@ -1,110 +0,0 @@ -/* java.beans.beancontext.BeanContextServiceRevokedEvent - Copyright (C) 1999, 2000 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.beans.beancontext; - -/** - * Event fired when services are revoked from a <code>BeanContextServices</code>. - * - * @author John Keiser - * @since JDK1.2 - * @see java.beans.beancontext.BeanContextServiceRevokedListener - */ - -public class BeanContextServiceRevokedEvent extends BeanContextEvent { - /** - * The <code>Class</code> representing the service which is now - * available. - */ - protected Class serviceClass; - private boolean invalidateRefs; - - /** - * Create a new service revoked event. - * @param services the <code>BeanContextServices</code> through - * which the service was available. This is also the source - * of the event. - * @param serviceClass the service class that is now revoked. - * @param revokeNow whether the revocation is immediate for all - * classes or just a suggestion. - */ - public BeanContextServiceRevokedEvent(BeanContextServices services, Class serviceClass, boolean revokeNow) { - super(services); - this.serviceClass = serviceClass; - invalidateRefs = revokeNow; - } - - /** - * Get the revoked service class. - * @return the service class. - */ - public Class getServiceClass() { - return serviceClass; - } - - /** - * Tell whether the revoked service class is the same as the specified class. - * Identical to <code>getServiceClass().equals(c)</code>. - * @param c the class to compare. - * @return whether the clases are equal. - */ - public boolean isServiceClass(Class c) { - return serviceClass.equals(c); - } - - /** - * Get the <code>BeanContextServices</code> through which the service was available. - * @return the <code>BeanContextServices</code> through which the - * service was available. - */ - public BeanContextServices getSourceAsBeanContextServices() { - return (BeanContextServices)getSource(); - } - - /** - * Tell whether current instances of the revoked service are usable or not. - * This is determined by whether the service was revoked - * immediately. - * - * @return whether current instances of the revoked service are - * usable. - */ - public boolean isCurrentServiceInvalidNow() { - return invalidateRefs; - } -} diff --git a/libjava/java/beans/beancontext/BeanContextServiceRevokedListener.java b/libjava/java/beans/beancontext/BeanContextServiceRevokedListener.java deleted file mode 100644 index 101e6e191b0..00000000000 --- a/libjava/java/beans/beancontext/BeanContextServiceRevokedListener.java +++ /dev/null @@ -1,62 +0,0 @@ -/* java.beans.beancontext.BeanContextServiceRevokedListener - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.beans.beancontext; - -import java.util.EventListener; - -/** - * Listens for service revoke events. - * - * @author John Keiser - * @since JDK1.2 - */ - -public interface BeanContextServiceRevokedListener extends EventListener { - /** - * Called by <code>BeanContextServices.revokeService()</code> to indicate that a service has been revoked. - * If you have a reference to such a service, it should be - * discarded and may no longer function properly. - * <code>getService()</code> will no longer work on the specified - * service class after this event has been fired. - * - * @param event the service revoked event. - * @see java.beans.beancontext.BeanContextServices#revokeService(java.lang.Class,java.beans.beancontext.BeanContextServiceProvider,boolean) - */ - void serviceRevoked(BeanContextServiceRevokedEvent event); -} diff --git a/libjava/java/beans/beancontext/BeanContextServices.java b/libjava/java/beans/beancontext/BeanContextServices.java deleted file mode 100644 index cb1950360af..00000000000 --- a/libjava/java/beans/beancontext/BeanContextServices.java +++ /dev/null @@ -1,216 +0,0 @@ -/* java.beans.beancontext.BeanContextServices - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.beans.beancontext; - -import java.util.Iterator; -import java.util.TooManyListenersException; - -/** - * Allows a <code>BeanContext</code> to provide services to its children. - * - * @specnote it is unclear whether a <code>BeanContextServices</code> - * should delegate unhandled requests to parents. I assume so. - * @author John Keiser - * @since 1.2 - */ - -public interface BeanContextServices - extends BeanContext, BeanContextServicesListener -{ - /** - * Register a service to make it available to others. - * This class may refuse to add the service based on whatever - * information it can gather, including whether the service - * provider is trusted. - * - * @param serviceClass the service class. - * @param provider the factory that will actually provide the service. - * @return whether the service was added or not. - */ - boolean addService (Class serviceClass, - BeanContextServiceProvider provider); - - /** - * Make it so that no one else can use this service. - * <P> - * - * If <code>revokeNow</code> is <code>false</code>, the only - * effect of this method is to make all subsequent calls to - * <code>getService()</code> on this service class fail. - * <P> - * - * If it is <code>true</code>, a message is also sent out to all - * listeners on the service and all references to it are released. - * - * @param serviceClass the service class to revoke. - * @param provider the service provider providing the service class. - * @param revokeNow whether to release all current references to - * the service. - */ - void revokeService (Class serviceClass, - BeanContextServiceProvider provider, - boolean revokeNow); - - /** - * Release your copy of this service. - * <P> - * - * If all copies of the service's class have been relinquished by - * the requestor, the <code>BeanContextServiceRevokedListener</code> - * previously registered by <code>getService()</code> will be - * unregistered. - * - * @param requestorChild the original <code>BeanContextChild</code> - * requesting the service. - * @param requestor the original requestor of the service. - * @param service the service to relinquish - * @see #getService(java.beans.beancontext.BeanContextChild,java.lang.Object,java.lang.Class,java.lang.Object,java.beans.beancontext.BeanContextServiceRevokedListener) - */ - void releaseService (BeanContextChild requestorChild, Object requestor, - Object service); - - /** - * Get a service from this <code>BeanContextServices</code>. - * <P> - * - * The specified listener will be registered to receive a - * revocation notice for the specified serviceClass. One - * notification per service class per requestor object will be - * sent. - * <P> - * - * The listener will be unregistered when all services that were - * obtained by that requestor for that service class are released. - * <P> - * - * If the requested service class is not available, or if this - * <code>BeanContextServices</code> object chooses not honor the - * request because the service class has been revoked or for some - * other reason, then this method will return <code>null</code>. - * <P> - * - * This method may throw unchecked exceptions, so watch out. - * - * @specnote it is not specified what happens when two subsequent - * calls are made to <code>getService()</code> with the - * same requestor object and service class but different - * listeners. Which listener is to be notified? - * - * @param requestorChild the <code>BeanContextChild</code> - * associated with the requestor. Typically this will be - * the same as the requestor itself, but since any - * <code>Object</code>, even one outside the hierarchy, may - * make a request, this parameter is necessary. Only weak - * references to this will be retained, and it will never - * be changed, only queried in a read-only manner. - * @param requestor the actual requestor of the service. Only - * weak references to this will be retained, and it will - * never be changed, only queried in a read-only manner. - * @param serviceClass the <code>Class</code> of the service being - * requested. - * @param serviceSelector a parameter to customize the service - * returned with. - * @param listener a listener that will be notified if the service - * being requested is revoked. - * @return an instance of <code>serviceClass</code> (such that - * <code>instanceof</code> serviceClass is true), or - * <code>null</code>. - */ - Object getService (BeanContextChild requestorChild, Object requestor, - Class serviceClass, Object serviceSelector, - BeanContextServiceRevokedListener listener) - throws TooManyListenersException; - - /** - * Get a list of all service classes supported. - * <P> - * - * This method must synchronize on - * <code>BeanContext.globalHierarchyLock</code>. - * - * @return a list of all service classes supported. - * @see java.beans.beancontext.BeanContext#globalHierarchyLock - */ - Iterator getCurrentServiceClasses (); - - /** - * Get a list of valid service selectors for the specified service class. - * <P> - * - * If the specified service class does not have a finite number of - * valid service selectors, it should return <code>null</code>. - * If it takes a general <code>Integer</code> parameter, for - * example, you may as well return <code>null</code> or the poor - * soul who called this method will be iterating all day. - * <P> - * - * If it has no valid service selectors, it should still return an empty - * <code>Iterator</code>. - * - * @param serviceClass the service class to get selectors for. - * @return a list of valid service selectors for the service - * class, or <code>null</code>. - */ - Iterator getCurrentServiceSelectors (Class serviceClass); - - /** - * Tell whether the specified service class is available. - * Iff getService() could return a non-null value for the - * specified service, this method will return <code>true</code>. - * - * @param serviceClass the service class to check on. - * @return whether the specified service class is available. - */ - boolean hasService (Class serviceClass); - - /** - * Add a listener on all adds and removes of services. - * @param listener the listener to add. - */ - void addBeanContextServicesListener (BeanContextServicesListener listener); - - /** - * Remove a listener on all adds and removes of services. - * @specnote it is not certain whether this should remove this - * listener if it was specified in - * <code>getService()</code>. - * @param listener the listener to add. - */ - void removeBeanContextServicesListener (BeanContextServicesListener listener); -} diff --git a/libjava/java/beans/beancontext/BeanContextServicesListener.java b/libjava/java/beans/beancontext/BeanContextServicesListener.java deleted file mode 100644 index becc7cdb6e4..00000000000 --- a/libjava/java/beans/beancontext/BeanContextServicesListener.java +++ /dev/null @@ -1,56 +0,0 @@ -/* java.beans.beancontext.BeanContextServicesListener - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.beans.beancontext; - -/** - * Listens for service add and revoke events. - * - * @author John Keiser - * @since JDK1.2 - */ - -public interface BeanContextServicesListener extends BeanContextServiceRevokedListener { - /** - * Called by <code>BeanContextServices</code> whenever a service is made available. - * - * @param event the service revoked event, with useful information - * about the new service. - */ - void serviceAvailable(BeanContextServiceAvailableEvent event); -} diff --git a/libjava/java/beans/beancontext/BeanContextServicesSupport.java b/libjava/java/beans/beancontext/BeanContextServicesSupport.java deleted file mode 100644 index b7c4a49d8a9..00000000000 --- a/libjava/java/beans/beancontext/BeanContextServicesSupport.java +++ /dev/null @@ -1,300 +0,0 @@ -/* BeanContextServicesSupport.java -- - Copyright (C) 2003, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.beans.beancontext; - -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Locale; -import java.util.TooManyListenersException; - -/** - * @author Michael Koch - * @since 1.2 - */ -public class BeanContextServicesSupport - extends BeanContextSupport - implements BeanContextServices -{ - private static final long serialVersionUID = -8494482757288719206L; - - protected class BCSSChild - extends BeanContextSupport.BCSChild - { - private static final long serialVersionUID = -6848044915271367103L; - } - - protected class BCSSProxyServiceProvider - implements BeanContextServiceProvider, - BeanContextServiceRevokedListener - { - private static final long serialVersionUID = 7078212910685744490L; - - public Iterator getCurrentServiceSelectors (BeanContextServices bcs, - Class serviceClass) - { - throw new Error ("Not implemented"); - } - - public Object getService (BeanContextServices bcs, - Object requestor, - Class serviceClass, - Object serviceSelector) - { - throw new Error ("Not implemented"); - } - - public void releaseService (BeanContextServices bcs, - Object requestor, - Object service) - { - throw new Error ("Not implemented"); - } - - public void serviceRevoked (BeanContextServiceRevokedEvent bcsre) - { - throw new Error ("Not implemented"); - } - } - - protected static class BCSSServiceProvider - implements Serializable - { - private static final long serialVersionUID = 861278251667444782L; - - protected BeanContextServiceProvider serviceProvider; - - protected BeanContextServiceProvider getServiceProvider() - { - return serviceProvider; - } - } - - protected transient ArrayList bcsListeners; - - protected transient BCSSProxyServiceProvider proxy; - - protected transient int serializable; - - protected transient HashMap services; - - public BeanContextServicesSupport () - { - super(); - } - - public BeanContextServicesSupport (BeanContextServices peer) - { - super(peer); - } - - public BeanContextServicesSupport(BeanContextServices peer, Locale locale) - { - super(peer, locale); - } - - public BeanContextServicesSupport(BeanContextServices peer, Locale locale, - boolean dtime) - { - super(peer, locale, dtime); - } - - public BeanContextServicesSupport(BeanContextServices peer, Locale locale, - boolean dtime, boolean visible) - { - super(peer, locale, dtime, visible); - } - - public void addBeanContextServicesListener - (BeanContextServicesListener listener) - { - if (! bcsListeners.contains(listener)) - bcsListeners.add(listener); - } - - public boolean addService (Class serviceClass, BeanContextServiceProvider bcsp) - { - throw new Error ("Not implemented"); - } - - protected boolean addService (Class serviceClass, - BeanContextServiceProvider bcsp, - boolean fireEvent) - { - throw new Error ("Not implemented"); - } - - protected void bcsPreDeserializationHook (ObjectInputStream ois) - throws ClassNotFoundException, IOException - { - throw new Error ("Not implemented"); - } - - protected void bcsPreSerializationHook (ObjectOutputStream oos) - throws IOException - { - throw new Error ("Not implemented"); - } - - protected void childJustRemovedHook (Object child, - BeanContextSupport.BCSChild bcsc) - { - throw new Error ("Not implemented"); - } - - protected BeanContextSupport.BCSChild createBCSChild (Object targetChild, - Object peer) - { - throw new Error ("Not implemented"); - } - - protected BeanContextServicesSupport.BCSSServiceProvider - createBCSSServiceProvider (Class sc, BeanContextServiceProvider bcsp) - { - throw new Error ("Not implemented"); - } - - protected final void fireServiceAdded (BeanContextServiceAvailableEvent bcssae) - { - throw new Error ("Not implemented"); - } - - protected final void fireServiceAdded (Class serviceClass) - { - throw new Error ("Not implemented"); - } - - protected final void fireServiceRevoked(BeanContextServiceRevokedEvent event) - { - throw new Error ("Not implemented"); - } - - protected final void fireServiceRevoked (Class serviceClass, - boolean revokeNow) - { - throw new Error ("Not implemented"); - } - - public BeanContextServices getBeanContextServicesPeer () - { - throw new Error ("Not implemented"); - } - - protected static final BeanContextServicesListener - getChildBeanContextServicesListener (Object child) - { - throw new Error ("Not implemented"); - } - - public Iterator getCurrentServiceClasses () - { - throw new Error ("Not implemented"); - } - - public Iterator getCurrentServiceSelectors (Class serviceClass) - { - throw new Error ("Not implemented"); - } - - public Object getService (BeanContextChild child, Object requestor, - Class serviceClass, Object serviceSelector, - BeanContextServiceRevokedListener bcsrl) - throws TooManyListenersException - { - throw new Error ("Not implemented"); - } - - public boolean hasService (Class serviceClass) - { - throw new Error ("Not implemented"); - } - - public void initialize () - { - super.initialize(); - - bcsListeners = new ArrayList(); - services = new HashMap(); - } - - protected void initializeBeanContextResources () - { - throw new Error ("Not implemented"); - } - - protected void releaseBeanContextResources () - { - throw new Error ("Not implemented"); - } - - public void releaseService (BeanContextChild child, Object requestor, - Object service) - { - throw new Error ("Not implemented"); - } - - public void removeBeanContextServicesListener - (BeanContextServicesListener listener) - { - int index = bcsListeners.indexOf(listener); - - if (index > -1) - bcsListeners.remove(index); - } - - public void revokeService (Class serviceClass, BeanContextServiceProvider bcsp, - boolean revokeCurrentServicesNow) - { - throw new Error ("Not implemented"); - } - - public void serviceAvailable (BeanContextServiceAvailableEvent bcssae) - { - throw new Error ("Not implemented"); - } - - public void serviceRevoked (BeanContextServiceRevokedEvent bcssre) - { - throw new Error ("Not implemented"); - } -} diff --git a/libjava/java/beans/beancontext/BeanContextSupport.java b/libjava/java/beans/beancontext/BeanContextSupport.java deleted file mode 100644 index 7e024e23a13..00000000000 --- a/libjava/java/beans/beancontext/BeanContextSupport.java +++ /dev/null @@ -1,460 +0,0 @@ -/* BeanContextSupport.java -- - Copyright (C) 2003, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.beans.beancontext; - -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.beans.PropertyVetoException; -import java.beans.VetoableChangeListener; -import java.beans.Visibility; -import java.io.IOException; -import java.io.InputStream; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; -import java.net.URL; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Locale; - -/** - * @author Michael Koch - * @since 1.2 - */ -public class BeanContextSupport extends BeanContextChildSupport - implements BeanContext, Serializable, PropertyChangeListener, - VetoableChangeListener -{ - private static final long serialVersionUID = -4879613978649577204L; - - private void readObject (ObjectInputStream s) - throws ClassNotFoundException, IOException - { - throw new Error ("Not implemented"); - } - - private void writeObject (ObjectOutputStream s) - throws ClassNotFoundException, IOException - { - throw new Error ("Not implemented"); - } - - protected class BCSChild implements Serializable - { - private static final long serialVersionUID = 3289144128843950629L; - } - - protected static final class BCSIterator implements Iterator - { - public boolean hasNext () - { - throw new Error ("Not implemented"); - } - - public Object next () - { - throw new Error ("Not implemented"); - } - - public void remove () - { - // This must be a noop remove operation. - } - } - - protected transient ArrayList bcmListeners; - - protected transient HashMap children; - - protected transient boolean designTime; - - protected transient Locale locale; - - protected transient boolean okToUseGui; - - /** - * Construct a BeanContextSupport instance. - */ - public BeanContextSupport () - { - this (null, null, true, true); - } - - /** - * Construct a BeanContextSupport instance. - */ - public BeanContextSupport (BeanContext peer) - { - this (peer, null, true, true); - } - - /** - * Construct a BeanContextSupport instance. - */ - public BeanContextSupport (BeanContext peer, Locale lcle) - { - this (peer, lcle, true, true); - } - - /** - * Construct a BeanContextSupport instance. - */ - public BeanContextSupport (BeanContext peer, Locale lcle, boolean dtime) - { - this (peer, lcle, dtime, true); - } - - /** - * Construct a BeanContextSupport instance. - */ - public BeanContextSupport (BeanContext peer, Locale lcle, boolean dtime, - boolean visible) - { - locale = lcle; - designTime = dtime; - okToUseGui = visible; - - initialize (); - } - - public boolean add (Object targetChild) - { - if (targetChild == null) - throw new IllegalArgumentException(); - - if (children.containsKey(targetChild)) - return false; - - // FIXME: The second argument is surely wrong. - children.put(targetChild, targetChild); - return true; - } - - public boolean addAll (Collection c) - { - throw new UnsupportedOperationException(); - } - - public void addBeanContextMembershipListener - (BeanContextMembershipListener listener) - { - if (! bcmListeners.contains(listener)) - bcmListeners.add(listener); - } - - public boolean avoidingGui () - { - throw new Error ("Not implemented"); - } - - protected Iterator bcsChildren () - { - throw new Error ("Not implemented"); - } - - protected void bcsPreDeserializationHook (ObjectInputStream ois) - throws ClassNotFoundException, IOException - { - throw new Error ("Not implemented"); - } - - protected void bcsPreSerializationHook (ObjectOutputStream oos) - throws IOException - { - throw new Error ("Not implemented"); - } - - protected void childDeserializedHook (Object child, BeanContextSupport.BCSChild bcsc) - { - throw new Error ("Not implemented"); - } - - protected void childJustAddedHook (Object child, BeanContextSupport.BCSChild bcsc) - { - throw new Error ("Not implemented"); - } - - protected void childJustRemovedHook (Object child, BeanContextSupport.BCSChild bcsc) - { - throw new Error ("Not implemented"); - } - - protected static final boolean classEquals (Class first, Class second) - { - throw new Error ("Not implemented"); - } - - public void clear () - { - throw new UnsupportedOperationException(); - } - - public boolean contains (Object o) - { - throw new Error ("Not implemented"); - } - - public boolean containsAll (Collection c) - { - throw new Error ("Not implemented"); - } - - public boolean containsKey (Object o) - { - throw new Error ("Not implemented"); - } - - protected final Object[] copyChildren () - { - throw new Error ("Not implemented"); - } - - protected BeanContextSupport.BCSChild createBCSChild (Object targetChild, Object peer) - { - throw new Error ("Not implemented"); - } - - protected final void deserialize (ObjectInputStream ois, Collection coll) - throws ClassNotFoundException, IOException - { - throw new Error ("Not implemented"); - } - - public void dontUseGui () - { - throw new Error ("Not implemented"); - } - - protected final void fireChildrenAdded (BeanContextMembershipEvent bcme) - { - throw new Error ("Not implemented"); - } - - protected final void fireChildrenRemoved (BeanContextMembershipEvent bcme) - { - throw new Error ("Not implemented"); - } - - public BeanContext getBeanContextPeer () - { - throw new Error ("Not implemented"); - } - - protected static final BeanContextChild getChildBeanContextChild (Object child) - { - throw new Error ("Not implemented"); - } - - protected static final BeanContextMembershipListener getChildBeanContextMembershipListener (Object child) - { - throw new Error ("Not implemented"); - } - - protected static final PropertyChangeListener getChildPropertyChangeListener (Object child) - { - throw new Error ("Not implemented"); - } - - protected static final Serializable getChildSerializable (Object child) - { - throw new Error ("Not implemented"); - } - - protected static final VetoableChangeListener getChildVetoableChangeListener (Object child) - { - throw new Error ("Not implemented"); - } - - protected static final Visibility getChildVisibility (Object child) - { - throw new Error ("Not implemented"); - } - - public Locale getLocale () - { - return locale; - } - - public URL getResource (String name, BeanContextChild bcc) - { - throw new Error ("Not implemented"); - } - - public InputStream getResourceAsStream (String name, BeanContextChild bcc) - { - throw new Error ("Not implemented"); - } - - protected void initialize () - { - bcmListeners = new ArrayList(); - children = new HashMap(); - } - - public Object instantiateChild (String beanName) - throws IOException, ClassNotFoundException - { - throw new Error ("Not implemented"); - } - - public boolean isDesignTime () - { - throw new Error ("Not implemented"); - } - - public boolean isEmpty () - { - throw new Error ("Not implemented"); - } - - public boolean isSerializing () - { - throw new Error ("Not implemented"); - } - - public Iterator iterator () - { - return children.keySet().iterator(); - } - - public boolean needsGui () - { - throw new Error ("Not implemented"); - } - - public void okToUseGui () - { - throw new Error ("Not implemented"); - } - - public void propertyChange (PropertyChangeEvent pce) - { - throw new Error ("Not implemented"); - } - - public final void readChildren (ObjectInputStream ois) - throws IOException, ClassNotFoundException - { - throw new Error ("Not implemented"); - } - - public boolean remove (Object targetChild) - { - return remove(targetChild, true); - } - - protected boolean remove (Object targetChild, boolean callChildSetBC) - { - if (targetChild == null) - throw new IllegalArgumentException(); - - throw new Error ("Not implemented"); - } - - public boolean removeAll (Collection c) - { - throw new UnsupportedOperationException(); - } - - public void removeBeanContextMembershipListener (BeanContextMembershipListener bcml) - { - throw new Error ("Not implemented"); - } - - public boolean retainAll (Collection c) - { - throw new UnsupportedOperationException(); - } - - protected final void serialize (ObjectOutputStream oos, Collection coll) - throws IOException - { - throw new Error ("Not implemented"); - } - - public void setDesignTime (boolean dtime) - { - throw new Error ("Not implemented"); - } - - public void setLocale (Locale newLocale) - throws PropertyVetoException - { - throw new Error ("Not implemented"); - } - - public int size () - { - throw new Error ("Not implemented"); - } - - public Object[] toArray () - { - return children.keySet().toArray(); - } - - public Object[] toArray(Object[] array) - { - return children.keySet().toArray(array); - } - - protected boolean validatePendingAdd (Object targetChild) - { - throw new Error ("Not implemented"); - } - - protected boolean validatePendingRemove (Object targetChild) - { - throw new Error ("Not implemented"); - } - - public void vetoableChange (PropertyChangeEvent pce) - throws PropertyVetoException - { - throw new Error ("Not implemented"); - } - - public final void writeChildren (ObjectOutputStream oos) - throws IOException - { - throw new Error ("Not implemented"); - } -} diff --git a/libjava/java/io/BufferedOutputStream.java b/libjava/java/io/BufferedOutputStream.java deleted file mode 100644 index ce7ebc7e938..00000000000 --- a/libjava/java/io/BufferedOutputStream.java +++ /dev/null @@ -1,192 +0,0 @@ -/* BufferedOutputStream.java -- Buffer output into large blocks before writing - Copyright (C) 1998, 2000, 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.io; - -/** - * This class accumulates bytes written in a buffer instead of immediately - * writing the data to the underlying output sink. The bytes are instead - * as one large block when the buffer is filled, or when the stream is - * closed or explicitly flushed. This mode operation can provide a more - * efficient mechanism for writing versus doing numerous small unbuffered - * writes. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public class BufferedOutputStream extends FilterOutputStream -{ - /** - * This is the default buffer size - */ - private static final int DEFAULT_BUFFER_SIZE = 512; - - /** - * This is the internal byte array used for buffering output before - * writing it. - */ - protected byte[] buf; - - /** - * This is the number of bytes that are currently in the buffer and - * are waiting to be written to the underlying stream. It always points to - * the index into the buffer where the next byte of data will be stored - */ - protected int count; - - /** - * This method initializes a new <code>BufferedOutputStream</code> instance - * that will write to the specified subordinate <code>OutputStream</code> - * and which will use a default buffer size of 512 bytes. - * - * @param out The underlying <code>OutputStream</code> to write data to - */ - public BufferedOutputStream(OutputStream out) - { - this(out, DEFAULT_BUFFER_SIZE); - } - - /** - * This method initializes a new <code>BufferedOutputStream</code> instance - * that will write to the specified subordinate <code>OutputStream</code> - * and which will use the specified buffer size - * - * @param out The underlying <code>OutputStream</code> to write data to - * @param size The size of the internal buffer - */ - public BufferedOutputStream(OutputStream out, int size) - { - super(out); - - buf = new byte[size]; - } - - /** - * This method causes any currently buffered bytes to be immediately - * written to the underlying output stream. - * - * @exception IOException If an error occurs - */ - public synchronized void flush() throws IOException - { - if (count == 0) - return; - - out.write(buf, 0, count); - count = 0; - out.flush(); - } - - /** - * This method flushes any remaining buffered bytes then closes the - * underlying output stream. Any further attempts to write to this stream - * may throw an exception - * - public synchronized void close() throws IOException - { - flush(); - out.close(); - } - */ - - /** - * This method runs when the object is garbage collected. It is - * responsible for ensuring that all buffered bytes are written and - * for closing the underlying stream. - * - * @exception IOException If an error occurs (ignored by the Java runtime) - * - protected void finalize() throws IOException - { - close(); - } - */ - - /** - * This method writes a single byte of data. This will be written to the - * buffer instead of the underlying data source. However, if the buffer - * is filled as a result of this write request, it will be flushed to the - * underlying output stream. - * - * @param b The byte of data to be written, passed as an int - * - * @exception IOException If an error occurs - */ - public synchronized void write(int b) throws IOException - { - if (count == buf.length) - flush(); - - buf[count] = (byte)(b & 0xFF); - ++count; - } - - /** - * This method writes <code>len</code> bytes from the byte array - * <code>buf</code> starting at position <code>offset</code> in the buffer. - * These bytes will be written to the internal buffer. However, if this - * write operation fills the buffer, the buffer will be flushed to the - * underlying output stream. - * - * @param buf The array of bytes to write. - * @param offset The index into the byte array to start writing from. - * @param len The number of bytes to write. - * - * @exception IOException If an error occurs - */ - public synchronized void write(byte[] buf, int offset, int len) - throws IOException - { - // Buffer can hold everything. Note that the case where LEN < 0 - // is automatically handled by the downstream write. - if (len < (this.buf.length - count)) - { - System.arraycopy(buf, offset, this.buf, count, len); - count += len; - } - else - { - // The write was too big. So flush the buffer and write the new - // bytes directly to the underlying stream, per the JDK 1.2 - // docs. - flush(); - out.write (buf, offset, len); - } - } - -} // class BufferedOutputStream - diff --git a/libjava/java/io/BufferedReader.java b/libjava/java/io/BufferedReader.java deleted file mode 100644 index 4849949c989..00000000000 --- a/libjava/java/io/BufferedReader.java +++ /dev/null @@ -1,581 +0,0 @@ -/* BufferedReader.java - Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 - Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.io; - -/* Written using "Java Class Libraries", 2nd edition, plus online - * API docs for JDK 1.2 beta from http://www.javasoft.com. - * Status: Believed complete and correct. - */ - -/** - * This subclass of <code>FilterReader</code> buffers input from an - * underlying implementation to provide a possibly more efficient read - * mechanism. It maintains the buffer and buffer state in instance - * variables that are available to subclasses. The default buffer size - * of 8192 chars can be overridden by the creator of the stream. - * <p> - * This class also implements mark/reset functionality. It is capable - * of remembering any number of input chars, to the limits of - * system memory or the size of <code>Integer.MAX_VALUE</code> - * - * @author Per Bothner (bothner@cygnus.com) - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public class BufferedReader extends Reader -{ - Reader in; - char[] buffer; - /* Index of current read position. Must be >= 0 and <= limit. */ - /* There is a special case where pos may be equal to limit+1; this - * is used as an indicator that a readLine was done with a '\r' was - * the very last char in the buffer. Since we don't want to read-ahead - * and potentially block, we set pos this way to indicate the situation - * and deal with it later. Doing it this way rather than having a - * separate boolean field to indicate the condition has the advantage - * that it is self-clearing on things like mark/reset. - */ - int pos; - /* Limit of valid data in buffer. Must be >= pos and <= buffer.length. */ - /* This can be < pos in the one special case described above. */ - int limit; - - /* The value -1 means there is no mark, or the mark has been invalidated. - Otherwise, markPos is the index in the buffer of the marked position. - Must be >= 0 and <= pos. - Note we do not explicitly store the read-limit. - The implicit read-limit is (buffer.length - markPos), which is - guaranteed to be >= the read-limit requested in the call to mark. */ - int markPos = -1; - - // The JCL book specifies the default buffer size as 8K characters. - // This is package-private because it is used by LineNumberReader. - static final int DEFAULT_BUFFER_SIZE = 8192; - - /** - * The line buffer for <code>readLine</code>. - */ - private StringBuffer sbuf = null; - - /** - * Create a new <code>BufferedReader</code> that will read from the - * specified subordinate stream with a default buffer size of 8192 chars. - * - * @param in The subordinate stream to read from - */ - public BufferedReader(Reader in) - { - this(in, DEFAULT_BUFFER_SIZE); - } - - /** - * Create a new <code>BufferedReader</code> that will read from the - * specified subordinate stream with a buffer size that is specified by the - * caller. - * - * @param in The subordinate stream to read from - * @param size The buffer size to use - * - * @exception IllegalArgumentException if size <= 0 - */ - public BufferedReader(Reader in, int size) - { - super(in.lock); - if (size <= 0) - throw new IllegalArgumentException("Illegal buffer size: " + size); - this.in = in; - buffer = new char[size]; - } - - /** - * This method closes the underlying stream and frees any associated - * resources. - * - * @exception IOException If an error occurs - */ - public void close() throws IOException - { - synchronized (lock) - { - if (in != null) - in.close(); - in = null; - buffer = null; - } - } - - /** - * Returns <code>true</code> to indicate that this class supports mark/reset - * functionality. - * - * @return <code>true</code> - */ - public boolean markSupported() - { - return true; - } - - /** - * Mark a position in the input to which the stream can be - * "reset" by calling the <code>reset()</code> method. The parameter - * <code>readLimit</code> is the number of chars that can be read from the - * stream after setting the mark before the mark becomes invalid. For - * example, if <code>mark()</code> is called with a read limit of 10, then - * when 11 chars of data are read from the stream before the - * <code>reset()</code> method is called, then the mark is invalid and the - * stream object instance is not required to remember the mark. - * <p> - * Note that the number of chars that can be remembered by this method - * can be greater than the size of the internal read buffer. It is also - * not dependent on the subordinate stream supporting mark/reset - * functionality. - * - * @param readLimit The number of chars that can be read before the mark - * becomes invalid - * - * @exception IOException If an error occurs - * @exception IllegalArgumentException if readLimit is negative. - */ - public void mark(int readLimit) throws IOException - { - if (readLimit < 0) - throw new IllegalArgumentException("Read-ahead limit is negative"); - - synchronized (lock) - { - checkStatus(); - // In this method we need to be aware of the special case where - // pos + 1 == limit. This indicates that a '\r' was the last char - // in the buffer during a readLine. We'll want to maintain that - // condition after we shift things around and if a larger buffer is - // needed to track readLimit, we'll have to make it one element - // larger to ensure we don't invalidate the mark too early, if the - // char following the '\r' is NOT a '\n'. This is ok because, per - // the spec, we are not required to invalidate when passing readLimit. - // - // Note that if 'pos > limit', then doing 'limit -= pos' will cause - // limit to be negative. This is the only way limit will be < 0. - - if (pos + readLimit > limit) - { - char[] old_buffer = buffer; - int extraBuffSpace = 0; - if (pos > limit) - extraBuffSpace = 1; - if (readLimit + extraBuffSpace > limit) - buffer = new char[readLimit + extraBuffSpace]; - limit -= pos; - if (limit >= 0) - { - System.arraycopy(old_buffer, pos, buffer, 0, limit); - pos = 0; - } - } - - if (limit < 0) - { - // Maintain the relationship of 'pos > limit'. - pos = 1; - limit = markPos = 0; - } - else - markPos = pos; - // Now pos + readLimit <= buffer.length. thus if we need to read - // beyond buffer.length, then we are allowed to invalidate markPos. - } - } - - /** - * Reset the stream to the point where the <code>mark()</code> method - * was called. Any chars that were read after the mark point was set will - * be re-read during subsequent reads. - * <p> - * This method will throw an IOException if the number of chars read from - * the stream since the call to <code>mark()</code> exceeds the mark limit - * passed when establishing the mark. - * - * @exception IOException If an error occurs; - */ - public void reset() throws IOException - { - synchronized (lock) - { - checkStatus(); - if (markPos < 0) - throw new IOException("mark never set or invalidated"); - - // Need to handle the extremely unlikely case where a readLine was - // done with a '\r' as the last char in the buffer; which was then - // immediately followed by a mark and a reset with NO intervening - // read of any sort. In that case, setting pos to markPos would - // lose that info and a subsequent read would thus not skip a '\n' - // (if one exists). The value of limit in this rare case is zero. - // We can assume that if limit is zero for other reasons, then - // pos is already set to zero and doesn't need to be readjusted. - if (limit > 0) - pos = markPos; - } - } - - /** - * This method determines whether or not a stream is ready to be read. If - * this method returns <code>false</code> then this stream could (but is - * not guaranteed to) block on the next read attempt. - * - * @return <code>true</code> if this stream is ready to be read, - * <code>false</code> otherwise - * - * @exception IOException If an error occurs - */ - public boolean ready() throws IOException - { - synchronized (lock) - { - checkStatus(); - return pos < limit || in.ready(); - } - } - - /** - * This method read chars from a stream and stores them into a caller - * supplied buffer. It starts storing the data at index - * <code>offset</code> into - * the buffer and attempts to read <code>len</code> chars. This method can - * return before reading the number of chars requested. The actual number - * of chars read is returned as an int. A -1 is returned to indicate the - * end of the stream. - * <p> - * This method will block until some data can be read. - * - * @param buf The array into which the chars read should be stored - * @param offset The offset into the array to start storing chars - * @param count The requested number of chars to read - * - * @return The actual number of chars read, or -1 if end of stream. - * - * @exception IOException If an error occurs. - * @exception IndexOutOfBoundsException If offset and count are not - * valid regarding buf. - */ - public int read(char[] buf, int offset, int count) throws IOException - { - if (offset < 0 || offset + count > buf.length || count < 0) - throw new IndexOutOfBoundsException(); - - synchronized (lock) - { - checkStatus(); - // Once again, we need to handle the special case of a readLine - // that has a '\r' at the end of the buffer. In this case, we'll - // need to skip a '\n' if it is the next char to be read. - // This special case is indicated by 'pos > limit'. - boolean retAtEndOfBuffer = false; - - int avail = limit - pos; - if (count > avail) - { - if (avail > 0) - count = avail; - else // pos >= limit - { - if (limit == buffer.length) - markPos = -1; // read too far - invalidate the mark. - if (pos > limit) - { - // Set a boolean and make pos == limit to simplify things. - retAtEndOfBuffer = true; - --pos; - } - if (markPos < 0) - { - // Optimization: can read directly into buf. - if (count >= buffer.length && !retAtEndOfBuffer) - return in.read(buf, offset, count); - pos = limit = 0; - } - avail = in.read(buffer, limit, buffer.length - limit); - if (retAtEndOfBuffer && avail > 0 && buffer[limit] == '\n') - { - --avail; - limit++; - } - if (avail < count) - { - if (avail <= 0) - return avail; - count = avail; - } - limit += avail; - } - } - System.arraycopy(buffer, pos, buf, offset, count); - pos += count; - return count; - } - } - - /* Read more data into the buffer. Update pos and limit appropriately. - Assumes pos==limit initially. May invalidate the mark if read too much. - Return number of chars read (never 0), or -1 on eof. */ - private int fill() throws IOException - { - checkStatus(); - // Handle the special case of a readLine that has a '\r' at the end of - // the buffer. In this case, we'll need to skip a '\n' if it is the - // next char to be read. This special case is indicated by 'pos > limit'. - boolean retAtEndOfBuffer = false; - if (pos > limit) - { - retAtEndOfBuffer = true; - --pos; - } - - if (markPos >= 0 && limit == buffer.length) - markPos = -1; - if (markPos < 0) - pos = limit = 0; - int count = in.read(buffer, limit, buffer.length - limit); - if (count > 0) - limit += count; - - if (retAtEndOfBuffer && buffer[pos] == '\n') - { - --count; - // If the mark was set to the location of the \n, then we - // must change it to fully pretend that the \n does not - // exist. - if (markPos == pos) - ++markPos; - ++pos; - } - - return count; - } - - public int read() throws IOException - { - synchronized (lock) - { - checkStatus(); - if (pos >= limit && fill () <= 0) - return -1; - return buffer[pos++]; - } - } - - /* Return the end of the line starting at this.pos and ending at limit. - * The index returns is *before* any line terminators, or limit - * if no line terminators were found. - */ - private int lineEnd(int limit) - { - int i = pos; - for (; i < limit; i++) - { - char ch = buffer[i]; - if (ch == '\n' || ch == '\r') - break; - } - return i; - } - - /** - * This method reads a single line of text from the input stream, returning - * it as a <code>String</code>. A line is terminated by "\n", a "\r", or - * an "\r\n" sequence. The system dependent line separator is not used. - * The line termination characters are not returned in the resulting - * <code>String</code>. - * - * @return The line of text read, or <code>null</code> if end of stream. - * - * @exception IOException If an error occurs - */ - public String readLine() throws IOException - { - checkStatus(); - // Handle the special case where a previous readLine (with no intervening - // reads/skips) had a '\r' at the end of the buffer. - // In this case, we'll need to skip a '\n' if it's the next char to be read. - // This special case is indicated by 'pos > limit'. - if (pos > limit) - { - int ch = read(); - if (ch < 0) - return null; - if (ch != '\n') - --pos; - } - int i = lineEnd(limit); - if (i < limit) - { - String str = String.valueOf(buffer, pos, i - pos); - pos = i + 1; - // If the last char in the buffer is a '\r', we must remember - // to check if the next char to be read after the buffer is refilled - // is a '\n'. If so, skip it. To indicate this condition, we set pos - // to be limit + 1, which normally is never possible. - if (buffer[i] == '\r') - if (pos == limit || buffer[pos] == '\n') - pos++; - return str; - } - if (sbuf == null) - sbuf = new StringBuffer(200); - else - sbuf.setLength(0); - sbuf.append(buffer, pos, i - pos); - pos = i; - // We only want to return null when no characters were read before - // EOF. So we must keep track of this separately. Otherwise we - // would treat an empty `sbuf' as an EOF condition, which is wrong - // when there is just a newline. - boolean eof = false; - for (;;) - { - // readLine should block. So we must not return until a -1 is reached. - if (pos >= limit) - { - // here count == 0 isn't sufficient to give a failure. - int count = fill(); - if (count < 0) - { - eof = true; - break; - } - continue; - } - int ch = buffer[pos++]; - if (ch == '\n' || ch == '\r') - { - // Check here if a '\r' was the last char in the buffer; if so, - // mark it as in the comment above to indicate future reads - // should skip a newline that is the next char read after - // refilling the buffer. - if (ch == '\r') - if (pos == limit || buffer[pos] == '\n') - pos++; - break; - } - i = lineEnd(limit); - sbuf.append(buffer, pos - 1, i - (pos - 1)); - pos = i; - } - return (sbuf.length() == 0 && eof) ? null : sbuf.toString(); - } - - /** - * This method skips the specified number of chars in the stream. It - * returns the actual number of chars skipped, which may be less than the - * requested amount. - * <p> - * This method first discards chars in the buffer, then calls the - * <code>skip</code> method on the underlying stream to skip the - * remaining chars. - * - * @param count The requested number of chars to skip - * - * @return The actual number of chars skipped. - * - * @exception IOException If an error occurs. - * @exception IllegalArgumentException If count is negative. - */ - public long skip(long count) throws IOException - { - synchronized (lock) - { - checkStatus(); - if (count < 0) - throw new IllegalArgumentException("skip value is negative"); - if (count == 0) - return 0; - // Yet again, we need to handle the special case of a readLine - // that has a '\r' at the end of the buffer. In this case, we need - // to ignore a '\n' if it is the next char to be read. - // This special case is indicated by 'pos > limit' (i.e. avail < 0). - // To simplify things, if we're dealing with the special case for - // readLine, just read the next char (since the fill method will - // skip the '\n' for us). By doing this, we'll have to back up pos. - // That's easier than trying to keep track of whether we've skipped - // one element or not. - if (pos > limit) - { - if (read() < 0) - return 0; - else - --pos; - } - - int avail = limit - pos; - - if (count < avail) - { - pos += count; - return count; - } - - pos = limit; - long todo = count - avail; - if (todo > buffer.length) - { - markPos = -1; - todo -= in.skip(todo); - } - else - { - while (todo > 0) - { - avail = fill(); - if (avail <= 0) - break; - if (avail > todo) - avail = (int) todo; - pos += avail; - todo -= avail; - } - } - return count - todo; - } - } - - private void checkStatus() throws IOException - { - if (in == null) - throw new IOException("Stream closed"); - } -} diff --git a/libjava/java/io/BufferedWriter.java b/libjava/java/io/BufferedWriter.java deleted file mode 100644 index 185a5344062..00000000000 --- a/libjava/java/io/BufferedWriter.java +++ /dev/null @@ -1,262 +0,0 @@ -/* BufferedWriter.java -- Buffer output into large blocks before writing - Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.io; - -/* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3 - * "The Java Language Specification", ISBN 0-201-63451-1 - * Status: Complete to version 1.1. - */ - -/** - * This class accumulates chars written in a buffer instead of immediately - * writing the data to the underlying output sink. The chars are instead - * as one large block when the buffer is filled, or when the stream is - * closed or explicitly flushed. This mode operation can provide a more - * efficient mechanism for writing versus doing numerous small unbuffered - * writes. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Tom Tromey (tromey@cygnus.com) - * @date September 25, 1998 - */ -public class BufferedWriter extends Writer -{ - /** - * This is the default buffer size - */ - private static final int DEFAULT_BUFFER_SIZE = 8192; - - /** - * This is the underlying <code>Writer</code> to which this object - * sends its output. - */ - private Writer out; - - /** - * This is the internal char array used for buffering output before - * writing it. - */ - char[] buffer; - - /** - * This is the number of chars that are currently in the buffer and - * are waiting to be written to the underlying stream. It always points to - * the index into the buffer where the next char of data will be stored - */ - int count; - - /** - * This method initializes a new <code>BufferedWriter</code> instance - * that will write to the specified subordinate <code>Writer</code> - * and which will use a default buffer size of 8192 chars. - * - * @param out The underlying <code>Writer</code> to write data to - */ - public BufferedWriter (Writer out) - { - this (out, DEFAULT_BUFFER_SIZE); - } - - /** - * This method initializes a new <code>BufferedWriter</code> instance - * that will write to the specified subordinate <code>Writer</code> - * and which will use the specified buffer size - * - * @param out The underlying <code>Writer</code> to write data to - * @param size The size of the internal buffer - */ - public BufferedWriter (Writer out, int size) - { - super(out.lock); - this.out = out; - this.buffer = new char[size]; - this.count = 0; - } - - /** - * This method flushes any remaining buffered chars then closes the - * underlying output stream. Any further attempts to write to this stream - * may throw an exception - * - * @exception IOException If an error occurs. - */ - public void close () throws IOException - { - synchronized (lock) - { - // It is safe to call localFlush even if the stream is already - // closed. - localFlush (); - out.close(); - buffer = null; - } - } - - /** - * This method causes any currently buffered chars to be immediately - * written to the underlying output stream. - * - * @exception IOException If an error occurs - */ - public void flush () throws IOException - { - synchronized (lock) - { - if (buffer == null) - throw new IOException ("Stream closed"); - localFlush (); - out.flush(); - } - } - - /** - * This method writes out a system depedent line separator sequence. The - * actual value written is detemined from the <xmp>line.separator</xmp> - * system property. - * - * @exception IOException If an error occurs - */ - public void newLine () throws IOException - { - write (System.getProperty("line.separator")); - } - - /** - * This method writes a single char of data. This will be written to the - * buffer instead of the underlying data source. However, if the buffer - * is filled as a result of this write request, it will be flushed to the - * underlying output stream. - * - * @param oneChar The char of data to be written, passed as an int - * - * @exception IOException If an error occurs - */ - public void write (int oneChar) throws IOException - { - synchronized (lock) - { - if (buffer == null) - throw new IOException ("Stream closed"); - buffer[count++] = (char) oneChar; - if (count == buffer.length) - localFlush (); - } - } - - /** - * This method writes <code>len</code> chars from the char array - * <code>buf</code> starting at position <code>offset</code> in the buffer. - * These chars will be written to the internal buffer. However, if this - * write operation fills the buffer, the buffer will be flushed to the - * underlying output stream. - * - * @param buf The array of chars to write. - * @param offset The index into the char array to start writing from. - * @param len The number of chars to write. - * - * @exception IOException If an error occurs - */ - public void write (char[] buf, int offset, int len) throws IOException - { - synchronized (lock) - { - if (buffer == null) - throw new IOException ("Stream closed"); - - // Bypass buffering if there is too much incoming data. - if (count + len > buffer.length) - { - localFlush (); - out.write(buf, offset, len); - } - else - { - System.arraycopy(buf, offset, buffer, count, len); - count += len; - if (count == buffer.length) - localFlush (); - } - } - } - - /** - * This method writes <code>len</code> chars from the <code>String</code> - * <code>str</code> starting at position <code>offset</code> in the string. - * These chars will be written to the internal buffer. However, if this - * write operation fills the buffer, the buffer will be flushed to the - * underlying output stream. - * - * @param str The <code>String</code> to write. - * @param offset The index into the string to start writing from. - * @param len The number of chars to write. - * - * @exception IOException If an error occurs - */ - public void write (String str, int offset, int len) throws IOException - { - synchronized (lock) - { - if (buffer == null) - throw new IOException ("Stream closed"); - - if (count + len > buffer.length) - { - localFlush (); - out.write(str, offset, len); - } - else - { - str.getChars(offset, offset + len, buffer, count); - count += len; - if (count == buffer.length) - localFlush (); - } - } - } - - // This should only be called with the lock held. - private void localFlush () throws IOException - { - if (count > 0) - { - out.write(buffer, 0, count); - count = 0; - } - } -} diff --git a/libjava/java/io/ByteArrayInputStream.java b/libjava/java/io/ByteArrayInputStream.java deleted file mode 100644 index 2bbde95b724..00000000000 --- a/libjava/java/io/ByteArrayInputStream.java +++ /dev/null @@ -1,251 +0,0 @@ -/* ByteArrayInputStream.java -- Read an array as a stream - Copyright (C) 1998, 1999, 2001, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.io; - -/** - * This class permits an array of bytes to be read as an input stream. - * - * @author Warren Levy (warrenl@cygnus.com) - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public class ByteArrayInputStream extends InputStream -{ - /** - * The array that contains the data supplied during read operations - */ - protected byte[] buf; - - /** - * The array index of the next byte to be read from the buffer - * <code>buf</code> - */ - protected int pos; - - /** - * The currently marked position in the stream. This defaults to 0, so a - * reset operation on the stream resets it to read from array index 0 in - * the buffer - even if the stream was initially created with an offset - * greater than 0 - */ - protected int mark; - - /** - * This indicates the maximum number of bytes that can be read from this - * stream. It is the array index of the position after the last valid - * byte in the buffer <code>buf</code> - */ - protected int count; - - /** - * Create a new ByteArrayInputStream that will read bytes from the passed - * in byte array. This stream will read from the beginning to the end - * of the array. It is identical to calling an overloaded constructor - * as <code>ByteArrayInputStream(buf, 0, buf.length)</code>. - * <p> - * Note that this array is not copied. If its contents are changed - * while this stream is being read, those changes will be reflected in the - * bytes supplied to the reader. Please use caution in changing the - * contents of the buffer while this stream is open. - * - * @param buffer The byte array buffer this stream will read from. - */ - public ByteArrayInputStream(byte[] buffer) - { - this(buffer, 0, buffer.length); - } - - /** - * Create a new ByteArrayInputStream that will read bytes from the - * passed in byte array. This stream will read from position - * <code>offset</code> in the array for a length of - * <code>length</code> bytes past <code>offset</code>. If the - * stream is reset to a position before <code>offset</code> then - * more than <code>length</code> bytes can be read from the stream. - * The <code>length</code> value should be viewed as the array index - * one greater than the last position in the buffer to read. - * <p> - * Note that this array is not copied. If its contents are changed - * while this stream is being read, those changes will be reflected in the - * bytes supplied to the reader. Please use caution in changing the - * contents of the buffer while this stream is open. - * - * @param buffer The byte array buffer this stream will read from. - * @param offset The index into the buffer to start reading bytes from - * @param length The number of bytes to read from the buffer - */ - public ByteArrayInputStream(byte[] buffer, int offset, int length) - { - if (offset < 0 || length < 0 || offset > buffer.length) - throw new IllegalArgumentException(); - - buf = buffer; - - count = offset + length; - if (count > buf.length) - count = buf.length; - - pos = offset; - mark = pos; - } - - /** - * This method returns the number of bytes available to be read from this - * stream. The value returned will be equal to <code>count - pos</code>. - * - * @return The number of bytes that can be read from this stream - * before blocking, which is all of them - */ - public synchronized int available() - { - return count - pos; - } - - /** - * This method sets the mark position in this stream to the current - * position. Note that the <code>readlimit</code> parameter in this - * method does nothing as this stream is always capable of - * remembering all the bytes int it. - * <p> - * Note that in this class the mark position is set by default to - * position 0 in the stream. This is in constrast to some other - * stream types where there is no default mark position. - * - * @param readLimit The number of bytes this stream must remember. - * This parameter is ignored. - */ - public synchronized void mark(int readLimit) - { - // readLimit is ignored per Java Class Lib. book, p.220. - mark = pos; - } - - /** - * This method overrides the <code>markSupported</code> method in - * <code>InputStream</code> in order to return <code>true</code> - - * indicating that this stream class supports mark/reset - * functionality. - * - * @return <code>true</code> to indicate that this class supports - * mark/reset. - */ - public boolean markSupported() - { - return true; - } - - /** - * This method reads one byte from the stream. The <code>pos</code> - * counter is advanced to the next byte to be read. The byte read is - * returned as an int in the range of 0-255. If the stream position - * is already at the end of the buffer, no byte is read and a -1 is - * returned in order to indicate the end of the stream. - * - * @return The byte read, or -1 if end of stream - */ - public synchronized int read() - { - if (pos < count) - return ((int) buf[pos++]) & 0xFF; - return -1; - } - - /** - * This method reads bytes from the stream and stores them into a - * caller supplied buffer. It starts storing the data at index - * <code>offset</code> into the buffer and attempts to read - * <code>len</code> bytes. This method can return before reading - * the number of bytes requested if the end of the stream is - * encountered first. The actual number of bytes read is returned. - * If no bytes can be read because the stream is already at the end - * of stream position, a -1 is returned. - * <p> - * This method does not block. - * - * @param buffer The array into which the bytes read should be stored. - * @param offset The offset into the array to start storing bytes - * @param length The requested number of bytes to read - * - * @return The actual number of bytes read, or -1 if end of stream. - */ - public synchronized int read(byte[] buffer, int offset, int length) - { - if (pos >= count) - return -1; - - int numBytes = Math.min(count - pos, length); - System.arraycopy(buf, pos, buffer, offset, numBytes); - pos += numBytes; - return numBytes; - } - - /** - * This method sets the read position in the stream to the mark - * point by setting the <code>pos</code> variable equal to the - * <code>mark</code> variable. Since a mark can be set anywhere in - * the array, the mark/reset methods int this class can be used to - * provide random search capabilities for this type of stream. - */ - public synchronized void reset() - { - pos = mark; - } - - /** - * This method attempts to skip the requested number of bytes in the - * input stream. It does this by advancing the <code>pos</code> - * value by the specified number of bytes. It this would exceed the - * length of the buffer, then only enough bytes are skipped to - * position the stream at the end of the buffer. The actual number - * of bytes skipped is returned. - * - * @param num The requested number of bytes to skip - * - * @return The actual number of bytes skipped. - */ - public synchronized long skip(long num) - { - // Even though the var numBytes is a long, in reality it can never - // be larger than an int since the result of subtracting 2 positive - // ints will always fit in an int. Since we have to return a long - // anyway, numBytes might as well just be a long. - long numBytes = Math.min((long) (count - pos), num < 0 ? 0L : num); - pos += numBytes; - return numBytes; - } -} diff --git a/libjava/java/io/ByteArrayOutputStream.java b/libjava/java/io/ByteArrayOutputStream.java deleted file mode 100644 index e996ebbc70f..00000000000 --- a/libjava/java/io/ByteArrayOutputStream.java +++ /dev/null @@ -1,283 +0,0 @@ -/* BufferedReader.java - Copyright (C) 1998, 1999, 2000, 2001, 2003, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.io; - -/* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3 - * "The Java Language Specification", ISBN 0-201-63451-1 - * Status: Complete to version 1.1. - */ - -/** - * This class allows data to be written to a byte array buffer and - * and then retrieved by an application. The internal byte array - * buffer is dynamically resized to hold all the data written. Please - * be aware that writing large amounts to data to this stream will - * cause large amounts of memory to be allocated. - * <p> - * The size of the internal buffer defaults to 32 and it is resized - * by doubling the size of the buffer. This default size can be - * overridden by using the - * <code>gnu.java.io.ByteArrayOutputStream.initialBufferSize</code> - * property. - * <p> - * There is a constructor that specified the initial buffer size and - * that is the preferred way to set that value because it it portable - * across all Java class library implementations. - * <p> - * Note that this class also has methods that convert the byte array - * buffer to a <code>String</code> using either the system default or an - * application specified character encoding. Thus it can handle - * multibyte character encodings. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Tom Tromey (tromey@cygnus.com) - * @date September 24, 1998 - */ -public class ByteArrayOutputStream extends OutputStream -{ - /** - * This method initializes a new <code>ByteArrayOutputStream</code> - * with the default buffer size of 32 bytes. If a different initial - * buffer size is desired, see the constructor - * <code>ByteArrayOutputStream(int size)</code>. For applications - * where the source code is not available, the default buffer size - * can be set using the system property - * <code>gnu.java.io.ByteArrayOutputStream.initialBufferSize</code> - */ - public ByteArrayOutputStream () - { - this (initial_buffer_size); - } - - /** - * This method initializes a new <code>ByteArrayOutputStream</code> with - * a specified initial buffer size. - * - * @param size The initial buffer size in bytes - */ - public ByteArrayOutputStream (int size) - { - buf = new byte[size]; - count = 0; - } - - /** - * This method discards all of the bytes that have been written to - * the internal buffer so far by setting the <code>count</code> - * variable to 0. The internal buffer remains at its currently - * allocated size. - */ - public synchronized void reset () - { - count = 0; - } - - /** - * This method returns the number of bytes that have been written to - * the buffer so far. This is the same as the value of the protected - * <code>count</code> variable. If the <code>reset</code> method is - * called, then this value is reset as well. Note that this method does - * not return the length of the internal buffer, but only the number - * of bytes that have been written to it. - * - * @return The number of bytes in the internal buffer - * - * @see #reset() - */ - public int size () - { - return count; - } - - /** - * This method returns a byte array containing the bytes that have been - * written to this stream so far. This array is a copy of the valid - * bytes in the internal buffer and its length is equal to the number of - * valid bytes, not necessarily to the the length of the current - * internal buffer. Note that since this method allocates a new array, - * it should be used with caution when the internal buffer is very large. - */ - public synchronized byte[] toByteArray () - { - byte[] ret = new byte[count]; - System.arraycopy(buf, 0, ret, 0, count); - return ret; - } - - /** - * Returns the bytes in the internal array as a <code>String</code>. The - * bytes in the buffer are converted to characters using the system default - * encoding. There is an overloaded <code>toString()</code> method that - * allows an application specified character encoding to be used. - * - * @return A <code>String</code> containing the data written to this - * stream so far - */ - public String toString () - { - return new String (buf, 0, count); - } - - /** - * Returns the bytes in the internal array as a <code>String</code>. The - * bytes in the buffer are converted to characters using the specified - * encoding. - * - * @param enc The name of the character encoding to use - * - * @return A <code>String</code> containing the data written to this - * stream so far - * - * @exception UnsupportedEncodingException If the named encoding is - * not available - */ - public String toString (String enc) throws UnsupportedEncodingException - { - return new String (buf, 0, count, enc); - } - - /** - * This method returns the bytes in the internal array as a - * <code>String</code>. It uses each byte in the array as the low - * order eight bits of the Unicode character value and the passed in - * parameter as the high eight bits. - * <p> - * This method does not convert bytes to characters in the proper way and - * so is deprecated in favor of the other overloaded <code>toString</code> - * methods which use a true character encoding. - * - * @param hibyte The high eight bits to use for each character in - * the <code>String</code> - * - * @return A <code>String</code> containing the data written to this - * stream so far - * - * @deprecated - */ - public String toString (int hibyte) - { - return new String (buf, 0, count, hibyte); - } - - // Resize buffer to accommodate new bytes. - private void resize (int add) - { - if (count + add > buf.length) - { - int newlen = buf.length * 2; - if (count + add > newlen) - newlen = count + add; - byte[] newbuf = new byte[newlen]; - System.arraycopy(buf, 0, newbuf, 0, count); - buf = newbuf; - } - } - - /** - * This method writes the writes the specified byte into the internal - * buffer. - * - * @param oneByte The byte to be read passed as an int - */ - public synchronized void write (int oneByte) - { - resize (1); - buf[count++] = (byte) oneByte; - } - - /** - * This method writes <code>len</code> bytes from the passed in array - * <code>buf</code> starting at index <code>offset</code> into the - * internal buffer. - * - * @param buffer The byte array to write data from - * @param offset The index into the buffer to start writing data from - * @param add The number of bytes to write - */ - public synchronized void write (byte[] buffer, int offset, int add) - { - // If ADD < 0 then arraycopy will throw the appropriate error for - // us. - if (add >= 0) - resize (add); - System.arraycopy(buffer, offset, buf, count, add); - count += add; - } - - /** - * This method writes all the bytes that have been written to this stream - * from the internal buffer to the specified <code>OutputStream</code>. - * - * @param out The <code>OutputStream</code> to write to - * - * @exception IOException If an error occurs - */ - public synchronized void writeTo (OutputStream out) throws IOException - { - out.write(buf, 0, count); - } - - /** - * The internal buffer where the data written is stored - */ - protected byte[] buf; - - /** - * The number of bytes that have been written to the buffer - */ - protected int count; - - /** - * The default initial buffer size. Specified by the JCL. - */ - private static final int DEFAULT_INITIAL_BUFFER_SIZE = 32; - - // The default buffer size which can be overridden by the user. - private static final int initial_buffer_size; - - static - { - int r - = Integer.getInteger ("gnu.java.io.ByteArrayOutputStream.initialBufferSize", - DEFAULT_INITIAL_BUFFER_SIZE).intValue (); - if (r <= 0) - r = DEFAULT_INITIAL_BUFFER_SIZE; - initial_buffer_size = r; - } -} diff --git a/libjava/java/io/CharArrayReader.java b/libjava/java/io/CharArrayReader.java deleted file mode 100644 index c14fa077592..00000000000 --- a/libjava/java/io/CharArrayReader.java +++ /dev/null @@ -1,305 +0,0 @@ -/* CharArrayReader.java -- Read an array of characters as a stream - Copyright (C) 1998, 2001, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.io; - -/** - * This class permits an array of chars to be read as an input stream. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Warren Levy (warrenl@cygnus.com) - */ -public class CharArrayReader extends Reader -{ - /** - * The array that contains the data supplied during read operations - */ - protected char[] buf; - - /** - * The array index of the next char to be read from the buffer - * <code>buf</code> - */ - protected int pos; - - /** - * The currently marked position in the stream. This defaults to 0, so a - * reset operation on the stream resets it to read from array index 0 in - * the buffer - even if the stream was initially created with an offset - * greater than 0 - */ - protected int markedPos; - - /** - * This indicates the maximum number of chars that can be read from this - * stream. It is the array index of the position after the last valid - * char in the buffer <code>buf</code> - */ - protected int count; - - /** - * Create a new CharArrayReader that will read chars from the passed - * in char array. This stream will read from the beginning to the end - * of the array. It is identical to calling an overloaded constructor - * as <code>CharArrayReader(buf, 0, buf.length)</code>. - * <p> - * Note that this array is not copied. If its contents are changed - * while this stream is being read, those changes will be reflected in the - * chars supplied to the reader. Please use caution in changing the - * contents of the buffer while this stream is open. - * - * @param buffer The char array buffer this stream will read from. - */ - public CharArrayReader(char[] buffer) - { - this(buffer, 0, buffer.length); - } - - /** - * Create a new CharArrayReader that will read chars from the passed - * in char array. This stream will read from position - * <code>offset</code> in the array for a length of - * <code>length</code> chars past <code>offset</code>. If the - * stream is reset to a position before <code>offset</code> then - * more than <code>length</code> chars can be read from the stream. - * The <code>length</code> value should be viewed as the array index - * one greater than the last position in the buffer to read. - * <p> - * Note that this array is not copied. If its contents are changed - * while this stream is being read, those changes will be reflected in the - * chars supplied to the reader. Please use caution in changing the - * contents of the buffer while this stream is open. - * - * @param buffer The char array buffer this stream will read from. - * @param offset The index into the buffer to start reading chars from - * @param length The number of chars to read from the buffer - */ - public CharArrayReader(char[] buffer, int offset, int length) - { - super(); - if (offset < 0 || length < 0 || offset > buffer.length) - throw new IllegalArgumentException(); - - buf = buffer; - - count = offset + length; - if (count > buf.length) - count = buf.length; - - pos = offset; - markedPos = pos; - } - - /** - * This method closes the stream. - */ - public void close() - { - synchronized (lock) - { - buf = null; - } - } - - /** - * This method sets the mark position in this stream to the current - * position. Note that the <code>readlimit</code> parameter in this - * method does nothing as this stream is always capable of - * remembering all the chars int it. - * <p> - * Note that in this class the mark position is set by default to - * position 0 in the stream. This is in constrast to some other - * stream types where there is no default mark position. - * - * @param readAheadLimit The number of chars this stream must - * remember. This parameter is ignored. - * - * @exception IOException If an error occurs - */ - public void mark(int readAheadLimit) throws IOException - { - synchronized (lock) - { - if (buf == null) - throw new IOException("Stream closed"); - // readAheadLimit is ignored per Java Class Lib. book, p. 318. - markedPos = pos; - } - } - - /** - * This method overrides the <code>markSupported</code> method in - * <code>Reader</code> in order to return <code>true</code> - - * indicating that this stream class supports mark/reset - * functionality. - * - * @return <code>true</code> to indicate that this class supports - * mark/reset. - */ - public boolean markSupported() - { - return true; - } - - /** - * This method reads one char from the stream. The <code>pos</code> - * counter is advanced to the next char to be read. The char read - * is returned as an int in the range of 0-65535. If the stream - * position is already at the end of the buffer, no char is read and - * a -1 is returned in order to indicate the end of the stream. - * - * @return The char read, or -1 if end of stream - */ - public int read() throws IOException - { - synchronized (lock) - { - if (buf == null) - throw new IOException("Stream closed"); - - if (pos < 0) - throw new ArrayIndexOutOfBoundsException(pos); - - if (pos < count) - return ((int) buf[pos++]) & 0xFFFF; - return -1; - } - } - - /** - * This method reads chars from the stream and stores them into a - * caller supplied buffer. It starts storing the data at index - * <code>offset</code> into the buffer and attempts to read - * <code>len</code> chars. This method can return before reading - * the number of chars requested if the end of the stream is - * encountered first. The actual number of chars read is returned. - * If no chars can be read because the stream is already at the end - * of stream position, a -1 is returned. - * <p> - * This method does not block. - * - * @param b The array into which the chars read should be stored. - * @param off The offset into the array to start storing chars - * @param len The requested number of chars to read - * - * @return The actual number of chars read, or -1 if end of stream. - */ - public int read(char[] b, int off, int len) throws IOException - { - synchronized (lock) - { - if (buf == null) - throw new IOException("Stream closed"); - - /* Don't need to check pos value, arraycopy will check it. */ - if (off < 0 || len < 0 || off + len > b.length) - throw new IndexOutOfBoundsException(); - - if (pos >= count) - return -1; - - int numChars = Math.min(count - pos, len); - System.arraycopy(buf, pos, b, off, numChars); - pos += numChars; - return numChars; - } - } - - /** - * Return true if more characters are available to be read. - * - * @return <code>true</code> to indicate that this stream is ready - * to be read. - * - * @specnote The JDK 1.3 API docs are wrong here. This method will - * return false if there are no more characters available. - */ - public boolean ready() throws IOException - { - if (buf == null) - throw new IOException("Stream closed"); - - return (pos < count); - } - - /** - * This method sets the read position in the stream to the mark - * point by setting the <code>pos</code> variable equal to the - * <code>mark</code> variable. Since a mark can be set anywhere in - * the array, the mark/reset methods int this class can be used to - * provide random search capabilities for this type of stream. - */ - public void reset() throws IOException - { - synchronized (lock) - { - if (buf == null) - throw new IOException("Stream closed"); - - pos = markedPos; - } - } - - /** - * This method attempts to skip the requested number of chars in the - * input stream. It does this by advancing the <code>pos</code> value by the - * specified number of chars. It this would exceed the length of the - * buffer, then only enough chars are skipped to position the stream at - * the end of the buffer. The actual number of chars skipped is returned. - * - * @param n The requested number of chars to skip - * - * @return The actual number of chars skipped. - */ - public long skip(long n) throws IOException - { - synchronized (lock) - { - if (buf == null) - throw new IOException("Stream closed"); - - // Even though the var numChars is a long, in reality it can never - // be larger than an int since the result of subtracting 2 positive - // ints will always fit in an int. Since we have to return a long - // anyway, numChars might as well just be a long. - long numChars = Math.min((long) (count - pos), n < 0 ? 0L : n); - pos += numChars; - return numChars; - } - } -} diff --git a/libjava/java/io/CharArrayWriter.java b/libjava/java/io/CharArrayWriter.java deleted file mode 100644 index f9b338fe0cc..00000000000 --- a/libjava/java/io/CharArrayWriter.java +++ /dev/null @@ -1,274 +0,0 @@ -/* CharArrayWriter.java -- Write chars to a buffer - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.io; - -/** - * This class allows data to be written to a char array buffer and - * and then retrieved by an application. The internal char array - * buffer is dynamically resized to hold all the data written. Please - * be aware that writing large amounts to data to this stream will - * cause large amounts of memory to be allocated. - * <p> - * The size of the internal buffer defaults to 32 and it is resized - * in increments of 1024 chars. This behavior can be over-ridden by using the - * following two properties: - * <p> - * <ul> - * <li><xmp>gnu.java.io.CharArrayWriter.initialBufferSize</xmp></li> - * <li><xmp>gnu.java.io.CharArrayWriter.bufferIncrementSize</xmp></li> - * </ul> - * <p> - * There is a constructor that specified the initial buffer size and - * that is the preferred way to set that value because it it portable - * across all Java class library implementations. - * <p> - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Tom Tromey (tromey@cygnus.com) - */ -public class CharArrayWriter extends Writer -{ - /** - * The default initial buffer size - */ - private static final int DEFAULT_INITIAL_BUFFER_SIZE = 32; - - /** - * This method initializes a new <code>CharArrayWriter</code> with - * the default buffer size of 32 chars. If a different initial - * buffer size is desired, see the constructor - * <code>CharArrayWriter(int size)</code>. - */ - public CharArrayWriter () - { - this (DEFAULT_INITIAL_BUFFER_SIZE); - } - - /** - * This method initializes a new <code>CharArrayWriter</code> with - * a specified initial buffer size. - * - * @param size The initial buffer size in chars - */ - public CharArrayWriter (int size) - { - super (); - buf = new char[size]; - } - - /** - * Closes the stream. This method is guaranteed not to free the contents - * of the internal buffer, which can still be retrieved. - */ - public void close () - { - } - - /** - * This method flushes all buffered chars to the stream. - */ - public void flush () - { - } - - /** - * This method discards all of the chars that have been written to the - * internal buffer so far by setting the <code>count</code> variable to - * 0. The internal buffer remains at its currently allocated size. - */ - public void reset () - { - synchronized (lock) - { - count = 0; - } - } - - /** - * This method returns the number of chars that have been written to - * the buffer so far. This is the same as the value of the protected - * <code>count</code> variable. If the <code>reset</code> method is - * called, then this value is reset as well. Note that this method does - * not return the length of the internal buffer, but only the number - * of chars that have been written to it. - * - * @return The number of chars in the internal buffer - * - * @see #reset() - */ - public int size () - { - return count; - } - - /** - * This method returns a char array containing the chars that have been - * written to this stream so far. This array is a copy of the valid - * chars in the internal buffer and its length is equal to the number of - * valid chars, not necessarily to the the length of the current - * internal buffer. Note that since this method allocates a new array, - * it should be used with caution when the internal buffer is very large. - */ - public char[] toCharArray () - { - synchronized (lock) - { - char[] nc = new char[count]; - System.arraycopy(buf, 0, nc, 0, count); - return nc; - } - } - - /** - * Returns the chars in the internal array as a <code>String</code>. The - * chars in the buffer are converted to characters using the system default - * encoding. There is an overloaded <code>toString()</code> method that - * allows an application specified character encoding to be used. - * - * @return A <code>String</code> containing the data written to this - * stream so far - */ - public String toString () - { - synchronized (lock) - { - return new String (buf, 0, count); - } - } - - /** - * This method writes the writes the specified char into the internal - * buffer. - * - * @param oneChar The char to be read passed as an int - */ - public void write (int oneChar) - { - synchronized (lock) - { - resize (1); - buf[count++] = (char) oneChar; - } - } - - /** - * This method writes <code>len</code> chars from the passed in array - * <code>buf</code> starting at index <code>offset</code> into that buffer - * - * @param buffer The char array to write data from - * @param offset The index into the buffer to start writing data from - * @param len The number of chars to write - */ - public void write (char[] buffer, int offset, int len) - { - synchronized (lock) - { - if (len >= 0) - resize (len); - System.arraycopy(buffer, offset, buf, count, len); - count += len; - } - } - - /** - * This method writes <code>len</code> chars from the passed in - * <code>String</code> <code>buf</code> starting at index - * <code>offset</code> into the internal buffer. - * - * @param str The <code>String</code> to write data from - * @param offset The index into the string to start writing data from - * @param len The number of chars to write - */ - public void write (String str, int offset, int len) - { - synchronized (lock) - { - if (len >= 0) - resize (len); - str.getChars(offset, offset + len, buf, count); - count += len; - } - } - - /** - * This method writes all the chars that have been written to this stream - * from the internal buffer to the specified <code>Writer</code>. - * - * @param out The <code>Writer</code> to write to - * - * @exception IOException If an error occurs - */ - public void writeTo (Writer out) throws IOException - { - synchronized (lock) - { - out.write(buf, 0, count); - } - } - - /** - * This private method makes the buffer bigger when we run out of room - * by allocating a larger buffer and copying the valid chars from the - * old array into it. This is obviously slow and should be avoided by - * application programmers by setting their initial buffer size big - * enough to hold everything if possible. - */ - private void resize (int len) - { - if (count + len >= buf.length) - { - int newlen = buf.length * 2; - if (count + len > newlen) - newlen = count + len; - char[] newbuf = new char[newlen]; - System.arraycopy(buf, 0, newbuf, 0, count); - buf = newbuf; - } - } - - /** - * The internal buffer where the data written is stored - */ - protected char[] buf; - - /** - * The number of chars that have been written to the buffer - */ - protected int count; -} diff --git a/libjava/java/io/CharConversionException.java b/libjava/java/io/CharConversionException.java deleted file mode 100644 index a7a608429ef..00000000000 --- a/libjava/java/io/CharConversionException.java +++ /dev/null @@ -1,73 +0,0 @@ -/* CharConversionException.java -- Character conversion exceptions - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.io; - -/** - * This exception is thrown to indicate that a problem occurred with - * an attempted character conversion. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Tom Tromey (tromey@cygnus.com) - * @since 1.1 - * @status updated to 1.4 - */ -public class CharConversionException extends IOException -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = -8680016352018427031L; - - /** - * Create an exception without a descriptive error message. - */ - public CharConversionException() - { - } - - /** - * Create an exception with a descriptive error message. - * - * @param message the descriptive error message - */ - public CharConversionException(String message) - { - super(message); - } -} // class CharConversionException diff --git a/libjava/java/io/DataInput.java b/libjava/java/io/DataInput.java deleted file mode 100644 index 45cb0c13025..00000000000 --- a/libjava/java/io/DataInput.java +++ /dev/null @@ -1,456 +0,0 @@ -/* DataInput.java -- Interface for reading data from a stream - Copyright (C) 1998, 1999, 2001, 2003, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.io; - -/* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3 - * "The Java Language Specification", ISBN 0-201-63451-1 - * plus online API docs for JDK 1.2 beta from http://www.javasoft.com. - * Status: Believed complete and correct. */ - -/** - * This interface is implemented by classes that can data from streams - * into Java primitive types. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Warren Levy (warrenl@cygnus.com) - */ -public interface DataInput -{ - - /** - * This method reads a Java boolean value from an input stream. It does - * so by reading a single byte of data. If that byte is zero, then the - * value returned is <code>false</code>. If the byte is non-zero, then - * the value returned is <code>true</code>. - * <p> - * This method can read a <code>boolean</code> written by an object - * implementing the <code>writeBoolean()</code> method in the - * <code>DataOutput</code> interface. - * - * @return The <code>boolean</code> value read - * - * @exception EOFException If end of file is reached before - * reading the boolean - * @exception IOException If any other error occurs - * - * @see DataOutput#writeBoolean - */ - boolean readBoolean() throws EOFException, IOException; - - /** - * This method reads a Java byte value from an input stream. The value - * is in the range of -128 to 127. - * <p> - * This method can read a <code>byte</code> written by an object - * implementing the - * <code>writeByte()</code> method in the <code>DataOutput</code> interface. - * <p> - * @return The <code>byte</code> value read - * - * @exception EOFException If end of file is reached before reading the byte - * @exception IOException If any other error occurs - * - * @see DataOutput#writeByte - */ - byte readByte() throws EOFException, IOException; - - /** - * This method reads 8 unsigned bits into a Java <code>int</code> value from - * the stream. The value returned is in the range of 0 to 255. - * <p> - * This method can read an unsigned byte written by an object - * implementing the - * <code>writeByte()</code> method in the <code>DataOutput</code> - * interface. - * - * @return The unsigned bytes value read as a Java <code>int</code>. - * - * @exception EOFException If end of file is reached before reading the value - * @exception IOException If any other error occurs - * - * @see DataOutput#writeByte - */ - int readUnsignedByte() throws EOFException, IOException; - - /** - * This method reads a Java <code>char</code> value from an input stream. - * It operates by reading two bytes from the stream and converting them to - * a single 16-bit Java <code>char</code>. The two bytes are stored most - * significant byte first (i.e., "big endian") regardless of the native - * host byte ordering. - * <p> - * As an example, if <code>byte1</code> and <code>byte2</code> represent the - * first and second byte read from the stream respectively, they will be - * transformed to a <code>char</code> in the following manner: - * <p> - * <code>(char)((byte1 << 8) + byte2)</code> - * <p> - * This method can read a <code>char</code> written by an object implementing - * the - * <code>writeChar()</code> method in the <code>DataOutput</code> interface. - * - * @return The <code>char</code> value read - * - * @exception EOFException If end of file is reached before reading the char - * @exception IOException If any other error occurs - * - * @see DataOutput#writeChar - */ - char readChar() throws EOFException, IOException; - - /** - * This method reads a signed 16-bit value into a Java in from the stream. - * It operates by reading two bytes from the stream and converting them to - * a single 16-bit Java <code>short</code>. The two bytes are stored most - * significant byte first (i.e., "big endian") regardless of the native - * host byte ordering. - * <p> - * As an example, if <code>byte1</code> and <code>byte2</code> represent the - * first and second byte read from the stream respectively, they will be - * transformed to a <code>short</code> in the following manner: - * <p> - * <code>(short)(((byte1 & 0xFF) << 8) + (byte2 & 0xFF))</code> - * <p> - * The value returned is in the range of -32768 to 32767. - * <p> - * This method can read a <code>short</code> written by an object - * implementing - * the <code>writeShort()</code> method in the <code>DataOutput</code> - * interface. - * - * @return The <code>short</code> value read - * - * @exception EOFException If end of file is reached before reading the value - * @exception IOException If any other error occurs - * - * @see DataOutput#writeShort - */ - short readShort() throws EOFException, IOException; - - /** - * This method reads 16 unsigned bits into a Java int value from the stream. - * It operates by reading two bytes from the stream and converting them to - * a single Java <code>int</code>. The two bytes are stored most - * significant byte first (i.e., "big endian") regardless of the native - * host byte ordering. - * <p> - * As an example, if <code>byte1</code> and <code>byte2</code> represent the - * first and second byte read from the stream respectively, they will be - * transformed to an <code>int</code> in the following manner: - * <p> - * <code>(int)(((byte1 0xFF) << 8) + (byte2 & 0xFF))</code> - * <p> - * The value returned is in the range of 0 to 65535. - * <p> - * This method can read an unsigned short written by an object implementing - * the <code>writeShort()</code> method in the - * <code>DataOutput</code> - * interface. - * - * @return The unsigned short value read as a Java <code>int</code>. - * - * @exception EOFException If end of file is reached before reading - * the value - * @exception IOException If any other error occurs - * - * @see DataOutput#writeShort - */ - int readUnsignedShort() throws EOFException, IOException; - - /** - * This method reads a Java <code>int</code> value from an input stream - * It operates by reading four bytes from the stream and converting them to - * a single Java <code>int</code>. The bytes are stored most - * significant byte first (i.e., "big endian") regardless of the native - * host byte ordering. - * <p> - * As an example, if <code>byte1</code> through <code>byte4</code> represent - * the first four bytes read from the stream, they will be - * transformed to an <code>int</code> in the following manner: - * <p> - * <code>(int)(((byte1 & 0xFF) << 24) + ((byte2 & 0xFF) << 16) + - * ((byte3 & 0xFF)<< 8) + (byte4 & 0xFF)))</code> - * <p> - * The value returned is in the range of -2147483648 to 2147483647. - * <p> - * This method can read an <code>int</code> written by an object - * implementing the <code>writeInt()</code> method in the - * <code>DataOutput</code> interface. - * - * @return The <code>int</code> value read - * - * @exception EOFException If end of file is reached before reading the int - * @exception IOException If any other error occurs - * - * @see DataOutput#writeInt - */ - int readInt() throws EOFException, IOException; - - /** - * This method reads a Java <code>long</code> value from an input stream - * It operates by reading eight bytes from the stream and converting them to - * a single Java <code>long</code>. The bytes are stored most - * significant byte first (i.e., "big endian") regardless of the native - * host byte ordering. - * <p> - * As an example, if <code>byte1</code> through <code>byte8</code> represent - * the first eight bytes read from the stream, they will be - * transformed to an <code>long</code> in the following manner: - * <p> - * <code>(long)(((byte1 & 0xFF) << 56) + ((byte2 & 0xFF) << 48) + - * ((byte3 & 0xFF) << 40) + ((byte4 & 0xFF) << 32) + - * ((byte5 & 0xFF) << 24) + ((byte6 & 0xFF) << 16) + - * ((byte7 & 0xFF) << 8) + (byte8 & 0xFF))) - * </code> - * <p> - * The value returned is in the range of -9223372036854775808 to - * 9223372036854775807. - * <p> - * This method can read an <code>long</code> written by an object - * implementing the <code>writeLong()</code> method in the - * <code>DataOutput</code> interface. - * - * @return The <code>long</code> value read - * - * @exception EOFException If end of file is reached before reading the long - * @exception IOException If any other error occurs - * - * @see DataOutput#writeLong - */ - long readLong() throws EOFException, IOException; - - /** - * This method reads a Java float value from an input stream. It operates - * by first reading an <code>int</code> value from the stream by calling the - * <code>readInt()</code> method in this interface, then converts that - * <code>int</code> to a <code>float</code> using the - * <code>intBitsToFloat</code> method in the class - * <code>java.lang.Float</code>. - * <p> - * This method can read a <code>float</code> written by an object - * implementing - * the <code>writeFloat()</code> method in the <code>DataOutput</code> - * interface. - * - * @return The <code>float</code> value read - * - * @exception EOFException If end of file is reached before reading the - * float - * @exception IOException If any other error occurs - * - * @see DataOutput#writeFloat - * @see java.lang.Float#intBitsToFloat - */ - float readFloat() throws EOFException, IOException; - - /** - * This method reads a Java double value from an input stream. It operates - * by first reading a <code>long</code> value from the stream by calling the - * <code>readLong()</code> method in this interface, then converts that - * <code>long</code> to a <code>double</code> using the - * <code>longBitsToDouble</code> method in the class - * <code>java.lang.Double</code>. - * <p> - * This method can read a <code>double</code> written by an object - * implementing the <code>writeDouble()</code> method in the - * <code>DataOutput</code> interface. - * - * @return The <code>double</code> value read - * - * @exception EOFException If end of file is reached before reading the - * double - * @exception IOException If any other error occurs - * - * @see DataOutput#writeDouble - * @see java.lang.Double#longBitsToDouble - */ - double readDouble() throws EOFException, IOException; - - /** - * This method reads the next line of text data from an input stream. - * It operates by reading bytes and converting those bytes to - * <code>char</code> - * values by treating the byte read as the low eight bits of the - * <code>char</code> and using 0 as the high eight bits. Because of this, - * it does not support the full 16-bit Unicode character set. - * <P> - * The reading of bytes ends when either the end of file or a line terminator - * is encountered. The bytes read are then returned as a - * <code>String</code>. - * A line terminator is a byte sequence consisting of either - * <code>\r</code>, <code>\n</code> or <code>\r\n</code>. These termination - * charaters are discarded and are not returned as part of the string. - * A line is also terminated by an end of file condition. - * <p> - * - * @return The line read as a <code>String</code> - * - * @exception IOException If an error occurs - */ - String readLine() throws IOException; - - /** - * This method reads a <code>String</code> from an input stream that is - * encoded in a modified UTF-8 format. This format has a leading two byte - * sequence that contains the remaining number of bytes to read. - * This two byte - * sequence is read using the <code>readUnsignedShort()</code> method of this - * interface. - * - * After the number of remaining bytes have been determined, these bytes - * are read an transformed into <code>char</code> values. These - * <code>char</code> values are encoded in the stream using either a one, - * two, or three byte format. - * The particular format in use can be determined by examining the first - * byte read. - * <p> - * If the first byte has a high order bit of 0, then - * that character consists on only one byte. This character value consists - * of seven bits that are at positions 0 through 6 of the byte. As an - * example, if <code>byte1</code> is the byte read from the stream, it would - * be converted to a <code>char</code> like so: - * <p> - * <code>(char)byte1</code> - * <p> - * If the first byte has 110 as its high order bits, then the - * character consists of two bytes. The bits that make up the character - * value are in positions 0 through 4 of the first byte and bit positions - * 0 through 5 of the second byte. (The second byte should have - * 10 as its high order bits). These values are in most significant - * byte first (i.e., "big endian") order. - * <p> - * As an example, if <code>byte1</code> and <code>byte2</code> are the first - * two bytes read respectively, and the high order bits of them match the - * patterns which indicate a two byte character encoding, then they would be - * converted to a Java <code>char</code> like so: - * <p> - * <code>(char)(((byte1 & 0x1F) << 6) + (byte2 & 0x3F))</code> - * <p> - * If the first byte has a 1110 as its high order bits, then the - * character consists of three bytes. The bits that make up the character - * value are in positions 0 through 3 of the first byte and bit positions - * 0 through 5 of the other two bytes. (The second and third bytes should - * have 10 as their high order bits). These values are in most - * significant byte first (i.e., "big endian") order. - * <p> - * As an example, if <code>byte1</code>, <code>byte2</code>, and - * <code>byte3</code> are the three bytes read, and the high order bits of - * them match the patterns which indicate a three byte character encoding, - * then they would be converted to a Java <code>char</code> like so: - * - * <code> - * (char)(((byte1 & 0x0F) << 12) + ((byte2 & 0x3F) + (byte3 & 0x3F)) - * </code> - * - * Note that all characters are encoded in the method that requires the - * fewest number of bytes with the exception of the character with the - * value of <code>\<llll>u0000</code> which is encoded as two bytes. - * This is a modification of the UTF standard used to prevent C language - * style <code>NUL</code> values from appearing in the byte stream. - * <p> - * This method can read data that was written by an object implementing the - * <code>writeUTF()</code> method in <code>DataOutput</code>. - * - * @return The <code>String</code> read - * - * @exception EOFException If end of file is reached before reading the - * String - * @exception UTFDataFormatException If the data is not in UTF-8 format - * @exception IOException If any other error occurs - * - * @see DataOutput#writeUTF - */ - String readUTF() throws EOFException, UTFDataFormatException, IOException; - - /** - * This method reads raw bytes into the passed array until the array is - * full. Note that this method blocks until the data is available and - * throws an exception if there is not enough data left in the stream to - * fill the buffer. Note also that zero length buffers are permitted. - * In this case, the method will return immediately without reading any - * bytes from the stream. - * - * @param buf The buffer into which to read the data - * - * @exception EOFException If end of file is reached before filling the - * buffer - * @exception IOException If any other error occurs - */ - void readFully(byte[] buf) throws EOFException, IOException; - - /** - * This method reads raw bytes into the passed array <code>buf</code> - * starting - * <code>offset</code> bytes into the buffer. The number of bytes read - * will be - * exactly <code>len</code>. Note that this method blocks until the data is - * available and throws an exception if there is not enough data left in - * the stream to read <code>len</code> bytes. Note also that zero length - * buffers are permitted. In this case, the method will return immediately - * without reading any bytes from the stream. - * - * @param buf The buffer into which to read the data - * @param offset The offset into the buffer to start storing data - * @param len The number of bytes to read into the buffer - * - * @exception EOFException If end of file is reached before filling the - * buffer - * @exception IOException If any other error occurs - */ - void readFully(byte[] buf, int offset, int len) - throws EOFException, IOException; - - /** - * This method skips and discards the specified number of bytes in an - * input stream. Note that this method may skip less than the requested - * number of bytes. The actual number of bytes skipped is returned. - * No bytes are skipped if a negative number is passed to this method. - * - * @param numBytes The number of bytes to skip - * - * @return The number of bytes actually skipped, which will always be - * <code>numBytes</code> - * - * @exception EOFException If end of file is reached before all bytes can be - * skipped - * @exception IOException If any other error occurs - */ - int skipBytes(int numBytes) throws EOFException, IOException; - -} // interface DataInput diff --git a/libjava/java/io/DataInputStream.java b/libjava/java/io/DataInputStream.java deleted file mode 100644 index da60a8e8c68..00000000000 --- a/libjava/java/io/DataInputStream.java +++ /dev/null @@ -1,739 +0,0 @@ -/* DataInputStream.java -- FilteredInputStream that implements DataInput - Copyright (C) 1998, 1999, 2000, 2001, 2003, 2005 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.io; - -/* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3 - * "The Java Language Specification", ISBN 0-201-63451-1 - * plus online API docs for JDK 1.2 beta from http://www.javasoft.com. - * Status: Believed complete and correct. - */ - -/** - * This subclass of <code>FilteredInputStream</code> implements the - * <code>DataInput</code> interface that provides method for reading primitive - * Java data types from a stream. - * - * @see DataInput - * - * @author Warren Levy (warrenl@cygnus.com) - * @author Aaron M. Renn (arenn@urbanophile.com) - * @date October 20, 1998. - */ -public class DataInputStream extends FilterInputStream implements DataInput -{ - // Byte buffer, used to make primitive read calls more efficient. - byte[] buf = new byte [8]; - - /** - * This constructor initializes a new <code>DataInputStream</code> - * to read from the specified subordinate stream. - * - * @param in The subordinate <code>InputStream</code> to read from - */ - public DataInputStream (InputStream in) - { - super (in); - } - - /** - * This method reads bytes from the underlying stream into the specified - * byte array buffer. It will attempt to fill the buffer completely, but - * may return a short count if there is insufficient data remaining to be - * read to fill the buffer. - * - * @param b The buffer into which bytes will be read. - * - * @return The actual number of bytes read, or -1 if end of stream reached - * before reading any bytes. - * - * @exception IOException If an error occurs. - */ - public final int read (byte[] b) throws IOException - { - return in.read (b, 0, b.length); - } - - /** - * This method reads bytes from the underlying stream into the specified - * byte array buffer. It will attempt to read <code>len</code> bytes and - * will start storing them at position <code>off</code> into the buffer. - * This method can return a short count if there is insufficient data - * remaining to be read to complete the desired read length. - * - * @param b The buffer into which bytes will be read. - * @param off The offset into the buffer to start storing bytes. - * @param len The requested number of bytes to read. - * - * @return The actual number of bytes read, or -1 if end of stream reached - * before reading any bytes. - * - * @exception IOException If an error occurs. - */ - public final int read (byte[] b, int off, int len) throws IOException - { - return in.read (b, off, len); - } - - /** - * This method reads a Java boolean value from an input stream. It does - * so by reading a single byte of data. If that byte is zero, then the - * value returned is <code>false</code>. If the byte is non-zero, then - * the value returned is <code>true</code>. - * <p> - * This method can read a <code>boolean</code> written by an object - * implementing the <code>writeBoolean()</code> method in the - * <code>DataOutput</code> interface. - * - * @return The <code>boolean</code> value read - * - * @exception EOFException If end of file is reached before reading - * the boolean - * @exception IOException If any other error occurs - * - * @see DataOutput#writeBoolean - */ - public final boolean readBoolean () throws IOException - { - return convertToBoolean (in.read ()); - } - - /** - * This method reads a Java byte value from an input stream. The value - * is in the range of -128 to 127. - * <p> - * This method can read a <code>byte</code> written by an object - * implementing the <code>writeByte()</code> method in the - * <code>DataOutput</code> interface. - * - * @return The <code>byte</code> value read - * - * @exception EOFException If end of file is reached before reading the byte - * @exception IOException If any other error occurs - * - * @see DataOutput#writeByte - */ - public final byte readByte () throws IOException - { - return convertToByte (in.read ()); - } - - /** - * This method reads a Java <code>char</code> value from an input stream. - * It operates by reading two bytes from the stream and converting them to - * a single 16-bit Java <code>char</code>. The two bytes are stored most - * significant byte first (i.e., "big endian") regardless of the native - * host byte ordering. - * <p> - * As an example, if <code>byte1</code> and <code>byte2</code> - * represent the first and second byte read from the stream - * respectively, they will be transformed to a <code>char</code> in - * the following manner: - * <p> - * <code>(char)(((byte1 & 0xFF) << 8) | (byte2 & 0xFF)</code> - * <p> - * This method can read a <code>char</code> written by an object - * implementing the <code>writeChar()</code> method in the - * <code>DataOutput</code> interface. - * - * @return The <code>char</code> value read - * - * @exception EOFException If end of file is reached before reading the char - * @exception IOException If any other error occurs - * - * @see DataOutput#writeChar - */ - public final char readChar () throws IOException - { - readFully (buf, 0, 2); - return convertToChar (buf); - } - - /** - * This method reads a Java double value from an input stream. It operates - * by first reading a <code>long</code> value from the stream by calling the - * <code>readLong()</code> method in this interface, then converts - * that <code>long</code> to a <code>double</code> using the - * <code>longBitsToDouble</code> method in the class - * <code>java.lang.Double</code> - * <p> - * This method can read a <code>double</code> written by an object - * implementing the <code>writeDouble()</code> method in the - * <code>DataOutput</code> interface. - * - * @return The <code>double</code> value read - * - * @exception EOFException If end of file is reached before reading - * the double - * @exception IOException If any other error occurs - * - * @see DataOutput#writeDouble - * @see java.lang.Double#longBitsToDouble - */ - public final double readDouble () throws IOException - { - return Double.longBitsToDouble (readLong ()); - } - - /** - * This method reads a Java float value from an input stream. It - * operates by first reading an <code>int</code> value from the - * stream by calling the <code>readInt()</code> method in this - * interface, then converts that <code>int</code> to a - * <code>float</code> using the <code>intBitsToFloat</code> method - * in the class <code>java.lang.Float</code> - * <p> - * This method can read a <code>float</code> written by an object - * implementing the <code>writeFloat()</code> method in the - * <code>DataOutput</code> interface. - * - * @return The <code>float</code> value read - * - * @exception EOFException If end of file is reached before reading the float - * @exception IOException If any other error occurs - * - * @see DataOutput#writeFloat - * @see java.lang.Float#intBitsToFloat - */ - public final float readFloat () throws IOException - { - return Float.intBitsToFloat (readInt ()); - } - - /** - * This method reads raw bytes into the passed array until the array is - * full. Note that this method blocks until the data is available and - * throws an exception if there is not enough data left in the stream to - * fill the buffer. Note also that zero length buffers are permitted. - * In this case, the method will return immediately without reading any - * bytes from the stream. - * - * @param b The buffer into which to read the data - * - * @exception EOFException If end of file is reached before filling the - * buffer - * @exception IOException If any other error occurs - */ - public final void readFully (byte[] b) throws IOException - { - readFully (b, 0, b.length); - } - - /** - * This method reads raw bytes into the passed array <code>buf</code> - * starting - * <code>offset</code> bytes into the buffer. The number of bytes read - * will be - * exactly <code>len</code>. Note that this method blocks until the data is - * available and throws an exception if there is not enough data left in - * the stream to read <code>len</code> bytes. Note also that zero length - * buffers are permitted. In this case, the method will return immediately - * without reading any bytes from the stream. - * - * @param buf The buffer into which to read the data - * @param offset The offset into the buffer to start storing data - * @param len The number of bytes to read into the buffer - * - * @exception EOFException If end of file is reached before filling the - * buffer - * @exception IOException If any other error occurs - */ - public final void readFully (byte[] buf, int offset, int len) throws IOException - { - if (len < 0) - throw new IndexOutOfBoundsException("Negative length: " + len); - - while (len > 0) - { - // in.read will block until some data is available. - int numread = in.read (buf, offset, len); - if (numread < 0) - throw new EOFException (); - len -= numread; - offset += numread; - } - } - - /** - * This method reads a Java <code>int</code> value from an input stream - * It operates by reading four bytes from the stream and converting them to - * a single Java <code>int</code>. The bytes are stored most - * significant byte first (i.e., "big endian") regardless of the native - * host byte ordering. - * <p> - * As an example, if <code>byte1</code> through <code>byte4</code> represent - * the first four bytes read from the stream, they will be - * transformed to an <code>int</code> in the following manner: - * <p> - * <code>(int)(((byte1 & 0xFF) << 24) + ((byte2 & 0xFF) << 16) + - * ((byte3 & 0xFF)<< 8) + (byte4 & 0xFF)))</code> - * <p> - * The value returned is in the range of -2147483648 to 2147483647. - * <p> - * This method can read an <code>int</code> written by an object - * implementing the <code>writeInt()</code> method in the - * <code>DataOutput</code> interface. - * - * @return The <code>int</code> value read - * - * @exception EOFException If end of file is reached before reading the int - * @exception IOException If any other error occurs - * - * @see DataOutput#writeInt - */ - public final int readInt () throws IOException - { - readFully (buf, 0, 4); - return convertToInt (buf); - } - - /** - * This method reads the next line of text data from an input - * stream. It operates by reading bytes and converting those bytes - * to <code>char</code> values by treating the byte read as the low - * eight bits of the <code>char</code> and using 0 as the high eight - * bits. Because of this, it does not support the full 16-bit - * Unicode character set. - * <p> - * The reading of bytes ends when either the end of file or a line - * terminator is encountered. The bytes read are then returned as a - * <code>String</code> A line terminator is a byte sequence - * consisting of either <code>\r</code>, <code>\n</code> or - * <code>\r\n</code>. These termination charaters are discarded and - * are not returned as part of the string. - * <p> - * This method can read data that was written by an object implementing the - * <code>writeLine()</code> method in <code>DataOutput</code>. - * - * @return The line read as a <code>String</code> - * - * @exception IOException If an error occurs - * - * @see DataOutput - * - * @deprecated - */ - public final String readLine() throws IOException - { - StringBuffer strb = new StringBuffer(); - - while (true) - { - int c = in.read(); - if (c == -1) // got an EOF - return strb.length() > 0 ? strb.toString() : null; - if (c == '\r') - { - int next_c = in.read(); - if (next_c != '\n' && next_c != -1) - { - if (! (in instanceof PushbackInputStream)) - in = new PushbackInputStream(in); - ((PushbackInputStream) in).unread(next_c); - } - break; - } - if (c == '\n') - break; - strb.append((char) c); - } - - return strb.length() > 0 ? strb.toString() : ""; - } - - /** - * This method reads a Java <code>long</code> value from an input stream - * It operates by reading eight bytes from the stream and converting them to - * a single Java <code>long</code>. The bytes are stored most - * significant byte first (i.e., "big endian") regardless of the native - * host byte ordering. - * <p> - * As an example, if <code>byte1</code> through <code>byte8</code> represent - * the first eight bytes read from the stream, they will be - * transformed to an <code>long</code> in the following manner: - * <p> - * <code>(long)(((byte1 & 0xFF) << 56) + ((byte2 & 0xFF) << 48) + - * ((byte3 & 0xFF) << 40) + ((byte4 & 0xFF) << 32) + - * ((byte5 & 0xFF) << 24) + ((byte6 & 0xFF) << 16) + - * ((byte7 & 0xFF) << 8) + (byte8 & 0xFF))) - * </code> - * <p> - * The value returned is in the range of -9223372036854775808 to - * 9223372036854775807. - * <p> - * This method can read an <code>long</code> written by an object - * implementing the <code>writeLong()</code> method in the - * <code>DataOutput</code> interface. - * - * @return The <code>long</code> value read - * - * @exception EOFException If end of file is reached before reading the long - * @exception IOException If any other error occurs - * - * @see DataOutput#writeLong - */ - public final long readLong () throws IOException - { - readFully (buf, 0, 8); - return convertToLong (buf); - } - - /** - * This method reads a signed 16-bit value into a Java in from the - * stream. It operates by reading two bytes from the stream and - * converting them to a single 16-bit Java <code>short</code>. The - * two bytes are stored most significant byte first (i.e., "big - * endian") regardless of the native host byte ordering. - * <p> - * As an example, if <code>byte1</code> and <code>byte2</code> - * represent the first and second byte read from the stream - * respectively, they will be transformed to a <code>short</code>. in - * the following manner: - * <p> - * <code>(short)(((byte1 & 0xFF) << 8) | (byte2 & 0xFF))</code> - * <p> - * The value returned is in the range of -32768 to 32767. - * <p> - * This method can read a <code>short</code> written by an object - * implementing the <code>writeShort()</code> method in the - * <code>DataOutput</code> interface. - * - * @return The <code>short</code> value read - * - * @exception EOFException If end of file is reached before reading the value - * @exception IOException If any other error occurs - * - * @see DataOutput#writeShort - */ - public final short readShort () throws IOException - { - readFully (buf, 0, 2); - return convertToShort (buf); - } - - /** - * This method reads 8 unsigned bits into a Java <code>int</code> - * value from the stream. The value returned is in the range of 0 to - * 255. - * <p> - * This method can read an unsigned byte written by an object - * implementing the <code>writeUnsignedByte()</code> method in the - * <code>DataOutput</code> interface. - * - * @return The unsigned bytes value read as a Java <code>int</code>. - * - * @exception EOFException If end of file is reached before reading the value - * @exception IOException If any other error occurs - * - * @see DataOutput#writeByte - */ - public final int readUnsignedByte () throws IOException - { - return convertToUnsignedByte (in.read ()); - } - - /** - * This method reads 16 unsigned bits into a Java int value from the stream. - * It operates by reading two bytes from the stream and converting them to - * a single Java <code>int</code> The two bytes are stored most - * significant byte first (i.e., "big endian") regardless of the native - * host byte ordering. - * <p> - * As an example, if <code>byte1</code> and <code>byte2</code> - * represent the first and second byte read from the stream - * respectively, they will be transformed to an <code>int</code> in - * the following manner: - * <p> - * <code>(int)(((byte1 & 0xFF) << 8) + (byte2 & 0xFF))</code> - * <p> - * The value returned is in the range of 0 to 65535. - * <p> - * This method can read an unsigned short written by an object - * implementing the <code>writeUnsignedShort()</code> method in the - * <code>DataOutput</code> interface. - * - * @return The unsigned short value read as a Java <code>int</code> - * - * @exception EOFException If end of file is reached before reading the value - * @exception IOException If any other error occurs - * - * @see DataOutput#writeShort - */ - public final int readUnsignedShort () throws IOException - { - readFully (buf, 0, 2); - return convertToUnsignedShort (buf); - } - - /** - * This method reads a <code>String</code> from an input stream that - * is encoded in a modified UTF-8 format. This format has a leading - * two byte sequence that contains the remaining number of bytes to - * read. This two byte sequence is read using the - * <code>readUnsignedShort()</code> method of this interface. - * <p> - * After the number of remaining bytes have been determined, these - * bytes are read an transformed into <code>char</code> values. - * These <code>char</code> values are encoded in the stream using - * either a one, two, or three byte format. The particular format - * in use can be determined by examining the first byte read. - * <p> - * If the first byte has a high order bit of 0, then that character - * consists on only one byte. This character value consists of - * seven bits that are at positions 0 through 6 of the byte. As an - * example, if <code>byte1</code> is the byte read from the stream, - * it would be converted to a <code>char</code> like so: - * <p> - * <code>(char)byte1</code> - * <p> - * If the first byte has 110 as its high order bits, then the - * character consists of two bytes. The bits that make up the character - * value are in positions 0 through 4 of the first byte and bit positions - * 0 through 5 of the second byte. (The second byte should have - * 10 as its high order bits). These values are in most significant - * byte first (i.e., "big endian") order. - * <p> - * As an example, if <code>byte1</code> and <code>byte2</code> are - * the first two bytes read respectively, and the high order bits of - * them match the patterns which indicate a two byte character - * encoding, then they would be converted to a Java - * <code>char</code> like so: - * <p> - * <code>(char)(((byte1 & 0x1F) << 6) | (byte2 & 0x3F))</code> - * <p> - * If the first byte has a 1110 as its high order bits, then the - * character consists of three bytes. The bits that make up the character - * value are in positions 0 through 3 of the first byte and bit positions - * 0 through 5 of the other two bytes. (The second and third bytes should - * have 10 as their high order bits). These values are in most - * significant byte first (i.e., "big endian") order. - * <p> - * As an example, if <code>byte1</code> <code>byte2</code> and - * <code>byte3</code> are the three bytes read, and the high order - * bits of them match the patterns which indicate a three byte - * character encoding, then they would be converted to a Java - * <code>char</code> like so: - * <p> - * <code>(char)(((byte1 & 0x0F) << 12) | ((byte2 & 0x3F) << 6) | - * (byte3 & 0x3F))</code> - * <p> - * Note that all characters are encoded in the method that requires - * the fewest number of bytes with the exception of the character - * with the value of <code>\u0000</code> which is encoded as two - * bytes. This is a modification of the UTF standard used to - * prevent C language style <code>NUL</code> values from appearing - * in the byte stream. - * <p> - * This method can read data that was written by an object implementing the - * <code>writeUTF()</code> method in <code>DataOutput</code> - * - * @return The <code>String</code> read - * - * @exception EOFException If end of file is reached before reading - * the String - * @exception UTFDataFormatException If the data is not in UTF-8 format - * @exception IOException If any other error occurs - * - * @see DataOutput#writeUTF - */ - public final String readUTF () throws IOException - { - return readUTF (this); - } - - /** - * This method reads a String encoded in UTF-8 format from the - * specified <code>DataInput</code> source. - * - * @param in The <code>DataInput</code> source to read from - * - * @return The String read from the source - * - * @exception IOException If an error occurs - * - * @see DataInput#readUTF - */ - public static final String readUTF(DataInput in) throws IOException - { - final int UTFlen = in.readUnsignedShort (); - byte[] buf = new byte [UTFlen]; - - // This blocks until the entire string is available rather than - // doing partial processing on the bytes that are available and then - // blocking. An advantage of the latter is that Exceptions - // could be thrown earlier. The former is a bit cleaner. - in.readFully (buf, 0, UTFlen); - - return convertFromUTF (buf); - } - - /** - * This method attempts to skip and discard the specified number of bytes - * in the input stream. It may actually skip fewer bytes than requested. - * This method will not skip any bytes if passed a negative number of bytes - * to skip. - * - * @param n The requested number of bytes to skip. - * - * @return The requested number of bytes to skip. - * - * @exception IOException If an error occurs. - * @specnote The JDK docs claim that this returns the number of bytes - * actually skipped. The JCL claims that this method can throw an - * EOFException. Neither of these appear to be true in the JDK 1.3's - * implementation. This tries to implement the actual JDK behaviour. - */ - public final int skipBytes (int n) throws IOException - { - if (n <= 0) - return 0; - try - { - return (int) in.skip (n); - } - catch (EOFException x) - { - // do nothing. - } - return n; - } - - static boolean convertToBoolean (int b) throws EOFException - { - if (b < 0) - throw new EOFException (); - - return (b != 0); - } - - static byte convertToByte (int i) throws EOFException - { - if (i < 0) - throw new EOFException (); - - return (byte) i; - } - - static int convertToUnsignedByte (int i) throws EOFException - { - if (i < 0) - throw new EOFException (); - - return (i & 0xFF); - } - - static char convertToChar (byte[] buf) - { - return (char) ((buf [0] << 8) - | (buf [1] & 0xff)); - } - - static short convertToShort (byte[] buf) - { - return (short) ((buf [0] << 8) - | (buf [1] & 0xff)); - } - - static int convertToUnsignedShort (byte[] buf) - { - return (((buf [0] & 0xff) << 8) - | (buf [1] & 0xff)); - } - - static int convertToInt (byte[] buf) - { - return (((buf [0] & 0xff) << 24) - | ((buf [1] & 0xff) << 16) - | ((buf [2] & 0xff) << 8) - | (buf [3] & 0xff)); - } - - static long convertToLong (byte[] buf) - { - return (((long)(buf [0] & 0xff) << 56) | - ((long)(buf [1] & 0xff) << 48) | - ((long)(buf [2] & 0xff) << 40) | - ((long)(buf [3] & 0xff) << 32) | - ((long)(buf [4] & 0xff) << 24) | - ((long)(buf [5] & 0xff) << 16) | - ((long)(buf [6] & 0xff) << 8) | - ((long)(buf [7] & 0xff))); - } - - // FIXME: This method should be re-thought. I suspect we have multiple - // UTF-8 decoders floating around. We should use the standard charset - // converters, maybe and adding a direct call into one of the new - // NIO converters for a super-fast UTF8 decode. - static String convertFromUTF (byte[] buf) - throws EOFException, UTFDataFormatException - { - // Give StringBuffer an initial estimated size to avoid - // enlarge buffer frequently - StringBuffer strbuf = new StringBuffer (buf.length / 2 + 2); - - for (int i = 0; i < buf.length; ) - { - if ((buf [i] & 0x80) == 0) // bit pattern 0xxxxxxx - strbuf.append ((char) (buf [i++] & 0xFF)); - else if ((buf [i] & 0xE0) == 0xC0) // bit pattern 110xxxxx - { - if (i + 1 >= buf.length - || (buf [i + 1] & 0xC0) != 0x80) - throw new UTFDataFormatException (); - - strbuf.append((char) (((buf [i++] & 0x1F) << 6) - | (buf [i++] & 0x3F))); - } - else if ((buf [i] & 0xF0) == 0xE0) // bit pattern 1110xxxx - { - if (i + 2 >= buf.length - || (buf [i + 1] & 0xC0) != 0x80 - || (buf [i + 2] & 0xC0) != 0x80) - throw new UTFDataFormatException (); - - strbuf.append ((char) (((buf [i++] & 0x0F) << 12) - | ((buf [i++] & 0x3F) << 6) - | (buf [i++] & 0x3F))); - } - else // must be ((buf [i] & 0xF0) == 0xF0 || (buf [i] & 0xC0) == 0x80) - throw new UTFDataFormatException (); // bit patterns 1111xxxx or - // 10xxxxxx - } - - return strbuf.toString (); - } -} diff --git a/libjava/java/io/DataOutput.java b/libjava/java/io/DataOutput.java deleted file mode 100644 index 2eccc552b8e..00000000000 --- a/libjava/java/io/DataOutput.java +++ /dev/null @@ -1,326 +0,0 @@ -/* DataOutput.java -- Interface for writing data from a stream - Copyright (C) 1998, 1999, 2001, 2003, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.io; - -/* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3 - * "The Java Language Specification", ISBN 0-201-63451-1 - * Status: Complete to version 1.1. - */ - -/** - * This interface is implemented by classes that can wrte data to streams - * from Java primitive types. This data can subsequently be read back - * by classes implementing the <code>DataInput</code> interface. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Tom Tromey (tromey@cygnus.com) - * - * @see DataInput - */ -public interface DataOutput -{ - /** - * This method writes a Java boolean value to an output stream. If - * <code>value</code> is <code>true</code>, a byte with the value of - * 1 will be written, otherwise a byte with the value of 0 will be - * written. - * - * The value written can be read using the <code>readBoolean</code> - * method in <code>DataInput</code>. - * - * @param value The boolean value to write - * - * @exception IOException If an error occurs - * - * @see DataInput#readBoolean - */ - void writeBoolean(boolean value) throws IOException; - - /** - * This method writes a Java byte value to an output stream. The - * byte to be written will be in the lowest 8 bits of the - * <code>int</code> value passed. - * - * The value written can be read using the <code>readByte</code> or - * <code>readUnsignedByte</code> methods in <code>DataInput</code>. - * - * @param value The int value to write - * - * @exception IOException If an error occurs - * - * @see DataInput#readByte - * @see DataInput#readUnsignedByte - */ - void writeByte(int value) throws IOException; - - /** - * This method writes a Java char value to an output stream. The - * char to be written will be in the lowest 16 bits of the <code>int</code> - * value passed. These bytes will be written "big endian". That is, - * with the high byte written first in the following manner: - * <p> - * <code>byte0 = (byte)((value & 0xFF00) >> 8);<br> - * byte1 = (byte)(value & 0x00FF);</code> - * <p> - * - * The value written can be read using the <code>readChar</code> - * method in <code>DataInput</code>. - * - * @param value The char value to write - * - * @exception IOException If an error occurs - * - * @see DataInput#readChar - */ - void writeChar(int value) throws IOException; - - /** - * This method writes a Java short value to an output stream. The - * char to be written will be in the lowest 16 bits of the <code>int</code> - * value passed. These bytes will be written "big endian". That is, - * with the high byte written first in the following manner: - * <p> - * <code>byte0 = (byte)((value & 0xFF00) >> 8);<br> - * byte1 = (byte)(value & 0x00FF);</code> - * <p> - * - * The value written can be read using the <code>readShort</code> and - * <code>readUnsignedShort</code> methods in <code>DataInput</code>. - * - * @param value The int value to write as a 16-bit value - * - * @exception IOException If an error occurs - * - * @see DataInput#readShort - * @see DataInput#readUnsignedShort - */ - void writeShort(int value) throws IOException; - - /** - * This method writes a Java int value to an output stream. The 4 bytes - * of the passed value will be written "big endian". That is, with - * the high byte written first in the following manner: - * <p> - * <code>byte0 = (byte)((value & 0xFF000000) >> 24);<br> - * byte1 = (byte)((value & 0x00FF0000) >> 16);<br> - * byte2 = (byte)((value & 0x0000FF00) >> 8);<br> - * byte3 = (byte)(value & 0x000000FF);</code> - * <p> - * - * The value written can be read using the <code>readInt</code> - * method in <code>DataInput</code>. - * - * @param value The int value to write - * - * @exception IOException If an error occurs - * - * @see DataInput#readInt - */ - void writeInt(int value) throws IOException; - - /** - * This method writes a Java long value to an output stream. The 8 bytes - * of the passed value will be written "big endian". That is, with - * the high byte written first in the following manner: - * <p> - * <code>byte0 = (byte)((value & 0xFF00000000000000L) >> 56);<br> - * byte1 = (byte)((value & 0x00FF000000000000L) >> 48);<br> - * byte2 = (byte)((value & 0x0000FF0000000000L) >> 40);<br> - * byte3 = (byte)((value & 0x000000FF00000000L) >> 32);<br> - * byte4 = (byte)((value & 0x00000000FF000000L) >> 24);<br> - * byte5 = (byte)((value & 0x0000000000FF0000L) >> 16);<br> - * byte6 = (byte)((value & 0x000000000000FF00L) >> 8);<br> - * byte7 = (byte)(value & 0x00000000000000FFL);</code> - * <p> - * - * The value written can be read using the <code>readLong</code> - * method in <code>DataInput</code>. - * - * @param value The long value to write - * - * @exception IOException If an error occurs - * - * @see DataInput#readLong - */ - void writeLong(long value) throws IOException; - - /** - * This method writes a Java <code>float</code> value to the stream. This - * value is written by first calling the method - * <code>Float.floatToIntBits</code> - * to retrieve an <code>int</code> representing the floating point number, - * then writing this <code>int</code> value to the stream exactly the same - * as the <code>writeInt()</code> method does. - * - * The value written can be read using the <code>readFloat</code> - * method in <code>DataInput</code>. - * - * @param value The float value to write - * - * @exception IOException If an error occurs - * - * @see writeInt - * @see DataInput#readFloat - * @see Float#floatToIntBits - */ - void writeFloat(float value) throws IOException; - - /** - * This method writes a Java <code>double</code> value to the stream. This - * value is written by first calling the method - * <code>Double.doubleToLongBits</code> - * to retrieve an <code>long</code> representing the floating point number, - * then writing this <code>long</code> value to the stream exactly the same - * as the <code>writeLong()</code> method does. - * - * The value written can be read using the <code>readDouble</code> - * method in <code>DataInput</code>. - * - * @param value The double value to write - * - * @exception IOException If any other error occurs - * - * @see writeLong - * @see DataInput#readDouble - * @see Double#doubleToLongBits - */ - void writeDouble(double value) throws IOException; - - /** - * This method writes all the bytes in a <code>String</code> out to the - * stream. One byte is written for each character in the - * <code>String</code>. - * The high eight bits of each character are discarded, thus this - * method is inappropriate for completely representing Unicode characters. - * - * @param value The <code>String</code> to write - * - * @exception IOException If an error occurs - */ - void writeBytes(String value) throws IOException; - - /** - * This method writes all the characters of a <code>String</code> to an - * output stream as an array of <code>char</code>'s. Each character - * is written using the method specified in the <code>writeChar</code> - * method. - * - * @param value The String to write - * - * @exception IOException If an error occurs - * - * @see writeChar - */ - void writeChars(String value) throws IOException; - - /** - * This method writes a Java <code>String</code> to the stream in a modified - * UTF-8 format. First, two bytes are written to the stream indicating the - * number of bytes to follow. This is written in the form of a Java - * <code>short</code> value in the same manner used by the - * <code>writeShort</code> method. Note that this is the number of - * bytes in the - * encoded <code>String</code> not the <code>String</code> length. Next - * come the encoded characters. Each character in the <code>String</code> - * is encoded as either one, two or three bytes. For characters in the - * range of <code>\u0001</code> to <code>\u007F</code>, one byte is used. - * The character - * value goes into bits 0-7 and bit eight is 0. For characters in the range - * of <code>\u0080</code> to <code>\u007FF</code>, two bytes are used. Bits - * 6-10 of the character value are encoded bits 0-4 of the first byte, with - * the high bytes having a value of "110". Bits 0-5 of the character value - * are stored in bits 0-5 of the second byte, with the high bits set to - * "10". This type of encoding is also done for the null character - * <code>\u0000</code>. This eliminates any C style NUL character values - * in the output. All remaining characters are stored as three bytes. - * Bits 12-15 of the character value are stored in bits 0-3 of the first - * byte. The high bits of the first bytes are set to "1110". Bits 6-11 - * of the character value are stored in bits 0-5 of the second byte. The - * high bits of the second byte are set to "10". And bits 0-5 of the - * character value are stored in bits 0-5 of byte three, with the high bits - * of that byte set to "10". - * - * The value written can be read using the <code>readUTF</code> - * method in <code>DataInput</code>. - * - * @param value The <code>String</code> to write - * - * @exception IOException If an error occurs - * - * @see DataInput#readUTF - */ - void writeUTF(String value) throws IOException; - - /** - * This method writes an 8-bit value (passed into the method as a Java - * <code>int</code>) to an output stream. The low 8 bits of the - * passed value are written. - * - * @param value The <code>byte</code> to write to the output stream - * - * @exception IOException If an error occurs - */ - void write(int value) throws IOException; - - /** - * This method writes the raw byte array passed in to the output stream. - * - * @param buf The byte array to write - * - * @exception IOException If an error occurs - */ - void write(byte[] buf) throws IOException; - - /** - * This method writes raw bytes from the passed array <code>buf</code> - * starting - * <code>offset</code> bytes into the buffer. The number of bytes - * written will be exactly <code>len</code>. - * - * @param buf The buffer from which to write the data - * @param offset The offset into the buffer to start writing data from - * @param len The number of bytes to write from the buffer to the output - * stream - * - * @exception IOException If any other error occurs - */ - void write(byte[] buf, int offset, int len) throws IOException; - -} // interface DataOutput - diff --git a/libjava/java/io/DataOutputStream.java b/libjava/java/io/DataOutputStream.java deleted file mode 100644 index 39f7ed1ff24..00000000000 --- a/libjava/java/io/DataOutputStream.java +++ /dev/null @@ -1,455 +0,0 @@ -/* DataOutputStream.java -- Writes primitive Java datatypes to streams - Copyright (C) 1998, 2001, 2003, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.io; - -/* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3 - * "The Java Language Specification", ISBN 0-201-63451-1 - * Status: Complete to version 1.1. - */ - -/** - * This class provides a mechanism for writing primitive Java datatypes - * to an <code>OutputStream</code> in a portable way. Data written to - * a stream using this class can be read back in using the - * <code>DataInputStream</code> class on any platform. - * - * @see DataInputStream - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Tom Tromey (tromey@cygnus.com) - */ -public class DataOutputStream extends FilterOutputStream implements DataOutput -{ - /** - * This is the total number of bytes that have been written to the - * stream by this object instance. - */ - protected int written; - - /** - * This method initializes an instance of <code>DataOutputStream</code> to - * write its data to the specified underlying <code>OutputStream</code> - * - * @param out The subordinate <code>OutputStream</code> to which this - * object will write - */ - public DataOutputStream (OutputStream out) - { - super (out); - written = 0; - } - - /** - * This method flushes any unwritten bytes to the underlying stream. - * - * @exception IOException If an error occurs. - */ - public void flush () throws IOException - { - out.flush(); - } - - /** - * This method returns the total number of bytes that have been written to - * the underlying output stream so far. This is the value of the - * <code>written</code> instance variable - * - * @return The number of bytes written to the stream. - */ - public final int size () - { - return written; - } - - /** - * This method writes the specified byte (passed as an <code>int</code>) - * to the underlying output stream. - * - * @param value The <code>byte</code> to write, passed as an <code>int</code>. - * - * @exception IOException If an error occurs. - */ - public synchronized void write (int value) throws IOException - { - out.write (value); - ++written; - } - - /** - * This method writes <code>len</code> bytes from the specified byte array - * <code>buf</code> starting at position <code>offset</code> into the - * buffer to the underlying output stream. - * - * @param buf The byte array to write from. - * @param offset The index into the byte array to start writing from. - * @param len The number of bytes to write. - * - * @exception IOException If an error occurs. - */ - public synchronized void write (byte[] buf, int offset, int len) - throws IOException - { - out.write(buf, offset, len); - written += len; - } - - /** - * This method writes a Java boolean value to an output stream. If - * <code>value</code> is <code>true</code>, a byte with the value of - * 1 will be written, otherwise a byte with the value of 0 will be - * written. - * - * The value written can be read using the <code>readBoolean</code> - * method in <code>DataInput</code>. - * - * @param value The <code>boolean</code> value to write to the stream - * - * @exception IOException If an error occurs - * - * @see DataInput#readBoolean - */ - public final void writeBoolean (boolean value) throws IOException - { - write (value ? 1 : 0); - } - - /** - * This method writes a Java byte value to an output stream. The - * byte to be written will be in the lowest 8 bits of the - * <code>int</code> value passed. - * - * The value written can be read using the <code>readByte</code> or - * <code>readUnsignedByte</code> methods in <code>DataInput</code>. - * - * @param value The <code>byte</code> to write to the stream, passed as - * the low eight bits of an <code>int</code>. - * - * @exception IOException If an error occurs - * - * @see DataInput#readByte - * @see DataInput#readUnsignedByte - */ - public final void writeByte (int value) throws IOException - { - write (value & 0xff); - } - - /** - * This method writes a Java short value to an output stream. The - * char to be written will be in the lowest 16 bits of the <code>int</code> - * value passed. These bytes will be written "big endian". That is, - * with the high byte written first in the following manner: - * <p> - * <code>byte0 = (byte)((value & 0xFF00) >> 8);<br> - * byte1 = (byte)(value & 0x00FF);</code> - * <p> - * - * The value written can be read using the <code>readShort</code> and - * <code>readUnsignedShort</code> methods in <code>DataInput</code>. - * - * @param value The <code>short</code> value to write to the stream, - * passed as an <code>int</code>. - * - * @exception IOException If an error occurs - * - * @see DataInput#readShort - * @see DataInput#readUnsignedShort - */ - public final synchronized void writeShort (int value) throws IOException - { - write ((byte) (0xff & (value >> 8))); - write ((byte) (0xff & value)); - } - - /** - * This method writes a Java char value to an output stream. The - * char to be written will be in the lowest 16 bits of the <code>int</code> - * value passed. These bytes will be written "big endian". That is, - * with the high byte written first in the following manner: - * <p> - * <code>byte0 = (byte)((value & 0xFF00) >> 8);<br> - * byte1 = (byte)(value & 0x00FF);</code> - * <p> - * - * The value written can be read using the <code>readChar</code> - * method in <code>DataInput</code>. - * - * @param value The <code>char</code> value to write, - * passed as an <code>int</code>. - * - * @exception IOException If an error occurs - * - * @see DataInput#readChar - */ - public final synchronized void writeChar (int value) throws IOException - { - write ((byte) (0xff & (value >> 8))); - write ((byte) (0xff & value)); - } - - /** - * This method writes a Java int value to an output stream. The 4 bytes - * of the passed value will be written "big endian". That is, with - * the high byte written first in the following manner: - * <p> - * <code>byte0 = (byte)((value & 0xFF000000) >> 24);<br> - * byte1 = (byte)((value & 0x00FF0000) >> 16);<br> - * byte2 = (byte)((value & 0x0000FF00) >> 8);<br> - * byte3 = (byte)(value & 0x000000FF);</code> - * <p> - * - * The value written can be read using the <code>readInt</code> - * method in <code>DataInput</code>. - * - * @param value The <code>int</code> value to write to the stream - * - * @exception IOException If an error occurs - * - * @see DataInput#readInt - */ - public final synchronized void writeInt (int value) throws IOException - { - write ((byte) (0xff & (value >> 24))); - write ((byte) (0xff & (value >> 16))); - write ((byte) (0xff & (value >> 8))); - write ((byte) (0xff & value)); - } - - /** - * This method writes a Java long value to an output stream. The 8 bytes - * of the passed value will be written "big endian". That is, with - * the high byte written first in the following manner: - * <p> - * <code>byte0 = (byte)((value & 0xFF00000000000000L) >> 56);<br> - * byte1 = (byte)((value & 0x00FF000000000000L) >> 48);<br> - * byte2 = (byte)((value & 0x0000FF0000000000L) >> 40);<br> - * byte3 = (byte)((value & 0x000000FF00000000L) >> 32);<br> - * byte4 = (byte)((value & 0x00000000FF000000L) >> 24);<br> - * byte5 = (byte)((value & 0x0000000000FF0000L) >> 16);<br> - * byte6 = (byte)((value & 0x000000000000FF00L) >> 8);<br> - * byte7 = (byte)(value & 0x00000000000000FFL);</code> - * <p> - * - * The value written can be read using the <code>readLong</code> - * method in <code>DataInput</code>. - * - * @param value The <code>long</code> value to write to the stream - * - * @exception IOException If an error occurs - * - * @see DataInput#readLong - */ - public final synchronized void writeLong (long value) throws IOException - { - write ((byte) (0xff & (value >> 56))); - write ((byte) (0xff & (value>> 48))); - write ((byte) (0xff & (value>> 40))); - write ((byte) (0xff & (value>> 32))); - write ((byte) (0xff & (value>> 24))); - write ((byte) (0xff & (value>> 16))); - write ((byte) (0xff & (value>> 8))); - write ((byte) (0xff & value)); - } - - /** - * This method writes a Java <code>float</code> value to the stream. This - * value is written by first calling the method - * <code>Float.floatToIntBits</code> - * to retrieve an <code>int</code> representing the floating point number, - * then writing this <code>int</code> value to the stream exactly the same - * as the <code>writeInt()</code> method does. - * - * The value written can be read using the <code>readFloat</code> - * method in <code>DataInput</code>. - * - * @param value The <code>float</code> value to write to the stream - * - * @exception IOException If an error occurs - * - * @see writeInt - * @see DataInput#readFloat - * @see Float#floatToIntBits - */ - public final void writeFloat (float value) throws IOException - { - writeInt (Float.floatToIntBits (value)); - } - - /** - * This method writes a Java <code>double</code> value to the stream. This - * value is written by first calling the method - * <code>Double.doubleToLongBits</code> - * to retrieve an <code>long</code> representing the floating point number, - * then writing this <code>long</code> value to the stream exactly the same - * as the <code>writeLong()</code> method does. - * - * The value written can be read using the <code>readDouble</code> - * method in <code>DataInput</code>. - * - * @param value The <code>double</code> value to write to the stream - * - * @exception IOException If an error occurs - * - * @see writeLong - * @see DataInput#readDouble - * @see Double#doubleToLongBits - */ - public final void writeDouble (double value) throws IOException - { - writeLong (Double.doubleToLongBits (value)); - } - - /** - * This method writes all the bytes in a <code>String</code> out to the - * stream. One byte is written for each character in the - * <code>String</code>. - * The high eight bits of each character are discarded, thus this - * method is inappropriate for completely representing Unicode characters. - * - * @param value The <code>String</code> to write to the stream - * - * @exception IOException If an error occurs - */ - public final void writeBytes (String value) throws IOException - { - int len = value.length(); - for (int i = 0; i < len; ++i) - writeByte (value.charAt(i)); - } - - /** - * This method writes all the characters of a <code>String</code> to an - * output stream as an array of <code>char</code>'s. Each character - * is written using the method specified in the <code>writeChar</code> - * method. - * - * @param value The <code>String</code> to write to the stream - * - * @exception IOException If an error occurs - * - * @see writeChar - */ - public final void writeChars (String value) throws IOException - { - int len = value.length(); - for (int i = 0; i < len; ++i) - writeChar (value.charAt(i)); - } - - /** - * This method writes a Java <code>String</code> to the stream in a modified - * UTF-8 format. First, two bytes are written to the stream indicating the - * number of bytes to follow. Note that this is the number of bytes in the - * encoded <code>String</code> not the <code>String</code> length. Next - * come the encoded characters. Each character in the <code>String</code> - * is encoded as either one, two or three bytes. For characters in the - * range of <code>\u0001</code> to <\u007F>, one byte is used. The character - * value goes into bits 0-7 and bit eight is 0. For characters in the range - * of <code>\u0080</code> to <code>\u007FF</code>, two bytes are used. Bits - * 6-10 of the character value are encoded bits 0-4 of the first byte, with - * the high bytes having a value of "110". Bits 0-5 of the character value - * are stored in bits 0-5 of the second byte, with the high bits set to - * "10". This type of encoding is also done for the null character - * <code>\u0000</code>. This eliminates any C style NUL character values - * in the output. All remaining characters are stored as three bytes. - * Bits 12-15 of the character value are stored in bits 0-3 of the first - * byte. The high bits of the first bytes are set to "1110". Bits 6-11 - * of the character value are stored in bits 0-5 of the second byte. The - * high bits of the second byte are set to "10". And bits 0-5 of the - * character value are stored in bits 0-5 of byte three, with the high bits - * of that byte set to "10". - * - * The value written can be read using the <code>readUTF</code> - * method in <code>DataInput</code>. - * - * @param value The <code>String</code> to write to the output in UTF format - * - * @exception IOException If an error occurs - * - * @see DataInput#readUTF - */ - public final synchronized void writeUTF(String value) throws IOException - { - int len = value.length(); - int sum = 0; - - for (int i = 0; i < len && sum <= 65535; ++i) - { - char c = value.charAt(i); - if (c >= '\u0001' && c <= '\u007f') - sum += 1; - else if (c == '\u0000' || (c >= '\u0080' && c <= '\u07ff')) - sum += 2; - else - sum += 3; - } - - if (sum > 65535) - throw new UTFDataFormatException (); - - int pos = 0; - byte[] buf = new byte[sum]; - - for (int i = 0; i < len; ++i) - { - char c = value.charAt(i); - if (c >= '\u0001' && c <= '\u007f') - buf[pos++] = (byte) c; - else if (c == '\u0000' || (c >= '\u0080' && c <= '\u07ff')) - { - buf[pos++] = (byte) (0xc0 | (0x1f & (c >> 6))); - buf[pos++] = (byte) (0x80 | (0x3f & c)); - } - else - { - // JSL says the first byte should be or'd with 0xc0, but - // that is a typo. Unicode says 0xe0, and that is what is - // consistent with DataInputStream. - buf[pos++] = (byte) (0xe0 | (0x0f & (c >> 12))); - buf[pos++] = (byte) (0x80 | (0x3f & (c >> 6))); - buf[pos++] = (byte) (0x80 | (0x3f & c)); - } - } - - writeShort (sum); - write(buf, 0, sum); - } - -} // class DataOutputStream - diff --git a/libjava/java/io/EOFException.java b/libjava/java/io/EOFException.java deleted file mode 100644 index cfedb7d9eb0..00000000000 --- a/libjava/java/io/EOFException.java +++ /dev/null @@ -1,76 +0,0 @@ -/* EOFException.java -- unexpected end of file exception - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.io; - -/** - * This exception is thrown when the end of the file or stream was - * encountered unexpectedly. This is not the normal way that an EOF - * condition is reported; such as a special value like -1 being returned. - * However, certain types of streams expecting certain data in a certain - * format might reach EOF before reading their expected data pattern and - * thus throw this exception. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Tom Tromey (tromey@cygnus.com) - * @status updated to 1.4 - */ -public class EOFException extends IOException -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = 6433858223774886977L; - - /** - * Create an exception without a descriptive error message. - */ - public EOFException() - { - } - - /** - * Create an exception with a descriptive error message. - * - * @param message the descriptive error message - */ - public EOFException(String message) - { - super(message); - } -} // class EOFException diff --git a/libjava/java/io/Externalizable.java b/libjava/java/io/Externalizable.java deleted file mode 100644 index 113c19ff60f..00000000000 --- a/libjava/java/io/Externalizable.java +++ /dev/null @@ -1,107 +0,0 @@ -/* Externalizable.java -- Interface for saving and restoring object data - Copyright (C) 1998 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.io; - -/** - * This interface provides a way that classes can completely control how - * the data of their object instances are written and read to and from - * streams. It has two methods which are used to write the data to a stream - * and to read the data from a stream. The read method must read the data - * in exactly the way it was written by the write method. - * <p> - * Note that classes which implement this interface must take into account - * that all superclass data must also be written to the stream as well. - * The class implementing this interface must figure out how to make that - * happen. - * <p> - * This interface can be used to provide object persistence. When an - * object is to be stored externally, the <code>writeExternal</code> method is - * called to save state. When the object is restored, an instance is - * created using the default no-argument constructor and the - * <code>readExternal</code> method is used to restore the state. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public interface Externalizable extends Serializable -{ - /** - * This method restores an object's state by reading in the instance data - * for the object from the passed in stream. Note that this stream is not - * a subclass of <code>InputStream</code>, but rather is a class that - * implements - * the <code>ObjectInput</code> interface. That interface provides a - * mechanism for - * reading in Java data types from a stream. - * <p> - * Note that this method must be compatible with <code>writeExternal</code>. - * It must read back the exact same types that were written by that - * method in the exact order they were written. - * <p> - * If this method needs to read back an object instance, then the class - * for that object must be found and loaded. If that operation fails, - * then this method throws a <code>ClassNotFoundException</code> - * - * @param in An <code>ObjectInput</code> instance for reading in the object - * state - * - * @exception ClassNotFoundException If the class of an object being - * restored cannot be found - * @exception IOException If any other error occurs - */ - void readExternal(ObjectInput in) - throws ClassNotFoundException, IOException; - - /** - * This method is responsible for writing the instance data of an object - * to the passed in stream. Note that this stream is not a subclass of - * <code>OutputStream</code>, but rather is a class that implements the - * <code>ObjectOutput</code> interface. That interface provides a - * number of methods - * for writing Java data values to a stream. - * <p> - * Not that the implementation of this method must be coordinated with - * the implementation of <code>readExternal</code>. - * - * @param out An <code>ObjectOutput</code> instance for writing the - * object state - * - * @exception IOException If an error occurs - */ - void writeExternal(ObjectOutput out) throws IOException; -} diff --git a/libjava/java/io/FileDescriptor.java b/libjava/java/io/FileDescriptor.java deleted file mode 100644 index d300c9cb617..00000000000 --- a/libjava/java/io/FileDescriptor.java +++ /dev/null @@ -1,139 +0,0 @@ -/* FileDescriptor.java -- Opaque file handle class - Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004 - Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.io; - -import gnu.java.nio.channels.FileChannelImpl; - -import java.nio.channels.ByteChannel; -import java.nio.channels.FileChannel; - -/** - * This class represents an opaque file handle as a Java class. It should - * be used only to pass to other methods that expect an object of this - * type. No system specific information can be obtained from this object. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Tom Tromey (tromey@cygnus.com) - * @date September 24, 1998 - */ -public final class FileDescriptor -{ - /** - * A <code>FileDescriptor</code> representing the system standard input - * stream. This will usually be accessed through the - * <code>System.in</code>variable. - */ - public static final FileDescriptor in - = new FileDescriptor (FileChannelImpl.in); - - /** - * A <code>FileDescriptor</code> representing the system standard output - * stream. This will usually be accessed through the - * <code>System.out</code>variable. - */ - public static final FileDescriptor out - = new FileDescriptor (FileChannelImpl.out); - - /** - * A <code>FileDescriptor</code> representing the system standard error - * stream. This will usually be accessed through the - * <code>System.err</code>variable. - */ - public static final FileDescriptor err - = new FileDescriptor (FileChannelImpl.err); - - final ByteChannel channel; - - /** - * This method is used to initialize an invalid FileDescriptor object. - */ - public FileDescriptor() - { - channel = null; - } - - /** - * This method is used to initialize a FileDescriptor object. - */ - FileDescriptor(ByteChannel channel) - { - this.channel = channel; - } - - - /** - * This method forces all data that has not yet been physically written to - * the underlying storage medium associated with this - * <code>FileDescriptor</code> - * to be written out. This method will not return until all data has - * been fully written to the underlying device. If the device does not - * support this functionality or if an error occurs, then an exception - * will be thrown. - */ - public void sync () throws SyncFailedException - { - if (channel instanceof FileChannel) - { - try - { - ((FileChannel) channel).force(true); - } - catch (IOException ex) - { - if (ex instanceof SyncFailedException) - throw (SyncFailedException) ex; - else - throw new SyncFailedException(ex.toString()); - } - } - } - - /** - * This methods tests whether or not this object represents a valid open - * native file handle. - * - * @return <code>true</code> if this object represents a valid - * native file handle, <code>false</code> otherwise - */ - public boolean valid () - { - return channel != null && channel.isOpen(); - } -} diff --git a/libjava/java/io/FileFilter.java b/libjava/java/io/FileFilter.java deleted file mode 100644 index e57ac9fd060..00000000000 --- a/libjava/java/io/FileFilter.java +++ /dev/null @@ -1,65 +0,0 @@ -/* FileFilter.java -- Filter a list of pathnames - Copyright (C) 1998,2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.io; - -/** - * This interface has one method which is used for filtering pathnames - * returned in a pathname listing. It is currently used by the - * <code>File.listFiles(FileFilter)</code> method. - * <p> - * The method in this interface determines if a particular pathname should - * or should not be included in the pathname listing. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * - * @see File#listFiles(java.io.FileFilter) - */ -public interface FileFilter -{ - /** - * This method determines whether or not a given pathname should be included - * in a pathname listing. - * - * @param pathname The pathname to test - * - * @return <code>true</code> if the path should be included in the list, - * <code>false</code> otherwise. - */ - boolean accept(File pathname); -} diff --git a/libjava/java/io/FileNotFoundException.java b/libjava/java/io/FileNotFoundException.java deleted file mode 100644 index 3c11e296072..00000000000 --- a/libjava/java/io/FileNotFoundException.java +++ /dev/null @@ -1,73 +0,0 @@ -/* FileNotFoundException.java -- the requested file could not be found - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.io; - -/** - * This exception is thrown when an attempt is made to access a file that - * does not exist, or is inaccessible for some other reason (such as writing - * a read-only file). - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Tom Tromey (tromey@cygnus.com) - * @status updated to 1.4 - */ -public class FileNotFoundException extends IOException -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = -897856973823710492L; - - /** - * Create an exception without a descriptive error message. - */ - public FileNotFoundException() - { - } - - /** - * Create an exception with a descriptive error message. - * - * @param message the descriptive error message - */ - public FileNotFoundException(String message) - { - super(message); - } -} // class FileNotFoundException diff --git a/libjava/java/io/FilePermission.java b/libjava/java/io/FilePermission.java deleted file mode 100644 index 356787bfa72..00000000000 --- a/libjava/java/io/FilePermission.java +++ /dev/null @@ -1,292 +0,0 @@ -/* FilePermission.java -- - Copyright (C) 1998, 2000, 2003, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.io; - -import java.security.Permission; - -public final class FilePermission extends Permission implements Serializable -{ - private static final long serialVersionUID = 7930732926638008763L; - - private static final String CURRENT_DIRECTORY = - System.getProperty("user.dir"); - - private static final String ALL_FILES = "<<ALL FILES>>"; - - private boolean readPerm = false; - private boolean writePerm = false; - private boolean executePerm = false; - private boolean deletePerm = false; - private final String actionsString; - - // Checks and caches the actions - private void checkPerms() throws IllegalArgumentException - { - String action; - int i = actionsString.indexOf(','); - int startI = 0; - while (i != -1) - { - action = actionsString.substring(startI, i).trim().toLowerCase(); - if (action.equals("read")) - readPerm = true; - else if (action.equals("write")) - writePerm = true; - else if (action.equals("execute")) - executePerm = true; - else if (action.equals("delete")) - deletePerm = true; - else - throw new IllegalArgumentException("Unknown action: " + action); - - startI = i + 1; - i = actionsString.indexOf(',', startI); - } - - action = actionsString.substring(startI).trim().toLowerCase(); - if (action.equals("read")) - readPerm = true; - else if (action.equals("write")) - writePerm = true; - else if (action.equals("execute")) - executePerm = true; - else if (action.equals("delete")) - deletePerm = true; - else - throw new IllegalArgumentException("Unknown action: " + action); - } - - /** - * Create a new FilePermission. - * - * @param pathExpression an expression specifying the paths this - * permission represents. - * @param actionsString a comma-separated list of the actions this - * permission represents. The actions must be "read", "write", - * "execute" and/or "delete". - */ - public FilePermission(String pathExpression, String actionsString) - { - // FIXME: what to do when the file string is malformed? - super(pathExpression); - if (pathExpression == null) - throw new NullPointerException("pathExpression"); - if (actionsString == null) - throw new IllegalArgumentException("actionsString"); - this.actionsString = actionsString; - checkPerms(); - } - - /** - * Get the actions this FilePermission supports. - * @return the String representing the actions this FilePermission supports. - */ - public String getActions() - { - return actionsString; - } - - /** - * Get the hash code for this Object.<P> - * FilePermission's hash code is calculated as the exclusive or of the - * target - * String's hash code and the action String's hash code. - * @specnote Sun did not specify how to calculate the hash code; - * I made this up. - * @return the hash code for this Object. - */ - public int hashCode() - { - return getName().hashCode() ^ actionsString.hashCode(); - } - - /** - * Check two FilePermissions for semantic equality. - * Two FilePermissions are exactly equivalent if they have identical path - * expressions and have exactly the same access permissions. - * @param o the Object to compare to. - * @return whether the Objects are semantically equivalent. - */ - public boolean equals(Object o) - { - if (! (o instanceof FilePermission)) - return false; - FilePermission p = (FilePermission) o; - - String f1 = getName(); - String f2 = p.getName(); - - // Compare names, taking into account if they refer to a directory - // and one has a separator and the other does not. - if (f1.length() > 0 && f1.charAt(f1.length() - 1) == File.separatorChar) - { - if (f2.length() > 0 - && f2.charAt(f2.length() - 1) == File.separatorChar) - { - if (! f2.equals(f1)) - return false; - } - else - { - if (! f2.equals(f1.substring(0, f1.length() - 1))) - return false; - } - } - else - { - if (f2.length() > 0 - && f2.charAt(f2.length() - 1) == File.separatorChar) - { - if (! f1.equals(f2.substring(0, f2.length() - 1))) - return false; - } - else - { - if (! f1.equals(f2)) - return false; - } - } - return (readPerm == p.readPerm - && writePerm == p.writePerm - && executePerm == p.executePerm - && deletePerm == p.deletePerm); - } - - /** - * Check to see if this permission implies another. - * Permission A implies permission B if these things are all true: - * <OL> - * <LI>A and B are both FilePermissions.</LI> - * <LI>All possible files in B are included in A - * (possibly more are in A).</LI> - * <LI>All actions B supports, A also supports.</LI> - * </OL> - * @param p the Permission to compare against. - * @return whether this Permission implies p - */ - public boolean implies(Permission p) - { - if (! (p instanceof FilePermission)) - return false; - - String f1 = getName(); - - if (f1.equals(ALL_FILES)) - return true; - - FilePermission fp = (FilePermission) p; - String f2 = fp.getName(); - - if (f1.charAt(0) != File.separatorChar) - f1 = CURRENT_DIRECTORY + f1; - if (f2.charAt(0) != File.separatorChar) - f2 = CURRENT_DIRECTORY + f2; - - String sub1; - - switch (f1.charAt(f1.length() - 1)) - { - case '*': - sub1 = f1.substring(0, f1.length() - 1); // chop off "*" - if (f2.length() <= sub1.length()) - { - // If it's smaller, there is no way it could be part of - // this directory. If it's the same (or length - 1), it - // could be the same directory but specifies access to - // the directory rather than the files in it. - return false; - } - else if (f2.charAt(sub1.length() - 1) == File.separatorChar) - { - // Make sure the part before the "/" is the same. - if (! f2.substring(0, sub1.length()).equals(sub1)) - return false; - // Make sure there are no subdirectories specified - // underneath this one. - if (f2.substring(sub1.length() + 1).indexOf(File.separatorChar) - != -1) - return false; - } - else - { - // Obviously not equal: f2 is either not a directory or - // is not the same directory (its name continues further - // than we want). - return false; - } - break; - case '-': - // Chop off "/-". - sub1 = f1.substring(0, f1.length() - 2); - if (f2.length() < sub1.length()) - { - // If it's smaller, there is no way it could be part of - // this directory. - return false; - } - else if (f2.length() > sub1.length() - && f2.charAt(sub1.length()) != File.separatorChar) - return false; - else if (! f2.substring(0, sub1.length()).equals(sub1)) - return false; - break; - - default: - if (f2.charAt(f2.length() - 1) == File.separatorChar) - { - if (! f1.equals(f2.substring(0, f2.length() - 1))) - return false; - } - else if (!f1.equals(f2)) - return false; - break; - } - - if (readPerm && ! fp.readPerm) - return false; - if (writePerm && ! fp.writePerm) - return false; - if (executePerm && ! fp.executePerm) - return false; - if (deletePerm && ! fp.deletePerm) - return false; - - return true; - } -} diff --git a/libjava/java/io/FileReader.java b/libjava/java/io/FileReader.java deleted file mode 100644 index 4a1dd5ff4ce..00000000000 --- a/libjava/java/io/FileReader.java +++ /dev/null @@ -1,92 +0,0 @@ -/* FileReader.java -- Convenience class for reading characters from a file - Copyright (C) 1998, 2000, 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.io; - -/** - * This class provides a convenient way to set up a <code>Reader</code> - * to read from a file. It opens the specified file for reading and creates - * the <code>InputStreamReader</code> to read from the - * resulting <code>FileInputStream</code>. This class can only be used - * to read from files using the default character encoding. Use - * <code>InputStreamReader</code> directly to use a non-default encoding. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public class FileReader extends InputStreamReader -{ - /** - * This method initializes a <code>FileReader</code> instance to read from - * the specified <code>File</code> object. - * - * @param file The <code>File</code> object representing the file to read from - * - * @exception FileNotFoundException If the file is not found or some other - * error occurs - */ - public FileReader(File file) throws FileNotFoundException - { - super(new FileInputStream(file)); - } - - /** - * This method initializes a <code>FileReader</code> instance to read from - * this specified <code>FileDescriptor</code> object. - * - * @param fd The <code>FileDescriptor</code> to read from. - */ - public FileReader(FileDescriptor fd) - { - super(new FileInputStream(fd)); - } - - /** - * This method initializes a <code>FileReader</code> instance to read from - * the specified named file. - * - * @param name The name of the file to read from - * - * @exception FileNotFoundException If the file is not found or some other - * error occurs - */ - public FileReader(String name) throws FileNotFoundException - { - super(new FileInputStream(name)); - } -} // class FileReader - diff --git a/libjava/java/io/FileWriter.java b/libjava/java/io/FileWriter.java deleted file mode 100644 index b34db83231e..00000000000 --- a/libjava/java/io/FileWriter.java +++ /dev/null @@ -1,137 +0,0 @@ -/* FileWriter.java -- Convenience class for writing to files. - Copyright (C) 1998, 1999, 2001, 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.io; - -/* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3 - * "The Java Language Specification", ISBN 0-201-63451-1 - * Status: Complete to version 1.1. - */ - -/** - * This is a convenience class for writing to files. It creates an - * <code>FileOutputStream</code> and initializes an - * <code>OutputStreamWriter</code> to write to it. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Tom Tromey (tromey@cygnus.com) - */ -public class FileWriter extends OutputStreamWriter -{ - /** - * This method initializes a new <code>FileWriter</code> object to write - * to the specified <code>File</code> object. - * - * @param file The <code>File</code> object to write to. - * - * @throws SecurityException If writing to this file is forbidden by the - * <code>SecurityManager</code>. - * @throws IOException If any other error occurs - */ - public FileWriter(File file) throws SecurityException, IOException - { - super(new FileOutputStream(file)); - } - - /** - * This method initializes a new <code>FileWriter</code> object to write - * to the specified <code>File</code> object. - * - * @param file The <code>File</code> object to write to. - * @param append <code>true</code> to start adding data at the end of the - * file, <code>false</code> otherwise. - * - * @throws SecurityException If writing to this file is forbidden by the - * <code>SecurityManager</code>. - * @throws IOException If any other error occurs - */ - public FileWriter(File file, boolean append) throws IOException - { - super(new FileOutputStream(file, append)); - } - - /** - * This method initializes a new <code>FileWriter</code> object to write - * to the specified <code>FileDescriptor</code> object. - * - * @param fd The <code>FileDescriptor</code> object to write to - * - * @throws SecurityException If writing to this file is forbidden by the - * <code>SecurityManager</code>. - */ - public FileWriter(FileDescriptor fd) throws SecurityException - { - super(new FileOutputStream(fd)); - } - - /** - * This method intializes a new <code>FileWriter</code> object to - * write to the - * specified named file. - * - * @param name The name of the file to write to - * - * @throws SecurityException If writing to this file is forbidden by the - * <code>SecurityManager</code>. - * @throws IOException If any other error occurs - */ - public FileWriter(String name) throws IOException - { - super(new FileOutputStream(name)); - } - - /** - * This method intializes a new <code>FileWriter</code> object to - * write to the - * specified named file. This form of the constructor allows the caller - * to determin whether data should be written starting at the beginning or - * the end of the file. - * - * @param name The name of the file to write to - * @param append <code>true</code> to start adding data at the end of the - * file, <code>false</code> otherwise. - * - * @throws SecurityException If writing to this file is forbidden by the - * <code>SecurityManager</code>. - * @throws IOException If any other error occurs - */ - public FileWriter(String name, boolean append) throws IOException - { - super(new FileOutputStream(name, append)); - } -} diff --git a/libjava/java/io/FilenameFilter.java b/libjava/java/io/FilenameFilter.java deleted file mode 100644 index 57b4d3b182c..00000000000 --- a/libjava/java/io/FilenameFilter.java +++ /dev/null @@ -1,76 +0,0 @@ -/* FilenameFilter.java -- Filter a list of filenames - Copyright (C) 1998, 1999, 2001, 2003, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.io; - -/* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3 - * "The Java Language Specification", ISBN 0-201-63451-1 - * Status: Complete to 1.1. - */ - -/** - * This interface has one method which is used for filtering filenames - * returned in a directory listing. It is currently used by the - * <code>File.list(FilenameFilter)</code> method and by the filename - * dialog in AWT. - * <p> - * The method in this interface determines if a particular file should - * or should not be included in the file listing. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Tom Tromey (tromey@cygnus.com) - * - * @see File#listFiles(java.io.FilenameFilter) - * @see java.awt.FileDialog#setFilenameFilter(java.io.FilenameFilter) - */ -public interface FilenameFilter -{ - /** - * This method determines whether or not a given file should be included - * in a directory listing. - * - * @param dir The <code>File</code> instance for the directory being read - * @param name The name of the file to test - * - * @return <code>true</code> if the file should be included in the list, - * <code>false</code> otherwise. - */ - boolean accept(File dir, String name); - -} // interface FilenameFilter - diff --git a/libjava/java/io/FilterInputStream.java b/libjava/java/io/FilterInputStream.java deleted file mode 100644 index d3cb9e4f71f..00000000000 --- a/libjava/java/io/FilterInputStream.java +++ /dev/null @@ -1,203 +0,0 @@ -/* FilterInputStream.java -- Base class for classes that filter input - Copyright (C) 1998, 1999, 2001, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.io; - -/* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3 - * "The Java Language Specification", ISBN 0-201-63451-1 - * plus online API docs for JDK 1.2 beta from http://www.javasoft.com. - * Status: Believed complete and correct. - */ - -/** - * This is the common superclass of all standard classes that filter - * input. It acts as a layer on top of an underlying <code>InputStream</code> - * and simply redirects calls made to it to the subordinate InputStream - * instead. Subclasses of this class perform additional filtering - * functions in addition to simply redirecting the call. - * <p> - * This class is not abstract. However, since it only redirects calls - * to a subordinate <code>InputStream</code> without adding any functionality - * on top of it, this class should not be used directly. Instead, various - * subclasses of this class should be used. This is enforced with a - * protected constructor. Do not try to hack around it. - * <p> - * When creating a subclass of <code>FilterInputStream</code>, override the - * appropriate methods to implement the desired filtering. However, note - * that the <code>read(byte[])</code> method does not need to be overridden - * as this class redirects calls to that method to - * <code>read(byte[], int, int)</code> instead of to the subordinate - * <code>InputStream read(byte[])</code> method. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Warren Levy (warrenl@cygnus.com) - */ -public class FilterInputStream extends InputStream -{ - /** - * This is the subordinate <code>InputStream</code> to which method calls - * are redirected - */ - protected InputStream in; - - /** - * Create a <code>FilterInputStream</code> with the specified subordinate - * <code>InputStream</code>. - * - * @param in The subordinate <code>InputStream</code> - */ - protected FilterInputStream(InputStream in) - { - this.in = in; - } - - /** - * Calls the <code>in.mark(int)</code> method. - * - * @param readlimit The parameter passed to <code>in.mark(int)</code> - */ - public void mark(int readlimit) - { - in.mark(readlimit); - } - - /** - * Calls the <code>in.markSupported()</code> method. - * - * @return <code>true</code> if mark/reset is supported, <code>false</code> - * otherwise - */ - public boolean markSupported() - { - return in.markSupported(); - } - - /** - * Calls the <code>in.reset()</code> method. - * - * @exception IOException If an error occurs - */ - public void reset() throws IOException - { - in.reset(); - } - - /** - * Calls the <code>in.available()</code> method. - * - * @return The value returned from <code>in.available()</code> - * - * @exception IOException If an error occurs - */ - public int available() throws IOException - { - return in.available(); - } - - /** - * Calls the <code>in.skip(long)</code> method - * - * @param numBytes The requested number of bytes to skip. - * - * @return The value returned from <code>in.skip(long)</code> - * - * @exception IOException If an error occurs - */ - public long skip(long numBytes) throws IOException - { - return in.skip(numBytes); - } - - /** - * Calls the <code>in.read()</code> method - * - * @return The value returned from <code>in.read()</code> - * - * @exception IOException If an error occurs - */ - public int read() throws IOException - { - return in.read(); - } - - /** - * Calls the <code>read(byte[], int, int)</code> overloaded method. - * Note that - * this method does not redirect its call directly to a corresponding - * method in <code>in</code>. This allows subclasses to override only the - * three argument version of <code>read</code>. - * - * @param buf The buffer to read bytes into - * - * @return The value retured from <code>in.read(byte[], int, int)</code> - * - * @exception IOException If an error occurs - */ - public int read(byte[] buf) throws IOException - { - return read(buf, 0, buf.length); - } - - /** - * Calls the <code>in.read(byte[], int, int)</code> method. - * - * @param buf The buffer to read bytes into - * @param offset The index into the buffer to start storing bytes - * @param len The maximum number of bytes to read. - * - * @return The value retured from <code>in.read(byte[], int, int)</code> - * - * @exception IOException If an error occurs - */ - public int read(byte[] buf, int offset, int len) throws IOException - { - return in.read(buf, offset, len); - } - - /** - * This method closes the input stream by closing the input stream that - * this object is filtering. Future attempts to access this stream may - * throw an exception. - * - * @exception IOException If an error occurs - */ - public void close() throws IOException - { - in.close(); - } -} diff --git a/libjava/java/io/FilterOutputStream.java b/libjava/java/io/FilterOutputStream.java deleted file mode 100644 index 4c2dfc04a65..00000000000 --- a/libjava/java/io/FilterOutputStream.java +++ /dev/null @@ -1,150 +0,0 @@ -/* FilterOutputStream.java -- Parent class for output streams that filter - Copyright (C) 1998, 1999, 2001, 2003, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.io; - -/* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3 - * "The Java Language Specification", ISBN 0-201-63451-1 - * Status: Complete to version 1.1. - */ - -/** - * This class is the common superclass of output stream classes that - * filter the output they write. These classes typically transform the - * data in some way prior to writing it out to another underlying - * <code>OutputStream</code>. This class simply overrides all the - * methods in <code>OutputStream</code> to redirect them to the - * underlying stream. Subclasses provide actual filtering. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Tom Tromey (tromey@cygnus.com) - */ -public class FilterOutputStream extends OutputStream -{ - /** - * This is the subordinate <code>OutputStream</code> that this class - * redirects its method calls to. - */ - protected OutputStream out; - - /** - * This method initializes an instance of <code>FilterOutputStream</code> - * to write to the specified subordinate <code>OutputStream</code>. - * - * @param out The <code>OutputStream</code> to write to - */ - public FilterOutputStream(OutputStream out) - { - this.out = out; - } - - /** - * This method closes the underlying <code>OutputStream</code>. Any - * further attempts to write to this stream may throw an exception. - * - * @exception IOException If an error occurs - */ - public void close() throws IOException - { - flush(); - out.close(); - } - - /** - * This method attempt to flush all buffered output to be written to the - * underlying output sink. - * - * @exception IOException If an error occurs - */ - public void flush() throws IOException - { - out.flush(); - } - - /** - * This method writes a single byte of output to the underlying - * <code>OutputStream</code>. - * - * @param b The byte to write, passed as an int. - * - * @exception IOException If an error occurs - */ - public void write(int b) throws IOException - { - out.write(b); - } - - /** - * This method writes all the bytes in the specified array to the underlying - * <code>OutputStream</code>. It does this by calling the three parameter - * version of this method - <code>write(byte[], int, int)</code> in this - * class instead of writing to the underlying <code>OutputStream</code> - * directly. This allows most subclasses to avoid overriding this method. - * - * @param buf The byte array to write bytes from - * - * @exception IOException If an error occurs - */ - public void write(byte[] buf) throws IOException - { - // Don't do checking here, per Java Lang Spec. - write(buf, 0, buf.length); - } - - /** - * This method calls the <code>write(int)</code> method <code>len</code> - * times for all bytes from the array <code>buf</code> starting at index - * <code>offset</code>. Subclasses should overwrite this method to get a - * more efficient implementation. - * - * @param buf The byte array to write bytes from - * @param offset The index into the array to start writing bytes from - * @param len The number of bytes to write - * - * @exception IOException If an error occurs - */ - public void write(byte[] buf, int offset, int len) throws IOException - { - // Don't do checking here, per Java Lang Spec. - for (int i=0; i < len; i++) - write(buf[offset + i]); - - } - -} // class FilterOutputStream - diff --git a/libjava/java/io/FilterReader.java b/libjava/java/io/FilterReader.java deleted file mode 100644 index 2bd040a7f72..00000000000 --- a/libjava/java/io/FilterReader.java +++ /dev/null @@ -1,185 +0,0 @@ -/* FilterReader.java -- Base class for char stream classes that filter input - Copyright (C) 1998, 1999, 2001, 2003, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.io; - -/* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3 - * "The Java Language Specification", ISBN 0-201-63451-1 - * plus online API docs for JDK 1.2 beta from http://www.javasoft.com. - * Status: Believed complete and correct. - */ - -/** - * This is the common superclass of all standard classes that filter - * input. It acts as a layer on top of an underlying <code>Reader</code> - * and simply redirects calls made to it to the subordinate Reader - * instead. Subclasses of this class perform additional filtering - * functions in addition to simply redirecting the call. - * <p> - * When creating a subclass of <code>FilterReader</code>, override the - * appropriate methods to implement the desired filtering. However, note - * that the <code>read(char[])</code> method does not need to be overridden - * as this class redirects calls to that method to - * <code>read(yte[], int, int)</code> instead of to the subordinate - * <code>Reader} read(yte[])</code> method. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Warren Levy (warrenl@cygnus.com) - */ -public abstract class FilterReader extends Reader -{ - /** - * This is the subordinate <code>Reader</code> to which method calls - * are redirected - */ - protected Reader in; - - /** - * Create a <code>FilterReader</code> with the specified subordinate - * <code>Reader</code>. - * The <code>lock</code> of the new <code>FilterReader</code> will be set - * to <code>in.lock</code>. - * - * @param in The subordinate <code>Reader</code> - */ - protected FilterReader(Reader in) - { - super(in.lock); - this.in = in; - } - - /** - * Calls the <code>in.mark(int)</code> method. - * - * @param readlimit The parameter passed to <code>in.mark(int)</code> - * - * @exception IOException If an error occurs - */ - public void mark(int readlimit) throws IOException - { - in.mark(readlimit); - } - - /** - * Calls the <code>in.markSupported()</code> method. - * - * @return <code>true</code> if mark/reset is supported, - * <code>false</code> otherwise - */ - public boolean markSupported() - { - return(in.markSupported()); - } - - /** - * Calls the <code>in.reset()</code> method. - * - * @exception IOException If an error occurs - */ - public void reset() throws IOException - { - in.reset(); - } - - /** - * Calls the <code>in.read()</code> method. - * - * @return The value returned from <code>in.available()</code> - * - * @exception IOException If an error occurs - */ - public boolean ready() throws IOException - { - return(in.ready()); - } - - /** - * Calls the <code>in.skip(long)</code> method - * - * @param numBytes The requested number of chars to skip. - * - * @return The value returned from <code>in.skip(long)</code> - * - * @exception IOException If an error occurs - */ - public long skip(long num_chars) throws IOException - { - return(in.skip(num_chars)); - } - - /** - * Calls the <code>in.read()</code> method - * - * @return The value returned from <code>in.read()</code> - * - * @exception IOException If an error occurs - */ - public int read() throws IOException - { - return(in.read()); - } - - /** - * Calls the <code>in.read(char[], int, int)</code> method. - * - * @param buf The buffer to read chars into - * @param offset The index into the buffer to start storing chars - * @param len The maximum number of chars to read. - * - * @return The value retured from <code>in.read(char[], int, int)</code> - * - * @exception IOException If an error occurs - */ - public int read(char[] buf, int offset, int len) throws IOException - { - return(in.read(buf, offset, len)); - } - - /** - * This method closes the stream by calling the <code>close()</code> method - * of the underlying stream. - * - * @exception IOException If an error occurs - */ - public void close() throws IOException - { - in.close(); - } - -} // class FilterReader - diff --git a/libjava/java/io/FilterWriter.java b/libjava/java/io/FilterWriter.java deleted file mode 100644 index 9b9ce33f9f6..00000000000 --- a/libjava/java/io/FilterWriter.java +++ /dev/null @@ -1,147 +0,0 @@ -/* FilterWriter.java -- Parent class for output streams that filter - Copyright (C) 1998, 1999, 2001, 2003, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.io; - -/* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3 - * "The Java Language Specification", ISBN 0-201-63451-1 - * Status: Complete to version 1.1. - */ - -/** - * This class is the common superclass of output character stream classes - * that filter the output they write. These classes typically transform the - * data in some way prior to writing it out to another underlying - * <code>Writer</code>. This class simply overrides all the - * methods in <code>Writer</code> to redirect them to the - * underlying stream. Subclasses provide actual filtering. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Tom Tromey (tromey@cygnus.com) - */ -public abstract class FilterWriter extends Writer -{ - /** - * This is the subordinate <code>Writer</code> that this class - * redirects its method calls to. - */ - protected Writer out; - - /** - * This method initializes an instance of <code>FilterWriter</code> - * to write to the specified subordinate <code>Writer</code>. - * The given <code>Writer</code> will be used as <code>lock</code> for - * the newly created <code>FilterWriter</code>. - * - * @param out The <code>Writer</code> to write to - */ - protected FilterWriter(Writer out) - { - super(out.lock); - this.out = out; - } - - /** - * This method closes the underlying <code>Writer</code>. Any - * further attempts to write to this stream may throw an exception. - * - * @exception IOException If an error occurs - */ - public void close() throws IOException - { - out.close(); - } - - /** - * This method attempt to flush all buffered output to be written to the - * underlying output sink. - * - * @exception IOException If an error occurs - */ - public void flush() throws IOException - { - out.flush(); - } - - /** - * This method writes a single char of output to the underlying - * <code>Writer</code>. - * - * @param b The char to write, passed as an int. - * - * @exception IOException If an error occurs - */ - public void write(int b) throws IOException - { - out.write(b); - } - - /** - * This method writes <code>len</code> chars from the array <code>buf</code> - * starting at index <code>offset</code> to the underlying - * <code>Writer</code>. - * - * @param buf The char array to write chars from - * @param offset The index into the array to start writing chars from - * @param len The number of chars to write - * - * @exception IOException If an error occurs - */ - public void write(char[] buf, int offset, int len) throws IOException - { - out.write(buf, offset, len); - } - - /** - * This method writes <code>len</code> chars from the <code>String</code> - * starting at position <code>offset</code>. - * - * @param str The <code>String</code> that is to be written - * @param offset The character offset into the <code>String</code> - * to start writing from - * @param len The number of chars to write - * - * @exception IOException If an error occurs - */ - public void write(String str, int offset, int len) throws IOException - { - out.write(str, offset, len); - } - -} // class FilterWriter - diff --git a/libjava/java/io/IOException.java b/libjava/java/io/IOException.java deleted file mode 100644 index cf3ad194633..00000000000 --- a/libjava/java/io/IOException.java +++ /dev/null @@ -1,74 +0,0 @@ -/* IOException.java -- Generic input/output exception - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.io; - -/** - * This exception is thrown to indicate an I/O problem of some sort - * occurred. Since this is a fairly generic exception, often a subclass - * of IOException will actually be thrown in order to provide a more - * detailed indication of what happened. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Tom Tromey (tromey@cygnus.com) - * @status updated to 1.4 - */ -public class IOException extends Exception -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = 7818375828146090155L; - - /** - * Create an exception without a descriptive error message. - */ - public IOException() - { - } - - /** - * Create an exception with a descriptive error message. - * - * @param message the descriptive error message - */ - public IOException(String message) - { - super(message); - } -} // class IOException diff --git a/libjava/java/io/InputStream.java b/libjava/java/io/InputStream.java deleted file mode 100644 index 86d1cd74914..00000000000 --- a/libjava/java/io/InputStream.java +++ /dev/null @@ -1,272 +0,0 @@ -/* InputStream.java -- Base class for input - Copyright (C) 1998, 1999, 2001, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.io; - -/** - * This abstract class forms the base of the hierarchy of classes that read - * input as a stream of bytes. It provides a common set of methods for - * reading bytes from streams. Subclasses implement and extend these - * methods to read bytes from a particular input source such as a file - * or network connection. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Warren Levy (warrenl@cygnus.com) - */ -public abstract class InputStream -{ - /** - * Default, no-arg, public constructor - */ - public InputStream() - { - } - - /** - * This method returns the number of bytes that can be read from this - * stream before a read can block. A return of 0 indicates that blocking - * might (or might not) occur on the very next read attempt. - * <p> - * This method always returns 0 in this class - * - * @return The number of bytes that can be read before blocking could occur - * - * @exception IOException If an error occurs - */ - public int available() throws IOException - { - return 0; - } - - /** - * This method closes the stream. Any futher attempts to read from the - * stream may generate an <code>IOException</code> - * <p> - * This method does nothing in this class, but subclasses may override - * this method in order to provide additional functionality. - * - * @exception IOException If an error occurs, which can only happen - * in a subclass - */ - public void close() throws IOException - { - // Do nothing - } - - /** - * This method marks a position in the input to which the stream can - * be "reset" by calling the <code>reset()</code> method. The - * parameter @code{readlimit} is the number of bytes that can be read - * from the stream after setting the mark before the mark becomes - * invalid. For example, if <code>mark()</code> is called with a - * read limit of 10, then when 11 bytes of data are read from the - * stream before the <code>reset()</code> method is called, then the - * mark is invalid and the stream object instance is not required to - * remember the mark. - * <p> - * This method does nothing in this class, but subclasses may override it - * to provide mark/reset functionality. - * - * @param readLimit The number of bytes that can be read before the - * mark becomes invalid - */ - public void mark(int readLimit) - { - // Do nothing - } - - /** - * This method returns a boolean that indicates whether the mark/reset - * methods are supported in this class. Those methods can be used to - * remember a specific point in the stream and reset the stream to that - * point. - * <p> - * This method always returns <code>false</code> in this class, but - * subclasses can override this method to return <code>true</code> - * if they support mark/reset functionality. - * - * @return <code>true</code> if mark/reset functionality is - * supported, <code>false</code> otherwise - */ - public boolean markSupported() - { - return false; - } - - /** - * This method reads an unsigned byte from the input stream and returns it - * as an int in the range of 0-255. This method also will return -1 if - * the end of the stream has been reached. - * <p> - * This method will block until the byte can be read. - * - * @return The byte read or -1 if end of stream - * - * @exception IOException If an error occurs - */ - public abstract int read() throws IOException; - - /** - * This method reads bytes from a stream and stores them into a caller - * supplied buffer. This method attempts to completely fill the buffer, - * but can return before doing so. The actual number of bytes read is - * returned as an int. A -1 is returned to indicate the end of the stream. - * <p> - * This method will block until some data can be read. - * <p> - * This method operates by calling an overloaded read method like so: - * <code>read(b, 0, b.length)</code> - * - * @param b The buffer into which the bytes read will be stored. - * - * @return The number of bytes read or -1 if end of stream. - * - * @exception IOException If an error occurs. - */ - public int read(byte[] b) throws IOException - { - return read(b, 0, b.length); - } - - /** - * This method read bytes from a stream and stores them into a - * caller supplied buffer. It starts storing the data at index - * <code>off</code> into the buffer and attempts to read - * <code>len</code> bytes. This method can return before reading the - * number of bytes requested. The actual number of bytes read is - * returned as an int. A -1 is returned to indicate the end of the - * stream. - * <p> - * This method will block until some data can be read. - * <p> - * This method operates by calling the single byte <code>read()</code> method - * in a loop until the desired number of bytes are read. The read loop - * stops short if the end of the stream is encountered or if an IOException - * is encountered on any read operation except the first. If the first - * attempt to read a bytes fails, the IOException is allowed to propagate - * upward. And subsequent IOException is caught and treated identically - * to an end of stream condition. Subclasses can (and should if possible) - * override this method to provide a more efficient implementation. - * - * @param b The array into which the bytes read should be stored - * @param off The offset into the array to start storing bytes - * @param len The requested number of bytes to read - * - * @return The actual number of bytes read, or -1 if end of stream. - * - * @exception IOException If an error occurs. - */ - public int read(byte[] b, int off, int len) throws IOException - { - if (off < 0 || len < 0 || off + len > b.length) - throw new IndexOutOfBoundsException(); - if (b.length == 0) - return 0; - - int i, ch; - - for (i = 0; i < len; ++i) - try - { - if ((ch = read()) < 0) - return i == 0 ? -1 : i; // EOF - b[off + i] = (byte) ch; - } - catch (IOException ex) - { - // Only reading the first byte should cause an IOException. - if (i == 0) - throw ex; - return i; - } - - return i; - } - - /** - * This method resets a stream to the point where the - * <code>mark()</code> method was called. Any bytes that were read - * after the mark point was set will be re-read during subsequent - * reads. - * <p> - * This method always throws an IOException in this class, but subclasses - * can override this method if they provide mark/reset functionality. - * - * @exception IOException Always thrown for this class - */ - public void reset() throws IOException - { - throw new IOException("mark/reset not supported"); - } - - /** - * This method skips the specified number of bytes in the stream. It - * returns the actual number of bytes skipped, which may be less than the - * requested amount. - * <p> - * This method reads and discards bytes into a byte array until the - * specified number of bytes were skipped or until either the end of stream - * is reached or a read attempt returns a short count. Subclasses can - * override this metho to provide a more efficient implementation where - * one exists. - * - * @param n The requested number of bytes to skip - * - * @return The actual number of bytes skipped. - * - * @exception IOException If an error occurs - */ - public long skip(long n) throws IOException - { - // Throw away n bytes by reading them into a temp byte[]. - // Limit the temp array to 2Kb so we don't grab too much memory. - final int buflen = n > 2048 ? 2048 : (int) n; - byte[] tmpbuf = new byte[buflen]; - final long origN = n; - - while (n > 0L) - { - int numread = read(tmpbuf, 0, n > buflen ? buflen : (int) n); - if (numread <= 0) - break; - n -= numread; - } - - return origN - n; - } -} diff --git a/libjava/java/io/InterruptedIOException.java b/libjava/java/io/InterruptedIOException.java deleted file mode 100644 index 96ec83649f8..00000000000 --- a/libjava/java/io/InterruptedIOException.java +++ /dev/null @@ -1,94 +0,0 @@ -/* InterruptedIOException.java -- an I/O operation was interrupted - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.io; - -/** - * This exception is thrown when a in process I/O operation is interrupted - * for some reason. The field bytesTransferred will contain the number of - * bytes that were read/written prior to the interruption. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Tom Tromey (tromey@cygnus.com) - * @see Thread#interrupt() - * @status updated to 1.4 - */ -public class InterruptedIOException extends IOException -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = 4020568460727500567L; - - /** - * The number of bytes read/written prior to the interruption. - * - * @serial count of bytes successfully transferred - */ - public int bytesTransferred; - - /** - * Create an extends without a descriptive error message. - */ - public InterruptedIOException() - { - } - - /** - * Create an exception with a descriptive error message. - * - * @param message the descriptive error message - */ - public InterruptedIOException(String message) - { - super(message); - } - - /** - * Create an exception with a descriptive error message and count of - * bytes transferred. - * - * @param message the descriptive error message - * @param bytesTransferred number of bytes tranferred before interruption - */ - InterruptedIOException(String message, int bytesTransferred) - { - super(message); - this.bytesTransferred = bytesTransferred; - } -} // class InterruptedIOException diff --git a/libjava/java/io/InvalidClassException.java b/libjava/java/io/InvalidClassException.java deleted file mode 100644 index c71b0c67fc7..00000000000 --- a/libjava/java/io/InvalidClassException.java +++ /dev/null @@ -1,111 +0,0 @@ -/* InvalidClassException.java -- deserializing a class failed - Copyright (C) 1998, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.io; - -/** - * This exception is thrown when there is some sort of problem with a - * class during a serialization operation. This could be:<br><ul> - * <li>the serial version of the class doesn't match</li> - * <li>the class contains unknown datatypes</li> - * <li>the class does not have an accessible no-arg constructor</li> - * </ul>. - * - * <p>The field <code>classname</code> will contain the name of the - * class that caused the problem if known. The getMessage() method - * for this exception will always include the name of that class - * if known. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @since 1.1 - * @status updated to 1.4 - */ -public class InvalidClassException extends ObjectStreamException -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = -4333316296251054416L; - - /** - * The name of the class which encountered the error. - * - * @serial the classname causing the error - */ - public String classname; - - /** - * Create an exception with a descriptive error message, but a null - * classname. - * - * @param message the descriptive error message - */ - public InvalidClassException(String message) - { - super(message); - } - - /** - * Create an exception with a descriptive error message, and the name of - * the class that caused the problem. - * - * @param classname the name of the faulty class - * @param message the descriptive error message - */ - public InvalidClassException(String classname, String message) - { - super(message); - this.classname = classname; - } - - /** - * Returns the descriptive error message for this exception. It will - * include the class name that caused the problem if known, in the format: - * <code>[classname][; ][super.getMessage()]</code>. - * - * @return A descriptive error message, may be null - */ - public String getMessage() - { - String msg = super.getMessage(); - if (msg == null) - return classname; - return (classname == null ? "" : classname + "; ") + msg; - } -} - diff --git a/libjava/java/io/InvalidObjectException.java b/libjava/java/io/InvalidObjectException.java deleted file mode 100644 index deee876db27..00000000000 --- a/libjava/java/io/InvalidObjectException.java +++ /dev/null @@ -1,66 +0,0 @@ -/* InvalidObjectException.java -- deserialization failed verification - Copyright (C) 1998, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.io; - -/** - * This exception is thrown when an object fails a validation test - * during serialization. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @since 1.1 - * @status updated to 1.4 - */ -public class InvalidObjectException extends ObjectStreamException -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = 3233174318281839583L; - - /** - * Create an exception with a descriptive error message String. This should - * be the cause of the verification failure. - * - * @param message the descriptive error message - */ - public InvalidObjectException(String message) - { - super(message); - } -} // class InvalidObjectException diff --git a/libjava/java/io/LineNumberInputStream.java b/libjava/java/io/LineNumberInputStream.java deleted file mode 100644 index 2552e467994..00000000000 --- a/libjava/java/io/LineNumberInputStream.java +++ /dev/null @@ -1,315 +0,0 @@ -/* LineNumberInputStream.java -- An input stream which counts line numbers - Copyright (C) 1998, 1999, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.io; - -/** - * This class functions like a standard <code>InputStream</code> - * except that it counts line numbers, and canonicalizes newline - * characters. As data is read, whenever the byte sequences "\r", - * "\n", or "\r\n" are encountered, the running line count is - * incremeted by one. Additionally, the whatever line termination - * sequence was encountered will be converted to a "\n" byte. Note - * that this class numbers lines from 0. When the first line - * terminator is encountered, the line number is incremented to 1, and - * so on. - * <p> - * This class counts only line termination characters. If the last line - * read from the stream does not end in a line termination sequence, it - * will not be counted as a line. - * <p> - * Note that since this class operates as a filter on an underlying - * stream, it has the same mark/reset functionality as the underlying - * stream. The <code>mark()</code> and <code>reset()</code> methods - * in this class handle line numbers correctly. Calling - * <code>reset()</code> resets the line number to the point at which - * <code>mark()</code> was called if the subordinate stream supports - * that functionality. - * <p> - * @deprecated This class is deprecated in favor if - * <code>LineNumberReader</code> because it operates on ASCII bytes - * instead of an encoded character stream. This class is for backward - * compatibility only and should not be used in new applications. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Warren Levy (warrenl@cygnus.com) - */ -public class LineNumberInputStream extends FilterInputStream -{ - /** The current line number. */ - private int lineNumber = 0; - - /** The line number when the stream was marked. */ - private int markLineNumber = 0; - - /** Flag to indicate a '\r' was just read so that an immediately - * subsequent '\n' can be ignored. */ - private boolean justReadReturnChar = false; - - /** - * Create a new <code>LineNumberInputStream</code> that reads from the - * specified subordinate <code>InputStream</code> - * - * @param in The subordinate <code>InputStream</code> to read from - */ - public LineNumberInputStream(InputStream in) - { - super(in); - } - - /** - * This method returns the number of bytes that can be read from the - * stream before the stream can block. This method is tricky - * because the subordinate <code>InputStream</code> might return - * only "\r\n" characters, which are replaced by a single "\n" - * character by the <code>read()</code> method of this class. So - * this method can only guarantee that <code>in.available() / - * 2</code> bytes can actually be read before blocking. In - * practice, considerably more bytes might be read before blocking - * <p> - * Note that the stream may not block if additional bytes beyond the count - * returned by this method are read. - * - * @return The number of bytes that can be read before blocking could occur - * - * @exception IOException If an error occurs - */ - public int available() throws IOException - { - // We can only guarantee half the characters that might be available - // without blocking because "\r\n" is treated as a single character. - return in.available() / 2; - } - - /** - * This method returns the current line number - * - * @return The current line number - */ - public int getLineNumber() - { - return lineNumber; - } - - /** - * This method marks a position in the input to which the stream can - * be "reset" byte calling the <code>reset()</code> method. The - * parameter <code>readlimit</code> is the number of bytes that can - * be read from the stream after setting the mark before the mark - * becomes invalid. For example, if <code>mark()</code> is called - * with a read limit of 10, then when 11 bytes of data are read from - * the stream before the <code>reset()</code> method is called, then - * the mark is invalid and the stream object instance is not - * required to remember the mark. - * <p> - * In this class, this method will remember the current line number - * as well as the current position in the stream. When the - * <code>reset()</code> method is called, the line number will be - * restored to the saved line number in addition to the stream - * position. - * <p> - * This method only works if the subordinate stream supports mark/reset - * functionality. - * - * @param readlimit The number of bytes that can be read before the - * mark becomes invalid - */ - public void mark(int readlimit) - { - in.mark(readlimit); - markLineNumber = lineNumber; - } - - /** - * This method reads an unsigned byte from the input stream and returns it - * as an int in the range of 0-255. This method will return -1 if the - * end of the stream has been reached. - * <p> - * Note that if a line termination sequence is encountered (ie, "\r", - * "\n", or "\r\n") then that line termination sequence is converted to - * a single "\n" value which is returned from this method. This means - * that it is possible this method reads two bytes from the subordinate - * stream instead of just one. - * <p> - * Note that this method will block until a byte of data is available - * to be read. - * - * @return The byte read or -1 if end of stream - * - * @exception IOException If an error occurs - */ - public int read() throws IOException - { - // Treat "\r\n" as a single character. A '\r' may have been read by - // a previous call to read so we keep an internal flag to avoid having - // to read ahead. - - int ch = in.read(); - - if (ch == '\n') - if (justReadReturnChar) - { - ch = in.read(); - justReadReturnChar = false; - } - else - lineNumber++; - else if (ch == '\r') - { - ch = '\n'; - justReadReturnChar = true; - lineNumber++; - } - else - justReadReturnChar = false; - - return ch; - } - - /** - * This method reads bytes from a stream and stores them into a caller - * supplied buffer. It starts storing data at index <code>offset</code> into - * the buffer and attemps to read <code>len</code> bytes. This method can - * return before reading the number of bytes requested. The actual number - * of bytes read is returned as an int. A -1 is returned to indicated the - * end of the stream. - * <p> - * This method will block until some data can be read. - * <p> - * Note that if a line termination sequence is encountered (ie, "\r", - * "\n", or "\r\n") then that line termination sequence is converted to - * a single "\n" value which is stored in the buffer. Only a single - * byte is counted towards the number of bytes read in this case. - * - * @param buf The array into which the bytes read should be stored - * @param offset The offset into the array to start storing bytes - * @param len The requested number of bytes to read - * - * @return The actual number of bytes read, or -1 if end of stream - * - * @exception IOException If an error occurs. - */ - public int read(byte[] b, int off, int len) throws IOException - { - if (off < 0 || len < 0 || off + len > b.length) - throw new ArrayIndexOutOfBoundsException(); - - // This case always succeeds. - if (len == 0) - return 0; - - // The simplest, though not necessarily the most time efficient thing - // to do is simply call read(void) len times. Since this is a deprecated - // class, that should be ok. - final int origOff = off; - while (len-- > 0) - { - int ch = read(); - if (ch < 0) - break; - - b[off++] = (byte) ch; - } - - // This is safe since we already know that some bytes were - // actually requested. - return off == origOff ? -1 : off - origOff; - } - - /** - * This method resets a stream to the point where the - * <code>mark()</code> method was called. Any bytes that were read - * after the mark point was set will be re-read during subsequent - * reads. - * <p> - * In this class, this method will also restore the line number that was - * current when the <code>mark()</code> method was called. - * <p> - * This method only works if the subordinate stream supports mark/reset - * functionality. - * - * @exception IOException If an error occurs - */ - public void reset() throws IOException - { - in.reset(); - lineNumber = markLineNumber; - justReadReturnChar = false; - } - - /** - * This method sets the current line number to the specified value. - * - * @param lineNumber The new line number - */ - public void setLineNumber(int lineNumber) - { - this.lineNumber = lineNumber; - } - - /** - * This method skips up to the requested number of bytes in the - * input stream. The actual number of bytes skipped is returned. If the - * desired number of bytes to skip is negative, no bytes are skipped. - * - * @param n requested number of bytes to skip. - * - * @return The actual number of bytes skipped. - * - * @exception IOException If an error occurs. - */ - public long skip(long n) throws IOException - { - if (n <= 0) - return 0L; - - final long origN = n; - - do - { - int ch = read(); - if (ch < 0) - break; - if (ch == '\n' || ch == '\r') - lineNumber++; - } - while (--n > 0); - - return origN - n; - } -} diff --git a/libjava/java/io/LineNumberReader.java b/libjava/java/io/LineNumberReader.java deleted file mode 100644 index ea418a5e4d6..00000000000 --- a/libjava/java/io/LineNumberReader.java +++ /dev/null @@ -1,417 +0,0 @@ -/* LineNumberReader.java -- A character input stream which counts line numbers - Copyright (C) 1998, 1999, 2001, 2003, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.io; - -/** - * This class functions like a standard <code>Reader</code> except that it - * counts line numbers, and canonicalizes newline characters. As data - * is read, whenever the char sequences "\r", "\n", or "\r\n" are encountered, - * the running line count is incremeted by one. Additionally, the whatever - * line termination sequence was encountered will be converted to a "\n" - * char. Note that this class numbers lines from 0. When the first - * line terminator is encountered, the line number is incremented to 1, and - * so on. Also note that actual "\r" and "\n" characters are looked for. - * The system dependent line separator sequence is ignored. - * <p> - * This class counts only line termination characters. If the last line - * read from the stream does not end in a line termination sequence, it - * will not be counted as a line. - * - * @author Per Bothner (bothner@cygnus.com) - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Guilhem Lavaux (guilhem@kaffe.org) - * @date December 28, 2003. - */ -/* Written using "Java Class Libraries", 2nd edition, plus online - * API docs for JDK 1.2 beta from http://www.javasoft.com. - * Status: Believed complete and correct. - * - * This implementation has the feature that if '\r' is read, it - * does not look for a '\n', but immediately returns '\n'. - * On the next read(), if a '\n' is read, it is skipped. - * This has the advantage that we do not read (and hang) unnecessarily. - * - * This implementation is also minimal in the number of fields it uses. - */ -public class LineNumberReader extends BufferedReader -{ - /** The current line number. */ - private int lineNumber; - /** Whether we already found a new line in the former call. */ - private boolean matchedNewLine; - /** The saved line number when calling mark() */ - private int savedLineNumber; - - /** - * Create a new <code>LineNumberReader</code> that reads from the - * specified subordinate <code>Reader</code>. A default 8K char sized - * buffer will be used for reads. - * - * @param in The subordinate <code>Reader</code> to read from - */ - public LineNumberReader(Reader in) - { - super(in, DEFAULT_BUFFER_SIZE); - } - - /** - * This method initializes a new <code>LineNumberReader</code> to read - * from the specified subordinate <code>Reader</code> using the specified - * read buffer size. - * - * @param in The subordinate <code>Reader</code> to read from - * @param size The buffer size to use for reading - */ - public LineNumberReader(Reader in, int size) - { - super(in, size); - } - - /** - * This method returns the current line number - * - * @return The current line number - */ - public int getLineNumber() - { - return lineNumber; - } - - /** - * This method sets the current line number to the specified value. - * - * @param line_number The new line number - */ - public void setLineNumber(int lineNumber) - { - this.lineNumber = lineNumber; - } - - /** - * This method marks a position in the input to which the stream can be - * "reset" char calling the <code>reset()</code> method. The parameter - * <code>readlimit</code> is the number of chars that can be read from the - * stream after setting the mark before the mark becomes invalid. For - * example, if <code>mark()</code> is called with a read limit of 10, - * then when - * 11 chars of data are read from the stream before the <code>reset()</code> - * method is called, then the mark is invalid and the stream object - * instance is not required to remember the mark. - * <p> - * In this class, this method will remember the current line number as well - * as the current position in the stream. When the <code>reset()</code> - * method - * is called, the line number will be restored to the saved line number in - * addition to the stream position. - * - * @param readlimit The number of chars that can be read before the - * mark becomes invalid - * - * @exception IOException If an error occurs - */ - public void mark(int readLimit) throws IOException - { - if (readLimit < 0) - throw new IllegalArgumentException("Read-ahead limit is negative"); - - synchronized (lock) - { - // This is basically the same as BufferedReader.mark. - // However, if the previous character was a '\r', we need to - // save that 'r', in case the next character is a '\n'. - if (pos + readLimit > limit) - { - int saveCR = matchedNewLine ? 1 : 0; - char[] old_buffer = buffer; - if (readLimit > limit) - buffer = new char[saveCR + readLimit]; - int copy_start = pos - saveCR; - savedLineNumber = lineNumber; - limit -= copy_start; - System.arraycopy(old_buffer, copy_start, buffer, 0, limit); - pos = saveCR; - } - markPos = pos; - } - } - - /** - * This method resets a stream to the point where the <code>mark()</code> - * method - * was called. Any chars that were read after the mark point was set will - * be re-read during subsequent reads. - * <p> - * In this class, this method will also restore the line number that was - * current when the <code>mark()</code> method was called. - * - * @exception IOException If an error occurs - */ - public void reset() throws IOException - { - synchronized (lock) - { - if (markPos < 0) - throw new IOException("mark never set or invalidated"); - lineNumber = savedLineNumber; - pos = markPos; - matchedNewLine = (markPos > 0 && buffer[markPos-1] == '\r'); - } - } - - /** - * This private method fills the input buffer whatever pos is. - * Consequently pos should be checked before calling this method. - * - * @return the number of bytes actually read from the input stream or - * -1 if end of stream. - * @exception IOException If an error occurs. - */ - private int fill() throws IOException - { - if (markPos >= 0 && limit == buffer.length) - markPos = -1; - if (markPos < 0) - pos = limit = 0; - int count = in.read(buffer, limit, buffer.length - limit); - if (count <= 0) - return -1; - limit += count; - - return count; - } - - /** - * This method reads an unsigned char from the input stream and returns it - * as an int in the range of 0-65535. This method will return -1 if the - * end of the stream has been reached. - * <p> - * Note that if a line termination sequence is encountered (ie, "\r", - * "\n", or "\r\n") then that line termination sequence is converted to - * a single "\n" value which is returned from this method. This means - * that it is possible this method reads two chars from the subordinate - * stream instead of just one. - * <p> - * Note that this method will block until a char of data is available - * to be read. - * - * @return The char read or -1 if end of stream - * - * @exception IOException If an error occurs - */ - public int read() throws IOException - { - synchronized (lock) - { - skipRedundantLF(); - if (pos >= limit && fill() < 0) - return -1; - char ch = buffer[pos++]; - - if ((matchedNewLine = (ch == '\r')) || ch == '\n') - { - lineNumber++; - return '\n'; - } - matchedNewLine = false; - return (int) ch; - } - } - - /** - * This method reads chars from a stream and stores them into a caller - * supplied buffer. It starts storing data at index <code>offset</code> into - * the buffer and attemps to read <code>len</code> chars. This method can - * return before reading the number of chars requested. The actual number - * of chars read is returned as an int. A -1 is returned to indicated the - * end of the stream. - * <p> - * This method will block until some data can be read. - * <p> - * Note that if a line termination sequence is encountered (ie, "\r", - * "\n", or "\r\n") then that line termination sequence is converted to - * a single "\n" value which is stored in the buffer. Only a single - * char is counted towards the number of chars read in this case. - * - * @param buf The array into which the chars read should be stored - * @param offset The offset into the array to start storing chars - * @param len The requested number of chars to read - * - * @return The actual number of chars read, or -1 if end of stream - * - * @exception IOException If an error occurs. - * @exception NullPointerException If buf is null (in any case). - * @exception IndexOutOfBoundsException If buffer parameters (offset and - * count) lies outside of the buffer capacity. - */ - public int read(char[] buf, int offset, int count) throws IOException - { - if (buf == null) - throw new NullPointerException(); - - if (offset + count > buf.length || offset < 0) - throw new IndexOutOfBoundsException(); - - if (count <= 0) - { - if (count < 0) - throw new IndexOutOfBoundsException(); - return 0; - } - - synchronized (lock) - { - if (pos >= limit && fill() < 0) - return -1; - - int start_offset = offset; - boolean matched = matchedNewLine; - - while (count-- > 0 && pos < limit) - { - char ch = buffer[pos++]; - if (ch == '\r') - { - lineNumber++; - matched = true; - } - else if (ch == '\n' && !matched) - lineNumber++; - else - matched = false; - - buf[offset++] = ch; - } - - matchedNewLine = matched; - return offset - start_offset; - } - } - - private void skipRedundantLF() throws IOException - { - if (pos > 0 && matchedNewLine) - { - if (pos < limit) - { // fast case - if (buffer[pos] == '\n') - pos++; - } - else - { // check whether the next buffer begins with '\n'. - // in that case kill the '\n'. - if (fill() <= 0) - return; - if (buffer[pos] == '\n') - pos++; - } - matchedNewLine = true; - } - } - - /** - * This method reads a line of text from the input stream and returns - * it as a <code>String</code>. A line is considered to be terminated - * by a "\r", "\n", or "\r\n" sequence, not by the system dependent line - * separator. - * - * @return The line read as a <code>String</code> or <code>null</code> - * if end of stream. - * - * @exception IOException If an error occurs - */ - public String readLine() throws IOException - { - // BufferedReader.readLine already does this. Shouldn't need to keep - // track of newlines (since the read method deals with this for us). - // But if the buffer is large, we may not call the read method at all - // and super.readLine can't increment lineNumber itself. - // Though it may seem kludgy, the safest thing to do is to save off - // lineNumber and increment it explicitly when we're done (iff we - // ended with a '\n' or '\r' as opposed to EOF). - // - // Also, we need to undo the special casing done by BufferedReader.readLine - // when a '\r' is the last char in the buffer. That situation is marked - // by 'pos > limit'. - int tmpLineNumber = lineNumber; - skipRedundantLF(); - String str = super.readLine(); - if (pos > limit) - --pos; - - // The only case where you mustn't increment the line number is you are - // at the EOS. - if (str != null) - lineNumber = tmpLineNumber + 1; - - return str; - } - - /** - * This method skips over characters in the stream. This method will - * skip the specified number of characters if possible, but is not required - * to skip them all. The actual number of characters skipped is returned. - * This method returns 0 if the specified number of chars is less than 1. - * - * @param count The specified number of chars to skip. - * - * @return The actual number of chars skipped. - * - * @exception IOException If an error occurs - */ - public long skip (long count) throws IOException - { - if (count < 0) - throw new IllegalArgumentException("skip() value is negative"); - if (count == 0) - return 0; - - int skipped; - char[] buf = new char[1]; - - for (skipped = 0; skipped < count; skipped++) - { - int ch = read(buf, 0, 1); - - if (ch < 0) - break; - } - - return skipped; - } -} - diff --git a/libjava/java/io/NotActiveException.java b/libjava/java/io/NotActiveException.java deleted file mode 100644 index 949ba8eca52..00000000000 --- a/libjava/java/io/NotActiveException.java +++ /dev/null @@ -1,72 +0,0 @@ -/* NotActiveException.java -- thrown when serialization is not active - Copyright (C) 1998, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.io; - -/** - * This exception is thrown when a problem occurs due to the fact that - * serialization is not active. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @since 1.1 - * @status updated to 1.4 - */ -public class NotActiveException extends ObjectStreamException -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = -3893467273049808895L; - - /** - * Create an exception without a descriptive error message. - */ - public NotActiveException() - { - } - - /** - * Create an exception with a descriptive error message. - * - * @param message the descriptive error message - */ - public NotActiveException(String message) - { - super(message); - } -} // class NotActiveException diff --git a/libjava/java/io/NotSerializableException.java b/libjava/java/io/NotSerializableException.java deleted file mode 100644 index d49c939e31d..00000000000 --- a/libjava/java/io/NotSerializableException.java +++ /dev/null @@ -1,74 +0,0 @@ -/* NotSerializableException.java -- a Serializable class that isn't - Copyright (C) 1998, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.io; - -/** - * This exception is thrown when a class implements Serializable because - * of a superclass, but should not be serialized. The descriptive message - * will consist of the name of the class in question. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @since 1.1 - * @status updated to 1.4 - */ -public class NotSerializableException extends ObjectStreamException -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = 2906642554793891381L; - - /** - * Create an exception without a descriptive error message. - */ - public NotSerializableException() - { - } - - /** - * Create an exception with a descriptive error message, which should - * be the name of the class. - * - * @param message the descriptive error message - */ - public NotSerializableException(String message) - { - super(message); - } -} // class NotSerializableException diff --git a/libjava/java/io/ObjectInput.java b/libjava/java/io/ObjectInput.java deleted file mode 100644 index 175b60f9dc0..00000000000 --- a/libjava/java/io/ObjectInput.java +++ /dev/null @@ -1,140 +0,0 @@ -/* ObjectInput.java -- Read object data from a stream - Copyright (C) 1998,2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.io; - -/** - * This interface extends the <code>DataInput</code> interface to provide a - * facility to read objects as well as primitive types from a stream. It - * also has methods that allow input to be done in a manner similar to - * <code>InputStream</code> - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * - * @see DataInput - */ -public interface ObjectInput extends DataInput -{ - /** - * This method returns the number of bytes that can be read without - * blocking. - * - * @return The number of bytes available before blocking - * - * @exception IOException If an error occurs - */ - int available() throws IOException; - - /** - * This method reading a byte of data from a stream. It returns that byte - * as an <code>int</code>. This method blocks if no data is available - * to be read. - * - * @return The byte of data read - * - * @exception IOException If an error occurs - */ - int read() throws IOException; - - /** - * This method reads raw bytes and stores them them a byte array buffer. - * Note that this method will block if no data is available. However, - * it will not necessarily block until it fills the entire buffer. That is, - * a "short count" is possible. - * - * @param buf The byte array to receive the data read - * - * @return The actual number of bytes read or -1 if end of stream - * - * @exception IOException If an error occurs - */ - int read(byte[] buf) throws IOException; - - /** - * This method reads raw bytes and stores them in a byte array buffer - * <code>buf</code> starting at position <code>offset</code> into the - * buffer. A - * maximum of <code>len</code> bytes will be read. Note that this method - * blocks if no data is available, but will not necessarily block until - * it can read <code>len</code> bytes of data. That is, a "short count" is - * possible. - * - * @param buf The byte array to receive the data read - * @param offset The offset into <code>buf</code> to start storing data - * @param len The maximum number of bytes to read - * - * @return The actual number of bytes read or -1 if end of stream - * - * @exception IOException If an error occurs - */ - int read(byte[] buf, int offset, int len) throws IOException; - - /** - * Reads an object instance and returns it. If the class for the object - * being read cannot be found, then a <code>ClassNotFoundException</code> - * will be thrown. - * - * @return The object instance that was read - * - * @exception ClassNotFoundException If a class for the object cannot be - * found - * @exception IOException If any other error occurs - */ - Object readObject() - throws ClassNotFoundException, IOException; - - /** - * This method causes the specified number of bytes to be read and - * discarded. It is possible that fewer than the requested number of bytes - * will actually be skipped. - * - * @param numBytes The number of bytes to skip - * - * @return The actual number of bytes skipped - * - * @exception IOException If an error occurs - */ - long skip(long numBytes) throws IOException; - - /** - * This method closes the input source - * - * @exception IOException If an error occurs - */ - void close() throws IOException; -} diff --git a/libjava/java/io/ObjectInputValidation.java b/libjava/java/io/ObjectInputValidation.java deleted file mode 100644 index 4fdb8414f63..00000000000 --- a/libjava/java/io/ObjectInputValidation.java +++ /dev/null @@ -1,67 +0,0 @@ -/* ObjectInputValidation.java -- Validate an object - Copyright (C) 1998, 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.io; - -/** - * This class allows an object to validate that it is valid after - * deserialization has run completely for it and all dependent objects. - * This allows an object to determine if it is invalid even if all - * state data was correctly deserialized from the stream. It can also - * be used to perform re-initialization type activities on an object - * after it has been completely deserialized. - * - * Since this method functions as a type of callback, it must be - * registered through <code>ObjectInputStream.registerValidation</code> - * in order to be invoked. This is typically done in the - * <code>readObject</code> method. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * - * @see ObjectInputStream#registerValidation - */ -public interface ObjectInputValidation -{ - /** - * This method is called to validate an object after serialization - * is complete. If the object is invalid an exception is thrown. - * - * @exception InvalidObjectException If the object is invalid - */ - void validateObject() throws InvalidObjectException; -} diff --git a/libjava/java/io/ObjectOutput.java b/libjava/java/io/ObjectOutput.java deleted file mode 100644 index d35a09c3acb..00000000000 --- a/libjava/java/io/ObjectOutput.java +++ /dev/null @@ -1,111 +0,0 @@ -/* ObjectOutput.java -- Interface for writing objects to a stream - Copyright (C) 1998, 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.io; - -/** - * This interface extends <code>DataOutput</code> to provide the additional - * facility of writing object instances to a stream. It also adds some - * additional methods to make the interface more - * <code>OutputStream</code> like. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * - * @see DataOutput - */ -public interface ObjectOutput extends DataOutput -{ - /** - * This method writes the specified byte to the output stream. - * - * @param b The byte to write. - * - * @exception IOException If an error occurs. - */ - void write(int b) throws IOException; - - /** - * This method writes all the bytes in the specified byte array to the - * output stream. - * - * @param buf The array of bytes to write. - * - * @exception IOException If an error occurs. - */ - void write(byte[] buf) throws IOException; - - /** - * This method writes <code>len</code> bytes from the specified array - * starting at index <code>offset</code> into that array. - * - * @param buf The byte array to write from. - * @param offset The index into the byte array to start writing from. - * @param len The number of bytes to write. - * - * @exception IOException If an error occurs. - */ - void write(byte[] buf, int offset, int len) - throws IOException; - - /** - * This method writes a object instance to a stream. The format of the - * data written is determined by the actual implementation of this method - * - * @param obj The object to write - * - * @exception IOException If an error occurs - */ - void writeObject(Object obj) throws IOException; - - /** - * This method causes any buffered data to be flushed out to the underlying - * stream - * - * @exception IOException If an error occurs - */ - void flush() throws IOException; - - /** - * This method closes the underlying stream. - * - * @exception IOException If an error occurs - */ - void close() throws IOException; - -} // interface ObjectOutput - diff --git a/libjava/java/io/ObjectOutputStream.java b/libjava/java/io/ObjectOutputStream.java deleted file mode 100644 index e7f1fc84b93..00000000000 --- a/libjava/java/io/ObjectOutputStream.java +++ /dev/null @@ -1,1570 +0,0 @@ -/* ObjectOutputStream.java -- Class used to write serialized objects - Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004 - Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.io; - -import gnu.classpath.Configuration; -import gnu.java.io.ObjectIdentityWrapper; -import gnu.java.lang.reflect.TypeSignature; -import gnu.java.security.action.SetAccessibleAction; - -import java.lang.reflect.Array; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.security.AccessController; -import java.util.Hashtable; - -/** - * An <code>ObjectOutputStream</code> can be used to write objects - * as well as primitive data in a platform-independent manner to an - * <code>OutputStream</code>. - * - * The data produced by an <code>ObjectOutputStream</code> can be read - * and reconstituted by an <code>ObjectInputStream</code>. - * - * <code>writeObject (Object)</code> is used to write Objects, the - * <code>write<type></code> methods are used to write primitive - * data (as in <code>DataOutputStream</code>). Strings can be written - * as objects or as primitive data. - * - * Not all objects can be written out using an - * <code>ObjectOutputStream</code>. Only those objects that are an - * instance of <code>java.io.Serializable</code> can be written. - * - * Using default serialization, information about the class of an - * object is written, all of the non-transient, non-static fields of - * the object are written, if any of these fields are objects, they are - * written out in the same manner. - * - * An object is only written out the first time it is encountered. If - * the object is encountered later, a reference to it is written to - * the underlying stream. Thus writing circular object graphs - * does not present a problem, nor are relationships between objects - * in a graph lost. - * - * Example usage: - * <pre> - * Hashtable map = new Hashtable (); - * map.put ("one", new Integer (1)); - * map.put ("two", new Integer (2)); - * - * ObjectOutputStream oos = - * new ObjectOutputStream (new FileOutputStream ("numbers")); - * oos.writeObject (map); - * oos.close (); - * - * ObjectInputStream ois = - * new ObjectInputStream (new FileInputStream ("numbers")); - * Hashtable newmap = (Hashtable)ois.readObject (); - * - * System.out.println (newmap); - * </pre> - * - * The default serialization can be overriden in two ways. - * - * By defining a method <code>private void - * writeObject (ObjectOutputStream)</code>, a class can dictate exactly - * how information about itself is written. - * <code>defaultWriteObject ()</code> may be called from this method to - * carry out default serialization. This method is not - * responsible for dealing with fields of super-classes or subclasses. - * - * By implementing <code>java.io.Externalizable</code>. This gives - * the class complete control over the way it is written to the - * stream. If this approach is used the burden of writing superclass - * and subclass data is transfered to the class implementing - * <code>java.io.Externalizable</code>. - * - * @see java.io.DataOutputStream - * @see java.io.Externalizable - * @see java.io.ObjectInputStream - * @see java.io.Serializable - */ -public class ObjectOutputStream extends OutputStream - implements ObjectOutput, ObjectStreamConstants -{ - /** - * Creates a new <code>ObjectOutputStream</code> that will do all of - * its writing onto <code>out</code>. This method also initializes - * the stream by writing the header information (stream magic number - * and stream version). - * - * @exception IOException Writing stream header to underlying - * stream cannot be completed. - * - * @see #writeStreamHeader() - */ - public ObjectOutputStream (OutputStream out) throws IOException - { - realOutput = new DataOutputStream(out); - blockData = new byte[ BUFFER_SIZE ]; - blockDataCount = 0; - blockDataOutput = new DataOutputStream(this); - setBlockDataMode(true); - replacementEnabled = false; - isSerializing = false; - nextOID = baseWireHandle; - OIDLookupTable = new Hashtable(); - protocolVersion = defaultProtocolVersion; - useSubclassMethod = false; - writeStreamHeader(); - - if (Configuration.DEBUG) - { - String val = System.getProperty("gcj.dumpobjects"); - if (val != null && !val.equals("")) - dump = true; - } - } - - /** - * Writes a representation of <code>obj</code> to the underlying - * output stream by writing out information about its class, then - * writing out each of the objects non-transient, non-static - * fields. If any of these fields are other objects, - * they are written out in the same manner. - * - * This method can be overriden by a class by implementing - * <code>private void writeObject (ObjectOutputStream)</code>. - * - * If an exception is thrown from this method, the stream is left in - * an undefined state. - * - * @exception NotSerializableException An attempt was made to - * serialize an <code>Object</code> that is not serializable. - * - * @exception InvalidClassException Somebody tried to serialize - * an object which is wrongly formatted. - * - * @exception IOException Exception from underlying - * <code>OutputStream</code>. - */ - public final void writeObject(Object obj) throws IOException - { - if (useSubclassMethod) - { - if (dump) - dumpElementln ("WRITE OVERRIDE: " + obj); - - writeObjectOverride(obj); - return; - } - - if (dump) - dumpElementln ("WRITE: " + obj); - - depth += 2; - - boolean was_serializing = isSerializing; - boolean old_mode = setBlockDataMode(false); - try - { - isSerializing = true; - boolean replaceDone = false; - Object replacedObject = null; - - while (true) - { - if (obj == null) - { - realOutput.writeByte(TC_NULL); - break; - } - - Integer handle = findHandle(obj); - if (handle != null) - { - realOutput.writeByte(TC_REFERENCE); - realOutput.writeInt(handle.intValue()); - break; - } - - if (obj instanceof Class) - { - Class cl = (Class)obj; - ObjectStreamClass osc = ObjectStreamClass.lookupForClassObject(cl); - realOutput.writeByte(TC_CLASS); - if (!osc.isProxyClass) - { - writeObject (osc); - } - else - { - realOutput.writeByte(TC_PROXYCLASSDESC); - Class[] intfs = cl.getInterfaces(); - realOutput.writeInt(intfs.length); - for (int i = 0; i < intfs.length; i++) - realOutput.writeUTF(intfs[i].getName()); - - boolean oldmode = setBlockDataMode(true); - annotateProxyClass(cl); - setBlockDataMode(oldmode); - realOutput.writeByte(TC_ENDBLOCKDATA); - - writeObject(osc.getSuper()); - } - assignNewHandle(obj); - break; - } - - if (obj instanceof ObjectStreamClass) - { - writeClassDescriptor((ObjectStreamClass) obj); - break; - } - - Class clazz = obj.getClass(); - ObjectStreamClass osc = ObjectStreamClass.lookupForClassObject(clazz); - if (osc == null) - throw new NotSerializableException(clazz.getName()); - - if ((replacementEnabled || obj instanceof Serializable) - && ! replaceDone) - { - replacedObject = obj; - - if (obj instanceof Serializable) - { - try - { - Method m = osc.writeReplaceMethod; - if (m != null) - obj = m.invoke(obj, new Object[0]); - } - catch (IllegalAccessException ignore) - { - } - catch (InvocationTargetException ignore) - { - } - } - - if (replacementEnabled) - obj = replaceObject(obj); - - replaceDone = true; - continue; - } - - if (obj instanceof String) - { - realOutput.writeByte(TC_STRING); - assignNewHandle(obj); - realOutput.writeUTF((String)obj); - break; - } - - if (clazz.isArray ()) - { - realOutput.writeByte(TC_ARRAY); - writeObject(osc); - assignNewHandle(obj); - writeArraySizeAndElements(obj, clazz.getComponentType()); - break; - } - - realOutput.writeByte(TC_OBJECT); - writeObject(osc); - - if (replaceDone) - assignNewHandle(replacedObject); - else - assignNewHandle(obj); - - if (obj instanceof Externalizable) - { - if (protocolVersion == PROTOCOL_VERSION_2) - setBlockDataMode(true); - - ((Externalizable)obj).writeExternal(this); - - if (protocolVersion == PROTOCOL_VERSION_2) - { - setBlockDataMode(false); - realOutput.writeByte(TC_ENDBLOCKDATA); - } - - break; - } - - if (obj instanceof Serializable) - { - Object prevObject = this.currentObject; - ObjectStreamClass prevObjectStreamClass = this.currentObjectStreamClass; - currentObject = obj; - ObjectStreamClass[] hierarchy = - ObjectStreamClass.getObjectStreamClasses(clazz); - - for (int i = 0; i < hierarchy.length; i++) - { - currentObjectStreamClass = hierarchy[i]; - - fieldsAlreadyWritten = false; - if (currentObjectStreamClass.hasWriteMethod()) - { - if (dump) - dumpElementln ("WRITE METHOD CALLED FOR: " + obj); - setBlockDataMode(true); - callWriteMethod(obj, currentObjectStreamClass); - setBlockDataMode(false); - realOutput.writeByte(TC_ENDBLOCKDATA); - if (dump) - dumpElementln ("WRITE ENDBLOCKDATA FOR: " + obj); - } - else - { - if (dump) - dumpElementln ("WRITE FIELDS CALLED FOR: " + obj); - writeFields(obj, currentObjectStreamClass); - } - } - - this.currentObject = prevObject; - this.currentObjectStreamClass = prevObjectStreamClass; - currentPutField = null; - break; - } - - throw new NotSerializableException(clazz.getName ()); - } // end pseudo-loop - } - catch (ObjectStreamException ose) - { - // Rethrow these are fatal. - throw ose; - } - catch (IOException e) - { - realOutput.writeByte(TC_EXCEPTION); - reset(true); - - setBlockDataMode(false); - try - { - if (Configuration.DEBUG) - { - e.printStackTrace(System.out); - } - writeObject(e); - } - catch (IOException ioe) - { - StreamCorruptedException ex = - new StreamCorruptedException - (ioe + " thrown while exception was being written to stream."); - if (Configuration.DEBUG) - { - ex.printStackTrace(System.out); - } - throw ex; - } - - reset (true); - - } - finally - { - isSerializing = was_serializing; - setBlockDataMode(old_mode); - depth -= 2; - - if (dump) - dumpElementln ("END: " + obj); - } - } - - protected void writeClassDescriptor(ObjectStreamClass osc) throws IOException - { - realOutput.writeByte(TC_CLASSDESC); - realOutput.writeUTF(osc.getName()); - realOutput.writeLong(osc.getSerialVersionUID()); - assignNewHandle(osc); - - int flags = osc.getFlags(); - - if (protocolVersion == PROTOCOL_VERSION_2 - && osc.isExternalizable()) - flags |= SC_BLOCK_DATA; - - realOutput.writeByte(flags); - - ObjectStreamField[] fields = osc.fields; - realOutput.writeShort(fields.length); - - ObjectStreamField field; - for (int i = 0; i < fields.length; i++) - { - field = fields[i]; - realOutput.writeByte(field.getTypeCode ()); - realOutput.writeUTF(field.getName ()); - - if (! field.isPrimitive()) - writeObject(field.getTypeString()); - } - - boolean oldmode = setBlockDataMode(true); - annotateClass(osc.forClass()); - setBlockDataMode(oldmode); - realOutput.writeByte(TC_ENDBLOCKDATA); - - if (osc.isSerializable() || osc.isExternalizable()) - writeObject(osc.getSuper()); - else - writeObject(null); - } - - /** - * Writes the current objects non-transient, non-static fields from - * the current class to the underlying output stream. - * - * This method is intended to be called from within a object's - * <code>private void writeObject (ObjectOutputStream)</code> - * method. - * - * @exception NotActiveException This method was called from a - * context other than from the current object's and current class's - * <code>private void writeObject (ObjectOutputStream)</code> - * method. - * - * @exception IOException Exception from underlying - * <code>OutputStream</code>. - */ - public void defaultWriteObject() - throws IOException, NotActiveException - { - markFieldsWritten(); - writeFields(currentObject, currentObjectStreamClass); - } - - - private void markFieldsWritten() throws IOException - { - if (currentObject == null || currentObjectStreamClass == null) - throw new NotActiveException - ("defaultWriteObject called by non-active class and/or object"); - - if (fieldsAlreadyWritten) - throw new IOException - ("Only one of writeFields and defaultWriteObject may be called, and it may only be called once"); - - fieldsAlreadyWritten = true; - } - - /** - * Resets stream to state equivalent to the state just after it was - * constructed. - * - * Causes all objects previously written to the stream to be - * forgotten. A notification of this reset is also written to the - * underlying stream. - * - * @exception IOException Exception from underlying - * <code>OutputStream</code> or reset called while serialization is - * in progress. - */ - public void reset() throws IOException - { - reset(false); - } - - - private void reset(boolean internal) throws IOException - { - if (!internal) - { - if (isSerializing) - throw new IOException("Reset called while serialization in progress"); - - realOutput.writeByte(TC_RESET); - } - - clearHandles(); - } - - - /** - * Informs this <code>ObjectOutputStream</code> to write data - * according to the specified protocol. There are currently two - * different protocols, specified by <code>PROTOCOL_VERSION_1</code> - * and <code>PROTOCOL_VERSION_2</code>. This implementation writes - * data using <code>PROTOCOL_VERSION_2</code> by default, as is done - * by the JDK 1.2. - * - * A non-portable method, <code>setDefaultProtocolVersion (int - * version)</code> is provided to change the default protocol - * version. - * - * For an explination of the differences beween the two protocols - * see XXX: the Java ObjectSerialization Specification. - * - * @exception IOException if <code>version</code> is not a valid - * protocol - * - * @see #setDefaultProtocolVersion(int) - */ - public void useProtocolVersion(int version) throws IOException - { - if (version != PROTOCOL_VERSION_1 && version != PROTOCOL_VERSION_2) - throw new IOException("Invalid protocol version requested."); - - protocolVersion = version; - } - - - /** - * <em>GNU $classpath specific</em> - * - * Changes the default stream protocol used by all - * <code>ObjectOutputStream</code>s. There are currently two - * different protocols, specified by <code>PROTOCOL_VERSION_1</code> - * and <code>PROTOCOL_VERSION_2</code>. The default default is - * <code>PROTOCOL_VERSION_1</code>. - * - * @exception IOException if <code>version</code> is not a valid - * protocol - * - * @see #useProtocolVersion(int) - */ - public static void setDefaultProtocolVersion(int version) - throws IOException - { - if (version != PROTOCOL_VERSION_1 && version != PROTOCOL_VERSION_2) - throw new IOException("Invalid protocol version requested."); - - defaultProtocolVersion = version; - } - - - /** - * An empty hook that allows subclasses to write extra information - * about classes to the stream. This method is called the first - * time each class is seen, and after all of the standard - * information about the class has been written. - * - * @exception IOException Exception from underlying - * <code>OutputStream</code>. - * - * @see ObjectInputStream#resolveClass(java.io.ObjectStreamClass) - */ - protected void annotateClass(Class cl) throws IOException - { - } - - protected void annotateProxyClass(Class cl) throws IOException - { - } - - /** - * Allows subclasses to replace objects that are written to the - * stream with other objects to be written in their place. This - * method is called the first time each object is encountered - * (modulo reseting of the stream). - * - * This method must be enabled before it will be called in the - * serialization process. - * - * @exception IOException Exception from underlying - * <code>OutputStream</code>. - * - * @see #enableReplaceObject(boolean) - */ - protected Object replaceObject(Object obj) throws IOException - { - return obj; - } - - - /** - * If <code>enable</code> is <code>true</code> and this object is - * trusted, then <code>replaceObject (Object)</code> will be called - * in subsequent calls to <code>writeObject (Object)</code>. - * Otherwise, <code>replaceObject (Object)</code> will not be called. - * - * @exception SecurityException This class is not trusted. - */ - protected boolean enableReplaceObject(boolean enable) - throws SecurityException - { - if (enable) - { - SecurityManager sm = System.getSecurityManager(); - if (sm != null) - sm.checkPermission(new SerializablePermission("enableSubstitution")); - } - - boolean old_val = replacementEnabled; - replacementEnabled = enable; - return old_val; - } - - - /** - * Writes stream magic and stream version information to the - * underlying stream. - * - * @exception IOException Exception from underlying - * <code>OutputStream</code>. - */ - protected void writeStreamHeader() throws IOException - { - realOutput.writeShort(STREAM_MAGIC); - realOutput.writeShort(STREAM_VERSION); - } - - /** - * Protected constructor that allows subclasses to override - * serialization. This constructor should be called by subclasses - * that wish to override <code>writeObject (Object)</code>. This - * method does a security check <i>NOTE: currently not - * implemented</i>, then sets a flag that informs - * <code>writeObject (Object)</code> to call the subclasses - * <code>writeObjectOverride (Object)</code> method. - * - * @see #writeObjectOverride(Object) - */ - protected ObjectOutputStream() throws IOException, SecurityException - { - SecurityManager sec_man = System.getSecurityManager (); - if (sec_man != null) - sec_man.checkPermission(SUBCLASS_IMPLEMENTATION_PERMISSION); - useSubclassMethod = true; - } - - - /** - * This method allows subclasses to override the default - * serialization mechanism provided by - * <code>ObjectOutputStream</code>. To make this method be used for - * writing objects, subclasses must invoke the 0-argument - * constructor on this class from there constructor. - * - * @see #ObjectOutputStream() - * - * @exception NotActiveException Subclass has arranged for this - * method to be called, but did not implement this method. - */ - protected void writeObjectOverride(Object obj) throws NotActiveException, - IOException - { - throw new NotActiveException - ("Subclass of ObjectOutputStream must implement writeObjectOverride"); - } - - - /** - * @see DataOutputStream#write(int) - */ - public void write (int data) throws IOException - { - if (writeDataAsBlocks) - { - if (blockDataCount == BUFFER_SIZE) - drain(); - - blockData[ blockDataCount++ ] = (byte)data; - } - else - realOutput.write(data); - } - - - /** - * @see DataOutputStream#write(byte[]) - */ - public void write(byte[] b) throws IOException - { - write(b, 0, b.length); - } - - - /** - * @see DataOutputStream#write(byte[],int,int) - */ - public void write(byte[] b, int off, int len) throws IOException - { - if (writeDataAsBlocks) - { - if (len < 0) - throw new IndexOutOfBoundsException(); - - if (blockDataCount + len < BUFFER_SIZE) - { - System.arraycopy(b, off, blockData, blockDataCount, len); - blockDataCount += len; - } - else - { - drain(); - writeBlockDataHeader(len); - realOutput.write(b, off, len); - } - } - else - realOutput.write(b, off, len); - } - - - /** - * @see DataOutputStream#flush() - */ - public void flush () throws IOException - { - drain(); - realOutput.flush(); - } - - - /** - * Causes the block-data buffer to be written to the underlying - * stream, but does not flush underlying stream. - * - * @exception IOException Exception from underlying - * <code>OutputStream</code>. - */ - protected void drain() throws IOException - { - if (blockDataCount == 0) - return; - - if (writeDataAsBlocks) - writeBlockDataHeader(blockDataCount); - realOutput.write(blockData, 0, blockDataCount); - blockDataCount = 0; - } - - - /** - * @see java.io.DataOutputStream#close () - */ - public void close() throws IOException - { - flush(); - realOutput.close(); - } - - - /** - * @see java.io.DataOutputStream#writeBoolean (boolean) - */ - public void writeBoolean(boolean data) throws IOException - { - blockDataOutput.writeBoolean(data); - } - - - /** - * @see java.io.DataOutputStream#writeByte (int) - */ - public void writeByte(int data) throws IOException - { - blockDataOutput.writeByte(data); - } - - - /** - * @see java.io.DataOutputStream#writeShort (int) - */ - public void writeShort (int data) throws IOException - { - blockDataOutput.writeShort(data); - } - - - /** - * @see java.io.DataOutputStream#writeChar (int) - */ - public void writeChar(int data) throws IOException - { - blockDataOutput.writeChar(data); - } - - - /** - * @see java.io.DataOutputStream#writeInt (int) - */ - public void writeInt(int data) throws IOException - { - blockDataOutput.writeInt(data); - } - - - /** - * @see java.io.DataOutputStream#writeLong (long) - */ - public void writeLong(long data) throws IOException - { - blockDataOutput.writeLong(data); - } - - - /** - * @see java.io.DataOutputStream#writeFloat (float) - */ - public void writeFloat(float data) throws IOException - { - blockDataOutput.writeFloat(data); - } - - - /** - * @see java.io.DataOutputStream#writeDouble (double) - */ - public void writeDouble(double data) throws IOException - { - blockDataOutput.writeDouble(data); - } - - - /** - * @see java.io.DataOutputStream#writeBytes (java.lang.String) - */ - public void writeBytes(String data) throws IOException - { - blockDataOutput.writeBytes(data); - } - - - /** - * @see java.io.DataOutputStream#writeChars (java.lang.String) - */ - public void writeChars(String data) throws IOException - { - dataOutput.writeChars(data); - } - - - /** - * @see java.io.DataOutputStream#writeUTF (java.lang.String) - */ - public void writeUTF(String data) throws IOException - { - dataOutput.writeUTF(data); - } - - - /** - * This class allows a class to specify exactly which fields should - * be written, and what values should be written for these fields. - * - * XXX: finish up comments - */ - public abstract static class PutField - { - public abstract void put (String name, boolean value); - public abstract void put (String name, byte value); - public abstract void put (String name, char value); - public abstract void put (String name, double value); - public abstract void put (String name, float value); - public abstract void put (String name, int value); - public abstract void put (String name, long value); - public abstract void put (String name, short value); - public abstract void put (String name, Object value); - - /** - * @deprecated - */ - public abstract void write (ObjectOutput out) throws IOException; - } - - public PutField putFields() throws IOException - { - if (currentPutField != null) - return currentPutField; - - currentPutField = new PutField() - { - private byte[] prim_field_data - = new byte[currentObjectStreamClass.primFieldSize]; - private Object[] objs - = new Object[currentObjectStreamClass.objectFieldCount]; - - private ObjectStreamField getField (String name) - { - ObjectStreamField field - = currentObjectStreamClass.getField(name); - - if (field == null) - throw new IllegalArgumentException("no such serializable field " + name); - - return field; - } - - public void put(String name, boolean value) - { - ObjectStreamField field = getField(name); - - checkType(field, 'Z'); - prim_field_data[field.getOffset ()] = (byte)(value ? 1 : 0); - } - - public void put(String name, byte value) - { - ObjectStreamField field = getField(name); - - checkType(field, 'B'); - prim_field_data[field.getOffset()] = value; - } - - public void put(String name, char value) - { - ObjectStreamField field = getField(name); - - checkType(field, 'C'); - int off = field.getOffset(); - prim_field_data[off++] = (byte)(value >>> 8); - prim_field_data[off] = (byte)value; - } - - public void put(String name, double value) - { - ObjectStreamField field = getField (name); - - checkType(field, 'D'); - int off = field.getOffset(); - long l_value = Double.doubleToLongBits (value); - prim_field_data[off++] = (byte)(l_value >>> 52); - prim_field_data[off++] = (byte)(l_value >>> 48); - prim_field_data[off++] = (byte)(l_value >>> 40); - prim_field_data[off++] = (byte)(l_value >>> 32); - prim_field_data[off++] = (byte)(l_value >>> 24); - prim_field_data[off++] = (byte)(l_value >>> 16); - prim_field_data[off++] = (byte)(l_value >>> 8); - prim_field_data[off] = (byte)l_value; - } - - public void put(String name, float value) - { - ObjectStreamField field = getField(name); - - checkType(field, 'F'); - int off = field.getOffset(); - int i_value = Float.floatToIntBits(value); - prim_field_data[off++] = (byte)(i_value >>> 24); - prim_field_data[off++] = (byte)(i_value >>> 16); - prim_field_data[off++] = (byte)(i_value >>> 8); - prim_field_data[off] = (byte)i_value; - } - - public void put(String name, int value) - { - ObjectStreamField field = getField(name); - checkType(field, 'I'); - int off = field.getOffset(); - prim_field_data[off++] = (byte)(value >>> 24); - prim_field_data[off++] = (byte)(value >>> 16); - prim_field_data[off++] = (byte)(value >>> 8); - prim_field_data[off] = (byte)value; - } - - public void put(String name, long value) - { - ObjectStreamField field = getField(name); - checkType(field, 'J'); - int off = field.getOffset(); - prim_field_data[off++] = (byte)(value >>> 52); - prim_field_data[off++] = (byte)(value >>> 48); - prim_field_data[off++] = (byte)(value >>> 40); - prim_field_data[off++] = (byte)(value >>> 32); - prim_field_data[off++] = (byte)(value >>> 24); - prim_field_data[off++] = (byte)(value >>> 16); - prim_field_data[off++] = (byte)(value >>> 8); - prim_field_data[off] = (byte)value; - } - - public void put(String name, short value) - { - ObjectStreamField field = getField(name); - checkType(field, 'S'); - int off = field.getOffset(); - prim_field_data[off++] = (byte)(value >>> 8); - prim_field_data[off] = (byte)value; - } - - public void put(String name, Object value) - { - ObjectStreamField field = getField(name); - - if (value != null && - ! field.getType().isAssignableFrom(value.getClass ())) - throw new IllegalArgumentException("Class " + value.getClass() + - " cannot be cast to " + field.getType()); - objs[field.getOffset()] = value; - } - - public void write(ObjectOutput out) throws IOException - { - // Apparently Block data is not used with PutField as per - // empirical evidence against JDK 1.2. Also see Mauve test - // java.io.ObjectInputOutput.Test.GetPutField. - boolean oldmode = setBlockDataMode(false); - out.write(prim_field_data); - for (int i = 0; i < objs.length; ++ i) - out.writeObject(objs[i]); - setBlockDataMode(oldmode); - } - - private void checkType(ObjectStreamField field, char type) - throws IllegalArgumentException - { - if (TypeSignature.getEncodingOfClass(field.getType()).charAt(0) - != type) - throw new IllegalArgumentException(); - } - }; - // end PutFieldImpl - - return currentPutField; - } - - - public void writeFields() throws IOException - { - if (currentPutField == null) - throw new NotActiveException("writeFields can only be called after putFields has been called"); - - markFieldsWritten(); - currentPutField.write(this); - } - - - // write out the block-data buffer, picking the correct header - // depending on the size of the buffer - private void writeBlockDataHeader(int size) throws IOException - { - if (size < 256) - { - realOutput.writeByte(TC_BLOCKDATA); - realOutput.write(size); - } - else - { - realOutput.writeByte(TC_BLOCKDATALONG); - realOutput.writeInt(size); - } - } - - - // lookup the handle for OBJ, return null if OBJ doesn't have a - // handle yet - private Integer findHandle(Object obj) - { - return (Integer)OIDLookupTable.get(new ObjectIdentityWrapper(obj)); - } - - - // assigns the next availible handle to OBJ - private int assignNewHandle(Object obj) - { - OIDLookupTable.put(new ObjectIdentityWrapper(obj), - new Integer(nextOID)); - return nextOID++; - } - - - // resets mapping from objects to handles - private void clearHandles() - { - nextOID = baseWireHandle; - OIDLookupTable.clear(); - } - - - // write out array size followed by each element of the array - private void writeArraySizeAndElements(Object array, Class clazz) - throws IOException - { - int length = Array.getLength(array); - - if (clazz.isPrimitive()) - { - if (clazz == Boolean.TYPE) - { - boolean[] cast_array = (boolean[])array; - realOutput.writeInt (length); - for (int i = 0; i < length; i++) - realOutput.writeBoolean(cast_array[i]); - return; - } - if (clazz == Byte.TYPE) - { - byte[] cast_array = (byte[])array; - realOutput.writeInt(length); - realOutput.write(cast_array, 0, length); - return; - } - if (clazz == Character.TYPE) - { - char[] cast_array = (char[])array; - realOutput.writeInt(length); - for (int i = 0; i < length; i++) - realOutput.writeChar(cast_array[i]); - return; - } - if (clazz == Double.TYPE) - { - double[] cast_array = (double[])array; - realOutput.writeInt(length); - for (int i = 0; i < length; i++) - realOutput.writeDouble(cast_array[i]); - return; - } - if (clazz == Float.TYPE) - { - float[] cast_array = (float[])array; - realOutput.writeInt(length); - for (int i = 0; i < length; i++) - realOutput.writeFloat(cast_array[i]); - return; - } - if (clazz == Integer.TYPE) - { - int[] cast_array = (int[])array; - realOutput.writeInt(length); - for (int i = 0; i < length; i++) - realOutput.writeInt(cast_array[i]); - return; - } - if (clazz == Long.TYPE) - { - long[] cast_array = (long[])array; - realOutput.writeInt (length); - for (int i = 0; i < length; i++) - realOutput.writeLong(cast_array[i]); - return; - } - if (clazz == Short.TYPE) - { - short[] cast_array = (short[])array; - realOutput.writeInt (length); - for (int i = 0; i < length; i++) - realOutput.writeShort(cast_array[i]); - return; - } - } - else - { - Object[] cast_array = (Object[])array; - realOutput.writeInt(length); - for (int i = 0; i < length; i++) - writeObject(cast_array[i]); - } - } - - - // writes out FIELDS of OBJECT for the specified ObjectStreamClass. - // FIELDS are already in canonical order. - private void writeFields(Object obj, ObjectStreamClass osc) - throws IOException - { - ObjectStreamField[] fields = osc.fields; - boolean oldmode = setBlockDataMode(false); - String field_name; - Class type; - - for (int i = 0; i < fields.length; i++) - { - field_name = fields[i].getName(); - type = fields[i].getType(); - - if (dump) - dumpElementln ("WRITE FIELD: " + field_name + " type=" + type); - - if (type == Boolean.TYPE) - realOutput.writeBoolean(getBooleanField(obj, osc.forClass(), field_name)); - else if (type == Byte.TYPE) - realOutput.writeByte(getByteField(obj, osc.forClass(), field_name)); - else if (type == Character.TYPE) - realOutput.writeChar(getCharField(obj, osc.forClass(), field_name)); - else if (type == Double.TYPE) - realOutput.writeDouble(getDoubleField(obj, osc.forClass(), field_name)); - else if (type == Float.TYPE) - realOutput.writeFloat(getFloatField(obj, osc.forClass(), field_name)); - else if (type == Integer.TYPE) - realOutput.writeInt(getIntField(obj, osc.forClass(), field_name)); - else if (type == Long.TYPE) - realOutput.writeLong(getLongField(obj, osc.forClass(), field_name)); - else if (type == Short.TYPE) - realOutput.writeShort(getShortField(obj, osc.forClass(), field_name)); - else - writeObject(getObjectField(obj, osc.forClass(), field_name, - fields[i].getTypeString ())); - } - setBlockDataMode(oldmode); - } - - - // Toggles writing primitive data to block-data buffer. - // Package-private to avoid a trampoline constructor. - boolean setBlockDataMode(boolean on) throws IOException - { - if (on == writeDataAsBlocks) - return on; - - drain(); - boolean oldmode = writeDataAsBlocks; - writeDataAsBlocks = on; - - if (on) - dataOutput = blockDataOutput; - else - dataOutput = realOutput; - - return oldmode; - } - - - private void callWriteMethod(Object obj, ObjectStreamClass osc) - throws IOException - { - currentPutField = null; - try - { - Object args[] = {this}; - osc.writeObjectMethod.invoke(obj, args); - } - catch (InvocationTargetException x) - { - /* Rethrow if possible. */ - Throwable exception = x.getTargetException(); - if (exception instanceof RuntimeException) - throw (RuntimeException) exception; - if (exception instanceof IOException) - throw (IOException) exception; - - IOException ioe - = new IOException("Exception thrown from writeObject() on " + - osc.forClass().getName() + ": " + - exception.getClass().getName()); - ioe.initCause(exception); - throw ioe; - } - catch (Exception x) - { - IOException ioe - = new IOException("Failure invoking writeObject() on " + - osc.forClass().getName() + ": " + - x.getClass().getName()); - ioe.initCause(x); - throw ioe; - } - } - - private boolean getBooleanField(Object obj, Class klass, String field_name) - throws IOException - { - try - { - Field f = getField(klass, field_name); - boolean b = f.getBoolean(obj); - return b; - } - catch (IllegalArgumentException _) - { - throw new InvalidClassException - ("invalid requested type for field " + field_name + " in class " + klass.getName()); - } - catch (IOException e) - { - throw e; - } - catch (Exception _) - { - throw new IOException("Unexpected exception " + _); - } - } - - private byte getByteField (Object obj, Class klass, String field_name) - throws IOException - { - try - { - Field f = getField (klass, field_name); - byte b = f.getByte (obj); - return b; - } - catch (IllegalArgumentException _) - { - throw new InvalidClassException - ("invalid requested type for field " + field_name + " in class " + klass.getName()); - } - catch (IOException e) - { - throw e; - } - catch (Exception _) - { - throw new IOException("Unexpected exception " + _); - } - } - - private char getCharField (Object obj, Class klass, String field_name) - throws IOException - { - try - { - Field f = getField (klass, field_name); - char b = f.getChar (obj); - return b; - } - catch (IllegalArgumentException _) - { - throw new InvalidClassException - ("invalid requested type for field " + field_name + " in class " + klass.getName()); - } - catch (IOException e) - { - throw e; - } - catch (Exception _) - { - throw new IOException("Unexpected exception " + _); - } - } - - private double getDoubleField (Object obj, Class klass, String field_name) - throws IOException - { - try - { - Field f = getField (klass, field_name); - double b = f.getDouble (obj); - return b; - } - catch (IllegalArgumentException _) - { - throw new InvalidClassException - ("invalid requested type for field " + field_name + " in class " + klass.getName()); - } - catch (IOException e) - { - throw e; - } - catch (Exception _) - { - throw new IOException("Unexpected exception " + _); - } - } - - private float getFloatField (Object obj, Class klass, String field_name) - throws IOException - { - try - { - Field f = getField (klass, field_name); - float b = f.getFloat (obj); - return b; - } - catch (IllegalArgumentException _) - { - throw new InvalidClassException - ("invalid requested type for field " + field_name + " in class " + klass.getName()); - } - catch (IOException e) - { - throw e; - } - catch (Exception _) - { - throw new IOException("Unexpected exception " + _); - } - } - - private int getIntField (Object obj, Class klass, String field_name) - throws IOException - { - try - { - Field f = getField (klass, field_name); - int b = f.getInt (obj); - return b; - } - catch (IllegalArgumentException _) - { - throw new InvalidClassException - ("invalid requested type for field " + field_name + " in class " + klass.getName()); - } - catch (IOException e) - { - throw e; - } - catch (Exception _) - { - throw new IOException("Unexpected exception " + _); - } - } - - private long getLongField (Object obj, Class klass, String field_name) - throws IOException - { - try - { - Field f = getField (klass, field_name); - long b = f.getLong (obj); - return b; - } - catch (IllegalArgumentException _) - { - throw new InvalidClassException - ("invalid requested type for field " + field_name + " in class " + klass.getName()); - } - catch (IOException e) - { - throw e; - } - catch (Exception _) - { - throw new IOException("Unexpected exception " + _); - } - } - - private short getShortField (Object obj, Class klass, String field_name) - throws IOException - { - try - { - Field f = getField (klass, field_name); - short b = f.getShort (obj); - return b; - } - catch (IllegalArgumentException _) - { - throw new InvalidClassException - ("invalid requested type for field " + field_name + " in class " + klass.getName()); - } - catch (IOException e) - { - throw e; - } - catch (Exception _) - { - throw new IOException("Unexpected exception " + _); - } - } - - private Object getObjectField (Object obj, Class klass, String field_name, - String type_code) throws IOException - { - try - { - Field f = getField (klass, field_name); - ObjectStreamField of = new ObjectStreamField(f.getName(), f.getType()); - - if (of.getTypeString() == null || - !of.getTypeString().equals(type_code)) - throw new InvalidClassException - ("invalid type code for " + field_name + " in class " + klass.getName()); - - Object o = f.get (obj); - // FIXME: We should check the type_code here - return o; - } - catch (IOException e) - { - throw e; - } - catch (Exception e) - { - throw new IOException (); - } - } - - private Field getField (Class klass, String name) - throws java.io.InvalidClassException - { - try - { - final Field f = klass.getDeclaredField(name); - setAccessible.setMember(f); - AccessController.doPrivileged(setAccessible); - return f; - } - catch (java.lang.NoSuchFieldException e) - { - throw new InvalidClassException - ("no field called " + name + " in class " + klass.getName()); - } - } - - private void dumpElementln (String msg) - { - for (int i = 0; i < depth; i++) - System.out.print (" "); - System.out.print (Thread.currentThread() + ": "); - System.out.println(msg); - } - - // this value comes from 1.2 spec, but is used in 1.1 as well - private static final int BUFFER_SIZE = 1024; - - private static int defaultProtocolVersion = PROTOCOL_VERSION_2; - - private DataOutputStream dataOutput; - private boolean writeDataAsBlocks; - private DataOutputStream realOutput; - private DataOutputStream blockDataOutput; - private byte[] blockData; - private int blockDataCount; - private Object currentObject; - // Package-private to avoid a trampoline. - ObjectStreamClass currentObjectStreamClass; - private PutField currentPutField; - private boolean fieldsAlreadyWritten; - private boolean replacementEnabled; - private boolean isSerializing; - private int nextOID; - private Hashtable OIDLookupTable; - private int protocolVersion; - private boolean useSubclassMethod; - private SetAccessibleAction setAccessible = new SetAccessibleAction(); - - // The nesting depth for debugging output - private int depth = 0; - - // Set if we're generating debugging dumps - private boolean dump = false; - - static - { - if (Configuration.INIT_LOAD_LIBRARY) - { - System.loadLibrary("javaio"); - } - } -} diff --git a/libjava/java/io/ObjectStreamConstants.java b/libjava/java/io/ObjectStreamConstants.java deleted file mode 100644 index f1a4af724e7..00000000000 --- a/libjava/java/io/ObjectStreamConstants.java +++ /dev/null @@ -1,89 +0,0 @@ -/* ObjectStreamConstants.java -- Interface containing constant values - used in reading and writing serialized objects - Copyright (C) 1998, 1999, 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.io; - -/** - * This interface contains constants that are used in object - * serialization. This interface is used by <code>ObjectOutputStream</code>, - * <code>ObjectInputStream</code>, and <code>ObjectStreamClass</code>. - * The values for these constants are specified by the Java library - * specification. - */ -public interface ObjectStreamConstants -{ - // FIXME: Javadoc comment these values. - int PROTOCOL_VERSION_1 = 1; - int PROTOCOL_VERSION_2 = 2; - - short STREAM_MAGIC = (short)0xaced; - short STREAM_VERSION = 5; - - byte TC_NULL = (byte)112; //0x70 - byte TC_REFERENCE = (byte)113; //0x71 - byte TC_CLASSDESC = (byte)114; //0x72 - byte TC_OBJECT = (byte)115; //0x73 - byte TC_STRING = (byte)116; //0x74 - byte TC_ARRAY = (byte)117; //0x75 - byte TC_CLASS = (byte)118; //0x76 - byte TC_BLOCKDATA = (byte)119; //0x77 - byte TC_ENDBLOCKDATA = (byte)120; //0x78 - byte TC_RESET = (byte)121; //0x79 - byte TC_BLOCKDATALONG = (byte)122; //0x7A - byte TC_EXCEPTION = (byte)123; //0x7B - byte TC_LONGSTRING = (byte)124; //0x7C - byte TC_PROXYCLASSDESC = (byte)125; //0x7D - - byte TC_BASE = TC_NULL; - byte TC_MAX = TC_PROXYCLASSDESC; - - int baseWireHandle = 0x7e0000; - - byte SC_WRITE_METHOD = 0x01; - byte SC_SERIALIZABLE = 0x02; - byte SC_EXTERNALIZABLE = 0x04; - byte SC_BLOCK_DATA = 0x08; - - SerializablePermission SUBSTITUTION_PERMISSION - = new SerializablePermission("enableSubstitution"); - - SerializablePermission SUBCLASS_IMPLEMENTATION_PERMISSION - = new SerializablePermission("enableSubclassImplementation"); -} - diff --git a/libjava/java/io/ObjectStreamException.java b/libjava/java/io/ObjectStreamException.java deleted file mode 100644 index 61d4dd09e52..00000000000 --- a/libjava/java/io/ObjectStreamException.java +++ /dev/null @@ -1,74 +0,0 @@ -/* ObjectStreamException.java -- Superclass of all serialization exceptions - Copyright (C) 1998, 2000, 2001, 2002, 2003, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.io; - -/** - * This exception is thrown when a problem occurs during serialization. - * There are more specific subclasses that give more fine grained - * indications of the precise failure. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Warren Levy (warrenl@cygnus.com) - * @since 1.1 - * @status updated to 1.4 - */ -public abstract class ObjectStreamException extends IOException -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = 7260898174833392607L; - - /** - * Create an exception without a descriptive error message. - */ - protected ObjectStreamException() - { - } - - /** - * Create an exception with a descriptive error message. - * - * @param message the descriptive error message - */ - protected ObjectStreamException(String message) - { - super(message); - } -} // class ObjectStreamException diff --git a/libjava/java/io/ObjectStreamField.java b/libjava/java/io/ObjectStreamField.java deleted file mode 100644 index 611457b3cfb..00000000000 --- a/libjava/java/io/ObjectStreamField.java +++ /dev/null @@ -1,412 +0,0 @@ -/* ObjectStreamField.java -- Class used to store name and class of fields - Copyright (C) 1998, 1999, 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.io; - -import gnu.java.lang.reflect.TypeSignature; - -import java.lang.reflect.Field; -import java.security.AccessController; -import java.security.PrivilegedAction; - -/** - * This class intends to describe the field of a class for the serialization - * subsystem. Serializable fields in a serializable class can be explicitly - * exported using an array of ObjectStreamFields. - */ -public class ObjectStreamField implements Comparable -{ - private String name; - private Class type; - private String typename; - private int offset = -1; // XXX make sure this is correct - private boolean unshared; - private boolean persistent = false; - private boolean toset = true; - private Field field; - - ObjectStreamField (Field field) - { - this (field.getName(), field.getType()); - this.field = field; - } - - /** - * This constructor creates an ObjectStreamField instance - * which represents a field named <code>name</code> and is - * of the type <code>type</code>. - * - * @param name Name of the field to export. - * @param type Type of the field in the concerned class. - */ - public ObjectStreamField (String name, Class type) - { - this (name, type, false); - } - - /** - * This constructor creates an ObjectStreamField instance - * which represents a field named <code>name</code> and is - * of the type <code>type</code>. - * - * @param name Name of the field to export. - * @param type Type of the field in the concerned class. - * @param unshared true if field will be unshared, false otherwise. - */ - public ObjectStreamField (String name, Class type, boolean unshared) - { - if (name == null) - throw new NullPointerException(); - - this.name = name; - this.type = type; - this.typename = TypeSignature.getEncodingOfClass(type); - this.unshared = unshared; - } - - /** - * There are many cases you can not get java.lang.Class from typename - * if your context class loader cannot load it, then use typename to - * construct the field. - * - * @param name Name of the field to export. - * @param typename The coded name of the type for this field. - */ - ObjectStreamField (String name, String typename) - { - this.name = name; - this.typename = typename; - try - { - type = TypeSignature.getClassForEncoding(typename); - } - catch(ClassNotFoundException e) - { - } - } - - /** - * There are many cases you can not get java.lang.Class from typename - * if your context class loader cann not load it, then use typename to - * construct the field. - * - * @param name Name of the field to export. - * @param typename The coded name of the type for this field. - * @param loader The class loader to use to resolve class names. - */ - ObjectStreamField (String name, String typename, ClassLoader loader) - { - this.name = name; - this.typename = typename; - try - { - type = TypeSignature.getClassForEncoding(typename, true, loader); - } - catch(ClassNotFoundException e) - { - } - } - - /** - * This method returns the name of the field represented by the - * ObjectStreamField instance. - * - * @return A string containing the name of the field. - */ - public String getName () - { - return name; - } - - /** - * This method returns the class representing the type of the - * field which is represented by this instance of ObjectStreamField. - * - * @return A class representing the type of the field. - */ - public Class getType () - { - return type; - } - - /** - * This method returns the char encoded type of the field which - * is represented by this instance of ObjectStreamField. - * - * @return A char representing the type of the field. - */ - public char getTypeCode () - { - return typename.charAt (0); - } - - /** - * This method returns a more explicit type name than - * {@link #getTypeCode()} in the case the type is a real - * class (and not a primitive). - * - * @return The name of the type (class name) if it is not a - * primitive, in the other case null is returned. - */ - public String getTypeString () - { - // use intern() - if (isPrimitive()) - return null; - return typename.intern(); - } - - /** - * This method returns the current offset of the field in - * the serialization stream relatively to the other fields. - * The offset is expressed in bytes. - * - * @return The offset of the field in bytes. - * @see #setOffset(int) - */ - public int getOffset () - { - return offset; - } - - /** - * This method sets the current offset of the field. - * - * @param off The offset of the field in bytes. - * @see getOffset() - */ - protected void setOffset (int off) - { - offset = off; - } - - /** - * This method returns whether the field represented by this object is - * unshared or not. - * - * @return Tells if this field is unshared or not. - */ - public boolean isUnshared () - { - return unshared; - } - - /** - * This method returns true if the type of the field - * represented by this instance is a primitive. - * - * @return true if the type is a primitive, false - * in the other case. - */ - public boolean isPrimitive () - { - return typename.length() == 1; - } - - /** - * Compares this object to the given object. - * - * @param obj the object to compare to. - * - * @return -1, 0 or 1. - */ - public int compareTo (Object obj) - { - ObjectStreamField f = (ObjectStreamField) obj; - boolean this_is_primitive = isPrimitive (); - boolean f_is_primitive = f.isPrimitive (); - - if (this_is_primitive && !f_is_primitive) - return -1; - - if (!this_is_primitive && f_is_primitive) - return 1; - - return getName ().compareTo (f.getName ()); - } - - /** - * This method is specific to classpath's implementation and so has the default - * access. It changes the state of this field to "persistent". It means that - * the field should not be changed when the stream is read (if it is not - * explicitly specified using serialPersistentFields). - * - * @param persistent True if the field is persistent, false in the - * other cases. - * @see #isPersistent() - */ - void setPersistent(boolean persistent) - { - this.persistent = persistent; - } - - /** - * This method returns true if the field is marked as persistent. - * - * @return True if persistent, false in the other cases. - * @see #setPersistent(boolean) - */ - boolean isPersistent() - { - return persistent; - } - - /** - * This method is specific to classpath's implementation and so - * has the default access. It changes the state of this field as - * to be set by ObjectInputStream. - * - * @param toset True if this field should be set, false in the other - * cases. - * @see #isToSet() - */ - void setToSet(boolean toset) - { - this.toset = toset; - } - - /** - * This method returns true if the field is marked as to be - * set. - * - * @return True if it is to be set, false in the other cases. - * @see #setToSet(boolean) - */ - boolean isToSet() - { - return toset; - } - - /** - * This method searches for its field reference in the specified class - * object. It requests privileges. If an error occurs the internal field - * reference is not modified. - * - * @throws NoSuchFieldException if the field name does not exist in this class. - * @throws SecurityException if there was an error requesting the privileges. - */ - void lookupField(Class clazz) throws NoSuchFieldException, SecurityException - { - final Field f = clazz.getDeclaredField(name); - - AccessController.doPrivileged(new PrivilegedAction() - { - public Object run() - { - f.setAccessible(true); - return null; - } - }); - - this.field = f; - } - - /** - * This method check whether the field described by this - * instance of ObjectStreamField is compatible with the - * actual implementation of this field. - * - * @throws NullPointerException if this field does not exist - * in the real class. - * @throws InvalidClassException if the types are incompatible. - */ - void checkFieldType() throws InvalidClassException - { - Class ftype = field.getType(); - - if (!ftype.isAssignableFrom(type)) - throw new InvalidClassException - ("invalid field type for " + name + - " in class " + field.getDeclaringClass()); - } - - /** - * Returns a string representing this object. - * - * @return the string. - */ - public String toString () - { - return "ObjectStreamField< " + type + " " + name + " >"; - } - - final void setBooleanField(Object obj, boolean val) - { - VMObjectStreamClass.setBooleanNative(field, obj, val); - } - - final void setByteField(Object obj, byte val) - { - VMObjectStreamClass.setByteNative(field, obj, val); - } - - final void setCharField(Object obj, char val) - { - VMObjectStreamClass.setCharNative(field, obj, val); - } - - final void setShortField(Object obj, short val) - { - VMObjectStreamClass.setShortNative(field, obj, val); - } - - final void setIntField(Object obj, int val) - { - VMObjectStreamClass.setIntNative(field, obj, val); - } - - final void setLongField(Object obj, long val) - { - VMObjectStreamClass.setLongNative(field, obj, val); - } - - final void setFloatField(Object obj, float val) - { - VMObjectStreamClass.setFloatNative(field, obj, val); - } - - final void setDoubleField(Object obj, double val) - { - VMObjectStreamClass.setDoubleNative(field, obj, val); - } - - final void setObjectField(Object obj, Object val) - { - VMObjectStreamClass.setObjectNative(field, obj, val); - } -} diff --git a/libjava/java/io/OptionalDataException.java b/libjava/java/io/OptionalDataException.java deleted file mode 100644 index 8d8b1bda0e3..00000000000 --- a/libjava/java/io/OptionalDataException.java +++ /dev/null @@ -1,91 +0,0 @@ -/* OptionalDataException.java -- indicates unexpected data in serialized stream - Copyright (C) 1998, 2000, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.io; - -/** - * This exception is thrown when unexpected data appears in the input - * stream from which a serialized object is being read. There are two - * cases:<br><ul> - * <li>The next stream element is primitive data. <code>eof</code> will - * be false, and <code>count</code> is the number of bytes of primitive - * data available.</li> - * <li>The data consumable by readObject or readExternal has been exhausted. - * <code>eof</code> is true, and <code>count</code> is 0.</li> - * </ul> - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Warren Levy (warrenl@cygnus.com) - * @since 1.1 - * @status updated to 1.4 - */ -public class OptionalDataException extends ObjectStreamException -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = -8011121865681257820L; - - /** - * Whether or not the end of the stream has been reached. - * - * @serial the end of the buffer was reached - */ - public boolean eof; - - /** - * The number of valid bytes that can be read. - * - * @serial the bytes of the buffer remaining - */ - public int length; - - /** - * Create a new OptionalDataException with an eof parameter indicating - * whether or not the end of stream is reached and the number of valid - * bytes that may be read. - * - * @param eof 'true' if end of stream reached, 'false' otherwise - * @param count The number of valid bytes to be read - */ - OptionalDataException(boolean eof, int count) - { - this.eof = eof; - this.length = count; - } -} // class OptionalDataException diff --git a/libjava/java/io/OutputStream.java b/libjava/java/io/OutputStream.java deleted file mode 100644 index 8608daaa161..00000000000 --- a/libjava/java/io/OutputStream.java +++ /dev/null @@ -1,140 +0,0 @@ -/* OutputStream.java -- Base class for byte output streams - Copyright (C) 1998, 1999, 2001, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.io; - -/** - * This abstract class forms the base of the hierarchy of classes that - * write output as a stream of bytes. It provides a common set of methods - * for writing bytes to stream. Subclasses implement and/or extend these - * methods to write bytes in a particular manner or to a particular - * destination such as a file on disk or network connection. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Tom Tromey (tromey@cygnus.com) - */ -public abstract class OutputStream -{ - /** - * This is the default no-argument constructor for this class. This method - * does nothing in this class. - */ - public OutputStream () - { - } - - /** - * This method writes a single byte to the output stream. The byte written - * is the low eight bits of the <code>int</code> passed and a argument. - * <p> - * Subclasses must provide an implementation of this abstract method - * - * @param b The byte to be written to the output stream, passed as - * the low eight bits of an <code>int</code> - * - * @exception IOException If an error occurs - */ - public abstract void write (int b) throws IOException; - - /** - * This method all the writes bytes from the passed array to the - * output stream. This method is equivalent to <code>write(b, 0, - * buf.length)</code> which is exactly how it is implemented in this - * class. - * - * @param b The array of bytes to write - * - * @exception IOException If an error occurs - */ - public void write (byte[] b) throws IOException, NullPointerException - { - write (b, 0, b.length); - } - - /** - * This method writes <code>len</code> bytes from the specified array - * <code>b</code> starting at index <code>off</code> into the array. - * <p> - * This method in this class calls the single byte <code>write()</code> - * method in a loop until all bytes have been written. Subclasses should - * override this method if possible in order to provide a more efficent - * implementation. - * - * @param b The array of bytes to write from - * @param off The index into the array to start writing from - * @param len The number of bytes to write - * - * @exception IOException If an error occurs - */ - public void write (byte[] b, int off, int len) - throws IOException, NullPointerException, IndexOutOfBoundsException - { - if (off < 0 || len < 0 || off + len > b.length) - throw new ArrayIndexOutOfBoundsException (); - for (int i = 0; i < len; ++i) - write (b[off + i]); - } - - /** - * This method forces any data that may have been buffered to be written - * to the underlying output device. Please note that the host environment - * might perform its own buffering unbeknowst to Java. In that case, a - * write made (for example, to a disk drive) might be cached in OS - * buffers instead of actually being written to disk. - * <p> - * This method in this class does nothing. - * - * @exception IOException If an error occurs - */ - public void flush () throws IOException - { - } - - /** - * This method closes the stream. Any internal or native resources - * associated with this stream are freed. Any subsequent attempt to - * access the stream might throw an exception. - * <p> - * This method in this class does nothing. - * - * @exception IOException If an error occurs - */ - public void close () throws IOException - { - } -} diff --git a/libjava/java/io/PipedInputStream.java b/libjava/java/io/PipedInputStream.java deleted file mode 100644 index beb310b4f0c..00000000000 --- a/libjava/java/io/PipedInputStream.java +++ /dev/null @@ -1,374 +0,0 @@ -/* PipedInputStream.java -- Read portion of piped streams. - Copyright (C) 1998, 1999, 2000, 2001, 2003, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.io; - -// NOTE: This implementation is very similar to that of PipedReader. If you -// fix a bug in here, chances are you should make a similar change to the -// PipedReader code. - -/** - * An input stream that reads its bytes from an output stream - * to which it is connected. - * <p> - * Data is read and written to an internal buffer. It is highly recommended - * that the <code>PipedInputStream</code> and connected - * <code>PipedOutputStream</code> - * be part of different threads. If they are not, the read and write - * operations could deadlock their thread. - * - * @specnote The JDK implementation appears to have some undocumented - * functionality where it keeps track of what thread is writing - * to pipe and throws an IOException if that thread susequently - * dies. This behaviour seems dubious and unreliable - we don't - * implement it. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public class PipedInputStream extends InputStream -{ - /** PipedOutputStream to which this is connected. Null only if this - * InputStream hasn't been connected yet. */ - PipedOutputStream source; - - /** Set to true if close() has been called on this InputStream. */ - boolean closed; - - - /** - * The size of the internal buffer used for input/output. - */ - /* The "Constant Field Values" Javadoc of the Sun J2SE 1.4 - * specifies 1024. - */ - protected static final int PIPE_SIZE = 1024; - - - /** - * This is the internal circular buffer used for storing bytes written - * to the pipe and from which bytes are read by this stream - */ - protected byte[] buffer = new byte[PIPE_SIZE]; - - /** - * The index into buffer where the next byte from the connected - * <code>PipedOutputStream</code> will be written. If this variable is - * equal to <code>out</code>, then the buffer is full. If set to < 0, - * the buffer is empty. - */ - protected int in = -1; - - /** - * This index into the buffer where bytes will be read from. - */ - protected int out = 0; - - /** Buffer used to implement single-argument read/receive */ - private byte[] read_buf = new byte[1]; - - /** - * Creates a new <code>PipedInputStream</code> that is not connected to a - * <code>PipedOutputStream</code>. It must be connected before bytes can - * be read from this stream. - */ - public PipedInputStream() - { - } - - /** - * This constructor creates a new <code>PipedInputStream</code> and connects - * it to the passed in <code>PipedOutputStream</code>. The stream is then - * ready for reading. - * - * @param source The <code>PipedOutputStream</code> to connect this - * stream to - * - * @exception IOException If <code>source</code> is already connected. - */ - public PipedInputStream(PipedOutputStream source) throws IOException - { - connect(source); - } - - /** - * This method connects this stream to the passed in - * <code>PipedOutputStream</code>. - * This stream is then ready for reading. If this stream is already - * connected or has been previously closed, then an exception is thrown - * - * @param src The <code>PipedOutputStream</code> to connect this stream to - * - * @exception IOException If this PipedInputStream or <code>source</code> - * has been connected already. - */ - public void connect(PipedOutputStream source) throws IOException - { - // The JDK (1.3) does not appear to check for a previously closed - // connection here. - - if (this.source != null || source.sink != null) - throw new IOException ("Already connected"); - - source.sink = this; - this.source = source; - } - - /** - * This method receives a byte of input from the source PipedOutputStream. - * If the internal circular buffer is full, this method blocks. - * - * @param val The byte to write to this stream - * - * @exception IOException if error occurs - * @specnote Weird. This method must be some sort of accident. - */ - protected synchronized void receive(int val) throws IOException - { - read_buf[0] = (byte) (val & 0xff); - receive (read_buf, 0, 1); - } - - /** - * This method is used by the connected <code>PipedOutputStream</code> to - * write bytes into the buffer. - * - * @param buf The array containing bytes to write to this stream - * @param offset The offset into the array to start writing from - * @param len The number of bytes to write. - * - * @exception IOException If an error occurs - * @specnote This code should be in PipedOutputStream.write, but we - * put it here in order to support that bizarre recieve(int) - * method. - */ - synchronized void receive(byte[] buf, int offset, int len) - throws IOException - { - if (closed) - throw new IOException ("Pipe closed"); - - int bufpos = offset; - int copylen; - - while (len > 0) - { - try - { - while (in == out) - { - // The pipe is full. Wake up any readers and wait for them. - notifyAll(); - wait(); - // The pipe could have been closed while we were waiting. - if (closed) - throw new IOException ("Pipe closed"); - } - } - catch (InterruptedException ix) - { - throw new InterruptedIOException (); - } - - if (in < 0) // The pipe is empty. - in = 0; - - // Figure out how many bytes from buf can be copied without - // overrunning out or going past the length of the buffer. - if (in < out) - copylen = Math.min (len, out - in); - else - copylen = Math.min (len, buffer.length - in); - - // Copy bytes until the pipe is filled, wrapping if necessary. - System.arraycopy(buf, bufpos, buffer, in, copylen); - len -= copylen; - bufpos += copylen; - in += copylen; - if (in == buffer.length) - in = 0; - } - // Notify readers that new data is in the pipe. - notifyAll(); - } - - /** - * This method reads one byte from the stream. - * -1 is returned to indicated that no bytes can be read - * because the end of the stream was reached. If the stream is already - * closed, a -1 will again be returned to indicate the end of the stream. - * - * <p>This method will block if no byte is available to be read.</p> - * - * @return the value of the read byte value, or -1 of the end of the stream - * was reached - * - * @throws IOException if an error occured - */ - public int read() throws IOException - { - // Method operates by calling the multibyte overloaded read method - // Note that read_buf is an internal instance variable. I allocate it - // there to avoid constant reallocation overhead for applications that - // call this method in a loop at the cost of some unneeded overhead - // if this method is never called. - - int r = read(read_buf, 0, 1); - return r != -1 ? (read_buf[0] & 0xff) : -1; - } - - /** - * This method reads bytes from the stream into a caller supplied buffer. - * It starts storing bytes at position <code>offset</code> into the - * buffer and - * reads a maximum of <code>len</code> bytes. Note that this method - * can actually - * read fewer than <code>len</code> bytes. The actual number of bytes - * read is - * returned. A -1 is returned to indicated that no bytes can be read - * because the end of the stream was reached - ie close() was called on the - * connected PipedOutputStream. - * <p> - * This method will block if no bytes are available to be read. - * - * @param buf The buffer into which bytes will be stored - * @param offset The index into the buffer at which to start writing. - * @param len The maximum number of bytes to read. - * - * @exception IOException If <code>close()</code> was called on this Piped - * InputStream. - */ - public synchronized int read(byte[] buf, int offset, int len) - throws IOException - { - if (source == null) - throw new IOException ("Not connected"); - if (closed) - throw new IOException ("Pipe closed"); - - // If the buffer is empty, wait until there is something in the pipe - // to read. - try - { - while (in < 0) - { - if (source.closed) - return -1; - wait(); - } - } - catch (InterruptedException ix) - { - throw new InterruptedIOException(); - } - - int total = 0; - int copylen; - - while (true) - { - // Figure out how many bytes from the pipe can be copied without - // overrunning in or going past the length of buf. - if (out < in) - copylen = Math.min (len, in - out); - else - copylen = Math.min (len, buffer.length - out); - - System.arraycopy (buffer, out, buf, offset, copylen); - offset += copylen; - len -= copylen; - out += copylen; - total += copylen; - - if (out == buffer.length) - out = 0; - - if (out == in) - { - // Pipe is now empty. - in = -1; - out = 0; - } - - // If output buffer is filled or the pipe is empty, we're done. - if (len == 0 || in == -1) - { - // Notify any waiting outputstream that there is now space - // to write. - notifyAll(); - return total; - } - } - } - - /** - * This method returns the number of bytes that can be read from this stream - * before blocking could occur. This is the number of bytes that are - * currently unread in the internal circular buffer. Note that once this - * many additional bytes are read, the stream may block on a subsequent - * read, but it not guaranteed to block. - * - * @return The number of bytes that can be read before blocking might occur - * - * @exception IOException If an error occurs - */ - public synchronized int available() throws IOException - { - // The JDK 1.3 implementation does not appear to check for the closed or - // unconnected stream conditions here. - - if (in < 0) - return 0; - else if (out < in) - return in - out; - else - return (buffer.length - out) + in; - } - - /** - * This methods closes the stream so that no more data can be read - * from it. - * - * @exception IOException If an error occurs - */ - public synchronized void close() throws IOException - { - closed = true; - // Wake any thread which may be in receive() waiting to write data. - notifyAll(); - } -} - diff --git a/libjava/java/io/PipedOutputStream.java b/libjava/java/io/PipedOutputStream.java deleted file mode 100644 index 81881050d1b..00000000000 --- a/libjava/java/io/PipedOutputStream.java +++ /dev/null @@ -1,181 +0,0 @@ -/* PipedOutputStream.java -- Write portion of piped streams. - Copyright (C) 1998, 2000, 2001, 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.io; - -// NOTE: This implementation is very similar to that of PipedWriter. If you -// fix a bug in here, chances are you should make a similar change to the -// PipedWriter code. - -/** - * This class writes its bytes to a <code>PipedInputStream</code> to - * which it is connected. - * <p> - * It is highly recommended that a <code>PipedOutputStream</code> and its - * connected <code>PipedInputStream</code> be in different threads. If - * they are in the same thread, read and write operations could deadlock - * the thread. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public class PipedOutputStream extends OutputStream -{ - /** Target PipedInputStream to which this is connected. Null only if this - * OutputStream hasn't been connected yet. */ - PipedInputStream sink; - - /** Set to true if close() has been called on this OutputStream. */ - boolean closed; - - /** - * Create an unconnected PipedOutputStream. It must be connected - * to a <code>PipedInputStream</code> using the <code>connect</code> - * method prior to writing any data or an exception will be thrown. - */ - public PipedOutputStream() - { - } - - /** - * Create a new <code>PipedOutputStream</code> instance - * to write to the specified <code>PipedInputStream</code>. This stream - * is then ready for writing. - * - * @param sink The <code>PipedInputStream</code> to connect this stream to. - * - * @exception IOException If <code>sink</code> has already been connected - * to a different PipedOutputStream. - */ - public PipedOutputStream(PipedInputStream sink) throws IOException - { - sink.connect(this); - } - - /** - * Connects this object to the specified <code>PipedInputStream</code> - * object. This stream will then be ready for writing. - * - * @param sink The <code>PipedInputStream</code> to connect this stream to - * - * @exception IOException If the stream has not been connected or has - * been closed. - */ - public void connect(PipedInputStream sink) throws IOException - { - if (this.sink != null || sink.source != null) - throw new IOException ("Already connected"); - sink.connect(this); - } - - /** - * Write a single byte of date to the stream. Note that this method will - * block if the <code>PipedInputStream</code> to which this object is - * connected has a full buffer. - * - * @param b The byte of data to be written, passed as an <code>int</code>. - * - * @exception IOException If the stream has not been connected or has - * been closed. - */ - public void write(int b) throws IOException - { - if (sink == null) - throw new IOException ("Not connected"); - if (closed) - throw new IOException ("Pipe closed"); - - sink.receive (b); - } - - /** - * This method writes <code>len</code> bytes of data from the byte array - * <code>buf</code> starting at index <code>offset</code> in the array - * to the stream. Note that this method will block if the - * <code>PipedInputStream</code> to which this object is connected has - * a buffer that cannot hold all of the bytes to be written. - * - * @param buffer The array containing bytes to write to the stream. - * @param offset The index into the array to start writing bytes from. - * @param len The number of bytes to write. - * - * @exception IOException If the stream has not been connected or has - * been closed. - */ - public void write(byte[] buffer, int offset, int len) throws IOException - { - if (sink == null) - throw new IOException ("Not connected"); - if (closed) - throw new IOException ("Pipe closed"); - - sink.receive(buffer, offset, len); - } - - /** - * This method does nothing. - * - * @exception IOException If the stream is closed. - * @specnote You'd think that this method would block until the sink - * had read all available data. Thats not the case - this method - * appears to be a no-op? - */ - public void flush() throws IOException - { - } - - /** - * This method closes this stream so that no more data can be written - * to it. Any further attempts to write to this stream may throw an - * exception - * - * @exception IOException If an error occurs - */ - public void close() throws IOException - { - // A close call on an unconnected PipedOutputStream has no effect. - if (sink != null) - { - closed = true; - // Notify any waiting readers that the stream is now closed. - synchronized (sink) - { - sink.notifyAll(); - } - } - } -} diff --git a/libjava/java/io/PipedReader.java b/libjava/java/io/PipedReader.java deleted file mode 100644 index 90fc10f672d..00000000000 --- a/libjava/java/io/PipedReader.java +++ /dev/null @@ -1,361 +0,0 @@ -/* PipedReader.java -- Read portion of piped character streams. - Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.io; - -// NOTE: This implementation is very similar to that of PipedInputStream. -// If you fix a bug in here, chances are you should make a similar change to -// the PipedInputStream code. - -/** - * An input stream that reads characters from a piped writer to which it is - * connected. - * <p> - * Data is read and written to an internal buffer. It is highly recommended - * that the <code>PipedReader</code> and connected <code>PipedWriter</code> - * be part of different threads. If they are not, there is a possibility - * that the read and write operations could deadlock their thread. - * - * @specnote The JDK implementation appears to have some undocumented - * functionality where it keeps track of what thread is writing - * to pipe and throws an IOException if that thread susequently - * dies. This behaviour seems dubious and unreliable - we don't - * implement it. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public class PipedReader extends Reader -{ - /** PipedWriter to which this is connected. Null only if this - * Reader hasn't been connected yet. */ - PipedWriter source; - - /** Set to true if close() has been called on this Reader. */ - boolean closed; - - /** - * The size of the internal buffer used for input/output. - */ - static final int PIPE_SIZE = 2048; - - /** - * This is the internal circular buffer used for storing chars written - * to the pipe and from which chars are read by this stream - */ - char[] buffer = new char[PIPE_SIZE]; - - /** - * The index into buffer where the next char from the connected - * <code>PipedWriter</code> will be written. If this variable is - * equal to <code>out</code>, then the buffer is full. If set to < 0, - * the buffer is empty. - */ - int in = -1; - - /** - * This index into the buffer where chars will be read from. - */ - int out = 0; - - /** Buffer used to implement single-argument read/receive */ - char[] read_buf = new char[1]; - - /** - * Creates a new <code>PipedReader</code> that is not connected to a - * <code>PipedWriter</code>. It must be connected before chars can - * be read from this stream. - */ - public PipedReader() - { - } - - /** - * This constructor creates a new <code>PipedReader</code> and connects - * it to the passed in <code>PipedWriter</code>. The stream is then - * ready for reading. - * - * @param source The <code>PipedWriter</code> to connect this stream to - * - * @exception IOException If <code>source</code> is already connected. - */ - public PipedReader(PipedWriter source) throws IOException - { - connect(source); - } - - /** - * This method connects this stream to the passed in - * <code>PipedWriter</code>. - * This stream is then ready for reading. If this stream is already - * connected or has been previously closed, then an exception is thrown - * - * @param source The <code>PipedWriter</code> to connect this stream to - * - * @exception IOException If this PipedReader or <code>source</code> - * has been connected already. - */ - public void connect(PipedWriter source) throws IOException - { - // The JDK (1.3) does not appear to check for a previously closed - // connection here. - - if (this.source != null || source.sink != null) - throw new IOException ("Already connected"); - - source.sink = this; - this.source = source; - } - - /** - * This method is used by the connected <code>PipedWriter</code> to - * write chars into the buffer. - * - * @param buf The array containing chars to write to this stream - * @param offset The offset into the array to start writing from - * @param len The number of chars to write. - * - * @exception IOException If an error occurs - * @specnote This code should be in PipedWriter.write, but we - * put it here in order to support that bizarre recieve(int) - * method. - */ - void receive(char[] buf, int offset, int len) - throws IOException - { - synchronized (lock) - { - if (closed) - throw new IOException ("Pipe closed"); - - int bufpos = offset; - int copylen; - - while (len > 0) - { - try - { - while (in == out) - { - // The pipe is full. Wake up any readers and wait for them. - lock.notifyAll(); - lock.wait(); - // The pipe could have been closed while we were waiting. - if (closed) - throw new IOException ("Pipe closed"); - } - } - catch (InterruptedException ix) - { - throw new InterruptedIOException (); - } - - if (in < 0) // The pipe is empty. - in = 0; - - // Figure out how many chars from buf can be copied without - // overrunning out or going past the length of the buffer. - if (in < out) - copylen = Math.min (len, out - in); - else - copylen = Math.min (len, buffer.length - in); - - // Copy chars until the pipe is filled, wrapping if necessary. - System.arraycopy(buf, bufpos, buffer, in, copylen); - len -= copylen; - bufpos += copylen; - in += copylen; - if (in == buffer.length) - in = 0; - } - // Notify readers that new data is in the pipe. - lock.notifyAll(); - } - } - - /** - * This method reads chars from the stream into a caller supplied buffer. - * It starts storing chars at position <code>offset</code> into the - * buffer and - * reads a maximum of <code>len</code> chars. Note that this method - * can actually - * read fewer than <code>len</code> chars. The actual number of chars - * read is - * returned. A -1 is returned to indicated that no chars can be read - * because the end of the stream was reached. If the stream is already - * closed, a -1 will again be returned to indicate the end of the stream. - * <p> - * This method will block if no char is available to be read. - */ - public int read() throws IOException - { - // Method operates by calling the multichar overloaded read method - // Note that read_buf is an internal instance variable. I allocate it - // there to avoid constant reallocation overhead for applications that - // call this method in a loop at the cost of some unneeded overhead - // if this method is never called. - - int r = read(read_buf, 0, 1); - return r != -1 ? read_buf[0] : -1; - } - - /** - * This method reads characters from the stream into a caller supplied - * buffer. It starts storing chars at position <code>offset</code> into - * the buffer and reads a maximum of <code>len</code> chars. Note that - * this method can actually read fewer than <code>len</code> chars. - * The actual number of chars read is - * returned. A -1 is returned to indicated that no chars can be read - * because the end of the stream was reached - ie close() was called on the - * connected PipedWriter. - * <p> - * This method will block if no chars are available to be read. - * - * @param buf The buffer into which chars will be stored - * @param offset The index into the buffer at which to start writing. - * @param len The maximum number of chars to read. - * - * @exception IOException If <code>close()</code> was called on this Piped - * Reader. - */ - public int read(char[] buf, int offset, int len) - throws IOException - { - synchronized (lock) - { - if (source == null) - throw new IOException ("Not connected"); - if (closed) - throw new IOException ("Pipe closed"); - - // If the buffer is empty, wait until there is something in the pipe - // to read. - try - { - while (in < 0) - { - if (source.closed) - return -1; - lock.wait(); - } - } - catch (InterruptedException ix) - { - throw new InterruptedIOException(); - } - - int total = 0; - int copylen; - - while (true) - { - // Figure out how many chars from the pipe can be copied without - // overrunning in or going past the length of buf. - if (out < in) - copylen = Math.min (len, in - out); - else - copylen = Math.min (len, buffer.length - out); - - System.arraycopy (buffer, out, buf, offset, copylen); - offset += copylen; - len -= copylen; - out += copylen; - total += copylen; - - if (out == buffer.length) - out = 0; - - if (out == in) - { - // Pipe is now empty. - in = -1; - out = 0; - } - - // If output buffer is filled or the pipe is empty, we're done. - if (len == 0 || in == -1) - { - // Notify any waiting Writer that there is now space - // to write. - lock.notifyAll(); - return total; - } - } - } - } - - public boolean ready() throws IOException - { - // The JDK 1.3 implementation does not appear to check for the closed or - // unconnected stream conditions here. However, checking for a - // closed stream is explicitly required by the JDK 1.2 and 1.3 - // documentation (for Reader.close()), so we do it. - - synchronized (lock) - { - if (closed) - throw new IOException("Pipe closed"); - - if (in < 0) - return false; - - int count; - if (out < in) - count = in - out; - else - count = (buffer.length - out) - in; - - return (count > 0); - } - } - - /** - * This methods closes the stream so that no more data can be read - * from it. - * - * @exception IOException If an error occurs - */ - public void close() throws IOException - { - synchronized (lock) - { - closed = true; - // Wake any thread which may be in receive() waiting to write data. - lock.notifyAll(); - } - } -} - diff --git a/libjava/java/io/PipedWriter.java b/libjava/java/io/PipedWriter.java deleted file mode 100644 index 92786e5de7d..00000000000 --- a/libjava/java/io/PipedWriter.java +++ /dev/null @@ -1,182 +0,0 @@ -/* PipedWriter.java -- Write portion of piped character streams. - Copyright (C) 1998, 2000, 2001, 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.io; - -// NOTE: This implementation is very similar to that of PipedOutputStream. -// If you fix a bug in here, chances are you should make a similar change to -// the PipedOutputStream code. - -/** - * This class writes its chars to a <code>PipedReader</code> to - * which it is connected. - * <p> - * It is highly recommended that a <code>PipedWriter</code> and its - * connected <code>PipedReader</code> be in different threads. If - * they are in the same thread, read and write operations could deadlock - * the thread. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public class PipedWriter extends Writer -{ - /** Target PipedReader to which this is connected. Null only if this - * Writer hasn't been connected yet. */ - PipedReader sink; - - /** Set to true if close() has been called on this Writer. */ - boolean closed; - - /** Buffer used to implement single-argument write */ - char[] read_buf = new char[1]; - - /** - * Create an unconnected PipedWriter. It must be connected - * to a <code>PipedReader</code> using the <code>connect</code> - * method prior to writing any data or an exception will be thrown. - */ - public PipedWriter() - { - } - - /** - * Create a new <code>PipedWriter</code> instance - * to write to the specified <code>PipedReader</code>. This stream - * is then ready for writing. - * - * @param sink The <code>PipedReader</code> to connect this stream to. - * - * @exception IOException If <code>sink</code> has already been connected - * to a different PipedWriter. - */ - public PipedWriter(PipedReader sink) throws IOException - { - sink.connect(this); - } - - /** - * Connects this object to the specified <code>PipedReader</code> - * object. This stream will then be ready for writing. - * - * @param sink The <code>PipedReader</code> to connect this stream to - * - * @exception IOException If the stream has not been connected or has - * been closed. - */ - public void connect(PipedReader sink) throws IOException - { - if (this.sink != null || sink.source != null) - throw new IOException ("Already connected"); - sink.connect(this); - } - - /** - * Write a single char of date to the stream. Note that this method will - * block if the <code>PipedReader</code> to which this object is - * connected has a full buffer. - * - * @param b The char of data to be written, passed as an <code>int</code>. - * - * @exception IOException If the stream has not been connected or has - * been closed. - */ - public void write(int b) throws IOException - { - read_buf[0] = (char) (b & 0xffff); - sink.receive (read_buf, 0, 1); - } - - /** - * This method writes <code>len</code> chars of data from the char array - * <code>buf</code> starting at index <code>offset</code> in the array - * to the stream. Note that this method will block if the - * <code>PipedReader</code> to which this object is connected has - * a buffer that cannot hold all of the chars to be written. - * - * @param buffer The array containing chars to write to the stream. - * @param offset The index into the array to start writing chars from. - * @param len The number of chars to write. - * - * @exception IOException If the stream has not been connected or has - * been closed. - */ - public void write(char[] buffer, int offset, int len) throws IOException - { - if (sink == null) - throw new IOException ("Not connected"); - if (closed) - throw new IOException ("Pipe closed"); - - sink.receive(buffer, offset, len); - } - - /** - * This method does nothing. - * - * @exception IOException If the stream is closed. - * @specnote You'd think that this method would block until the sink - * had read all available data. Thats not the case - this method - * appears to be a no-op? - */ - public void flush() throws IOException - { - if (closed) - throw new IOException ("Pipe closed"); - } - - /** - * This method closes this stream so that no more data can be written - * to it. Any further attempts to write to this stream may throw an - * exception - * - * @exception IOException If an error occurs - */ - public void close() throws IOException - { - // A close call on an unconnected PipedWriter has no effect. - if (sink != null) - { - closed = true; - // Notify any waiting readers that the stream is now closed. - synchronized (sink) - { - sink.notifyAll(); - } - } - } -} diff --git a/libjava/java/io/PrintWriter.java b/libjava/java/io/PrintWriter.java deleted file mode 100644 index 5fd0b162f31..00000000000 --- a/libjava/java/io/PrintWriter.java +++ /dev/null @@ -1,571 +0,0 @@ -/* PrintWriter.java -- prints primitive values and objects to a stream as text - Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.io; - -/* Written using "Java Class Libraries", 2nd edition, plus online - * API docs for JDK 1.2 beta from http://www.javasoft.com. - * Status: Believed complete and correct. - * However, should use native methods for conversion. - */ - -/** - * This class prints Java primitive values and objects to a stream as - * text. None of the methods in this class throw an exception. However, - * errors can be detected by calling the <code>checkError()</code> method. - * Additionally, this stream can be designated as "autoflush" when - * created so that any writes are automatically flushed to the underlying - * output sink whenever one of the <code>println</code> methods is - * called. (Note that this differs from the <code>PrintStream</code> - * class which also auto-flushes when it encounters a newline character - * in the chars written). - * - * @author Per Bothner (bothner@cygnus.com) - * @author Aaron M. Renn (arenn@urbanophile.com) - * @date April 17, 1998. - */ -public class PrintWriter extends Writer -{ - /** - * <code>true</code> if auto-flush is enabled, <code>false</code> otherwise - */ - private boolean autoflush; - - /** - * This boolean indicates whether or not an error has ever occurred - * on this stream. - */ - private boolean error; - - /** - * This is the underlying <code>Writer</code> we are sending output - * to - */ - protected Writer out; - - /** - * This method intializes a new <code>PrintWriter</code> object to write - * to the specified output sink. The form of the constructor does not - * enable auto-flush functionality. - * - * @param wr The <code>Writer</code> to write to. - */ - public PrintWriter(Writer wr) - { - super(wr.lock); - this.out = wr; - } - - /** - * This method intializes a new <code>PrintWriter</code> object to write - * to the specified output sink. This constructor also allows "auto-flush" - * functionality to be specified where the stream will be flushed after - * every line is terminated or newline character is written. - * - * @param wr The <code>Writer</code> to write to. - * @param autoflush <code>true</code> to flush the stream after every - * line, <code>false</code> otherwise - */ - public PrintWriter(Writer wr, boolean autoflush) - { - super(wr.lock); - this.out = wr; - this.autoflush = autoflush; - } - - /** - * This method initializes a new <code>PrintWriter</code> object to write - * to the specified <code>OutputStream</code>. Characters will be converted - * to chars using the system default encoding. Auto-flush functionality - * will not be enabled. - * - * @param out The <code>OutputStream</code> to write to - */ - public PrintWriter(OutputStream out) - { - super(); - this.out = new OutputStreamWriter(out); - this.lock = this.out; - } - - /** - * This method initializes a new <code>PrintWriter</code> object to write - * to the specified <code>OutputStream</code>. Characters will be converted - * to chars using the system default encoding. This form of the - * constructor allows auto-flush functionality to be enabled if desired - * - * @param out The <code>OutputStream</code> to write to - * @param autoflush <code>true</code> to flush the stream after every - * <code>println</code> call, <code>false</code> otherwise. - */ - public PrintWriter(OutputStream out, boolean autoflush) - { - this(out); - this.autoflush = autoflush; - } - - /** - * This method can be called by subclasses to indicate that an error - * has occurred and should be reported by <code>checkError</code>. - */ - protected void setError() - { - error = true; - } - - /** - * This method checks to see if an error has occurred on this stream. Note - * that once an error has occurred, this method will continue to report - * <code>true</code> forever for this stream. Before checking for an - * error condition, this method flushes the stream. - * - * @return <code>true</code> if an error has occurred, - * <code>false</code> otherwise - */ - public boolean checkError() - { - flush(); - return error; - } - - /** - * This method flushes any buffered chars to the underlying stream and - * then flushes that stream as well. - */ - public void flush() - { - try - { - out.flush(); - } - catch (IOException ex) - { - error = true; - } - } - - /** - * This method closes this stream and all underlying streams. - */ - public void close() - { - try - { - out.close(); - } - catch (IOException ex) - { - error = true; - } - } - - /** - * This method prints a <code>String</code> to the stream. The actual - * value printed depends on the system default encoding. - * - * @param str The <code>String</code> to print. - */ - public void print(String str) - { - write(str == null ? "null" : str); - } - - /** - * This method prints a char to the stream. The actual value printed is - * determined by the character encoding in use. - * - * @param ch The <code>char</code> value to be printed - */ - public void print(char ch) - { - write((int) ch); - } - - /** - * This method prints an array of characters to the stream. The actual - * value printed depends on the system default encoding. - * - * @param charArray The array of characters to print. - */ - public void print(char[] charArray) - { - write(charArray, 0, charArray.length); - } - - /** - * This methods prints a boolean value to the stream. <code>true</code> - * values are printed as "true" and <code>false</code> values are printed - * as "false". - * - * @param bool The <code>boolean</code> value to print - */ - public void print(boolean bool) - { - // We purposely call write() and not print() here. This preserves - // compatibility with JDK 1.2. - write (bool ? "true" : "false"); - } - - /** - * This method prints an integer to the stream. The value printed is - * determined using the <code>String.valueOf()</code> method. - * - * @param inum The <code>int</code> value to be printed - */ - public void print(int inum) - { - // We purposely call write() and not print() here. This preserves - // compatibility with JDK 1.2. - write(Integer.toString(inum)); - } - - /** - * This method prints a long to the stream. The value printed is - * determined using the <code>String.valueOf()</code> method. - * - * @param lnum The <code>long</code> value to be printed - */ - public void print(long lnum) - { - // We purposely call write() and not print() here. This preserves - // compatibility with JDK 1.2. - write(Long.toString(lnum)); - } - - /** - * This method prints a float to the stream. The value printed is - * determined using the <code>String.valueOf()</code> method. - * - * @param fnum The <code>float</code> value to be printed - */ - public void print(float fnum) - { - // We purposely call write() and not print() here. This preserves - // compatibility with JDK 1.2. - write(Float.toString(fnum)); - } - - /** - * This method prints a double to the stream. The value printed is - * determined using the <code>String.valueOf()</code> method. - * - * @param dnum The <code>double</code> value to be printed - */ - public void print(double dnum) - { - // We purposely call write() and not print() here. This preserves - // compatibility with JDK 1.2. - write(Double.toString(dnum)); - } - - /** - * This method prints an <code>Object</code> to the stream. The actual - * value printed is determined by calling the <code>String.valueOf()</code> - * method. - * - * @param obj The <code>Object</code> to print. - */ - public void print(Object obj) - { - // We purposely call write() and not print() here. This preserves - // compatibility with JDK 1.2. - write(obj == null ? "null" : obj.toString()); - } - - /** - * This is the system dependent line separator - */ - private static final char[] line_separator - = System.getProperty("line.separator").toCharArray(); - - /** - * This method prints a line separator sequence to the stream. The value - * printed is determined by the system property <xmp>line.separator</xmp> - * and is not necessarily the Unix '\n' newline character. - */ - public void println() - { - synchronized (lock) - { - try - { - write(line_separator, 0, line_separator.length); - if (autoflush) - out.flush(); - } - catch (IOException ex) - { - error = true; - } - } - } - - /** - * This methods prints a boolean value to the stream. <code>true</code> - * values are printed as "true" and <code>false</code> values are printed - * as "false". - * - * This method prints a line termination sequence after printing the value. - * - * @param bool The <code>boolean</code> value to print - */ - public void println(boolean bool) - { - synchronized (lock) - { - print(bool); - println(); - } - } - - /** - * This method prints an integer to the stream. The value printed is - * determined using the <code>String.valueOf()</code> method. - * - * This method prints a line termination sequence after printing the value. - * - * @param inum The <code>int</code> value to be printed - */ - public void println(int inum) - { - synchronized (lock) - { - print(inum); - println(); - } - } - - /** - * This method prints a long to the stream. The value printed is - * determined using the <code>String.valueOf()</code> method. - * - * This method prints a line termination sequence after printing the value. - * - * @param lnum The <code>long</code> value to be printed - */ - public void println(long lnum) - { - synchronized (lock) - { - print(lnum); - println(); - } - } - - /** - * This method prints a float to the stream. The value printed is - * determined using the <code>String.valueOf()</code> method. - * - * This method prints a line termination sequence after printing the value. - * - * @param fnum The <code>float</code> value to be printed - */ - public void println(float fnum) - { - synchronized (lock) - { - print(fnum); - println(); - } - } - - /** - * This method prints a double to the stream. The value printed is - * determined using the <code>String.valueOf()</code> method. - * - * This method prints a line termination sequence after printing the value. - * - * @param dnum The <code>double</code> value to be printed - */ - public void println(double dnum) - { - synchronized (lock) - { - print(dnum); - println(); - } - } - - /** - * This method prints an <code>Object</code> to the stream. The actual - * value printed is determined by calling the <code>String.valueOf()</code> - * method. - * - * This method prints a line termination sequence after printing the value. - * - * @param obj The <code>Object</code> to print. - */ - public void println(Object obj) - { - synchronized (lock) - { - print(obj); - println(); - } - } - - /** - * This method prints a <code>String</code> to the stream. The actual - * value printed depends on the system default encoding. - * - * This method prints a line termination sequence after printing the value. - * - * @param str The <code>String</code> to print. - */ - public void println(String str) - { - synchronized (lock) - { - print(str); - println(); - } - } - - /** - * This method prints a char to the stream. The actual value printed is - * determined by the character encoding in use. - * - * This method prints a line termination sequence after printing the value. - * - * @param ch The <code>char</code> value to be printed - */ - public void println(char ch) - { - synchronized (lock) - { - print(ch); - println(); - } - } - - /** - * This method prints an array of characters to the stream. The actual - * value printed depends on the system default encoding. - * - * This method prints a line termination sequence after printing the value. - * - * @param charArray The array of characters to print. - */ - public void println(char[] charArray) - { - synchronized (lock) - { - print(charArray); - println(); - } - } - - /** - * This method writes a single char to the stream. - * - * @param ch The char to be written, passed as a int - */ - public void write(int ch) - { - try - { - out.write(ch); - } - catch (IOException ex) - { - error = true; - } - } - - /** - * This method writes <code>count</code> chars from the specified array - * starting at index <code>offset</code> into the array. - * - * @param charArray The array of chars to write - * @param offset The index into the array to start writing from - * @param count The number of chars to write - */ - public void write(char[] charArray, int offset, int count) - { - try - { - out.write(charArray, offset, count); - } - catch (IOException ex) - { - error = true; - } - } - - /** - * This method writes <code>count</code> chars from the specified - * <code>String</code> to the output starting at character position - * <code>offset</code> into the <code>String</code> - * - * @param str The <code>String</code> to write chars from - * @param offset The offset into the <code>String</code> to start writing from - * @param count The number of chars to write. - */ - public void write(String str, int offset, int count) - { - try - { - out.write(str, offset, count); - } - catch (IOException ex) - { - error = true; - } - } - - /** - * This method write all the chars in the specified array to the output. - * - * @param charArray The array of characters to write - */ - public void write(char[] charArray) - { - write(charArray, 0, charArray.length); - } - - /** - * This method writes the contents of the specified <code>String</code> - * to the underlying stream. - * - * @param str The <code>String</code> to write - */ - public void write(String str) - { - write(str, 0, str.length()); - } -} - diff --git a/libjava/java/io/PushbackInputStream.java b/libjava/java/io/PushbackInputStream.java deleted file mode 100644 index 71cf244274e..00000000000 --- a/libjava/java/io/PushbackInputStream.java +++ /dev/null @@ -1,328 +0,0 @@ -/* PushbackInputStream.java -- An input stream that can unread bytes - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.io; - -/** - * This subclass of <code>FilterInputStream</code> provides the ability to - * unread data from a stream. It maintains an internal buffer of unread - * data that is supplied to the next read operation. This is conceptually - * similar to mark/reset functionality, except that in this case the - * position to reset the stream to does not need to be known in advance. - * <p> - * The default pushback buffer size one byte, but this can be overridden - * by the creator of the stream. - * <p> - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Warren Levy (warrenl@cygnus.com) - */ -public class PushbackInputStream extends FilterInputStream -{ - /** - * This is the default buffer size - */ - private static final int DEFAULT_BUFFER_SIZE = 1; - - /** - * This is the buffer that is used to store the pushed back data - */ - protected byte[] buf; - - /** - * This is the position in the buffer from which the next byte will be - * read. Bytes are stored in reverse order in the buffer, starting from - * <code>buf[buf.length - 1]</code> to <code>buf[0]</code>. Thus when - * <code>pos</code> is 0 the buffer is full and <code>buf.length</code> when - * it is empty - */ - protected int pos; - - /** - * This method initializes a <code>PushbackInputStream</code> to - * read from the specified subordinate <code>InputStream</code> - * with a default pushback buffer size of 1. - * - * @param in The subordinate stream to read from - */ - public PushbackInputStream(InputStream in) - { - this(in, DEFAULT_BUFFER_SIZE); - } - - /** - * This method initializes a <code>PushbackInputStream</code> to - * read from the specified subordinate <code>InputStream</code> with - * the specified buffer size - * - * @param in The subordinate <code>InputStream</code> to read from - * @param size The pushback buffer size to use - */ - public PushbackInputStream(InputStream in, int size) - { - super(in); - if (size < 0) - throw new IllegalArgumentException(); - buf = new byte[size]; - pos = buf.length; - } - - /** - * This method returns the number of bytes that can be read from this - * stream before a read can block. A return of 0 indicates that blocking - * might (or might not) occur on the very next read attempt. - * <p> - * This method will return the number of bytes available from the - * pushback buffer plus the number of bytes available from the - * underlying stream. - * - * @return The number of bytes that can be read before blocking could occur - * - * @exception IOException If an error occurs - */ - public int available() throws IOException - { - return (buf.length - pos) + super.available(); - } - - /** - * This method closes the stream and releases any associated resources. - * - * @exception IOException If an error occurs. - */ - public synchronized void close() throws IOException - { - buf = null; - super.close(); - } - - /** - * This method returns <code>false</code> to indicate that it does - * not support mark/reset functionality. - * - * @return This method returns <code>false</code> to indicate that - * this class does not support mark/reset functionality - */ - public boolean markSupported() - { - return false; - } - - /** - * This method always throws an IOException in this class because - * mark/reset functionality is not supported. - * - * @exception IOException Always thrown for this class - */ - public void reset() throws IOException - { - throw new IOException("Mark not supported in this class"); - } - - /** - * This method reads an unsigned byte from the input stream and returns it - * as an int in the range of 0-255. This method also will return -1 if - * the end of the stream has been reached. The byte returned will be read - * from the pushback buffer, unless the buffer is empty, in which case - * the byte will be read from the underlying stream. - * <p> - * This method will block until the byte can be read. - * - * @return The byte read or -1 if end of stream - * - * @exception IOException If an error occurs - */ - public synchronized int read() throws IOException - { - if (pos < buf.length) - return ((int) buf[pos++]) & 0xFF; - - return super.read(); - } - - /** - * This method read bytes from a stream and stores them into a - * caller supplied buffer. It starts storing the data at index - * <code>offset</code> into the buffer and attempts to read - * <code>len</code> bytes. This method can return before reading the - * number of bytes requested. The actual number of bytes read is - * returned as an int. A -1 is returned to indicate the end of the - * stream. - * <p> - * This method will block until some data can be read. - * <p> - * This method first reads bytes from the pushback buffer in order to - * satisfy the read request. If the pushback buffer cannot provide all - * of the bytes requested, the remaining bytes are read from the - * underlying stream. - * - * @param b The array into which the bytes read should be stored - * @param off The offset into the array to start storing bytes - * @param len The requested number of bytes to read - * - * @return The actual number of bytes read, or -1 if end of stream. - * - * @exception IOException If an error occurs. - */ - public synchronized int read(byte[] b, int off, int len) throws IOException - { - int numBytes = Math.min(buf.length - pos, len); - - if (numBytes > 0) - { - System.arraycopy (buf, pos, b, off, numBytes); - pos += numBytes; - len -= numBytes; - off += numBytes; - } - - if (len > 0) - { - len = super.read(b, off, len); - if (len == -1) //EOF - return numBytes > 0 ? numBytes : -1; - numBytes += len; - } - return numBytes; - } - - /** - * This method pushes a single byte of data into the pushback buffer. - * The byte pushed back is the one that will be returned as the first byte - * of the next read. - * <p> - * If the pushback buffer is full, this method throws an exception. - * <p> - * The argument to this method is an <code>int</code>. Only the low - * eight bits of this value are pushed back. - * - * @param b The byte to be pushed back, passed as an int - * - * @exception IOException If the pushback buffer is full. - */ - public synchronized void unread(int b) throws IOException - { - if (pos <= 0) - throw new IOException("Insufficient space in pushback buffer"); - - buf[--pos] = (byte) b; - } - - /** - * This method pushes all of the bytes in the passed byte array into - * the pushback bfer. These bytes are pushed in reverse order so that - * the next byte read from the stream after this operation will be - * <code>b[0]</code> followed by <code>b[1]</code>, etc. - * <p> - * If the pushback buffer cannot hold all of the requested bytes, an - * exception is thrown. - * - * @param b The byte array to be pushed back - * - * @exception IOException If the pushback buffer is full - */ - public synchronized void unread(byte[] b) throws IOException - { - unread(b, 0, b.length); - } - - /** - * This method pushed back bytes from the passed in array into the - * pushback buffer. The bytes from <code>b[offset]</code> to - * <code>b[offset + len]</code> are pushed in reverse order so that - * the next byte read from the stream after this operation will be - * <code>b[offset]</code> followed by <code>b[offset + 1]</code>, - * etc. - * <p> - * If the pushback buffer cannot hold all of the requested bytes, an - * exception is thrown. - * - * @param b The byte array to be pushed back - * @param off The index into the array where the bytes to be push start - * @param len The number of bytes to be pushed. - * - * @exception IOException If the pushback buffer is full - */ - public synchronized void unread(byte[] b, int off, int len) - throws IOException - { - if (pos < len) - throw new IOException("Insufficient space in pushback buffer"); - - // Note the order that these bytes are being added is the opposite - // of what would be done if they were added to the buffer one at a time. - // See the Java Class Libraries book p. 1390. - System.arraycopy(b, off, buf, pos - len, len); - - // Don't put this into the arraycopy above, an exception might be thrown - // and in that case we don't want to modify pos. - pos -= len; - } - - /** - * This method skips the specified number of bytes in the stream. It - * returns the actual number of bytes skipped, which may be less than the - * requested amount. - * <p> - * This method first discards bytes from the buffer, then calls the - * <code>skip</code> method on the underlying <code>InputStream</code> to - * skip additional bytes if necessary. - * - * @param n The requested number of bytes to skip - * - * @return The actual number of bytes skipped. - * - * @exception IOException If an error occurs - * - * @since 1.2 - */ - public synchronized long skip(long n) throws IOException - { - final long origN = n; - - if (n > 0L) - { - int numread = (int) Math.min((long) (buf.length - pos), n); - pos += numread; - n -= numread; - if (n > 0) - n -= super.skip(n); - } - - return origN - n; - } -} diff --git a/libjava/java/io/PushbackReader.java b/libjava/java/io/PushbackReader.java deleted file mode 100644 index 04bccc70fc5..00000000000 --- a/libjava/java/io/PushbackReader.java +++ /dev/null @@ -1,384 +0,0 @@ -/* PushbackReader.java -- An character stream that can unread chars - Copyright (C) 1998, 2000, 2001, 2003, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.io; - -/** - * This subclass of <code>FilterReader</code> provides the ability to - * unread data from a stream. It maintains an internal buffer of unread - * data that is supplied to the next read operation. This is conceptually - * similar to mark/reset functionality, except that in this case the - * position to reset the stream to does not need to be known in advance. - * <p> - * The default pushback buffer size one char, but this can be overridden - * by the creator of the stream. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Warren Levy (warrenl@cygnus.com) - */ -public class PushbackReader extends FilterReader -{ - /** - * This is the default buffer size - */ - private static final int DEFAULT_BUFFER_SIZE = 1; - - /** - * This is the buffer that is used to store the pushed back data - */ - private char[] buf; - - /** - * This is the position in the buffer from which the next char will be - * read. Bytes are stored in reverse order in the buffer, starting from - * <code>buf[buf.length - 1]</code> to <code>buf[0]</code>. Thus when - * <code>pos</code> is 0 the buffer is full and <code>buf.length</code> when - * it is empty - */ - private int pos; - - /** - * This method initializes a <code>PushbackReader</code> to read from the - * specified subordinate <code>Reader</code> with a default pushback buffer - * size of 1. - * - * @param in The subordinate stream to read from - */ - public PushbackReader(Reader in) - { - this(in, DEFAULT_BUFFER_SIZE); - } - - /** - * This method initializes a <code>PushbackReader</code> to read from the - * specified subordinate <code>Reader</code> with the specified buffer - * size - * - * @param in The subordinate <code>Reader</code> to read from - * @param bufsize The pushback buffer size to use - */ - public PushbackReader(Reader in, int bufsize) - { - super(in); - - if (bufsize < 0) - throw new IllegalArgumentException("buffer size must be positive"); - - buf = new char[bufsize]; - pos = bufsize; - } - - /** - * This method closes the stream and frees any associated resources. - * - * @exception IOException If an error occurs. - */ - public void close() throws IOException - { - synchronized (lock) - { - buf = null; - super.close(); - } - } - - /** - * This method throws an exception when called since this class does - * not support mark/reset. - * - * @param read_limit Not used. - * - * @exception IOException Always thrown to indicate mark/reset not supported. - */ - public void mark(int read_limit) throws IOException - { - throw new IOException("mark not supported in this class"); - } - - /** - * This method returns <code>false</code> to indicate that it does not support - * mark/reset functionality. - * - * @return This method returns <code>false</code> to indicate that this - * class does not support mark/reset functionality - * - */ - public boolean markSupported() - { - return(false); - } - - /** - * This method always throws an IOException in this class because - * mark/reset functionality is not supported. - * - * @exception IOException Always thrown for this class - */ - public void reset() throws IOException - { - throw new IOException("reset not supported in this class"); - } - - /** - * This method determines whether or not this stream is ready to be read. - * If it returns <code>false</code> to indicate that the stream is not - * ready, any attempt to read from the stream could (but is not - * guaranteed to) block. - * <p> - * This stream is ready to read if there are either chars waiting to be - * read in the pushback buffer or if the underlying stream is ready to - * be read. - * - * @return <code>true</code> if this stream is ready to be read, - * <code>false</code> otherwise - * - * @exception IOException If an error occurs - */ - public boolean ready() throws IOException - { - synchronized (lock) - { - if (buf == null) - throw new IOException ("stream closed"); - - if (((buf.length - pos) > 0) || super.ready()) - return(true); - else - return(false); - } - } - - // Don't delete this method just because the spec says it shouldn't be there! - // See the CVS log for details. - /** - * This method skips the specified number of chars in the stream. It - * returns the actual number of chars skipped, which may be less than the - * requested amount. - * <p> - * This method first discards chars from the buffer, then calls the - * <code>skip</code> method on the underlying <code>Reader</code> to - * skip additional chars if necessary. - * - * @param num_chars The requested number of chars to skip - * - * @return The actual number of chars skipped. - * - * @exception IOException If an error occurs - */ - public long skip(long num_chars) throws IOException - { - synchronized (lock) - { - if (num_chars <= 0) - return(0); - - if ((buf.length - pos) >= num_chars) - { - pos += num_chars; - return(num_chars); - } - - int chars_discarded = buf.length - pos; - pos = buf.length; - - long chars_skipped = in.skip(num_chars - chars_discarded); - - return(chars_discarded + chars_skipped); - } - } - - /** - * This method reads an unsigned char from the input stream and returns it - * as an int in the range of 0-65535. This method also will return -1 if - * the end of the stream has been reached. The char returned will be read - * from the pushback buffer, unless the buffer is empty, in which case - * the char will be read from the underlying stream. - * <p> - * This method will block until the char can be read. - * - * @return The char read or -1 if end of stream - * - * @exception IOException If an error occurs - */ - public int read() throws IOException - { - synchronized (lock) - { - if (buf == null) - throw new IOException("stream closed"); - - if (pos == buf.length) - return(super.read()); - - ++pos; - return((buf[pos - 1] & 0xFFFF)); - } - } - - /** - * This method read chars from a stream and stores them into a caller - * supplied buffer. It starts storing the data at index <code>offset</code> - * into - * the buffer and attempts to read <code>len</code> chars. This method can - * return before reading the number of chars requested. The actual number - * of chars read is returned as an int. A -1 is returned to indicate the - * end of the stream. - * <p> - * This method will block until some data can be read. - * <p> - * This method first reads chars from the pushback buffer in order to - * satisfy the read request. If the pushback buffer cannot provide all - * of the chars requested, the remaining chars are read from the - * underlying stream. - * - * @param buffer The array into which the chars read should be stored - * @param offset The offset into the array to start storing chars - * @param length The requested number of chars to read - * - * @return The actual number of chars read, or -1 if end of stream. - * - * @exception IOException If an error occurs. - */ - public synchronized int read(char[] buffer, int offset, int length) - throws IOException - { - synchronized (lock) - { - if (buf == null) - throw new IOException("stream closed"); - - if (offset < 0 || length < 0 || offset + length > buffer.length) - throw new ArrayIndexOutOfBoundsException(); - - int numBytes = Math.min(buf.length - pos, length); - if (numBytes > 0) - { - System.arraycopy (buf, pos, buffer, offset, numBytes); - pos += numBytes; - return numBytes; - } - - return super.read(buffer, offset, length); - } - } - - /** - * This method pushes a single char of data into the pushback buffer. - * The char pushed back is the one that will be returned as the first char - * of the next read. - * <p> - * If the pushback buffer is full, this method throws an exception. - * <p> - * The argument to this method is an <code>int</code>. Only the low eight - * bits of this value are pushed back. - * - * @param b The char to be pushed back, passed as an int - * - * @exception IOException If the pushback buffer is full. - */ - public void unread(int b) throws IOException - { - synchronized (lock) - { - if (buf == null) - throw new IOException("stream closed"); - if (pos == 0) - throw new IOException("Pushback buffer is full"); - - --pos; - buf[pos] = (char)(b & 0xFFFF); - } - } - - /** - * This method pushes all of the chars in the passed char array into - * the pushback buffer. These chars are pushed in reverse order so that - * the next char read from the stream after this operation will be - * <code>buf[0]</code> followed by <code>buf[1]</code>, etc. - * <p> - * If the pushback buffer cannot hold all of the requested chars, an - * exception is thrown. - * - * @param buf The char array to be pushed back - * - * @exception IOException If the pushback buffer is full - */ - public synchronized void unread(char[] buf) throws IOException - { - unread(buf, 0, buf.length); - } - - /** - * This method pushed back chars from the passed in array into the pushback - * buffer. The chars from <code>buf[offset]</code> to - * <code>buf[offset + len]</code> - * are pushed in reverse order so that the next char read from the stream - * after this operation will be <code>buf[offset]</code> followed by - * <code>buf[offset + 1]</code>, etc. - * <p> - * If the pushback buffer cannot hold all of the requested chars, an - * exception is thrown. - * - * @param buffer The char array to be pushed back - * @param offset The index into the array where the chars to be push start - * @param length The number of chars to be pushed. - * - * @exception IOException If the pushback buffer is full - */ - public synchronized void unread(char[] buffer, int offset, int length) - throws IOException - { - synchronized (lock) - { - if (buf == null) - throw new IOException("stream closed"); - if (pos < length) - throw new IOException("Pushback buffer is full"); - - // Note the order that these chars are being added is the opposite - // of what would be done if they were added to the buffer one at a time. - // See the Java Class Libraries book p. 1397. - System.arraycopy(buffer, offset, buf, pos - length, length); - - // Don't put this into the arraycopy above, an exception might be thrown - // and in that case we don't want to modify pos. - pos -= length; - } - } -} - diff --git a/libjava/java/io/Reader.java b/libjava/java/io/Reader.java deleted file mode 100644 index 7970d9a2434..00000000000 --- a/libjava/java/io/Reader.java +++ /dev/null @@ -1,271 +0,0 @@ -/* Reader.java -- base class of classes that read input as a stream of chars - Copyright (C) 1998, 1999, 2000, 2003 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.io; - -/* Written using "Java Class Libraries", 2nd edition, plus online - * API docs for JDK 1.2 beta from http://www.javasoft.com. - * Status: Believed complete and correct. - */ - -/** - * This abstract class forms the base of the hierarchy of classes that read - * input as a stream of characters. It provides a common set of methods for - * reading characters from streams. Subclasses implement and extend these - * methods to read characters from a particular input source such as a file - * or network connection. - * - * @author Per Bothner (bothner@cygnus.com) - * @date April 21, 1998. - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public abstract class Reader -{ - /** - * This is the <code>Object</code> used for synchronizing critical code - * sections. Subclasses should use this variable instead of a - * synchronized method or an explicit synchronization on <code>this</code> - */ - protected Object lock; - - /** - * Unitializes a <code>Reader</code> that will use the object - * itself for synchronization of critical code sections. - */ - protected Reader() - { - this.lock = this; - } - - /** - * Initializes a <code>Reader</code> that will use the specified - * <code>Object</code> for synchronization of critical code sections. - * - * @param lock The <code>Object</code> to use for synchronization - */ - protected Reader(Object lock) - { - this.lock = lock; - } - - /** - * Read chars from a stream and stores them into a caller - * supplied buffer. It starts storing the data at index <code>offset</code> - * into the buffer and attempts to read <code>len</code> chars. This method - * can return before reading the number of chars requested. The actual - * number of chars read is returned as an int. A -1 is returned to indicate - * the end of the stream. - * <p> - * This method will block until some data can be read. - * <p> - * This method operates by calling the single char <code>read()</code> method - * in a loop until the desired number of chars are read. The read loop - * stops short if the end of the stream is encountered or if an IOException - * is encountered on any read operation except the first. If the first - * attempt to read a chars fails, the IOException is allowed to propagate - * upward. And subsequent IOException is caught and treated identically - * to an end of stream condition. Subclasses can (and should if possible) - * override this method to provide a more efficient implementation. - * - * @param buf The array into which the chars read should be stored - * @param offset The offset into the array to start storing chars - * @param count The requested number of chars to read - * - * @return The actual number of chars read, or -1 if end of stream. - * - * @exception IOException If an error occurs. - */ - public abstract int read(char buf[], int offset, int count) - throws IOException; - - /** - * Reads chars from a stream and stores them into a caller - * supplied buffer. This method attempts to completely fill the buffer, - * but can return before doing so. The actual number of chars read is - * returned as an int. A -1 is returned to indicate the end of the stream. - * <p> - * This method will block until some data can be read. - * <p> - * This method operates by calling an overloaded read method like so: - * <code>read(buf, 0, buf.length)</code> - * - * @param buf The buffer into which the chars read will be stored. - * - * @return The number of chars read or -1 if end of stream. - * - * @exception IOException If an error occurs. - */ - public int read(char buf[]) throws IOException - { - return read(buf, 0, buf.length); - } - - /** - * Reads an char from the input stream and returns it - * as an int in the range of 0-65535. This method also will return -1 if - * the end of the stream has been reached. - * <p> - * This method will block until the char can be read. - * - * @return The char read or -1 if end of stream - * - * @exception IOException If an error occurs - */ - public int read() throws IOException - { - char[] buf = new char[1]; - int count = read(buf, 0, 1); - return count > 0 ? buf[0] : -1; - } - - /** - * Closes the stream. Any futher attempts to read from the - * stream may generate an <code>IOException</code>. - * - * @exception IOException If an error occurs - */ - public abstract void close() throws IOException; - - /** - * Returns a boolean that indicates whether the mark/reset - * methods are supported in this class. Those methods can be used to - * remember a specific point in the stream and reset the stream to that - * point. - * <p> - * This method always returns <code>false</code> in this class, but - * subclasses can override this method to return <code>true</code> if they - * support mark/reset functionality. - * - * @return <code>true</code> if mark/reset functionality is supported, - * <code>false</code> otherwise - * - */ - public boolean markSupported() - { - return false; - } - - /** - * Marks a position in the input to which the stream can be - * "reset" by calling the <code>reset()</code> method. The parameter - * <code>readlimit</code> is the number of chars that can be read from the - * stream after setting the mark before the mark becomes invalid. For - * example, if <code>mark()</code> is called with a read limit of 10, then - * when 11 chars of data are read from the stream before the - * <code>reset()</code> method is called, then the mark is invalid and the - * stream object instance is not required to remember the mark. - * - * @param readLimit The number of chars that can be read before the mark - * becomes invalid - * - * @exception IOException If an error occurs such as mark not being - * supported for this class - */ - public void mark(int readLimit) throws IOException - { - throw new IOException("mark not supported"); - } - - /** - * Resets a stream to the point where the <code>mark()</code> - * method was called. Any chars that were read after the mark point was - * set will be re-read during subsequent reads. - * <p> - * This method always throws an IOException in this class, but subclasses - * can override this method if they provide mark/reset functionality. - * - * @exception IOException Always thrown for this class - */ - public void reset() throws IOException - { - throw new IOException("reset not supported"); - } - - /** - * Determines whether or not this stream is ready to be - * read. If it returns <code>false</code> the stream may block if a - * read is attempted, but it is not guaranteed to do so. - * <p> - * This method always returns <code>false</code> in this class - * - * @return <code>true</code> if the stream is ready to be read, - * <code>false</code> otherwise. - * - * @exception IOException If an error occurs - */ - public boolean ready() throws IOException - { - return false; - } - - /** - * Skips the specified number of chars in the stream. It - * returns the actual number of chars skipped, which may be less than the - * requested amount. - * <p> - * This method reads and discards chars into a 256 char array until the - * specified number of chars were skipped or until either the end of stream - * is reached or a read attempt returns a short count. Subclasses can - * override this method to provide a more efficient implementation where - * one exists. - * - * @param count The requested number of chars to skip - * - * @return The actual number of chars skipped. - * - * @exception IOException If an error occurs - */ - public long skip(long count) throws IOException - { - if (count <= 0) - return 0; - int bsize = count > 1024 ? 1024 : (int) count; - char[] buffer = new char[bsize]; - long todo = count; - synchronized (lock) - { - while (todo > 0) - { - int skipped = read(buffer, 0, bsize > todo ? (int) todo : bsize); - if (skipped <= 0) - break; - todo -= skipped; - } - } - return count - todo; - } -} diff --git a/libjava/java/io/SequenceInputStream.java b/libjava/java/io/SequenceInputStream.java deleted file mode 100644 index 7fefe243263..00000000000 --- a/libjava/java/io/SequenceInputStream.java +++ /dev/null @@ -1,221 +0,0 @@ -/* SequenceInputStream.java -- Reads multiple input streams in sequence - Copyright (C) 1998, 1999, 2001, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.io; - -import java.util.Enumeration; - -/* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3 - * "The Java Language Specification", ISBN 0-201-63451-1 - * plus online API docs for JDK 1.2 beta from http://www.javasoft.com. - * Status: Believed complete and correct. - */ - -/** - * This class merges a sequence of multiple <code>InputStream</code>'s in - * order to form a single logical stream that can be read by applications - * that expect only one stream. - * <p> - * The streams passed to the constructor method are read in order until - * they return -1 to indicate they are at end of stream. When a stream - * reports end of stream, it is closed, then the next stream is read. - * When the last stream is closed, the next attempt to read from this - * stream will return a -1 to indicate it is at end of stream. - * <p> - * If this stream is closed prior to all subordinate streams being read - * to completion, all subordinate streams are closed. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Warren Levy (warrenl@cygnus.com) - */ -public class SequenceInputStream extends InputStream -{ - /** The handle for the current input stream. */ - private InputStream in; - - /** Secondary input stream; not used if constructed w/ enumeration. */ - private InputStream in2; - - /** The enumeration handle; not used if constructed w/ 2 explicit input streams. */ - private Enumeration e; - - /** - * This method creates a new <code>SequenceInputStream</code> that obtains - * its list of subordinate <code>InputStream</code>s from the specified - * <code>Enumeration</code> - * - * @param e An <code>Enumeration</code> that will return a list of - * <code>InputStream</code>s to read in sequence - */ - public SequenceInputStream(Enumeration e) - { - this.e = e; - in = (InputStream) e.nextElement(); - in2 = null; - } - - /** - * This method creates a new <code>SequenceInputStream</code> that will read - * the two specified subordinate <code>InputStream</code>s in sequence. - * - * @param s1 The first <code>InputStream</code> to read - * @param s2 The second <code>InputStream</code> to read - */ - public SequenceInputStream(InputStream s1, InputStream s2) - { - in = s1; - in2 = s2; - } - - /** - * This method returns the number of bytes than can be read from the - * currently being read subordinate stream before that stream could - * block. Note that it is possible more bytes than this can actually - * be read without the stream blocking. If a 0 is returned, then the - * stream could block on the very next read. - * - * @return The number of bytes that can be read before blocking could occur - * - * @exception IOException If an error occurs - */ - public int available() throws IOException - { - if (in == null) - return 0; - - return in.available(); - } - - /** - * Closes this stream. This will cause any remaining unclosed subordinate - * <code>InputStream</code>'s to be closed as well. Subsequent attempts to - * read from this stream may cause an exception. - * - * @exception IOException If an error occurs - */ - public void close() throws IOException - { - while (in != null) - { - in.close(); - in = getNextStream (); - } - } - - /** - * This method reads an unsigned byte from the input stream and returns it - * as an int in the range of 0-255. This method also will return -1 if - * the end of the stream has been reached. This will only happen when - * all of the subordinate streams have been read. - * <p> - * This method will block until the byte can be read. - * - * @return The byte read, or -1 if end of stream - * - * @exception IOException If an error occurs - */ - public int read() throws IOException - { - int ch = -1; - - while (in != null && (ch = in.read()) < 0) - { - in.close(); - in = getNextStream(); - } - - return ch; - } - - /** - * This method reads bytes from a stream and stores them into a caller - * supplied buffer. It starts storing the data at index <code>offset</code> - * into the buffer and attempts to read <code>len</code> bytes. This method - * can return before reading the number of bytes requested. The actual number - * of bytes read is returned as an int. A -1 is returend to indicate the - * end of the stream. This will only happen when all of the subordinate - * streams have been read. - * <p> - * This method will block until at least one byte can be read. - * - * @param b The array into which bytes read should be stored - * @param off The offset into the array to start storing bytes - * @param len The requested number of bytes to read - * - * @return The actual number of bytes read, or -1 if end of stream - * - * @exception IOException If an error occurs - */ - public int read(byte[] b, int off, int len) throws IOException - { - int ch = -1; - - // The validity of the parameters will be checked by in.read so - // don't bother doing it here. - while (in != null && (ch = in.read(b, off, len)) < 0) - { - in.close(); - in = getNextStream(); - } - - return ch; - } - - /** - * This private method is used to get the next <code>InputStream</code> to - * read from. Returns null when no more streams are available. - */ - private InputStream getNextStream() - { - InputStream nextIn = null; - - if (e != null) - { - if (e.hasMoreElements()) - nextIn = (InputStream) e.nextElement(); - } - else - if (in2 != null) - { - nextIn = in2; - in2 = null; - } - - return nextIn; - } -} diff --git a/libjava/java/io/Serializable.java b/libjava/java/io/Serializable.java deleted file mode 100644 index a6d99f6d522..00000000000 --- a/libjava/java/io/Serializable.java +++ /dev/null @@ -1,54 +0,0 @@ -/* Serializable.java -- Interface to indicate a class may be serialized - Copyright (C) 1998, 1999, 2001, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.io; - -/* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3 - * Status: Believed complete - */ - -/** - * This interface has no methods. It simply serves to indicate that - * the implementing class may be serialized. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Warren Levy (warrenl@cygnus.com) - */ -public interface Serializable -{ -} // interface Serializable diff --git a/libjava/java/io/SerializablePermission.java b/libjava/java/io/SerializablePermission.java deleted file mode 100644 index b5c07e4ec2c..00000000000 --- a/libjava/java/io/SerializablePermission.java +++ /dev/null @@ -1,113 +0,0 @@ -/* SerializablePermission.java -- Basic permissions related to serialization. - Copyright (C) 1998, 2000, 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.io; - -import java.security.BasicPermission; - -/** - * This class models permissions related to serialization. As a subclass - * of <code>BasicPermission</code>, this class has permissions that have - * a name only. There is no associated action list. - * <p> - * There are currently two allowable permission names for this class: - * <ul> - * <li><code>enableSubclassImplementation</code> - Allows a subclass to - * override the default serialization behavior of objects.</li> - * <li><code>enableSubstitution</code> - Allows substitution of one object - * for another during serialization or deserialization.</li> - * </ul> - * - * @see java.security.BasicPermission - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public final class SerializablePermission extends BasicPermission -{ - static final long serialVersionUID = 8537212141160296410L; - - /* - * Class Variables - */ - - private static final String[] legal_names = { "enableSubclassImplementation", - "enableSubstitution" }; - /* - * Constructors - */ - - /** - * This method initializes a new instance of - * <code>SerializablePermission</code> - * that has the specified name. - * - * @param name The name of the permission. - * - * @exception IllegalArgumentException If the name is not valid for - * this class. - */ - public SerializablePermission(String name) - { - this(name, null); - } - - /** - * This method initializes a new instance of - * <code>SerializablePermission</code> - * that has the specified name and action list. Note that the action list - * is unused in this class. - * - * @param name The name of the permission. - * @param actions The action list (unused). - * - * @exception IllegalArgumentException If the name is not valid for - * this class. - */ - public SerializablePermission(String name, String actions) - { - super(name, actions); - - for (int i = 0; i < legal_names.length; i++) - if (legal_names[i].equals(name)) - return; - - throw new IllegalArgumentException("Bad permission name: " + name); - } - -} // class SerializablePermission - diff --git a/libjava/java/io/StreamCorruptedException.java b/libjava/java/io/StreamCorruptedException.java deleted file mode 100644 index d24d12150c5..00000000000 --- a/libjava/java/io/StreamCorruptedException.java +++ /dev/null @@ -1,73 +0,0 @@ -/* StreamCorruptedException.java -- Error in stream during serialization - Copyright (C) 1998, 2000, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.io; - -/** - * This exception is thrown when there is an error in the data that is - * read from a stream during de-serialization. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Warren Levy (warrenl@cygnus.com) - * @since 1.1 - * @status updated to 1.4 - */ -public class StreamCorruptedException extends ObjectStreamException -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = 8983558202217591746L; - - /** - * Create an exception without a descriptive error message. - */ - public StreamCorruptedException() - { - } - - /** - * Create an exception with a descriptive error message. - * - * @param message the descriptive error message - */ - public StreamCorruptedException(String message) - { - super(message); - } -} // class StreamCorruptedException diff --git a/libjava/java/io/StreamTokenizer.java b/libjava/java/io/StreamTokenizer.java deleted file mode 100644 index bd7773b1990..00000000000 --- a/libjava/java/io/StreamTokenizer.java +++ /dev/null @@ -1,708 +0,0 @@ -/* StreamTokenizer.java -- parses streams of characters into tokens - Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.io; - -/** - * This class parses streams of characters into tokens. There are a - * million-zillion flags that can be set to control the parsing, as - * described under the various method headings. - * - * @author Warren Levy (warrenl@cygnus.com) - * @date October 25, 1998. - */ -/* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3 - * "The Java Language Specification", ISBN 0-201-63451-1 - * plus online API docs for JDK 1.2 beta from http://www.javasoft.com. - * Status: Believed complete and correct. - */ - -public class StreamTokenizer -{ - /** A constant indicating that the end of the stream has been read. */ - public static final int TT_EOF = -1; - - /** A constant indicating that the end of the line has been read. */ - public static final int TT_EOL = '\n'; - - /** A constant indicating that a number token has been read. */ - public static final int TT_NUMBER = -2; - - /** A constant indicating that a word token has been read. */ - public static final int TT_WORD = -3; - - /** A constant indicating that no tokens have been read yet. */ - private static final int TT_NONE = -4; - - /** - * Contains the type of the token read resulting from a call to nextToken - * The rules are as follows: - * <ul> - * <li>For a token consisting of a single ordinary character, this is the - * value of that character.</li> - * <li>For a quoted string, this is the value of the quote character</li> - * <li>For a word, this is TT_WORD</li> - * <li>For a number, this is TT_NUMBER</li> - * <li>For the end of the line, this is TT_EOL</li> - * <li>For the end of the stream, this is TT_EOF</li> - * </ul> - */ - public int ttype = TT_NONE; - - /** The String associated with word and string tokens. */ - public String sval; - - /** The numeric value associated with number tokens. */ - public double nval; - - /* Indicates whether end-of-line is recognized as a token. */ - private boolean eolSignificant = false; - - /* Indicates whether word tokens are automatically made lower case. */ - private boolean lowerCase = false; - - /* Indicates whether C++ style comments are recognized and skipped. */ - private boolean slashSlash = false; - - /* Indicates whether C style comments are recognized and skipped. */ - private boolean slashStar = false; - - /* Attribute tables of each byte from 0x00 to 0xFF. */ - private boolean[] whitespace = new boolean[256]; - private boolean[] alphabetic = new boolean[256]; - private boolean[] numeric = new boolean[256]; - private boolean[] quote = new boolean[256]; - private boolean[] comment = new boolean[256]; - - /* The Reader associated with this class. */ - private PushbackReader in; - - /* Indicates if a token has been pushed back. */ - private boolean pushedBack = false; - - /* Contains the current line number of the reader. */ - private int lineNumber = 1; - - /** - * This method reads bytes from an <code>InputStream</code> and tokenizes - * them. For details on how this method operates by default, see - * <code>StreamTokenizer(Reader)</code>. - * - * @param is The <code>InputStream</code> to read from - * - * @deprecated Since JDK 1.1. - */ - public StreamTokenizer(InputStream is) - { - this(new InputStreamReader(is)); - } - - /** - * This method initializes a new <code>StreamTokenizer</code> to read - * characters from a <code>Reader</code> and parse them. The char values - * have their hight bits masked so that the value is treated a character - * in the range of 0x0000 to 0x00FF. - * <p> - * This constructor sets up the parsing table to parse the stream in the - * following manner: - * <ul> - * <li>The values 'A' through 'Z', 'a' through 'z' and 0xA0 through 0xFF - * are initialized as alphabetic</li> - * <li>The values 0x00 through 0x20 are initialized as whitespace</li> - * <li>The values '\'' and '"' are initialized as quote characters</li> - * <li>'/' is a comment character</li> - * <li>Numbers will be parsed</li> - * <li>EOL is not treated as significant</li> - * <li>C and C++ (//) comments are not recognized</li> - * </ul> - * - * @param r The <code>Reader</code> to read chars from - */ - public StreamTokenizer(Reader r) - { - in = new PushbackReader(r); - - whitespaceChars(0x00, 0x20); - wordChars('A', 'Z'); - wordChars('a', 'z'); - wordChars(0xA0, 0xFF); - commentChar('/'); - quoteChar('\''); - quoteChar('"'); - parseNumbers(); - } - - /** - * This method sets the comment attribute on the specified - * character. Other attributes for the character are cleared. - * - * @param ch The character to set the comment attribute for, passed as an int - */ - public void commentChar(int ch) - { - if (ch >= 0 && ch <= 255) - { - comment[ch] = true; - whitespace[ch] = false; - alphabetic[ch] = false; - numeric[ch] = false; - quote[ch] = false; - } - } - - /** - * This method sets a flag that indicates whether or not the end of line - * sequence terminates and is a token. The defaults to <code>false</code> - * - * @param flag <code>true</code> if EOF is significant, <code>false</code> - * otherwise - */ - public void eolIsSignificant(boolean flag) - { - eolSignificant = flag; - } - - /** - * This method returns the current line number. Note that if the - * <code>pushBack()</code> method is called, it has no effect on the - * line number returned by this method. - * - * @return The current line number - */ - public int lineno() - { - return lineNumber; - } - - /** - * This method sets a flag that indicates whether or not alphabetic - * tokens that are returned should be converted to lower case. - * - * @param flag <code>true</code> to convert to lower case, - * <code>false</code> otherwise - */ - public void lowerCaseMode(boolean flag) - { - lowerCase = flag; - } - - private boolean isWhitespace(int ch) - { - return (ch >= 0 && ch <= 255 && whitespace[ch]); - } - - private boolean isAlphabetic(int ch) - { - return ((ch > 255) || (ch >= 0 && alphabetic[ch])); - } - - private boolean isNumeric(int ch) - { - return (ch >= 0 && ch <= 255 && numeric[ch]); - } - - private boolean isQuote(int ch) - { - return (ch >= 0 && ch <= 255 && quote[ch]); - } - - private boolean isComment(int ch) - { - return (ch >= 0 && ch <= 255 && comment[ch]); - } - - /** - * This method reads the next token from the stream. It sets the - * <code>ttype</code> variable to the appropriate token type and - * returns it. It also can set <code>sval</code> or <code>nval</code> - * as described below. The parsing strategy is as follows: - * <ul> - * <li>Skip any whitespace characters.</li> - * <li>If a numeric character is encountered, attempt to parse a numeric - * value. Leading '-' characters indicate a numeric only if followed by - * another non-'-' numeric. The value of the numeric token is terminated - * by either the first non-numeric encountered, or the second occurrence of - * '-' or '.'. The token type returned is TT_NUMBER and <code>nval</code> - * is set to the value parsed.</li> - * <li>If an alphabetic character is parsed, all subsequent characters - * are read until the first non-alphabetic or non-numeric character is - * encountered. The token type returned is TT_WORD and the value parsed - * is stored in <code>sval</code>. If lower case mode is set, the token - * stored in <code>sval</code> is converted to lower case. The end of line - * sequence terminates a word only if EOL signficance has been turned on. - * The start of a comment also terminates a word. Any character with a - * non-alphabetic and non-numeric attribute (such as white space, a quote, - * or a commet) are treated as non-alphabetic and terminate the word.</li> - * <li>If a comment character is parsed, then all remaining characters on - * the current line are skipped and another token is parsed. Any EOL or - * EOF's encountered are not discarded, but rather terminate the comment.</li> - * <li>If a quote character is parsed, then all characters up to the - * second occurrence of the same quote character are parsed into a - * <code>String</code>. This <code>String</code> is stored as - * <code>sval</code>, but is not converted to lower case, even if lower case - * mode is enabled. The token type returned is the value of the quote - * character encountered. Any escape sequences - * (\b (backspace), \t (HTAB), \n (linefeed), \f (form feed), \r - * (carriage return), \" (double quote), \' (single quote), \\ - * (backslash), \XXX (octal esacpe)) are converted to the appropriate - * char values. Invalid esacape sequences are left in untranslated. - * Unicode characters like ('\ u0000') are not recognized. </li> - * <li>If the C++ comment sequence "//" is encountered, and the parser - * is configured to handle that sequence, then the remainder of the line - * is skipped and another token is read exactly as if a character with - * the comment attribute was encountered.</li> - * <li>If the C comment sequence "/*" is encountered, and the parser - * is configured to handle that sequence, then all characters up to and - * including the comment terminator sequence are discarded and another - * token is parsed.</li> - * <li>If all cases above are not met, then the character is an ordinary - * character that is parsed as a token by itself. The char encountered - * is returned as the token type.</li> - * </ul> - * - * @return The token type - * @exception IOException If an I/O error occurs - */ - public int nextToken() throws IOException - { - if (pushedBack) - { - pushedBack = false; - if (ttype != TT_NONE) - return ttype; - } - - sval = null; - int ch; - - // Skip whitespace. Deal with EOL along the way. - while (isWhitespace(ch = in.read())) - if (ch == '\n' || ch == '\r') - { - lineNumber++; - - // Throw away \n if in combination with \r. - if (ch == '\r' && (ch = in.read()) != '\n') - { - if (ch != TT_EOF) - in.unread(ch); - } - if (eolSignificant) - return (ttype = TT_EOL); - } - - if (ch == '/') - if ((ch = in.read()) == '/' && slashSlash) - { - while ((ch = in.read()) != '\n' && ch != '\r' && ch != TT_EOF) - ; - if (ch != TT_EOF) - in.unread(ch); - return nextToken(); // Recursive, but not too deep in normal cases - } - else if (ch == '*' && slashStar) - { - while (true) - { - ch = in.read(); - if (ch == '*') - { - if ((ch = in.read()) == '/') - break; - else if (ch != TT_EOF) - in.unread(ch); - } - else if (ch == '\n' || ch == '\r') - { - lineNumber++; - if (ch == '\r' && (ch = in.read()) != '\n') - { - if (ch != TT_EOF) - in.unread(ch); - } - } - else if (ch == TT_EOF) - { - break; - } - } - return nextToken(); // Recursive, but not too deep in normal cases - } - else - { - if (ch != TT_EOF) - in.unread(ch); - ch = '/'; - } - - if (ch == TT_EOF) - ttype = TT_EOF; - else if (isNumeric(ch)) - { - boolean isNegative = false; - if (ch == '-') - { - // Read ahead to see if this is an ordinary '-' rather than numeric. - ch = in.read(); - if (isNumeric(ch) && ch != '-') - { - isNegative = true; - } - else - { - if (ch != TT_EOF) - in.unread(ch); - return (ttype = '-'); - } - } - - StringBuffer tokbuf = new StringBuffer(); - tokbuf.append((char) ch); - - int decCount = 0; - while (isNumeric(ch = in.read()) && ch != '-') - if (ch == '.' && decCount++ > 0) - break; - else - tokbuf.append((char) ch); - - if (ch != TT_EOF) - in.unread(ch); - ttype = TT_NUMBER; - try - { - nval = Double.valueOf(tokbuf.toString()).doubleValue(); - } - catch (NumberFormatException _) - { - nval = 0.0; - } - if (isNegative) - nval = -nval; - } - else if (isAlphabetic(ch)) - { - StringBuffer tokbuf = new StringBuffer(); - tokbuf.append((char) ch); - while (isAlphabetic(ch = in.read()) || isNumeric(ch)) - tokbuf.append((char) ch); - if (ch != TT_EOF) - in.unread(ch); - ttype = TT_WORD; - sval = tokbuf.toString(); - if (lowerCase) - sval = sval.toLowerCase(); - } - else if (isComment(ch)) - { - while ((ch = in.read()) != '\n' && ch != '\r' && ch != TT_EOF) - ; - if (ch != TT_EOF) - in.unread(ch); - return nextToken(); // Recursive, but not too deep in normal cases. - } - else if (isQuote(ch)) - { - ttype = ch; - StringBuffer tokbuf = new StringBuffer(); - while ((ch = in.read()) != ttype && ch != '\n' && ch != '\r' && - ch != TT_EOF) - { - if (ch == '\\') - switch (ch = in.read()) - { - case 'a': ch = 0x7; - break; - case 'b': ch = '\b'; - break; - case 'f': ch = 0xC; - break; - case 'n': ch = '\n'; - break; - case 'r': ch = '\r'; - break; - case 't': ch = '\t'; - break; - case 'v': ch = 0xB; - break; - case '\n': ch = '\n'; - break; - case '\r': ch = '\r'; - break; - case '\"': - case '\'': - case '\\': - break; - default: - int ch1, nextch; - if ((nextch = ch1 = ch) >= '0' && ch <= '7') - { - ch -= '0'; - if ((nextch = in.read()) >= '0' && nextch <= '7') - { - ch = ch * 8 + nextch - '0'; - if ((nextch = in.read()) >= '0' && nextch <= '7' && - ch1 >= '0' && ch1 <= '3') - { - ch = ch * 8 + nextch - '0'; - nextch = in.read(); - } - } - } - - if (nextch != TT_EOF) - in.unread(nextch); - } - - tokbuf.append((char) ch); - } - - // Throw away matching quote char. - if (ch != ttype && ch != TT_EOF) - in.unread(ch); - - sval = tokbuf.toString(); - } - else - { - ttype = ch; - } - - return ttype; - } - - private void resetChar(int ch) - { - whitespace[ch] = alphabetic[ch] = numeric[ch] = quote[ch] = comment[ch] = - false; - } - - /** - * This method makes the specified character an ordinary character. This - * means that none of the attributes (whitespace, alphabetic, numeric, - * quote, or comment) will be set on this character. This character will - * parse as its own token. - * - * @param ch The character to make ordinary, passed as an int - */ - public void ordinaryChar(int ch) - { - if (ch >= 0 && ch <= 255) - resetChar(ch); - } - - /** - * This method makes all the characters in the specified range, range - * terminators included, ordinary. This means the none of the attributes - * (whitespace, alphabetic, numeric, quote, or comment) will be set on - * any of the characters in the range. This makes each character in this - * range parse as its own token. - * - * @param low The low end of the range of values to set the whitespace - * attribute for - * @param hi The high end of the range of values to set the whitespace - * attribute for - */ - public void ordinaryChars(int low, int hi) - { - if (low < 0) - low = 0; - if (hi > 255) - hi = 255; - for (int i = low; i <= hi; i++) - resetChar(i); - } - - /** - * This method sets the numeric attribute on the characters '0' - '9' and - * the characters '.' and '-'. - */ - public void parseNumbers() - { - for (int i = 0; i <= 9; i++) - numeric['0' + i] = true; - - numeric['.'] = true; - numeric['-'] = true; - } - - /** - * Puts the current token back into the StreamTokenizer so - * <code>nextToken</code> will return the same value on the next call. - * May cause the lineno method to return an incorrect value - * if lineno is called before the next call to nextToken. - */ - public void pushBack() - { - pushedBack = true; - } - - /** - * This method sets the quote attribute on the specified character. - * Other attributes for the character are cleared. - * - * @param ch The character to set the quote attribute for, passed as an int. - */ - public void quoteChar(int ch) - { - if (ch >= 0 && ch <= 255) - { - quote[ch] = true; - comment[ch] = false; - whitespace[ch] = false; - alphabetic[ch] = false; - numeric[ch] = false; - } - } - - /** - * This method removes all attributes (whitespace, alphabetic, numeric, - * quote, and comment) from all characters. It is equivalent to calling - * <code>ordinaryChars(0x00, 0xFF)</code>. - * - * @see #ordinaryChars(int, int) - */ - public void resetSyntax() - { - ordinaryChars(0x00, 0xFF); - } - - /** - * This method sets a flag that indicates whether or not "C++" language style - * comments ("//" comments through EOL ) are handled by the parser. - * If this is <code>true</code> commented out sequences are skipped and - * ignored by the parser. This defaults to <code>false</code>. - * - * @param flag <code>true</code> to recognized and handle "C++" style - * comments, <code>false</code> otherwise - */ - public void slashSlashComments(boolean flag) - { - slashSlash = flag; - } - - /** - * This method sets a flag that indicates whether or not "C" language style - * comments (with nesting not allowed) are handled by the parser. - * If this is <code>true</code> commented out sequences are skipped and - * ignored by the parser. This defaults to <code>false</code>. - * - * @param flag <code>true</code> to recognized and handle "C" style comments, - * <code>false</code> otherwise - */ - public void slashStarComments(boolean flag) - { - slashStar = flag; - } - - /** - * This method returns the current token value as a <code>String</code> in - * the form "Token[x], line n", where 'n' is the current line numbers and - * 'x' is determined as follows. - * <p> - * <ul> - * <li>If no token has been read, then 'x' is "NOTHING" and 'n' is 0</li> - * <li>If <code>ttype</code> is TT_EOF, then 'x' is "EOF"</li> - * <li>If <code>ttype</code> is TT_EOL, then 'x' is "EOL"</li> - * <li>If <code>ttype</code> is TT_WORD, then 'x' is <code>sval</code></li> - * <li>If <code>ttype</code> is TT_NUMBER, then 'x' is "n=strnval" where - * 'strnval' is <code>String.valueOf(nval)</code>.</li> - * <li>If <code>ttype</code> is a quote character, then 'x' is - * <code>sval</code></li> - * <li>For all other cases, 'x' is <code>ttype</code></li> - * </ul> - */ - public String toString() - { - String tempstr; - if (ttype == TT_EOF) - tempstr = "EOF"; - else if (ttype == TT_EOL) - tempstr = "EOL"; - else if (ttype == TT_WORD) - tempstr = sval; - else if (ttype == TT_NUMBER) - tempstr = "n=" + nval; - else if (ttype == TT_NONE) - tempstr = "NOTHING"; - else // must be an ordinary char. - tempstr = "\'" + (char) ttype + "\'"; - - return "Token[" + tempstr + "], line " + lineno(); - } - - /** - * This method sets the whitespace attribute for all characters in the - * specified range, range terminators included. - * - * @param low The low end of the range of values to set the whitespace - * attribute for - * @param hi The high end of the range of values to set the whitespace - * attribute for - */ - public void whitespaceChars(int low, int hi) - { - if (low < 0) - low = 0; - if (hi > 255) - hi = 255; - for (int i = low; i <= hi; i++) - { - resetChar(i); - whitespace[i] = true; - } - } - - /** - * This method sets the alphabetic attribute for all characters in the - * specified range, range terminators included. - * - * @param low The low end of the range of values to set the alphabetic - * attribute for - * @param hi The high end of the range of values to set the alphabetic - * attribute for - */ - public void wordChars(int low, int hi) - { - if (low < 0) - low = 0; - if (hi > 255) - hi = 255; - for (int i = low; i <= hi; i++) - alphabetic[i] = true; - } -} diff --git a/libjava/java/io/StringBufferInputStream.java b/libjava/java/io/StringBufferInputStream.java deleted file mode 100644 index 090881985b8..00000000000 --- a/libjava/java/io/StringBufferInputStream.java +++ /dev/null @@ -1,187 +0,0 @@ -/* StringBufferInputStream.java -- Read an String as a stream - Copyright (C) 1998, 1999, 2001, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.io; - -/* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3 - * "The Java Language Specification", ISBN 0-201-63451-1 - * plus online API docs for JDK 1.2 beta from http://www.javasoft.com. - * Status: Believed complete and correct. Deprecated in JDK 1.1. - */ - -/** - * This class permits a <code>String</code> to be read as an input stream. - * The low eight bits of each character in the <code>String</code> are the - * bytes that are returned. The high eight bits of each character are - * discarded. - * <p> - * The mark/reset functionality in this class behaves differently than - * normal. The <code>mark()</code> method is always ignored and the - * <code>reset()</code> method always resets in stream to start reading from - * position 0 in the String. Note that since this method does not override - * <code>markSupported()</code> in <code>InputStream</code>, calling that - * method will return <code>false</code>. - * <p> - * Note that this class is deprecated because it does not properly handle - * 16-bit Java characters. It is provided for backwards compatibility only - * and should not be used for new development. The <code>StringReader</code> - * class should be used instead. - * - * @deprecated - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Warren Levy (warrenl@cygnus.com) - */ -public class StringBufferInputStream extends InputStream -{ - /** The String which is the input to this stream. */ - protected String buffer; - - /** Position of the next byte in buffer to be read. */ - protected int pos = 0; - - /** The length of the String buffer. */ - protected int count; - - /** - * Create a new <code>StringBufferInputStream</code> that will read bytes - * from the passed in <code>String</code>. This stream will read from the - * beginning to the end of the <code>String</code>. - * - * @param s The <code>String</code> this stream will read from. - */ - public StringBufferInputStream(String s) - { - buffer = s; - count = s.length(); - } - - /** - * This method returns the number of bytes available to be read from this - * stream. The value returned will be equal to <code>count - pos</code>. - * - * @return The number of bytes that can be read from this stream before - * blocking, which is all of them - */ - public int available() - { - return count - pos; - } - - /** - * This method reads one byte from the stream. The <code>pos</code> counter - * is advanced to the next byte to be read. The byte read is returned as - * an int in the range of 0-255. If the stream position is already at the - * end of the buffer, no byte is read and a -1 is returned in order to - * indicate the end of the stream. - * - * @return The byte read, or -1 if end of stream - */ - public int read() - { - if (pos >= count) - return -1; // EOF - - return ((int) buffer.charAt(pos++)) & 0xFF; - } - -/** - * This method reads bytes from the stream and stores them into a caller - * supplied buffer. It starts storing the data at index <code>offset</code> - * into the buffer and attempts to read <code>len</code> bytes. This method - * can return before reading the number of bytes requested if the end of the - * stream is encountered first. The actual number of bytes read is - * returned. If no bytes can be read because the stream is already at - * the end of stream position, a -1 is returned. - * <p> - * This method does not block. - * - * @param b The array into which the bytes read should be stored. - * @param off The offset into the array to start storing bytes - * @param len The requested number of bytes to read - * - * @return The actual number of bytes read, or -1 if end of stream. - */ - public int read(byte[] b, int off, int len) - { - if (off < 0 || len < 0 || off + len > b.length) - throw new ArrayIndexOutOfBoundsException(); - - if (pos >= count) - return -1; // EOF - - int numRead = Math.min(len, count - pos); - if (numRead < 0) - return 0; - - buffer.getBytes(pos, pos + numRead, b, off); - pos += numRead; - return numRead; - } - - /** - * This method sets the read position in the stream to the beginning - * setting the <code>pos</code> variable equal to 0. Note that this differs - * from the common implementation of the <code>reset()</code> method. - */ - public void reset() - { - pos = 0; - } - - /** - * This method attempts to skip the requested number of bytes in the - * input stream. It does this by advancing the <code>pos</code> value by the - * specified number of bytes. It this would exceed the length of the - * buffer, then only enough bytes are skipped to position the stream at - * the end of the buffer. The actual number of bytes skipped is returned. - * - * @param n The requested number of bytes to skip - * - * @return The actual number of bytes skipped. - */ - public long skip(long n) - { - if (n < 0) - return 0L; - - long actualSkip = Math.min(n, count - pos); - pos += actualSkip; - return actualSkip; - } -} diff --git a/libjava/java/io/StringReader.java b/libjava/java/io/StringReader.java deleted file mode 100644 index 7e4e7d84f62..00000000000 --- a/libjava/java/io/StringReader.java +++ /dev/null @@ -1,209 +0,0 @@ -/* StringReader.java -- permits a String to be read as a character input stream - Copyright (C) 1998, 1999, 2000, 2003 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.io; - -/* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3 - * "The Java Language Specification", ISBN 0-201-63451-1 - * plus online API docs for JDK 1.2 beta from http://www.javasoft.com. - * Status: Believed complete and correct - */ - -/** - * This class permits a <code>String</code> to be read as a character - * input stream. - * <p> - * The mark/reset functionality in this class behaves differently than - * normal. If no mark has been set, then calling the <code>reset()</code> - * method rewinds the read pointer to the beginning of the <code>String</code>. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Warren Levy (warrenl@cygnus.com) - * @date October 19, 1998. - */ -public class StringReader extends Reader -{ - /* A String provided by the creator of the stream. */ - private String buf; - - /* Position of the next char in buf to be read. */ - private int pos; - - /* The currently marked position in the stream. */ - private int markedPos; - - /* The index in buf one greater than the last valid character. */ - private int count; - - /** - * Create a new <code>StringReader</code> that will read chars from the - * passed in <code>String</code>. This stream will read from the beginning - * to the end of the <code>String</code>. - * - * @param buffer The <code>String</code> this stream will read from. - */ - public StringReader(String buffer) - { - super(); - buf = buffer; - - count = buffer.length(); - markedPos = pos = 0; - } - - public void close() - { - synchronized (lock) - { - buf = null; - } - } - - public void mark(int readAheadLimit) throws IOException - { - synchronized (lock) - { - if (buf == null) - throw new IOException("Stream closed"); - - // readAheadLimit is ignored per Java Class Lib. book, p. 1692. - markedPos = pos; - } - } - - public boolean markSupported() - { - return true; - } - - public int read() throws IOException - { - synchronized (lock) - { - if (buf == null) - throw new IOException("Stream closed"); - - if (pos < count) - return ((int) buf.charAt(pos++)) & 0xFFFF; - return -1; - } - } - - public int read(char[] b, int off, int len) throws IOException - { - synchronized (lock) - { - if (buf == null) - throw new IOException("Stream closed"); - - /* Don't need to check pos value, arraycopy will check it. */ - if (off < 0 || len < 0 || off + len > b.length) - throw new ArrayIndexOutOfBoundsException(); - - if (pos >= count) - return -1; - - int lastChar = Math.min(count, pos + len); - buf.getChars(pos, lastChar, b, off); - int numChars = lastChar - pos; - pos = lastChar; - return numChars; - } - } - - /** - * This method determines if the stream is ready to be read. This class - * is always ready to read and so always returns <code>true</code>, unless - * close() has previously been called in which case an IOException is - * thrown. - * - * @return <code>true</code> to indicate that this object is ready to be read. - * @exception IOException If the stream is closed. - */ - public boolean ready() throws IOException - { - if (buf == null) - throw new IOException("Stream closed"); - - return true; - } - - /** - * Sets the read position in the stream to the previously - * marked position or to 0 (i.e., the beginning of the stream) if the mark - * has not already been set. - */ - public void reset() throws IOException - { - synchronized (lock) - { - if (buf == null) - throw new IOException("Stream closed"); - - pos = markedPos; - } - } - - /** - * This method attempts to skip the requested number of chars in the - * input stream. It does this by advancing the <code>pos</code> value by - * the specified number of chars. It this would exceed the length of the - * buffer, then only enough chars are skipped to position the stream at - * the end of the buffer. The actual number of chars skipped is returned. - * - * @param n The requested number of chars to skip - * - * @return The actual number of chars skipped. - */ - public long skip(long n) throws IOException - { - synchronized (lock) - { - if (buf == null) - throw new IOException("Stream closed"); - - // Even though the var numChars is a long, in reality it can never - // be larger than an int since the result of subtracting 2 positive - // ints will always fit in an int. Since we have to return a long - // anyway, numChars might as well just be a long. - long numChars = Math.min((long) (count - pos), n < 0 ? 0L : n); - pos += numChars; - return numChars; - } - } -} - diff --git a/libjava/java/io/StringWriter.java b/libjava/java/io/StringWriter.java deleted file mode 100644 index a1e9aeb6bd2..00000000000 --- a/libjava/java/io/StringWriter.java +++ /dev/null @@ -1,191 +0,0 @@ -/* StringWriter.java -- Writes bytes to a StringBuffer - Copyright (C) 1998, 1999, 2000, 2001, 2003, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.io; - -// Wow is this a dumb class. CharArrayWriter can do all this and -// more. I would redirect all calls to one in fact, but the javadocs say -// use a StringBuffer so I will comply. - -/** - * This class writes chars to an internal <code>StringBuffer</code> that - * can then be used to retrieve a <code>String</code>. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Tom Tromey (tromey@cygnus.com) - */ -public class StringWriter extends Writer -{ - /** - * This is the default size of the buffer if the user doesn't specify it. - * @specnote The JCL Volume 1 says that 16 is the default size. - */ - private static final int DEFAULT_BUFFER_SIZE = 16; - - /** - * This method closes the stream. The contents of the internal buffer - * can still be retrieved, but future writes are not guaranteed to work. - * - * @exception IOException If an error orrurs. - */ - public void close () throws IOException - { - // JCL says this does nothing. This seems to violate the Writer - // contract, in that other methods should still throw an - // IOException after a close. Still, we just follow JCL. - } - - /** - * This method flushes any buffered characters to the underlying output. - * It does nothing in this class. - */ - public void flush () - { - } - - /** - * This method returns the <code>StringBuffer</code> object that this - * object is writing to. Note that this is the actual internal buffer, so - * any operations performed on it will affect this stream object. - * - * @return The <code>StringBuffer</code> object being written to - */ - public StringBuffer getBuffer () - { - return buffer; - } - - /** - * This method initializes a new <code>StringWriter</code> to write to a - * <code>StringBuffer</code> initially sized to a default size of 16 - * chars. - */ - public StringWriter () - { - this (DEFAULT_BUFFER_SIZE); - } - - /** - * This method initializes a new <code>StringWriter</code> to write to a - * <code>StringBuffer</code> with the specified initial size. - * - * @param size The initial size to make the <code>StringBuffer</code> - */ - public StringWriter (int size) - { - super (); - buffer = new StringBuffer (size); - lock = buffer; - } - - /** - * This method returns the contents of the internal <code>StringBuffer</code> - * as a <code>String</code>. - * - * @return A <code>String</code> representing the chars written to - * this stream. - */ - public String toString () - { - return buffer.toString(); - } - - /** - * This method writes a single character to the output, storing it in - * the internal buffer. - * - * @param oneChar The <code>char</code> to write, passed as an int. - */ - public void write (int oneChar) - { - buffer.append((char) (oneChar & 0xFFFF)); - } - - /** - * This method writes <code>len</code> chars from the specified - * array starting at index <code>offset</code> in that array to this - * stream by appending the chars to the end of the internal buffer. - * - * @param chars The array of chars to write - * @param offset The index into the array to start writing from - * @param len The number of chars to write - */ - public void write (char[] chars, int offset, int len) - { - buffer.append(chars, offset, len); - } - - /** - * This method writes the characters in the specified <code>String</code> - * to the stream by appending them to the end of the internal buffer. - * - * @param str The <code>String</code> to write to the stream. - */ - public void write (String str) - { - buffer.append(str); - } - - /** - * This method writes out <code>len</code> characters of the specified - * <code>String</code> to the stream starting at character position - * <code>offset</code> into the stream. This is done by appending the - * characters to the internal buffer. - * - * @param str The <code>String</code> to write characters from - * @param offset The character position to start writing from - * @param len The number of characters to write. - */ - public void write (String str, int offset, int len) - { -// char[] tmpbuf = new char[len]; -// str.getChars(offset, offset+len, tmpbuf, 0); -// buf.append(tmpbuf, 0, tmpbuf.length); - // This implementation assumes that String.substring is more - // efficient than using String.getChars and copying the data - // twice. For libgcj, this is true. For Classpath, it is not. - // FIXME. - buffer.append(str.substring(offset, offset + len)); - } - - /** - * This is the <code>StringBuffer</code> that we use to store bytes that - * are written. - */ - private StringBuffer buffer; -} diff --git a/libjava/java/io/SyncFailedException.java b/libjava/java/io/SyncFailedException.java deleted file mode 100644 index c514c44f23f..00000000000 --- a/libjava/java/io/SyncFailedException.java +++ /dev/null @@ -1,66 +0,0 @@ -/* SyncFailedException.java -- a file sync failed - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.io; - -/** - * Thrown when a file synchronization fails. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Tom Tromey (tromey@cygnus.com) - * @see FileDescriptor#sync() - * @since 1.1 - * @status updated to 1.4 - */ -public class SyncFailedException extends IOException -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = -2353342684412443330L; - - /** - * Create an exception with a descriptive error message. - * - * @param message the descriptive error message - */ - public SyncFailedException(String message) - { - super(message); - } -} // class SyncFailedException diff --git a/libjava/java/io/UTFDataFormatException.java b/libjava/java/io/UTFDataFormatException.java deleted file mode 100644 index 6bb76aebdfe..00000000000 --- a/libjava/java/io/UTFDataFormatException.java +++ /dev/null @@ -1,74 +0,0 @@ -/* UTFDataFormatException.java -- thrown on bad format in UTF data - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.io; - -/** - * When reading a UTF string from an input stream, this exception is thrown - * to indicate that the data read is invalid. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Tom Tromey (tromey@cygnus.com) - * @see DataInput - * @see DataInputStream#readUTF(DataInput) - * @status updated to 1.4 - */ -public class UTFDataFormatException extends IOException -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = 420743449228280612L; - - /** - * Create a new UTFDataFormatException without a descriptive error message. - */ - public UTFDataFormatException() - { - } - - /** - * Create a new UTFDataFormatException with a descriptive error message. - * - * @param message the descriptive error message - */ - public UTFDataFormatException(String message) - { - super(message); - } -} // class UTFDataFormatException diff --git a/libjava/java/io/UnsupportedEncodingException.java b/libjava/java/io/UnsupportedEncodingException.java deleted file mode 100644 index cf0ab64cb89..00000000000 --- a/libjava/java/io/UnsupportedEncodingException.java +++ /dev/null @@ -1,73 +0,0 @@ -/* UnsupportedEncodingException.java -- the requested encoding isn't supported - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.io; - -/** - * This exception is thrown when the requested character encoding is - * not supported. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Per Bothner (bothner@cygnus.com) - * @since 1.1 - * @status updated to 1.4 - */ -public class UnsupportedEncodingException extends IOException -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = -4274276298326136670L; - - /** - * Create an exception without a descriptive error message. - */ - public UnsupportedEncodingException() - { - } - - /** - * Create an exception with a descriptive error message. - * - * @param message the descriptive error message - */ - public UnsupportedEncodingException(String message) - { - super(message); - } -} // class UnsupportedEncodingException diff --git a/libjava/java/io/WriteAbortedException.java b/libjava/java/io/WriteAbortedException.java deleted file mode 100644 index f051dc975c8..00000000000 --- a/libjava/java/io/WriteAbortedException.java +++ /dev/null @@ -1,109 +0,0 @@ -/* WriteAbortedException.java -- wraps an exception thrown while writing - Copyright (C) 1998, 2000, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.io; - -/** - * This exception is thrown when another ObjectStreamException occurs during - * a serialization read or write. The stream is reset, and deserialized - * objects are discarded. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.1 - * @status updated to 1.4 - */ -public class WriteAbortedException extends ObjectStreamException -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = -3326426625597282442L; - - /** - * The cause of this exception. This pre-dates the exception chaining - * of Throwable; and although you can change this field, you are wiser - * to leave it alone. - * - * @serial the exception cause - */ - public Exception detail; - - /** - * Create a new WriteAbortedException with a specified message and - * cause. - * - * @param msg the message - * @param detail the cause - */ - public WriteAbortedException(String msg, Exception detail) - { - super(msg); - initCause(detail); - this.detail = detail; - } - - /** - * This method returns a message indicating what went wrong, in this - * format: - * <code>super.getMessage() + (detail == null ? "" : "; " + detail)</code>. - * - * @return the chained message - */ - public String getMessage() - { - if (detail == this || detail == null) - return super.getMessage(); - return super.getMessage() + "; " + detail; - } - - /** - * Returns the cause of this exception. Note that this may not be the - * original cause, thanks to the <code>detail</code> field being public - * and non-final (yuck). However, to avoid violating the contract of - * Throwable.getCause(), this returns null if <code>detail == this</code>, - * as no exception can be its own cause. - * - * @return the cause - * @since 1.4 - */ - public Throwable getCause() - { - return detail == this ? null : detail; - } -} // class WriteAbortedException diff --git a/libjava/java/io/Writer.java b/libjava/java/io/Writer.java deleted file mode 100644 index f153e31cfed..00000000000 --- a/libjava/java/io/Writer.java +++ /dev/null @@ -1,192 +0,0 @@ -/* Writer.java -- Base class for character output streams - Copyright (C) 1998, 1999, 2001, 2003, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.io; - -/* Written using "Java Class Libraries", 2nd edition, plus online - * API docs for JDK 1.2 beta from http://www.javasoft.com. - * Status: Believed complete and correct. - */ - -/** - * This abstract class forms the base of the hierarchy of classes that - * write output as a stream of chars. It provides a common set of methods - * for writing chars to stream. Subclasses implement and/or extend these - * methods to write chars in a particular manner or to a particular - * destination such as a file on disk or network connection. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Per Bothner (bothner@cygnus.com) - */ -public abstract class Writer -{ - /** - * This is the object used to synchronize criticial code sections for - * thread safety. Subclasses should use this field instead of using - * synchronized methods or explicity synchronizations on <code>this</code> - */ - protected Object lock; - - /** - * This is the default no-argument constructor for this class. This method - * will set up the class to synchronize criticial sections on itself. - */ - protected Writer() - { - lock = this; - } - - /** - * This method initializes a <code>Writer</code> that will synchronize - * on the specified <code>Object</code>. - * - * @param lock The <code>Object</code> to use for synchronizing critical - * sections. Must not be null. - */ - protected Writer(Object lock) - { - if (lock == null) - throw new NullPointerException(); - - this.lock = lock; - } - - /** - * This method forces any data that may have been buffered to be written - * to the underlying output device. Please note that the host environment - * might perform its own buffering unbeknowst to Java. In that case, a - * write made (for example, to a disk drive) might be cached in OS - * buffers instead of actually being written to disk. - * - * @exception IOException If an error occurs - */ - public abstract void flush() throws IOException; - - /** - * This method closes the stream. Any internal or native resources - * associated - * with this stream are freed. Any subsequent attempt to access the stream - * might throw an exception. - * <p> - * This method in this class does nothing. - * - * @exception IOException If an error occurs - */ - public abstract void close() throws IOException; - - /** - * This method writes a single char to the output stream. - * - * @param b The char to be written to the output stream, passed as an int - * - * @exception IOException If an error occurs - */ - public void write(int b) throws IOException - { - char[] buf = new char[1]; - - buf[0] = (char)b; - write(buf, 0, buf.length); - } - - /** - * This method all the writes char from the passed array to the output - * stream. This method is equivalent to - * <code>write(buf, 0, buf.length)</code> which - * is exactly how it is implemented in this class. - * - * @param buf The array of char to write - * - * @exception IOException If an error occurs - */ - public void write(char[] buf) throws IOException - { - write(buf, 0, buf.length); - } - - /** - * This method writes <code>len</code> char from the specified array - * <code>buf</code> starting at index <code>offset</code> into the array. - * <p> - * Subclasses must provide an implementation of this abstract method. - * - * @param buf The array of char to write from - * @param offset The index into the array to start writing from - * @param len The number of char to write - * - * @exception IOException If an error occurs - */ - public abstract void write(char[] buf, int offset, int len) - throws IOException; - - /** - * This method writes all the characters in a <code>String</code> to the - * output. - * - * @param str The <code>String</code> whose chars are to be written. - * - * @exception IOException If an error occurs - */ - public void write(String str) throws IOException - { - write(str, 0, str.length()); - } - - /** - * This method writes <code>len</code> chars from the <code>String</code> - * starting at position <code>offset</code>. - * - * @param str The <code>String</code> that is to be written - * @param offset The character offset into the <code>String</code> to start - * writing from - * @param len The number of chars to write - * - * @exception IOException If an error occurs - */ - public void write(String str, int offset, int len) throws IOException - { - // FIXME - for libgcj re-write using native code to not require - // copied buffer. - char[] buf = new char[len]; - - str.getChars(offset, offset + len, buf, 0); - write(buf, 0, len); - } - -} // class Writer - diff --git a/libjava/java/lang/AbstractMethodError.java b/libjava/java/lang/AbstractMethodError.java deleted file mode 100644 index b9eb622ee8e..00000000000 --- a/libjava/java/lang/AbstractMethodError.java +++ /dev/null @@ -1,75 +0,0 @@ -/* AbstractMethodError.java -- thrown if an abstract method is invoked - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang; - -/** - * An <code>AbstractMethodError</code> is thrown when an application attempts - * to access an abstract method. Compilers typically detect this error, but - * it can be thrown at run time if the definition of a class has changed - * since the application was last compiled. This can also occur when - * reflecting on methods. - * - * @author Brian Jones - * @author Tom Tromey (tromey@cygnus.com) - * @status updated to 1.4 - */ -public class AbstractMethodError extends IncompatibleClassChangeError -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = -1654391082989018462L; - - /** - * Create an error without a message. - */ - public AbstractMethodError() - { - } - - /** - * Create an error with a message. - * - * @param s the message - */ - public AbstractMethodError(String s) - { - super(s); - } -} diff --git a/libjava/java/lang/ArithmeticException.java b/libjava/java/lang/ArithmeticException.java deleted file mode 100644 index 5acea43533b..00000000000 --- a/libjava/java/lang/ArithmeticException.java +++ /dev/null @@ -1,77 +0,0 @@ -/* ArithmeticException.java -- exception thrown to indicate conditions - like divide by zero. - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang; - -/** - * Thrown when a math error has occured, such as trying to divide an - * integer by zero. For example:<br> - * <pre> - * int i = 0; - * int j = 2 / i; - * </pre> - * - * @author Brian Jones - * @author Warren Levy (warrenl@cygnus.com) - * @status updated to 1.4 - */ -public class ArithmeticException extends RuntimeException -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = 2256477558314496007L; - - /** - * Create an exception without a message. - */ - public ArithmeticException() - { - } - - /** - * Create an exception with a message. - * - * @param s the message - */ - public ArithmeticException(String s) - { - super(s); - } -} diff --git a/libjava/java/lang/ArrayIndexOutOfBoundsException.java b/libjava/java/lang/ArrayIndexOutOfBoundsException.java deleted file mode 100644 index 371623bdaaa..00000000000 --- a/libjava/java/lang/ArrayIndexOutOfBoundsException.java +++ /dev/null @@ -1,87 +0,0 @@ -/* ArrayIndexOutOfBoundsException.java -- exception thrown when accessing - an illegal index. - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang; - -/** - * Thrown when attempting to access a position outside the valid range of - * an array. For example:<br> - * <pre> - * int[] i = { 1 }; - * i[1] = 2; - * </pre> - * - * @author Brian Jones - * @author Warren Levy (warrenl@cygnus.com) - * @status updated to 1.4 - */ -public class ArrayIndexOutOfBoundsException extends IndexOutOfBoundsException -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = -5116101128118950844L; - - /** - * Create an exception without a message. - */ - public ArrayIndexOutOfBoundsException() - { - } - - /** - * Create an exception with a message. - * - * @param s the message - */ - public ArrayIndexOutOfBoundsException(String s) - { - super(s); - } - - /** - * Create an exception indicating the illegal index. - * - * @param index the invalid index - */ - public ArrayIndexOutOfBoundsException(int index) - { - super("Array index out of range: " + index); - } -} diff --git a/libjava/java/lang/ArrayStoreException.java b/libjava/java/lang/ArrayStoreException.java deleted file mode 100644 index 042e78c5515..00000000000 --- a/libjava/java/lang/ArrayStoreException.java +++ /dev/null @@ -1,77 +0,0 @@ -/* ArrayStoreException.java -- exception thrown to when trying to store an - object into an array of a different type. - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang; - -/** - * Thrown when trying to store an object of the wrong runtime type in an - * array. For example:<br> - * <pre> - * Object[] o = new Integer[1]; - * o[0] = "oops"; - * </pre> - * - * @author Brian Jones - * @author Warren Levy (warrenl@cygnus.com) - * @status updated to 1.4 - */ -public class ArrayStoreException extends RuntimeException -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = -4522193890499838241L; - - /** - * Create an exception without a message. - */ - public ArrayStoreException() - { - } - - /** - * Create an exception with a message. - * - * @param s the message - */ - public ArrayStoreException(String s) - { - super(s); - } -} diff --git a/libjava/java/lang/AssertionError.java b/libjava/java/lang/AssertionError.java deleted file mode 100644 index 778eb583051..00000000000 --- a/libjava/java/lang/AssertionError.java +++ /dev/null @@ -1,148 +0,0 @@ -/* AssertionError.java -- indication of a failed assertion - Copyright (C) 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang; - -/** - * An assertion error normally occurs as a result of the <code>assert</code> - * statement added in JDK 1.4, to indicate that an assertion failed. There - * are enough constructors to ensure that - * <code>new AssertionError(<em>expression</em>)</code> will work for all - * expressions, regardless of type, as if the error message were given by - * the string <code>"" + <em>expression</em></code>. This extends Error, - * because you usually do not want to inadvertently trap an assertion failure. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.4 - * @status updated to 1.4 - */ -public class AssertionError extends Error -{ - /** - * Compatible with JDK 1.4+. - */ - private static final long serialVersionUID = -5013299493970297370L; - - /** - * Construct an AssertionError with no detail message. - */ - public AssertionError() - { - } - - /** - * Construct an AssertionError with the string conversion of the given - * object as its error message. If the object is a Throwable, it is also - * set as the cause of this error. - * - * @param msg the source of the error message - * @see Throwable#getCause() - */ - public AssertionError(Object msg) - { - super("" + msg); - if (msg instanceof Throwable) - initCause((Throwable) msg); - } - - /** - * Construct an AssertionError with the string conversion of the given - * boolean as its error message. - * - * @param msg the source of the error message - */ - public AssertionError(boolean msg) - { - super(msg ? "true" : "false"); - } - - /** - * Construct an AssertionError with the string conversion of the given - * char as its error message. - * - * @param msg the source of the error message - */ - public AssertionError(char msg) - { - super(String.valueOf(msg)); - } - - /** - * Construct an AssertionError with the string conversion of the given - * int as its error message. - * - * @param msg the source of the error message - */ - public AssertionError(int msg) - { - super(Integer.toString(msg, 10)); - } - - /** - * Construct an AssertionError with the string conversion of the given - * long as its error message. - * - * @param msg the source of the error message - */ - public AssertionError(long msg) - { - super(Long.toString(msg)); - } - - /** - * Construct an AssertionError with the string conversion of the given - * float as its error message. - * - * @param msg the source of the error message - */ - public AssertionError(float msg) - { - super(Float.toString(msg)); - } - - /** - * Construct an AssertionError with the string conversion of the given - * double as its error message. - * - * @param msg the source of the error message - */ - public AssertionError(double msg) - { - super(Double.toString(msg)); - } -} diff --git a/libjava/java/lang/Boolean.java b/libjava/java/lang/Boolean.java deleted file mode 100644 index b6910280e6b..00000000000 --- a/libjava/java/lang/Boolean.java +++ /dev/null @@ -1,224 +0,0 @@ -/* Boolean.java -- object wrapper for boolean - Copyright (C) 1998, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang; - -import java.io.Serializable; - -/** - * Instances of class <code>Boolean</code> represent primitive - * <code>boolean</code> values. - * - * @author Paul Fisher - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.0 - * @status updated to 1.4 - */ -public final class Boolean implements Serializable -{ - /** - * Compatible with JDK 1.0.2+. - */ - private static final long serialVersionUID = -3665804199014368530L; - - /** - * This field is a <code>Boolean</code> object representing the - * primitive value <code>true</code>. This instance is returned - * by the static <code>valueOf()</code> methods if they return - * a <code>Boolean</code> representing <code>true</code>. - */ - public static final Boolean TRUE = new Boolean(true); - - /** - * This field is a <code>Boolean</code> object representing the - * primitive value <code>false</code>. This instance is returned - * by the static <code>valueOf()</code> methods if they return - * a <code>Boolean</code> representing <code>false</code>. - */ - public static final Boolean FALSE = new Boolean(false); - - /** - * The primitive type <code>boolean</code> is represented by this - * <code>Class</code> object. - * - * @since 1.1 - */ - public static final Class TYPE = VMClassLoader.getPrimitiveClass('Z'); - - /** - * The immutable value of this Boolean. - * @serial the wrapped value - */ - private final boolean value; - - /** - * Create a <code>Boolean</code> object representing the value of the - * argument <code>value</code>. In general the use of the static - * method <code>valueof(boolean)</code> is more efficient since it will - * not create a new object. - * - * @param value the primitive value of this <code>Boolean</code> - * @see #valueOf(boolean) - */ - public Boolean(boolean value) - { - this.value = value; - } - - /** - * Creates a <code>Boolean</code> object representing the primitive - * <code>true</code> if and only if <code>s</code> matches - * the string "true" ignoring case, otherwise the object will represent - * the primitive <code>false</code>. In general the use of the static - * method <code>valueof(String)</code> is more efficient since it will - * not create a new object. - * - * @param s the <code>String</code> representation of <code>true</code> - * or false - */ - public Boolean(String s) - { - value = "true".equalsIgnoreCase(s); - } - - /** - * Return the primitive <code>boolean</code> value of this - * <code>Boolean</code> object. - * - * @return true or false, depending on the value of this Boolean - */ - public boolean booleanValue() - { - return value; - } - - /** - * Returns the Boolean <code>TRUE</code> if the given boolean is - * <code>true</code>, otherwise it will return the Boolean - * <code>FALSE</code>. - * - * @param b the boolean to wrap - * @return the wrapper object - * @see #TRUE - * @see #FALSE - * @since 1.4 - */ - public static Boolean valueOf(boolean b) - { - return b ? TRUE : FALSE; - } - - /** - * Returns the Boolean <code>TRUE</code> if and only if the given - * String is equal, ignoring case, to the the String "true", otherwise - * it will return the Boolean <code>FALSE</code>. - * - * @param s the string to convert - * @return a wrapped boolean from the string - */ - public static Boolean valueOf(String s) - { - return "true".equalsIgnoreCase(s) ? TRUE : FALSE; - } - - /** - * Returns "true" if the value of the give boolean is <code>true</code> and - * returns "false" if the value of the given boolean is <code>false</code>. - * - * @param b the boolean to convert - * @return the string representation of the boolean - * @since 1.4 - */ - public static String toString(boolean b) - { - return b ? "true" : "false"; - } - - /** - * Returns "true" if the value of this object is <code>true</code> and - * returns "false" if the value of this object is <code>false</code>. - * - * @return the string representation of this - */ - public String toString() - { - return value ? "true" : "false"; - } - - /** - * Returns the integer <code>1231</code> if this object represents - * the primitive <code>true</code> and the integer <code>1237</code> - * otherwise. - * - * @return the hash code - */ - public int hashCode() - { - return value ? 1231 : 1237; - } - - /** - * If the <code>obj</code> is an instance of <code>Boolean</code> and - * has the same primitive value as this object then <code>true</code> - * is returned. In all other cases, including if the <code>obj</code> - * is <code>null</code>, <code>false</code> is returned. - * - * @param obj possibly an instance of any <code>Class</code> - * @return true if <code>obj</code> equals this - */ - public boolean equals(Object obj) - { - return obj instanceof Boolean && value == ((Boolean) obj).value; - } - - /** - * If the value of the system property <code>name</code> matches - * "true" ignoring case then the function returns <code>true</code>. - * - * @param name the property name to look up - * @return true if the property resulted in "true" - * @throws SecurityException if accessing the system property is forbidden - * @see System#getProperty(String) - */ - public static boolean getBoolean(String name) - { - if (name == null || "".equals(name)) - return false; - return "true".equalsIgnoreCase(System.getProperty(name)); - } -} diff --git a/libjava/java/lang/Byte.java b/libjava/java/lang/Byte.java deleted file mode 100644 index 338e2167aa1..00000000000 --- a/libjava/java/lang/Byte.java +++ /dev/null @@ -1,357 +0,0 @@ -/* Byte.java -- object wrapper for byte - Copyright (C) 1998, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang; - -/** - * Instances of class <code>Byte</code> represent primitive <code>byte</code> - * values. - * - * Additionally, this class provides various helper functions and variables - * useful to bytes. - * - * @author Paul Fisher - * @author John Keiser - * @author Per Bothner - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.1 - * @status updated to 1.4 - */ -public final class Byte extends Number implements Comparable -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = -7183698231559129828L; - - /** - * The minimum value a <code>byte</code> can represent is -128 (or - * -2<sup>7</sup>). - */ - public static final byte MIN_VALUE = -128; - - /** - * The maximum value a <code>byte</code> can represent is 127 (or - * 2<sup>7</sup> - 1). - */ - public static final byte MAX_VALUE = 127; - - /** - * The primitive type <code>byte</code> is represented by this - * <code>Class</code> object. - */ - public static final Class TYPE = VMClassLoader.getPrimitiveClass('B'); - - /** - * The immutable value of this Byte. - * - * @serial the wrapped byte - */ - private final byte value; - - /** - * Create a <code>Byte</code> object representing the value of the - * <code>byte</code> argument. - * - * @param value the value to use - */ - public Byte(byte value) - { - this.value = value; - } - - /** - * Create a <code>Byte</code> object representing the value specified - * by the <code>String</code> argument - * - * @param s the string to convert - * @throws NumberFormatException if the String does not contain a byte - * @see #valueOf(String) - */ - public Byte(String s) - { - value = parseByte(s, 10); - } - - /** - * Converts the <code>byte</code> to a <code>String</code> and assumes - * a radix of 10. - * - * @param b the <code>byte</code> to convert to <code>String</code> - * @return the <code>String</code> representation of the argument - */ - public static String toString(byte b) - { - return String.valueOf(b); - } - - /** - * Converts the specified <code>String</code> into a <code>byte</code>. - * This function assumes a radix of 10. - * - * @param s the <code>String</code> to convert - * @return the <code>byte</code> value of <code>s</code> - * @throws NumberFormatException if <code>s</code> cannot be parsed as a - * <code>byte</code> - * @see #parseByte(String) - */ - public static byte parseByte(String s) - { - return parseByte(s, 10); - } - - /** - * Converts the specified <code>String</code> into an <code>int</code> - * using the specified radix (base). The string must not be <code>null</code> - * or empty. It may begin with an optional '-', which will negate the answer, - * provided that there are also valid digits. Each digit is parsed as if by - * <code>Character.digit(d, radix)</code>, and must be in the range - * <code>0</code> to <code>radix - 1</code>. Finally, the result must be - * within <code>MIN_VALUE</code> to <code>MAX_VALUE</code>, inclusive. - * Unlike Double.parseDouble, you may not have a leading '+'. - * - * @param s the <code>String</code> to convert - * @param radix the radix (base) to use in the conversion - * @return the <code>String</code> argument converted to <code>byte</code> - * @throws NumberFormatException if <code>s</code> cannot be parsed as a - * <code>byte</code> - */ - public static byte parseByte(String s, int radix) - { - int i = Integer.parseInt(s, radix, false); - if ((byte) i != i) - throw new NumberFormatException(); - return (byte) i; - } - - /** - * Creates a new <code>Byte</code> object using the <code>String</code> - * and specified radix (base). - * - * @param s the <code>String</code> to convert - * @param radix the radix (base) to convert with - * @return the new <code>Byte</code> - * @throws NumberFormatException if <code>s</code> cannot be parsed as a - * <code>byte</code> - * @see #parseByte(String, int) - */ - public static Byte valueOf(String s, int radix) - { - return new Byte(parseByte(s, radix)); - } - - /** - * Creates a new <code>Byte</code> object using the <code>String</code>, - * assuming a radix of 10. - * - * @param s the <code>String</code> to convert - * @return the new <code>Byte</code> - * @throws NumberFormatException if <code>s</code> cannot be parsed as a - * <code>byte</code> - * @see #Byte(String) - * @see #parseByte(String) - */ - public static Byte valueOf(String s) - { - return new Byte(parseByte(s, 10)); - } - - /** - * Convert the specified <code>String</code> into a <code>Byte</code>. - * The <code>String</code> may represent decimal, hexadecimal, or - * octal numbers. - * - * <p>The extended BNF grammar is as follows:<br> - * <pre> - * <em>DecodableString</em>: - * ( [ <code>-</code> ] <em>DecimalNumber</em> ) - * | ( [ <code>-</code> ] ( <code>0x</code> | <code>0X</code> - * | <code>#</code> ) { <em>HexDigit</em> }+ ) - * | ( [ <code>-</code> ] <code>0</code> { <em>OctalDigit</em> } ) - * <em>DecimalNumber</em>: - * <em>DecimalDigit except '0'</em> { <em>DecimalDigit</em> } - * <em>DecimalDigit</em>: - * <em>Character.digit(d, 10) has value 0 to 9</em> - * <em>OctalDigit</em>: - * <em>Character.digit(d, 8) has value 0 to 7</em> - * <em>DecimalDigit</em>: - * <em>Character.digit(d, 16) has value 0 to 15</em> - * </pre> - * Finally, the value must be in the range <code>MIN_VALUE</code> to - * <code>MAX_VALUE</code>, or an exception is thrown. - * - * @param s the <code>String</code> to interpret - * @return the value of the String as a <code>Byte</code> - * @throws NumberFormatException if <code>s</code> cannot be parsed as a - * <code>byte</code> - * @throws NullPointerException if <code>s</code> is null - * @see Integer#decode(String) - */ - public static Byte decode(String s) - { - int i = Integer.parseInt(s, 10, true); - if ((byte) i != i) - throw new NumberFormatException(); - return new Byte((byte) i); - } - - /** - * Return the value of this <code>Byte</code>. - * - * @return the byte value - */ - public byte byteValue() - { - return value; - } - - /** - * Return the value of this <code>Byte</code> as a <code>short</code>. - * - * @return the short value - */ - public short shortValue() - { - return value; - } - - /** - * Return the value of this <code>Byte</code> as an <code>int</code>. - * - * @return the int value - */ - public int intValue() - { - return value; - } - - /** - * Return the value of this <code>Byte</code> as a <code>long</code>. - * - * @return the long value - */ - public long longValue() - { - return value; - } - - /** - * Return the value of this <code>Byte</code> as a <code>float</code>. - * - * @return the float value - */ - public float floatValue() - { - return value; - } - - /** - * Return the value of this <code>Byte</code> as a <code>double</code>. - * - * @return the double value - */ - public double doubleValue() - { - return value; - } - - /** - * Converts the <code>Byte</code> value to a <code>String</code> and - * assumes a radix of 10. - * - * @return the <code>String</code> representation of this <code>Byte</code> - * @see Integer#toString() - */ - public String toString() - { - return String.valueOf(value); - } - - /** - * Return a hashcode representing this Object. <code>Byte</code>'s hash - * code is simply its value. - * - * @return this Object's hash code - */ - public int hashCode() - { - return value; - } - - /** - * Returns <code>true</code> if <code>obj</code> is an instance of - * <code>Byte</code> and represents the same byte value. - * - * @param obj the object to compare - * @return whether these Objects are semantically equal - */ - public boolean equals(Object obj) - { - return obj instanceof Byte && value == ((Byte) obj).value; - } - - /** - * Compare two Bytes numerically by comparing their <code>byte</code> values. - * The result is positive if the first is greater, negative if the second - * is greater, and 0 if the two are equal. - * - * @param b the Byte to compare - * @return the comparison - * @since 1.2 - */ - public int compareTo(Byte b) - { - return value - b.value; - } - - /** - * Behaves like <code>compareTo(Byte)</code> unless the Object - * is not a <code>Byte</code>. - * - * @param o the object to compare - * @return the comparison - * @throws ClassCastException if the argument is not a <code>Byte</code> - * @see #compareTo(Byte) - * @see Comparable - * @since 1.2 - */ - public int compareTo(Object o) - { - return compareTo((Byte) o); - } -} diff --git a/libjava/java/lang/CharSequence.java b/libjava/java/lang/CharSequence.java deleted file mode 100644 index 5c014e173a8..00000000000 --- a/libjava/java/lang/CharSequence.java +++ /dev/null @@ -1,99 +0,0 @@ -/* CharSequence.java -- Anything that has an indexed sequence of chars - Copyright (C) 2001, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang; - -/** - * General functions on a sequence of chars. This interface is implemented - * by <code>String</code>, <code>StringBuffer</code> and - * <code>CharBuffer</code> to give a uniform way to get chars at a certain - * index, the number of characters in the sequence and a subrange of the - * chars. Indexes start at 0 and the last index is <code>length()-1</code>. - * - * <p>Even when classes implement this interface they are not always - * exchangeble because they might implement their compare, equals or hash - * function differently. This means that in general one should not use a - * <code>CharSequence</code> as keys in collections since two sequences - * with the same chars at the same indexes with the same length might not - * have the same hash code, be equal or be comparable since the are - * represented by different classes. - * - * @author Mark Wielaard (mark@klomp.org) - * @since 1.4 - * @status updated to 1.4 - */ -public interface CharSequence -{ - /** - * Returns the character at the given index. - * - * @param i the index to retrieve from - * @return the character at that location - * @throws IndexOutOfBoundsException if i < 0 || i >= length() - 1 - */ - char charAt(int i); - - /** - * Returns the length of the sequence. This is the number of 16-bit - * characters in the sequence, which may differ from the length of the - * underlying encoding. - * - * @return the sequence length - */ - int length(); - - /** - * Returns a new <code>CharSequence</code> of the indicated range. - * - * @param begin the start index (inclusive) - * @param end the end index (exclusive) - * @return a subsequence of this - * @throws IndexOutOfBoundsException if begin > end || begin < 0 || - * end > length() - */ - CharSequence subSequence(int begin, int end); - - /** - * Returns the complete <code>CharSequence</code> as a <code>String</code>. - * Classes that implement this interface should return a <code>String</code> - * which contains only the characters in the sequence in the correct order. - * - * @return the character sequence as a String - */ - String toString(); -} diff --git a/libjava/java/lang/ClassCastException.java b/libjava/java/lang/ClassCastException.java deleted file mode 100644 index c490f42aaa8..00000000000 --- a/libjava/java/lang/ClassCastException.java +++ /dev/null @@ -1,76 +0,0 @@ -/* ClassCastException.java -- exception thrown on bad cast - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang; - -/** - * Thrown when an attempt is made to cast an object which is not of the - * appropriate runtime type. For example:<br> - * <pre> - * Object o = new Vector(); - * String s = (String) o; - * </pre> - * - * @author Brian Jones - * @author Warren Levy (warrenl@cygnus.com) - * @status updated to 1.4 - */ -public class ClassCastException extends RuntimeException -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = -9223365651070458532L; - - /** - * Create an exception without a message. - */ - public ClassCastException() - { - } - - /** - * Create an exception with a message. - * - * @param s the message - */ - public ClassCastException(String s) - { - super(s); - } -} diff --git a/libjava/java/lang/ClassCircularityError.java b/libjava/java/lang/ClassCircularityError.java deleted file mode 100644 index ecdfb7aaf3a..00000000000 --- a/libjava/java/lang/ClassCircularityError.java +++ /dev/null @@ -1,73 +0,0 @@ -/* ClassCircularityError.java -- thrown when linking circular classes - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang; - -/** - * A <code>ClassCircularityError</code> is thrown when a circular dependency - * has been detected while initializing a class. This signals binary - * incompatible versions of class files, as the compiler normally catches this. - * - * @author Brian Jones - * @author Tom Tromey (tromey@cygnus.com) - * @status updated to 1.4 - */ -public class ClassCircularityError extends LinkageError -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = 1054362542914539689L; - - /** - * Create an error without a message. - */ - public ClassCircularityError() - { - } - - /** - * Create an error with a message. - * - * @param s the message - */ - public ClassCircularityError(String s) - { - super(s); - } -} diff --git a/libjava/java/lang/ClassFormatError.java b/libjava/java/lang/ClassFormatError.java deleted file mode 100644 index 7f90f5cd83e..00000000000 --- a/libjava/java/lang/ClassFormatError.java +++ /dev/null @@ -1,72 +0,0 @@ -/* ClassFormatError.java -- thrown if a class file is invalid - Copyright (C) 1998, 1999, 2001, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang; - -/** - * A <code>ClassFormatError</code> is thrown when a Java Virtual Machine - * unable to read a class file because the file is corrupted or cannot be - * interpreted as a class file. - * - * @author Brian Jones - * @status updated to 1.4 - */ -public class ClassFormatError extends LinkageError -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = -8420114879011949195L; - - /** - * Create an error without a message. - */ - public ClassFormatError() - { - } - - /** - * Create an error with a message. - * - * @param s the message - */ - public ClassFormatError(String s) - { - super(s); - } -} diff --git a/libjava/java/lang/ClassNotFoundException.java b/libjava/java/lang/ClassNotFoundException.java deleted file mode 100644 index 6b6ae949dd2..00000000000 --- a/libjava/java/lang/ClassNotFoundException.java +++ /dev/null @@ -1,125 +0,0 @@ -/* ClassNotFoundException.java -- thrown when class definition cannot be found - Copyright (C) 1998, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang; - -/** - * Thrown when a class is requested by reflection, but the class definition - * cannot be found. This exception is often chained from another Throwable. - * - * @author Brian Jones - * @author Eric Blake (ebb9@email.byu.edu) - * @see Class#forName(String) - * @see ClassLoader#findSystemClass(String) - * @see ClassLoader#loadClass(String, boolean) - * @status updated to 1.4 - */ -public class ClassNotFoundException extends Exception -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = 9176873029745254542L; - - /** - * The cause of this exception (duplicates the one stored in Throwable). - * - * @serial the exception cause - * @since 1.2 - */ - private final Throwable ex; - - /** - * Create an exception without a message. Note that this initializes the - * cause to null. - */ - public ClassNotFoundException() - { - this(null, null); - } - - /** - * Create an exception with a message. Note that this initializes the - * cause to null. - * - * @param s the message - */ - public ClassNotFoundException(String s) - { - this(s, null); - } - - /** - * Create an exception with a message and chain it to the exception - * which occurred while loading the class. - * - * @param s the message - * @param ex the chained exception - * @since 1.2 - */ - public ClassNotFoundException(String s, Throwable ex) - { - super(s, ex); - this.ex = ex; - } - - /** - * Returns the exception which occurred while loading the class, - * otherwise returns null. This is a legacy method; the preferred choice - * now is {@link Throwable#getCause()}. - * - * @return the cause of this exception - * @since 1.2 - */ - public Throwable getException() - { - return ex; - } - - /** - * Returns the exception which occurred while loading the class, - * otherwise returns null. - * - * @return the cause of this exception - * @since 1.4 - */ - public Throwable getCause() - { - return ex; - } -} diff --git a/libjava/java/lang/CloneNotSupportedException.java b/libjava/java/lang/CloneNotSupportedException.java deleted file mode 100644 index 9d10cf389f9..00000000000 --- a/libjava/java/lang/CloneNotSupportedException.java +++ /dev/null @@ -1,92 +0,0 @@ -/* CloneNotSupportedException.java -- thrown when an object cannot be cloned - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang; - -/** - * Thrown to indicate an object should not or could not be cloned. This - * includes the case when {@link Object#clone()} is called on an object - * which does not implement the {@link Cloneable} interface. For example:<br> - * <pre> - * void m() throws CloneNotSupportedException - * { - * clone(); - * } - * </pre> - * - * <p>Notice that calling <code>clone()</code> on an array will never produce - * this exception, as the VM will always succeed in copying the array, or - * cause an OutOfMemoryError first. For example:<br> - * <pre> - * void m(int[] array) - * { - * int[] copy = (int[]) array.clone(); - * } - * </pre> - * - * @author Brian Jones - * @author Warren Levy (warrenl@cygnus.com) - * @author Eric Blake (ebb9@email.byu.edu) - * @see Cloneable - * @see Object#clone() - * @status updated to 1.4 - */ -public class CloneNotSupportedException extends Exception -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = 5195511250079656443L; - - /** - * Create an exception without a message. - */ - public CloneNotSupportedException() - { - } - - /** - * Create an exception with a message. - * - * @param s the error message - */ - public CloneNotSupportedException(String s) - { - super(s); - } -} diff --git a/libjava/java/lang/Cloneable.java b/libjava/java/lang/Cloneable.java deleted file mode 100644 index 10f20ce3b6e..00000000000 --- a/libjava/java/lang/Cloneable.java +++ /dev/null @@ -1,78 +0,0 @@ -/* Cloneable.java -- Interface for marking objects cloneable by Object.clone() - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang; - -/** - * This interface should be implemented by classes wishing to - * support of override <code>Object.clone()</code>. The default - * behaviour of <code>clone()</code> performs a shallow copy, but - * subclasses often change this to perform a deep copy. Therefore, - * it is a good idea to document how deep your clone will go. - * If <code>clone()</code> is called on an object which does not - * implement this interface, a <code>CloneNotSupportedException</code> - * will be thrown. - * - * <p>This interface is simply a tagging interface; it carries no - * requirements on methods to implement. However, it is typical for - * a Cloneable class to implement at least <code>equals</code>, - * <code>hashCode</code>, and <code>clone</code>, sometimes - * increasing the accessibility of clone to be public. The typical - * implementation of <code>clone</code> invokes <code>super.clone()</code> - * rather than a constructor, but this is not a requirement. - * - * <p>If an object that implement Cloneable should not be cloned, - * simply override the <code>clone</code> method to throw a - * <code>CloneNotSupportedException</code>. - * - * <p>All array types implement Cloneable, and have a public - * <code>clone</code> method that will never fail with a - * <code>CloneNotSupportedException</code>. - * - * @author Paul Fisher - * @author Eric Blake (ebb9@email.byu.edu) - * @author Warren Levy (warrenl@cygnus.com) - * @see Object#clone() - * @see CloneNotSupportedException - * @since 1.0 - * @status updated to 1.4 - */ -public interface Cloneable -{ - // Tagging interface only. -} diff --git a/libjava/java/lang/Comparable.java b/libjava/java/lang/Comparable.java deleted file mode 100644 index a8afe1ec33e..00000000000 --- a/libjava/java/lang/Comparable.java +++ /dev/null @@ -1,98 +0,0 @@ -/* Comparable.java -- Interface for comparaing objects to obtain an ordering - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang; - -/** - * Interface for objects that can be ordering among other objects. The - * ordering can be <em>total</em>, such that two objects only compare equal - * if they are also equal by the equals method, or <em>partial</em> such - * that this is not necessarily true. For example, a case-sensitive - * dictionary order comparison of Strings is total, but if it is - * case-insensitive it is partial, because "abc" and "ABC" compare as - * equal even though "abc".equals("ABC") returns false. However, if you use - * a partial ordering, it is a good idea to document your class as - * "inconsistent with equals", because the behavior of your class in a - * SortedMap will be different than in a HashMap. - * - * <p>Lists, arrays, and sets of objects that implement this interface can - * be sorted automatically, without the need for an explicit - * {@link java.util.Comparator}. Note that <code>e1.compareTo(null)</code> - * should throw an Exception; as should comparison between incompatible - * classes. - * - * @author Geoff Berry - * @author Warren Levy (warrenl@cygnus.com) - * @see java.util.Comparator - * @see java.util.Collections#sort(java.util.List) - * @see java.util.Arrays#sort(Object[]) - * @see java.util.SortedSet - * @see java.util.SortedMap - * @see java.util.TreeSet - * @see java.util.TreeMap - * @since 1.2 - * @status updated to 1.4 - */ -public interface Comparable -{ - /** - * Compares this object with another, and returns a numerical result based - * on the comparison. If the result is negative, this object sorts less - * than the other; if 0, the two are equal, and if positive, this object - * sorts greater than the other. To translate this into boolean, simply - * perform <code>o1.compareTo(o2) <em><op></em> 0</code>, where op - * is one of <, <=, =, !=, >, or >=. - * - * <p>You must make sure that the comparison is mutual, ie. - * <code>sgn(x.compareTo(y)) == -sgn(y.compareTo(x))</code> (where sgn() is - * defined as -1, 0, or 1 based on the sign). This includes throwing an - * exception in either direction if the two are not comparable; hence, - * <code>compareTo(null)</code> should always throw an Exception. - * - * <p>You should also ensure transitivity, in two forms: - * <code>x.compareTo(y) > 0 && y.compareTo(z) > 0</code> implies - * <code>x.compareTo(z) > 0</code>; and <code>x.compareTo(y) == 0</code> - * implies <code>x.compareTo(z) == y.compareTo(z)</code>. - * - * @param o the object to be compared - * @return an integer describing the comparison - * @throws NullPointerException if o is null - * @throws ClassCastException if o cannot be compared - */ - int compareTo(Object o); -} diff --git a/libjava/java/lang/Compiler.java b/libjava/java/lang/Compiler.java deleted file mode 100644 index 56fb951bbd9..00000000000 --- a/libjava/java/lang/Compiler.java +++ /dev/null @@ -1,127 +0,0 @@ -/* Compiler.java -- placeholder for Java-to-native runtime compilers - Copyright (C) 1998, 1999, 2001, 2002, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang; - -/** - * The <code>Compiler</code> class is a placeholder for a JIT compiler - * implementation, and does nothing unless there is such a compiler. - * - * <p>The system property <code>java.compiler</code> may contain the name - * of a library to load with <code>System.loadLibrary</code> when the - * virtual machine first starts. If so, and loading the library succeeds, - * then a function by the name of <code>java_lang_Compiler_start()</code> - * in that library is called. - * - * <p>Note that a VM might not have implemented any of this. - * - * @author Tom Tromey (tromey@cygnus.com) - * @see System#getProperty(String) - * @see System#getProperty(String, String) - * @see System#loadLibrary(String) - * @since JDK 1.0 - * @status updated to 1.4 - */ -public final class Compiler -{ - /** - * Don't allow new `Compiler's to be made. - */ - private Compiler() - { - } - - /** - * Compile the class named by <code>oneClass</code>. - * - * @param oneClass the class to compile - * @return <code>false</code> if no compiler is available or - * compilation failed, <code>true</code> if compilation succeeded - * @throws NullPointerException if oneClass is null - */ - public static boolean compileClass(Class oneClass) - { - return VMCompiler.compileClass(oneClass); - } - - /** - * Compile the classes whose name matches <code>classNames</code>. - * - * @param classNames the name of classes to compile - * @return <code>false</code> if no compiler is available or - * compilation failed, <code>true</code> if compilation succeeded - * @throws NullPointerException if classNames is null - */ - public static boolean compileClasses(String classNames) - { - return VMCompiler.compileClasses(classNames); - } - - /** - * This method examines the argument and performs an operation - * according to the compilers documentation. No specific operation - * is required. - * - * @param arg a compiler-specific argument - * @return a compiler-specific value, including null - * @throws NullPointerException if the compiler doesn't like a null arg - */ - public static Object command(Object arg) - { - return VMCompiler.command(arg); - } - - /** - * Calling <code>Compiler.enable()</code> will cause the compiler - * to resume operation if it was previously disabled; provided that a - * compiler even exists. - */ - public static void enable() - { - VMCompiler.enable(); - } - - /** - * Calling <code>Compiler.disable()</code> will cause the compiler - * to be suspended; provided that a compiler even exists. - */ - public static void disable() - { - VMCompiler.disable(); - } -} diff --git a/libjava/java/lang/Error.java b/libjava/java/lang/Error.java deleted file mode 100644 index f66c7548b33..00000000000 --- a/libjava/java/lang/Error.java +++ /dev/null @@ -1,107 +0,0 @@ -/* Error.java -- Indication of fatal abnormal conditions - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang; - -/** - * Applications should not try to catch errors since they indicate - * abnormal conditions. An abnormal condition is something which should not - * occur, or which should not be recovered from. This latter category - * includes <code>ThreadDeath</code> and <code>AssertionError</code>. - * - * <p>A method is not required to declare any subclass of <code>Error</code> in - * its <code>throws</code> clause which might be thrown but not caught while - * executing the method. - * - * @author Brian Jones - * @author Tom Tromey (tromey@cygnus.com) - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.0 - * @status updated to 1.4 - */ -public class Error extends Throwable -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = 4980196508277280342L; - - /** - * Create an error without a message. The cause remains uninitialized. - * - * @see #initCause(Throwable) - */ - public Error() - { - } - - /** - * Create an error with a message. The cause remains uninitialized. - * - * @param s the message string - * @see #initCause(Throwable) - */ - public Error(String s) - { - super(s); - } - - /** - * Create an error with a message and a cause. - * - * @param s the message string - * @param cause the cause of this error - * @since 1.4 - */ - public Error(String s, Throwable cause) - { - super(s, cause); - } - - /** - * Create an error with a given cause, and a message of - * <code>cause == null ? null : cause.toString()</code>. - * - * @param cause the cause of this error - * @since 1.4 - */ - public Error(Throwable cause) - { - super(cause); - } -} diff --git a/libjava/java/lang/Exception.java b/libjava/java/lang/Exception.java deleted file mode 100644 index 42f7c640dd3..00000000000 --- a/libjava/java/lang/Exception.java +++ /dev/null @@ -1,104 +0,0 @@ -/* Exception.java -- generic exception thrown to indicate an exceptional - condition has occurred. - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang; - -/** - * The root class of all exceptions worth catching in a program. This - * includes the special category of <code>RuntimeException</code>, which - * does not need to be declared in a throws clause. Exceptions can be used - * to represent almost any exceptional behavior, such as programming errors, - * mouse movements, keyboard clicking, etc. - * - * @author Brian Jones - * @author Warren Levy (warrenl@cygnus.com) - * @author Eric Blake (ebb9@email.byu.edu) - * @status updated to 1.4 - */ -public class Exception extends Throwable -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = -3387516993124229948L; - - /** - * Create an exception without a message. The cause remains uninitialized. - * - * @see #initCause(Throwable) - */ - public Exception() - { - } - - /** - * Create an exception with a message. The cause remains uninitialized. - * - * @param s the message - * @see #initCause(Throwable) - */ - public Exception(String s) - { - super(s); - } - - /** - * Create an exception with a message and a cause. - * - * @param s the message string - * @param cause the cause of this error - * @since 1.4 - */ - public Exception(String s, Throwable cause) - { - super(s, cause); - } - - /** - * Create an exception with a given cause, and a message of - * <code>cause == null ? null : cause.toString()</code>. - * - * @param cause the cause of this exception - * @since 1.4 - */ - public Exception(Throwable cause) - { - super(cause); - } -} diff --git a/libjava/java/lang/ExceptionInInitializerError.java b/libjava/java/lang/ExceptionInInitializerError.java deleted file mode 100644 index 1e580958054..00000000000 --- a/libjava/java/lang/ExceptionInInitializerError.java +++ /dev/null @@ -1,123 +0,0 @@ -/* ExceptionInInitializerError.java -- thrown when class initialization fails - with an uncaught exception - Copyright (C) 1998, 1999, 2000, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang; - -/** - * An <code>ExceptionInInitializerError</code> is thrown when an uncaught - * exception has occurred in a static initializer or the initializer for a - * static variable. In general, this wraps only RuntimeExceptions, since the - * compiler does not allow a checked exception to be uncaught in an - * initializer. This exception only occurs during reflection, when a class - * is initialized as part of another action. - * - * @author Brian Jones - * @author Tom Tromey (tromey@cygnus.com) - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.1 - * @status updated to 1.4 - */ -public class ExceptionInInitializerError extends LinkageError -{ - /** - * Compatible with JDK 1.1+. - */ - static final long serialVersionUID = 1521711792217232256L; - - /** - * The cause of this exception (duplicates the one stored in Throwable). - * - * @serial the exception cause - */ - private final Throwable exception; - - /** - * Create an error without a message. The cause is initialized as null. - */ - public ExceptionInInitializerError() - { - this((String) null); - } - - /** - * Create an error with a message. The cause is initialized as null. - * - * @param s the message - */ - public ExceptionInInitializerError(String s) - { - super(s); - exception = null; - } - - /** - * Creates an error an saves a reference to the <code>Throwable</code> - * object. The message string is null. - * - * @param t the exception thrown - */ - public ExceptionInInitializerError(Throwable t) - { - super(null); - initCause(t); - exception = t; - } - - /** - * Return the exception that caused this error to be created. This is a - * legacy method; the preferred choice now is {@link Throwable#getCause()}. - * - * @return the cause, or null if unknown - */ - public Throwable getException() - { - return exception; - } - - /** - * Return the exception that cause this error to be created. - * - * @return the cause, or null if unknown - * @since 1.4 - */ - public Throwable getCause() - { - return exception; - } -} diff --git a/libjava/java/lang/IllegalAccessError.java b/libjava/java/lang/IllegalAccessError.java deleted file mode 100644 index e4821606a41..00000000000 --- a/libjava/java/lang/IllegalAccessError.java +++ /dev/null @@ -1,76 +0,0 @@ -/* IllegalAccessError.java -- thrown when linking to an inaccessible member - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang; - -/** - * An <code>IllegalAccessError</code> is thrown when an attempt is made to - * call a method, or access or modify a field that the application does not - * have access to. Because this error is usually caught by a compiler, - * the error only occurs at runtime when the definition of a class has - * changed in a way that is incompatible with the previously compiled - * application. - * - * @author Brian Jones - * @author Tom Tromey (tromey@cygnus.com) - * @status updated to 1.4 - */ -public class IllegalAccessError extends IncompatibleClassChangeError -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = -8988904074992417891L; - - /** - * Create an error without a message. - */ - public IllegalAccessError() - { - } - - /** - * Create an error with a message. - * - * @param s the message - */ - public IllegalAccessError(String s) - { - super(s); - } -} diff --git a/libjava/java/lang/IllegalAccessException.java b/libjava/java/lang/IllegalAccessException.java deleted file mode 100644 index 3fe83b5c716..00000000000 --- a/libjava/java/lang/IllegalAccessException.java +++ /dev/null @@ -1,95 +0,0 @@ -/* IllegalAccessException.java -- thrown on attempt to reflect on - inaccessible data - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang; - -/** - * Thrown whenever a reflective method tries to do something that the - * compiler would not allow. For example, using reflection to set a private - * variable that belongs to a class in another package is bad. - * - * @author Brian Jones - * @author Warren Levy (warrenl@cygnus.com) - * @see Class#newInstance() - * @see Field#set(Object, Object) - * @see Field#setBoolean(Object, boolean) - * @see Field#setByte(Object, byte) - * @see Field#setShort(Object, short) - * @see Field#setChar(Object, char) - * @see Field#setInt(Object, int) - * @see Field#setLong(Object, long) - * @see Field#setFloat(Object, float) - * @see Field#setDouble(Object, double) - * @see Field#get(Object) - * @see Field#getBoolean(Object) - * @see Field#getByte(Object) - * @see Field#getShort(Object) - * @see Field#getChar(Object) - * @see Field#getInt(Object) - * @see Field#getLong(Object) - * @see Field#getFloat(Object) - * @see Field#getDouble(Object) - * @see Method#invoke(Object, Object[]) - * @see Constructor#newInstance(Object[]) - * @status updated to 1.4 - */ -public class IllegalAccessException extends Exception -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = 6616958222490762034L; - - /** - * Create an exception without a message. - */ - public IllegalAccessException() - { - } - - /** - * Create an exception with a message. - * - * @param s the message - */ - public IllegalAccessException(String s) - { - super(s); - } -} diff --git a/libjava/java/lang/IllegalArgumentException.java b/libjava/java/lang/IllegalArgumentException.java deleted file mode 100644 index 7b822b91665..00000000000 --- a/libjava/java/lang/IllegalArgumentException.java +++ /dev/null @@ -1,75 +0,0 @@ -/* IllegalArgumentException.java -- thrown when a method is passed an - illegal or inappropriate argument - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.lang; - -/** - * Thrown when a method is passed an illegal or inappropriate argument. For - * example:<br> - * <pre> - * wait(-1); - * </pre> - * - * @author Brian Jones - * @author Warren Levy (warrenl@cygnus.com) - * @status updated to 1.4 - */ -public class IllegalArgumentException extends RuntimeException -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = -5365630128856068164L; - - /** - * Create an exception without a message. - */ - public IllegalArgumentException() - { - } - - /** - * Create an exception with a message. - * - * @param s the message - */ - public IllegalArgumentException(String s) - { - super(s); - } -} diff --git a/libjava/java/lang/IllegalMonitorStateException.java b/libjava/java/lang/IllegalMonitorStateException.java deleted file mode 100644 index 13b3f952bb5..00000000000 --- a/libjava/java/lang/IllegalMonitorStateException.java +++ /dev/null @@ -1,78 +0,0 @@ -/* IllegalMonitorStateException.java -- thrown when trying to wait or - notify a monitor that is not owned - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang; - -/** - * Thrown when a thread attempts to wait or notify on a monitor that it - * does not own (ie. it has not synchronized on the object). For example:<br> - * <pre> - * void m() { - * notify(); - * } - * </pre> - * - * @author Brian Jones - * @author Warren Levy (warrenl@cygnus.com) - * @status updated to 1.4 - */ -public class IllegalMonitorStateException extends RuntimeException -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = 3713306369498869069L; - - /** - * Create an exception without a message. - */ - public IllegalMonitorStateException() - { - } - - /** - * Create an exception with a message. - * - * @param s the message - */ - public IllegalMonitorStateException(String s) - { - super(s); - } -} diff --git a/libjava/java/lang/IllegalStateException.java b/libjava/java/lang/IllegalStateException.java deleted file mode 100644 index 5c2bbad37a2..00000000000 --- a/libjava/java/lang/IllegalStateException.java +++ /dev/null @@ -1,80 +0,0 @@ -/* IllegalStateException.java -- thrown when invoking a method at - an illegal or inappropriate time - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang; - -/** - * Thrown when a method is invoked at an illegal or inappropriate time. For - * example:<br> - * <pre> - * void m(Collecion c) - * { - * c.iterator().remove(); - * } - * </pre> - * - * @author Brian Jones - * @author Warren Levy (warrenl@cygnus.com) - * @since 1.1 - * @status updated to 1.4 - */ -public class IllegalStateException extends RuntimeException -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = -1848914673093119416L; - - /** - * Create an exception without a message. - */ - public IllegalStateException() - { - } - - /** - * Create an exception with a message. - * - * @param s the message - */ - public IllegalStateException(String s) - { - super(s); - } -} diff --git a/libjava/java/lang/IllegalThreadStateException.java b/libjava/java/lang/IllegalThreadStateException.java deleted file mode 100644 index e14385a3e83..00000000000 --- a/libjava/java/lang/IllegalThreadStateException.java +++ /dev/null @@ -1,75 +0,0 @@ -/* IllegalThreadStateException.java -- thrown when trying to manipulate a - Thread when it is not in an appropriate state - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang; - -/** - * Thrown When trying to manipulate a Thread which is in an inappropriate - * state. Since the documentation suggests that this can happen with - * <code>Thread.suspend</code> or <code>Thread.resume</code>, but these - * two methods are deprecated, this exception is likely very rare. - * - * @author Brian Jones - * @author Warren Levy (warrenl@cygnus.com) - * @status updated to 1.4 - */ -public class IllegalThreadStateException extends IllegalArgumentException -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = -7626246362397460174L; - - /** - * Create an exception without a message. - */ - public IllegalThreadStateException() - { - } - - /** - * Create an exception with a message. - * - * @param s the message - */ - public IllegalThreadStateException(String s) - { - super(s); - } -} diff --git a/libjava/java/lang/IncompatibleClassChangeError.java b/libjava/java/lang/IncompatibleClassChangeError.java deleted file mode 100644 index 637410a9009..00000000000 --- a/libjava/java/lang/IncompatibleClassChangeError.java +++ /dev/null @@ -1,73 +0,0 @@ -/* IncompatibleClassChangeError.java -- thrown for binary incompatible classes - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang; - -/** - * An <code>IncompatibleClassChangeError</code> is thrown when the definition - * of a class used by the currently executing method has changed in an - * incompatible way. - * - * @author Brian Jones - * @author Tom Tromey (tromey@cygnus.com) - * @status updated to 1.4 - */ -public class IncompatibleClassChangeError extends LinkageError -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = -4914975503642802119L; - - /** - * Create an error without a message. - */ - public IncompatibleClassChangeError() - { - } - - /** - * Create an error with a message. - * - * @param s the message - */ - public IncompatibleClassChangeError(String s) - { - super(s); - } -} diff --git a/libjava/java/lang/IndexOutOfBoundsException.java b/libjava/java/lang/IndexOutOfBoundsException.java deleted file mode 100644 index c53c67e5574..00000000000 --- a/libjava/java/lang/IndexOutOfBoundsException.java +++ /dev/null @@ -1,75 +0,0 @@ -/* IndexOutOfBoundsException.java -- thrown for an invalid index - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang; - -/** - * This exception can be thrown to indicate an attempt to access an - * index which is out of bounds on objects like String, Array, or Vector. - * Usually any negative integer less than or equal to -1 and positive - * integer greater than or equal to the size of the object is an index - * which would be out of bounds. - * - * @author Brian Jones - * @author Warren Levy (warrenl@cygnus.com) - * @status updated to 1.4 - */ -public class IndexOutOfBoundsException extends RuntimeException -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = 234122996006267687L; - - /** - * Create an exception without a message. - */ - public IndexOutOfBoundsException() - { - } - - /** - * Create an exception with a message. - * - * @param s the message - */ - public IndexOutOfBoundsException(String s) - { - super(s); - } -} diff --git a/libjava/java/lang/InstantiationError.java b/libjava/java/lang/InstantiationError.java deleted file mode 100644 index dd12b513a22..00000000000 --- a/libjava/java/lang/InstantiationError.java +++ /dev/null @@ -1,75 +0,0 @@ -/* InstantiationError.java -- thrown when the linker cannot create an instance - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang; - -/** - * An <code>InstantiationError</code> is thrown when an attempt is made to - * create an instance of an abstract class or an interface. Because this - * error is usually caught by a compiler, the error only occurs at runtime - * when the definition of a class has changed in a way that is incompatible - * with the previously compiled application. - * - * @author Brian Jones - * @author Tom Tromey (tromey@cygnus.com) - * @status updated to 1.4 - */ -public class InstantiationError extends IncompatibleClassChangeError -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = -4885810657349421204L; - - /** - * Create an error without a message. - */ - public InstantiationError() - { - } - - /** - * Create an error with a message. - * - * @param s the message - */ - public InstantiationError(String s) - { - super(s); - } -} diff --git a/libjava/java/lang/InstantiationException.java b/libjava/java/lang/InstantiationException.java deleted file mode 100644 index 367b14bd278..00000000000 --- a/libjava/java/lang/InstantiationException.java +++ /dev/null @@ -1,74 +0,0 @@ -/* InstantiationException.java -- thrown when reflection cannot create an - instance - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang; - -/** - * Thrown when an attempt is made to use reflection to build a - * non-instantiable class (an interface or abstract class). - * - * @author Brian Jones - * @author Warren Levy (warrenl@cygnus.com) - * @see Class#newInstance() - * @status updated to 1.4 - */ -public class InstantiationException extends Exception -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = -8441929162975509110L; - - /** - * Create an exception without a message. - */ - public InstantiationException() - { - } - - /** - * Create an exception with a message. - * - * @param s the message - */ - public InstantiationException(String s) - { - super(s); - } -} diff --git a/libjava/java/lang/Integer.java b/libjava/java/lang/Integer.java deleted file mode 100644 index 61d7ef0f7e2..00000000000 --- a/libjava/java/lang/Integer.java +++ /dev/null @@ -1,606 +0,0 @@ -/* Integer.java -- object wrapper for int - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang; - -/** - * Instances of class <code>Integer</code> represent primitive - * <code>int</code> values. - * - * Additionally, this class provides various helper functions and variables - * related to ints. - * - * @author Paul Fisher - * @author John Keiser - * @author Warren Levy - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.0 - * @status updated to 1.4 - */ -public final class Integer extends Number implements Comparable -{ - /** - * Compatible with JDK 1.0.2+. - */ - private static final long serialVersionUID = 1360826667806852920L; - - /** - * The minimum value an <code>int</code> can represent is -2147483648 (or - * -2<sup>31</sup>). - */ - public static final int MIN_VALUE = 0x80000000; - - /** - * The maximum value an <code>int</code> can represent is 2147483647 (or - * 2<sup>31</sup> - 1). - */ - public static final int MAX_VALUE = 0x7fffffff; - - /** - * The primitive type <code>int</code> is represented by this - * <code>Class</code> object. - * @since 1.1 - */ - public static final Class TYPE = VMClassLoader.getPrimitiveClass('I'); - - /** - * The immutable value of this Integer. - * - * @serial the wrapped int - */ - private final int value; - - /** - * Create an <code>Integer</code> object representing the value of the - * <code>int</code> argument. - * - * @param value the value to use - */ - public Integer(int value) - { - this.value = value; - } - - /** - * Create an <code>Integer</code> object representing the value of the - * argument after conversion to an <code>int</code>. - * - * @param s the string to convert - * @throws NumberFormatException if the String does not contain an int - * @see #valueOf(String) - */ - public Integer(String s) - { - value = parseInt(s, 10, false); - } - - /** - * Converts the <code>int</code> to a <code>String</code> using - * the specified radix (base). If the radix exceeds - * <code>Character.MIN_RADIX</code> or <code>Character.MAX_RADIX</code>, 10 - * is used instead. If the result is negative, the leading character is - * '-' ('\\u002D'). The remaining characters come from - * <code>Character.forDigit(digit, radix)</code> ('0'-'9','a'-'z'). - * - * @param num the <code>int</code> to convert to <code>String</code> - * @param radix the radix (base) to use in the conversion - * @return the <code>String</code> representation of the argument - */ - public static String toString(int num, int radix) - { - if (radix < Character.MIN_RADIX || radix > Character.MAX_RADIX) - radix = 10; - - // For negative numbers, print out the absolute value w/ a leading '-'. - // Use an array large enough for a binary number. - char[] buffer = new char[33]; - int i = 33; - boolean isNeg = false; - if (num < 0) - { - isNeg = true; - num = -num; - - // When the value is MIN_VALUE, it overflows when made positive - if (num < 0) - { - buffer[--i] = digits[(int) (-(num + radix) % radix)]; - num = -(num / radix); - } - } - - do - { - buffer[--i] = digits[num % radix]; - num /= radix; - } - while (num > 0); - - if (isNeg) - buffer[--i] = '-'; - - // Package constructor avoids an array copy. - return new String(buffer, i, 33 - i, true); - } - - /** - * Converts the <code>int</code> to a <code>String</code> assuming it is - * unsigned in base 16. - * - * @param i the <code>int</code> to convert to <code>String</code> - * @return the <code>String</code> representation of the argument - */ - public static String toHexString(int i) - { - return toUnsignedString(i, 4); - } - - /** - * Converts the <code>int</code> to a <code>String</code> assuming it is - * unsigned in base 8. - * - * @param i the <code>int</code> to convert to <code>String</code> - * @return the <code>String</code> representation of the argument - */ - public static String toOctalString(int i) - { - return toUnsignedString(i, 3); - } - - /** - * Converts the <code>int</code> to a <code>String</code> assuming it is - * unsigned in base 2. - * - * @param i the <code>int</code> to convert to <code>String</code> - * @return the <code>String</code> representation of the argument - */ - public static String toBinaryString(int i) - { - return toUnsignedString(i, 1); - } - - /** - * Converts the <code>int</code> to a <code>String</code> and assumes - * a radix of 10. - * - * @param i the <code>int</code> to convert to <code>String</code> - * @return the <code>String</code> representation of the argument - * @see #toString(int, int) - */ - public static String toString(int i) - { - // This is tricky: in libgcj, String.valueOf(int) is a fast native - // implementation. In Classpath it just calls back to - // Integer.toString(int, int). - return String.valueOf(i); - } - - /** - * Converts the specified <code>String</code> into an <code>int</code> - * using the specified radix (base). The string must not be <code>null</code> - * or empty. It may begin with an optional '-', which will negate the answer, - * provided that there are also valid digits. Each digit is parsed as if by - * <code>Character.digit(d, radix)</code>, and must be in the range - * <code>0</code> to <code>radix - 1</code>. Finally, the result must be - * within <code>MIN_VALUE</code> to <code>MAX_VALUE</code>, inclusive. - * Unlike Double.parseDouble, you may not have a leading '+'. - * - * @param str the <code>String</code> to convert - * @param radix the radix (base) to use in the conversion - * @return the <code>String</code> argument converted to <code>int</code> - * @throws NumberFormatException if <code>s</code> cannot be parsed as an - * <code>int</code> - */ - public static int parseInt(String str, int radix) - { - return parseInt(str, radix, false); - } - - /** - * Converts the specified <code>String</code> into an <code>int</code>. - * This function assumes a radix of 10. - * - * @param s the <code>String</code> to convert - * @return the <code>int</code> value of <code>s</code> - * @throws NumberFormatException if <code>s</code> cannot be parsed as an - * <code>int</code> - * @see #parseInt(String, int) - */ - public static int parseInt(String s) - { - return parseInt(s, 10, false); - } - - /** - * Creates a new <code>Integer</code> object using the <code>String</code> - * and specified radix (base). - * - * @param s the <code>String</code> to convert - * @param radix the radix (base) to convert with - * @return the new <code>Integer</code> - * @throws NumberFormatException if <code>s</code> cannot be parsed as an - * <code>int</code> - * @see #parseInt(String, int) - */ - public static Integer valueOf(String s, int radix) - { - return new Integer(parseInt(s, radix, false)); - } - - /** - * Creates a new <code>Integer</code> object using the <code>String</code>, - * assuming a radix of 10. - * - * @param s the <code>String</code> to convert - * @return the new <code>Integer</code> - * @throws NumberFormatException if <code>s</code> cannot be parsed as an - * <code>int</code> - * @see #Integer(String) - * @see #parseInt(String) - */ - public static Integer valueOf(String s) - { - return new Integer(parseInt(s, 10, false)); - } - - /** - * Return the value of this <code>Integer</code> as a <code>byte</code>. - * - * @return the byte value - */ - public byte byteValue() - { - return (byte) value; - } - - /** - * Return the value of this <code>Integer</code> as a <code>short</code>. - * - * @return the short value - */ - public short shortValue() - { - return (short) value; - } - - /** - * Return the value of this <code>Integer</code>. - * @return the int value - */ - public int intValue() - { - return value; - } - - /** - * Return the value of this <code>Integer</code> as a <code>long</code>. - * - * @return the long value - */ - public long longValue() - { - return value; - } - - /** - * Return the value of this <code>Integer</code> as a <code>float</code>. - * - * @return the float value - */ - public float floatValue() - { - return value; - } - - /** - * Return the value of this <code>Integer</code> as a <code>double</code>. - * - * @return the double value - */ - public double doubleValue() - { - return value; - } - - /** - * Converts the <code>Integer</code> value to a <code>String</code> and - * assumes a radix of 10. - * - * @return the <code>String</code> representation - */ - public String toString() - { - return String.valueOf(value); - } - - /** - * Return a hashcode representing this Object. <code>Integer</code>'s hash - * code is simply its value. - * - * @return this Object's hash code - */ - public int hashCode() - { - return value; - } - - /** - * Returns <code>true</code> if <code>obj</code> is an instance of - * <code>Integer</code> and represents the same int value. - * - * @param obj the object to compare - * @return whether these Objects are semantically equal - */ - public boolean equals(Object obj) - { - return obj instanceof Integer && value == ((Integer) obj).value; - } - - /** - * Get the specified system property as an <code>Integer</code>. The - * <code>decode()</code> method will be used to interpret the value of - * the property. - * - * @param nm the name of the system property - * @return the system property as an <code>Integer</code>, or null if the - * property is not found or cannot be decoded - * @throws SecurityException if accessing the system property is forbidden - * @see System#getProperty(String) - * @see #decode(String) - */ - public static Integer getInteger(String nm) - { - return getInteger(nm, null); - } - - /** - * Get the specified system property as an <code>Integer</code>, or use a - * default <code>int</code> value if the property is not found or is not - * decodable. The <code>decode()</code> method will be used to interpret - * the value of the property. - * - * @param nm the name of the system property - * @param val the default value - * @return the value of the system property, or the default - * @throws SecurityException if accessing the system property is forbidden - * @see System#getProperty(String) - * @see #decode(String) - */ - public static Integer getInteger(String nm, int val) - { - Integer result = getInteger(nm, null); - return result == null ? new Integer(val) : result; - } - - /** - * Get the specified system property as an <code>Integer</code>, or use a - * default <code>Integer</code> value if the property is not found or is - * not decodable. The <code>decode()</code> method will be used to - * interpret the value of the property. - * - * @param nm the name of the system property - * @param def the default value - * @return the value of the system property, or the default - * @throws SecurityException if accessing the system property is forbidden - * @see System#getProperty(String) - * @see #decode(String) - */ - public static Integer getInteger(String nm, Integer def) - { - if (nm == null || "".equals(nm)) - return def; - nm = System.getProperty(nm); - if (nm == null) - return def; - try - { - return decode(nm); - } - catch (NumberFormatException e) - { - return def; - } - } - - /** - * Convert the specified <code>String</code> into an <code>Integer</code>. - * The <code>String</code> may represent decimal, hexadecimal, or - * octal numbers. - * - * <p>The extended BNF grammar is as follows:<br> - * <pre> - * <em>DecodableString</em>: - * ( [ <code>-</code> ] <em>DecimalNumber</em> ) - * | ( [ <code>-</code> ] ( <code>0x</code> | <code>0X</code> - * | <code>#</code> ) <em>HexDigit</em> { <em>HexDigit</em> } ) - * | ( [ <code>-</code> ] <code>0</code> { <em>OctalDigit</em> } ) - * <em>DecimalNumber</em>: - * <em>DecimalDigit except '0'</em> { <em>DecimalDigit</em> } - * <em>DecimalDigit</em>: - * <em>Character.digit(d, 10) has value 0 to 9</em> - * <em>OctalDigit</em>: - * <em>Character.digit(d, 8) has value 0 to 7</em> - * <em>DecimalDigit</em>: - * <em>Character.digit(d, 16) has value 0 to 15</em> - * </pre> - * Finally, the value must be in the range <code>MIN_VALUE</code> to - * <code>MAX_VALUE</code>, or an exception is thrown. - * - * @param str the <code>String</code> to interpret - * @return the value of the String as an <code>Integer</code> - * @throws NumberFormatException if <code>s</code> cannot be parsed as a - * <code>int</code> - * @throws NullPointerException if <code>s</code> is null - * @since 1.2 - */ - public static Integer decode(String str) - { - return new Integer(parseInt(str, 10, true)); - } - - /** - * Compare two Integers numerically by comparing their <code>int</code> - * values. The result is positive if the first is greater, negative if the - * second is greater, and 0 if the two are equal. - * - * @param i the Integer to compare - * @return the comparison - * @since 1.2 - */ - public int compareTo(Integer i) - { - if (value == i.value) - return 0; - // Returns just -1 or 1 on inequality; doing math might overflow. - return value > i.value ? 1 : -1; - } - - /** - * Behaves like <code>compareTo(Integer)</code> unless the Object - * is not an <code>Integer</code>. - * - * @param o the object to compare - * @return the comparison - * @throws ClassCastException if the argument is not an <code>Integer</code> - * @see #compareTo(Integer) - * @see Comparable - * @since 1.2 - */ - public int compareTo(Object o) - { - return compareTo((Integer) o); - } - - /** - * Helper for converting unsigned numbers to String. - * - * @param num the number - * @param exp log2(digit) (ie. 1, 3, or 4 for binary, oct, hex) - */ - // Package visible for use by Long. - static String toUnsignedString(int num, int exp) - { - // Use an array large enough for a binary number. - int mask = (1 << exp) - 1; - char[] buffer = new char[32]; - int i = 32; - do - { - buffer[--i] = digits[num & mask]; - num >>>= exp; - } - while (num != 0); - - // Package constructor avoids an array copy. - return new String(buffer, i, 32 - i, true); - } - - /** - * Helper for parsing ints, used by Integer, Short, and Byte. - * - * @param str the string to parse - * @param radix the radix to use, must be 10 if decode is true - * @param decode if called from decode - * @return the parsed int value - * @throws NumberFormatException if there is an error - * @throws NullPointerException if decode is true and str if null - * @see #parseInt(String, int) - * @see #decode(String) - * @see Byte#parseInt(String, int) - * @see Short#parseInt(String, int) - */ - static int parseInt(String str, int radix, boolean decode) - { - if (! decode && str == null) - throw new NumberFormatException(); - int index = 0; - int len = str.length(); - boolean isNeg = false; - if (len == 0) - throw new NumberFormatException(); - int ch = str.charAt(index); - if (ch == '-') - { - if (len == 1) - throw new NumberFormatException(); - isNeg = true; - ch = str.charAt(++index); - } - if (decode) - { - if (ch == '0') - { - if (++index == len) - return 0; - if ((str.charAt(index) & ~('x' ^ 'X')) == 'X') - { - radix = 16; - index++; - } - else - radix = 8; - } - else if (ch == '#') - { - radix = 16; - index++; - } - } - if (index == len) - throw new NumberFormatException(); - - int max = MAX_VALUE / radix; - // We can't directly write `max = (MAX_VALUE + 1) / radix'. - // So instead we fake it. - if (isNeg && MAX_VALUE % radix == radix - 1) - ++max; - - int val = 0; - while (index < len) - { - if (val < 0 || val > max) - throw new NumberFormatException(); - - ch = Character.digit(str.charAt(index++), radix); - val = val * radix + ch; - if (ch < 0 || (val < 0 && (! isNeg || val != MIN_VALUE))) - throw new NumberFormatException(); - } - return isNeg ? -val : val; - } -} diff --git a/libjava/java/lang/InternalError.java b/libjava/java/lang/InternalError.java deleted file mode 100644 index 3a95bbeaf57..00000000000 --- a/libjava/java/lang/InternalError.java +++ /dev/null @@ -1,72 +0,0 @@ -/* InternalError.java -- thrown when the VM encounters an internal error - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang; - -/** - * An <code>InternalError</code> is thrown when a mystical error has - * occurred in the Java Virtual Machine. - * - * @author Brian Jones - * @author Tom Tromey (tromey@cygnus.com) - * @status updated to 1.4 - */ -public class InternalError extends VirtualMachineError -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = -9062593416125562365L; - - /** - * Create an error without a message. - */ - public InternalError() - { - } - - /** - * Create an error with a message. - * - * @param s the message - */ - public InternalError(String s) - { - super(s); - } -} diff --git a/libjava/java/lang/InterruptedException.java b/libjava/java/lang/InterruptedException.java deleted file mode 100644 index da2173c8b4e..00000000000 --- a/libjava/java/lang/InterruptedException.java +++ /dev/null @@ -1,80 +0,0 @@ -/* InterruptedException.java -- thrown when a thread is interrupted - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang; - -/** - * Thrown when a thread interrupts another thread which was previously - * sleeping, waiting, or paused in some other way. See the - * <code>interrupt</code> method of class <code>Thread</code>. - * - * @author Brian Jones - * @author Warren Levy (warrenl@cygnus.com) - * @see Object#wait() - * @see Object#wait(long) - * @see Object#wait(long, int) - * @see Thread#sleep(long) - * @see Thread#interrupt() - * @see Thread#interrupted() - * @status updated to 1.4 - */ -public class InterruptedException extends Exception -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = 6700697376100628473L; - - /** - * Create an exception without a message. - */ - public InterruptedException() - { - } - - /** - * Create an exception with a message. - * - * - * @param s the message - */ - public InterruptedException(String s) - { - super(s); - } -} diff --git a/libjava/java/lang/LinkageError.java b/libjava/java/lang/LinkageError.java deleted file mode 100644 index 028702081ba..00000000000 --- a/libjava/java/lang/LinkageError.java +++ /dev/null @@ -1,74 +0,0 @@ -/* LinkageError.java -- thrown when classes valid at separate compile times - cannot be linked to each other - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang; - -/** - * Subclasses of <code>LinkageError</code> are thrown to indicate that two - * classes which were compatible at separate compilation times cannot be - * linked to one another. - * - * @author Brian Jones - * @author Tom Tromey (tromey@cygnus.com) - * @status updated to 1.4 - */ -public class LinkageError extends Error -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = 3579600108157160122L; - - /** - * Create an error without a message. - */ - public LinkageError() - { - } - - /** - * Create an error with a message. - * - * @param s the message - */ - public LinkageError(String s) - { - super(s); - } -} diff --git a/libjava/java/lang/Long.java b/libjava/java/lang/Long.java deleted file mode 100644 index 703eab8a0f3..00000000000 --- a/libjava/java/lang/Long.java +++ /dev/null @@ -1,614 +0,0 @@ -/* Long.java -- object wrapper for long - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang; - -/** - * Instances of class <code>Long</code> represent primitive - * <code>long</code> values. - * - * Additionally, this class provides various helper functions and variables - * related to longs. - * - * @author Paul Fisher - * @author John Keiser - * @author Warren Levy - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.0 - * @status updated to 1.4 - */ -public final class Long extends Number implements Comparable -{ - /** - * Compatible with JDK 1.0.2+. - */ - private static final long serialVersionUID = 4290774380558885855L; - - /** - * The minimum value a <code>long</code> can represent is - * -9223372036854775808L (or -2<sup>63</sup>). - */ - public static final long MIN_VALUE = 0x8000000000000000L; - - /** - * The maximum value a <code>long</code> can represent is - * 9223372036854775807 (or 2<sup>63</sup> - 1). - */ - public static final long MAX_VALUE = 0x7fffffffffffffffL; - - /** - * The primitive type <code>long</code> is represented by this - * <code>Class</code> object. - * @since 1.1 - */ - public static final Class TYPE = VMClassLoader.getPrimitiveClass ('J'); - - /** - * The immutable value of this Long. - * - * @serial the wrapped long - */ - private final long value; - - /** - * Create a <code>Long</code> object representing the value of the - * <code>long</code> argument. - * - * @param value the value to use - */ - public Long(long value) - { - this.value = value; - } - - /** - * Create a <code>Long</code> object representing the value of the - * argument after conversion to a <code>long</code>. - * - * @param s the string to convert - * @throws NumberFormatException if the String does not contain a long - * @see #valueOf(String) - */ - public Long(String s) - { - value = parseLong(s, 10, false); - } - - /** - * Converts the <code>long</code> to a <code>String</code> using - * the specified radix (base). If the radix exceeds - * <code>Character.MIN_RADIX</code> or <code>Character.MAX_RADIX</code>, 10 - * is used instead. If the result is negative, the leading character is - * '-' ('\\u002D'). The remaining characters come from - * <code>Character.forDigit(digit, radix)</code> ('0'-'9','a'-'z'). - * - * @param num the <code>long</code> to convert to <code>String</code> - * @param radix the radix (base) to use in the conversion - * @return the <code>String</code> representation of the argument - */ - public static String toString(long num, int radix) - { - // Use the Integer toString for efficiency if possible. - if ((int) num == num) - return Integer.toString((int) num, radix); - - if (radix < Character.MIN_RADIX || radix > Character.MAX_RADIX) - radix = 10; - - // For negative numbers, print out the absolute value w/ a leading '-'. - // Use an array large enough for a binary number. - char[] buffer = new char[65]; - int i = 65; - boolean isNeg = false; - if (num < 0) - { - isNeg = true; - num = -num; - - // When the value is MIN_VALUE, it overflows when made positive - if (num < 0) - { - buffer[--i] = digits[(int) (-(num + radix) % radix)]; - num = -(num / radix); - } - } - - do - { - buffer[--i] = digits[(int) (num % radix)]; - num /= radix; - } - while (num > 0); - - if (isNeg) - buffer[--i] = '-'; - - // Package constructor avoids an array copy. - return new String(buffer, i, 65 - i, true); - } - - /** - * Converts the <code>long</code> to a <code>String</code> assuming it is - * unsigned in base 16. - * - * @param l the <code>long</code> to convert to <code>String</code> - * @return the <code>String</code> representation of the argument - */ - public static String toHexString(long l) - { - return toUnsignedString(l, 4); - } - - /** - * Converts the <code>long</code> to a <code>String</code> assuming it is - * unsigned in base 8. - * - * @param l the <code>long</code> to convert to <code>String</code> - * @return the <code>String</code> representation of the argument - */ - public static String toOctalString(long l) - { - return toUnsignedString(l, 3); - } - - /** - * Converts the <code>long</code> to a <code>String</code> assuming it is - * unsigned in base 2. - * - * @param l the <code>long</code> to convert to <code>String</code> - * @return the <code>String</code> representation of the argument - */ - public static String toBinaryString(long l) - { - return toUnsignedString(l, 1); - } - - /** - * Converts the <code>long</code> to a <code>String</code> and assumes - * a radix of 10. - * - * @param num the <code>long</code> to convert to <code>String</code> - * @return the <code>String</code> representation of the argument - * @see #toString(long, int) - */ - public static String toString(long num) - { - return toString(num, 10); - } - - /** - * Converts the specified <code>String</code> into an <code>int</code> - * using the specified radix (base). The string must not be <code>null</code> - * or empty. It may begin with an optional '-', which will negate the answer, - * provided that there are also valid digits. Each digit is parsed as if by - * <code>Character.digit(d, radix)</code>, and must be in the range - * <code>0</code> to <code>radix - 1</code>. Finally, the result must be - * within <code>MIN_VALUE</code> to <code>MAX_VALUE</code>, inclusive. - * Unlike Double.parseDouble, you may not have a leading '+'; and 'l' or - * 'L' as the last character is only valid in radices 22 or greater, where - * it is a digit and not a type indicator. - * - * @param str the <code>String</code> to convert - * @param radix the radix (base) to use in the conversion - * @return the <code>String</code> argument converted to <code>long</code> - * @throws NumberFormatException if <code>s</code> cannot be parsed as a - * <code>long</code> - */ - public static long parseLong(String str, int radix) - { - return parseLong(str, radix, false); - } - - /** - * Converts the specified <code>String</code> into a <code>long</code>. - * This function assumes a radix of 10. - * - * @param s the <code>String</code> to convert - * @return the <code>int</code> value of <code>s</code> - * @throws NumberFormatException if <code>s</code> cannot be parsed as a - * <code>long</code> - * @see #parseLong(String, int) - */ - public static long parseLong(String s) - { - return parseLong(s, 10, false); - } - - /** - * Creates a new <code>Long</code> object using the <code>String</code> - * and specified radix (base). - * - * @param s the <code>String</code> to convert - * @param radix the radix (base) to convert with - * @return the new <code>Long</code> - * @throws NumberFormatException if <code>s</code> cannot be parsed as a - * <code>long</code> - * @see #parseLong(String, int) - */ - public static Long valueOf(String s, int radix) - { - return new Long(parseLong(s, radix, false)); - } - - /** - * Creates a new <code>Long</code> object using the <code>String</code>, - * assuming a radix of 10. - * - * @param s the <code>String</code> to convert - * @return the new <code>Long</code> - * @throws NumberFormatException if <code>s</code> cannot be parsed as a - * <code>long</code> - * @see #Long(String) - * @see #parseLong(String) - */ - public static Long valueOf(String s) - { - return new Long(parseLong(s, 10, false)); - } - - /** - * Convert the specified <code>String</code> into a <code>Long</code>. - * The <code>String</code> may represent decimal, hexadecimal, or - * octal numbers. - * - * <p>The extended BNF grammar is as follows:<br> - * <pre> - * <em>DecodableString</em>: - * ( [ <code>-</code> ] <em>DecimalNumber</em> ) - * | ( [ <code>-</code> ] ( <code>0x</code> | <code>0X</code> - * | <code>#</code> ) <em>HexDigit</em> { <em>HexDigit</em> } ) - * | ( [ <code>-</code> ] <code>0</code> { <em>OctalDigit</em> } ) - * <em>DecimalNumber</em>: - * <em>DecimalDigit except '0'</em> { <em>DecimalDigit</em> } - * <em>DecimalDigit</em>: - * <em>Character.digit(d, 10) has value 0 to 9</em> - * <em>OctalDigit</em>: - * <em>Character.digit(d, 8) has value 0 to 7</em> - * <em>DecimalDigit</em>: - * <em>Character.digit(d, 16) has value 0 to 15</em> - * </pre> - * Finally, the value must be in the range <code>MIN_VALUE</code> to - * <code>MAX_VALUE</code>, or an exception is thrown. Note that you cannot - * use a trailing 'l' or 'L', unlike in Java source code. - * - * @param str the <code>String</code> to interpret - * @return the value of the String as a <code>Long</code> - * @throws NumberFormatException if <code>s</code> cannot be parsed as a - * <code>long</code> - * @throws NullPointerException if <code>s</code> is null - * @since 1.2 - */ - public static Long decode(String str) - { - return new Long(parseLong(str, 10, true)); - } - - /** - * Return the value of this <code>Long</code> as a <code>byte</code>. - * - * @return the byte value - */ - public byte byteValue() - { - return (byte) value; - } - - /** - * Return the value of this <code>Long</code> as a <code>short</code>. - * - * @return the short value - */ - public short shortValue() - { - return (short) value; - } - - /** - * Return the value of this <code>Long</code> as an <code>int</code>. - * - * @return the int value - */ - public int intValue() - { - return (int) value; - } - - /** - * Return the value of this <code>Long</code>. - * - * @return the long value - */ - public long longValue() - { - return value; - } - - /** - * Return the value of this <code>Long</code> as a <code>float</code>. - * - * @return the float value - */ - public float floatValue() - { - return value; - } - - /** - * Return the value of this <code>Long</code> as a <code>double</code>. - * - * @return the double value - */ - public double doubleValue() - { - return value; - } - - /** - * Converts the <code>Long</code> value to a <code>String</code> and - * assumes a radix of 10. - * - * @return the <code>String</code> representation - */ - public String toString() - { - return toString(value, 10); - } - - /** - * Return a hashcode representing this Object. <code>Long</code>'s hash - * code is calculated by <code>(int) (value ^ (value >> 32))</code>. - * - * @return this Object's hash code - */ - public int hashCode() - { - return (int) (value ^ (value >>> 32)); - } - - /** - * Returns <code>true</code> if <code>obj</code> is an instance of - * <code>Long</code> and represents the same long value. - * - * @param obj the object to compare - * @return whether these Objects are semantically equal - */ - public boolean equals(Object obj) - { - return obj instanceof Long && value == ((Long) obj).value; - } - - /** - * Get the specified system property as a <code>Long</code>. The - * <code>decode()</code> method will be used to interpret the value of - * the property. - * - * @param nm the name of the system property - * @return the system property as a <code>Long</code>, or null if the - * property is not found or cannot be decoded - * @throws SecurityException if accessing the system property is forbidden - * @see System#getProperty(String) - * @see #decode(String) - */ - public static Long getLong(String nm) - { - return getLong(nm, null); - } - - /** - * Get the specified system property as a <code>Long</code>, or use a - * default <code>long</code> value if the property is not found or is not - * decodable. The <code>decode()</code> method will be used to interpret - * the value of the property. - * - * @param nm the name of the system property - * @param val the default value - * @return the value of the system property, or the default - * @throws SecurityException if accessing the system property is forbidden - * @see System#getProperty(String) - * @see #decode(String) - */ - public static Long getLong(String nm, long val) - { - Long result = getLong(nm, null); - return result == null ? new Long(val) : result; - } - - /** - * Get the specified system property as a <code>Long</code>, or use a - * default <code>Long</code> value if the property is not found or is - * not decodable. The <code>decode()</code> method will be used to - * interpret the value of the property. - * - * @param nm the name of the system property - * @param def the default value - * @return the value of the system property, or the default - * @throws SecurityException if accessing the system property is forbidden - * @see System#getProperty(String) - * @see #decode(String) - */ - public static Long getLong(String nm, Long def) - { - if (nm == null || "".equals(nm)) - return def; - nm = System.getProperty(nm); - if (nm == null) - return def; - try - { - return decode(nm); - } - catch (NumberFormatException e) - { - return def; - } - } - - /** - * Compare two Longs numerically by comparing their <code>long</code> - * values. The result is positive if the first is greater, negative if the - * second is greater, and 0 if the two are equal. - * - * @param l the Long to compare - * @return the comparison - * @since 1.2 - */ - public int compareTo(Long l) - { - if (value == l.value) - return 0; - // Returns just -1 or 1 on inequality; doing math might overflow the long. - return value > l.value ? 1 : -1; - } - - /** - * Behaves like <code>compareTo(Long)</code> unless the Object - * is not a <code>Long</code>. - * - * @param o the object to compare - * @return the comparison - * @throws ClassCastException if the argument is not a <code>Long</code> - * @see #compareTo(Long) - * @see Comparable - * @since 1.2 - */ - public int compareTo(Object o) - { - return compareTo((Long) o); - } - - /** - * Helper for converting unsigned numbers to String. - * - * @param num the number - * @param exp log2(digit) (ie. 1, 3, or 4 for binary, oct, hex) - */ - private static String toUnsignedString(long num, int exp) - { - // Use the Integer toUnsignedString for efficiency if possible. - // If NUM<0 then this particular optimization doesn't work - // properly. - if (num >= 0 && (int) num == num) - return Integer.toUnsignedString((int) num, exp); - - // Use an array large enough for a binary number. - int mask = (1 << exp) - 1; - char[] buffer = new char[64]; - int i = 64; - do - { - buffer[--i] = digits[(int) num & mask]; - num >>>= exp; - } - while (num != 0); - - // Package constructor avoids an array copy. - return new String(buffer, i, 64 - i, true); - } - - /** - * Helper for parsing longs. - * - * @param str the string to parse - * @param radix the radix to use, must be 10 if decode is true - * @param decode if called from decode - * @return the parsed long value - * @throws NumberFormatException if there is an error - * @throws NullPointerException if decode is true and str is null - * @see #parseLong(String, int) - * @see #decode(String) - */ - private static long parseLong(String str, int radix, boolean decode) - { - if (! decode && str == null) - throw new NumberFormatException(); - int index = 0; - int len = str.length(); - boolean isNeg = false; - if (len == 0) - throw new NumberFormatException(); - int ch = str.charAt(index); - if (ch == '-') - { - if (len == 1) - throw new NumberFormatException(); - isNeg = true; - ch = str.charAt(++index); - } - if (decode) - { - if (ch == '0') - { - if (++index == len) - return 0; - if ((str.charAt(index) & ~('x' ^ 'X')) == 'X') - { - radix = 16; - index++; - } - else - radix = 8; - } - else if (ch == '#') - { - radix = 16; - index++; - } - } - if (index == len) - throw new NumberFormatException(); - - long max = MAX_VALUE / radix; - // We can't directly write `max = (MAX_VALUE + 1) / radix'. - // So instead we fake it. - if (isNeg && MAX_VALUE % radix == radix - 1) - ++max; - - long val = 0; - while (index < len) - { - if (val < 0 || val > max) - throw new NumberFormatException(); - - ch = Character.digit(str.charAt(index++), radix); - val = val * radix + ch; - if (ch < 0 || (val < 0 && (! isNeg || val != MIN_VALUE))) - throw new NumberFormatException(); - } - return isNeg ? -val : val; - } -} diff --git a/libjava/java/lang/Math.java b/libjava/java/lang/Math.java deleted file mode 100644 index 08081e2523a..00000000000 --- a/libjava/java/lang/Math.java +++ /dev/null @@ -1,650 +0,0 @@ -/* java.lang.Math -- common mathematical functions, native allowed - Copyright (C) 1998, 2001, 2002, 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang; - -import gnu.classpath.Configuration; - -import java.util.Random; - -/** - * Helper class containing useful mathematical functions and constants. - * <P> - * - * Note that angles are specified in radians. Conversion functions are - * provided for your convenience. - * - * @author Paul Fisher - * @author John Keiser - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.0 - */ -public final class Math -{ - /** - * Math is non-instantiable - */ - private Math() - { - } - - static - { - if (Configuration.INIT_LOAD_LIBRARY) - { - System.loadLibrary("javalang"); - } - } - - /** - * A random number generator, initialized on first use. - */ - private static Random rand; - - /** - * The most accurate approximation to the mathematical constant <em>e</em>: - * <code>2.718281828459045</code>. Used in natural log and exp. - * - * @see #log(double) - * @see #exp(double) - */ - public static final double E = 2.718281828459045; - - /** - * The most accurate approximation to the mathematical constant <em>pi</em>: - * <code>3.141592653589793</code>. This is the ratio of a circle's diameter - * to its circumference. - */ - public static final double PI = 3.141592653589793; - - /** - * Take the absolute value of the argument. - * (Absolute value means make it positive.) - * <P> - * - * Note that the the largest negative value (Integer.MIN_VALUE) cannot - * be made positive. In this case, because of the rules of negation in - * a computer, MIN_VALUE is what will be returned. - * This is a <em>negative</em> value. You have been warned. - * - * @param i the number to take the absolute value of - * @return the absolute value - * @see Integer#MIN_VALUE - */ - public static int abs(int i) - { - return (i < 0) ? -i : i; - } - - /** - * Take the absolute value of the argument. - * (Absolute value means make it positive.) - * <P> - * - * Note that the the largest negative value (Long.MIN_VALUE) cannot - * be made positive. In this case, because of the rules of negation in - * a computer, MIN_VALUE is what will be returned. - * This is a <em>negative</em> value. You have been warned. - * - * @param l the number to take the absolute value of - * @return the absolute value - * @see Long#MIN_VALUE - */ - public static long abs(long l) - { - return (l < 0) ? -l : l; - } - - /** - * Take the absolute value of the argument. - * (Absolute value means make it positive.) - * <P> - * - * This is equivalent, but faster than, calling - * <code>Float.intBitsToFloat(0x7fffffff & Float.floatToIntBits(a))</code>. - * - * @param f the number to take the absolute value of - * @return the absolute value - */ - public static float abs(float f) - { - return (f <= 0) ? 0 - f : f; - } - - /** - * Take the absolute value of the argument. - * (Absolute value means make it positive.) - * - * This is equivalent, but faster than, calling - * <code>Double.longBitsToDouble(Double.doubleToLongBits(a) - * << 1) >>> 1);</code>. - * - * @param d the number to take the absolute value of - * @return the absolute value - */ - public static double abs(double d) - { - return (d <= 0) ? 0 - d : d; - } - - /** - * Return whichever argument is smaller. - * - * @param a the first number - * @param b a second number - * @return the smaller of the two numbers - */ - public static int min(int a, int b) - { - return (a < b) ? a : b; - } - - /** - * Return whichever argument is smaller. - * - * @param a the first number - * @param b a second number - * @return the smaller of the two numbers - */ - public static long min(long a, long b) - { - return (a < b) ? a : b; - } - - /** - * Return whichever argument is smaller. If either argument is NaN, the - * result is NaN, and when comparing 0 and -0, -0 is always smaller. - * - * @param a the first number - * @param b a second number - * @return the smaller of the two numbers - */ - public static float min(float a, float b) - { - // this check for NaN, from JLS 15.21.1, saves a method call - if (a != a) - return a; - // no need to check if b is NaN; < will work correctly - // recall that -0.0 == 0.0, but [+-]0.0 - [+-]0.0 behaves special - if (a == 0 && b == 0) - return -(-a - b); - return (a < b) ? a : b; - } - - /** - * Return whichever argument is smaller. If either argument is NaN, the - * result is NaN, and when comparing 0 and -0, -0 is always smaller. - * - * @param a the first number - * @param b a second number - * @return the smaller of the two numbers - */ - public static double min(double a, double b) - { - // this check for NaN, from JLS 15.21.1, saves a method call - if (a != a) - return a; - // no need to check if b is NaN; < will work correctly - // recall that -0.0 == 0.0, but [+-]0.0 - [+-]0.0 behaves special - if (a == 0 && b == 0) - return -(-a - b); - return (a < b) ? a : b; - } - - /** - * Return whichever argument is larger. - * - * @param a the first number - * @param b a second number - * @return the larger of the two numbers - */ - public static int max(int a, int b) - { - return (a > b) ? a : b; - } - - /** - * Return whichever argument is larger. - * - * @param a the first number - * @param b a second number - * @return the larger of the two numbers - */ - public static long max(long a, long b) - { - return (a > b) ? a : b; - } - - /** - * Return whichever argument is larger. If either argument is NaN, the - * result is NaN, and when comparing 0 and -0, 0 is always larger. - * - * @param a the first number - * @param b a second number - * @return the larger of the two numbers - */ - public static float max(float a, float b) - { - // this check for NaN, from JLS 15.21.1, saves a method call - if (a != a) - return a; - // no need to check if b is NaN; > will work correctly - // recall that -0.0 == 0.0, but [+-]0.0 - [+-]0.0 behaves special - if (a == 0 && b == 0) - return a - -b; - return (a > b) ? a : b; - } - - /** - * Return whichever argument is larger. If either argument is NaN, the - * result is NaN, and when comparing 0 and -0, 0 is always larger. - * - * @param a the first number - * @param b a second number - * @return the larger of the two numbers - */ - public static double max(double a, double b) - { - // this check for NaN, from JLS 15.21.1, saves a method call - if (a != a) - return a; - // no need to check if b is NaN; > will work correctly - // recall that -0.0 == 0.0, but [+-]0.0 - [+-]0.0 behaves special - if (a == 0 && b == 0) - return a - -b; - return (a > b) ? a : b; - } - - /** - * The trigonometric function <em>sin</em>. The sine of NaN or infinity is - * NaN, and the sine of 0 retains its sign. This is accurate within 1 ulp, - * and is semi-monotonic. - * - * @param a the angle (in radians) - * @return sin(a) - */ - public static native double sin(double a); - - /** - * The trigonometric function <em>cos</em>. The cosine of NaN or infinity is - * NaN. This is accurate within 1 ulp, and is semi-monotonic. - * - * @param a the angle (in radians) - * @return cos(a) - */ - public static native double cos(double a); - - /** - * The trigonometric function <em>tan</em>. The tangent of NaN or infinity - * is NaN, and the tangent of 0 retains its sign. This is accurate within 1 - * ulp, and is semi-monotonic. - * - * @param a the angle (in radians) - * @return tan(a) - */ - public static native double tan(double a); - - /** - * The trigonometric function <em>arcsin</em>. The range of angles returned - * is -pi/2 to pi/2 radians (-90 to 90 degrees). If the argument is NaN or - * its absolute value is beyond 1, the result is NaN; and the arcsine of - * 0 retains its sign. This is accurate within 1 ulp, and is semi-monotonic. - * - * @param a the sin to turn back into an angle - * @return arcsin(a) - */ - public static native double asin(double a); - - /** - * The trigonometric function <em>arccos</em>. The range of angles returned - * is 0 to pi radians (0 to 180 degrees). If the argument is NaN or - * its absolute value is beyond 1, the result is NaN. This is accurate - * within 1 ulp, and is semi-monotonic. - * - * @param a the cos to turn back into an angle - * @return arccos(a) - */ - public static native double acos(double a); - - /** - * The trigonometric function <em>arcsin</em>. The range of angles returned - * is -pi/2 to pi/2 radians (-90 to 90 degrees). If the argument is NaN, the - * result is NaN; and the arctangent of 0 retains its sign. This is accurate - * within 1 ulp, and is semi-monotonic. - * - * @param a the tan to turn back into an angle - * @return arcsin(a) - * @see #atan2(double, double) - */ - public static native double atan(double a); - - /** - * A special version of the trigonometric function <em>arctan</em>, for - * converting rectangular coordinates <em>(x, y)</em> to polar - * <em>(r, theta)</em>. This computes the arctangent of x/y in the range - * of -pi to pi radians (-180 to 180 degrees). Special cases:<ul> - * <li>If either argument is NaN, the result is NaN.</li> - * <li>If the first argument is positive zero and the second argument is - * positive, or the first argument is positive and finite and the second - * argument is positive infinity, then the result is positive zero.</li> - * <li>If the first argument is negative zero and the second argument is - * positive, or the first argument is negative and finite and the second - * argument is positive infinity, then the result is negative zero.</li> - * <li>If the first argument is positive zero and the second argument is - * negative, or the first argument is positive and finite and the second - * argument is negative infinity, then the result is the double value - * closest to pi.</li> - * <li>If the first argument is negative zero and the second argument is - * negative, or the first argument is negative and finite and the second - * argument is negative infinity, then the result is the double value - * closest to -pi.</li> - * <li>If the first argument is positive and the second argument is - * positive zero or negative zero, or the first argument is positive - * infinity and the second argument is finite, then the result is the - * double value closest to pi/2.</li> - * <li>If the first argument is negative and the second argument is - * positive zero or negative zero, or the first argument is negative - * infinity and the second argument is finite, then the result is the - * double value closest to -pi/2.</li> - * <li>If both arguments are positive infinity, then the result is the - * double value closest to pi/4.</li> - * <li>If the first argument is positive infinity and the second argument - * is negative infinity, then the result is the double value closest to - * 3*pi/4.</li> - * <li>If the first argument is negative infinity and the second argument - * is positive infinity, then the result is the double value closest to - * -pi/4.</li> - * <li>If both arguments are negative infinity, then the result is the - * double value closest to -3*pi/4.</li> - * - * </ul><p>This is accurate within 2 ulps, and is semi-monotonic. To get r, - * use sqrt(x*x+y*y). - * - * @param y the y position - * @param x the x position - * @return <em>theta</em> in the conversion of (x, y) to (r, theta) - * @see #atan(double) - */ - public static native double atan2(double y, double x); - - /** - * Take <em>e</em><sup>a</sup>. The opposite of <code>log()</code>. If the - * argument is NaN, the result is NaN; if the argument is positive infinity, - * the result is positive infinity; and if the argument is negative - * infinity, the result is positive zero. This is accurate within 1 ulp, - * and is semi-monotonic. - * - * @param a the number to raise to the power - * @return the number raised to the power of <em>e</em> - * @see #log(double) - * @see #pow(double, double) - */ - public static native double exp(double a); - - /** - * Take ln(a) (the natural log). The opposite of <code>exp()</code>. If the - * argument is NaN or negative, the result is NaN; if the argument is - * positive infinity, the result is positive infinity; and if the argument - * is either zero, the result is negative infinity. This is accurate within - * 1 ulp, and is semi-monotonic. - * - * <p>Note that the way to get log<sub>b</sub>(a) is to do this: - * <code>ln(a) / ln(b)</code>. - * - * @param a the number to take the natural log of - * @return the natural log of <code>a</code> - * @see #exp(double) - */ - public static native double log(double a); - - /** - * Take a square root. If the argument is NaN or negative, the result is - * NaN; if the argument is positive infinity, the result is positive - * infinity; and if the result is either zero, the result is the same. - * This is accurate within the limits of doubles. - * - * <p>For other roots, use pow(a, 1 / rootNumber). - * - * @param a the numeric argument - * @return the square root of the argument - * @see #pow(double, double) - */ - public static native double sqrt(double a); - - /** - * Raise a number to a power. Special cases:<ul> - * <li>If the second argument is positive or negative zero, then the result - * is 1.0.</li> - * <li>If the second argument is 1.0, then the result is the same as the - * first argument.</li> - * <li>If the second argument is NaN, then the result is NaN.</li> - * <li>If the first argument is NaN and the second argument is nonzero, - * then the result is NaN.</li> - * <li>If the absolute value of the first argument is greater than 1 and - * the second argument is positive infinity, or the absolute value of the - * first argument is less than 1 and the second argument is negative - * infinity, then the result is positive infinity.</li> - * <li>If the absolute value of the first argument is greater than 1 and - * the second argument is negative infinity, or the absolute value of the - * first argument is less than 1 and the second argument is positive - * infinity, then the result is positive zero.</li> - * <li>If the absolute value of the first argument equals 1 and the second - * argument is infinite, then the result is NaN.</li> - * <li>If the first argument is positive zero and the second argument is - * greater than zero, or the first argument is positive infinity and the - * second argument is less than zero, then the result is positive zero.</li> - * <li>If the first argument is positive zero and the second argument is - * less than zero, or the first argument is positive infinity and the - * second argument is greater than zero, then the result is positive - * infinity.</li> - * <li>If the first argument is negative zero and the second argument is - * greater than zero but not a finite odd integer, or the first argument is - * negative infinity and the second argument is less than zero but not a - * finite odd integer, then the result is positive zero.</li> - * <li>If the first argument is negative zero and the second argument is a - * positive finite odd integer, or the first argument is negative infinity - * and the second argument is a negative finite odd integer, then the result - * is negative zero.</li> - * <li>If the first argument is negative zero and the second argument is - * less than zero but not a finite odd integer, or the first argument is - * negative infinity and the second argument is greater than zero but not a - * finite odd integer, then the result is positive infinity.</li> - * <li>If the first argument is negative zero and the second argument is a - * negative finite odd integer, or the first argument is negative infinity - * and the second argument is a positive finite odd integer, then the result - * is negative infinity.</li> - * <li>If the first argument is less than zero and the second argument is a - * finite even integer, then the result is equal to the result of raising - * the absolute value of the first argument to the power of the second - * argument.</li> - * <li>If the first argument is less than zero and the second argument is a - * finite odd integer, then the result is equal to the negative of the - * result of raising the absolute value of the first argument to the power - * of the second argument.</li> - * <li>If the first argument is finite and less than zero and the second - * argument is finite and not an integer, then the result is NaN.</li> - * <li>If both arguments are integers, then the result is exactly equal to - * the mathematical result of raising the first argument to the power of - * the second argument if that result can in fact be represented exactly as - * a double value.</li> - * - * </ul><p>(In the foregoing descriptions, a floating-point value is - * considered to be an integer if and only if it is a fixed point of the - * method {@link #ceil(double)} or, equivalently, a fixed point of the - * method {@link #floor(double)}. A value is a fixed point of a one-argument - * method if and only if the result of applying the method to the value is - * equal to the value.) This is accurate within 1 ulp, and is semi-monotonic. - * - * @param a the number to raise - * @param b the power to raise it to - * @return a<sup>b</sup> - */ - public static native double pow(double a, double b); - - /** - * Get the IEEE 754 floating point remainder on two numbers. This is the - * value of <code>x - y * <em>n</em></code>, where <em>n</em> is the closest - * double to <code>x / y</code> (ties go to the even n); for a zero - * remainder, the sign is that of <code>x</code>. If either argument is NaN, - * the first argument is infinite, or the second argument is zero, the result - * is NaN; if x is finite but y is infinite, the result is x. This is - * accurate within the limits of doubles. - * - * @param x the dividend (the top half) - * @param y the divisor (the bottom half) - * @return the IEEE 754-defined floating point remainder of x/y - * @see #rint(double) - */ - public static native double IEEEremainder(double x, double y); - - /** - * Take the nearest integer that is that is greater than or equal to the - * argument. If the argument is NaN, infinite, or zero, the result is the - * same; if the argument is between -1 and 0, the result is negative zero. - * Note that <code>Math.ceil(x) == -Math.floor(-x)</code>. - * - * @param a the value to act upon - * @return the nearest integer >= <code>a</code> - */ - public static native double ceil(double a); - - /** - * Take the nearest integer that is that is less than or equal to the - * argument. If the argument is NaN, infinite, or zero, the result is the - * same. Note that <code>Math.ceil(x) == -Math.floor(-x)</code>. - * - * @param a the value to act upon - * @return the nearest integer <= <code>a</code> - */ - public static native double floor(double a); - - /** - * Take the nearest integer to the argument. If it is exactly between - * two integers, the even integer is taken. If the argument is NaN, - * infinite, or zero, the result is the same. - * - * @param a the value to act upon - * @return the nearest integer to <code>a</code> - */ - public static native double rint(double a); - - /** - * Take the nearest integer to the argument. This is equivalent to - * <code>(int) Math.floor(a + 0.5f)</code>. If the argument is NaN, the result - * is 0; otherwise if the argument is outside the range of int, the result - * will be Integer.MIN_VALUE or Integer.MAX_VALUE, as appropriate. - * - * @param a the argument to round - * @return the nearest integer to the argument - * @see Integer#MIN_VALUE - * @see Integer#MAX_VALUE - */ - public static int round(float a) - { - // this check for NaN, from JLS 15.21.1, saves a method call - if (a != a) - return 0; - return (int) floor(a + 0.5f); - } - - /** - * Take the nearest long to the argument. This is equivalent to - * <code>(long) Math.floor(a + 0.5)</code>. If the argument is NaN, the - * result is 0; otherwise if the argument is outside the range of long, the - * result will be Long.MIN_VALUE or Long.MAX_VALUE, as appropriate. - * - * @param a the argument to round - * @return the nearest long to the argument - * @see Long#MIN_VALUE - * @see Long#MAX_VALUE - */ - public static long round(double a) - { - // this check for NaN, from JLS 15.21.1, saves a method call - if (a != a) - return 0; - return (long) floor(a + 0.5d); - } - - /** - * Get a random number. This behaves like Random.nextDouble(), seeded by - * System.currentTimeMillis() when first called. In other words, the number - * is from a pseudorandom sequence, and lies in the range [+0.0, 1.0). - * This random sequence is only used by this method, and is threadsafe, - * although you may want your own random number generator if it is shared - * among threads. - * - * @return a random number - * @see Random#nextDouble() - * @see System#currentTimeMillis() - */ - public static synchronized double random() - { - if (rand == null) - rand = new Random(); - return rand.nextDouble(); - } - - /** - * Convert from degrees to radians. The formula for this is - * radians = degrees * (pi/180); however it is not always exact given the - * limitations of floating point numbers. - * - * @param degrees an angle in degrees - * @return the angle in radians - * @since 1.2 - */ - public static double toRadians(double degrees) - { - return (degrees * PI) / 180; - } - - /** - * Convert from radians to degrees. The formula for this is - * degrees = radians * (180/pi); however it is not always exact given the - * limitations of floating point numbers. - * - * @param rads an angle in radians - * @return the angle in degrees - * @since 1.2 - */ - public static double toDegrees(double rads) - { - return (rads * 180) / PI; - } -} diff --git a/libjava/java/lang/NegativeArraySizeException.java b/libjava/java/lang/NegativeArraySizeException.java deleted file mode 100644 index fcfa52e475c..00000000000 --- a/libjava/java/lang/NegativeArraySizeException.java +++ /dev/null @@ -1,77 +0,0 @@ -/* NegativeArraySizeException.java -- thrown on attempt to create array - with a negative size - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang; - -/** - * Thrown when an attempt is made to create an array with a negative - * size. For example:<br> - * <pre> - * int i = -1; - * int[] array = new int[i]; - * </pre> - * - * @author Brian Jones - * @author Warren Levy (warrenl@cygnus.com) - * @status updated to 1.4 - */ -public class NegativeArraySizeException extends RuntimeException -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = -8960118058596991861L; - - /** - * Create an exception without a message. - */ - public NegativeArraySizeException() - { - } - - /** - * Create an exception with a message. - * - * @param s the message - */ - public NegativeArraySizeException(String s) - { - super(s); - } -} diff --git a/libjava/java/lang/NoClassDefFoundError.java b/libjava/java/lang/NoClassDefFoundError.java deleted file mode 100644 index 7e8e6caff80..00000000000 --- a/libjava/java/lang/NoClassDefFoundError.java +++ /dev/null @@ -1,76 +0,0 @@ -/* NoClassDefFoundError.java -- thrown when a ClassLoader cannot find a class - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang; - -/** - * A <code>NoClassDefFoundError</code> is thrown when a classloader or the - * Java Virtual Machine tries to load a class and no definition of the class - * can be found. This could happen when using the <code>new</code> expression - * or during a normal method call. The reason this would occur at runtime is - * because the missing class definition existed when the currently executing - * class was compiled, but now that definition cannot be found. - * - * @author Brian Jones - * @author Tom Tromey (tromey@cygnus.com) - * @status updated to 1.4 - */ -public class NoClassDefFoundError extends LinkageError -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = 9095859863287012458L; - - /** - * Create an error without a message. - */ - public NoClassDefFoundError() - { - } - - /** - * Create an error with a message. - * - * @param s the message - */ - public NoClassDefFoundError(String s) - { - super(s); - } -} diff --git a/libjava/java/lang/NoSuchFieldError.java b/libjava/java/lang/NoSuchFieldError.java deleted file mode 100644 index af42e35dcf2..00000000000 --- a/libjava/java/lang/NoSuchFieldError.java +++ /dev/null @@ -1,74 +0,0 @@ -/* NoSuchFieldError.java -- thrown when the linker does not find a field - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang; - -/** - * A <code>NoSuchFieldError</code> is thrown if an application attempts - * to access a field of a class, and that class no longer has that field. - * This is normally detected by the compiler, so it signals that you are - * using binary incompatible class versions. - * - * @author Brian Jones - * @author Tom Tromey (tromey@cygnus.com) - * @status updated to 1.4 - */ -public class NoSuchFieldError extends IncompatibleClassChangeError -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = -3456430195886129035L; - - /** - * Create an error without a message. - */ - public NoSuchFieldError() - { - } - - /** - * Create an error with a message. - * - * @param s the message - */ - public NoSuchFieldError(String s) - { - super(s); - } -} diff --git a/libjava/java/lang/NoSuchFieldException.java b/libjava/java/lang/NoSuchFieldException.java deleted file mode 100644 index 74d52d137c4..00000000000 --- a/libjava/java/lang/NoSuchFieldException.java +++ /dev/null @@ -1,73 +0,0 @@ -/* NoSuchFieldException.java -- thrown when reflecting a non-existant field - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang; - -/** - * Thrown to indicate the class does not have the specified field. This is - * caused by a variety of reflection methods, when looking up a field by name. - * - * @author Brian Jones - * @author Warren Levy (warrenl@cygnus.com) - * @since 1.1 - * @status updated to 1.4 - */ -public class NoSuchFieldException extends Exception -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = -6143714805279938260L; - - /** - * Create an exception without a message. - */ - public NoSuchFieldException() - { - } - - /** - * Create an exception with a message. - * - * @param s the message - */ - public NoSuchFieldException(String s) - { - super(s); - } -} diff --git a/libjava/java/lang/NoSuchMethodError.java b/libjava/java/lang/NoSuchMethodError.java deleted file mode 100644 index 2bda776e8e9..00000000000 --- a/libjava/java/lang/NoSuchMethodError.java +++ /dev/null @@ -1,74 +0,0 @@ -/* NoSuchMethodError.java -- thrown when the linker does not find a method - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang; - -/** - * A <code>NoSuchMethodError</code> is thrown if an application attempts - * to access a method of a class, and that class no longer has that method. - * This is normally detected by the compiler, so it signals that you are - * using binary incompatible class versions. - * - * @author Brian Jones - * @author Tom Tromey (tromey@cygnus.com) - * @status updated to 1.4 - */ -public class NoSuchMethodError extends IncompatibleClassChangeError -{ - /** - * Compatible with JDK 1.0+. - */ - static final long serialVersionUID = -3765521442372831335L; - - /** - * Create an error without a message. - */ - public NoSuchMethodError() - { - } - - /** - * Create an error with a message. - * - * @param s the message - */ - public NoSuchMethodError(String s) - { - super(s); - } -} diff --git a/libjava/java/lang/NoSuchMethodException.java b/libjava/java/lang/NoSuchMethodException.java deleted file mode 100644 index e423efb79f6..00000000000 --- a/libjava/java/lang/NoSuchMethodException.java +++ /dev/null @@ -1,72 +0,0 @@ -/* NoSuchMethodException.java -- thrown when reflecting a non-existant method - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang; - -/** - * Thrown to indicate the class does not have the specified method. This is - * caused by a variety of reflection methods, when looking up a method by name. - * - * @author Brian Jones - * @author Warren Levy (warrenl@cygnus.com) - * @status updated to 1.4 - */ -public class NoSuchMethodException extends Exception -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = 5034388446362600923L; - - /** - * Create an exception without a message. - */ - public NoSuchMethodException() - { - } - - /** - * Create an exception with a message. - * - * @param s the message - */ - public NoSuchMethodException(String s) - { - super(s); - } -} diff --git a/libjava/java/lang/NullPointerException.java b/libjava/java/lang/NullPointerException.java deleted file mode 100644 index 29a4ee086c5..00000000000 --- a/libjava/java/lang/NullPointerException.java +++ /dev/null @@ -1,82 +0,0 @@ -/* NullPointerException.java -- thrown when using null instead of an object - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang; - -/** - * Thrown when attempting to use <code>null</code> where an object - * is required. The Virtual Machine automatically throws this exception - * for the following:<br><ul> - * <li>Calling an instance method on a null object</li> - * <li>Accessing or modifying a field of a null object</li> - * <li>Taking the array length of a null array</li> - * <li>Accessing or modifying the slots of a null array</li> - * <li>Throwing a null Throwable</li> - * <li>Synchronizing on a null object</li> - * </ul> - * <p>Applications should also throw NullPointerExceptions whenever - * <code>null</code> is an inappropriate parameter to a method. - * - * @author Brian Jones - * @author Warren Levy (warrenl@cygnus.com) - * @status updated to 1.4 - */ -public class NullPointerException extends RuntimeException -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = 5162710183389028792L; - - /** - * Create an exception without a message. - */ - public NullPointerException() - { - } - - /** - * Create an exception with a message. - * - * @param s the message - */ - public NullPointerException(String s) - { - super(s); - } -} diff --git a/libjava/java/lang/Number.java b/libjava/java/lang/Number.java deleted file mode 100644 index eb81f78c86e..00000000000 --- a/libjava/java/lang/Number.java +++ /dev/null @@ -1,131 +0,0 @@ -/* Number.java =- abstract superclass of numeric objects - Copyright (C) 1998, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang; - -import java.io.Serializable; - -/** - * Number is a generic superclass of all the numeric classes, including - * the wrapper classes {@link Byte}, {@link Short}, {@link Integer}, - * {@link Long}, {@link Float}, and {@link Double}. Also worth mentioning - * are the classes in {@link java.math}. - * - * It provides ways to convert numeric objects to any primitive. - * - * @author Paul Fisher - * @author John Keiser - * @author Warren Levy - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.0 - * @status updated to 1.4 - */ -public abstract class Number implements Serializable -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = -8742448824652078965L; - - /** - * Table for calculating digits, used in Character, Long, and Integer. - */ - static final char[] digits = { - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', - 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', - 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', - 'u', 'v', 'w', 'x', 'y', 'z', - }; - - /** - * The basic constructor (often called implicitly). - */ - public Number() - { - } - - /** - * Return the value of this <code>Number</code> as an <code>int</code>. - * - * @return the int value - */ - public abstract int intValue(); - - /** - * Return the value of this <code>Number</code> as a <code>long</code>. - * - * @return the long value - */ - public abstract long longValue(); - - /** - * Return the value of this <code>Number</code> as a <code>float</code>. - * - * @return the float value - */ - public abstract float floatValue(); - - /** - * Return the value of this <code>Number</code> as a <code>float</code>. - * - * @return the double value - */ - public abstract double doubleValue(); - - /** - * Return the value of this <code>Number</code> as a <code>byte</code>. - * - * @return the byte value - * @since 1.1 - */ - public byte byteValue() - { - return (byte) intValue(); - } - - /** - * Return the value of this <code>Number</code> as a <code>short</code>. - * - * @return the short value - * @since 1.1 - */ - public short shortValue() - { - return (short) intValue(); - } -} diff --git a/libjava/java/lang/NumberFormatException.java b/libjava/java/lang/NumberFormatException.java deleted file mode 100644 index bf98156d13c..00000000000 --- a/libjava/java/lang/NumberFormatException.java +++ /dev/null @@ -1,73 +0,0 @@ -/* NumberFormatException.java -- thrown when parsing a bad string as a number - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang; - -/** - * Can be thrown when attempting to convert a <code>String</code> to - * one of the numeric types, but the operation fails because the string - * has the wrong format. - * - * @author Brian Jones - * @author Warren Levy (warrenl@cygnus.com) - * @status updated to 1.4 - */ -public class NumberFormatException extends IllegalArgumentException -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = -2848938806368998894L; - - /** - * Create an exception without a message. - */ - public NumberFormatException() - { - } - - /** - * Create an exception with a message. - * - * @param s the message - */ - public NumberFormatException(String s) - { - super(s); - } -} diff --git a/libjava/java/lang/OutOfMemoryError.java b/libjava/java/lang/OutOfMemoryError.java deleted file mode 100644 index 66da563a0fb..00000000000 --- a/libjava/java/lang/OutOfMemoryError.java +++ /dev/null @@ -1,73 +0,0 @@ -/* OutOfMemoryError.java -- thrown when a memory allocation fails - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang; - -/** - * Thrown when the Java Virtual Machine is unable to allocate an object - * because it is out of memory and no more memory could be made available - * by the garbage collector. - * - * @author Brian Jones - * @author Tom Tromey (tromey@cygnus.com) - * @status updated to 1.4 - */ -public class OutOfMemoryError extends VirtualMachineError -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = 8228564086184010517L; - - /** - * Create an error without a message. - */ - public OutOfMemoryError() - { - } - - /** - * Create an error with a message. - * - * @param s the message - */ - public OutOfMemoryError(String s) - { - super(s); - } -} diff --git a/libjava/java/lang/Process.java b/libjava/java/lang/Process.java deleted file mode 100644 index b6e18ca4df3..00000000000 --- a/libjava/java/lang/Process.java +++ /dev/null @@ -1,129 +0,0 @@ -/* Process.java - Represent spawned system process - Copyright (C) 1998, 1999, 2001, 2002, 2003, 2004, 2005 - Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang; - -import java.io.InputStream; -import java.io.OutputStream; - -/** - * An instance of a subclass of <code>Process</code> is created by the - * <code>Runtime.exec</code> methods. Methods in <code>Process</code> - * provide a means to send input to a process, obtain the output from a - * subprocess, destroy a subprocess, obtain the exit value from a - * subprocess, and wait for a subprocess to complete. - * - * <p>This is dependent on the platform, and some processes (like native - * windowing processes, 16-bit processes in Windows, or shell scripts) may - * be limited in functionality. Because some platforms have limited buffers - * between processes, you may need to provide input and read output to prevent - * the process from blocking, or even deadlocking. - * - * <p>Even if all references to this object disapper, the process continues - * to execute to completion. There are no guarantees that the - * subprocess execute asynchronously or concurrently with the process which - * owns this object. - * - * @author Brian Jones - * @author Tom Tromey (tromey@cygnus.com) - * @see Runtime#exec(String[], String[], File) - * @since 1.0 - * @status updated to 1.4 - */ -public abstract class Process -{ - /** - * Empty constructor does nothing. - */ - public Process() - { - } - - /** - * Obtain the output stream that sends data to the subprocess. This is - * the STDIN of the subprocess. When implementing, you should probably - * use a buffered stream. - * - * @return the output stream that pipes to the process input - */ - public abstract OutputStream getOutputStream(); - - /** - * Obtain the input stream that receives data from the subprocess. This is - * the STDOUT of the subprocess. When implementing, you should probably - * use a buffered stream. - * - * @return the input stream that pipes data from the process output - */ - public abstract InputStream getInputStream(); - - /** - * Obtain the input stream that receives data from the subprocess. This is - * the STDERR of the subprocess. When implementing, you should probably - * use a buffered stream. - * - * @return the input stream that pipes data from the process error output - */ - public abstract InputStream getErrorStream(); - - /** - * The thread calling <code>waitFor</code> will block until the subprocess - * has terminated. If the process has already terminated then the method - * immediately returns with the exit value of the subprocess. - * - * @return the subprocess exit value; 0 conventionally denotes success - * @throws InterruptedException if another thread interrupts the blocked one - */ - public abstract int waitFor() throws InterruptedException; - - /** - * When a process terminates there is associated with that termination - * an exit value for the process to indicate why it terminated. A return - * of <code>0</code> denotes normal process termination by convention. - * - * @return the exit value of the subprocess - * @throws IllegalThreadStateException if the subprocess has not terminated - */ - public abstract int exitValue(); - - /** - * Kills the subprocess and all of its children forcibly. - */ - public abstract void destroy(); -} // class Process diff --git a/libjava/java/lang/Runnable.java b/libjava/java/lang/Runnable.java deleted file mode 100644 index 32c52b94a05..00000000000 --- a/libjava/java/lang/Runnable.java +++ /dev/null @@ -1,62 +0,0 @@ -/* Runnable -- interface for a method tied to an Object; often for Threads - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang; - -/** - * Runnable is an interface you implement to indicate that your class can be - * executed as the main part of a Thread, among other places. When you want - * an entry point to run a piece of code, implement this interface and - * override run. - * - * @author Paul Fisher - * @author Tom Tromey (tromey@cygnus.com) - * @see Thread - * @since 1.0 - * @status updated to 1.4 - */ -public interface Runnable -{ - /** - * This method will be called by whoever wishes to run your class - * implementing Runnable. Note that there are no restrictions on what - * you are allowed to do in the run method, except that you cannot - * throw a checked exception. - */ - void run(); -} diff --git a/libjava/java/lang/RuntimeException.java b/libjava/java/lang/RuntimeException.java deleted file mode 100644 index 72cf0872bc7..00000000000 --- a/libjava/java/lang/RuntimeException.java +++ /dev/null @@ -1,102 +0,0 @@ -/* RuntimeException.java -- root of all unchecked exceptions - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang; - -/** - * All exceptions which are subclasses of <code>RuntimeException</code> - * can be thrown at any time during the execution of a Java virtual machine. - * Methods which throw these exceptions are not required to declare them - * in their throws clause. - * - * @author Brian Jones - * @author Warren Levy (warrenl@cygnus.com) - * @author Eric Blake (ebb9@email.byu.edu) - * @status updated to 1.4 - */ -public class RuntimeException extends Exception -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = -7034897190745766939L; - - /** - * Create an exception without a message. The cause remains uninitialized. - * - * @see #initCause(Throwable) - */ - public RuntimeException() - { - } - - /** - * Create an exception with a message. The cause remains uninitialized. - * - * @param s the message string - * @see #initCause(Throwable) - */ - public RuntimeException(String s) - { - super(s); - } - - /** - * Create an exception with a message and a cause. - * - * @param s the message string - * @param cause the cause of this exception - * @since 1.4 - */ - public RuntimeException(String s, Throwable cause) - { - super(s, cause); - } - - /** - * Create an exception with the given cause, and a message of - * <code>cause == null ? null : cause.toString()</code>. - * - * @param cause the cause of this exception - * @since 1.4 - */ - public RuntimeException(Throwable cause) - { - super(cause); - } -} diff --git a/libjava/java/lang/RuntimePermission.java b/libjava/java/lang/RuntimePermission.java deleted file mode 100644 index ca33307d12b..00000000000 --- a/libjava/java/lang/RuntimePermission.java +++ /dev/null @@ -1,208 +0,0 @@ -/* RuntimePermission.java -- permission for a secure runtime action - Copyright (C) 1998, 2000, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang; - -import java.security.BasicPermission; - -/** - * A <code>RuntimePermission</code> contains a permission name, but no - * actions list. This means you either have the permission or you don't. - * - * Permission names have the follow the hierarchial property naming - * convention. In addition, an asterisk may appear at the end of a - * name if following a period or by itself. - * - * <table border=1> - * <tr><th>Valid names</th><th>Invalid names</th></tr> - * <tr><td>"accessClassInPackage.*","*"</td> - * <td>"**", "*x", "*.a"</td></tr> - * </table> - * <br> - * - * The following table provides a list of all the possible RuntimePermission - * permission names with a description of what that permission allows.<br> - * <table border=1> - * <tr><th>Permission Name</th><th>Permission Allows</th><th>Risks</th</tr> - * <tr> - * <td><code>createClassLoader</code></td> - * <td>creation of a class loader</td> - * <td>a class loader can load rogue classes which bypass all security - * permissions</td></tr> - * <tr> - * <td><code>getClassLoader</code></td> - * <td>retrieval of the class loader for the calling class</td> - * <td>rogue code could load classes not otherwise available</td></tr> - * <tr> - * <td><code>setContextClassLoader</code></td> - * <td>allows the setting of the context class loader used by a thread</td> - * <td>rogue code could change the context class loader needed by system - * threads</td></tr> - * <tr> - * <td><code>setSecurityManager</code></td> - * <td>allows the application to replace the security manager</td> - * <td>the new manager may be less restrictive, so that rogue code can - * bypass existing security checks</td></tr> - * <tr> - * <td><code>createSecurityManager</code></td> - * <td>allows the application to create a new security manager</td> - * <td>rogue code can use the new security manager to discover information - * about the execution stack</td></tr> - * <tr> - * <td><code>exitVM</code></td> - * <td>allows the application to halt the virtual machine</td> - * <td>rogue code can mount a denial-of-service attack by killing the - * virtual machine</td></tr> - * <tr> - * <td><code>shutdownHooks</code></td> - * <td>allows registration and modification of shutdown hooks</td> - * <td>rogue code can add a hook that interferes with clean - * virtual machine shutdown</td></tr> - * <tr> - * <td><code>setFactory</code></td> - * <td>allows the application to set the socket factory for socket, - * server socket, stream handler, or RMI socket factory.</td> - * <td>rogue code can create a rogue network object which mangles or - * intercepts data</td></tr> - * <tr> - * <td><code>setIO</code></td> - * <td>allows the application to set System.out, System.in, and - * System.err</td> - * <td>rogue code could sniff user input and intercept or mangle - * output</td></tr> - * <tr> - * <td><code>modifyThread</code></td> - * <td>allows the application to modify any thread in the virtual machine - * using any of the methods <code>stop</code>, <code>resume</code>, - * <code>suspend</code>, <code>setPriority</code>, and - * <code>setName</code> of classs <code>Thread</code></td> - * <td>rogue code could adversely modify system or user threads</td></tr> - * <tr> - * <td><code>stopThread</code></td> - * <td>allows the application to <code>stop</code> any thread it has - * access to in the system</td> - * <td>rogue code can stop arbitrary threads</td></tr> - * <tr> - * <td><code>modifyThreadGroup</code></td> - * <td>allows the application to modify thread groups using any of the - * methods <code>destroy</code>, <code>resume</code>, - * <code>setDaemon</code>, <code>setMaxPriority</code>, - * <code>stop</code>, and <code>suspend</code> of the class - * <code>ThreadGroup</code></td> - * <td>rogue code can mount a denial-of-service attack by changing run - * priorities</td></tr> - * <tr> - * <td><code>getProtectionDomain</code></td> - * <td>retrieve a class's ProtectionDomain</td> - * <td>rogue code can gain information about the security policy, to - * prepare a better attack</td></tr> - * <tr> - * <td><code>readFileDescriptor</code></td> - * <td>read a file descriptor</td> - * <td>rogue code can read sensitive information</td></tr> - * <tr> - * <td><code>writeFileDescriptor</code></td> - * <td>write a file descriptor</td> - * <td>rogue code can write files, including viruses, and can modify the - * virtual machine binary; if not just fill up the disk</td></tr> - * <tr> - * <td><code>loadLibrary.</code><em>library name</em></td> - * <td>dynamic linking of the named library</td> - * <td>native code can bypass many security checks of pure Java</td></tr> - * <tr> - * <td><code>accessClassInPackage.</code><em>package name</em></td> - * <td>access to a package via a ClassLoader</td> - * <td>rogue code can access classes not normally available</td></tr> - * <tr> - * <td><code>defineClassInPackage.</code><em>package name</em></td> - * <td>define a class inside a given package</td> - * <td>rogue code can install rogue classes, including in trusted packages - * like java.security or java.lang</td></tr> - * <tr> - * <td><code>accessDeclaredMembers</code></td> - * <td>access declared class members via reflection</td> - * <td>rogue code can discover information, invoke methods, or modify fields - * that are not otherwise available</td></tr> - * <tr> - * <td><code>queuePrintJob</code></td> - * <td>initiate a print job</td> - * <td>rogue code could make a hard copy of sensitive information, or - * simply waste paper</td></tr> - * </table> - * - * @author Brian Jones - * @author Eric Blake (ebb9@email.byu.edu) - * @see BasicPermission - * @see Permission - * @see SecurityManager - * @since 1.2 - * @status updated to 1.4 - */ -public final class RuntimePermission extends BasicPermission -{ - /** - * Compatible with JDK 1.2+. - */ - private static final long serialVersionUID = 7399184964622342223L; - - /** - * Create a new permission with the specified name. - * - * @param permissionName the name of the granted permission - * @throws NullPointerException if name is null - * @throws IllegalArgumentException thrown if name is empty or invalid - */ - public RuntimePermission(String permissionName) - { - super(permissionName); - } - - /** - * Create a new permission with the specified name. The actions argument - * is ignored, as runtime permissions have no actions. - * - * @param permissionName the name of the granted permission - * @param actions ignored - * @throws NullPointerException if name is null - * @throws IllegalArgumentException thrown if name is empty or invalid - */ - public RuntimePermission(String permissionName, String actions) - { - super(permissionName); - } -} diff --git a/libjava/java/lang/SecurityException.java b/libjava/java/lang/SecurityException.java deleted file mode 100644 index a95d797054f..00000000000 --- a/libjava/java/lang/SecurityException.java +++ /dev/null @@ -1,74 +0,0 @@ -/* SecurityException.java -- thrown to indicate a security violation - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang; - -/** - * The security manager will throw this exception to indicate a security - * violation. This can occur any time an operation is attempted which is - * deemed unsafe by the current security policies. - * - * @author Brian Jones - * @author Warren Levy (warrenl@cygnus.com) - * @see SecurityManager - * @status updated to 1.4 - */ -public class SecurityException extends RuntimeException -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = 6878364983674394167L; - - /** - * Create an exception without a message. - */ - public SecurityException() - { - } - - /** - * Create an exception with a message. - * - * @param s the message - */ - public SecurityException(String s) - { - super(s); - } -} diff --git a/libjava/java/lang/Short.java b/libjava/java/lang/Short.java deleted file mode 100644 index fbeea915bd3..00000000000 --- a/libjava/java/lang/Short.java +++ /dev/null @@ -1,353 +0,0 @@ -/* Short.java -- object wrapper for short - Copyright (C) 1998, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang; - -/** - * Instances of class <code>Short</code> represent primitive - * <code>short</code> values. - * - * Additionally, this class provides various helper functions and variables - * related to shorts. - * - * @author Paul Fisher - * @author John Keiser - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.1 - * @status updated to 1.4 - */ -public final class Short extends Number implements Comparable -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = 7515723908773894738L; - - /** - * The minimum value a <code>short</code> can represent is -32768 (or - * -2<sup>15</sup>). - */ - public static final short MIN_VALUE = -32768; - - /** - * The minimum value a <code>short</code> can represent is 32767 (or - * 2<sup>15</sup>). - */ - public static final short MAX_VALUE = 32767; - - /** - * The primitive type <code>short</code> is represented by this - * <code>Class</code> object. - */ - public static final Class TYPE = VMClassLoader.getPrimitiveClass('S'); - - /** - * The immutable value of this Short. - * - * @serial the wrapped short - */ - private final short value; - - /** - * Create a <code>Short</code> object representing the value of the - * <code>short</code> argument. - * - * @param value the value to use - */ - public Short(short value) - { - this.value = value; - } - - /** - * Create a <code>Short</code> object representing the value of the - * argument after conversion to a <code>short</code>. - * - * @param s the string to convert - * @throws NumberFormatException if the String cannot be parsed - */ - public Short(String s) - { - value = parseShort(s, 10); - } - - /** - * Converts the <code>short</code> to a <code>String</code> and assumes - * a radix of 10. - * - * @param s the <code>short</code> to convert to <code>String</code> - * @return the <code>String</code> representation of the argument - */ - public static String toString(short s) - { - return String.valueOf(s); - } - - /** - * Converts the specified <code>String</code> into a <code>short</code>. - * This function assumes a radix of 10. - * - * @param s the <code>String</code> to convert - * @return the <code>short</code> value of <code>s</code> - * @throws NumberFormatException if <code>s</code> cannot be parsed as a - * <code>short</code> - */ - public static short parseShort(String s) - { - return parseShort(s, 10); - } - - /** - * Converts the specified <code>String</code> into a <code>short</code> - * using the specified radix (base). The string must not be <code>null</code> - * or empty. It may begin with an optional '-', which will negate the answer, - * provided that there are also valid digits. Each digit is parsed as if by - * <code>Character.digit(d, radix)</code>, and must be in the range - * <code>0</code> to <code>radix - 1</code>. Finally, the result must be - * within <code>MIN_VALUE</code> to <code>MAX_VALUE</code>, inclusive. - * Unlike Double.parseDouble, you may not have a leading '+'. - * - * @param s the <code>String</code> to convert - * @param radix the radix (base) to use in the conversion - * @return the <code>String</code> argument converted to <code>short</code> - * @throws NumberFormatException if <code>s</code> cannot be parsed as a - * <code>short</code> - */ - public static short parseShort(String s, int radix) - { - int i = Integer.parseInt(s, radix, false); - if ((short) i != i) - throw new NumberFormatException(); - return (short) i; - } - - /** - * Creates a new <code>Short</code> object using the <code>String</code> - * and specified radix (base). - * - * @param s the <code>String</code> to convert - * @param radix the radix (base) to convert with - * @return the new <code>Short</code> - * @throws NumberFormatException if <code>s</code> cannot be parsed as a - * <code>short</code> - * @see #parseShort(String, int) - */ - public static Short valueOf(String s, int radix) - { - return new Short(parseShort(s, radix)); - } - - /** - * Creates a new <code>Short</code> object using the <code>String</code>, - * assuming a radix of 10. - * - * @param s the <code>String</code> to convert - * @return the new <code>Short</code> - * @throws NumberFormatException if <code>s</code> cannot be parsed as a - * <code>short</code> - * @see #Short(String) - * @see #parseShort(String) - */ - public static Short valueOf(String s) - { - return new Short(parseShort(s, 10)); - } - - /** - * Convert the specified <code>String</code> into a <code>Short</code>. - * The <code>String</code> may represent decimal, hexadecimal, or - * octal numbers. - * - * <p>The extended BNF grammar is as follows:<br> - * <pre> - * <em>DecodableString</em>: - * ( [ <code>-</code> ] <em>DecimalNumber</em> ) - * | ( [ <code>-</code> ] ( <code>0x</code> | <code>0X</code> - * | <code>#</code> ) <em>HexDigit</em> { <em>HexDigit</em> } ) - * | ( [ <code>-</code> ] <code>0</code> { <em>OctalDigit</em> } ) - * <em>DecimalNumber</em>: - * <em>DecimalDigit except '0'</em> { <em>DecimalDigit</em> } - * <em>DecimalDigit</em>: - * <em>Character.digit(d, 10) has value 0 to 9</em> - * <em>OctalDigit</em>: - * <em>Character.digit(d, 8) has value 0 to 7</em> - * <em>DecimalDigit</em>: - * <em>Character.digit(d, 16) has value 0 to 15</em> - * </pre> - * Finally, the value must be in the range <code>MIN_VALUE</code> to - * <code>MAX_VALUE</code>, or an exception is thrown. - * - * @param s the <code>String</code> to interpret - * @return the value of the String as a <code>Short</code> - * @throws NumberFormatException if <code>s</code> cannot be parsed as a - * <code>short</code> - * @throws NullPointerException if <code>s</code> is null - * @see Integer#decode(String) - */ - public static Short decode(String s) - { - int i = Integer.parseInt(s, 10, true); - if ((short) i != i) - throw new NumberFormatException(); - return new Short((short) i); - } - - /** - * Return the value of this <code>Short</code> as a <code>byte</code>. - * - * @return the byte value - */ - public byte byteValue() - { - return (byte) value; - } - - /** - * Return the value of this <code>Short</code>. - * - * @return the short value - */ - public short shortValue() - { - return value; - } - - /** - * Return the value of this <code>Short</code> as an <code>int</code>. - * - * @return the int value - */ - public int intValue() - { - return value; - } - - /** - * Return the value of this <code>Short</code> as a <code>long</code>. - * - * @return the long value - */ - public long longValue() - { - return value; - } - - /** - * Return the value of this <code>Short</code> as a <code>float</code>. - * - * @return the float value - */ - public float floatValue() - { - return value; - } - - /** - * Return the value of this <code>Short</code> as a <code>double</code>. - * - * @return the double value - */ - public double doubleValue() - { - return value; - } - - /** - * Converts the <code>Short</code> value to a <code>String</code> and - * assumes a radix of 10. - * - * @return the <code>String</code> representation of this <code>Short</code> - */ - public String toString() - { - return String.valueOf(value); - } - - /** - * Return a hashcode representing this Object. <code>Short</code>'s hash - * code is simply its value. - * - * @return this Object's hash code - */ - public int hashCode() - { - return value; - } - - /** - * Returns <code>true</code> if <code>obj</code> is an instance of - * <code>Short</code> and represents the same short value. - * - * @param obj the object to compare - * @return whether these Objects are semantically equal - */ - public boolean equals(Object obj) - { - return obj instanceof Short && value == ((Short) obj).value; - } - - /** - * Compare two Shorts numerically by comparing their <code>short</code> - * values. The result is positive if the first is greater, negative if the - * second is greater, and 0 if the two are equal. - * - * @param s the Short to compare - * @return the comparison - * @since 1.2 - */ - public int compareTo(Short s) - { - return value - s.value; - } - - /** - * Behaves like <code>compareTo(Short)</code> unless the Object - * is not a <code>Short</code>. - * - * @param o the object to compare - * @return the comparison - * @throws ClassCastException if the argument is not a <code>Short</code> - * @see #compareTo(Short) - * @see Comparable - * @since 1.2 - */ - public int compareTo(Object o) - { - return compareTo((Short)o); - } -} diff --git a/libjava/java/lang/StackOverflowError.java b/libjava/java/lang/StackOverflowError.java deleted file mode 100644 index 5188ddda159..00000000000 --- a/libjava/java/lang/StackOverflowError.java +++ /dev/null @@ -1,72 +0,0 @@ -/* StackOverflowError.java -- thrown when the stack depth is exceeded - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang; - -/** - * A <code>StackOverflowError</code> is thrown when the execution stack - * overflow occurs. This often occurs when a method enters infinit recursion. - * - * @author Brian Jones - * @author Tom Tromey (tromey@cygnus.com) - * @status updated to 1.4 - */ -public class StackOverflowError extends VirtualMachineError -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = 8609175038441759607L; - - /** - * Create an error without a message. - */ - public StackOverflowError() - { - } - - /** - * Create an error with a message. - * - * @param s the message - */ - public StackOverflowError(String s) - { - super(s); - } -} diff --git a/libjava/java/lang/StackTraceElement.java b/libjava/java/lang/StackTraceElement.java deleted file mode 100644 index 6dd4d8532e8..00000000000 --- a/libjava/java/lang/StackTraceElement.java +++ /dev/null @@ -1,259 +0,0 @@ -/* StackTraceElement.java -- One function call or call stack element - Copyright (C) 2001, 2002, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang; - -import java.io.Serializable; - -/** - * One function call or stack trace element. Gives information about - * the execution point such as the source file name, the line number, - * the fully qualified class name, the method name and whether this method - * is native, if this information is known. - * - * @author Mark Wielaard (mark@klomp.org) - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.4 - * @status updated to 1.4 - */ -public final class StackTraceElement implements Serializable -{ - /** - * Compatible with JDK 1.4+. - */ - private static final long serialVersionUID = 6992337162326171013L; - - /** - * The name of the file, null if unknown. - * - * @serial the source code filename, if known - */ - private final String fileName; - - /** - * The line number in the file, negative if unknown. - * - * @serial the source code line number, if known - */ - private final int lineNumber; - - /** - * The fully qualified class name, null if unknown. - * - * @serial the enclosing class, if known - */ - private final String declaringClass; - - /** - * The method name in the class, null if unknown. - * - * @serial the enclosing method, if known - */ - private final String methodName; - - /** Whether the method is native. */ - private final transient boolean isNative; - - /** - * A package local constructor for the StackTraceElement class, to be - * called by the Virtual Machine as part of Throwable.fillInStackTrace. - * There are no public constructors defined for this class. Creation - * of new elements is implementation specific. - * - * @param fileName the name of the file, null if unknown - * @param lineNumber the line in the file, negative if unknown - * @param className the fully qualified name of the class, null if unknown - * @param methodName the name of the method, null if unknown - * @param isNative true if native, false otherwise - */ - StackTraceElement(String fileName, int lineNumber, String className, - String methodName, boolean isNative) - { - this.fileName = fileName; - this.lineNumber = lineNumber; - this.declaringClass = className; - this.methodName = methodName; - this.isNative = isNative; - } - - /** - * Returns the name of the file, or null if unknown. This is usually - * obtained from the <code>SourceFile</code> attribute of the class file - * format, if present. - * - * @return the file name - */ - public String getFileName() - { - return fileName; - } - - /** - * Returns the line number in the file, or a negative number if unknown. - * This is usually obtained from the <code>LineNumberTable</code> attribute - * of the method in the class file format, if present. - * - * @return the line number - */ - public int getLineNumber() - { - return lineNumber; - } - - /** - * Returns the fully qualified class name, or null if unknown. - * - * @return the class name - */ - public String getClassName() - { - return declaringClass; - } - - /** - * Returns the method name in the class, or null if unknown. If the - * execution point is in a constructor, the name is - * <code><init></code>; if the execution point is in the class - * initializer, the name is <code><clinit></code>. - * - * @return the method name - */ - public String getMethodName() - { - return methodName; - } - - /** - * Returns true if the method is native, or false if it is not or unknown. - * - * @return whether the method is native - */ - public boolean isNativeMethod() - { - return isNative; - } - - /** - * Returns a string representation of this stack trace element. The - * returned String is implementation specific. This implementation - * returns the following String: "[class][.][method]([file][:line])". - * If the fully qualified class name or the method is unknown it is - * omitted including the point seperator. If the source file name is - * unknown it is replaced by "Unknown Source" if the method is not native - * or by "Native Method" if the method is native. If the line number - * is unknown it and the colon are omitted. - * - * @return a string representation of this execution point - */ - public String toString() - { - StringBuffer sb = new StringBuffer(); - if (declaringClass != null) - { - sb.append(declaringClass); - if (methodName != null) - sb.append('.'); - } - if (methodName != null) - sb.append(methodName); - sb.append(" ("); - if (fileName != null) - sb.append(fileName); - else - sb.append(isNative ? "Native Method" : "Unknown Source"); - if (lineNumber >= 0) - sb.append(':').append(lineNumber); - sb.append(')'); - return sb.toString(); - } - - /** - * Returns true if the given object is also a StackTraceElement and all - * attributes, except the native flag, are equal (either the same attribute - * between the two elments are null, or both satisfy Object.equals). - * - * @param o the object to compare - * @return true if the two are equal - */ - public boolean equals(Object o) - { - if (! (o instanceof StackTraceElement)) - return false; - StackTraceElement e = (StackTraceElement) o; - return equals(fileName, e.fileName) - && lineNumber == e.lineNumber - && equals(declaringClass, e.declaringClass) - && equals(methodName, e.methodName); - } - - /** - * Returns the hashCode of this StackTraceElement. This implementation - * computes the hashcode by xor-ing the hashcode of all attributes except - * the native flag. - * - * @return the hashcode - */ - public int hashCode() - { - return hashCode(fileName) ^ lineNumber ^ hashCode(declaringClass) - ^ hashCode(methodName); - } - - /** - * Compare two objects according to Collection semantics. - * - * @param o1 the first object - * @param o2 the second object - * @return o1 == null ? o2 == null : o1.equals(o2) - */ - private static boolean equals(Object o1, Object o2) - { - return o1 == null ? o2 == null : o1.equals(o2); - } - - /** - * Hash an object according to Collection semantics. - * - * @param o the object to hash - * @return o1 == null ? 0 : o1.hashCode() - */ - private static int hashCode(Object o) - { - return o == null ? 0 : o.hashCode(); - } -} diff --git a/libjava/java/lang/StrictMath.java b/libjava/java/lang/StrictMath.java deleted file mode 100644 index 32bd3540d80..00000000000 --- a/libjava/java/lang/StrictMath.java +++ /dev/null @@ -1,1844 +0,0 @@ -/* java.lang.StrictMath -- common mathematical functions, strict Java - Copyright (C) 1998, 2001, 2002, 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -/* - * Some of the algorithms in this class are in the public domain, as part - * of fdlibm (freely-distributable math library), available at - * http://www.netlib.org/fdlibm/, and carry the following copyright: - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunSoft, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -package java.lang; - -import gnu.classpath.Configuration; - -import java.util.Random; - -/** - * Helper class containing useful mathematical functions and constants. - * This class mirrors {@link Math}, but is 100% portable, because it uses - * no native methods whatsoever. Also, these algorithms are all accurate - * to less than 1 ulp, and execute in <code>strictfp</code> mode, while - * Math is allowed to vary in its results for some functions. Unfortunately, - * this usually means StrictMath has less efficiency and speed, as Math can - * use native methods. - * - * <p>The source of the various algorithms used is the fdlibm library, at:<br> - * <a href="http://www.netlib.org/fdlibm/">http://www.netlib.org/fdlibm/</a> - * - * Note that angles are specified in radians. Conversion functions are - * provided for your convenience. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.3 - */ -public final strictfp class StrictMath -{ - /** - * StrictMath is non-instantiable. - */ - private StrictMath() - { - } - - /** - * A random number generator, initialized on first use. - * - * @see #random() - */ - private static Random rand; - - /** - * The most accurate approximation to the mathematical constant <em>e</em>: - * <code>2.718281828459045</code>. Used in natural log and exp. - * - * @see #log(double) - * @see #exp(double) - */ - public static final double E - = 2.718281828459045; // Long bits 0x4005bf0z8b145769L. - - /** - * The most accurate approximation to the mathematical constant <em>pi</em>: - * <code>3.141592653589793</code>. This is the ratio of a circle's diameter - * to its circumference. - */ - public static final double PI - = 3.141592653589793; // Long bits 0x400921fb54442d18L. - - /** - * Take the absolute value of the argument. (Absolute value means make - * it positive.) - * - * <p>Note that the the largest negative value (Integer.MIN_VALUE) cannot - * be made positive. In this case, because of the rules of negation in - * a computer, MIN_VALUE is what will be returned. - * This is a <em>negative</em> value. You have been warned. - * - * @param i the number to take the absolute value of - * @return the absolute value - * @see Integer#MIN_VALUE - */ - public static int abs(int i) - { - return (i < 0) ? -i : i; - } - - /** - * Take the absolute value of the argument. (Absolute value means make - * it positive.) - * - * <p>Note that the the largest negative value (Long.MIN_VALUE) cannot - * be made positive. In this case, because of the rules of negation in - * a computer, MIN_VALUE is what will be returned. - * This is a <em>negative</em> value. You have been warned. - * - * @param l the number to take the absolute value of - * @return the absolute value - * @see Long#MIN_VALUE - */ - public static long abs(long l) - { - return (l < 0) ? -l : l; - } - - /** - * Take the absolute value of the argument. (Absolute value means make - * it positive.) - * - * @param f the number to take the absolute value of - * @return the absolute value - */ - public static float abs(float f) - { - return (f <= 0) ? 0 - f : f; - } - - /** - * Take the absolute value of the argument. (Absolute value means make - * it positive.) - * - * @param d the number to take the absolute value of - * @return the absolute value - */ - public static double abs(double d) - { - return (d <= 0) ? 0 - d : d; - } - - /** - * Return whichever argument is smaller. - * - * @param a the first number - * @param b a second number - * @return the smaller of the two numbers - */ - public static int min(int a, int b) - { - return (a < b) ? a : b; - } - - /** - * Return whichever argument is smaller. - * - * @param a the first number - * @param b a second number - * @return the smaller of the two numbers - */ - public static long min(long a, long b) - { - return (a < b) ? a : b; - } - - /** - * Return whichever argument is smaller. If either argument is NaN, the - * result is NaN, and when comparing 0 and -0, -0 is always smaller. - * - * @param a the first number - * @param b a second number - * @return the smaller of the two numbers - */ - public static float min(float a, float b) - { - // this check for NaN, from JLS 15.21.1, saves a method call - if (a != a) - return a; - // no need to check if b is NaN; < will work correctly - // recall that -0.0 == 0.0, but [+-]0.0 - [+-]0.0 behaves special - if (a == 0 && b == 0) - return -(-a - b); - return (a < b) ? a : b; - } - - /** - * Return whichever argument is smaller. If either argument is NaN, the - * result is NaN, and when comparing 0 and -0, -0 is always smaller. - * - * @param a the first number - * @param b a second number - * @return the smaller of the two numbers - */ - public static double min(double a, double b) - { - // this check for NaN, from JLS 15.21.1, saves a method call - if (a != a) - return a; - // no need to check if b is NaN; < will work correctly - // recall that -0.0 == 0.0, but [+-]0.0 - [+-]0.0 behaves special - if (a == 0 && b == 0) - return -(-a - b); - return (a < b) ? a : b; - } - - /** - * Return whichever argument is larger. - * - * @param a the first number - * @param b a second number - * @return the larger of the two numbers - */ - public static int max(int a, int b) - { - return (a > b) ? a : b; - } - - /** - * Return whichever argument is larger. - * - * @param a the first number - * @param b a second number - * @return the larger of the two numbers - */ - public static long max(long a, long b) - { - return (a > b) ? a : b; - } - - /** - * Return whichever argument is larger. If either argument is NaN, the - * result is NaN, and when comparing 0 and -0, 0 is always larger. - * - * @param a the first number - * @param b a second number - * @return the larger of the two numbers - */ - public static float max(float a, float b) - { - // this check for NaN, from JLS 15.21.1, saves a method call - if (a != a) - return a; - // no need to check if b is NaN; > will work correctly - // recall that -0.0 == 0.0, but [+-]0.0 - [+-]0.0 behaves special - if (a == 0 && b == 0) - return a - -b; - return (a > b) ? a : b; - } - - /** - * Return whichever argument is larger. If either argument is NaN, the - * result is NaN, and when comparing 0 and -0, 0 is always larger. - * - * @param a the first number - * @param b a second number - * @return the larger of the two numbers - */ - public static double max(double a, double b) - { - // this check for NaN, from JLS 15.21.1, saves a method call - if (a != a) - return a; - // no need to check if b is NaN; > will work correctly - // recall that -0.0 == 0.0, but [+-]0.0 - [+-]0.0 behaves special - if (a == 0 && b == 0) - return a - -b; - return (a > b) ? a : b; - } - - /** - * The trigonometric function <em>sin</em>. The sine of NaN or infinity is - * NaN, and the sine of 0 retains its sign. - * - * @param a the angle (in radians) - * @return sin(a) - */ - public static double sin(double a) - { - if (a == Double.NEGATIVE_INFINITY || ! (a < Double.POSITIVE_INFINITY)) - return Double.NaN; - - if (abs(a) <= PI / 4) - return sin(a, 0); - - // Argument reduction needed. - double[] y = new double[2]; - int n = remPiOver2(a, y); - switch (n & 3) - { - case 0: - return sin(y[0], y[1]); - case 1: - return cos(y[0], y[1]); - case 2: - return -sin(y[0], y[1]); - default: - return -cos(y[0], y[1]); - } - } - - /** - * The trigonometric function <em>cos</em>. The cosine of NaN or infinity is - * NaN. - * - * @param a the angle (in radians). - * @return cos(a). - */ - public static double cos(double a) - { - if (a == Double.NEGATIVE_INFINITY || ! (a < Double.POSITIVE_INFINITY)) - return Double.NaN; - - if (abs(a) <= PI / 4) - return cos(a, 0); - - // Argument reduction needed. - double[] y = new double[2]; - int n = remPiOver2(a, y); - switch (n & 3) - { - case 0: - return cos(y[0], y[1]); - case 1: - return -sin(y[0], y[1]); - case 2: - return -cos(y[0], y[1]); - default: - return sin(y[0], y[1]); - } - } - - /** - * The trigonometric function <em>tan</em>. The tangent of NaN or infinity - * is NaN, and the tangent of 0 retains its sign. - * - * @param a the angle (in radians) - * @return tan(a) - */ - public static double tan(double a) - { - if (a == Double.NEGATIVE_INFINITY || ! (a < Double.POSITIVE_INFINITY)) - return Double.NaN; - - if (abs(a) <= PI / 4) - return tan(a, 0, false); - - // Argument reduction needed. - double[] y = new double[2]; - int n = remPiOver2(a, y); - return tan(y[0], y[1], (n & 1) == 1); - } - - /** - * The trigonometric function <em>arcsin</em>. The range of angles returned - * is -pi/2 to pi/2 radians (-90 to 90 degrees). If the argument is NaN or - * its absolute value is beyond 1, the result is NaN; and the arcsine of - * 0 retains its sign. - * - * @param x the sin to turn back into an angle - * @return arcsin(x) - */ - public static double asin(double x) - { - boolean negative = x < 0; - if (negative) - x = -x; - if (! (x <= 1)) - return Double.NaN; - if (x == 1) - return negative ? -PI / 2 : PI / 2; - if (x < 0.5) - { - if (x < 1 / TWO_27) - return negative ? -x : x; - double t = x * x; - double p = t * (PS0 + t * (PS1 + t * (PS2 + t * (PS3 + t - * (PS4 + t * PS5))))); - double q = 1 + t * (QS1 + t * (QS2 + t * (QS3 + t * QS4))); - return negative ? -x - x * (p / q) : x + x * (p / q); - } - double w = 1 - x; // 1>|x|>=0.5. - double t = w * 0.5; - double p = t * (PS0 + t * (PS1 + t * (PS2 + t * (PS3 + t - * (PS4 + t * PS5))))); - double q = 1 + t * (QS1 + t * (QS2 + t * (QS3 + t * QS4))); - double s = sqrt(t); - if (x >= 0.975) - { - w = p / q; - t = PI / 2 - (2 * (s + s * w) - PI_L / 2); - } - else - { - w = (float) s; - double c = (t - w * w) / (s + w); - p = 2 * s * (p / q) - (PI_L / 2 - 2 * c); - q = PI / 4 - 2 * w; - t = PI / 4 - (p - q); - } - return negative ? -t : t; - } - - /** - * The trigonometric function <em>arccos</em>. The range of angles returned - * is 0 to pi radians (0 to 180 degrees). If the argument is NaN or - * its absolute value is beyond 1, the result is NaN. - * - * @param x the cos to turn back into an angle - * @return arccos(x) - */ - public static double acos(double x) - { - boolean negative = x < 0; - if (negative) - x = -x; - if (! (x <= 1)) - return Double.NaN; - if (x == 1) - return negative ? PI : 0; - if (x < 0.5) - { - if (x < 1 / TWO_57) - return PI / 2; - double z = x * x; - double p = z * (PS0 + z * (PS1 + z * (PS2 + z * (PS3 + z - * (PS4 + z * PS5))))); - double q = 1 + z * (QS1 + z * (QS2 + z * (QS3 + z * QS4))); - double r = x - (PI_L / 2 - x * (p / q)); - return negative ? PI / 2 + r : PI / 2 - r; - } - if (negative) // x<=-0.5. - { - double z = (1 + x) * 0.5; - double p = z * (PS0 + z * (PS1 + z * (PS2 + z * (PS3 + z - * (PS4 + z * PS5))))); - double q = 1 + z * (QS1 + z * (QS2 + z * (QS3 + z * QS4))); - double s = sqrt(z); - double w = p / q * s - PI_L / 2; - return PI - 2 * (s + w); - } - double z = (1 - x) * 0.5; // x>0.5. - double s = sqrt(z); - double df = (float) s; - double c = (z - df * df) / (s + df); - double p = z * (PS0 + z * (PS1 + z * (PS2 + z * (PS3 + z - * (PS4 + z * PS5))))); - double q = 1 + z * (QS1 + z * (QS2 + z * (QS3 + z * QS4))); - double w = p / q * s + c; - return 2 * (df + w); - } - - /** - * The trigonometric function <em>arcsin</em>. The range of angles returned - * is -pi/2 to pi/2 radians (-90 to 90 degrees). If the argument is NaN, the - * result is NaN; and the arctangent of 0 retains its sign. - * - * @param x the tan to turn back into an angle - * @return arcsin(x) - * @see #atan2(double, double) - */ - public static double atan(double x) - { - double lo; - double hi; - boolean negative = x < 0; - if (negative) - x = -x; - if (x >= TWO_66) - return negative ? -PI / 2 : PI / 2; - if (! (x >= 0.4375)) // |x|<7/16, or NaN. - { - if (! (x >= 1 / TWO_29)) // Small, or NaN. - return negative ? -x : x; - lo = hi = 0; - } - else if (x < 1.1875) - { - if (x < 0.6875) // 7/16<=|x|<11/16. - { - x = (2 * x - 1) / (2 + x); - hi = ATAN_0_5H; - lo = ATAN_0_5L; - } - else // 11/16<=|x|<19/16. - { - x = (x - 1) / (x + 1); - hi = PI / 4; - lo = PI_L / 4; - } - } - else if (x < 2.4375) // 19/16<=|x|<39/16. - { - x = (x - 1.5) / (1 + 1.5 * x); - hi = ATAN_1_5H; - lo = ATAN_1_5L; - } - else // 39/16<=|x|<2**66. - { - x = -1 / x; - hi = PI / 2; - lo = PI_L / 2; - } - - // Break sum from i=0 to 10 ATi*z**(i+1) into odd and even poly. - double z = x * x; - double w = z * z; - double s1 = z * (AT0 + w * (AT2 + w * (AT4 + w * (AT6 + w - * (AT8 + w * AT10))))); - double s2 = w * (AT1 + w * (AT3 + w * (AT5 + w * (AT7 + w * AT9)))); - if (hi == 0) - return negative ? x * (s1 + s2) - x : x - x * (s1 + s2); - z = hi - ((x * (s1 + s2) - lo) - x); - return negative ? -z : z; - } - - /** - * A special version of the trigonometric function <em>arctan</em>, for - * converting rectangular coordinates <em>(x, y)</em> to polar - * <em>(r, theta)</em>. This computes the arctangent of x/y in the range - * of -pi to pi radians (-180 to 180 degrees). Special cases:<ul> - * <li>If either argument is NaN, the result is NaN.</li> - * <li>If the first argument is positive zero and the second argument is - * positive, or the first argument is positive and finite and the second - * argument is positive infinity, then the result is positive zero.</li> - * <li>If the first argument is negative zero and the second argument is - * positive, or the first argument is negative and finite and the second - * argument is positive infinity, then the result is negative zero.</li> - * <li>If the first argument is positive zero and the second argument is - * negative, or the first argument is positive and finite and the second - * argument is negative infinity, then the result is the double value - * closest to pi.</li> - * <li>If the first argument is negative zero and the second argument is - * negative, or the first argument is negative and finite and the second - * argument is negative infinity, then the result is the double value - * closest to -pi.</li> - * <li>If the first argument is positive and the second argument is - * positive zero or negative zero, or the first argument is positive - * infinity and the second argument is finite, then the result is the - * double value closest to pi/2.</li> - * <li>If the first argument is negative and the second argument is - * positive zero or negative zero, or the first argument is negative - * infinity and the second argument is finite, then the result is the - * double value closest to -pi/2.</li> - * <li>If both arguments are positive infinity, then the result is the - * double value closest to pi/4.</li> - * <li>If the first argument is positive infinity and the second argument - * is negative infinity, then the result is the double value closest to - * 3*pi/4.</li> - * <li>If the first argument is negative infinity and the second argument - * is positive infinity, then the result is the double value closest to - * -pi/4.</li> - * <li>If both arguments are negative infinity, then the result is the - * double value closest to -3*pi/4.</li> - * - * </ul><p>This returns theta, the angle of the point. To get r, albeit - * slightly inaccurately, use sqrt(x*x+y*y). - * - * @param y the y position - * @param x the x position - * @return <em>theta</em> in the conversion of (x, y) to (r, theta) - * @see #atan(double) - */ - public static double atan2(double y, double x) - { - if (x != x || y != y) - return Double.NaN; - if (x == 1) - return atan(y); - if (x == Double.POSITIVE_INFINITY) - { - if (y == Double.POSITIVE_INFINITY) - return PI / 4; - if (y == Double.NEGATIVE_INFINITY) - return -PI / 4; - return 0 * y; - } - if (x == Double.NEGATIVE_INFINITY) - { - if (y == Double.POSITIVE_INFINITY) - return 3 * PI / 4; - if (y == Double.NEGATIVE_INFINITY) - return -3 * PI / 4; - return (1 / (0 * y) == Double.POSITIVE_INFINITY) ? PI : -PI; - } - if (y == 0) - { - if (1 / (0 * x) == Double.POSITIVE_INFINITY) - return y; - return (1 / y == Double.POSITIVE_INFINITY) ? PI : -PI; - } - if (y == Double.POSITIVE_INFINITY || y == Double.NEGATIVE_INFINITY - || x == 0) - return y < 0 ? -PI / 2 : PI / 2; - - double z = abs(y / x); // Safe to do y/x. - if (z > TWO_60) - z = PI / 2 + 0.5 * PI_L; - else if (x < 0 && z < 1 / TWO_60) - z = 0; - else - z = atan(z); - if (x > 0) - return y > 0 ? z : -z; - return y > 0 ? PI - (z - PI_L) : z - PI_L - PI; - } - - /** - * Take <em>e</em><sup>a</sup>. The opposite of <code>log()</code>. If the - * argument is NaN, the result is NaN; if the argument is positive infinity, - * the result is positive infinity; and if the argument is negative - * infinity, the result is positive zero. - * - * @param x the number to raise to the power - * @return the number raised to the power of <em>e</em> - * @see #log(double) - * @see #pow(double, double) - */ - public static double exp(double x) - { - if (x != x) - return x; - if (x > EXP_LIMIT_H) - return Double.POSITIVE_INFINITY; - if (x < EXP_LIMIT_L) - return 0; - - // Argument reduction. - double hi; - double lo; - int k; - double t = abs(x); - if (t > 0.5 * LN2) - { - if (t < 1.5 * LN2) - { - hi = t - LN2_H; - lo = LN2_L; - k = 1; - } - else - { - k = (int) (INV_LN2 * t + 0.5); - hi = t - k * LN2_H; - lo = k * LN2_L; - } - if (x < 0) - { - hi = -hi; - lo = -lo; - k = -k; - } - x = hi - lo; - } - else if (t < 1 / TWO_28) - return 1; - else - lo = hi = k = 0; - - // Now x is in primary range. - t = x * x; - double c = x - t * (P1 + t * (P2 + t * (P3 + t * (P4 + t * P5)))); - if (k == 0) - return 1 - (x * c / (c - 2) - x); - double y = 1 - (lo - x * c / (2 - c) - hi); - return scale(y, k); - } - - /** - * Take ln(a) (the natural log). The opposite of <code>exp()</code>. If the - * argument is NaN or negative, the result is NaN; if the argument is - * positive infinity, the result is positive infinity; and if the argument - * is either zero, the result is negative infinity. - * - * <p>Note that the way to get log<sub>b</sub>(a) is to do this: - * <code>ln(a) / ln(b)</code>. - * - * @param x the number to take the natural log of - * @return the natural log of <code>a</code> - * @see #exp(double) - */ - public static double log(double x) - { - if (x == 0) - return Double.NEGATIVE_INFINITY; - if (x < 0) - return Double.NaN; - if (! (x < Double.POSITIVE_INFINITY)) - return x; - - // Normalize x. - long bits = Double.doubleToLongBits(x); - int exp = (int) (bits >> 52); - if (exp == 0) // Subnormal x. - { - x *= TWO_54; - bits = Double.doubleToLongBits(x); - exp = (int) (bits >> 52) - 54; - } - exp -= 1023; // Unbias exponent. - bits = (bits & 0x000fffffffffffffL) | 0x3ff0000000000000L; - x = Double.longBitsToDouble(bits); - if (x >= SQRT_2) - { - x *= 0.5; - exp++; - } - x--; - if (abs(x) < 1 / TWO_20) - { - if (x == 0) - return exp * LN2_H + exp * LN2_L; - double r = x * x * (0.5 - 1 / 3.0 * x); - if (exp == 0) - return x - r; - return exp * LN2_H - ((r - exp * LN2_L) - x); - } - double s = x / (2 + x); - double z = s * s; - double w = z * z; - double t1 = w * (LG2 + w * (LG4 + w * LG6)); - double t2 = z * (LG1 + w * (LG3 + w * (LG5 + w * LG7))); - double r = t2 + t1; - if (bits >= 0x3ff6174a00000000L && bits < 0x3ff6b85200000000L) - { - double h = 0.5 * x * x; // Need more accuracy for x near sqrt(2). - if (exp == 0) - return x - (h - s * (h + r)); - return exp * LN2_H - ((h - (s * (h + r) + exp * LN2_L)) - x); - } - if (exp == 0) - return x - s * (x - r); - return exp * LN2_H - ((s * (x - r) - exp * LN2_L) - x); - } - - /** - * Take a square root. If the argument is NaN or negative, the result is - * NaN; if the argument is positive infinity, the result is positive - * infinity; and if the result is either zero, the result is the same. - * - * <p>For other roots, use pow(x, 1/rootNumber). - * - * @param x the numeric argument - * @return the square root of the argument - * @see #pow(double, double) - */ - public static double sqrt(double x) - { - if (x < 0) - return Double.NaN; - if (x == 0 || ! (x < Double.POSITIVE_INFINITY)) - return x; - - // Normalize x. - long bits = Double.doubleToLongBits(x); - int exp = (int) (bits >> 52); - if (exp == 0) // Subnormal x. - { - x *= TWO_54; - bits = Double.doubleToLongBits(x); - exp = (int) (bits >> 52) - 54; - } - exp -= 1023; // Unbias exponent. - bits = (bits & 0x000fffffffffffffL) | 0x0010000000000000L; - if ((exp & 1) == 1) // Odd exp, double x to make it even. - bits <<= 1; - exp >>= 1; - - // Generate sqrt(x) bit by bit. - bits <<= 1; - long q = 0; - long s = 0; - long r = 0x0020000000000000L; // Move r right to left. - while (r != 0) - { - long t = s + r; - if (t <= bits) - { - s = t + r; - bits -= t; - q += r; - } - bits <<= 1; - r >>= 1; - } - - // Use floating add to round correctly. - if (bits != 0) - q += q & 1; - return Double.longBitsToDouble((q >> 1) + ((exp + 1022L) << 52)); - } - - /** - * Raise a number to a power. Special cases:<ul> - * <li>If the second argument is positive or negative zero, then the result - * is 1.0.</li> - * <li>If the second argument is 1.0, then the result is the same as the - * first argument.</li> - * <li>If the second argument is NaN, then the result is NaN.</li> - * <li>If the first argument is NaN and the second argument is nonzero, - * then the result is NaN.</li> - * <li>If the absolute value of the first argument is greater than 1 and - * the second argument is positive infinity, or the absolute value of the - * first argument is less than 1 and the second argument is negative - * infinity, then the result is positive infinity.</li> - * <li>If the absolute value of the first argument is greater than 1 and - * the second argument is negative infinity, or the absolute value of the - * first argument is less than 1 and the second argument is positive - * infinity, then the result is positive zero.</li> - * <li>If the absolute value of the first argument equals 1 and the second - * argument is infinite, then the result is NaN.</li> - * <li>If the first argument is positive zero and the second argument is - * greater than zero, or the first argument is positive infinity and the - * second argument is less than zero, then the result is positive zero.</li> - * <li>If the first argument is positive zero and the second argument is - * less than zero, or the first argument is positive infinity and the - * second argument is greater than zero, then the result is positive - * infinity.</li> - * <li>If the first argument is negative zero and the second argument is - * greater than zero but not a finite odd integer, or the first argument is - * negative infinity and the second argument is less than zero but not a - * finite odd integer, then the result is positive zero.</li> - * <li>If the first argument is negative zero and the second argument is a - * positive finite odd integer, or the first argument is negative infinity - * and the second argument is a negative finite odd integer, then the result - * is negative zero.</li> - * <li>If the first argument is negative zero and the second argument is - * less than zero but not a finite odd integer, or the first argument is - * negative infinity and the second argument is greater than zero but not a - * finite odd integer, then the result is positive infinity.</li> - * <li>If the first argument is negative zero and the second argument is a - * negative finite odd integer, or the first argument is negative infinity - * and the second argument is a positive finite odd integer, then the result - * is negative infinity.</li> - * <li>If the first argument is less than zero and the second argument is a - * finite even integer, then the result is equal to the result of raising - * the absolute value of the first argument to the power of the second - * argument.</li> - * <li>If the first argument is less than zero and the second argument is a - * finite odd integer, then the result is equal to the negative of the - * result of raising the absolute value of the first argument to the power - * of the second argument.</li> - * <li>If the first argument is finite and less than zero and the second - * argument is finite and not an integer, then the result is NaN.</li> - * <li>If both arguments are integers, then the result is exactly equal to - * the mathematical result of raising the first argument to the power of - * the second argument if that result can in fact be represented exactly as - * a double value.</li> - * - * </ul><p>(In the foregoing descriptions, a floating-point value is - * considered to be an integer if and only if it is a fixed point of the - * method {@link #ceil(double)} or, equivalently, a fixed point of the - * method {@link #floor(double)}. A value is a fixed point of a one-argument - * method if and only if the result of applying the method to the value is - * equal to the value.) - * - * @param x the number to raise - * @param y the power to raise it to - * @return x<sup>y</sup> - */ - public static double pow(double x, double y) - { - // Special cases first. - if (y == 0) - return 1; - if (y == 1) - return x; - if (y == -1) - return 1 / x; - if (x != x || y != y) - return Double.NaN; - - // When x < 0, yisint tells if y is not an integer (0), even(1), - // or odd (2). - int yisint = 0; - if (x < 0 && floor(y) == y) - yisint = (y % 2 == 0) ? 2 : 1; - double ax = abs(x); - double ay = abs(y); - - // More special cases, of y. - if (ay == Double.POSITIVE_INFINITY) - { - if (ax == 1) - return Double.NaN; - if (ax > 1) - return y > 0 ? y : 0; - return y < 0 ? -y : 0; - } - if (y == 2) - return x * x; - if (y == 0.5) - return sqrt(x); - - // More special cases, of x. - if (x == 0 || ax == Double.POSITIVE_INFINITY || ax == 1) - { - if (y < 0) - ax = 1 / ax; - if (x < 0) - { - if (x == -1 && yisint == 0) - ax = Double.NaN; - else if (yisint == 1) - ax = -ax; - } - return ax; - } - if (x < 0 && yisint == 0) - return Double.NaN; - - // Now we can start! - double t; - double t1; - double t2; - double u; - double v; - double w; - if (ay > TWO_31) - { - if (ay > TWO_64) // Automatic over/underflow. - return ((ax < 1) ? y < 0 : y > 0) ? Double.POSITIVE_INFINITY : 0; - // Over/underflow if x is not close to one. - if (ax < 0.9999995231628418) - return y < 0 ? Double.POSITIVE_INFINITY : 0; - if (ax >= 1.0000009536743164) - return y > 0 ? Double.POSITIVE_INFINITY : 0; - // Now |1-x| is <= 2**-20, sufficient to compute - // log(x) by x-x^2/2+x^3/3-x^4/4. - t = x - 1; - w = t * t * (0.5 - t * (1 / 3.0 - t * 0.25)); - u = INV_LN2_H * t; - v = t * INV_LN2_L - w * INV_LN2; - t1 = (float) (u + v); - t2 = v - (t1 - u); - } - else - { - long bits = Double.doubleToLongBits(ax); - int exp = (int) (bits >> 52); - if (exp == 0) // Subnormal x. - { - ax *= TWO_54; - bits = Double.doubleToLongBits(ax); - exp = (int) (bits >> 52) - 54; - } - exp -= 1023; // Unbias exponent. - ax = Double.longBitsToDouble((bits & 0x000fffffffffffffL) - | 0x3ff0000000000000L); - boolean k; - if (ax < SQRT_1_5) // |x|<sqrt(3/2). - k = false; - else if (ax < SQRT_3) // |x|<sqrt(3). - k = true; - else - { - k = false; - ax *= 0.5; - exp++; - } - - // Compute s = s_h+s_l = (x-1)/(x+1) or (x-1.5)/(x+1.5). - u = ax - (k ? 1.5 : 1); - v = 1 / (ax + (k ? 1.5 : 1)); - double s = u * v; - double s_h = (float) s; - double t_h = (float) (ax + (k ? 1.5 : 1)); - double t_l = ax - (t_h - (k ? 1.5 : 1)); - double s_l = v * ((u - s_h * t_h) - s_h * t_l); - // Compute log(ax). - double s2 = s * s; - double r = s_l * (s_h + s) + s2 * s2 - * (L1 + s2 * (L2 + s2 * (L3 + s2 * (L4 + s2 * (L5 + s2 * L6))))); - s2 = s_h * s_h; - t_h = (float) (3.0 + s2 + r); - t_l = r - (t_h - 3.0 - s2); - // u+v = s*(1+...). - u = s_h * t_h; - v = s_l * t_h + t_l * s; - // 2/(3log2)*(s+...). - double p_h = (float) (u + v); - double p_l = v - (p_h - u); - double z_h = CP_H * p_h; - double z_l = CP_L * p_h + p_l * CP + (k ? DP_L : 0); - // log2(ax) = (s+..)*2/(3*log2) = exp + dp_h + z_h + z_l. - t = exp; - t1 = (float) (z_h + z_l + (k ? DP_H : 0) + t); - t2 = z_l - (t1 - t - (k ? DP_H : 0) - z_h); - } - - // Split up y into y1+y2 and compute (y1+y2)*(t1+t2). - boolean negative = x < 0 && yisint == 1; - double y1 = (float) y; - double p_l = (y - y1) * t1 + y * t2; - double p_h = y1 * t1; - double z = p_l + p_h; - if (z >= 1024) // Detect overflow. - { - if (z > 1024 || p_l + OVT > z - p_h) - return negative ? Double.NEGATIVE_INFINITY - : Double.POSITIVE_INFINITY; - } - else if (z <= -1075) // Detect underflow. - { - if (z < -1075 || p_l <= z - p_h) - return negative ? -0.0 : 0; - } - - // Compute 2**(p_h+p_l). - int n = round((float) z); - p_h -= n; - t = (float) (p_l + p_h); - u = t * LN2_H; - v = (p_l - (t - p_h)) * LN2 + t * LN2_L; - z = u + v; - w = v - (z - u); - t = z * z; - t1 = z - t * (P1 + t * (P2 + t * (P3 + t * (P4 + t * P5)))); - double r = (z * t1) / (t1 - 2) - (w + z * w); - z = scale(1 - (r - z), n); - return negative ? -z : z; - } - - /** - * Get the IEEE 754 floating point remainder on two numbers. This is the - * value of <code>x - y * <em>n</em></code>, where <em>n</em> is the closest - * double to <code>x / y</code> (ties go to the even n); for a zero - * remainder, the sign is that of <code>x</code>. If either argument is NaN, - * the first argument is infinite, or the second argument is zero, the result - * is NaN; if x is finite but y is infinite, the result is x. - * - * @param x the dividend (the top half) - * @param y the divisor (the bottom half) - * @return the IEEE 754-defined floating point remainder of x/y - * @see #rint(double) - */ - public static double IEEEremainder(double x, double y) - { - // Purge off exception values. - if (x == Double.NEGATIVE_INFINITY || ! (x < Double.POSITIVE_INFINITY) - || y == 0 || y != y) - return Double.NaN; - - boolean negative = x < 0; - x = abs(x); - y = abs(y); - if (x == y || x == 0) - return 0 * x; // Get correct sign. - - // Achieve x < 2y, then take first shot at remainder. - if (y < TWO_1023) - x %= y + y; - - // Now adjust x to get correct precision. - if (y < 4 / TWO_1023) - { - if (x + x > y) - { - x -= y; - if (x + x >= y) - x -= y; - } - } - else - { - y *= 0.5; - if (x > y) - { - x -= y; - if (x >= y) - x -= y; - } - } - return negative ? -x : x; - } - - /** - * Take the nearest integer that is that is greater than or equal to the - * argument. If the argument is NaN, infinite, or zero, the result is the - * same; if the argument is between -1 and 0, the result is negative zero. - * Note that <code>Math.ceil(x) == -Math.floor(-x)</code>. - * - * @param a the value to act upon - * @return the nearest integer >= <code>a</code> - */ - public static double ceil(double a) - { - return -floor(-a); - } - - /** - * Take the nearest integer that is that is less than or equal to the - * argument. If the argument is NaN, infinite, or zero, the result is the - * same. Note that <code>Math.ceil(x) == -Math.floor(-x)</code>. - * - * @param a the value to act upon - * @return the nearest integer <= <code>a</code> - */ - public static double floor(double a) - { - double x = abs(a); - if (! (x < TWO_52) || (long) a == a) - return a; // No fraction bits; includes NaN and infinity. - if (x < 1) - return a >= 0 ? 0 * a : -1; // Worry about signed zero. - return a < 0 ? (long) a - 1.0 : (long) a; // Cast to long truncates. - } - - /** - * Take the nearest integer to the argument. If it is exactly between - * two integers, the even integer is taken. If the argument is NaN, - * infinite, or zero, the result is the same. - * - * @param a the value to act upon - * @return the nearest integer to <code>a</code> - */ - public static double rint(double a) - { - double x = abs(a); - if (! (x < TWO_52)) - return a; // No fraction bits; includes NaN and infinity. - if (x <= 0.5) - return 0 * a; // Worry about signed zero. - if (x % 2 <= 0.5) - return (long) a; // Catch round down to even. - return (long) (a + (a < 0 ? -0.5 : 0.5)); // Cast to long truncates. - } - - /** - * Take the nearest integer to the argument. This is equivalent to - * <code>(int) Math.floor(f + 0.5f)</code>. If the argument is NaN, the - * result is 0; otherwise if the argument is outside the range of int, the - * result will be Integer.MIN_VALUE or Integer.MAX_VALUE, as appropriate. - * - * @param f the argument to round - * @return the nearest integer to the argument - * @see Integer#MIN_VALUE - * @see Integer#MAX_VALUE - */ - public static int round(float f) - { - return (int) floor(f + 0.5f); - } - - /** - * Take the nearest long to the argument. This is equivalent to - * <code>(long) Math.floor(d + 0.5)</code>. If the argument is NaN, the - * result is 0; otherwise if the argument is outside the range of long, the - * result will be Long.MIN_VALUE or Long.MAX_VALUE, as appropriate. - * - * @param d the argument to round - * @return the nearest long to the argument - * @see Long#MIN_VALUE - * @see Long#MAX_VALUE - */ - public static long round(double d) - { - return (long) floor(d + 0.5); - } - - /** - * Get a random number. This behaves like Random.nextDouble(), seeded by - * System.currentTimeMillis() when first called. In other words, the number - * is from a pseudorandom sequence, and lies in the range [+0.0, 1.0). - * This random sequence is only used by this method, and is threadsafe, - * although you may want your own random number generator if it is shared - * among threads. - * - * @return a random number - * @see Random#nextDouble() - * @see System#currentTimeMillis() - */ - public static synchronized double random() - { - if (rand == null) - rand = new Random(); - return rand.nextDouble(); - } - - /** - * Convert from degrees to radians. The formula for this is - * radians = degrees * (pi/180); however it is not always exact given the - * limitations of floating point numbers. - * - * @param degrees an angle in degrees - * @return the angle in radians - */ - public static double toRadians(double degrees) - { - return (degrees * PI) / 180; - } - - /** - * Convert from radians to degrees. The formula for this is - * degrees = radians * (180/pi); however it is not always exact given the - * limitations of floating point numbers. - * - * @param rads an angle in radians - * @return the angle in degrees - */ - public static double toDegrees(double rads) - { - return (rads * 180) / PI; - } - - /** - * Constants for scaling and comparing doubles by powers of 2. The compiler - * must automatically inline constructs like (1/TWO_54), so we don't list - * negative powers of two here. - */ - private static final double - TWO_16 = 0x10000, // Long bits 0x40f0000000000000L. - TWO_20 = 0x100000, // Long bits 0x4130000000000000L. - TWO_24 = 0x1000000, // Long bits 0x4170000000000000L. - TWO_27 = 0x8000000, // Long bits 0x41a0000000000000L. - TWO_28 = 0x10000000, // Long bits 0x41b0000000000000L. - TWO_29 = 0x20000000, // Long bits 0x41c0000000000000L. - TWO_31 = 0x80000000L, // Long bits 0x41e0000000000000L. - TWO_49 = 0x2000000000000L, // Long bits 0x4300000000000000L. - TWO_52 = 0x10000000000000L, // Long bits 0x4330000000000000L. - TWO_54 = 0x40000000000000L, // Long bits 0x4350000000000000L. - TWO_57 = 0x200000000000000L, // Long bits 0x4380000000000000L. - TWO_60 = 0x1000000000000000L, // Long bits 0x43b0000000000000L. - TWO_64 = 1.8446744073709552e19, // Long bits 0x43f0000000000000L. - TWO_66 = 7.378697629483821e19, // Long bits 0x4410000000000000L. - TWO_1023 = 8.98846567431158e307; // Long bits 0x7fe0000000000000L. - - /** - * Super precision for 2/pi in 24-bit chunks, for use in - * {@link #remPiOver2()}. - */ - private static final int TWO_OVER_PI[] = { - 0xa2f983, 0x6e4e44, 0x1529fc, 0x2757d1, 0xf534dd, 0xc0db62, - 0x95993c, 0x439041, 0xfe5163, 0xabdebb, 0xc561b7, 0x246e3a, - 0x424dd2, 0xe00649, 0x2eea09, 0xd1921c, 0xfe1deb, 0x1cb129, - 0xa73ee8, 0x8235f5, 0x2ebb44, 0x84e99c, 0x7026b4, 0x5f7e41, - 0x3991d6, 0x398353, 0x39f49c, 0x845f8b, 0xbdf928, 0x3b1ff8, - 0x97ffde, 0x05980f, 0xef2f11, 0x8b5a0a, 0x6d1f6d, 0x367ecf, - 0x27cb09, 0xb74f46, 0x3f669e, 0x5fea2d, 0x7527ba, 0xc7ebe5, - 0xf17b3d, 0x0739f7, 0x8a5292, 0xea6bfb, 0x5fb11f, 0x8d5d08, - 0x560330, 0x46fc7b, 0x6babf0, 0xcfbc20, 0x9af436, 0x1da9e3, - 0x91615e, 0xe61b08, 0x659985, 0x5f14a0, 0x68408d, 0xffd880, - 0x4d7327, 0x310606, 0x1556ca, 0x73a8c9, 0x60e27b, 0xc08c6b, - }; - - /** - * Super precision for pi/2 in 24-bit chunks, for use in - * {@link #remPiOver2()}. - */ - private static final double PI_OVER_TWO[] = { - 1.570796251296997, // Long bits 0x3ff921fb40000000L. - 7.549789415861596e-8, // Long bits 0x3e74442d00000000L. - 5.390302529957765e-15, // Long bits 0x3cf8469880000000L. - 3.282003415807913e-22, // Long bits 0x3b78cc5160000000L. - 1.270655753080676e-29, // Long bits 0x39f01b8380000000L. - 1.2293330898111133e-36, // Long bits 0x387a252040000000L. - 2.7337005381646456e-44, // Long bits 0x36e3822280000000L. - 2.1674168387780482e-51, // Long bits 0x3569f31d00000000L. - }; - - /** - * More constants related to pi, used in {@link #remPiOver2()} and - * elsewhere. - */ - private static final double - PI_L = 1.2246467991473532e-16, // Long bits 0x3ca1a62633145c07L. - PIO2_1 = 1.5707963267341256, // Long bits 0x3ff921fb54400000L. - PIO2_1L = 6.077100506506192e-11, // Long bits 0x3dd0b4611a626331L. - PIO2_2 = 6.077100506303966e-11, // Long bits 0x3dd0b4611a600000L. - PIO2_2L = 2.0222662487959506e-21, // Long bits 0x3ba3198a2e037073L. - PIO2_3 = 2.0222662487111665e-21, // Long bits 0x3ba3198a2e000000L. - PIO2_3L = 8.4784276603689e-32; // Long bits 0x397b839a252049c1L. - - /** - * Natural log and square root constants, for calculation of - * {@link #exp(double)}, {@link #log(double)} and - * {@link #power(double, double)}. CP is 2/(3*ln(2)). - */ - private static final double - SQRT_1_5 = 1.224744871391589, // Long bits 0x3ff3988e1409212eL. - SQRT_2 = 1.4142135623730951, // Long bits 0x3ff6a09e667f3bcdL. - SQRT_3 = 1.7320508075688772, // Long bits 0x3ffbb67ae8584caaL. - EXP_LIMIT_H = 709.782712893384, // Long bits 0x40862e42fefa39efL. - EXP_LIMIT_L = -745.1332191019411, // Long bits 0xc0874910d52d3051L. - CP = 0.9617966939259756, // Long bits 0x3feec709dc3a03fdL. - CP_H = 0.9617967009544373, // Long bits 0x3feec709e0000000L. - CP_L = -7.028461650952758e-9, // Long bits 0xbe3e2fe0145b01f5L. - LN2 = 0.6931471805599453, // Long bits 0x3fe62e42fefa39efL. - LN2_H = 0.6931471803691238, // Long bits 0x3fe62e42fee00000L. - LN2_L = 1.9082149292705877e-10, // Long bits 0x3dea39ef35793c76L. - INV_LN2 = 1.4426950408889634, // Long bits 0x3ff71547652b82feL. - INV_LN2_H = 1.4426950216293335, // Long bits 0x3ff7154760000000L. - INV_LN2_L = 1.9259629911266175e-8; // Long bits 0x3e54ae0bf85ddf44L. - - /** - * Constants for computing {@link #log(double)}. - */ - private static final double - LG1 = 0.6666666666666735, // Long bits 0x3fe5555555555593L. - LG2 = 0.3999999999940942, // Long bits 0x3fd999999997fa04L. - LG3 = 0.2857142874366239, // Long bits 0x3fd2492494229359L. - LG4 = 0.22222198432149784, // Long bits 0x3fcc71c51d8e78afL. - LG5 = 0.1818357216161805, // Long bits 0x3fc7466496cb03deL. - LG6 = 0.15313837699209373, // Long bits 0x3fc39a09d078c69fL. - LG7 = 0.14798198605116586; // Long bits 0x3fc2f112df3e5244L. - - /** - * Constants for computing {@link #pow(double, double)}. L and P are - * coefficients for series; OVT is -(1024-log2(ovfl+.5ulp)); and DP is ???. - * The P coefficients also calculate {@link #exp(double)}. - */ - private static final double - L1 = 0.5999999999999946, // Long bits 0x3fe3333333333303L. - L2 = 0.4285714285785502, // Long bits 0x3fdb6db6db6fabffL. - L3 = 0.33333332981837743, // Long bits 0x3fd55555518f264dL. - L4 = 0.272728123808534, // Long bits 0x3fd17460a91d4101L. - L5 = 0.23066074577556175, // Long bits 0x3fcd864a93c9db65L. - L6 = 0.20697501780033842, // Long bits 0x3fca7e284a454eefL. - P1 = 0.16666666666666602, // Long bits 0x3fc555555555553eL. - P2 = -2.7777777777015593e-3, // Long bits 0xbf66c16c16bebd93L. - P3 = 6.613756321437934e-5, // Long bits 0x3f11566aaf25de2cL. - P4 = -1.6533902205465252e-6, // Long bits 0xbebbbd41c5d26bf1L. - P5 = 4.1381367970572385e-8, // Long bits 0x3e66376972bea4d0L. - DP_H = 0.5849624872207642, // Long bits 0x3fe2b80340000000L. - DP_L = 1.350039202129749e-8, // Long bits 0x3e4cfdeb43cfd006L. - OVT = 8.008566259537294e-17; // Long bits 0x3c971547652b82feL. - - /** - * Coefficients for computing {@link #sin(double)}. - */ - private static final double - S1 = -0.16666666666666632, // Long bits 0xbfc5555555555549L. - S2 = 8.33333333332249e-3, // Long bits 0x3f8111111110f8a6L. - S3 = -1.984126982985795e-4, // Long bits 0xbf2a01a019c161d5L. - S4 = 2.7557313707070068e-6, // Long bits 0x3ec71de357b1fe7dL. - S5 = -2.5050760253406863e-8, // Long bits 0xbe5ae5e68a2b9cebL. - S6 = 1.58969099521155e-10; // Long bits 0x3de5d93a5acfd57cL. - - /** - * Coefficients for computing {@link #cos(double)}. - */ - private static final double - C1 = 0.0416666666666666, // Long bits 0x3fa555555555554cL. - C2 = -1.388888888887411e-3, // Long bits 0xbf56c16c16c15177L. - C3 = 2.480158728947673e-5, // Long bits 0x3efa01a019cb1590L. - C4 = -2.7557314351390663e-7, // Long bits 0xbe927e4f809c52adL. - C5 = 2.087572321298175e-9, // Long bits 0x3e21ee9ebdb4b1c4L. - C6 = -1.1359647557788195e-11; // Long bits 0xbda8fae9be8838d4L. - - /** - * Coefficients for computing {@link #tan(double)}. - */ - private static final double - T0 = 0.3333333333333341, // Long bits 0x3fd5555555555563L. - T1 = 0.13333333333320124, // Long bits 0x3fc111111110fe7aL. - T2 = 0.05396825397622605, // Long bits 0x3faba1ba1bb341feL. - T3 = 0.021869488294859542, // Long bits 0x3f9664f48406d637L. - T4 = 8.8632398235993e-3, // Long bits 0x3f8226e3e96e8493L. - T5 = 3.5920791075913124e-3, // Long bits 0x3f6d6d22c9560328L. - T6 = 1.4562094543252903e-3, // Long bits 0x3f57dbc8fee08315L. - T7 = 5.880412408202641e-4, // Long bits 0x3f4344d8f2f26501L. - T8 = 2.464631348184699e-4, // Long bits 0x3f3026f71a8d1068L. - T9 = 7.817944429395571e-5, // Long bits 0x3f147e88a03792a6L. - T10 = 7.140724913826082e-5, // Long bits 0x3f12b80f32f0a7e9L. - T11 = -1.8558637485527546e-5, // Long bits 0xbef375cbdb605373L. - T12 = 2.590730518636337e-5; // Long bits 0x3efb2a7074bf7ad4L. - - /** - * Coefficients for computing {@link #asin(double)} and - * {@link #acos(double)}. - */ - private static final double - PS0 = 0.16666666666666666, // Long bits 0x3fc5555555555555L. - PS1 = -0.3255658186224009, // Long bits 0xbfd4d61203eb6f7dL. - PS2 = 0.20121253213486293, // Long bits 0x3fc9c1550e884455L. - PS3 = -0.04005553450067941, // Long bits 0xbfa48228b5688f3bL. - PS4 = 7.915349942898145e-4, // Long bits 0x3f49efe07501b288L. - PS5 = 3.479331075960212e-5, // Long bits 0x3f023de10dfdf709L. - QS1 = -2.403394911734414, // Long bits 0xc0033a271c8a2d4bL. - QS2 = 2.0209457602335057, // Long bits 0x40002ae59c598ac8L. - QS3 = -0.6882839716054533, // Long bits 0xbfe6066c1b8d0159L. - QS4 = 0.07703815055590194; // Long bits 0x3fb3b8c5b12e9282L. - - /** - * Coefficients for computing {@link #atan(double)}. - */ - private static final double - ATAN_0_5H = 0.4636476090008061, // Long bits 0x3fddac670561bb4fL. - ATAN_0_5L = 2.2698777452961687e-17, // Long bits 0x3c7a2b7f222f65e2L. - ATAN_1_5H = 0.982793723247329, // Long bits 0x3fef730bd281f69bL. - ATAN_1_5L = 1.3903311031230998e-17, // Long bits 0x3c7007887af0cbbdL. - AT0 = 0.3333333333333293, // Long bits 0x3fd555555555550dL. - AT1 = -0.19999999999876483, // Long bits 0xbfc999999998ebc4L. - AT2 = 0.14285714272503466, // Long bits 0x3fc24924920083ffL. - AT3 = -0.11111110405462356, // Long bits 0xbfbc71c6fe231671L. - AT4 = 0.09090887133436507, // Long bits 0x3fb745cdc54c206eL. - AT5 = -0.0769187620504483, // Long bits 0xbfb3b0f2af749a6dL. - AT6 = 0.06661073137387531, // Long bits 0x3fb10d66a0d03d51L. - AT7 = -0.058335701337905735, // Long bits 0xbfadde2d52defd9aL. - AT8 = 0.049768779946159324, // Long bits 0x3fa97b4b24760debL. - AT9 = -0.036531572744216916, // Long bits 0xbfa2b4442c6a6c2fL. - AT10 = 0.016285820115365782; // Long bits 0x3f90ad3ae322da11L. - - /** - * Helper function for reducing an angle to a multiple of pi/2 within - * [-pi/4, pi/4]. - * - * @param x the angle; not infinity or NaN, and outside pi/4 - * @param y an array of 2 doubles modified to hold the remander x % pi/2 - * @return the quadrant of the result, mod 4: 0: [-pi/4, pi/4], - * 1: [pi/4, 3*pi/4], 2: [3*pi/4, 5*pi/4], 3: [-3*pi/4, -pi/4] - */ - private static int remPiOver2(double x, double[] y) - { - boolean negative = x < 0; - x = abs(x); - double z; - int n; - if (Configuration.DEBUG && (x <= PI / 4 || x != x - || x == Double.POSITIVE_INFINITY)) - throw new InternalError("Assertion failure"); - if (x < 3 * PI / 4) // If |x| is small. - { - z = x - PIO2_1; - if ((float) x != (float) (PI / 2)) // 33+53 bit pi is good enough. - { - y[0] = z - PIO2_1L; - y[1] = z - y[0] - PIO2_1L; - } - else // Near pi/2, use 33+33+53 bit pi. - { - z -= PIO2_2; - y[0] = z - PIO2_2L; - y[1] = z - y[0] - PIO2_2L; - } - n = 1; - } - else if (x <= TWO_20 * PI / 2) // Medium size. - { - n = (int) (2 / PI * x + 0.5); - z = x - n * PIO2_1; - double w = n * PIO2_1L; // First round good to 85 bits. - y[0] = z - w; - if (n >= 32 || (float) x == (float) (w)) - { - if (x / y[0] >= TWO_16) // Second iteration, good to 118 bits. - { - double t = z; - w = n * PIO2_2; - z = t - w; - w = n * PIO2_2L - (t - z - w); - y[0] = z - w; - if (x / y[0] >= TWO_49) // Third iteration, 151 bits accuracy. - { - t = z; - w = n * PIO2_3; - z = t - w; - w = n * PIO2_3L - (t - z - w); - y[0] = z - w; - } - } - } - y[1] = z - y[0] - w; - } - else - { - // All other (large) arguments. - int e0 = (int) (Double.doubleToLongBits(x) >> 52) - 1046; - z = scale(x, -e0); // e0 = ilogb(z) - 23. - double[] tx = new double[3]; - for (int i = 0; i < 2; i++) - { - tx[i] = (int) z; - z = (z - tx[i]) * TWO_24; - } - tx[2] = z; - int nx = 2; - while (tx[nx] == 0) - nx--; - n = remPiOver2(tx, y, e0, nx); - } - if (negative) - { - y[0] = -y[0]; - y[1] = -y[1]; - return -n; - } - return n; - } - - /** - * Helper function for reducing an angle to a multiple of pi/2 within - * [-pi/4, pi/4]. - * - * @param x the positive angle, broken into 24-bit chunks - * @param y an array of 2 doubles modified to hold the remander x % pi/2 - * @param e0 the exponent of x[0] - * @param nx the last index used in x - * @return the quadrant of the result, mod 4: 0: [-pi/4, pi/4], - * 1: [pi/4, 3*pi/4], 2: [3*pi/4, 5*pi/4], 3: [-3*pi/4, -pi/4] - */ - private static int remPiOver2(double[] x, double[] y, int e0, int nx) - { - int i; - int ih; - int n; - double fw; - double z; - int[] iq = new int[20]; - double[] f = new double[20]; - double[] q = new double[20]; - boolean recompute = false; - - // Initialize jk, jz, jv, q0; note that 3>q0. - int jk = 4; - int jz = jk; - int jv = max((e0 - 3) / 24, 0); - int q0 = e0 - 24 * (jv + 1); - - // Set up f[0] to f[nx+jk] where f[nx+jk] = TWO_OVER_PI[jv+jk]. - int j = jv - nx; - int m = nx + jk; - for (i = 0; i <= m; i++, j++) - f[i] = (j < 0) ? 0 : TWO_OVER_PI[j]; - - // Compute q[0],q[1],...q[jk]. - for (i = 0; i <= jk; i++) - { - for (j = 0, fw = 0; j <= nx; j++) - fw += x[j] * f[nx + i - j]; - q[i] = fw; - } - - do - { - // Distill q[] into iq[] reversingly. - for (i = 0, j = jz, z = q[jz]; j > 0; i++, j--) - { - fw = (int) (1 / TWO_24 * z); - iq[i] = (int) (z - TWO_24 * fw); - z = q[j - 1] + fw; - } - - // Compute n. - z = scale(z, q0); - z -= 8 * floor(z * 0.125); // Trim off integer >= 8. - n = (int) z; - z -= n; - ih = 0; - if (q0 > 0) // Need iq[jz-1] to determine n. - { - i = iq[jz - 1] >> (24 - q0); - n += i; - iq[jz - 1] -= i << (24 - q0); - ih = iq[jz - 1] >> (23 - q0); - } - else if (q0 == 0) - ih = iq[jz - 1] >> 23; - else if (z >= 0.5) - ih = 2; - - if (ih > 0) // If q > 0.5. - { - n += 1; - int carry = 0; - for (i = 0; i < jz; i++) // Compute 1-q. - { - j = iq[i]; - if (carry == 0) - { - if (j != 0) - { - carry = 1; - iq[i] = 0x1000000 - j; - } - } - else - iq[i] = 0xffffff - j; - } - switch (q0) - { - case 1: // Rare case: chance is 1 in 12 for non-default. - iq[jz - 1] &= 0x7fffff; - break; - case 2: - iq[jz - 1] &= 0x3fffff; - } - if (ih == 2) - { - z = 1 - z; - if (carry != 0) - z -= scale(1, q0); - } - } - - // Check if recomputation is needed. - if (z == 0) - { - j = 0; - for (i = jz - 1; i >= jk; i--) - j |= iq[i]; - if (j == 0) // Need recomputation. - { - int k; - for (k = 1; iq[jk - k] == 0; k++); // k = no. of terms needed. - - for (i = jz + 1; i <= jz + k; i++) // Add q[jz+1] to q[jz+k]. - { - f[nx + i] = TWO_OVER_PI[jv + i]; - for (j = 0, fw = 0; j <= nx; j++) - fw += x[j] * f[nx + i - j]; - q[i] = fw; - } - jz += k; - recompute = true; - } - } - } - while (recompute); - - // Chop off zero terms. - if (z == 0) - { - jz--; - q0 -= 24; - while (iq[jz] == 0) - { - jz--; - q0 -= 24; - } - } - else // Break z into 24-bit if necessary. - { - z = scale(z, -q0); - if (z >= TWO_24) - { - fw = (int) (1 / TWO_24 * z); - iq[jz] = (int) (z - TWO_24 * fw); - jz++; - q0 += 24; - iq[jz] = (int) fw; - } - else - iq[jz] = (int) z; - } - - // Convert integer "bit" chunk to floating-point value. - fw = scale(1, q0); - for (i = jz; i >= 0; i--) - { - q[i] = fw * iq[i]; - fw *= 1 / TWO_24; - } - - // Compute PI_OVER_TWO[0,...,jk]*q[jz,...,0]. - double[] fq = new double[20]; - for (i = jz; i >= 0; i--) - { - fw = 0; - for (int k = 0; k <= jk && k <= jz - i; k++) - fw += PI_OVER_TWO[k] * q[i + k]; - fq[jz - i] = fw; - } - - // Compress fq[] into y[]. - fw = 0; - for (i = jz; i >= 0; i--) - fw += fq[i]; - y[0] = (ih == 0) ? fw : -fw; - fw = fq[0] - fw; - for (i = 1; i <= jz; i++) - fw += fq[i]; - y[1] = (ih == 0) ? fw : -fw; - return n; - } - - /** - * Helper method for scaling a double by a power of 2. - * - * @param x the double - * @param n the scale; |n| < 2048 - * @return x * 2**n - */ - private static double scale(double x, int n) - { - if (Configuration.DEBUG && abs(n) >= 2048) - throw new InternalError("Assertion failure"); - if (x == 0 || x == Double.NEGATIVE_INFINITY - || ! (x < Double.POSITIVE_INFINITY) || n == 0) - return x; - long bits = Double.doubleToLongBits(x); - int exp = (int) (bits >> 52) & 0x7ff; - if (exp == 0) // Subnormal x. - { - x *= TWO_54; - exp = ((int) (Double.doubleToLongBits(x) >> 52) & 0x7ff) - 54; - } - exp += n; - if (exp > 0x7fe) // Overflow. - return Double.POSITIVE_INFINITY * x; - if (exp > 0) // Normal. - return Double.longBitsToDouble((bits & 0x800fffffffffffffL) - | ((long) exp << 52)); - if (exp <= -54) - return 0 * x; // Underflow. - exp += 54; // Subnormal result. - x = Double.longBitsToDouble((bits & 0x800fffffffffffffL) - | ((long) exp << 52)); - return x * (1 / TWO_54); - } - - /** - * Helper trig function; computes sin in range [-pi/4, pi/4]. - * - * @param x angle within about pi/4 - * @param y tail of x, created by remPiOver2 - * @return sin(x+y) - */ - private static double sin(double x, double y) - { - if (Configuration.DEBUG && abs(x + y) > 0.7854) - throw new InternalError("Assertion failure"); - if (abs(x) < 1 / TWO_27) - return x; // If |x| ~< 2**-27, already know answer. - - double z = x * x; - double v = z * x; - double r = S2 + z * (S3 + z * (S4 + z * (S5 + z * S6))); - if (y == 0) - return x + v * (S1 + z * r); - return x - ((z * (0.5 * y - v * r) - y) - v * S1); - } - - /** - * Helper trig function; computes cos in range [-pi/4, pi/4]. - * - * @param x angle within about pi/4 - * @param y tail of x, created by remPiOver2 - * @return cos(x+y) - */ - private static double cos(double x, double y) - { - if (Configuration.DEBUG && abs(x + y) > 0.7854) - throw new InternalError("Assertion failure"); - x = abs(x); - if (x < 1 / TWO_27) - return 1; // If |x| ~< 2**-27, already know answer. - - double z = x * x; - double r = z * (C1 + z * (C2 + z * (C3 + z * (C4 + z * (C5 + z * C6))))); - - if (x < 0.3) - return 1 - (0.5 * z - (z * r - x * y)); - - double qx = (x > 0.78125) ? 0.28125 : (x * 0.25); - return 1 - qx - ((0.5 * z - qx) - (z * r - x * y)); - } - - /** - * Helper trig function; computes tan in range [-pi/4, pi/4]. - * - * @param x angle within about pi/4 - * @param y tail of x, created by remPiOver2 - * @param invert true iff -1/tan should be returned instead - * @return tan(x+y) - */ - private static double tan(double x, double y, boolean invert) - { - // PI/2 is irrational, so no double is a perfect multiple of it. - if (Configuration.DEBUG && (abs(x + y) > 0.7854 || (x == 0 && invert))) - throw new InternalError("Assertion failure"); - boolean negative = x < 0; - if (negative) - { - x = -x; - y = -y; - } - if (x < 1 / TWO_28) // If |x| ~< 2**-28, already know answer. - return (negative ? -1 : 1) * (invert ? -1 / x : x); - - double z; - double w; - boolean large = x >= 0.6744; - if (large) - { - z = PI / 4 - x; - w = PI_L / 4 - y; - x = z + w; - y = 0; - } - z = x * x; - w = z * z; - // Break x**5*(T1+x**2*T2+...) into - // x**5(T1+x**4*T3+...+x**20*T11) - // + x**5(x**2*(T2+x**4*T4+...+x**22*T12)). - double r = T1 + w * (T3 + w * (T5 + w * (T7 + w * (T9 + w * T11)))); - double v = z * (T2 + w * (T4 + w * (T6 + w * (T8 + w * (T10 + w * T12))))); - double s = z * x; - r = y + z * (s * (r + v) + y); - r += T0 * s; - w = x + r; - if (large) - { - v = invert ? -1 : 1; - return (negative ? -1 : 1) * (v - 2 * (x - (w * w / (w + v) - r))); - } - if (! invert) - return w; - - // Compute -1.0/(x+r) accurately. - z = (float) w; - v = r - (z - x); - double a = -1 / w; - double t = (float) a; - return t + a * (1 + t * z + t * v); - } -} diff --git a/libjava/java/lang/StringIndexOutOfBoundsException.java b/libjava/java/lang/StringIndexOutOfBoundsException.java deleted file mode 100644 index ebc4a04a391..00000000000 --- a/libjava/java/lang/StringIndexOutOfBoundsException.java +++ /dev/null @@ -1,85 +0,0 @@ -/* StringIndexOutOfBoundsException.java -- thrown to indicate attempt to - exceed string bounds - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang; - -/** - * This exception can be thrown to indicate an attempt to access an index - * which is out of bounds of a String. Any negative integer, and a positive - * integer greater than or equal to the size of the string, is an index - * which would be out of bounds. - * - * @author Brian Jones - * @author Warren Levy (warrenl@cygnus.com) - * @status updated to 1.4 - */ -public class StringIndexOutOfBoundsException extends IndexOutOfBoundsException -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = -6762910422159637258L; - - /** - * Create an exception without a message. - */ - public StringIndexOutOfBoundsException() - { - } - - /** - * Create an exception with a message. - * - * @param s the message - */ - public StringIndexOutOfBoundsException(String s) - { - super(s); - } - - /** - * Create an exception noting the illegal index. - * - * @param index the invalid index - */ - public StringIndexOutOfBoundsException(int index) - { - super("String index out of range: " + index); - } -} diff --git a/libjava/java/lang/ThreadDeath.java b/libjava/java/lang/ThreadDeath.java deleted file mode 100644 index c7d88fb2a25..00000000000 --- a/libjava/java/lang/ThreadDeath.java +++ /dev/null @@ -1,68 +0,0 @@ -/* ThreadDeath.java - special exception registering Thread death - Copyright (C) 1998, 1999, 2000, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang; - -/** - * ThreadDeath is thrown in a thread when someone calls <code>stop()</code> - * on that thread. <b>Important:</b> Make sure you rethrow this exception - * if you catch it. If you don't, the thread will not die. - * - * <p>This is an Error rather than an exception, so that normal code will - * not catch it. It is intended for asynchronous cleanup when using the - * deprecated Thread.stop() method. - * - * @author John Keiser - * @author Tom Tromey (tromey@cygnus.com) - * @see Thread#stop() - * @status updated to 1.4 - */ -public class ThreadDeath extends Error -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = -4417128565033088268L; - - /** - * Create an error without a message. - */ - public ThreadDeath() - { - } -} diff --git a/libjava/java/lang/ThreadGroup.java b/libjava/java/lang/ThreadGroup.java deleted file mode 100644 index 6e4c27a7135..00000000000 --- a/libjava/java/lang/ThreadGroup.java +++ /dev/null @@ -1,749 +0,0 @@ -/* ThreadGroup -- a group of Threads - Copyright (C) 1998, 2000, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.lang; - -import java.util.Vector; - -/** - * ThreadGroup allows you to group Threads together. There is a hierarchy - * of ThreadGroups, and only the initial ThreadGroup has no parent. A Thread - * may access information about its own ThreadGroup, but not its parents or - * others outside the tree. - * - * @author John Keiser - * @author Tom Tromey - * @author Bryce McKinlay - * @author Eric Blake (ebb9@email.byu.edu) - * @see Thread - * @since 1.0 - * @status updated to 1.4 - */ -public class ThreadGroup -{ - /** The Initial, top-level ThreadGroup. */ - static ThreadGroup root = new ThreadGroup(); - - /** - * This flag is set if an uncaught exception occurs. The runtime should - * check this and exit with an error status if it is set. - */ - static boolean had_uncaught_exception; - - /** The parent thread group. */ - private final ThreadGroup parent; - - /** The group name, non-null. */ - final String name; - - /** The threads in the group. */ - private final Vector threads = new Vector(); - - /** Child thread groups, or null when this group is destroyed. */ - private Vector groups = new Vector(); - - /** If all threads in the group are daemons. */ - private boolean daemon_flag = false; - - /** The maximum group priority. */ - private int maxpri; - - /** - * Hidden constructor to build the root node. - */ - private ThreadGroup() - { - name = "main"; - parent = null; - maxpri = Thread.MAX_PRIORITY; - } - - /** - * Create a new ThreadGroup using the given name and the current thread's - * ThreadGroup as a parent. There may be a security check, - * <code>checkAccess</code>. - * - * @param name the name to use for the ThreadGroup - * @throws SecurityException if the current thread cannot create a group - * @see #checkAccess() - */ - public ThreadGroup(String name) - { - this(Thread.currentThread().group, name); - } - - /** - * Create a new ThreadGroup using the given name and parent group. The new - * group inherits the maximum priority and daemon status of its parent - * group. There may be a security check, <code>checkAccess</code>. - * - * @param name the name to use for the ThreadGroup - * @param parent the ThreadGroup to use as a parent - * @throws NullPointerException if parent is null - * @throws SecurityException if the current thread cannot create a group - * @throws IllegalThreadStateException if the parent is destroyed - * @see #checkAccess() - */ - public ThreadGroup(ThreadGroup parent, String name) - { - parent.checkAccess(); - this.parent = parent; - this.name = name; - maxpri = parent.maxpri; - daemon_flag = parent.daemon_flag; - synchronized (parent) - { - if (parent.groups == null) - throw new IllegalThreadStateException(); - parent.groups.add(this); - } - } - - /** - * Get the name of this ThreadGroup. - * - * @return the name of this ThreadGroup - */ - public final String getName() - { - return name; - } - - /** - * Get the parent of this ThreadGroup. If the parent is not null, there - * may be a security check, <code>checkAccess</code>. - * - * @return the parent of this ThreadGroup - * @throws SecurityException if permission is denied - */ - public final ThreadGroup getParent() - { - if (parent != null) - parent.checkAccess(); - return parent; - } - - /** - * Get the maximum priority of Threads in this ThreadGroup. Threads created - * after this call in this group may not exceed this priority. - * - * @return the maximum priority of Threads in this ThreadGroup - */ - public final int getMaxPriority() - { - return maxpri; - } - - /** - * Tell whether this ThreadGroup is a daemon group. A daemon group will - * be automatically destroyed when its last thread is stopped and - * its last thread group is destroyed. - * - * @return whether this ThreadGroup is a daemon group - */ - public final boolean isDaemon() - { - return daemon_flag; - } - - /** - * Tell whether this ThreadGroup has been destroyed or not. - * - * @return whether this ThreadGroup has been destroyed or not - * @since 1.1 - */ - public synchronized boolean isDestroyed() - { - return groups == null; - } - - /** - * Set whether this ThreadGroup is a daemon group. A daemon group will be - * destroyed when its last thread is stopped and its last thread group is - * destroyed. There may be a security check, <code>checkAccess</code>. - * - * @param daemon whether this ThreadGroup should be a daemon group - * @throws SecurityException if you cannot modify this ThreadGroup - * @see #checkAccess() - */ - public final void setDaemon(boolean daemon) - { - checkAccess(); - daemon_flag = daemon; - } - - /** - * Set the maximum priority for Threads in this ThreadGroup. setMaxPriority - * can only be used to reduce the current maximum. If maxpri is greater - * than the current Maximum of the parent group, the current value is not - * changed. Otherwise, all groups which belong to this have their priority - * adjusted as well. Calling this does not affect threads already in this - * ThreadGroup. There may be a security check, <code>checkAccess</code>. - * - * @param maxpri the new maximum priority for this ThreadGroup - * @throws SecurityException if you cannot modify this ThreadGroup - * @see #getMaxPriority() - * @see #checkAccess() - */ - public final synchronized void setMaxPriority(int maxpri) - { - checkAccess(); - if (maxpri < Thread.MIN_PRIORITY || maxpri > Thread.MAX_PRIORITY) - return; - if (parent != null && maxpri > parent.maxpri) - maxpri = parent.maxpri; - this.maxpri = maxpri; - if (groups == null) - return; - int i = groups.size(); - while (--i >= 0) - ((ThreadGroup) groups.get(i)).setMaxPriority(maxpri); - } - - /** - * Check whether this ThreadGroup is an ancestor of the specified - * ThreadGroup, or if they are the same. - * - * @param group the group to test on - * @return whether this ThreadGroup is a parent of the specified group - */ - public final boolean parentOf(ThreadGroup group) - { - while (group != null) - { - if (group == this) - return true; - group = group.parent; - } - return false; - } - - /** - * Find out if the current Thread can modify this ThreadGroup. This passes - * the check on to <code>SecurityManager.checkAccess(this)</code>. - * - * @throws SecurityException if the current Thread cannot modify this - * ThreadGroup - * @see SecurityManager#checkAccess(ThreadGroup) - */ - public final void checkAccess() - { - // Bypass System.getSecurityManager, for bootstrap efficiency. - SecurityManager sm = SecurityManager.current; - if (sm != null) - sm.checkAccess(this); - } - - /** - * Return an estimate of the total number of active threads in this - * ThreadGroup and all its descendants. This cannot return an exact number, - * since the status of threads may change after they were counted; but it - * should be pretty close. Based on a JDC bug, - * <a href="http://developer.java.sun.com/developer/bugParade/bugs/4089701.html"> - * 4089701</a>, we take active to mean isAlive(). - * - * @return count of active threads in this ThreadGroup and its descendants - */ - public int activeCount() - { - int total = 0; - if (groups == null) - return total; - int i = threads.size(); - while (--i >= 0) - if (((Thread) threads.get(i)).isAlive()) - total++; - i = groups.size(); - while (--i >= 0) - total += ((ThreadGroup) groups.get(i)).activeCount(); - return total; - } - - /** - * Copy all of the active Threads from this ThreadGroup and its descendants - * into the specified array. If the array is not big enough to hold all - * the Threads, extra Threads will simply not be copied. There may be a - * security check, <code>checkAccess</code>. - * - * @param array the array to put the threads into - * @return the number of threads put into the array - * @throws SecurityException if permission was denied - * @throws NullPointerException if array is null - * @throws ArrayStoreException if a thread does not fit in the array - * @see #activeCount() - * @see #checkAccess() - * @see #enumerate(Thread[], boolean) - */ - public int enumerate(Thread[] array) - { - return enumerate(array, 0, true); - } - - /** - * Copy all of the active Threads from this ThreadGroup and, if desired, - * from its descendants, into the specified array. If the array is not big - * enough to hold all the Threads, extra Threads will simply not be copied. - * There may be a security check, <code>checkAccess</code>. - * - * @param array the array to put the threads into - * @param recurse whether to recurse into descendent ThreadGroups - * @return the number of threads put into the array - * @throws SecurityException if permission was denied - * @throws NullPointerException if array is null - * @throws ArrayStoreException if a thread does not fit in the array - * @see #activeCount() - * @see #checkAccess() - */ - public int enumerate(Thread[] array, boolean recurse) - { - return enumerate(array, 0, recurse); - } - - /** - * Get the number of active groups in this ThreadGroup. This group itself - * is not included in the count. A sub-group is active if it has not been - * destroyed. This cannot return an exact number, since the status of - * threads may change after they were counted; but it should be pretty close. - * - * @return the number of active groups in this ThreadGroup - */ - public int activeGroupCount() - { - if (groups == null) - return 0; - int total = groups.size(); - int i = total; - while (--i >= 0) - total += ((ThreadGroup) groups.get(i)).activeGroupCount(); - return total; - } - - /** - * Copy all active ThreadGroups that are descendants of this ThreadGroup - * into the specified array. If the array is not large enough to hold all - * active ThreadGroups, extra ThreadGroups simply will not be copied. There - * may be a security check, <code>checkAccess</code>. - * - * @param array the array to put the ThreadGroups into - * @return the number of ThreadGroups copied into the array - * @throws SecurityException if permission was denied - * @throws NullPointerException if array is null - * @throws ArrayStoreException if a group does not fit in the array - * @see #activeCount() - * @see #checkAccess() - * @see #enumerate(ThreadGroup[], boolean) - */ - public int enumerate(ThreadGroup[] array) - { - return enumerate(array, 0, true); - } - - /** - * Copy all active ThreadGroups that are children of this ThreadGroup into - * the specified array, and if desired, also all descendents. If the array - * is not large enough to hold all active ThreadGroups, extra ThreadGroups - * simply will not be copied. There may be a security check, - * <code>checkAccess</code>. - * - * @param array the array to put the ThreadGroups into - * @param recurse whether to recurse into descendent ThreadGroups - * @return the number of ThreadGroups copied into the array - * @throws SecurityException if permission was denied - * @throws NullPointerException if array is null - * @throws ArrayStoreException if a group does not fit in the array - * @see #activeCount() - * @see #checkAccess() - */ - public int enumerate(ThreadGroup[] array, boolean recurse) - { - return enumerate(array, 0, recurse); - } - - /** - * Stop all Threads in this ThreadGroup and its descendants. - * - * <p>This is inherently unsafe, as it can interrupt synchronized blocks and - * leave data in bad states. Hence, there is a security check: - * <code>checkAccess()</code>, followed by further checks on each thread - * being stopped. - * - * @throws SecurityException if permission is denied - * @see #checkAccess() - * @see Thread#stop(Throwable) - * @deprecated unsafe operation, try not to use - */ - public final synchronized void stop() - { - checkAccess(); - if (groups == null) - return; - int i = threads.size(); - while (--i >= 0) - ((Thread) threads.get(i)).stop(); - i = groups.size(); - while (--i >= 0) - ((ThreadGroup) groups.get(i)).stop(); - } - - /** - * Interrupt all Threads in this ThreadGroup and its sub-groups. There may - * be a security check, <code>checkAccess</code>. - * - * @throws SecurityException if permission is denied - * @see #checkAccess() - * @see Thread#interrupt() - * @since 1.2 - */ - public final synchronized void interrupt() - { - checkAccess(); - if (groups == null) - return; - int i = threads.size(); - while (--i >= 0) - ((Thread) threads.get(i)).interrupt(); - i = groups.size(); - while (--i >= 0) - ((ThreadGroup) groups.get(i)).interrupt(); - } - - /** - * Suspend all Threads in this ThreadGroup and its descendants. - * - * <p>This is inherently unsafe, as suspended threads still hold locks, - * which can lead to deadlock. Hence, there is a security check: - * <code>checkAccess()</code>, followed by further checks on each thread - * being suspended. - * - * @throws SecurityException if permission is denied - * @see #checkAccess() - * @see Thread#suspend() - * @deprecated unsafe operation, try not to use - */ - public final synchronized void suspend() - { - checkAccess(); - if (groups == null) - return; - int i = threads.size(); - while (--i >= 0) - ((Thread) threads.get(i)).suspend(); - i = groups.size(); - while (--i >= 0) - ((ThreadGroup) groups.get(i)).suspend(); - } - - /** - * Resume all suspended Threads in this ThreadGroup and its descendants. - * To mirror suspend(), there is a security check: - * <code>checkAccess()</code>, followed by further checks on each thread - * being resumed. - * - * @throws SecurityException if permission is denied - * @see #checkAccess() - * @see Thread#suspend() - * @deprecated pointless, since suspend is deprecated - */ - public final synchronized void resume() - { - checkAccess(); - if (groups == null) - return; - int i = threads.size(); - while (--i >= 0) - ((Thread) threads.get(i)).resume(); - i = groups.size(); - while (--i >= 0) - ((ThreadGroup) groups.get(i)).resume(); - } - - /** - * Destroy this ThreadGroup. The group must be empty, meaning that all - * threads and sub-groups have completed execution. Daemon groups are - * destroyed automatically. There may be a security check, - * <code>checkAccess</code>. - * - * @throws IllegalThreadStateException if the ThreadGroup is not empty, or - * was previously destroyed - * @throws SecurityException if permission is denied - * @see #checkAccess() - */ - public final synchronized void destroy() - { - checkAccess(); - if (! threads.isEmpty() || groups == null) - throw new IllegalThreadStateException(); - int i = groups.size(); - while (--i >= 0) - ((ThreadGroup) groups.get(i)).destroy(); - groups = null; - if (parent != null) - parent.removeGroup(this); - } - - /** - * Print out information about this ThreadGroup to System.out. This is - * meant for debugging purposes. <b>WARNING:</b> This method is not secure, - * and can print the name of threads to standard out even when you cannot - * otherwise get at such threads. - */ - public void list() - { - list(""); - } - - /** - * When a Thread in this ThreadGroup does not catch an exception, the - * virtual machine calls this method. The default implementation simply - * passes the call to the parent; then in top ThreadGroup, it will - * ignore ThreadDeath and print the stack trace of any other throwable. - * Override this method if you want to handle the exception in a different - * manner. - * - * @param thread the thread that exited - * @param t the uncaught throwable - * @throws NullPointerException if t is null - * @see ThreadDeath - * @see System#err - * @see Throwable#printStackTrace() - */ - public void uncaughtException(Thread thread, Throwable t) - { - if (parent != null) - parent.uncaughtException(thread, t); - else if (! (t instanceof ThreadDeath)) - { - if (t == null) - throw new NullPointerException(); - had_uncaught_exception = true; - try - { - if (thread != null) - System.err.print("Exception in thread \"" + thread.name + "\" "); - t.printStackTrace(System.err); - } - catch (Throwable x) - { - // This means that something is badly screwed up with the runtime, - // or perhaps someone overloaded the Throwable.printStackTrace to - // die. In any case, try to deal with it gracefully. - try - { - System.err.println(t); - System.err.println("*** Got " + x - + " while trying to print stack trace."); - } - catch (Throwable x2) - { - // Here, someone may have overloaded t.toString() or - // x.toString() to die. Give up all hope; we can't even chain - // the exception, because the chain would likewise die. - System.err.println("*** Catastrophic failure while handling " - + "uncaught exception."); - throw new InternalError(); - } - } - } - } - - /** - * Originally intended to tell the VM whether it may suspend Threads in - * low memory situations, this method was never implemented by Sun, and - * is hence a no-op. - * - * @param allow whether to allow low-memory thread suspension; ignored - * @return false - * @since 1.1 - * @deprecated pointless, since suspend is deprecated - */ - public boolean allowThreadSuspension(boolean allow) - { - return false; - } - - /** - * Return a human-readable String representing this ThreadGroup. The format - * of the string is:<br> - * <code>getClass().getName() + "[name=" + getName() + ",maxpri=" - * + getMaxPriority() + ']'</code>. - * - * @return a human-readable String representing this ThreadGroup - */ - public String toString() - { - return getClass().getName() + "[name=" + name + ",maxpri=" + maxpri + ']'; - } - - /** - * Implements enumerate. - * - * @param list the array to put the threads into - * @param next the next open slot in the array - * @param recurse whether to recurse into descendent ThreadGroups - * @return the number of threads put into the array - * @throws SecurityException if permission was denied - * @throws NullPointerException if list is null - * @throws ArrayStoreException if a thread does not fit in the array - * @see #enumerate(Thread[]) - * @see #enumerate(Thread[], boolean) - */ - private int enumerate(Thread[] list, int next, boolean recurse) - { - checkAccess(); - if (groups == null) - return next; - int i = threads.size(); - while (--i >= 0 && next < list.length) - { - Thread t = (Thread) threads.get(i); - if (t.isAlive()) - list[next++] = t; - } - if (recurse) - { - i = groups.size(); - while (--i >= 0 && next < list.length) - { - ThreadGroup g = (ThreadGroup) groups.get(i); - next = g.enumerate(list, next, true); - } - } - return next; - } - - /** - * Implements enumerate. - * - * @param list the array to put the groups into - * @param next the next open slot in the array - * @param recurse whether to recurse into descendent ThreadGroups - * @return the number of groups put into the array - * @throws SecurityException if permission was denied - * @throws NullPointerException if list is null - * @throws ArrayStoreException if a group does not fit in the array - * @see #enumerate(ThreadGroup[]) - * @see #enumerate(ThreadGroup[], boolean) - */ - private int enumerate(ThreadGroup[] list, int next, boolean recurse) - { - checkAccess(); - if (groups == null) - return next; - int i = groups.size(); - while (--i >= 0 && next < list.length) - { - ThreadGroup g = (ThreadGroup) groups.get(i); - list[next++] = g; - if (recurse && next != list.length) - next = g.enumerate(list, next, true); - } - return next; - } - - /** - * Implements list. - * - * @param indentation the current level of indentation - * @see #list() - */ - private void list(String indentation) - { - if (groups == null) - return; - System.out.println(indentation + this); - indentation += " "; - int i = threads.size(); - while (--i >= 0) - System.out.println(indentation + threads.get(i)); - i = groups.size(); - while (--i >= 0) - ((ThreadGroup) groups.get(i)).list(indentation); - } - - /** - * Add a thread to the group. Called by Thread constructors. - * - * @param t the thread to add, non-null - * @throws IllegalThreadStateException if the group is destroyed - */ - final synchronized void addThread(Thread t) - { - if (groups == null) - throw new IllegalThreadStateException("ThreadGroup is destroyed"); - threads.add(t); - } - - /** - * Called by the VM to remove a thread that has died. - * - * @param t the thread to remove, non-null - * @XXX A ThreadListener to call this might be nice. - */ - final synchronized void removeThread(Thread t) - { - if (groups == null) - return; - threads.remove(t); - t.group = null; - // Daemon groups are automatically destroyed when all their threads die. - if (daemon_flag && groups.size() == 0 && threads.size() == 0) - { - // We inline destroy to avoid the access check. - groups = null; - if (parent != null) - parent.removeGroup(this); - } - } - - /** - * Called when a group is destroyed, to remove it from its parent. - * - * @param g the destroyed group, non-null - */ - final synchronized void removeGroup(ThreadGroup g) - { - groups.remove(g); - // Daemon groups are automatically destroyed when all their threads die. - if (daemon_flag && groups.size() == 0 && threads.size() == 0) - { - // We inline destroy to avoid the access check. - groups = null; - if (parent != null) - parent.removeGroup(this); - } - } -} // class ThreadGroup diff --git a/libjava/java/lang/Throwable.java b/libjava/java/lang/Throwable.java deleted file mode 100644 index c47a14bf040..00000000000 --- a/libjava/java/lang/Throwable.java +++ /dev/null @@ -1,563 +0,0 @@ -/* java.lang.Throwable -- Root class for all Exceptions and Errors - Copyright (C) 1998, 1999, 2002, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.lang; - -import gnu.classpath.SystemProperties; - -import java.io.PrintStream; -import java.io.PrintWriter; -import java.io.Serializable; - -/** - * Throwable is the superclass of all exceptions that can be raised. - * - * <p>There are two special cases: {@link Error} and {@link RuntimeException}: - * these two classes (and their subclasses) are considered unchecked - * exceptions, and are either frequent enough or catastrophic enough that you - * do not need to declare them in <code>throws</code> clauses. Everything - * else is a checked exception, and is ususally a subclass of - * {@link Exception}; these exceptions have to be handled or declared. - * - * <p>Instances of this class are usually created with knowledge of the - * execution context, so that you can get a stack trace of the problem spot - * in the code. Also, since JDK 1.4, Throwables participate in "exception - * chaining." This means that one exception can be caused by another, and - * preserve the information of the original. - * - * <p>One reason this is useful is to wrap exceptions to conform to an - * interface. For example, it would be bad design to require all levels - * of a program interface to be aware of the low-level exceptions thrown - * at one level of abstraction. Another example is wrapping a checked - * exception in an unchecked one, to communicate that failure occured - * while still obeying the method throws clause of a superclass. - * - * <p>A cause is assigned in one of two ways; but can only be assigned once - * in the lifetime of the Throwable. There are new constructors added to - * several classes in the exception hierarchy that directly initialize the - * cause, or you can use the <code>initCause</code> method. This second - * method is especially useful if the superclass has not been retrofitted - * with new constructors:<br> - * <pre> - * try - * { - * lowLevelOp(); - * } - * catch (LowLevelException lle) - * { - * throw (HighLevelException) new HighLevelException().initCause(lle); - * } - * </pre> - * Notice the cast in the above example; without it, your method would need - * a throws clase that declared Throwable, defeating the purpose of chainig - * your exceptions. - * - * <p>By convention, exception classes have two constructors: one with no - * arguments, and one that takes a String for a detail message. Further, - * classes which are likely to be used in an exception chain also provide - * a constructor that takes a Throwable, with or without a detail message - * string. - * - * <p>Another 1.4 feature is the StackTrace, a means of reflection that - * allows the program to inspect the context of the exception, and which is - * serialized, so that remote procedure calls can correctly pass exceptions. - * - * @author Brian Jones - * @author John Keiser - * @author Mark Wielaard - * @author Tom Tromey - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.0 - * @status updated to 1.4 - */ -public class Throwable implements Serializable -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = -3042686055658047285L; - - /** - * The detail message. - * - * @serial specific details about the exception, may be null - */ - private final String detailMessage; - - /** - * The cause of the throwable, including null for an unknown or non-chained - * cause. This may only be set once; so the field is set to - * <code>this</code> until initialized. - * - * @serial the cause, or null if unknown, or this if not yet set - * @since 1.4 - */ - private Throwable cause = this; - - /** - * The stack trace, in a serialized form. - * - * @serial the elements of the stack trace; this is non-null, and has - * no null entries - * @since 1.4 - */ - private StackTraceElement[] stackTrace; - - /** - * Instantiate this Throwable with an empty message. The cause remains - * uninitialized. {@link #fillInStackTrace()} will be called to set - * up the stack trace. - */ - public Throwable() - { - this((String) null); - } - - /** - * Instantiate this Throwable with the given message. The cause remains - * uninitialized. {@link #fillInStackTrace()} will be called to set - * up the stack trace. - * - * @param message the message to associate with the Throwable - */ - public Throwable(String message) - { - fillInStackTrace(); - detailMessage = message; - } - - /** - * Instantiate this Throwable with the given message and cause. Note that - * the message is unrelated to the message of the cause. - * {@link #fillInStackTrace()} will be called to set up the stack trace. - * - * @param message the message to associate with the Throwable - * @param cause the cause, may be null - * @since 1.4 - */ - public Throwable(String message, Throwable cause) - { - this(message); - this.cause = cause; - } - - /** - * Instantiate this Throwable with the given cause. The message is then - * built as <code>cause == null ? null : cause.toString()</code>. - * {@link #fillInStackTrace()} will be called to set up the stack trace. - * - * @param cause the cause, may be null - * @since 1.4 - */ - public Throwable(Throwable cause) - { - this(cause == null ? null : cause.toString(), cause); - } - - /** - * Get the message associated with this Throwable. - * - * @return the error message associated with this Throwable, may be null - */ - public String getMessage() - { - return detailMessage; - } - - /** - * Get a localized version of this Throwable's error message. - * This method must be overridden in a subclass of Throwable - * to actually produce locale-specific methods. The Throwable - * implementation just returns getMessage(). - * - * @return a localized version of this error message - * @see #getMessage() - * @since 1.1 - */ - public String getLocalizedMessage() - { - return getMessage(); - } - - /** - * Returns the cause of this exception, or null if the cause is not known - * or non-existant. This cause is initialized by the new constructors, - * or by calling initCause. - * - * @return the cause of this Throwable - * @since 1.4 - */ - public Throwable getCause() - { - return cause == this ? null : cause; - } - - /** - * Initialize the cause of this Throwable. This may only be called once - * during the object lifetime, including implicitly by chaining - * constructors. - * - * @param cause the cause of this Throwable, may be null - * @return this - * @throws IllegalArgumentException if cause is this (a Throwable can't be - * its own cause!) - * @throws IllegalStateException if the cause has already been set - * @since 1.4 - */ - public Throwable initCause(Throwable cause) - { - if (cause == this) - throw new IllegalArgumentException(); - if (this.cause != this) - throw new IllegalStateException(); - this.cause = cause; - return this; - } - - /** - * Get a human-readable representation of this Throwable. The detail message - * is retrieved by getLocalizedMessage(). Then, with a null detail - * message, this string is simply the object's class name; otherwise - * the string is <code>getClass().getName() + ": " + message</code>. - * - * @return a human-readable String represting this Throwable - */ - public String toString() - { - String msg = getLocalizedMessage(); - return getClass().getName() + (msg == null ? "" : ": " + msg); - } - - /** - * Print a stack trace to the standard error stream. This stream is the - * current contents of <code>System.err</code>. The first line of output - * is the result of {@link #toString()}, and the remaining lines represent - * the data created by {@link #fillInStackTrace()}. While the format is - * unspecified, this implementation uses the suggested format, demonstrated - * by this example:<br> - * <pre> - * public class Junk - * { - * public static void main(String args[]) - * { - * try - * { - * a(); - * } - * catch(HighLevelException e) - * { - * e.printStackTrace(); - * } - * } - * static void a() throws HighLevelException - * { - * try - * { - * b(); - * } - * catch(MidLevelException e) - * { - * throw new HighLevelException(e); - * } - * } - * static void b() throws MidLevelException - * { - * c(); - * } - * static void c() throws MidLevelException - * { - * try - * { - * d(); - * } - * catch(LowLevelException e) - * { - * throw new MidLevelException(e); - * } - * } - * static void d() throws LowLevelException - * { - * e(); - * } - * static void e() throws LowLevelException - * { - * throw new LowLevelException(); - * } - * } - * class HighLevelException extends Exception - * { - * HighLevelException(Throwable cause) { super(cause); } - * } - * class MidLevelException extends Exception - * { - * MidLevelException(Throwable cause) { super(cause); } - * } - * class LowLevelException extends Exception - * { - * } - * </pre> - * <p> - * <pre> - * HighLevelException: MidLevelException: LowLevelException - * at Junk.a(Junk.java:13) - * at Junk.main(Junk.java:4) - * Caused by: MidLevelException: LowLevelException - * at Junk.c(Junk.java:23) - * at Junk.b(Junk.java:17) - * at Junk.a(Junk.java:11) - * ... 1 more - * Caused by: LowLevelException - * at Junk.e(Junk.java:30) - * at Junk.d(Junk.java:27) - * at Junk.c(Junk.java:21) - * ... 3 more - * </pre> - */ - public void printStackTrace() - { - printStackTrace(System.err); - } - - /** - * Print a stack trace to the specified PrintStream. See - * {@link #printStackTrace()} for the sample format. - * - * @param s the PrintStream to write the trace to - */ - public void printStackTrace(PrintStream s) - { - s.print(stackTraceString()); - } - - /** - * Prints the exception, the detailed message and the stack trace - * associated with this Throwable to the given <code>PrintWriter</code>. - * The actual output written is implemention specific. Use the result of - * <code>getStackTrace()</code> when more precise information is needed. - * - * <p>This implementation first prints a line with the result of this - * object's <code>toString()</code> method. - * <br> - * Then for all elements given by <code>getStackTrace</code> it prints - * a line containing three spaces, the string "at " and the result of calling - * the <code>toString()</code> method on the <code>StackTraceElement</code> - * object. If <code>getStackTrace()</code> returns an empty array it prints - * a line containing three spaces and the string - * "<<No stacktrace available>>". - * <br> - * Then if <code>getCause()</code> doesn't return null it adds a line - * starting with "Caused by: " and the result of calling - * <code>toString()</code> on the cause. - * <br> - * Then for every cause (of a cause, etc) the stacktrace is printed the - * same as for the top level <code>Throwable</code> except that as soon - * as all the remaining stack frames of the cause are the same as the - * the last stack frames of the throwable that the cause is wrapped in - * then a line starting with three spaces and the string "... X more" is - * printed, where X is the number of remaining stackframes. - * - * @param pw the PrintWriter to write the trace to - * @since 1.1 - */ - public void printStackTrace (PrintWriter pw) - { - pw.print(stackTraceString()); - } - - /* - * We use inner class to avoid a static initializer in this basic class. - */ - private static class StaticData - { - static final String nl = SystemProperties.getProperty("line.separator"); - } - - // Create whole stack trace in a stringbuffer so we don't have to print - // it line by line. This prevents printing multiple stack traces from - // different threads to get mixed up when written to the same PrintWriter. - private String stackTraceString() - { - StringBuffer sb = new StringBuffer(); - - // Main stacktrace - StackTraceElement[] stack = getStackTrace(); - stackTraceStringBuffer(sb, this.toString(), stack, 0); - - // The cause(s) - Throwable cause = getCause(); - while (cause != null) - { - // Cause start first line - sb.append("Caused by: "); - - // Cause stacktrace - StackTraceElement[] parentStack = stack; - stack = cause.getStackTrace(); - if (parentStack == null || parentStack.length == 0) - stackTraceStringBuffer(sb, cause.toString(), stack, 0); - else - { - int equal = 0; // Count how many of the last stack frames are equal - int frame = stack.length-1; - int parentFrame = parentStack.length-1; - while (frame > 0 && parentFrame > 0) - { - if (stack[frame].equals(parentStack[parentFrame])) - { - equal++; - frame--; - parentFrame--; - } - else - break; - } - stackTraceStringBuffer(sb, cause.toString(), stack, equal); - } - cause = cause.getCause(); - } - - return sb.toString(); - } - - // Adds to the given StringBuffer a line containing the name and - // all stacktrace elements minus the last equal ones. - private static void stackTraceStringBuffer(StringBuffer sb, String name, - StackTraceElement[] stack, int equal) - { - String nl = StaticData.nl; - // (finish) first line - sb.append(name); - sb.append(nl); - - // The stacktrace - if (stack == null || stack.length == 0) - { - sb.append(" <<No stacktrace available>>"); - sb.append(nl); - } - else - { - for (int i = 0; i < stack.length-equal; i++) - { - sb.append(" at "); - sb.append(stack[i] == null ? "<<Unknown>>" : stack[i].toString()); - sb.append(nl); - } - if (equal > 0) - { - sb.append(" ..."); - sb.append(equal); - sb.append(" more"); - sb.append(nl); - } - } - } - - /** - * Fill in the stack trace with the current execution stack. - * - * @return this same throwable - * @see #printStackTrace() - */ - public Throwable fillInStackTrace() - { - vmState = VMThrowable.fillInStackTrace(this); - stackTrace = null; // Should be regenerated when used. - - return this; - } - - /** - * Provides access to the information printed in {@link #printStackTrace()}. - * The array is non-null, with no null entries, although the virtual - * machine is allowed to skip stack frames. If the array is not 0-length, - * then slot 0 holds the information on the stack frame where the Throwable - * was created (or at least where <code>fillInStackTrace()</code> was - * called). - * - * @return an array of stack trace information, as available from the VM - * @since 1.4 - */ - public StackTraceElement[] getStackTrace() - { - if (stackTrace == null) - if (vmState == null) - stackTrace = new StackTraceElement[0]; - else - { - stackTrace = vmState.getStackTrace(this); - vmState = null; // No longer needed - } - - return stackTrace; - } - - /** - * Change the stack trace manually. This method is designed for remote - * procedure calls, which intend to alter the stack trace before or after - * serialization according to the context of the remote call. - * <p> - * The contents of the given stacktrace is copied so changes to the - * original array do not change the stack trace elements of this - * throwable. - * - * @param stackTrace the new trace to use - * @throws NullPointerException if stackTrace is null or has null elements - * @since 1.4 - */ - public void setStackTrace(StackTraceElement[] stackTrace) - { - int i = stackTrace.length; - StackTraceElement[] st = new StackTraceElement[i]; - - while (--i >= 0) - { - st[i] = stackTrace[i]; - if (st[i] == null) - throw new NullPointerException("Element " + i + " null"); - } - - this.stackTrace = st; - } - - /** - * VM state when fillInStackTrace was called. - * Used by getStackTrace() to get an array of StackTraceElements. - * Cleared when no longer needed. - */ - private transient VMThrowable vmState; -} diff --git a/libjava/java/lang/UnknownError.java b/libjava/java/lang/UnknownError.java deleted file mode 100644 index 7b317bd2aa2..00000000000 --- a/libjava/java/lang/UnknownError.java +++ /dev/null @@ -1,72 +0,0 @@ -/* UnknownError.java -- thrown when the VM cannot provide more information - about a catastrophic error - Copyright (C) 1998, 1999, 2001, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang; - -/** - * An <code>UnknownError</code> is thrown when a serious but unknown - * problem has occurred in the Java Virtual Machine. - * - * @author Brian Jones - * @status updated to 1.4 - */ -public class UnknownError extends VirtualMachineError -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = 2524784860676771849L; - - /** - * Create an error without a message. - */ - public UnknownError() - { - } - - /** - * Create an error with a message. - * - * @param s the message - */ - public UnknownError(String s) - { - super(s); - } -} diff --git a/libjava/java/lang/UnsatisfiedLinkError.java b/libjava/java/lang/UnsatisfiedLinkError.java deleted file mode 100644 index 0d513d8e0ca..00000000000 --- a/libjava/java/lang/UnsatisfiedLinkError.java +++ /dev/null @@ -1,74 +0,0 @@ -/* UnsatisfiedLinkError.java -- thrown when a native method cannot be loaded - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang; - -/** - * A <code>UnsatisfiedLinkError</code> is thrown if an appropriate - * native language definition of a method declared <code>native</code> - * cannot be found by the Java Virtual Machine. - * - * @author Brian Jones - * @author Tom Tromey (tromey@cygnus.com) - * @see Runtime - * @status updated to 1.4 - */ -public class UnsatisfiedLinkError extends LinkageError -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = -4019343241616879428L; - - /** - * Create an error without a message. - */ - public UnsatisfiedLinkError() - { - } - - /** - * Create an error with a message. - * - * @param s the message - */ - public UnsatisfiedLinkError(String s) - { - super(s); - } -} diff --git a/libjava/java/lang/UnsupportedClassVersionError.java b/libjava/java/lang/UnsupportedClassVersionError.java deleted file mode 100644 index d6974b7694d..00000000000 --- a/libjava/java/lang/UnsupportedClassVersionError.java +++ /dev/null @@ -1,74 +0,0 @@ -/* UnsupportedClassVersionError.java -- thrown when a class file version - exceeds the capability of the virtual machine - Copyright (C) 1998, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang; - -/** - * An <code>UnsupportedClassVersionError</code> is thrown when the - * Java Virtual Machine determines it does not support the major and minor - * version numbers in the class file it is attempting to read. - * - * @author Brian Jones - * @since 1.2 - * @status updated to 1.4 - */ -public class UnsupportedClassVersionError extends ClassFormatError -{ - /** - * Compatible with JDK 1.2+. - */ - private static final long serialVersionUID = -7123279212883497373L; - - /** - * Create an error without a message. - */ - public UnsupportedClassVersionError() - { - } - - /** - * Create an error with a message. - * - * @param s the message - */ - public UnsupportedClassVersionError(String s) - { - super(s); - } -} diff --git a/libjava/java/lang/UnsupportedOperationException.java b/libjava/java/lang/UnsupportedOperationException.java deleted file mode 100644 index 0387d0ee29d..00000000000 --- a/libjava/java/lang/UnsupportedOperationException.java +++ /dev/null @@ -1,73 +0,0 @@ -/* UnsupportedOperationException.java -- thrown when an operation is not - supported - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang; - -/** - * This exception is thrown by an object when an operation is - * requested of it that it does not support. - * - * @author Warren Levy (warrenl@cygnus.com) - * @since 1.2 - * @status updated to 1.4 - */ -public class UnsupportedOperationException extends RuntimeException -{ - /** - * Compatible with JDK 1.2+. - */ - private static final long serialVersionUID = -1242599979055084673L; - - /** - * Create an exception without a message. - */ - public UnsupportedOperationException() - { - } - - /** - * Create an exception with a message. - * - * @param s the message - */ - public UnsupportedOperationException(String s) - { - super(s); - } -} diff --git a/libjava/java/lang/VerifyError.java b/libjava/java/lang/VerifyError.java deleted file mode 100644 index 350ceaa5e95..00000000000 --- a/libjava/java/lang/VerifyError.java +++ /dev/null @@ -1,72 +0,0 @@ -/* VerifyError.java -- thrown when a class fails verification - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang; - -/** - * A <code>VerifyError</code> is thrown if there is a security problem or - * internal inconsistency in a class file as detected by the "verifier." - * - * @author Brian Jones - * @author Tom Tromey (tromey@cygnus.com) - * @status updated to 1.4 - */ -public class VerifyError extends LinkageError -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = 7001962396098498785L; - - /** - * Create an error without a message. - */ - public VerifyError() - { - } - - /** - * Create an error with a message. - * - * @param s the message - */ - public VerifyError(String s) - { - super(s); - } -} diff --git a/libjava/java/lang/VirtualMachineError.java b/libjava/java/lang/VirtualMachineError.java deleted file mode 100644 index 3062c4fe800..00000000000 --- a/libjava/java/lang/VirtualMachineError.java +++ /dev/null @@ -1,73 +0,0 @@ -/* VirtualMachineError.java -- thrown when the Virtual Machine has a problem - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang; - -/** - * A <code>VirtualMachineError</code> or its subclasses are thrown to - * indicate there is something wrong with the Java Virtual Machine or that - * it does not have the resources needed for it to continue execution. - * - * @author Brian Jones - * @author Tom Tromey (tromey@cygnus.com) - * @status updated to 1.4 - */ -public abstract class VirtualMachineError extends Error -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = 4161983926571568670L; - - /** - * Create an error without a message. - */ - public VirtualMachineError() - { - } - - /** - * Create an error with a message. - * - * @param s the message - */ - public VirtualMachineError(String s) - { - super(s); - } -} diff --git a/libjava/java/lang/Void.java b/libjava/java/lang/Void.java deleted file mode 100644 index 15035426830..00000000000 --- a/libjava/java/lang/Void.java +++ /dev/null @@ -1,68 +0,0 @@ -/* Void.class - defines void.class - Copyright (C) 1998, 1999, 2001, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.lang; - - -/** - * Void is a placeholder class so that the variable <code>Void.TYPE</code> - * (also available as <code>void.class</code>) can be supported for - * reflection return types. - * - * <p>This class could be Serializable, but that is up to Sun.</p> - * - * @author Paul Fisher - * @author John Keiser - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.1 - * @status updated to 1.4 - */ -public final class Void -{ - /** - * The return type <code>void</code> is represented by this - * <code>Class</code> object. - */ - public static final Class TYPE = VMClassLoader.getPrimitiveClass('V'); - - /** - * Void is non-instantiable. - */ - private Void() - { - } -} diff --git a/libjava/java/lang/dtoa.c b/libjava/java/lang/dtoa.c deleted file mode 100644 index 6d5ad3b422e..00000000000 --- a/libjava/java/lang/dtoa.c +++ /dev/null @@ -1,906 +0,0 @@ -/**************************************************************** - * - * The author of this software is David M. Gay. - * - * Copyright (c) 1991 by AT&T. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose without fee is hereby granted, provided that this entire notice - * is included in all copies of any software which is or includes a copy - * or modification of this software and in all copies of the supporting - * documentation for such software. - * - * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED - * WARRANTY. IN PARTICULAR, NEITHER THE AUTHOR NOR AT&T MAKES ANY - * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY - * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. - * - ***************************************************************/ - -/* Please send bug reports to - David M. Gay - AT&T Bell Laboratories, Room 2C-463 - 600 Mountain Avenue - Murray Hill, NJ 07974-2070 - U.S.A. - dmg@research.att.com or research!dmg - */ - -#include "mprec.h" -#include <string.h> - -static int -_DEFUN (quorem, - (b, S), - _Jv_Bigint * b _AND _Jv_Bigint * S) -{ - int n; - long borrow, y; - unsigned long carry, q, ys; - unsigned long *bx, *bxe, *sx, *sxe; -#ifdef Pack_32 - long z; - unsigned long si, zs; -#endif - - n = S->_wds; -#ifdef DEBUG - /*debug*/ if (b->_wds > n) - /*debug*/ Bug ("oversize b in quorem"); -#endif - if (b->_wds < n) - return 0; - sx = S->_x; - sxe = sx + --n; - bx = b->_x; - bxe = bx + n; - q = *bxe / (*sxe + 1); /* ensure q <= true quotient */ -#ifdef DEBUG - /*debug*/ if (q > 9) - /*debug*/ Bug ("oversized quotient in quorem"); -#endif - if (q) - { - borrow = 0; - carry = 0; - do - { -#ifdef Pack_32 - si = *sx++; - ys = (si & 0xffff) * q + carry; - zs = (si >> 16) * q + (ys >> 16); - carry = zs >> 16; - y = (*bx & 0xffff) - (ys & 0xffff) + borrow; - borrow = y >> 16; - Sign_Extend (borrow, y); - z = (*bx >> 16) - (zs & 0xffff) + borrow; - borrow = z >> 16; - Sign_Extend (borrow, z); - Storeinc (bx, z, y); -#else - ys = *sx++ * q + carry; - carry = ys >> 16; - y = *bx - (ys & 0xffff) + borrow; - borrow = y >> 16; - Sign_Extend (borrow, y); - *bx++ = y & 0xffff; -#endif - } - while (sx <= sxe); - if (!*bxe) - { - bx = b->_x; - while (--bxe > bx && !*bxe) - --n; - b->_wds = n; - } - } - if (cmp (b, S) >= 0) - { - q++; - borrow = 0; - carry = 0; - bx = b->_x; - sx = S->_x; - do - { -#ifdef Pack_32 - si = *sx++; - ys = (si & 0xffff) + carry; - zs = (si >> 16) + (ys >> 16); - carry = zs >> 16; - y = (*bx & 0xffff) - (ys & 0xffff) + borrow; - borrow = y >> 16; - Sign_Extend (borrow, y); - z = (*bx >> 16) - (zs & 0xffff) + borrow; - borrow = z >> 16; - Sign_Extend (borrow, z); - Storeinc (bx, z, y); -#else - ys = *sx++ + carry; - carry = ys >> 16; - y = *bx - (ys & 0xffff) + borrow; - borrow = y >> 16; - Sign_Extend (borrow, y); - *bx++ = y & 0xffff; -#endif - } - while (sx <= sxe); - bx = b->_x; - bxe = bx + n; - if (!*bxe) - { - while (--bxe > bx && !*bxe) - --n; - b->_wds = n; - } - } - return q; -} - -#ifdef DEBUG -#include <stdio.h> - -void -print (_Jv_Bigint * b) -{ - int i, wds; - unsigned long *x, y; - wds = b->_wds; - x = b->_x+wds; - i = 0; - do - { - x--; - fprintf (stderr, "%08x", *x); - } - while (++i < wds); - fprintf (stderr, "\n"); -} -#endif - -/* dtoa for IEEE arithmetic (dmg): convert double to ASCII string. - * - * Inspired by "How to Print Floating-Point Numbers Accurately" by - * Guy L. Steele, Jr. and Jon L. White [Proc. ACM SIGPLAN '90, pp. 92-101]. - * - * Modifications: - * 1. Rather than iterating, we use a simple numeric overestimate - * to determine k = floor(log10(d)). We scale relevant - * quantities using O(log2(k)) rather than O(k) multiplications. - * 2. For some modes > 2 (corresponding to ecvt and fcvt), we don't - * try to generate digits strictly left to right. Instead, we - * compute with fewer bits and propagate the carry if necessary - * when rounding the final digit up. This is often faster. - * 3. Under the assumption that input will be rounded nearest, - * mode 0 renders 1e23 as 1e23 rather than 9.999999999999999e22. - * That is, we allow equality in stopping tests when the - * round-nearest rule will give the same floating-point value - * as would satisfaction of the stopping test with strict - * inequality. - * 4. We remove common factors of powers of 2 from relevant - * quantities. - * 5. When converting floating-point integers less than 1e16, - * we use floating-point arithmetic rather than resorting - * to multiple-precision integers. - * 6. When asked to produce fewer than 15 digits, we first try - * to get by with floating-point arithmetic; we resort to - * multiple-precision integer arithmetic only if we cannot - * guarantee that the floating-point calculation has given - * the correctly rounded result. For k requested digits and - * "uniformly" distributed input, the probability is - * something like 10^(k-15) that we must resort to the long - * calculation. - */ - - -char * -_DEFUN (_dtoa_r, - (ptr, _d, mode, ndigits, decpt, sign, rve, float_type), - struct _Jv_reent *ptr _AND - double _d _AND - int mode _AND - int ndigits _AND - int *decpt _AND - int *sign _AND - char **rve _AND - int float_type) -{ - /* - float_type == 0 for double precision, 1 for float. - - Arguments ndigits, decpt, sign are similar to those - of ecvt and fcvt; trailing zeros are suppressed from - the returned string. If not null, *rve is set to point - to the end of the return value. If d is +-Infinity or NaN, - then *decpt is set to 9999. - - mode: - 0 ==> shortest string that yields d when read in - and rounded to nearest. - 1 ==> like 0, but with Steele & White stopping rule; - e.g. with IEEE P754 arithmetic , mode 0 gives - 1e23 whereas mode 1 gives 9.999999999999999e22. - 2 ==> max(1,ndigits) significant digits. This gives a - return value similar to that of ecvt, except - that trailing zeros are suppressed. - 3 ==> through ndigits past the decimal point. This - gives a return value similar to that from fcvt, - except that trailing zeros are suppressed, and - ndigits can be negative. - 4-9 should give the same return values as 2-3, i.e., - 4 <= mode <= 9 ==> same return as mode - 2 + (mode & 1). These modes are mainly for - debugging; often they run slower but sometimes - faster than modes 2-3. - 4,5,8,9 ==> left-to-right digit generation. - 6-9 ==> don't try fast floating-point estimate - (if applicable). - - > 16 ==> Floating-point arg is treated as single precision. - - Values of mode other than 0-9 are treated as mode 0. - - Sufficient space is allocated to the return value - to hold the suppressed trailing zeros. - */ - - int bbits, b2, b5, be, dig, i, ieps, ilim0, j, j1, k, k0, - k_check, leftright, m2, m5, s2, s5, try_quick; - int ilim = 0, ilim1 = 0, spec_case = 0; - union double_union d, d2, eps; - long L; -#ifndef Sudden_Underflow - int denorm; - unsigned long x; -#endif - _Jv_Bigint *b, *b1, *delta, *mlo = NULL, *mhi, *S; - double ds; - char *s, *s0; - - d.d = _d; - - if (ptr->_result) - { - ptr->_result->_k = ptr->_result_k; - ptr->_result->_maxwds = 1 << ptr->_result_k; - Bfree (ptr, ptr->_result); - ptr->_result = 0; - } - - if (word0 (d) & Sign_bit) - { - /* set sign for everything, including 0's and NaNs */ - *sign = 1; - word0 (d) &= ~Sign_bit; /* clear sign bit */ - } - else - *sign = 0; - -#if defined(IEEE_Arith) + defined(VAX) -#ifdef IEEE_Arith - if ((word0 (d) & Exp_mask) == Exp_mask) -#else - if (word0 (d) == 0x8000) -#endif - { - /* Infinity or NaN */ - *decpt = 9999; - s = -#ifdef IEEE_Arith - !word1 (d) && !(word0 (d) & 0xfffff) ? "Infinity" : -#endif - "NaN"; - if (rve) - *rve = -#ifdef IEEE_Arith - s[3] ? s + 8 : -#endif - s + 3; - return s; - } -#endif -#ifdef IBM - d.d += 0; /* normalize */ -#endif - if (!d.d) - { - *decpt = 1; - s = "0"; - if (rve) - *rve = s + 1; - return s; - } - - b = d2b (ptr, d.d, &be, &bbits); -#ifdef Sudden_Underflow - i = (int) (word0 (d) >> Exp_shift1 & (Exp_mask >> Exp_shift1)); -#else - if ((i = (int) (word0 (d) >> Exp_shift1 & (Exp_mask >> Exp_shift1)))) - { -#endif - d2.d = d.d; - word0 (d2) &= Frac_mask1; - word0 (d2) |= Exp_11; -#ifdef IBM - if (j = 11 - hi0bits (word0 (d2) & Frac_mask)) - d2.d /= 1 << j; -#endif - - /* log(x) ~=~ log(1.5) + (x-1.5)/1.5 - * log10(x) = log(x) / log(10) - * ~=~ log(1.5)/log(10) + (x-1.5)/(1.5*log(10)) - * log10(d) = (i-Bias)*log(2)/log(10) + log10(d2) - * - * This suggests computing an approximation k to log10(d) by - * - * k = (i - Bias)*0.301029995663981 - * + ( (d2-1.5)*0.289529654602168 + 0.176091259055681 ); - * - * We want k to be too large rather than too small. - * The error in the first-order Taylor series approximation - * is in our favor, so we just round up the constant enough - * to compensate for any error in the multiplication of - * (i - Bias) by 0.301029995663981; since |i - Bias| <= 1077, - * and 1077 * 0.30103 * 2^-52 ~=~ 7.2e-14, - * adding 1e-13 to the constant term more than suffices. - * Hence we adjust the constant term to 0.1760912590558. - * (We could get a more accurate k by invoking log10, - * but this is probably not worthwhile.) - */ - - i -= Bias; -#ifdef IBM - i <<= 2; - i += j; -#endif -#ifndef Sudden_Underflow - denorm = 0; - } - else - { - /* d is denormalized */ - - i = bbits + be + (Bias + (P - 1) - 1); - x = i > 32 ? word0 (d) << (64 - i) | word1 (d) >> (i - 32) - : word1 (d) << (32 - i); - d2.d = x; - word0 (d2) -= 31 * Exp_msk1; /* adjust exponent */ - i -= (Bias + (P - 1) - 1) + 1; - denorm = 1; - } -#endif - ds = (d2.d - 1.5) * 0.289529654602168 + 0.1760912590558 + i * 0.301029995663981; - k = (int) ds; - if (ds < 0. && ds != k) - k--; /* want k = floor(ds) */ - k_check = 1; - if (k >= 0 && k <= Ten_pmax) - { - if (d.d < tens[k]) - k--; - k_check = 0; - } - j = bbits - i - 1; - if (j >= 0) - { - b2 = 0; - s2 = j; - } - else - { - b2 = -j; - s2 = 0; - } - if (k >= 0) - { - b5 = 0; - s5 = k; - s2 += k; - } - else - { - b2 -= k; - b5 = -k; - s5 = 0; - } - if (mode < 0 || mode > 9) - mode = 0; - try_quick = 1; - if (mode > 5) - { - mode -= 4; - try_quick = 0; - } - leftright = 1; - switch (mode) - { - case 0: - case 1: - ilim = ilim1 = -1; - i = 18; - ndigits = 0; - break; - case 2: - leftright = 0; - /* no break */ - case 4: - if (ndigits <= 0) - ndigits = 1; - ilim = ilim1 = i = ndigits; - break; - case 3: - leftright = 0; - /* no break */ - case 5: - i = ndigits + k + 1; - ilim = i; - ilim1 = i - 1; - if (i <= 0) - i = 1; - } - j = sizeof (unsigned long); - for (ptr->_result_k = 0; (int) (sizeof (_Jv_Bigint) - sizeof (unsigned long)) + j <= i; - j <<= 1) - ptr->_result_k++; - ptr->_result = Balloc (ptr, ptr->_result_k); - s = s0 = (char *) ptr->_result; - - if (ilim >= 0 && ilim <= Quick_max && try_quick) - { - /* Try to get by with floating-point arithmetic. */ - - i = 0; - d2.d = d.d; - k0 = k; - ilim0 = ilim; - ieps = 2; /* conservative */ - if (k > 0) - { - ds = tens[k & 0xf]; - j = k >> 4; - if (j & Bletch) - { - /* prevent overflows */ - j &= Bletch - 1; - d.d /= bigtens[n_bigtens - 1]; - ieps++; - } - for (; j; j >>= 1, i++) - if (j & 1) - { - ieps++; - ds *= bigtens[i]; - } - d.d /= ds; - } - else if ((j1 = -k)) - { - d.d *= tens[j1 & 0xf]; - for (j = j1 >> 4; j; j >>= 1, i++) - if (j & 1) - { - ieps++; - d.d *= bigtens[i]; - } - } - if (k_check && d.d < 1. && ilim > 0) - { - if (ilim1 <= 0) - goto fast_failed; - ilim = ilim1; - k--; - d.d *= 10.; - ieps++; - } - eps.d = ieps * d.d + 7.; - word0 (eps) -= (P - 1) * Exp_msk1; - if (ilim == 0) - { - S = mhi = 0; - d.d -= 5.; - if (d.d > eps.d) - goto one_digit; - if (d.d < -eps.d) - goto no_digits; - goto fast_failed; - } -#ifndef No_leftright - if (leftright) - { - /* Use Steele & White method of only - * generating digits needed. - */ - eps.d = 0.5 / tens[ilim - 1] - eps.d; - for (i = 0;;) - { - L = d.d; - d.d -= L; - *s++ = '0' + (int) L; - if (d.d < eps.d) - goto ret1; - if (1. - d.d < eps.d) - goto bump_up; - if (++i >= ilim) - break; - eps.d *= 10.; - d.d *= 10.; - } - } - else - { -#endif - /* Generate ilim digits, then fix them up. */ - eps.d *= tens[ilim - 1]; - for (i = 1;; i++, d.d *= 10.) - { - L = d.d; - d.d -= L; - *s++ = '0' + (int) L; - if (i == ilim) - { - if (d.d > 0.5 + eps.d) - goto bump_up; - else if (d.d < 0.5 - eps.d) - { - while (*--s == '0'); - s++; - goto ret1; - } - break; - } - } -#ifndef No_leftright - } -#endif - fast_failed: - s = s0; - d.d = d2.d; - k = k0; - ilim = ilim0; - } - - /* Do we have a "small" integer? */ - - if (be >= 0 && k <= Int_max) - { - /* Yes. */ - ds = tens[k]; - if (ndigits < 0 && ilim <= 0) - { - S = mhi = 0; - if (ilim < 0 || d.d <= 5 * ds) - goto no_digits; - goto one_digit; - } - for (i = 1;; i++) - { - L = d.d / ds; - d.d -= L * ds; -#ifdef Check_FLT_ROUNDS - /* If FLT_ROUNDS == 2, L will usually be high by 1 */ - if (d.d < 0) - { - L--; - d.d += ds; - } -#endif - *s++ = '0' + (int) L; - if (i == ilim) - { - d.d += d.d; - if (d.d > ds || (d.d == ds && L & 1)) - { - bump_up: - while (*--s == '9') - if (s == s0) - { - k++; - *s = '0'; - break; - } - ++*s++; - } - break; - } - if (!(d.d *= 10.)) - break; - } - goto ret1; - } - - m2 = b2; - m5 = b5; - mhi = mlo = 0; - if (leftright) - { - if (mode < 2) - { - i = -#ifndef Sudden_Underflow - denorm ? be + (Bias + (P - 1) - 1 + 1) : -#endif -#ifdef IBM - 1 + 4 * P - 3 - bbits + ((bbits + be - 1) & 3); -#else - 1 + P - bbits; -#endif - } - else - { - j = ilim - 1; - if (m5 >= j) - m5 -= j; - else - { - s5 += j -= m5; - b5 += j; - m5 = 0; - } - if ((i = ilim) < 0) - { - m2 -= i; - i = 0; - } - } - b2 += i; - s2 += i; - mhi = i2b (ptr, 1); - } - if (m2 > 0 && s2 > 0) - { - i = m2 < s2 ? m2 : s2; - b2 -= i; - m2 -= i; - s2 -= i; - } - if (b5 > 0) - { - if (leftright) - { - if (m5 > 0) - { - mhi = pow5mult (ptr, mhi, m5); - b1 = mult (ptr, mhi, b); - Bfree (ptr, b); - b = b1; - } - if ((j = b5 - m5)) - b = pow5mult (ptr, b, j); - } - else - b = pow5mult (ptr, b, b5); - } - S = i2b (ptr, 1); - if (s5 > 0) - S = pow5mult (ptr, S, s5); - - /* Check for special case that d is a normalized power of 2. */ - - if (mode < 2) - { - if (!word1 (d) && !(word0 (d) & Bndry_mask) -#ifndef Sudden_Underflow - && word0(d) & Exp_mask -#endif - ) - { - /* The special case */ - b2 += Log2P; - s2 += Log2P; - spec_case = 1; - } - else - spec_case = 0; - } - - /* Arrange for convenient computation of quotients: - * shift left if necessary so divisor has 4 leading 0 bits. - * - * Perhaps we should just compute leading 28 bits of S once - * and for all and pass them and a shift to quorem, so it - * can do shifts and ors to compute the numerator for q. - */ - -#ifdef Pack_32 - if ((i = ((s5 ? 32 - hi0bits (S->_x[S->_wds - 1]) : 1) + s2) & 0x1f)) - i = 32 - i; -#else - if ((i = ((s5 ? 32 - hi0bits (S->_x[S->_wds - 1]) : 1) + s2) & 0xf)) - i = 16 - i; -#endif - if (i > 4) - { - i -= 4; - b2 += i; - m2 += i; - s2 += i; - } - else if (i < 4) - { - i += 28; - b2 += i; - m2 += i; - s2 += i; - } - if (b2 > 0) - b = lshift (ptr, b, b2); - if (s2 > 0) - S = lshift (ptr, S, s2); - if (k_check) - { - if (cmp (b, S) < 0) - { - k--; - b = multadd (ptr, b, 10, 0); /* we botched the k estimate */ - if (leftright) - mhi = multadd (ptr, mhi, 10, 0); - ilim = ilim1; - } - } - if (ilim <= 0 && mode > 2) - { - if (ilim < 0 || cmp (b, S = multadd (ptr, S, 5, 0)) <= 0) - { - /* no digits, fcvt style */ - no_digits: - k = -1 - ndigits; - goto ret; - } - one_digit: - *s++ = '1'; - k++; - goto ret; - } - if (leftright) - { - if (m2 > 0) - mhi = lshift (ptr, mhi, m2); - - /* Single precision case, */ - if (float_type) - mhi = lshift (ptr, mhi, 29); - - /* Compute mlo -- check for special case - * that d is a normalized power of 2. - */ - - mlo = mhi; - if (spec_case) - { - mhi = Balloc (ptr, mhi->_k); - Bcopy (mhi, mlo); - mhi = lshift (ptr, mhi, Log2P); - } - - for (i = 1;; i++) - { - dig = quorem (b, S) + '0'; - /* Do we yet have the shortest decimal string - * that will round to d? - */ - j = cmp (b, mlo); - delta = diff (ptr, S, mhi); - j1 = delta->_sign ? 1 : cmp (b, delta); - Bfree (ptr, delta); -#ifndef ROUND_BIASED - if (j1 == 0 && !mode && !(word1 (d) & 1)) - { - if (dig == '9') - goto round_9_up; - if (j > 0) - dig++; - *s++ = dig; - goto ret; - } -#endif - if (j < 0 || (j == 0 && !mode -#ifndef ROUND_BIASED - && !(word1 (d) & 1) -#endif - )) - { - if (j1 > 0) - { - b = lshift (ptr, b, 1); - j1 = cmp (b, S); - if ((j1 > 0 || (j1 == 0 && dig & 1)) - && dig++ == '9') - goto round_9_up; - } - *s++ = dig; - goto ret; - } - if (j1 > 0) - { - if (dig == '9') - { /* possible if i == 1 */ - round_9_up: - *s++ = '9'; - goto roundoff; - } - *s++ = dig + 1; - goto ret; - } - *s++ = dig; - if (i == ilim) - break; - b = multadd (ptr, b, 10, 0); - if (mlo == mhi) - mlo = mhi = multadd (ptr, mhi, 10, 0); - else - { - mlo = multadd (ptr, mlo, 10, 0); - mhi = multadd (ptr, mhi, 10, 0); - } - } - } - else - for (i = 1;; i++) - { - *s++ = dig = quorem (b, S) + '0'; - if (i >= ilim) - break; - b = multadd (ptr, b, 10, 0); - } - - /* Round off last digit */ - - b = lshift (ptr, b, 1); - j = cmp (b, S); - if (j > 0 || (j == 0 && dig & 1)) - { - roundoff: - while (*--s == '9') - if (s == s0) - { - k++; - *s++ = '1'; - goto ret; - } - ++*s++; - } - else - { - while (*--s == '0'); - s++; - } -ret: - Bfree (ptr, S); - if (mhi) - { - if (mlo && mlo != mhi) - Bfree (ptr, mlo); - Bfree (ptr, mhi); - } -ret1: - Bfree (ptr, b); - *s = 0; - *decpt = k + 1; - if (rve) - *rve = s; - return s0; -} - - -_VOID -_DEFUN (_dtoa, - (_d, mode, ndigits, decpt, sign, rve, buf, float_type), - double _d _AND - int mode _AND - int ndigits _AND - int *decpt _AND - int *sign _AND - char **rve _AND - char *buf _AND - int float_type) -{ - struct _Jv_reent reent; - char *p; - memset (&reent, 0, sizeof reent); - - p = _dtoa_r (&reent, _d, mode, ndigits, decpt, sign, rve, float_type); - strcpy (buf, p); - - return; -} diff --git a/libjava/java/lang/e_acos.c b/libjava/java/lang/e_acos.c deleted file mode 100644 index ee6b168a1c5..00000000000 --- a/libjava/java/lang/e_acos.c +++ /dev/null @@ -1,111 +0,0 @@ - -/* @(#)e_acos.c 5.1 93/09/24 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* __ieee754_acos(x) - * Method : - * acos(x) = pi/2 - asin(x) - * acos(-x) = pi/2 + asin(x) - * For |x|<=0.5 - * acos(x) = pi/2 - (x + x*x^2*R(x^2)) (see asin.c) - * For x>0.5 - * acos(x) = pi/2 - (pi/2 - 2asin(sqrt((1-x)/2))) - * = 2asin(sqrt((1-x)/2)) - * = 2s + 2s*z*R(z) ...z=(1-x)/2, s=sqrt(z) - * = 2f + (2c + 2s*z*R(z)) - * where f=hi part of s, and c = (z-f*f)/(s+f) is the correction term - * for f so that f+c ~ sqrt(z). - * For x<-0.5 - * acos(x) = pi - 2asin(sqrt((1-|x|)/2)) - * = pi - 0.5*(s+s*z*R(z)), where z=(1-|x|)/2,s=sqrt(z) - * - * Special cases: - * if x is NaN, return x itself; - * if |x|>1, return NaN with invalid signal. - * - * Function needed: sqrt - */ - -#include "fdlibm.h" - -#ifndef _DOUBLE_IS_32BITS - -#ifdef __STDC__ -static const double -#else -static double -#endif -one= 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */ -pi = 3.14159265358979311600e+00, /* 0x400921FB, 0x54442D18 */ -pio2_hi = 1.57079632679489655800e+00, /* 0x3FF921FB, 0x54442D18 */ -pio2_lo = 6.12323399573676603587e-17, /* 0x3C91A626, 0x33145C07 */ -pS0 = 1.66666666666666657415e-01, /* 0x3FC55555, 0x55555555 */ -pS1 = -3.25565818622400915405e-01, /* 0xBFD4D612, 0x03EB6F7D */ -pS2 = 2.01212532134862925881e-01, /* 0x3FC9C155, 0x0E884455 */ -pS3 = -4.00555345006794114027e-02, /* 0xBFA48228, 0xB5688F3B */ -pS4 = 7.91534994289814532176e-04, /* 0x3F49EFE0, 0x7501B288 */ -pS5 = 3.47933107596021167570e-05, /* 0x3F023DE1, 0x0DFDF709 */ -qS1 = -2.40339491173441421878e+00, /* 0xC0033A27, 0x1C8A2D4B */ -qS2 = 2.02094576023350569471e+00, /* 0x40002AE5, 0x9C598AC8 */ -qS3 = -6.88283971605453293030e-01, /* 0xBFE6066C, 0x1B8D0159 */ -qS4 = 7.70381505559019352791e-02; /* 0x3FB3B8C5, 0xB12E9282 */ - -#ifdef __STDC__ - double __ieee754_acos(double x) -#else - double __ieee754_acos(x) - double x; -#endif -{ - double z,p,q,r,w,s,c,df; - int32_t hx,ix; - GET_HIGH_WORD(hx,x); - ix = hx&0x7fffffff; - if(ix>=0x3ff00000) { /* |x| >= 1 */ - uint32_t lx; - GET_LOW_WORD(lx,x); - if(((ix-0x3ff00000)|lx)==0) { /* |x|==1 */ - if(hx>0) return 0.0; /* acos(1) = 0 */ - else return pi+2.0*pio2_lo; /* acos(-1)= pi */ - } - return (x-x)/(x-x); /* acos(|x|>1) is NaN */ - } - if(ix<0x3fe00000) { /* |x| < 0.5 */ - if(ix<=0x3c600000) return pio2_hi+pio2_lo;/*if|x|<2**-57*/ - z = x*x; - p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5))))); - q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4))); - r = p/q; - return pio2_hi - (x - (pio2_lo-x*r)); - } else if (hx<0) { /* x < -0.5 */ - z = (one+x)*0.5; - p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5))))); - q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4))); - s = __ieee754_sqrt(z); - r = p/q; - w = r*s-pio2_lo; - return pi - 2.0*(s+w); - } else { /* x > 0.5 */ - z = (one-x)*0.5; - s = __ieee754_sqrt(z); - df = s; - SET_LOW_WORD(df,0); - c = (z-df*df)/(s+df); - p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5))))); - q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4))); - r = p/q; - w = r*s+c; - return 2.0*(df+w); - } -} - -#endif /* defined(_DOUBLE_IS_32BITS) */ diff --git a/libjava/java/lang/e_asin.c b/libjava/java/lang/e_asin.c deleted file mode 100644 index 90fc77ffc3b..00000000000 --- a/libjava/java/lang/e_asin.c +++ /dev/null @@ -1,120 +0,0 @@ - -/* @(#)e_asin.c 5.1 93/09/24 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* __ieee754_asin(x) - * Method : - * Since asin(x) = x + x^3/6 + x^5*3/40 + x^7*15/336 + ... - * we approximate asin(x) on [0,0.5] by - * asin(x) = x + x*x^2*R(x^2) - * where - * R(x^2) is a rational approximation of (asin(x)-x)/x^3 - * and its remez error is bounded by - * |(asin(x)-x)/x^3 - R(x^2)| < 2^(-58.75) - * - * For x in [0.5,1] - * asin(x) = pi/2-2*asin(sqrt((1-x)/2)) - * Let y = (1-x), z = y/2, s := sqrt(z), and pio2_hi+pio2_lo=pi/2; - * then for x>0.98 - * asin(x) = pi/2 - 2*(s+s*z*R(z)) - * = pio2_hi - (2*(s+s*z*R(z)) - pio2_lo) - * For x<=0.98, let pio4_hi = pio2_hi/2, then - * f = hi part of s; - * c = sqrt(z) - f = (z-f*f)/(s+f) ...f+c=sqrt(z) - * and - * asin(x) = pi/2 - 2*(s+s*z*R(z)) - * = pio4_hi+(pio4-2s)-(2s*z*R(z)-pio2_lo) - * = pio4_hi+(pio4-2f)-(2s*z*R(z)-(pio2_lo+2c)) - * - * Special cases: - * if x is NaN, return x itself; - * if |x|>1, return NaN with invalid signal. - * - */ - - -#include "fdlibm.h" - -#ifndef _DOUBLE_IS_32BITS - -#ifdef __STDC__ -static const double -#else -static double -#endif -one = 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */ -huge = 1.000e+300, -pio2_hi = 1.57079632679489655800e+00, /* 0x3FF921FB, 0x54442D18 */ -pio2_lo = 6.12323399573676603587e-17, /* 0x3C91A626, 0x33145C07 */ -pio4_hi = 7.85398163397448278999e-01, /* 0x3FE921FB, 0x54442D18 */ - /* coefficient for R(x^2) */ -pS0 = 1.66666666666666657415e-01, /* 0x3FC55555, 0x55555555 */ -pS1 = -3.25565818622400915405e-01, /* 0xBFD4D612, 0x03EB6F7D */ -pS2 = 2.01212532134862925881e-01, /* 0x3FC9C155, 0x0E884455 */ -pS3 = -4.00555345006794114027e-02, /* 0xBFA48228, 0xB5688F3B */ -pS4 = 7.91534994289814532176e-04, /* 0x3F49EFE0, 0x7501B288 */ -pS5 = 3.47933107596021167570e-05, /* 0x3F023DE1, 0x0DFDF709 */ -qS1 = -2.40339491173441421878e+00, /* 0xC0033A27, 0x1C8A2D4B */ -qS2 = 2.02094576023350569471e+00, /* 0x40002AE5, 0x9C598AC8 */ -qS3 = -6.88283971605453293030e-01, /* 0xBFE6066C, 0x1B8D0159 */ -qS4 = 7.70381505559019352791e-02; /* 0x3FB3B8C5, 0xB12E9282 */ - -#ifdef __STDC__ - double __ieee754_asin(double x) -#else - double __ieee754_asin(x) - double x; -#endif -{ - double t = 0., w, p, q, c, r, s; - int32_t hx,ix; - GET_HIGH_WORD(hx,x); - ix = hx&0x7fffffff; - if(ix>= 0x3ff00000) { /* |x|>= 1 */ - uint32_t lx; - GET_LOW_WORD(lx,x); - if(((ix-0x3ff00000)|lx)==0) - /* asin(1)=+-pi/2 with inexact */ - return x*pio2_hi+x*pio2_lo; - return (x-x)/(x-x); /* asin(|x|>1) is NaN */ - } else if (ix<0x3fe00000) { /* |x|<0.5 */ - if(ix<0x3e400000) { /* if |x| < 2**-27 */ - if(huge+x>one) return x;/* return x with inexact if x!=0*/ - } else - t = x*x; - p = t*(pS0+t*(pS1+t*(pS2+t*(pS3+t*(pS4+t*pS5))))); - q = one+t*(qS1+t*(qS2+t*(qS3+t*qS4))); - w = p/q; - return x+x*w; - } - /* 1> |x|>= 0.5 */ - w = one-fabs(x); - t = w*0.5; - p = t*(pS0+t*(pS1+t*(pS2+t*(pS3+t*(pS4+t*pS5))))); - q = one+t*(qS1+t*(qS2+t*(qS3+t*qS4))); - s = __ieee754_sqrt(t); - if(ix>=0x3FEF3333) { /* if |x| > 0.975 */ - w = p/q; - t = pio2_hi-(2.0*(s+s*w)-pio2_lo); - } else { - w = s; - SET_LOW_WORD(w,0); - c = (t-w*w)/(s+w); - r = p/q; - p = 2.0*s*r-(pio2_lo-2.0*c); - q = pio4_hi-2.0*w; - t = pio4_hi-(p-q); - } - if(hx>0) return t; else return -t; -} - -#endif /* defined(_DOUBLE_IS_32BITS) */ diff --git a/libjava/java/lang/e_atan2.c b/libjava/java/lang/e_atan2.c deleted file mode 100644 index c75448db26c..00000000000 --- a/libjava/java/lang/e_atan2.c +++ /dev/null @@ -1,131 +0,0 @@ - -/* @(#)e_atan2.c 5.1 93/09/24 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - * - */ - -/* __ieee754_atan2(y,x) - * Method : - * 1. Reduce y to positive by atan2(y,x)=-atan2(-y,x). - * 2. Reduce x to positive by (if x and y are unexceptional): - * ARG (x+iy) = arctan(y/x) ... if x > 0, - * ARG (x+iy) = pi - arctan[y/(-x)] ... if x < 0, - * - * Special cases: - * - * ATAN2((anything), NaN ) is NaN; - * ATAN2(NAN , (anything) ) is NaN; - * ATAN2(+-0, +(anything but NaN)) is +-0 ; - * ATAN2(+-0, -(anything but NaN)) is +-pi ; - * ATAN2(+-(anything but 0 and NaN), 0) is +-pi/2; - * ATAN2(+-(anything but INF and NaN), +INF) is +-0 ; - * ATAN2(+-(anything but INF and NaN), -INF) is +-pi; - * ATAN2(+-INF,+INF ) is +-pi/4 ; - * ATAN2(+-INF,-INF ) is +-3pi/4; - * ATAN2(+-INF, (anything but,0,NaN, and INF)) is +-pi/2; - * - * Constants: - * The hexadecimal values are the intended ones for the following - * constants. The decimal values may be used, provided that the - * compiler will convert from decimal to binary accurately enough - * to produce the hexadecimal values shown. - */ - -#include "fdlibm.h" - -#ifndef _DOUBLE_IS_32BITS - -#ifdef __STDC__ -static const double -#else -static double -#endif -tiny = 1.0e-300, -zero = 0.0, -pi_o_4 = 7.8539816339744827900E-01, /* 0x3FE921FB, 0x54442D18 */ -pi_o_2 = 1.5707963267948965580E+00, /* 0x3FF921FB, 0x54442D18 */ -pi = 3.1415926535897931160E+00, /* 0x400921FB, 0x54442D18 */ -pi_lo = 1.2246467991473531772E-16; /* 0x3CA1A626, 0x33145C07 */ - -#ifdef __STDC__ - double __ieee754_atan2(double y, double x) -#else - double __ieee754_atan2(y,x) - double y,x; -#endif -{ - double z; - int32_t k,m,hx,hy,ix,iy; - uint32_t lx,ly; - - EXTRACT_WORDS(hx,lx,x); - ix = hx&0x7fffffff; - EXTRACT_WORDS(hy,ly,y); - iy = hy&0x7fffffff; - if(((ix|((lx|-lx)>>31))>0x7ff00000)|| - ((iy|((ly|-ly)>>31))>0x7ff00000)) /* x or y is NaN */ - return x+y; - if(((hx-0x3ff00000)|lx)==0) return atan(y); /* x=1.0 */ - m = ((hy>>31)&1)|((hx>>30)&2); /* 2*sign(x)+sign(y) */ - - /* when y = 0 */ - if((iy|ly)==0) { - switch(m) { - case 0: - case 1: return y; /* atan(+-0,+anything)=+-0 */ - case 2: return pi+tiny;/* atan(+0,-anything) = pi */ - case 3: return -pi-tiny;/* atan(-0,-anything) =-pi */ - } - } - /* when x = 0 */ - if((ix|lx)==0) return (hy<0)? -pi_o_2-tiny: pi_o_2+tiny; - - /* when x is INF */ - if(ix==0x7ff00000) { - if(iy==0x7ff00000) { - switch(m) { - case 0: return pi_o_4+tiny;/* atan(+INF,+INF) */ - case 1: return -pi_o_4-tiny;/* atan(-INF,+INF) */ - case 2: return 3.0*pi_o_4+tiny;/*atan(+INF,-INF)*/ - case 3: return -3.0*pi_o_4-tiny;/*atan(-INF,-INF)*/ - } - } else { - switch(m) { - case 0: return zero ; /* atan(+...,+INF) */ - case 1: return -zero ; /* atan(-...,+INF) */ - case 2: return pi+tiny ; /* atan(+...,-INF) */ - case 3: return -pi-tiny ; /* atan(-...,-INF) */ - } - } - } - /* when y is INF */ - if(iy==0x7ff00000) return (hy<0)? -pi_o_2-tiny: pi_o_2+tiny; - - /* compute y/x */ - k = (iy-ix)>>20; - if(k > 60) z=pi_o_2+0.5*pi_lo; /* |y/x| > 2**60 */ - else if(hx<0&&k<-60) z=0.0; /* |y|/x < -2**60 */ - else z=atan(fabs(y/x)); /* safe to do y/x */ - switch (m) { - case 0: return z ; /* atan(+,+) */ - case 1: { - uint32_t zh; - GET_HIGH_WORD(zh,z); - SET_HIGH_WORD(z,zh ^ 0x80000000); - } - return z ; /* atan(-,+) */ - case 2: return pi-(z-pi_lo);/* atan(+,-) */ - default: /* case 3 */ - return (z-pi_lo)-pi;/* atan(-,-) */ - } -} - -#endif /* defined(_DOUBLE_IS_32BITS) */ diff --git a/libjava/java/lang/e_exp.c b/libjava/java/lang/e_exp.c deleted file mode 100644 index ad37f86b029..00000000000 --- a/libjava/java/lang/e_exp.c +++ /dev/null @@ -1,167 +0,0 @@ - -/* @(#)e_exp.c 5.1 93/09/24 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* __ieee754_exp(x) - * Returns the exponential of x. - * - * Method - * 1. Argument reduction: - * Reduce x to an r so that |r| <= 0.5*ln2 ~ 0.34658. - * Given x, find r and integer k such that - * - * x = k*ln2 + r, |r| <= 0.5*ln2. - * - * Here r will be represented as r = hi-lo for better - * accuracy. - * - * 2. Approximation of exp(r) by a special rational function on - * the interval [0,0.34658]: - * Write - * R(r**2) = r*(exp(r)+1)/(exp(r)-1) = 2 + r*r/6 - r**4/360 + ... - * We use a special Reme algorithm on [0,0.34658] to generate - * a polynomial of degree 5 to approximate R. The maximum error - * of this polynomial approximation is bounded by 2**-59. In - * other words, - * R(z) ~ 2.0 + P1*z + P2*z**2 + P3*z**3 + P4*z**4 + P5*z**5 - * (where z=r*r, and the values of P1 to P5 are listed below) - * and - * | 5 | -59 - * | 2.0+P1*z+...+P5*z - R(z) | <= 2 - * | | - * The computation of exp(r) thus becomes - * 2*r - * exp(r) = 1 + ------- - * R - r - * r*R1(r) - * = 1 + r + ----------- (for better accuracy) - * 2 - R1(r) - * where - * 2 4 10 - * R1(r) = r - (P1*r + P2*r + ... + P5*r ). - * - * 3. Scale back to obtain exp(x): - * From step 1, we have - * exp(x) = 2^k * exp(r) - * - * Special cases: - * exp(INF) is INF, exp(NaN) is NaN; - * exp(-INF) is 0, and - * for finite argument, only exp(0)=1 is exact. - * - * Accuracy: - * according to an error analysis, the error is always less than - * 1 ulp (unit in the last place). - * - * Misc. info. - * For IEEE double - * if x > 7.09782712893383973096e+02 then exp(x) overflow - * if x < -7.45133219101941108420e+02 then exp(x) underflow - * - * Constants: - * The hexadecimal values are the intended ones for the following - * constants. The decimal values may be used, provided that the - * compiler will convert from decimal to binary accurately enough - * to produce the hexadecimal values shown. - */ - -#include "fdlibm.h" - -#ifndef _DOUBLE_IS_32BITS - -#ifdef __STDC__ -static const double -#else -static double -#endif -one = 1.0, -halF[2] = {0.5,-0.5,}, -huge = 1.0e+300, -twom1000= 9.33263618503218878990e-302, /* 2**-1000=0x01700000,0*/ -o_threshold= 7.09782712893383973096e+02, /* 0x40862E42, 0xFEFA39EF */ -u_threshold= -7.45133219101941108420e+02, /* 0xc0874910, 0xD52D3051 */ -ln2HI[2] ={ 6.93147180369123816490e-01, /* 0x3fe62e42, 0xfee00000 */ - -6.93147180369123816490e-01,},/* 0xbfe62e42, 0xfee00000 */ -ln2LO[2] ={ 1.90821492927058770002e-10, /* 0x3dea39ef, 0x35793c76 */ - -1.90821492927058770002e-10,},/* 0xbdea39ef, 0x35793c76 */ -invln2 = 1.44269504088896338700e+00, /* 0x3ff71547, 0x652b82fe */ -P1 = 1.66666666666666019037e-01, /* 0x3FC55555, 0x5555553E */ -P2 = -2.77777777770155933842e-03, /* 0xBF66C16C, 0x16BEBD93 */ -P3 = 6.61375632143793436117e-05, /* 0x3F11566A, 0xAF25DE2C */ -P4 = -1.65339022054652515390e-06, /* 0xBEBBBD41, 0xC5D26BF1 */ -P5 = 4.13813679705723846039e-08; /* 0x3E663769, 0x72BEA4D0 */ - - -#ifdef __STDC__ - double __ieee754_exp(double x) /* default IEEE double exp */ -#else - double __ieee754_exp(x) /* default IEEE double exp */ - double x; -#endif -{ - double y,hi = 0., lo = 0.,c,t; - int32_t k = 0, xsb; - uint32_t hx; - - GET_HIGH_WORD(hx,x); - xsb = (hx>>31)&1; /* sign bit of x */ - hx &= 0x7fffffff; /* high word of |x| */ - - /* filter out non-finite argument */ - if(hx >= 0x40862E42) { /* if |x|>=709.78... */ - if(hx>=0x7ff00000) { - uint32_t lx; - GET_LOW_WORD(lx,x); - if(((hx&0xfffff)|lx)!=0) - return x+x; /* NaN */ - else return (xsb==0)? x:0.0; /* exp(+-inf)={inf,0} */ - } - if(x > o_threshold) return huge*huge; /* overflow */ - if(x < u_threshold) return twom1000*twom1000; /* underflow */ - } - - /* argument reduction */ - if(hx > 0x3fd62e42) { /* if |x| > 0.5 ln2 */ - if(hx < 0x3FF0A2B2) { /* and |x| < 1.5 ln2 */ - hi = x-ln2HI[xsb]; lo=ln2LO[xsb]; k = 1-xsb-xsb; - } else { - k = invln2*x+halF[xsb]; - t = k; - hi = x - t*ln2HI[0]; /* t*ln2HI is exact here */ - lo = t*ln2LO[0]; - } - x = hi - lo; - } - else if(hx < 0x3e300000) { /* when |x|<2**-28 */ - if(huge+x>one) return one+x;/* trigger inexact */ - } - else k = 0; - - /* x is now in primary range */ - t = x*x; - c = x - t*(P1+t*(P2+t*(P3+t*(P4+t*P5)))); - if(k==0) return one-((x*c)/(c-2.0)-x); - else y = one-((lo-(x*c)/(2.0-c))-hi); - if(k >= -1021) { - uint32_t hy; - GET_HIGH_WORD(hy,y); - SET_HIGH_WORD(y,hy+(k<<20)); /* add k to y's exponent */ - return y; - } else { - uint32_t hy; - GET_HIGH_WORD(hy,y); - SET_HIGH_WORD(y,hy+((k+1000)<<20)); /* add k to y's exponent */ - return y*twom1000; - } -} - -#endif /* defined(_DOUBLE_IS_32BITS) */ diff --git a/libjava/java/lang/e_fmod.c b/libjava/java/lang/e_fmod.c deleted file mode 100644 index 1cf09907666..00000000000 --- a/libjava/java/lang/e_fmod.c +++ /dev/null @@ -1,140 +0,0 @@ - -/* @(#)e_fmod.c 5.1 93/09/24 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* - * __ieee754_fmod(x,y) - * Return x mod y in exact arithmetic - * Method: shift and subtract - */ - -#include "fdlibm.h" - -#ifndef _DOUBLE_IS_32BITS - -#ifdef __STDC__ -static const double one = 1.0, Zero[] = {0.0, -0.0,}; -#else -static double one = 1.0, Zero[] = {0.0, -0.0,}; -#endif - -#ifdef __STDC__ - double __ieee754_fmod(double x, double y) -#else - double __ieee754_fmod(x,y) - double x,y ; -#endif -{ - int32_t n,hx,hy,hz,ix,iy,sx,i; - uint32_t lx,ly,lz; - - EXTRACT_WORDS(hx,lx,x); - EXTRACT_WORDS(hy,ly,y); - sx = hx&0x80000000; /* sign of x */ - hx ^=sx; /* |x| */ - hy &= 0x7fffffff; /* |y| */ - - /* purge off exception values */ - if((hy|ly)==0||(hx>=0x7ff00000)|| /* y=0,or x not finite */ - ((hy|((ly|-ly)>>31))>0x7ff00000)) /* or y is NaN */ - return (x*y)/(x*y); - if(hx<=hy) { - if((hx<hy)||(lx<ly)) return x; /* |x|<|y| return x */ - if(lx==ly) - return Zero[(uint32_t)sx>>31]; /* |x|=|y| return x*0*/ - } - - /* determine ix = ilogb(x) */ - if(hx<0x00100000) { /* subnormal x */ - if(hx==0) { - for (ix = -1043, i=lx; i>0; i<<=1) ix -=1; - } else { - for (ix = -1022,i=(hx<<11); i>0; i<<=1) ix -=1; - } - } else ix = (hx>>20)-1023; - - /* determine iy = ilogb(y) */ - if(hy<0x00100000) { /* subnormal y */ - if(hy==0) { - for (iy = -1043, i=ly; i>0; i<<=1) iy -=1; - } else { - for (iy = -1022,i=(hy<<11); i>0; i<<=1) iy -=1; - } - } else iy = (hy>>20)-1023; - - /* set up {hx,lx}, {hy,ly} and align y to x */ - if(ix >= -1022) - hx = 0x00100000|(0x000fffff&hx); - else { /* subnormal x, shift x to normal */ - n = -1022-ix; - if(n<=31) { - hx = (hx<<n)|(lx>>(32-n)); - lx <<= n; - } else { - hx = lx<<(n-32); - lx = 0; - } - } - if(iy >= -1022) - hy = 0x00100000|(0x000fffff&hy); - else { /* subnormal y, shift y to normal */ - n = -1022-iy; - if(n<=31) { - hy = (hy<<n)|(ly>>(32-n)); - ly <<= n; - } else { - hy = ly<<(n-32); - ly = 0; - } - } - - /* fix point fmod */ - n = ix - iy; - while(n--) { - hz=hx-hy;lz=lx-ly; if(lx<ly) hz -= 1; - if(hz<0){hx = hx+hx+(lx>>31); lx = lx+lx;} - else { - if((hz|lz)==0) /* return sign(x)*0 */ - return Zero[(uint32_t)sx>>31]; - hx = hz+hz+(lz>>31); lx = lz+lz; - } - } - hz=hx-hy;lz=lx-ly; if(lx<ly) hz -= 1; - if(hz>=0) {hx=hz;lx=lz;} - - /* convert back to floating value and restore the sign */ - if((hx|lx)==0) /* return sign(x)*0 */ - return Zero[(uint32_t)sx>>31]; - while(hx<0x00100000) { /* normalize x */ - hx = hx+hx+(lx>>31); lx = lx+lx; - iy -= 1; - } - if(iy>= -1022) { /* normalize output */ - hx = ((hx-0x00100000)|((iy+1023)<<20)); - INSERT_WORDS(x,hx|sx,lx); - } else { /* subnormal output */ - n = -1022 - iy; - if(n<=20) { - lx = (lx>>n)|((uint32_t)hx<<(32-n)); - hx >>= n; - } else if (n<=31) { - lx = (hx<<(32-n))|(lx>>n); hx = sx; - } else { - lx = hx>>(n-32); hx = sx; - } - INSERT_WORDS(x,hx|sx,lx); - x *= one; /* create necessary signal */ - } - return x; /* exact output */ -} - -#endif /* defined(_DOUBLE_IS_32BITS) */ diff --git a/libjava/java/lang/e_log.c b/libjava/java/lang/e_log.c deleted file mode 100644 index 093473e1048..00000000000 --- a/libjava/java/lang/e_log.c +++ /dev/null @@ -1,152 +0,0 @@ - -/* @(#)e_log.c 5.1 93/09/24 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* __ieee754_log(x) - * Return the logrithm of x - * - * Method : - * 1. Argument Reduction: find k and f such that - * x = 2^k * (1+f), - * where sqrt(2)/2 < 1+f < sqrt(2) . - * - * 2. Approximation of log(1+f). - * Let s = f/(2+f) ; based on log(1+f) = log(1+s) - log(1-s) - * = 2s + 2/3 s**3 + 2/5 s**5 + ....., - * = 2s + s*R - * We use a special Reme algorithm on [0,0.1716] to generate - * a polynomial of degree 14 to approximate R The maximum error - * of this polynomial approximation is bounded by 2**-58.45. In - * other words, - * 2 4 6 8 10 12 14 - * R(z) ~ Lg1*s +Lg2*s +Lg3*s +Lg4*s +Lg5*s +Lg6*s +Lg7*s - * (the values of Lg1 to Lg7 are listed in the program) - * and - * | 2 14 | -58.45 - * | Lg1*s +...+Lg7*s - R(z) | <= 2 - * | | - * Note that 2s = f - s*f = f - hfsq + s*hfsq, where hfsq = f*f/2. - * In order to guarantee error in log below 1ulp, we compute log - * by - * log(1+f) = f - s*(f - R) (if f is not too large) - * log(1+f) = f - (hfsq - s*(hfsq+R)). (better accuracy) - * - * 3. Finally, log(x) = k*ln2 + log(1+f). - * = k*ln2_hi+(f-(hfsq-(s*(hfsq+R)+k*ln2_lo))) - * Here ln2 is split into two floating point number: - * ln2_hi + ln2_lo, - * where n*ln2_hi is always exact for |n| < 2000. - * - * Special cases: - * log(x) is NaN with signal if x < 0 (including -INF) ; - * log(+INF) is +INF; log(0) is -INF with signal; - * log(NaN) is that NaN with no signal. - * - * Accuracy: - * according to an error analysis, the error is always less than - * 1 ulp (unit in the last place). - * - * Constants: - * The hexadecimal values are the intended ones for the following - * constants. The decimal values may be used, provided that the - * compiler will convert from decimal to binary accurately enough - * to produce the hexadecimal values shown. - */ - -#include "fdlibm.h" - -#ifndef _DOUBLE_IS_32BITS - -#ifdef __STDC__ -static const double -#else -static double -#endif -ln2_hi = 6.93147180369123816490e-01, /* 3fe62e42 fee00000 */ -ln2_lo = 1.90821492927058770002e-10, /* 3dea39ef 35793c76 */ -two54 = 1.80143985094819840000e+16, /* 43500000 00000000 */ -Lg1 = 6.666666666666735130e-01, /* 3FE55555 55555593 */ -Lg2 = 3.999999999940941908e-01, /* 3FD99999 9997FA04 */ -Lg3 = 2.857142874366239149e-01, /* 3FD24924 94229359 */ -Lg4 = 2.222219843214978396e-01, /* 3FCC71C5 1D8E78AF */ -Lg5 = 1.818357216161805012e-01, /* 3FC74664 96CB03DE */ -Lg6 = 1.531383769920937332e-01, /* 3FC39A09 D078C69F */ -Lg7 = 1.479819860511658591e-01; /* 3FC2F112 DF3E5244 */ - -#ifdef __STDC__ -static const double zero = 0.0; -#else -static double zero = 0.0; -#endif - -#ifdef __STDC__ - double __ieee754_log(double x) -#else - double __ieee754_log(x) - double x; -#endif -{ - double hfsq,f,s,z,R,w,t1,t2,dk; - int32_t k,hx,i,j; - uint32_t lx; - - EXTRACT_WORDS(hx,lx,x); - - k=0; - if (hx < 0x00100000) { /* x < 2**-1022 */ - if (((hx&0x7fffffff)|lx)==0) - return -two54/zero; /* log(+-0)=-inf */ - if (hx<0) return (x-x)/zero; /* log(-#) = NaN */ - k -= 54; x *= two54; /* subnormal number, scale up x */ - GET_HIGH_WORD(hx,x); - } - if (hx >= 0x7ff00000) return x+x; - k += (hx>>20)-1023; - hx &= 0x000fffff; - i = (hx+0x95f64)&0x100000; - SET_HIGH_WORD(x,hx|(i^0x3ff00000)); /* normalize x or x/2 */ - k += (i>>20); - f = x-1.0; - if((0x000fffff&(2+hx))<3) { /* |f| < 2**-20 */ - if(f==zero) { - if(k==0) - return zero; - else { - dk=(double)k; - return dk*ln2_hi+dk*ln2_lo; - } - } - R = f*f*(0.5-0.33333333333333333*f); - if(k==0) return f-R; else {dk=(double)k; - return dk*ln2_hi-((R-dk*ln2_lo)-f);} - } - s = f/(2.0+f); - dk = (double)k; - z = s*s; - i = hx-0x6147a; - w = z*z; - j = 0x6b851-hx; - t1= w*(Lg2+w*(Lg4+w*Lg6)); - t2= z*(Lg1+w*(Lg3+w*(Lg5+w*Lg7))); - i |= j; - R = t2+t1; - if(i>0) { - hfsq=0.5*f*f; - if(k==0) return f-(hfsq-s*(hfsq+R)); else - return dk*ln2_hi-((hfsq-(s*(hfsq+R)+dk*ln2_lo))-f); - } else { - if(k==0) return f-s*(f-R); else - return dk*ln2_hi-((s*(f-R)-dk*ln2_lo)-f); - } -} - -#endif /* defined(_DOUBLE_IS_32BITS) */ diff --git a/libjava/java/lang/e_pow.c b/libjava/java/lang/e_pow.c deleted file mode 100644 index b21c0e92b39..00000000000 --- a/libjava/java/lang/e_pow.c +++ /dev/null @@ -1,312 +0,0 @@ - -/* @(#)e_pow.c 5.1 93/09/24 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* __ieee754_pow(x,y) return x**y - * - * n - * Method: Let x = 2 * (1+f) - * 1. Compute and return log2(x) in two pieces: - * log2(x) = w1 + w2, - * where w1 has 53-24 = 29 bit trailing zeros. - * 2. Perform y*log2(x) = n+y' by simulating muti-precision - * arithmetic, where |y'|<=0.5. - * 3. Return x**y = 2**n*exp(y'*log2) - * - * Special cases: - * 1. (anything) ** 0 is 1 - * 2. (anything) ** 1 is itself - * 3. (anything) ** NAN is NAN - * 4. NAN ** (anything except 0) is NAN - * 5. +-(|x| > 1) ** +INF is +INF - * 6. +-(|x| > 1) ** -INF is +0 - * 7. +-(|x| < 1) ** +INF is +0 - * 8. +-(|x| < 1) ** -INF is +INF - * 9. +-1 ** +-INF is NAN - * 10. +0 ** (+anything except 0, NAN) is +0 - * 11. -0 ** (+anything except 0, NAN, odd integer) is +0 - * 12. +0 ** (-anything except 0, NAN) is +INF - * 13. -0 ** (-anything except 0, NAN, odd integer) is +INF - * 14. -0 ** (odd integer) = -( +0 ** (odd integer) ) - * 15. +INF ** (+anything except 0,NAN) is +INF - * 16. +INF ** (-anything except 0,NAN) is +0 - * 17. -INF ** (anything) = -0 ** (-anything) - * 18. (-anything) ** (integer) is (-1)**(integer)*(+anything**integer) - * 19. (-anything except 0 and inf) ** (non-integer) is NAN - * - * Accuracy: - * pow(x,y) returns x**y nearly rounded. In particular - * pow(integer,integer) - * always returns the correct integer provided it is - * representable. - * - * Constants : - * The hexadecimal values are the intended ones for the following - * constants. The decimal values may be used, provided that the - * compiler will convert from decimal to binary accurately enough - * to produce the hexadecimal values shown. - */ - -#include "fdlibm.h" - -#ifndef _DOUBLE_IS_32BITS - -#ifdef __STDC__ -static const double -#else -static double -#endif -bp[] = {1.0, 1.5,}, -dp_h[] = { 0.0, 5.84962487220764160156e-01,}, /* 0x3FE2B803, 0x40000000 */ -dp_l[] = { 0.0, 1.35003920212974897128e-08,}, /* 0x3E4CFDEB, 0x43CFD006 */ -zero = 0.0, -one = 1.0, -two = 2.0, -two53 = 9007199254740992.0, /* 0x43400000, 0x00000000 */ -huge = 1.0e300, -tiny = 1.0e-300, - /* poly coefs for (3/2)*(log(x)-2s-2/3*s**3 */ -L1 = 5.99999999999994648725e-01, /* 0x3FE33333, 0x33333303 */ -L2 = 4.28571428578550184252e-01, /* 0x3FDB6DB6, 0xDB6FABFF */ -L3 = 3.33333329818377432918e-01, /* 0x3FD55555, 0x518F264D */ -L4 = 2.72728123808534006489e-01, /* 0x3FD17460, 0xA91D4101 */ -L5 = 2.30660745775561754067e-01, /* 0x3FCD864A, 0x93C9DB65 */ -L6 = 2.06975017800338417784e-01, /* 0x3FCA7E28, 0x4A454EEF */ -P1 = 1.66666666666666019037e-01, /* 0x3FC55555, 0x5555553E */ -P2 = -2.77777777770155933842e-03, /* 0xBF66C16C, 0x16BEBD93 */ -P3 = 6.61375632143793436117e-05, /* 0x3F11566A, 0xAF25DE2C */ -P4 = -1.65339022054652515390e-06, /* 0xBEBBBD41, 0xC5D26BF1 */ -P5 = 4.13813679705723846039e-08, /* 0x3E663769, 0x72BEA4D0 */ -lg2 = 6.93147180559945286227e-01, /* 0x3FE62E42, 0xFEFA39EF */ -lg2_h = 6.93147182464599609375e-01, /* 0x3FE62E43, 0x00000000 */ -lg2_l = -1.90465429995776804525e-09, /* 0xBE205C61, 0x0CA86C39 */ -ovt = 8.0085662595372944372e-0017, /* -(1024-log2(ovfl+.5ulp)) */ -cp = 9.61796693925975554329e-01, /* 0x3FEEC709, 0xDC3A03FD =2/(3ln2) */ -cp_h = 9.61796700954437255859e-01, /* 0x3FEEC709, 0xE0000000 =(float)cp */ -cp_l = -7.02846165095275826516e-09, /* 0xBE3E2FE0, 0x145B01F5 =tail of cp_h*/ -ivln2 = 1.44269504088896338700e+00, /* 0x3FF71547, 0x652B82FE =1/ln2 */ -ivln2_h = 1.44269502162933349609e+00, /* 0x3FF71547, 0x60000000 =24b 1/ln2*/ -ivln2_l = 1.92596299112661746887e-08; /* 0x3E54AE0B, 0xF85DDF44 =1/ln2 tail*/ - -#ifdef __STDC__ - double __ieee754_pow(double x, double y) -#else - double __ieee754_pow(x,y) - double x, y; -#endif -{ - double z,ax,z_h,z_l,p_h,p_l; - double y1,t1,t2,r,s,t,u,v,w; - int32_t i,j,k,yisint,n; - int32_t hx,hy,ix,iy; - uint32_t lx,ly; - - EXTRACT_WORDS(hx,lx,x); - EXTRACT_WORDS(hy,ly,y); - ix = hx&0x7fffffff; iy = hy&0x7fffffff; - - /* y==zero: x**0 = 1 */ - if((iy|ly)==0) return one; - - /* +-NaN return x+y */ - if(ix > 0x7ff00000 || ((ix==0x7ff00000)&&(lx!=0)) || - iy > 0x7ff00000 || ((iy==0x7ff00000)&&(ly!=0))) - return x+y; - - /* determine if y is an odd int when x < 0 - * yisint = 0 ... y is not an integer - * yisint = 1 ... y is an odd int - * yisint = 2 ... y is an even int - */ - yisint = 0; - if(hx<0) { - if(iy>=0x43400000) yisint = 2; /* even integer y */ - else if(iy>=0x3ff00000) { - k = (iy>>20)-0x3ff; /* exponent */ - if(k>20) { - j = ly>>(52-k); - if((uint32_t)(j<<(52-k))==ly) yisint = 2-(j&1); - } else if(ly==0) { - j = iy>>(20-k); - if((j<<(20-k))==iy) yisint = 2-(j&1); - } - } - } - - /* special value of y */ - if(ly==0) { - if (iy==0x7ff00000) { /* y is +-inf */ - if(((ix-0x3ff00000)|lx)==0) - return y - y; /* inf**+-1 is NaN */ - else if (ix >= 0x3ff00000)/* (|x|>1)**+-inf = inf,0 */ - return (hy>=0)? y: zero; - else /* (|x|<1)**-,+inf = inf,0 */ - return (hy<0)?-y: zero; - } - if(iy==0x3ff00000) { /* y is +-1 */ - if(hy<0) return one/x; else return x; - } - if(hy==0x40000000) return x*x; /* y is 2 */ - if(hy==0x3fe00000) { /* y is 0.5 */ - if(hx>=0) /* x >= +0 */ - return __ieee754_sqrt(x); - } - } - - ax = fabs(x); - /* special value of x */ - if(lx==0) { - if(ix==0x7ff00000||ix==0||ix==0x3ff00000){ - z = ax; /*x is +-0,+-inf,+-1*/ - if(hy<0) z = one/z; /* z = (1/|x|) */ - if(hx<0) { - if(((ix-0x3ff00000)|yisint)==0) { - z = (z-z)/(z-z); /* (-1)**non-int is NaN */ - } else if(yisint==1) - z = -z; /* (x<0)**odd = -(|x|**odd) */ - } - return z; - } - } - - /* (x<0)**(non-int) is NaN */ - /* GCJ LOCAL: This used to be - if((((hx>>31)+1)|yisint)==0) return (x-x)/(x-x); - but ANSI C says a right shift of a signed negative quantity is - implementation defined. */ - if(((((uint32_t)hx>>31)-1)|yisint)==0) return (x-x)/(x-x); - - /* |y| is huge */ - if(iy>0x41e00000) { /* if |y| > 2**31 */ - if(iy>0x43f00000){ /* if |y| > 2**64, must o/uflow */ - if(ix<=0x3fefffff) return (hy<0)? huge*huge:tiny*tiny; - if(ix>=0x3ff00000) return (hy>0)? huge*huge:tiny*tiny; - } - /* over/underflow if x is not close to one */ - if(ix<0x3fefffff) return (hy<0)? huge*huge:tiny*tiny; - if(ix>0x3ff00000) return (hy>0)? huge*huge:tiny*tiny; - /* now |1-x| is tiny <= 2**-20, suffice to compute - log(x) by x-x^2/2+x^3/3-x^4/4 */ - t = x-1; /* t has 20 trailing zeros */ - w = (t*t)*(0.5-t*(0.3333333333333333333333-t*0.25)); - u = ivln2_h*t; /* ivln2_h has 21 sig. bits */ - v = t*ivln2_l-w*ivln2; - t1 = u+v; - SET_LOW_WORD(t1,0); - t2 = v-(t1-u); - } else { - double s2,s_h,s_l,t_h,t_l; - n = 0; - /* take care subnormal number */ - if(ix<0x00100000) - {ax *= two53; n -= 53; GET_HIGH_WORD(ix,ax); } - n += ((ix)>>20)-0x3ff; - j = ix&0x000fffff; - /* determine interval */ - ix = j|0x3ff00000; /* normalize ix */ - if(j<=0x3988E) k=0; /* |x|<sqrt(3/2) */ - else if(j<0xBB67A) k=1; /* |x|<sqrt(3) */ - else {k=0;n+=1;ix -= 0x00100000;} - SET_HIGH_WORD(ax,ix); - - /* compute s = s_h+s_l = (x-1)/(x+1) or (x-1.5)/(x+1.5) */ - u = ax-bp[k]; /* bp[0]=1.0, bp[1]=1.5 */ - v = one/(ax+bp[k]); - s = u*v; - s_h = s; - SET_LOW_WORD(s_h,0); - /* t_h=ax+bp[k] High */ - t_h = zero; - SET_HIGH_WORD(t_h,((ix>>1)|0x20000000)+0x00080000+(k<<18)); - t_l = ax - (t_h-bp[k]); - s_l = v*((u-s_h*t_h)-s_h*t_l); - /* compute log(ax) */ - s2 = s*s; - r = s2*s2*(L1+s2*(L2+s2*(L3+s2*(L4+s2*(L5+s2*L6))))); - r += s_l*(s_h+s); - s2 = s_h*s_h; - t_h = 3.0+s2+r; - SET_LOW_WORD(t_h,0); - t_l = r-((t_h-3.0)-s2); - /* u+v = s*(1+...) */ - u = s_h*t_h; - v = s_l*t_h+t_l*s; - /* 2/(3log2)*(s+...) */ - p_h = u+v; - SET_LOW_WORD(p_h,0); - p_l = v-(p_h-u); - z_h = cp_h*p_h; /* cp_h+cp_l = 2/(3*log2) */ - z_l = cp_l*p_h+p_l*cp+dp_l[k]; - /* log2(ax) = (s+..)*2/(3*log2) = n + dp_h + z_h + z_l */ - t = (double)n; - t1 = (((z_h+z_l)+dp_h[k])+t); - SET_LOW_WORD(t1,0); - t2 = z_l-(((t1-t)-dp_h[k])-z_h); - } - - s = one; /* s (sign of result -ve**odd) = -1 else = 1 */ - if(((((uint32_t)hx>>31)-1)|(yisint-1))==0) - s = -one;/* (-ve)**(odd int) */ - - /* split up y into y1+y2 and compute (y1+y2)*(t1+t2) */ - y1 = y; - SET_LOW_WORD(y1,0); - p_l = (y-y1)*t1+y*t2; - p_h = y1*t1; - z = p_l+p_h; - EXTRACT_WORDS(j,i,z); - if (j>=0x40900000) { /* z >= 1024 */ - if(((j-0x40900000)|i)!=0) /* if z > 1024 */ - return s*huge*huge; /* overflow */ - else { - if(p_l+ovt>z-p_h) return s*huge*huge; /* overflow */ - } - } else if((j&0x7fffffff)>=0x4090cc00 ) { /* z <= -1075 */ - if(((j-0xc090cc00)|i)!=0) /* z < -1075 */ - return s*tiny*tiny; /* underflow */ - else { - if(p_l<=z-p_h) return s*tiny*tiny; /* underflow */ - } - } - /* - * compute 2**(p_h+p_l) - */ - i = j&0x7fffffff; - k = (i>>20)-0x3ff; - n = 0; - if(i>0x3fe00000) { /* if |z| > 0.5, set n = [z+0.5] */ - n = j+(0x00100000>>(k+1)); - k = ((n&0x7fffffff)>>20)-0x3ff; /* new k for n */ - t = zero; - SET_HIGH_WORD(t,n&~(0x000fffff>>k)); - n = ((n&0x000fffff)|0x00100000)>>(20-k); - if(j<0) n = -n; - p_h -= t; - } - t = p_l+p_h; - SET_LOW_WORD(t,0); - u = t*lg2_h; - v = (p_l-(t-p_h))*lg2+t*lg2_l; - z = u+v; - w = v-(z-u); - t = z*z; - t1 = z - t*(P1+t*(P2+t*(P3+t*(P4+t*P5)))); - r = (z*t1)/(t1-two)-(w+z*w); - z = one-(r-z); - GET_HIGH_WORD(j,z); - j += (n<<20); - if((j>>20)<=0) z = scalbn(z,(int)n); /* subnormal output */ - else SET_HIGH_WORD(z,j); - return s*z; -} - -#endif /* defined(_DOUBLE_IS_32BITS) */ diff --git a/libjava/java/lang/e_rem_pio2.c b/libjava/java/lang/e_rem_pio2.c deleted file mode 100644 index 543234c60c5..00000000000 --- a/libjava/java/lang/e_rem_pio2.c +++ /dev/null @@ -1,185 +0,0 @@ - -/* @(#)e_rem_pio2.c 5.1 93/09/24 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - * - */ - -/* __ieee754_rem_pio2(x,y) - * - * return the remainder of x rem pi/2 in y[0]+y[1] - * use __kernel_rem_pio2() - */ - -#include "fdlibm.h" - -#ifndef _DOUBLE_IS_32BITS - -/* - * Table of constants for 2/pi, 396 Hex digits (476 decimal) of 2/pi - */ -#ifdef __STDC__ -static const int32_t two_over_pi[] = { -#else -static int32_t two_over_pi[] = { -#endif -0xA2F983, 0x6E4E44, 0x1529FC, 0x2757D1, 0xF534DD, 0xC0DB62, -0x95993C, 0x439041, 0xFE5163, 0xABDEBB, 0xC561B7, 0x246E3A, -0x424DD2, 0xE00649, 0x2EEA09, 0xD1921C, 0xFE1DEB, 0x1CB129, -0xA73EE8, 0x8235F5, 0x2EBB44, 0x84E99C, 0x7026B4, 0x5F7E41, -0x3991D6, 0x398353, 0x39F49C, 0x845F8B, 0xBDF928, 0x3B1FF8, -0x97FFDE, 0x05980F, 0xEF2F11, 0x8B5A0A, 0x6D1F6D, 0x367ECF, -0x27CB09, 0xB74F46, 0x3F669E, 0x5FEA2D, 0x7527BA, 0xC7EBE5, -0xF17B3D, 0x0739F7, 0x8A5292, 0xEA6BFB, 0x5FB11F, 0x8D5D08, -0x560330, 0x46FC7B, 0x6BABF0, 0xCFBC20, 0x9AF436, 0x1DA9E3, -0x91615E, 0xE61B08, 0x659985, 0x5F14A0, 0x68408D, 0xFFD880, -0x4D7327, 0x310606, 0x1556CA, 0x73A8C9, 0x60E27B, 0xC08C6B, -}; - -#ifdef __STDC__ -static const int32_t npio2_hw[] = { -#else -static int32_t npio2_hw[] = { -#endif -0x3FF921FB, 0x400921FB, 0x4012D97C, 0x401921FB, 0x401F6A7A, 0x4022D97C, -0x4025FDBB, 0x402921FB, 0x402C463A, 0x402F6A7A, 0x4031475C, 0x4032D97C, -0x40346B9C, 0x4035FDBB, 0x40378FDB, 0x403921FB, 0x403AB41B, 0x403C463A, -0x403DD85A, 0x403F6A7A, 0x40407E4C, 0x4041475C, 0x4042106C, 0x4042D97C, -0x4043A28C, 0x40446B9C, 0x404534AC, 0x4045FDBB, 0x4046C6CB, 0x40478FDB, -0x404858EB, 0x404921FB, -}; - -/* - * invpio2: 53 bits of 2/pi - * pio2_1: first 33 bit of pi/2 - * pio2_1t: pi/2 - pio2_1 - * pio2_2: second 33 bit of pi/2 - * pio2_2t: pi/2 - (pio2_1+pio2_2) - * pio2_3: third 33 bit of pi/2 - * pio2_3t: pi/2 - (pio2_1+pio2_2+pio2_3) - */ - -#ifdef __STDC__ -static const double -#else -static double -#endif -zero = 0.00000000000000000000e+00, /* 0x00000000, 0x00000000 */ -half = 5.00000000000000000000e-01, /* 0x3FE00000, 0x00000000 */ -two24 = 1.67772160000000000000e+07, /* 0x41700000, 0x00000000 */ -invpio2 = 6.36619772367581382433e-01, /* 0x3FE45F30, 0x6DC9C883 */ -pio2_1 = 1.57079632673412561417e+00, /* 0x3FF921FB, 0x54400000 */ -pio2_1t = 6.07710050650619224932e-11, /* 0x3DD0B461, 0x1A626331 */ -pio2_2 = 6.07710050630396597660e-11, /* 0x3DD0B461, 0x1A600000 */ -pio2_2t = 2.02226624879595063154e-21, /* 0x3BA3198A, 0x2E037073 */ -pio2_3 = 2.02226624871116645580e-21, /* 0x3BA3198A, 0x2E000000 */ -pio2_3t = 8.47842766036889956997e-32; /* 0x397B839A, 0x252049C1 */ - -#ifdef __STDC__ - int32_t __ieee754_rem_pio2(double x, double *y) -#else - int32_t __ieee754_rem_pio2(x,y) - double x,y[]; -#endif -{ - double z = 0., w, t, r, fn; - double tx[3]; - int32_t i,j,n,ix,hx; - int e0,nx; - uint32_t low; - - GET_HIGH_WORD(hx,x); /* high word of x */ - ix = hx&0x7fffffff; - if(ix<=0x3fe921fb) /* |x| ~<= pi/4 , no need for reduction */ - {y[0] = x; y[1] = 0; return 0;} - if(ix<0x4002d97c) { /* |x| < 3pi/4, special case with n=+-1 */ - if(hx>0) { - z = x - pio2_1; - if(ix!=0x3ff921fb) { /* 33+53 bit pi is good enough */ - y[0] = z - pio2_1t; - y[1] = (z-y[0])-pio2_1t; - } else { /* near pi/2, use 33+33+53 bit pi */ - z -= pio2_2; - y[0] = z - pio2_2t; - y[1] = (z-y[0])-pio2_2t; - } - return 1; - } else { /* negative x */ - z = x + pio2_1; - if(ix!=0x3ff921fb) { /* 33+53 bit pi is good enough */ - y[0] = z + pio2_1t; - y[1] = (z-y[0])+pio2_1t; - } else { /* near pi/2, use 33+33+53 bit pi */ - z += pio2_2; - y[0] = z + pio2_2t; - y[1] = (z-y[0])+pio2_2t; - } - return -1; - } - } - if(ix<=0x413921fb) { /* |x| ~<= 2^19*(pi/2), medium size */ - t = fabs(x); - n = (int32_t) (t*invpio2+half); - fn = (double)n; - r = t-fn*pio2_1; - w = fn*pio2_1t; /* 1st round good to 85 bit */ - if(n<32&&ix!=npio2_hw[n-1]) { - y[0] = r-w; /* quick check no cancellation */ - } else { - uint32_t high; - j = ix>>20; - y[0] = r-w; - GET_HIGH_WORD(high,y[0]); - i = j-((high>>20)&0x7ff); - if(i>16) { /* 2nd iteration needed, good to 118 */ - t = r; - w = fn*pio2_2; - r = t-w; - w = fn*pio2_2t-((t-r)-w); - y[0] = r-w; - GET_HIGH_WORD(high,y[0]); - i = j-((high>>20)&0x7ff); - if(i>49) { /* 3rd iteration need, 151 bits acc */ - t = r; /* will cover all possible cases */ - w = fn*pio2_3; - r = t-w; - w = fn*pio2_3t-((t-r)-w); - y[0] = r-w; - } - } - } - y[1] = (r-y[0])-w; - if(hx<0) {y[0] = -y[0]; y[1] = -y[1]; return -n;} - else return n; - } - /* - * all other (large) arguments - */ - if(ix>=0x7ff00000) { /* x is inf or NaN */ - y[0]=y[1]=x-x; return 0; - } - /* set z = scalbn(|x|,ilogb(x)-23) */ - GET_LOW_WORD(low,x); - SET_LOW_WORD(z,low); - e0 = (int)((ix>>20)-1046); /* e0 = ilogb(z)-23; */ - SET_HIGH_WORD(z, ix - ((int32_t)e0<<20)); - for(i=0;i<2;i++) { - tx[i] = (double)((int32_t)(z)); - z = (z-tx[i])*two24; - } - tx[2] = z; - nx = 3; - while(tx[nx-1]==zero) nx--; /* skip zero term */ - n = __kernel_rem_pio2(tx,y,e0,nx,2,two_over_pi); - if(hx<0) {y[0] = -y[0]; y[1] = -y[1]; return -n;} - return n; -} - -#endif /* defined(_DOUBLE_IS_32BITS) */ diff --git a/libjava/java/lang/e_remainder.c b/libjava/java/lang/e_remainder.c deleted file mode 100644 index 4716d8d05fd..00000000000 --- a/libjava/java/lang/e_remainder.c +++ /dev/null @@ -1,80 +0,0 @@ - -/* @(#)e_remainder.c 5.1 93/09/24 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* __ieee754_remainder(x,p) - * Return : - * returns x REM p = x - [x/p]*p as if in infinite - * precise arithmetic, where [x/p] is the (infinite bit) - * integer nearest x/p (in half way case choose the even one). - * Method : - * Based on fmod() return x-[x/p]chopped*p exactlp. - */ - -#include "fdlibm.h" - -#ifndef _DOUBLE_IS_32BITS - -#ifdef __STDC__ -static const double zero = 0.0; -#else -static double zero = 0.0; -#endif - - -#ifdef __STDC__ - double __ieee754_remainder(double x, double p) -#else - double __ieee754_remainder(x,p) - double x,p; -#endif -{ - int32_t hx,hp; - uint32_t sx,lx,lp; - double p_half; - - EXTRACT_WORDS(hx,lx,x); - EXTRACT_WORDS(hp,lp,p); - sx = hx&0x80000000; - hp &= 0x7fffffff; - hx &= 0x7fffffff; - - /* purge off exception values */ - if((hp|lp)==0) return (x*p)/(x*p); /* p = 0 */ - if((hx>=0x7ff00000)|| /* x not finite */ - ((hp>=0x7ff00000)&& /* p is NaN */ - (((hp-0x7ff00000)|lp)!=0))) - return (x*p)/(x*p); - - - if (hp<=0x7fdfffff) x = __ieee754_fmod(x,p+p); /* now x < 2p */ - if (((hx-hp)|(lx-lp))==0) return zero*x; - x = fabs(x); - p = fabs(p); - if (hp<0x00200000) { - if(x+x>p) { - x-=p; - if(x+x>=p) x -= p; - } - } else { - p_half = 0.5*p; - if(x>p_half) { - x-=p; - if(x>=p_half) x -= p; - } - } - GET_HIGH_WORD(hx,x); - SET_HIGH_WORD(x,hx^sx); - return x; -} - -#endif /* defined(_DOUBLE_IS_32BITS) */ diff --git a/libjava/java/lang/e_scalb.c b/libjava/java/lang/e_scalb.c deleted file mode 100644 index 0bb924b43ee..00000000000 --- a/libjava/java/lang/e_scalb.c +++ /dev/null @@ -1,55 +0,0 @@ - -/* @(#)e_scalb.c 5.1 93/09/24 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* - * __ieee754_scalb(x, fn) is provide for - * passing various standard test suite. One - * should use scalbn() instead. - */ - -#include "fdlibm.h" - -#ifndef _DOUBLE_IS_32BITS - -#ifdef _SCALB_INT -#ifdef __STDC__ - double __ieee754_scalb(double x, int fn) -#else - double __ieee754_scalb(x,fn) - double x; int fn; -#endif -#else -#ifdef __STDC__ - double __ieee754_scalb(double x, double fn) -#else - double __ieee754_scalb(x,fn) - double x, fn; -#endif -#endif -{ -#ifdef _SCALB_INT - return scalbn(x,fn); -#else - if (isnan(x)||isnan(fn)) return x*fn; - if (!finite(fn)) { - if(fn>0.0) return x*fn; - else return x/(-fn); - } - if (rint(fn)!=fn) return (fn-fn)/(fn-fn); - if ( fn > 65000.0) return scalbn(x, 65000); - if (-fn > 65000.0) return scalbn(x,-65000); - return scalbn(x,(int)fn); -#endif -} - -#endif /* defined(_DOUBLE_IS_32BITS) */ diff --git a/libjava/java/lang/e_sqrt.c b/libjava/java/lang/e_sqrt.c deleted file mode 100644 index 1d566a0847e..00000000000 --- a/libjava/java/lang/e_sqrt.c +++ /dev/null @@ -1,452 +0,0 @@ - -/* @(#)e_sqrt.c 5.1 93/09/24 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* __ieee754_sqrt(x) - * Return correctly rounded sqrt. - * ------------------------------------------ - * | Use the hardware sqrt if you have one | - * ------------------------------------------ - * Method: - * Bit by bit method using integer arithmetic. (Slow, but portable) - * 1. Normalization - * Scale x to y in [1,4) with even powers of 2: - * find an integer k such that 1 <= (y=x*2^(2k)) < 4, then - * sqrt(x) = 2^k * sqrt(y) - * 2. Bit by bit computation - * Let q = sqrt(y) truncated to i bit after binary point (q = 1), - * i 0 - * i+1 2 - * s = 2*q , and y = 2 * ( y - q ). (1) - * i i i i - * - * To compute q from q , one checks whether - * i+1 i - * - * -(i+1) 2 - * (q + 2 ) <= y. (2) - * i - * -(i+1) - * If (2) is false, then q = q ; otherwise q = q + 2 . - * i+1 i i+1 i - * - * With some algebric manipulation, it is not difficult to see - * that (2) is equivalent to - * -(i+1) - * s + 2 <= y (3) - * i i - * - * The advantage of (3) is that s and y can be computed by - * i i - * the following recurrence formula: - * if (3) is false - * - * s = s , y = y ; (4) - * i+1 i i+1 i - * - * otherwise, - * -i -(i+1) - * s = s + 2 , y = y - s - 2 (5) - * i+1 i i+1 i i - * - * One may easily use induction to prove (4) and (5). - * Note. Since the left hand side of (3) contain only i+2 bits, - * it does not necessary to do a full (53-bit) comparison - * in (3). - * 3. Final rounding - * After generating the 53 bits result, we compute one more bit. - * Together with the remainder, we can decide whether the - * result is exact, bigger than 1/2ulp, or less than 1/2ulp - * (it will never equal to 1/2ulp). - * The rounding mode can be detected by checking whether - * huge + tiny is equal to huge, and whether huge - tiny is - * equal to huge for some floating point number "huge" and "tiny". - * - * Special cases: - * sqrt(+-0) = +-0 ... exact - * sqrt(inf) = inf - * sqrt(-ve) = NaN ... with invalid signal - * sqrt(NaN) = NaN ... with invalid signal for signaling NaN - * - * Other methods : see the appended file at the end of the program below. - *--------------- - */ - -#include "fdlibm.h" - -#ifndef _DOUBLE_IS_32BITS - -#ifdef __STDC__ -static const double one = 1.0, tiny=1.0e-300; -#else -static double one = 1.0, tiny=1.0e-300; -#endif - -#ifdef __STDC__ - double __ieee754_sqrt(double x) -#else - double __ieee754_sqrt(x) - double x; -#endif -{ - double z; - int32_t sign = (int)0x80000000; - uint32_t r,t1,s1,ix1,q1; - int32_t ix0,s0,q,m,t,i; - - EXTRACT_WORDS(ix0,ix1,x); - - /* take care of Inf and NaN */ - if((ix0&0x7ff00000)==0x7ff00000) { - return x*x+x; /* sqrt(NaN)=NaN, sqrt(+inf)=+inf - sqrt(-inf)=sNaN */ - } - /* take care of zero */ - if(ix0<=0) { - if(((ix0&(~sign))|ix1)==0) return x;/* sqrt(+-0) = +-0 */ - else if(ix0<0) - return (x-x)/(x-x); /* sqrt(-ve) = sNaN */ - } - /* normalize x */ - m = (ix0>>20); - if(m==0) { /* subnormal x */ - while(ix0==0) { - m -= 21; - ix0 |= (ix1>>11); ix1 <<= 21; - } - for(i=0;(ix0&0x00100000)==0;i++) ix0<<=1; - m -= i-1; - ix0 |= (ix1>>(32-i)); - ix1 <<= i; - } - m -= 1023; /* unbias exponent */ - ix0 = (ix0&0x000fffff)|0x00100000; - if(m&1){ /* odd m, double x to make it even */ - ix0 += ix0 + ((ix1&sign)>>31); - ix1 += ix1; - } - m >>= 1; /* m = [m/2] */ - - /* generate sqrt(x) bit by bit */ - ix0 += ix0 + ((ix1&sign)>>31); - ix1 += ix1; - q = q1 = s0 = s1 = 0; /* [q,q1] = sqrt(x) */ - r = 0x00200000; /* r = moving bit from right to left */ - - while(r!=0) { - t = s0+r; - if(t<=ix0) { - s0 = t+r; - ix0 -= t; - q += r; - } - ix0 += ix0 + ((ix1&sign)>>31); - ix1 += ix1; - r>>=1; - } - - r = sign; - while(r!=0) { - t1 = s1+r; - t = s0; - if((t<ix0)||((t==ix0)&&(t1<=ix1))) { - s1 = t1+r; - if(((t1&sign)==(uint32_t)sign)&&(s1&sign)==0) s0 += 1; - ix0 -= t; - if (ix1 < t1) ix0 -= 1; - ix1 -= t1; - q1 += r; - } - ix0 += ix0 + ((ix1&sign)>>31); - ix1 += ix1; - r>>=1; - } - - /* use floating add to find out rounding direction */ - if((ix0|ix1)!=0) { - z = one-tiny; /* trigger inexact flag */ - if (z>=one) { - z = one+tiny; - if (q1==(uint32_t)0xffffffff) { q1=0; q += 1;} - else if (z>one) { - if (q1==(uint32_t)0xfffffffe) q+=1; - q1+=2; - } else - q1 += (q1&1); - } - } - ix0 = (q>>1)+0x3fe00000; - ix1 = q1>>1; - if ((q&1)==1) ix1 |= sign; - ix0 += (m <<20); - INSERT_WORDS(z,ix0,ix1); - return z; -} - -#endif /* defined(_DOUBLE_IS_32BITS) */ - -/* -Other methods (use floating-point arithmetic) -------------- -(This is a copy of a drafted paper by Prof W. Kahan -and K.C. Ng, written in May, 1986) - - Two algorithms are given here to implement sqrt(x) - (IEEE double precision arithmetic) in software. - Both supply sqrt(x) correctly rounded. The first algorithm (in - Section A) uses newton iterations and involves four divisions. - The second one uses reciproot iterations to avoid division, but - requires more multiplications. Both algorithms need the ability - to chop results of arithmetic operations instead of round them, - and the INEXACT flag to indicate when an arithmetic operation - is executed exactly with no roundoff error, all part of the - standard (IEEE 754-1985). The ability to perform shift, add, - subtract and logical AND operations upon 32-bit words is needed - too, though not part of the standard. - -A. sqrt(x) by Newton Iteration - - (1) Initial approximation - - Let x0 and x1 be the leading and the trailing 32-bit words of - a floating point number x (in IEEE double format) respectively - - 1 11 52 ...widths - ------------------------------------------------------ - x: |s| e | f | - ------------------------------------------------------ - msb lsb msb lsb ...order - - - ------------------------ ------------------------ - x0: |s| e | f1 | x1: | f2 | - ------------------------ ------------------------ - - By performing shifts and subtracts on x0 and x1 (both regarded - as integers), we obtain an 8-bit approximation of sqrt(x) as - follows. - - k := (x0>>1) + 0x1ff80000; - y0 := k - T1[31&(k>>15)]. ... y ~ sqrt(x) to 8 bits - Here k is a 32-bit integer and T1[] is an integer array containing - correction terms. Now magically the floating value of y (y's - leading 32-bit word is y0, the value of its trailing word is 0) - approximates sqrt(x) to almost 8-bit. - - Value of T1: - static int T1[32]= { - 0, 1024, 3062, 5746, 9193, 13348, 18162, 23592, - 29598, 36145, 43202, 50740, 58733, 67158, 75992, 85215, - 83599, 71378, 60428, 50647, 41945, 34246, 27478, 21581, - 16499, 12183, 8588, 5674, 3403, 1742, 661, 130,}; - - (2) Iterative refinement - - Apply Heron's rule three times to y, we have y approximates - sqrt(x) to within 1 ulp (Unit in the Last Place): - - y := (y+x/y)/2 ... almost 17 sig. bits - y := (y+x/y)/2 ... almost 35 sig. bits - y := y-(y-x/y)/2 ... within 1 ulp - - - Remark 1. - Another way to improve y to within 1 ulp is: - - y := (y+x/y) ... almost 17 sig. bits to 2*sqrt(x) - y := y - 0x00100006 ... almost 18 sig. bits to sqrt(x) - - 2 - (x-y )*y - y := y + 2* ---------- ...within 1 ulp - 2 - 3y + x - - - This formula has one division fewer than the one above; however, - it requires more multiplications and additions. Also x must be - scaled in advance to avoid spurious overflow in evaluating the - expression 3y*y+x. Hence it is not recommended uless division - is slow. If division is very slow, then one should use the - reciproot algorithm given in section B. - - (3) Final adjustment - - By twiddling y's last bit it is possible to force y to be - correctly rounded according to the prevailing rounding mode - as follows. Let r and i be copies of the rounding mode and - inexact flag before entering the square root program. Also we - use the expression y+-ulp for the next representable floating - numbers (up and down) of y. Note that y+-ulp = either fixed - point y+-1, or multiply y by nextafter(1,+-inf) in chopped - mode. - - I := FALSE; ... reset INEXACT flag I - R := RZ; ... set rounding mode to round-toward-zero - z := x/y; ... chopped quotient, possibly inexact - If(not I) then { ... if the quotient is exact - if(z=y) { - I := i; ... restore inexact flag - R := r; ... restore rounded mode - return sqrt(x):=y. - } else { - z := z - ulp; ... special rounding - } - } - i := TRUE; ... sqrt(x) is inexact - If (r=RN) then z=z+ulp ... rounded-to-nearest - If (r=RP) then { ... round-toward-+inf - y = y+ulp; z=z+ulp; - } - y := y+z; ... chopped sum - y0:=y0-0x00100000; ... y := y/2 is correctly rounded. - I := i; ... restore inexact flag - R := r; ... restore rounded mode - return sqrt(x):=y. - - (4) Special cases - - Square root of +inf, +-0, or NaN is itself; - Square root of a negative number is NaN with invalid signal. - - -B. sqrt(x) by Reciproot Iteration - - (1) Initial approximation - - Let x0 and x1 be the leading and the trailing 32-bit words of - a floating point number x (in IEEE double format) respectively - (see section A). By performing shifs and subtracts on x0 and y0, - we obtain a 7.8-bit approximation of 1/sqrt(x) as follows. - - k := 0x5fe80000 - (x0>>1); - y0:= k - T2[63&(k>>14)]. ... y ~ 1/sqrt(x) to 7.8 bits - - Here k is a 32-bit integer and T2[] is an integer array - containing correction terms. Now magically the floating - value of y (y's leading 32-bit word is y0, the value of - its trailing word y1 is set to zero) approximates 1/sqrt(x) - to almost 7.8-bit. - - Value of T2: - static int T2[64]= { - 0x1500, 0x2ef8, 0x4d67, 0x6b02, 0x87be, 0xa395, 0xbe7a, 0xd866, - 0xf14a, 0x1091b,0x11fcd,0x13552,0x14999,0x15c98,0x16e34,0x17e5f, - 0x18d03,0x19a01,0x1a545,0x1ae8a,0x1b5c4,0x1bb01,0x1bfde,0x1c28d, - 0x1c2de,0x1c0db,0x1ba73,0x1b11c,0x1a4b5,0x1953d,0x18266,0x16be0, - 0x1683e,0x179d8,0x18a4d,0x19992,0x1a789,0x1b445,0x1bf61,0x1c989, - 0x1d16d,0x1d77b,0x1dddf,0x1e2ad,0x1e5bf,0x1e6e8,0x1e654,0x1e3cd, - 0x1df2a,0x1d635,0x1cb16,0x1be2c,0x1ae4e,0x19bde,0x1868e,0x16e2e, - 0x1527f,0x1334a,0x11051,0xe951, 0xbe01, 0x8e0d, 0x5924, 0x1edd,}; - - (2) Iterative refinement - - Apply Reciproot iteration three times to y and multiply the - result by x to get an approximation z that matches sqrt(x) - to about 1 ulp. To be exact, we will have - -1ulp < sqrt(x)-z<1.0625ulp. - - ... set rounding mode to Round-to-nearest - y := y*(1.5-0.5*x*y*y) ... almost 15 sig. bits to 1/sqrt(x) - y := y*((1.5-2^-30)+0.5*x*y*y)... about 29 sig. bits to 1/sqrt(x) - ... special arrangement for better accuracy - z := x*y ... 29 bits to sqrt(x), with z*y<1 - z := z + 0.5*z*(1-z*y) ... about 1 ulp to sqrt(x) - - Remark 2. The constant 1.5-2^-30 is chosen to bias the error so that - (a) the term z*y in the final iteration is always less than 1; - (b) the error in the final result is biased upward so that - -1 ulp < sqrt(x) - z < 1.0625 ulp - instead of |sqrt(x)-z|<1.03125ulp. - - (3) Final adjustment - - By twiddling y's last bit it is possible to force y to be - correctly rounded according to the prevailing rounding mode - as follows. Let r and i be copies of the rounding mode and - inexact flag before entering the square root program. Also we - use the expression y+-ulp for the next representable floating - numbers (up and down) of y. Note that y+-ulp = either fixed - point y+-1, or multiply y by nextafter(1,+-inf) in chopped - mode. - - R := RZ; ... set rounding mode to round-toward-zero - switch(r) { - case RN: ... round-to-nearest - if(x<= z*(z-ulp)...chopped) z = z - ulp; else - if(x<= z*(z+ulp)...chopped) z = z; else z = z+ulp; - break; - case RZ:case RM: ... round-to-zero or round-to--inf - R:=RP; ... reset rounding mod to round-to-+inf - if(x<z*z ... rounded up) z = z - ulp; else - if(x>=(z+ulp)*(z+ulp) ...rounded up) z = z+ulp; - break; - case RP: ... round-to-+inf - if(x>(z+ulp)*(z+ulp)...chopped) z = z+2*ulp; else - if(x>z*z ...chopped) z = z+ulp; - break; - } - - Remark 3. The above comparisons can be done in fixed point. For - example, to compare x and w=z*z chopped, it suffices to compare - x1 and w1 (the trailing parts of x and w), regarding them as - two's complement integers. - - ...Is z an exact square root? - To determine whether z is an exact square root of x, let z1 be the - trailing part of z, and also let x0 and x1 be the leading and - trailing parts of x. - - If ((z1&0x03ffffff)!=0) ... not exact if trailing 26 bits of z!=0 - I := 1; ... Raise Inexact flag: z is not exact - else { - j := 1 - [(x0>>20)&1] ... j = logb(x) mod 2 - k := z1 >> 26; ... get z's 25-th and 26-th - fraction bits - I := i or (k&j) or ((k&(j+j+1))!=(x1&3)); - } - R:= r ... restore rounded mode - return sqrt(x):=z. - - If multiplication is cheaper then the foregoing red tape, the - Inexact flag can be evaluated by - - I := i; - I := (z*z!=x) or I. - - Note that z*z can overwrite I; this value must be sensed if it is - True. - - Remark 4. If z*z = x exactly, then bit 25 to bit 0 of z1 must be - zero. - - -------------------- - z1: | f2 | - -------------------- - bit 31 bit 0 - - Further more, bit 27 and 26 of z1, bit 0 and 1 of x1, and the odd - or even of logb(x) have the following relations: - - ------------------------------------------------- - bit 27,26 of z1 bit 1,0 of x1 logb(x) - ------------------------------------------------- - 00 00 odd and even - 01 01 even - 10 10 odd - 10 00 even - 11 01 even - ------------------------------------------------- - - (4) Special cases (see (4) of Section A). - - */ diff --git a/libjava/java/lang/fdlibm.h b/libjava/java/lang/fdlibm.h deleted file mode 100644 index fbfbb660bfd..00000000000 --- a/libjava/java/lang/fdlibm.h +++ /dev/null @@ -1,350 +0,0 @@ - -/* @(#)fdlibm.h 5.1 93/09/24 */ -/* - * ==================================================== - * Copyright (C) 1993, 2000 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* AIX needs _XOPEN_SOURCE */ -#ifdef _AIX -#define _XOPEN_SOURCE -#endif - -#include <config.h> -#include <stdlib.h> - -/* GCJ LOCAL: Include files. */ -#include "ieeefp.h" - -#include "mprec.h" - -/* CYGNUS LOCAL: Default to XOPEN_MODE. */ -#define _XOPEN_MODE - -#ifdef __P -#undef __P -#endif - -#ifdef __STDC__ -#define __P(p) p -#else -#define __P(p) () -#endif - -#ifndef HUGE -#define HUGE ((float)3.40282346638528860e+38) -#endif - -/* - * set X_TLOSS = pi*2**52, which is possibly defined in <values.h> - * (one may replace the following line by "#include <values.h>") - */ - -#define X_TLOSS 1.41484755040568800000e+16 - -/* These typedefs are true for the targets running Java. */ - -#define _IEEE_LIBM - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * ANSI/POSIX - */ -extern double acos __P((double)); -extern double asin __P((double)); -extern double atan __P((double)); -extern double atan2 __P((double, double)); -extern double cos __P((double)); -extern double sin __P((double)); -extern double tan __P((double)); - -extern double cosh __P((double)); -extern double sinh __P((double)); -extern double tanh __P((double)); - -extern double exp __P((double)); -extern double frexp __P((double, int *)); -extern double ldexp __P((double, int)); -extern double log __P((double)); -extern double log10 __P((double)); -extern double modf __P((double, double *)); - -extern double pow __P((double, double)); -extern double sqrt __P((double)); - -extern double ceil __P((double)); -extern double fabs __P((double)); -extern double floor __P((double)); -extern double fmod __P((double, double)); - -extern double erf __P((double)); -extern double erfc __P((double)); -extern double gamma __P((double)); -extern double hypot __P((double, double)); -extern int isnan __P((double)); -extern int finite __P((double)); -extern double j0 __P((double)); -extern double j1 __P((double)); -extern double jn __P((int, double)); -extern double lgamma __P((double)); -extern double y0 __P((double)); -extern double y1 __P((double)); -extern double yn __P((int, double)); - -extern double acosh __P((double)); -extern double asinh __P((double)); -extern double atanh __P((double)); -extern double cbrt __P((double)); -extern double logb __P((double)); -extern double nextafter __P((double, double)); -extern double remainder __P((double, double)); - -/* Functions that are not documented, and are not in <math.h>. */ - -extern double logb __P((double)); -#ifdef _SCALB_INT -extern double scalb __P((double, int)); -#else -extern double scalb __P((double, double)); -#endif -extern double significand __P((double)); - -/* ieee style elementary functions */ -extern double __ieee754_sqrt __P((double)); -extern double __ieee754_acos __P((double)); -extern double __ieee754_acosh __P((double)); -extern double __ieee754_log __P((double)); -extern double __ieee754_atanh __P((double)); -extern double __ieee754_asin __P((double)); -extern double __ieee754_atan2 __P((double,double)); -extern double __ieee754_exp __P((double)); -extern double __ieee754_cosh __P((double)); -extern double __ieee754_fmod __P((double,double)); -extern double __ieee754_pow __P((double,double)); -extern double __ieee754_lgamma_r __P((double,int *)); -extern double __ieee754_gamma_r __P((double,int *)); -extern double __ieee754_log10 __P((double)); -extern double __ieee754_sinh __P((double)); -extern double __ieee754_hypot __P((double,double)); -extern double __ieee754_j0 __P((double)); -extern double __ieee754_j1 __P((double)); -extern double __ieee754_y0 __P((double)); -extern double __ieee754_y1 __P((double)); -extern double __ieee754_jn __P((int,double)); -extern double __ieee754_yn __P((int,double)); -extern double __ieee754_remainder __P((double,double)); -extern int32_t __ieee754_rem_pio2 __P((double,double*)); -#ifdef _SCALB_INT -extern double __ieee754_scalb __P((double,int)); -#else -extern double __ieee754_scalb __P((double,double)); -#endif - -/* fdlibm kernel function */ -extern double __kernel_standard __P((double,double,int)); -extern double __kernel_sin __P((double,double,int)); -extern double __kernel_cos __P((double,double)); -extern double __kernel_tan __P((double,double,int)); -extern int __kernel_rem_pio2 __P((double*,double*,int,int,int,const int32_t*)); - -/* Undocumented float functions. */ -extern float logbf __P((float)); -#ifdef _SCALB_INT -extern float scalbf __P((float, int)); -#else -extern float scalbf __P((float, float)); -#endif -extern float significandf __P((float)); - -/* - * Functions callable from C, intended to support IEEE arithmetic. - */ -extern double copysign __P((double, double)); -extern int ilogb __P((double)); -extern double rint __P((double)); -extern float rintf __P((float)); -extern double scalbn __P((double, int)); - -/* ieee style elementary float functions */ -extern float __ieee754_sqrtf __P((float)); -extern float __ieee754_acosf __P((float)); -extern float __ieee754_acoshf __P((float)); -extern float __ieee754_logf __P((float)); -extern float __ieee754_atanhf __P((float)); -extern float __ieee754_asinf __P((float)); -extern float __ieee754_atan2f __P((float,float)); -extern float __ieee754_expf __P((float)); -extern float __ieee754_coshf __P((float)); -extern float __ieee754_fmodf __P((float,float)); -extern float __ieee754_powf __P((float,float)); -extern float __ieee754_lgammaf_r __P((float,int *)); -extern float __ieee754_gammaf_r __P((float,int *)); -extern float __ieee754_log10f __P((float)); -extern float __ieee754_sinhf __P((float)); -extern float __ieee754_hypotf __P((float,float)); -extern float __ieee754_j0f __P((float)); -extern float __ieee754_j1f __P((float)); -extern float __ieee754_y0f __P((float)); -extern float __ieee754_y1f __P((float)); -extern float __ieee754_jnf __P((int,float)); -extern float __ieee754_ynf __P((int,float)); -extern float __ieee754_remainderf __P((float,float)); -extern int32_t __ieee754_rem_pio2f __P((float,float*)); -#ifdef _SCALB_INT -extern float __ieee754_scalbf __P((float,int)); -#else -extern float __ieee754_scalbf __P((float,float)); -#endif - -/* float versions of fdlibm kernel functions */ -extern float __kernel_sinf __P((float,float,int)); -extern float __kernel_cosf __P((float,float)); -extern float __kernel_tanf __P((float,float,int)); -extern int __kernel_rem_pio2f __P((float*,float*,int,int,int,const int32_t*)); - -/* The original code used statements like - n0 = ((*(int*)&one)>>29)^1; * index of high word * - ix0 = *(n0+(int*)&x); * high word of x * - ix1 = *((1-n0)+(int*)&x); * low word of x * - to dig two 32 bit words out of the 64 bit IEEE floating point - value. That is non-ANSI, and, moreover, the gcc instruction - scheduler gets it wrong. We instead use the following macros. - Unlike the original code, we determine the endianness at compile - time, not at run time; I don't see much benefit to selecting - endianness at run time. */ - -#ifndef __IEEE_BIG_ENDIAN -#ifndef __IEEE_LITTLE_ENDIAN - #error Must define endianness -#endif -#endif - -/* A union which permits us to convert between a double and two 32 bit - ints. */ - -#ifdef __IEEE_BIG_ENDIAN - -typedef union -{ - double value; - struct - { - uint32_t msw; - uint32_t lsw; - } parts; -} ieee_double_shape_type; - -#endif - -#ifdef __IEEE_LITTLE_ENDIAN - -typedef union -{ - double value; - struct - { - uint32_t lsw; - uint32_t msw; - } parts; -} ieee_double_shape_type; - -#endif - -/* Get two 32 bit ints from a double. */ - -#define EXTRACT_WORDS(ix0,ix1,d) \ -do { \ - ieee_double_shape_type ew_u; \ - ew_u.value = (d); \ - (ix0) = ew_u.parts.msw; \ - (ix1) = ew_u.parts.lsw; \ -} while (0) - -/* Get the more significant 32 bit int from a double. */ - -#define GET_HIGH_WORD(i,d) \ -do { \ - ieee_double_shape_type gh_u; \ - gh_u.value = (d); \ - (i) = gh_u.parts.msw; \ -} while (0) - -/* Get the less significant 32 bit int from a double. */ - -#define GET_LOW_WORD(i,d) \ -do { \ - ieee_double_shape_type gl_u; \ - gl_u.value = (d); \ - (i) = gl_u.parts.lsw; \ -} while (0) - -/* Set a double from two 32 bit ints. */ - -#define INSERT_WORDS(d,ix0,ix1) \ -do { \ - ieee_double_shape_type iw_u; \ - iw_u.parts.msw = (ix0); \ - iw_u.parts.lsw = (ix1); \ - (d) = iw_u.value; \ -} while (0) - -/* Set the more significant 32 bits of a double from an int. */ - -#define SET_HIGH_WORD(d,v) \ -do { \ - ieee_double_shape_type sh_u; \ - sh_u.value = (d); \ - sh_u.parts.msw = (v); \ - (d) = sh_u.value; \ -} while (0) - -/* Set the less significant 32 bits of a double from an int. */ - -#define SET_LOW_WORD(d,v) \ -do { \ - ieee_double_shape_type sl_u; \ - sl_u.value = (d); \ - sl_u.parts.lsw = (v); \ - (d) = sl_u.value; \ -} while (0) - -/* A union which permits us to convert between a float and a 32 bit - int. */ - -typedef union -{ - float value; - uint32_t word; -} ieee_float_shape_type; - -/* Get a 32 bit int from a float. */ - -#define GET_FLOAT_WORD(i,d) \ -do { \ - ieee_float_shape_type gf_u; \ - gf_u.value = (d); \ - (i) = gf_u.word; \ -} while (0) - -/* Set a float from a 32 bit int. */ - -#define SET_FLOAT_WORD(d,i) \ -do { \ - ieee_float_shape_type sf_u; \ - sf_u.word = (i); \ - (d) = sf_u.value; \ -} while (0) - -#ifdef __cplusplus -} -#endif - diff --git a/libjava/java/lang/ieeefp.h b/libjava/java/lang/ieeefp.h deleted file mode 100644 index 3638d546eab..00000000000 --- a/libjava/java/lang/ieeefp.h +++ /dev/null @@ -1,163 +0,0 @@ -#ifndef __IEEE_BIG_ENDIAN -#ifndef __IEEE_LITTLE_ENDIAN - -#ifdef __alpha__ -#define __IEEE_LITTLE_ENDIAN -#endif - -#if defined(__arm__) || defined(__thumb__) -/* ARM traditionally used big-endian words; and within those words the - byte ordering was big or little endian depending upon the target. - Modern floating-point formats are naturally ordered; in this case - __VFP_FP__ will be defined, even if soft-float. */ -#ifdef __VFP_FP__ -#ifdef __ARMEL__ -#define __IEEE_LITTLE_ENDIAN -#else -#define __IEEE_BIG_ENDIAN -#endif -#else -#define __IEEE_BIG_ENDIAN -#ifdef __ARMEL__ -#define __IEEE_BYTES_LITTLE_ENDIAN -#endif -#endif -#endif - -#ifdef __hppa__ -#define __IEEE_BIG_ENDIAN -#endif - -#if defined (__sparc) || defined (__sparc__) -#define __IEEE_BIG_ENDIAN -#endif - -#ifdef __m32r__ -#ifdef __LITTLE_ENDIAN__ -#define __IEEE_LITTLE_ENDIAN -#else -#define __IEEE_BIG_ENDIAN -#endif -#endif - -#if defined(__m68k__) || defined(__mc68000__) -#define __IEEE_BIG_ENDIAN -#endif - -#if defined (__H8300__) || defined (__H8300H__) -#define __IEEE_BIG_ENDIAN -#define __SMALL_BITFIELDS -#define _DOUBLE_IS_32BITS -#endif - -#ifdef __H8500__ -#define __IEEE_BIG_ENDIAN -#define __SMALL_BITFIELDS -#define _DOUBLE_IS_32BITS -#endif - -#ifdef __sh__ -#ifdef __LITTLE_ENDIAN__ -#define __IEEE_LITTLE_ENDIAN -#else -#define __IEEE_BIG_ENDIAN -#endif - -#ifdef __SH3E__ -#define _DOUBLE_IS_32BITS -#endif -#endif - -#ifdef _AM29K -#define __IEEE_BIG_ENDIAN -#endif - -#ifdef __i386__ -#define __IEEE_LITTLE_ENDIAN -#endif - -#ifdef __x86_64__ -#define __IEEE_LITTLE_ENDIAN -#endif - -#ifdef __i960__ -#define __IEEE_LITTLE_ENDIAN -#endif - -#ifdef __MIPSEL__ -#define __IEEE_LITTLE_ENDIAN -#endif - -#ifdef __MIPSEB__ -#define __IEEE_BIG_ENDIAN -#endif - -#ifdef __pj__ -#ifdef __pjl__ -#define __IEEE_LITTLE_ENDIAN -#else -#define __IEEE_BIG_ENDIAN -#endif -#endif - -/* necv70 was __IEEE_LITTLE_ENDIAN. */ - -#ifdef __W65__ -#define __IEEE_LITTLE_ENDIAN -#define __SMALL_BITFIELDS -#define _DOUBLE_IS_32BITS -#endif - -#if defined(__Z8001__) || defined(__Z8002__) -#define __IEEE_BIG_ENDIAN -#endif - -#ifdef __m88k__ -#define __IEEE_BIG_ENDIAN -#endif - -#ifdef __v800 -#define __IEEE_LITTLE_ENDIAN -#endif - -#if defined (__PPC__) || defined (__ppc__) || defined (__ppc64__) -#if (defined(_BIG_ENDIAN) && _BIG_ENDIAN) || (defined(_AIX) && _AIX) \ - || defined (__APPLE__) -#define __IEEE_BIG_ENDIAN -#else -#if (defined(_LITTLE_ENDIAN) && _LITTLE_ENDIAN) || (defined(__sun__) && __sun__) || (defined(__WIN32__) && __WIN32__) -#define __IEEE_LITTLE_ENDIAN -#endif -#endif -#endif - -#ifdef __fr30__ -#define __IEEE_BIG_ENDIAN -#endif - -#ifdef __mcore__ -#define __IEEE_BIG_ENDIAN -#endif - - -#ifdef __ia64__ -#ifdef __BIG_ENDIAN__ -#define __IEEE_BIG_ENDIAN -#else -#define __IEEE_LITTLE_ENDIAN -#endif -#endif - -#ifdef __s390__ -#define __IEEE_BIG_ENDIAN -#endif - -#ifndef __IEEE_BIG_ENDIAN -#ifndef __IEEE_LITTLE_ENDIAN -#error Endianess not declared!! -#endif /* not __IEEE_LITTLE_ENDIAN */ -#endif /* not __IEEE_BIG_ENDIAN */ - -#endif /* not __IEEE_LITTLE_ENDIAN */ -#endif /* not __IEEE_BIG_ENDIAN */ - diff --git a/libjava/java/lang/k_cos.c b/libjava/java/lang/k_cos.c deleted file mode 100644 index acf50a82e83..00000000000 --- a/libjava/java/lang/k_cos.c +++ /dev/null @@ -1,96 +0,0 @@ - -/* @(#)k_cos.c 5.1 93/09/24 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* - * __kernel_cos( x, y ) - * kernel cos function on [-pi/4, pi/4], pi/4 ~ 0.785398164 - * Input x is assumed to be bounded by ~pi/4 in magnitude. - * Input y is the tail of x. - * - * Algorithm - * 1. Since cos(-x) = cos(x), we need only to consider positive x. - * 2. if x < 2^-27 (hx<0x3e400000 0), return 1 with inexact if x!=0. - * 3. cos(x) is approximated by a polynomial of degree 14 on - * [0,pi/4] - * 4 14 - * cos(x) ~ 1 - x*x/2 + C1*x + ... + C6*x - * where the remez error is - * - * | 2 4 6 8 10 12 14 | -58 - * |cos(x)-(1-.5*x +C1*x +C2*x +C3*x +C4*x +C5*x +C6*x )| <= 2 - * | | - * - * 4 6 8 10 12 14 - * 4. let r = C1*x +C2*x +C3*x +C4*x +C5*x +C6*x , then - * cos(x) = 1 - x*x/2 + r - * since cos(x+y) ~ cos(x) - sin(x)*y - * ~ cos(x) - x*y, - * a correction term is necessary in cos(x) and hence - * cos(x+y) = 1 - (x*x/2 - (r - x*y)) - * For better accuracy when x > 0.3, let qx = |x|/4 with - * the last 32 bits mask off, and if x > 0.78125, let qx = 0.28125. - * Then - * cos(x+y) = (1-qx) - ((x*x/2-qx) - (r-x*y)). - * Note that 1-qx and (x*x/2-qx) is EXACT here, and the - * magnitude of the latter is at least a quarter of x*x/2, - * thus, reducing the rounding error in the subtraction. - */ - -#include "fdlibm.h" - -#ifndef _DOUBLE_IS_32BITS - -#ifdef __STDC__ -static const double -#else -static double -#endif -one = 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */ -C1 = 4.16666666666666019037e-02, /* 0x3FA55555, 0x5555554C */ -C2 = -1.38888888888741095749e-03, /* 0xBF56C16C, 0x16C15177 */ -C3 = 2.48015872894767294178e-05, /* 0x3EFA01A0, 0x19CB1590 */ -C4 = -2.75573143513906633035e-07, /* 0xBE927E4F, 0x809C52AD */ -C5 = 2.08757232129817482790e-09, /* 0x3E21EE9E, 0xBDB4B1C4 */ -C6 = -1.13596475577881948265e-11; /* 0xBDA8FAE9, 0xBE8838D4 */ - -#ifdef __STDC__ - double __kernel_cos(double x, double y) -#else - double __kernel_cos(x, y) - double x,y; -#endif -{ - double a,hz,z,r,qx; - int32_t ix; - GET_HIGH_WORD(ix,x); - ix &= 0x7fffffff; /* ix = |x|'s high word*/ - if(ix<0x3e400000) { /* if x < 2**27 */ - if(((int)x)==0) return one; /* generate inexact */ - } - z = x*x; - r = z*(C1+z*(C2+z*(C3+z*(C4+z*(C5+z*C6))))); - if(ix < 0x3FD33333) /* if |x| < 0.3 */ - return one - (0.5*z - (z*r - x*y)); - else { - if(ix > 0x3fe90000) { /* x > 0.78125 */ - qx = 0.28125; - } else { - INSERT_WORDS(qx,ix-0x00200000,0); /* x/4 */ - } - hz = 0.5*z-qx; - a = one-qx; - return a - (hz - (z*r-x*y)); - } -} - -#endif /* defined(_DOUBLE_IS_32BITS) */ diff --git a/libjava/java/lang/k_rem_pio2.c b/libjava/java/lang/k_rem_pio2.c deleted file mode 100644 index 2f4ca17256c..00000000000 --- a/libjava/java/lang/k_rem_pio2.c +++ /dev/null @@ -1,320 +0,0 @@ - -/* @(#)k_rem_pio2.c 5.1 93/09/24 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* - * __kernel_rem_pio2(x,y,e0,nx,prec,ipio2) - * double x[],y[]; int e0,nx,prec; int ipio2[]; - * - * __kernel_rem_pio2 return the last three digits of N with - * y = x - N*pi/2 - * so that |y| < pi/2. - * - * The method is to compute the integer (mod 8) and fraction parts of - * (2/pi)*x without doing the full multiplication. In general we - * skip the part of the product that are known to be a huge integer ( - * more accurately, = 0 mod 8 ). Thus the number of operations are - * independent of the exponent of the input. - * - * (2/pi) is represented by an array of 24-bit integers in ipio2[]. - * - * Input parameters: - * x[] The input value (must be positive) is broken into nx - * pieces of 24-bit integers in double precision format. - * x[i] will be the i-th 24 bit of x. The scaled exponent - * of x[0] is given in input parameter e0 (i.e., x[0]*2^e0 - * match x's up to 24 bits. - * - * Example of breaking a double positive z into x[0]+x[1]+x[2]: - * e0 = ilogb(z)-23 - * z = scalbn(z,-e0) - * for i = 0,1,2 - * x[i] = floor(z) - * z = (z-x[i])*2**24 - * - * - * y[] ouput result in an array of double precision numbers. - * The dimension of y[] is: - * 24-bit precision 1 - * 53-bit precision 2 - * 64-bit precision 2 - * 113-bit precision 3 - * The actual value is the sum of them. Thus for 113-bit - * precison, one may have to do something like: - * - * long double t,w,r_head, r_tail; - * t = (long double)y[2] + (long double)y[1]; - * w = (long double)y[0]; - * r_head = t+w; - * r_tail = w - (r_head - t); - * - * e0 The exponent of x[0] - * - * nx dimension of x[] - * - * prec an integer indicating the precision: - * 0 24 bits (single) - * 1 53 bits (double) - * 2 64 bits (extended) - * 3 113 bits (quad) - * - * ipio2[] - * integer array, contains the (24*i)-th to (24*i+23)-th - * bit of 2/pi after binary point. The corresponding - * floating value is - * - * ipio2[i] * 2^(-24(i+1)). - * - * External function: - * double scalbn(), floor(); - * - * - * Here is the description of some local variables: - * - * jk jk+1 is the initial number of terms of ipio2[] needed - * in the computation. The recommended value is 2,3,4, - * 6 for single, double, extended,and quad. - * - * jz local integer variable indicating the number of - * terms of ipio2[] used. - * - * jx nx - 1 - * - * jv index for pointing to the suitable ipio2[] for the - * computation. In general, we want - * ( 2^e0*x[0] * ipio2[jv-1]*2^(-24jv) )/8 - * is an integer. Thus - * e0-3-24*jv >= 0 or (e0-3)/24 >= jv - * Hence jv = max(0,(e0-3)/24). - * - * jp jp+1 is the number of terms in PIo2[] needed, jp = jk. - * - * q[] double array with integral value, representing the - * 24-bits chunk of the product of x and 2/pi. - * - * q0 the corresponding exponent of q[0]. Note that the - * exponent for q[i] would be q0-24*i. - * - * PIo2[] double precision array, obtained by cutting pi/2 - * into 24 bits chunks. - * - * f[] ipio2[] in floating point - * - * iq[] integer array by breaking up q[] in 24-bits chunk. - * - * fq[] final product of x*(2/pi) in fq[0],..,fq[jk] - * - * ih integer. If >0 it indicates q[] is >= 0.5, hence - * it also indicates the *sign* of the result. - * - */ - - -/* - * Constants: - * The hexadecimal values are the intended ones for the following - * constants. The decimal values may be used, provided that the - * compiler will convert from decimal to binary accurately enough - * to produce the hexadecimal values shown. - */ - -#include "fdlibm.h" - -#ifndef _DOUBLE_IS_32BITS - -#ifdef __STDC__ -static const int init_jk[] = {2,3,4,6}; /* initial value for jk */ -#else -static int init_jk[] = {2,3,4,6}; -#endif - -#ifdef __STDC__ -static const double PIo2[] = { -#else -static double PIo2[] = { -#endif - 1.57079625129699707031e+00, /* 0x3FF921FB, 0x40000000 */ - 7.54978941586159635335e-08, /* 0x3E74442D, 0x00000000 */ - 5.39030252995776476554e-15, /* 0x3CF84698, 0x80000000 */ - 3.28200341580791294123e-22, /* 0x3B78CC51, 0x60000000 */ - 1.27065575308067607349e-29, /* 0x39F01B83, 0x80000000 */ - 1.22933308981111328932e-36, /* 0x387A2520, 0x40000000 */ - 2.73370053816464559624e-44, /* 0x36E38222, 0x80000000 */ - 2.16741683877804819444e-51, /* 0x3569F31D, 0x00000000 */ -}; - -#ifdef __STDC__ -static const double -#else -static double -#endif -zero = 0.0, -one = 1.0, -two24 = 1.67772160000000000000e+07, /* 0x41700000, 0x00000000 */ -twon24 = 5.96046447753906250000e-08; /* 0x3E700000, 0x00000000 */ - -#ifdef __STDC__ - int __kernel_rem_pio2(double *x, double *y, int e0, int nx, int prec, const int32_t *ipio2) -#else - int __kernel_rem_pio2(x,y,e0,nx,prec,ipio2) - double x[], y[]; int e0,nx,prec; int32_t ipio2[]; -#endif -{ - int32_t jz,jx,jv,jp,jk,carry,n,iq[20],i,j,k,m,q0,ih; - double z,fw,f[20],fq[20],q[20]; - - /* initialize jk*/ - jk = init_jk[prec]; - jp = jk; - - /* determine jx,jv,q0, note that 3>q0 */ - jx = nx-1; - jv = (e0-3)/24; if(jv<0) jv=0; - q0 = e0-24*(jv+1); - - /* set up f[0] to f[jx+jk] where f[jx+jk] = ipio2[jv+jk] */ - j = jv-jx; m = jx+jk; - for(i=0;i<=m;i++,j++) f[i] = (j<0)? zero : (double) ipio2[j]; - - /* compute q[0],q[1],...q[jk] */ - for (i=0;i<=jk;i++) { - for(j=0,fw=0.0;j<=jx;j++) fw += x[j]*f[jx+i-j]; q[i] = fw; - } - - jz = jk; -recompute: - /* distill q[] into iq[] reversingly */ - for(i=0,j=jz,z=q[jz];j>0;i++,j--) { - fw = (double)((int32_t)(twon24* z)); - iq[i] = (int32_t)(z-two24*fw); - z = q[j-1]+fw; - } - - /* compute n */ - z = scalbn(z,(int)q0); /* actual value of z */ - z -= 8.0*floor(z*0.125); /* trim off integer >= 8 */ - n = (int32_t) z; - z -= (double)n; - ih = 0; - if(q0>0) { /* need iq[jz-1] to determine n */ - i = (iq[jz-1]>>(24-q0)); n += i; - iq[jz-1] -= i<<(24-q0); - ih = iq[jz-1]>>(23-q0); - } - else if(q0==0) ih = iq[jz-1]>>23; - else if(z>=0.5) ih=2; - - if(ih>0) { /* q > 0.5 */ - n += 1; carry = 0; - for(i=0;i<jz ;i++) { /* compute 1-q */ - j = iq[i]; - if(carry==0) { - if(j!=0) { - carry = 1; iq[i] = 0x1000000- j; - } - } else iq[i] = 0xffffff - j; - } - if(q0>0) { /* rare case: chance is 1 in 12 */ - switch(q0) { - case 1: - iq[jz-1] &= 0x7fffff; break; - case 2: - iq[jz-1] &= 0x3fffff; break; - } - } - if(ih==2) { - z = one - z; - if(carry!=0) z -= scalbn(one,(int)q0); - } - } - - /* check if recomputation is needed */ - if(z==zero) { - j = 0; - for (i=jz-1;i>=jk;i--) j |= iq[i]; - if(j==0) { /* need recomputation */ - for(k=1;iq[jk-k]==0;k++); /* k = no. of terms needed */ - - for(i=jz+1;i<=jz+k;i++) { /* add q[jz+1] to q[jz+k] */ - f[jx+i] = (double) ipio2[jv+i]; - for(j=0,fw=0.0;j<=jx;j++) fw += x[j]*f[jx+i-j]; - q[i] = fw; - } - jz += k; - goto recompute; - } - } - - /* chop off zero terms */ - if(z==0.0) { - jz -= 1; q0 -= 24; - while(iq[jz]==0) { jz--; q0-=24;} - } else { /* break z into 24-bit if necessary */ - z = scalbn(z,-(int)q0); - if(z>=two24) { - fw = (double)((int32_t)(twon24*z)); - iq[jz] = (int32_t)(z-two24*fw); - jz += 1; q0 += 24; - iq[jz] = (int32_t) fw; - } else iq[jz] = (int32_t) z ; - } - - /* convert integer "bit" chunk to floating-point value */ - fw = scalbn(one,(int)q0); - for(i=jz;i>=0;i--) { - q[i] = fw*(double)iq[i]; fw*=twon24; - } - - /* compute PIo2[0,...,jp]*q[jz,...,0] */ - for(i=jz;i>=0;i--) { - for(fw=0.0,k=0;k<=jp&&k<=jz-i;k++) fw += PIo2[k]*q[i+k]; - fq[jz-i] = fw; - } - - /* compress fq[] into y[] */ - switch(prec) { - case 0: - fw = 0.0; - for (i=jz;i>=0;i--) fw += fq[i]; - y[0] = (ih==0)? fw: -fw; - break; - case 1: - case 2: - fw = 0.0; - for (i=jz;i>=0;i--) fw += fq[i]; - y[0] = (ih==0)? fw: -fw; - fw = fq[0]-fw; - for (i=1;i<=jz;i++) fw += fq[i]; - y[1] = (ih==0)? fw: -fw; - break; - case 3: /* painful */ - for (i=jz;i>0;i--) { - fw = fq[i-1]+fq[i]; - fq[i] += fq[i-1]-fw; - fq[i-1] = fw; - } - for (i=jz;i>1;i--) { - fw = fq[i-1]+fq[i]; - fq[i] += fq[i-1]-fw; - fq[i-1] = fw; - } - for (fw=0.0,i=jz;i>=2;i--) fw += fq[i]; - if(ih==0) { - y[0] = fq[0]; y[1] = fq[1]; y[2] = fw; - } else { - y[0] = -fq[0]; y[1] = -fq[1]; y[2] = -fw; - } - } - return n&7; -} - -#endif /* defined(_DOUBLE_IS_32BITS) */ diff --git a/libjava/java/lang/k_sin.c b/libjava/java/lang/k_sin.c deleted file mode 100644 index b4ad387c589..00000000000 --- a/libjava/java/lang/k_sin.c +++ /dev/null @@ -1,79 +0,0 @@ - -/* @(#)k_sin.c 5.1 93/09/24 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* __kernel_sin( x, y, iy) - * kernel sin function on [-pi/4, pi/4], pi/4 ~ 0.7854 - * Input x is assumed to be bounded by ~pi/4 in magnitude. - * Input y is the tail of x. - * Input iy indicates whether y is 0. (if iy=0, y assume to be 0). - * - * Algorithm - * 1. Since sin(-x) = -sin(x), we need only to consider positive x. - * 2. if x < 2^-27 (hx<0x3e400000 0), return x with inexact if x!=0. - * 3. sin(x) is approximated by a polynomial of degree 13 on - * [0,pi/4] - * 3 13 - * sin(x) ~ x + S1*x + ... + S6*x - * where - * - * |sin(x) 2 4 6 8 10 12 | -58 - * |----- - (1+S1*x +S2*x +S3*x +S4*x +S5*x +S6*x )| <= 2 - * | x | - * - * 4. sin(x+y) = sin(x) + sin'(x')*y - * ~ sin(x) + (1-x*x/2)*y - * For better accuracy, let - * 3 2 2 2 2 - * r = x *(S2+x *(S3+x *(S4+x *(S5+x *S6)))) - * then 3 2 - * sin(x) = x + (S1*x + (x *(r-y/2)+y)) - */ - -#include "fdlibm.h" - -#ifndef _DOUBLE_IS_32BITS - -#ifdef __STDC__ -static const double -#else -static double -#endif -half = 5.00000000000000000000e-01, /* 0x3FE00000, 0x00000000 */ -S1 = -1.66666666666666324348e-01, /* 0xBFC55555, 0x55555549 */ -S2 = 8.33333333332248946124e-03, /* 0x3F811111, 0x1110F8A6 */ -S3 = -1.98412698298579493134e-04, /* 0xBF2A01A0, 0x19C161D5 */ -S4 = 2.75573137070700676789e-06, /* 0x3EC71DE3, 0x57B1FE7D */ -S5 = -2.50507602534068634195e-08, /* 0xBE5AE5E6, 0x8A2B9CEB */ -S6 = 1.58969099521155010221e-10; /* 0x3DE5D93A, 0x5ACFD57C */ - -#ifdef __STDC__ - double __kernel_sin(double x, double y, int iy) -#else - double __kernel_sin(x, y, iy) - double x,y; int iy; /* iy=0 if y is zero */ -#endif -{ - double z,r,v; - int32_t ix; - GET_HIGH_WORD(ix,x); - ix &= 0x7fffffff; /* high word of x */ - if(ix<0x3e400000) /* |x| < 2**-27 */ - {if((int)x==0) return x;} /* generate inexact */ - z = x*x; - v = z*x; - r = S2+z*(S3+z*(S4+z*(S5+z*S6))); - if(iy==0) return x+v*(S1+z*r); - else return x-((z*(half*y-v*r)-y)-v*S1); -} - -#endif /* defined(_DOUBLE_IS_32BITS) */ diff --git a/libjava/java/lang/k_tan.c b/libjava/java/lang/k_tan.c deleted file mode 100644 index a1067a70a0d..00000000000 --- a/libjava/java/lang/k_tan.c +++ /dev/null @@ -1,132 +0,0 @@ - -/* @(#)k_tan.c 5.1 93/09/24 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* __kernel_tan( x, y, k ) - * kernel tan function on [-pi/4, pi/4], pi/4 ~ 0.7854 - * Input x is assumed to be bounded by ~pi/4 in magnitude. - * Input y is the tail of x. - * Input k indicates whether tan (if k=1) or - * -1/tan (if k= -1) is returned. - * - * Algorithm - * 1. Since tan(-x) = -tan(x), we need only to consider positive x. - * 2. if x < 2^-28 (hx<0x3e300000 0), return x with inexact if x!=0. - * 3. tan(x) is approximated by a odd polynomial of degree 27 on - * [0,0.67434] - * 3 27 - * tan(x) ~ x + T1*x + ... + T13*x - * where - * - * |tan(x) 2 4 26 | -59.2 - * |----- - (1+T1*x +T2*x +.... +T13*x )| <= 2 - * | x | - * - * Note: tan(x+y) = tan(x) + tan'(x)*y - * ~ tan(x) + (1+x*x)*y - * Therefore, for better accuracy in computing tan(x+y), let - * 3 2 2 2 2 - * r = x *(T2+x *(T3+x *(...+x *(T12+x *T13)))) - * then - * 3 2 - * tan(x+y) = x + (T1*x + (x *(r+y)+y)) - * - * 4. For x in [0.67434,pi/4], let y = pi/4 - x, then - * tan(x) = tan(pi/4-y) = (1-tan(y))/(1+tan(y)) - * = 1 - 2*(tan(y) - (tan(y)^2)/(1+tan(y))) - */ - -#include "fdlibm.h" - -#ifndef _DOUBLE_IS_32BITS - -#ifdef __STDC__ -static const double -#else -static double -#endif -one = 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */ -pio4 = 7.85398163397448278999e-01, /* 0x3FE921FB, 0x54442D18 */ -pio4lo= 3.06161699786838301793e-17, /* 0x3C81A626, 0x33145C07 */ -T[] = { - 3.33333333333334091986e-01, /* 0x3FD55555, 0x55555563 */ - 1.33333333333201242699e-01, /* 0x3FC11111, 0x1110FE7A */ - 5.39682539762260521377e-02, /* 0x3FABA1BA, 0x1BB341FE */ - 2.18694882948595424599e-02, /* 0x3F9664F4, 0x8406D637 */ - 8.86323982359930005737e-03, /* 0x3F8226E3, 0xE96E8493 */ - 3.59207910759131235356e-03, /* 0x3F6D6D22, 0xC9560328 */ - 1.45620945432529025516e-03, /* 0x3F57DBC8, 0xFEE08315 */ - 5.88041240820264096874e-04, /* 0x3F4344D8, 0xF2F26501 */ - 2.46463134818469906812e-04, /* 0x3F3026F7, 0x1A8D1068 */ - 7.81794442939557092300e-05, /* 0x3F147E88, 0xA03792A6 */ - 7.14072491382608190305e-05, /* 0x3F12B80F, 0x32F0A7E9 */ - -1.85586374855275456654e-05, /* 0xBEF375CB, 0xDB605373 */ - 2.59073051863633712884e-05, /* 0x3EFB2A70, 0x74BF7AD4 */ -}; - -#ifdef __STDC__ - double __kernel_tan(double x, double y, int iy) -#else - double __kernel_tan(x, y, iy) - double x,y; int iy; -#endif -{ - double z,r,v,w,s; - int32_t ix,hx; - GET_HIGH_WORD(hx,x); - ix = hx&0x7fffffff; /* high word of |x| */ - if(ix<0x3e300000) /* x < 2**-28 */ - {if((int)x==0) { /* generate inexact */ - uint32_t low; - GET_LOW_WORD(low,x); - if(((ix|low)|(iy+1))==0) return one/fabs(x); - else return (iy==1)? x: -one/x; - } - } - if(ix>=0x3FE59428) { /* |x|>=0.6744 */ - if(hx<0) {x = -x; y = -y;} - z = pio4-x; - w = pio4lo-y; - x = z+w; y = 0.0; - } - z = x*x; - w = z*z; - /* Break x^5*(T[1]+x^2*T[2]+...) into - * x^5(T[1]+x^4*T[3]+...+x^20*T[11]) + - * x^5(x^2*(T[2]+x^4*T[4]+...+x^22*[T12])) - */ - r = T[1]+w*(T[3]+w*(T[5]+w*(T[7]+w*(T[9]+w*T[11])))); - v = z*(T[2]+w*(T[4]+w*(T[6]+w*(T[8]+w*(T[10]+w*T[12]))))); - s = z*x; - r = y + z*(s*(r+v)+y); - r += T[0]*s; - w = x+r; - if(ix>=0x3FE59428) { - v = (double)iy; - return (double)(1-((hx>>30)&2))*(v-2.0*(x-(w*w/(w+v)-r))); - } - if(iy==1) return w; - else { /* if allow error up to 2 ulp, - simply return -1.0/(x+r) here */ - /* compute -1.0/(x+r) accurately */ - double a,t; - z = w; - SET_LOW_WORD(z,0); - v = r-(z - x); /* z+v = r+x */ - t = a = -1.0/w; /* a = -1.0/w */ - SET_LOW_WORD(t,0); - s = 1.0+t*z; - return t+a*(s+t*v); - } -} - -#endif /* defined(_DOUBLE_IS_32BITS) */ diff --git a/libjava/java/lang/mprec.c b/libjava/java/lang/mprec.c deleted file mode 100644 index 00679ed3918..00000000000 --- a/libjava/java/lang/mprec.c +++ /dev/null @@ -1,958 +0,0 @@ -/**************************************************************** - * - * The author of this software is David M. Gay. - * - * Copyright (c) 1991 by AT&T. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose without fee is hereby granted, provided that this entire notice - * is included in all copies of any software which is or includes a copy - * or modification of this software and in all copies of the supporting - * documentation for such software. - * - * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED - * WARRANTY. IN PARTICULAR, NEITHER THE AUTHOR NOR AT&T MAKES ANY - * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY - * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. - * - ***************************************************************/ - -/* Please send bug reports to - David M. Gay - AT&T Bell Laboratories, Room 2C-463 - 600 Mountain Avenue - Murray Hill, NJ 07974-2070 - U.S.A. - dmg@research.att.com or research!dmg - */ - -/* strtod for IEEE-, VAX-, and IBM-arithmetic machines. - * - * This strtod returns a nearest machine number to the input decimal - * string (or sets errno to ERANGE). With IEEE arithmetic, ties are - * broken by the IEEE round-even rule. Otherwise ties are broken by - * biased rounding (add half and chop). - * - * Inspired loosely by William D. Clinger's paper "How to Read Floating - * Point Numbers Accurately" [Proc. ACM SIGPLAN '90, pp. 92-101]. - * - * Modifications: - * - * 1. We only require IEEE, IBM, or VAX double-precision - * arithmetic (not IEEE double-extended). - * 2. We get by with floating-point arithmetic in a case that - * Clinger missed -- when we're computing d * 10^n - * for a small integer d and the integer n is not too - * much larger than 22 (the maximum integer k for which - * we can represent 10^k exactly), we may be able to - * compute (d*10^k) * 10^(e-k) with just one roundoff. - * 3. Rather than a bit-at-a-time adjustment of the binary - * result in the hard case, we use floating-point - * arithmetic to determine the adjustment to within - * one bit; only in really hard cases do we need to - * compute a second residual. - * 4. Because of 3., we don't need a large table of powers of 10 - * for ten-to-e (just some small tables, e.g. of 10^k - * for 0 <= k <= 22). - */ - -/* - * #define IEEE_8087 for IEEE-arithmetic machines where the least - * significant byte has the lowest address. - * #define IEEE_MC68k for IEEE-arithmetic machines where the most - * significant byte has the lowest address. - * #define Sudden_Underflow for IEEE-format machines without gradual - * underflow (i.e., that flush to zero on underflow). - * #define IBM for IBM mainframe-style floating-point arithmetic. - * #define VAX for VAX-style floating-point arithmetic. - * #define Unsigned_Shifts if >> does treats its left operand as unsigned. - * #define No_leftright to omit left-right logic in fast floating-point - * computation of dtoa. - * #define Check_FLT_ROUNDS if FLT_ROUNDS can assume the values 2 or 3. - * #define RND_PRODQUOT to use rnd_prod and rnd_quot (assembly routines - * that use extended-precision instructions to compute rounded - * products and quotients) with IBM. - * #define ROUND_BIASED for IEEE-format with biased rounding. - * #define Inaccurate_Divide for IEEE-format with correctly rounded - * products but inaccurate quotients, e.g., for Intel i860. - * #define Just_16 to store 16 bits per 32-bit long when doing high-precision - * integer arithmetic. Whether this speeds things up or slows things - * down depends on the machine and the number being converted. - */ - -#include <stdlib.h> -#include <string.h> -#include <java-assert.h> -#include "mprec.h" - -/* reent.c knows this value */ -#define _Kmax 15 -#include <stdio.h> - -_Jv_Bigint * -_DEFUN (Balloc, (ptr, k), struct _Jv_reent *ptr _AND int k) -{ - _Jv_Bigint *rv = NULL; - - int i = 0; - int j = 1; - - JvAssert ((1 << k) < MAX_BIGNUM_WDS); - - while ((ptr->_allocation_map & j) && i < MAX_BIGNUMS) - i++, j <<= 1; - - JvAssert (i < MAX_BIGNUMS); - - if (i >= MAX_BIGNUMS) - return NULL; - - ptr->_allocation_map |= j; - rv = &ptr->_freelist[i]; - - rv->_k = k; - rv->_maxwds = 32; - - return rv; -} - - -void -_DEFUN (Bfree, (ptr, v), struct _Jv_reent *ptr _AND _Jv_Bigint * v) -{ - long i; - - i = v - ptr->_freelist; - - JvAssert (i >= 0 && i < MAX_BIGNUMS); - - if (i >= 0 && i < MAX_BIGNUMS) - ptr->_allocation_map &= ~ (1 << i); -} - - -_Jv_Bigint * -_DEFUN (multadd, (ptr, b, m, a), - struct _Jv_reent *ptr _AND - _Jv_Bigint * b _AND - int m _AND - int a) -{ - int i, wds; - unsigned long *x, y; -#ifdef Pack_32 - unsigned long xi, z; -#endif - _Jv_Bigint *b1; - - wds = b->_wds; - x = b->_x; - i = 0; - do - { -#ifdef Pack_32 - xi = *x; - y = (xi & 0xffff) * m + a; - z = (xi >> 16) * m + (y >> 16); - a = (int) (z >> 16); - *x++ = (z << 16) + (y & 0xffff); -#else - y = *x * m + a; - a = (int) (y >> 16); - *x++ = y & 0xffff; -#endif - } - while (++i < wds); - if (a) - { - if (wds >= b->_maxwds) - { - b1 = Balloc (ptr, b->_k + 1); - Bcopy (b1, b); - Bfree (ptr, b); - b = b1; - } - b->_x[wds++] = a; - b->_wds = wds; - } - return b; -} - -_Jv_Bigint * -_DEFUN (s2b, (ptr, s, nd0, nd, y9), - struct _Jv_reent * ptr _AND - _CONST char *s _AND - int nd0 _AND - int nd _AND - unsigned long y9) -{ - _Jv_Bigint *b; - int i, k; - long x, y; - - x = (nd + 8) / 9; - for (k = 0, y = 1; x > y; y <<= 1, k++); -#ifdef Pack_32 - b = Balloc (ptr, k); - b->_x[0] = y9; - b->_wds = 1; -#else - b = Balloc (ptr, k + 1); - b->_x[0] = y9 & 0xffff; - b->_wds = (b->_x[1] = y9 >> 16) ? 2 : 1; -#endif - - i = 9; - if (9 < nd0) - { - s += 9; - do - b = multadd (ptr, b, 10, *s++ - '0'); - while (++i < nd0); - s++; - } - else - s += 10; - for (; i < nd; i++) - b = multadd (ptr, b, 10, *s++ - '0'); - return b; -} - -int -_DEFUN (hi0bits, - (x), register unsigned long x) -{ - register int k = 0; - - if (!(x & 0xffff0000)) - { - k = 16; - x <<= 16; - } - if (!(x & 0xff000000)) - { - k += 8; - x <<= 8; - } - if (!(x & 0xf0000000)) - { - k += 4; - x <<= 4; - } - if (!(x & 0xc0000000)) - { - k += 2; - x <<= 2; - } - if (!(x & 0x80000000)) - { - k++; - if (!(x & 0x40000000)) - return 32; - } - return k; -} - -int -_DEFUN (lo0bits, (y), unsigned long *y) -{ - register int k; - register unsigned long x = *y; - - if (x & 7) - { - if (x & 1) - return 0; - if (x & 2) - { - *y = x >> 1; - return 1; - } - *y = x >> 2; - return 2; - } - k = 0; - if (!(x & 0xffff)) - { - k = 16; - x >>= 16; - } - if (!(x & 0xff)) - { - k += 8; - x >>= 8; - } - if (!(x & 0xf)) - { - k += 4; - x >>= 4; - } - if (!(x & 0x3)) - { - k += 2; - x >>= 2; - } - if (!(x & 1)) - { - k++; - x >>= 1; - if (!(x & 1)) - return 32; - } - *y = x; - return k; -} - -_Jv_Bigint * -_DEFUN (i2b, (ptr, i), struct _Jv_reent * ptr _AND int i) -{ - _Jv_Bigint *b; - - b = Balloc (ptr, 1); - b->_x[0] = i; - b->_wds = 1; - return b; -} - -_Jv_Bigint * -_DEFUN (mult, (ptr, a, b), struct _Jv_reent * ptr _AND _Jv_Bigint * a _AND _Jv_Bigint * b) -{ - _Jv_Bigint *c; - int k, wa, wb, wc; - unsigned long carry, y, z; - unsigned long *x, *xa, *xae, *xb, *xbe, *xc, *xc0; -#ifdef Pack_32 - unsigned long z2; -#endif - - if (a->_wds < b->_wds) - { - c = a; - a = b; - b = c; - } - k = a->_k; - wa = a->_wds; - wb = b->_wds; - wc = wa + wb; - if (wc > a->_maxwds) - k++; - c = Balloc (ptr, k); - for (x = c->_x, xa = x + wc; x < xa; x++) - *x = 0; - xa = a->_x; - xae = xa + wa; - xb = b->_x; - xbe = xb + wb; - xc0 = c->_x; -#ifdef Pack_32 - for (; xb < xbe; xb++, xc0++) - { - if ((y = *xb & 0xffff)) - { - x = xa; - xc = xc0; - carry = 0; - do - { - z = (*x & 0xffff) * y + (*xc & 0xffff) + carry; - carry = z >> 16; - z2 = (*x++ >> 16) * y + (*xc >> 16) + carry; - carry = z2 >> 16; - Storeinc (xc, z2, z); - } - while (x < xae); - *xc = carry; - } - if ((y = *xb >> 16)) - { - x = xa; - xc = xc0; - carry = 0; - z2 = *xc; - do - { - z = (*x & 0xffff) * y + (*xc >> 16) + carry; - carry = z >> 16; - Storeinc (xc, z, z2); - z2 = (*x++ >> 16) * y + (*xc & 0xffff) + carry; - carry = z2 >> 16; - } - while (x < xae); - *xc = z2; - } - } -#else - for (; xb < xbe; xc0++) - { - if ((y = *xb++)) - { - x = xa; - xc = xc0; - carry = 0; - do - { - z = *x++ * y + *xc + carry; - carry = z >> 16; - *xc++ = z & 0xffff; - } - while (x < xae); - *xc = carry; - } - } -#endif - for (xc0 = c->_x, xc = xc0 + wc; wc > 0 && !*--xc; --wc); - c->_wds = wc; - return c; -} - -_Jv_Bigint * -_DEFUN (pow5mult, - (ptr, b, k), struct _Jv_reent * ptr _AND _Jv_Bigint * b _AND int k) -{ - _Jv_Bigint *b1, *p5, *p51; - int i; - static _CONST int p05[3] = {5, 25, 125}; - - if ((i = k & 3)) - b = multadd (ptr, b, p05[i - 1], 0); - - if (!(k >>= 2)) - return b; - if (!(p5 = ptr->_p5s)) - { - /* first time */ - p5 = ptr->_p5s = i2b (ptr, 625); - p5->_next = 0; - } - for (;;) - { - if (k & 1) - { - b1 = mult (ptr, b, p5); - Bfree (ptr, b); - b = b1; - } - if (!(k >>= 1)) - break; - if (!(p51 = p5->_next)) - { - p51 = p5->_next = mult (ptr, p5, p5); - p51->_next = 0; - } - p5 = p51; - } - return b; -} - -_Jv_Bigint * -_DEFUN (lshift, (ptr, b, k), struct _Jv_reent * ptr _AND _Jv_Bigint * b _AND int k) -{ - int i, k1, n, n1; - _Jv_Bigint *b1; - unsigned long *x, *x1, *xe, z; - -#ifdef Pack_32 - n = k >> 5; -#else - n = k >> 4; -#endif - k1 = b->_k; - n1 = n + b->_wds + 1; - for (i = b->_maxwds; n1 > i; i <<= 1) - k1++; - b1 = Balloc (ptr, k1); - x1 = b1->_x; - for (i = 0; i < n; i++) - *x1++ = 0; - x = b->_x; - xe = x + b->_wds; -#ifdef Pack_32 - if (k &= 0x1f) - { - k1 = 32 - k; - z = 0; - do - { - *x1++ = *x << k | z; - z = *x++ >> k1; - } - while (x < xe); - if ((*x1 = z)) - ++n1; - } -#else - if (k &= 0xf) - { - k1 = 16 - k; - z = 0; - do - { - *x1++ = (*x << k & 0xffff) | z; - z = *x++ >> k1; - } - while (x < xe); - if ((*x1 = z)) - ++n1; - } -#endif - else - do - *x1++ = *x++; - while (x < xe); - b1->_wds = n1 - 1; - Bfree (ptr, b); - return b1; -} - -int -_DEFUN (cmp, (a, b), _Jv_Bigint * a _AND _Jv_Bigint * b) -{ - unsigned long *xa, *xa0, *xb, *xb0; - int i, j; - - i = a->_wds; - j = b->_wds; -#ifdef DEBUG - if (i > 1 && !a->_x[i - 1]) - Bug ("cmp called with a->_x[a->_wds-1] == 0"); - if (j > 1 && !b->_x[j - 1]) - Bug ("cmp called with b->_x[b->_wds-1] == 0"); -#endif - if (i -= j) - return i; - xa0 = a->_x; - xa = xa0 + j; - xb0 = b->_x; - xb = xb0 + j; - for (;;) - { - if (*--xa != *--xb) - return *xa < *xb ? -1 : 1; - if (xa <= xa0) - break; - } - return 0; -} - -_Jv_Bigint * -_DEFUN (diff, (ptr, a, b), struct _Jv_reent * ptr _AND - _Jv_Bigint * a _AND _Jv_Bigint * b) -{ - _Jv_Bigint *c; - int i, wa, wb; - long borrow, y; /* We need signed shifts here. */ - unsigned long *xa, *xae, *xb, *xbe, *xc; -#ifdef Pack_32 - long z; -#endif - - i = cmp (a, b); - if (!i) - { - c = Balloc (ptr, 0); - c->_wds = 1; - c->_x[0] = 0; - return c; - } - if (i < 0) - { - c = a; - a = b; - b = c; - i = 1; - } - else - i = 0; - c = Balloc (ptr, a->_k); - c->_sign = i; - wa = a->_wds; - xa = a->_x; - xae = xa + wa; - wb = b->_wds; - xb = b->_x; - xbe = xb + wb; - xc = c->_x; - borrow = 0; -#ifdef Pack_32 - do - { - y = (*xa & 0xffff) - (*xb & 0xffff) + borrow; - borrow = y >> 16; - Sign_Extend (borrow, y); - z = (*xa++ >> 16) - (*xb++ >> 16) + borrow; - borrow = z >> 16; - Sign_Extend (borrow, z); - Storeinc (xc, z, y); - } - while (xb < xbe); - while (xa < xae) - { - y = (*xa & 0xffff) + borrow; - borrow = y >> 16; - Sign_Extend (borrow, y); - z = (*xa++ >> 16) + borrow; - borrow = z >> 16; - Sign_Extend (borrow, z); - Storeinc (xc, z, y); - } -#else - do - { - y = *xa++ - *xb++ + borrow; - borrow = y >> 16; - Sign_Extend (borrow, y); - *xc++ = y & 0xffff; - } - while (xb < xbe); - while (xa < xae) - { - y = *xa++ + borrow; - borrow = y >> 16; - Sign_Extend (borrow, y); - *xc++ = y & 0xffff; - } -#endif - while (!*--xc) - wa--; - c->_wds = wa; - return c; -} - -double -_DEFUN (ulp, (_x), double _x) -{ - union double_union x, a; - register long L; - - x.d = _x; - - L = (word0 (x) & Exp_mask) - (P - 1) * Exp_msk1; -#ifndef Sudden_Underflow - if (L > 0) - { -#endif -#ifdef IBM - L |= Exp_msk1 >> 4; -#endif - word0 (a) = L; -#ifndef _DOUBLE_IS_32BITS - word1 (a) = 0; -#endif - -#ifndef Sudden_Underflow - } - else - { - L = -L >> Exp_shift; - if (L < Exp_shift) - { - word0 (a) = 0x80000 >> L; -#ifndef _DOUBLE_IS_32BITS - word1 (a) = 0; -#endif - } - else - { - word0 (a) = 0; - L -= Exp_shift; -#ifndef _DOUBLE_IS_32BITS - word1 (a) = L >= 31 ? 1 : 1 << (31 - L); -#endif - } - } -#endif - return a.d; -} - -double -_DEFUN (b2d, (a, e), - _Jv_Bigint * a _AND int *e) -{ - unsigned long *xa, *xa0, w, y, z; - int k; - union double_union d; -#ifdef VAX - unsigned long d0, d1; -#else -#define d0 word0(d) -#define d1 word1(d) -#endif - - xa0 = a->_x; - xa = xa0 + a->_wds; - y = *--xa; -#ifdef DEBUG - if (!y) - Bug ("zero y in b2d"); -#endif - k = hi0bits (y); - *e = 32 - k; -#ifdef Pack_32 - if (k < Ebits) - { - d0 = Exp_1 | y >> (Ebits - k); - w = xa > xa0 ? *--xa : 0; -#ifndef _DOUBLE_IS_32BITS - d1 = y << (32 - Ebits + k) | w >> (Ebits - k); -#endif - goto ret_d; - } - z = xa > xa0 ? *--xa : 0; - if (k -= Ebits) - { - d0 = Exp_1 | y << k | z >> (32 - k); - y = xa > xa0 ? *--xa : 0; -#ifndef _DOUBLE_IS_32BITS - d1 = z << k | y >> (32 - k); -#endif - } - else - { - d0 = Exp_1 | y; -#ifndef _DOUBLE_IS_32BITS - d1 = z; -#endif - } -#else - if (k < Ebits + 16) - { - z = xa > xa0 ? *--xa : 0; - d0 = Exp_1 | y << (k - Ebits) | z >> (Ebits + 16 - k); - w = xa > xa0 ? *--xa : 0; - y = xa > xa0 ? *--xa : 0; - d1 = z << (k + 16 - Ebits) | w << (k - Ebits) | y >> (16 + Ebits - k); - goto ret_d; - } - z = xa > xa0 ? *--xa : 0; - w = xa > xa0 ? *--xa : 0; - k -= Ebits + 16; - d0 = Exp_1 | y << (k + 16) | z << k | w >> (16 - k); - y = xa > xa0 ? *--xa : 0; - d1 = w << (k + 16) | y << k; -#endif -ret_d: -#ifdef VAX - word0 (d) = d0 >> 16 | d0 << 16; - word1 (d) = d1 >> 16 | d1 << 16; -#else -#undef d0 -#undef d1 -#endif - return d.d; -} - -_Jv_Bigint * -_DEFUN (d2b, - (ptr, _d, e, bits), - struct _Jv_reent * ptr _AND - double _d _AND - int *e _AND - int *bits) - -{ - union double_union d; - _Jv_Bigint *b; - int de, i, k; - unsigned long *x, y, z; -#ifdef VAX - unsigned long d0, d1; - d.d = _d; - d0 = word0 (d) >> 16 | word0 (d) << 16; - d1 = word1 (d) >> 16 | word1 (d) << 16; -#else -#define d0 word0(d) -#define d1 word1(d) - d.d = _d; -#endif - -#ifdef Pack_32 - b = Balloc (ptr, 1); -#else - b = Balloc (ptr, 2); -#endif - x = b->_x; - - z = d0 & Frac_mask; - d0 &= 0x7fffffff; /* clear sign bit, which we ignore */ -#ifdef Sudden_Underflow - de = (int) (d0 >> Exp_shift); -#ifndef IBM - z |= Exp_msk11; -#endif -#else - if ((de = (int) (d0 >> Exp_shift))) - z |= Exp_msk1; -#endif -#ifdef Pack_32 -#ifndef _DOUBLE_IS_32BITS - if ((y = d1)) - { - if ((k = lo0bits (&y))) - { - x[0] = y | z << (32 - k); - z >>= k; - } - else - x[0] = y; - i = b->_wds = (x[1] = z) ? 2 : 1; - } - else -#endif - { -#ifdef DEBUG - if (!z) - Bug ("Zero passed to d2b"); -#endif - k = lo0bits (&z); - x[0] = z; - i = b->_wds = 1; -#ifndef _DOUBLE_IS_32BITS - k += 32; -#endif - } -#else - if ((y = d1)) - { - if ((k = lo0bits (&y))) - if (k >= 16) - { - x[0] = y | (z << (32 - k) & 0xffff); - x[1] = z >> (k - 16) & 0xffff; - x[2] = z >> k; - i = 2; - } - else - { - x[0] = y & 0xffff; - x[1] = (y >> 16 | z << (16 - k)) & 0xffff; - x[2] = z >> k & 0xffff; - x[3] = z >> (k + 16); - i = 3; - } - else - { - x[0] = y & 0xffff; - x[1] = y >> 16; - x[2] = z & 0xffff; - x[3] = z >> 16; - i = 3; - } - } - else - { -#ifdef DEBUG - if (!z) - Bug ("Zero passed to d2b"); -#endif - k = lo0bits (&z); - if (k >= 16) - { - x[0] = z; - i = 0; - } - else - { - x[0] = z & 0xffff; - x[1] = z >> 16; - i = 1; - } - k += 32; - } - while (!x[i]) - --i; - b->_wds = i + 1; -#endif -#ifndef Sudden_Underflow - if (de) - { -#endif -#ifdef IBM - *e = (de - Bias - (P - 1) << 2) + k; - *bits = 4 * P + 8 - k - hi0bits (word0 (d) & Frac_mask); -#else - *e = de - Bias - (P - 1) + k; - *bits = P - k; -#endif -#ifndef Sudden_Underflow - } - else - { - *e = de - Bias - (P - 1) + 1 + k; -#ifdef Pack_32 - *bits = 32 * i - hi0bits (x[i - 1]); -#else - *bits = (i + 2) * 16 - hi0bits (x[i]); -#endif - } -#endif - return b; -} -#undef d0 -#undef d1 - -double -_DEFUN (ratio, (a, b), _Jv_Bigint * a _AND _Jv_Bigint * b) - -{ - union double_union da, db; - int k, ka, kb; - - da.d = b2d (a, &ka); - db.d = b2d (b, &kb); -#ifdef Pack_32 - k = ka - kb + 32 * (a->_wds - b->_wds); -#else - k = ka - kb + 16 * (a->_wds - b->_wds); -#endif -#ifdef IBM - if (k > 0) - { - word0 (da) += (k >> 2) * Exp_msk1; - if (k &= 3) - da.d *= 1 << k; - } - else - { - k = -k; - word0 (db) += (k >> 2) * Exp_msk1; - if (k &= 3) - db.d *= 1 << k; - } -#else - if (k > 0) - word0 (da) += k * Exp_msk1; - else - { - k = -k; - word0 (db) += k * Exp_msk1; - } -#endif - return da.d / db.d; -} - - -_CONST double - tens[] = -{ - 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, - 1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19, - 1e20, 1e21, 1e22, 1e23, 1e24 - -}; - -#if !defined(_DOUBLE_IS_32BITS) && !defined(__v800) -_CONST double bigtens[] = -{1e16, 1e32, 1e64, 1e128, 1e256}; - -_CONST double tinytens[] = -{1e-16, 1e-32, 1e-64, 1e-128, 1e-256}; -#else -_CONST double bigtens[] = -{1e16, 1e32}; - -_CONST double tinytens[] = -{1e-16, 1e-32}; -#endif - - diff --git a/libjava/java/lang/mprec.h b/libjava/java/lang/mprec.h deleted file mode 100644 index 26472a2278b..00000000000 --- a/libjava/java/lang/mprec.h +++ /dev/null @@ -1,397 +0,0 @@ -/**************************************************************** - * - * The author of this software is David M. Gay. - * - * Copyright (c) 1991, 2000 by AT&T. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose without fee is hereby granted, provided that this entire notice - * is included in all copies of any software which is or includes a copy - * or modification of this software and in all copies of the supporting - * documentation for such software. - * - * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED - * WARRANTY. IN PARTICULAR, NEITHER THE AUTHOR NOR AT&T MAKES ANY - * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY - * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. - * - ***************************************************************/ - -/* Please send bug reports to - David M. Gay - AT&T Bell Laboratories, Room 2C-463 - 600 Mountain Avenue - Murray Hill, NJ 07974-2070 - U.S.A. - dmg@research.att.com or research!dmg - */ - -#include <config.h> -#include "ieeefp.h" - -#if defined HAVE_STDINT_H -#include <stdint.h> -#elif defined HAVE_INTTYPES_H -#include <inttypes.h> -#endif - -#if defined HAVE_SYS_TYPES_H -#include <sys/types.h> -#endif - -#if defined HAVE_SYS_CONFIG_H -#include <sys/config.h> -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -/* ISO C99 int type declarations */ - -#if !defined HAVE_INT32_DEFINED && defined HAVE_BSD_INT32_DEFINED -typedef u_int32_t uint32_t; -#endif - -#if !defined HAVE_BSD_INT32_DEFINED && !defined HAVE_INT32_DEFINED -/* FIXME this could have problems with systems that don't define SI to be 4 */ -typedef int int32_t __attribute__((mode(SI))); - -/* This is a blatant hack: on Solaris 2.5, pthread.h defines uint32_t - in pthread.h, which we sometimes include. We protect our - definition the same way Solaris 2.5 does, to avoid redefining it. */ -# ifndef _UINT32_T -typedef unsigned int uint32_t __attribute__((mode(SI))); -# endif -#endif - - /* These typedefs are true for the targets running Java. */ - -#ifdef __IEEE_LITTLE_ENDIAN -#define IEEE_8087 -#endif - -#ifdef __IEEE_BIG_ENDIAN -#define IEEE_MC68k -#endif - -#ifdef __Z8000__ -#define Just_16 -#endif - -#ifdef DEBUG -#include "stdio.h" -#define Bug(x) {fprintf(stderr, "%s\n", x); exit(1);} -#endif - - -#ifdef Unsigned_Shifts -#define Sign_Extend(a,b) if (b < 0) a |= (uint32_t)0xffff0000; -#else -#define Sign_Extend(a,b) /*no-op*/ -#endif - -#if defined(IEEE_8087) + defined(IEEE_MC68k) + defined(VAX) + defined(IBM) != 1 -Exactly one of IEEE_8087, IEEE_MC68k, VAX, or IBM should be defined. -#endif - -/* If we are going to examine or modify specific bits in a double using - the word0 and/or word1 macros, then we must wrap the double inside - a union. This is necessary to avoid undefined behavior according to - the ANSI C spec. */ -union double_union -{ - double d; - uint32_t i[2]; -}; - -#ifdef IEEE_8087 -#define word0(x) (x.i[1]) -#define word1(x) (x.i[0]) -#else -#define word0(x) (x.i[0]) -#define word1(x) (x.i[1]) -#endif - -/* The following definition of Storeinc is appropriate for MIPS processors. - * An alternative that might be better on some machines is - * #define Storeinc(a,b,c) (*a++ = b << 16 | c & 0xffff) - */ -#if defined(IEEE_8087) + defined(VAX) -#define Storeinc(a,b,c) (((unsigned short *)a)[1] = (unsigned short)b, \ -((unsigned short *)a)[0] = (unsigned short)c, a++) -#else -#define Storeinc(a,b,c) (((unsigned short *)a)[0] = (unsigned short)b, \ -((unsigned short *)a)[1] = (unsigned short)c, a++) -#endif - -/* #define P DBL_MANT_DIG */ -/* Ten_pmax = floor(P*log(2)/log(5)) */ -/* Bletch = (highest power of 2 < DBL_MAX_10_EXP) / 16 */ -/* Quick_max = floor((P-1)*log(FLT_RADIX)/log(10) - 1) */ -/* Int_max = floor(P*log(FLT_RADIX)/log(10) - 1) */ - -#if defined(IEEE_8087) + defined(IEEE_MC68k) -#if defined (_DOUBLE_IS_32BITS) -#define Exp_shift 23 -#define Exp_shift1 23 -#define Exp_msk1 ((uint32_t)0x00800000L) -#define Exp_msk11 ((uint32_t)0x00800000L) -#define Exp_mask ((uint32_t)0x7f800000L) -#define P 24 -#define Bias 127 -#if 0 -#define IEEE_Arith /* it is, but the code doesn't handle IEEE singles yet */ -#endif -#define Emin (-126) -#define Exp_1 ((uint32_t)0x3f800000L) -#define Exp_11 ((uint32_t)0x3f800000L) -#define Ebits 8 -#define Frac_mask ((uint32_t)0x007fffffL) -#define Frac_mask1 ((uint32_t)0x007fffffL) -#define Ten_pmax 10 -#define Sign_bit ((uint32_t)0x80000000L) -#define Ten_pmax 10 -#define Bletch 2 -#define Bndry_mask ((uint32_t)0x007fffffL) -#define Bndry_mask1 ((uint32_t)0x007fffffL) -#define LSB 1 -#define Sign_bit ((uint32_t)0x80000000L) -#define Log2P 1 -#define Tiny0 0 -#define Tiny1 1 -#define Quick_max 5 -#define Int_max 6 -#define Infinite(x) (word0(x) == ((uint32_t)0x7f800000L)) -#undef word0 -#undef word1 - -#define word0(x) (x.i[0]) -#define word1(x) 0 -#else - -#define Exp_shift 20 -#define Exp_shift1 20 -#define Exp_msk1 ((uint32_t)0x100000L) -#define Exp_msk11 ((uint32_t)0x100000L) -#define Exp_mask ((uint32_t)0x7ff00000L) -#define P 53 -#define Bias 1023 -#define IEEE_Arith -#define Emin (-1022) -#define Exp_1 ((uint32_t)0x3ff00000L) -#define Exp_11 ((uint32_t)0x3ff00000L) -#define Ebits 11 -#define Frac_mask ((uint32_t)0xfffffL) -#define Frac_mask1 ((uint32_t)0xfffffL) -#define Ten_pmax 22 -#define Bletch 0x10 -#define Bndry_mask ((uint32_t)0xfffffL) -#define Bndry_mask1 ((uint32_t)0xfffffL) -#define LSB 1 -#define Sign_bit ((uint32_t)0x80000000L) -#define Log2P 1 -#define Tiny0 0 -#define Tiny1 1 -#define Quick_max 14 -#define Int_max 14 -#define Infinite(x) (word0(x) == ((uint32_t)0x7ff00000L)) /* sufficient test for here */ -#endif - -#else -#undef Sudden_Underflow -#define Sudden_Underflow -#ifdef IBM -#define Exp_shift 24 -#define Exp_shift1 24 -#define Exp_msk1 ((uint32_t)0x1000000L) -#define Exp_msk11 ((uint32_t)0x1000000L) -#define Exp_mask ((uint32_t)0x7f000000L) -#define P 14 -#define Bias 65 -#define Exp_1 ((uint32_t)0x41000000L) -#define Exp_11 ((uint32_t)0x41000000L) -#define Ebits 8 /* exponent has 7 bits, but 8 is the right value in b2d */ -#define Frac_mask ((uint32_t)0xffffffL) -#define Frac_mask1 ((uint32_t)0xffffffL) -#define Bletch 4 -#define Ten_pmax 22 -#define Bndry_mask ((uint32_t)0xefffffL) -#define Bndry_mask1 ((uint32_t)0xffffffL) -#define LSB 1 -#define Sign_bit ((uint32_t)0x80000000L) -#define Log2P 4 -#define Tiny0 ((uint32_t)0x100000L) -#define Tiny1 0 -#define Quick_max 14 -#define Int_max 15 -#else /* VAX */ -#define Exp_shift 23 -#define Exp_shift1 7 -#define Exp_msk1 0x80 -#define Exp_msk11 ((uint32_t)0x800000L) -#define Exp_mask ((uint32_t)0x7f80L) -#define P 56 -#define Bias 129 -#define Exp_1 ((uint32_t)0x40800000L) -#define Exp_11 ((uint32_t)0x4080L) -#define Ebits 8 -#define Frac_mask ((uint32_t)0x7fffffL) -#define Frac_mask1 ((uint32_t)0xffff007fL) -#define Ten_pmax 24 -#define Bletch 2 -#define Bndry_mask ((uint32_t)0xffff007fL) -#define Bndry_mask1 ((uint32_t)0xffff007fL) -#define LSB ((uint32_t)0x10000L) -#define Sign_bit ((uint32_t)0x8000L) -#define Log2P 1 -#define Tiny0 0x80 -#define Tiny1 0 -#define Quick_max 15 -#define Int_max 15 -#endif -#endif - -#ifndef IEEE_Arith -#define ROUND_BIASED -#endif - -#ifdef RND_PRODQUOT -#define rounded_product(a,b) a = rnd_prod(a, b) -#define rounded_quotient(a,b) a = rnd_quot(a, b) -#ifdef KR_headers -extern double rnd_prod(), rnd_quot(); -#else -extern double rnd_prod(double, double), rnd_quot(double, double); -#endif -#else -#define rounded_product(a,b) a *= b -#define rounded_quotient(a,b) a /= b -#endif - -#define Big0 (Frac_mask1 | Exp_msk1*(DBL_MAX_EXP+Bias-1)) -#define Big1 ((uint32_t)0xffffffffL) - -#ifndef Just_16 -/* When Pack_32 is not defined, we store 16 bits per 32-bit long. - * This makes some inner loops simpler and sometimes saves work - * during multiplications, but it often seems to make things slightly - * slower. Hence the default is now to store 32 bits per long. - */ - -#ifndef Pack_32 -#if SIZEOF_VOID_P != 8 -#define Pack_32 -#endif -#endif -#endif - - -#define MAX_BIGNUMS 16 -#define MAX_BIGNUM_WDS 32 - -struct _Jv_Bigint -{ - struct _Jv_Bigint *_next; - int _k, _maxwds, _sign, _wds; - unsigned long _x[MAX_BIGNUM_WDS]; -}; - - -#define _PTR void * -#define _AND , -#define _NOARGS void -#define _CONST const -#define _VOLATILE volatile -#define _SIGNED signed -#define _DOTS , ... -#define _VOID void -#define _EXFUN(name, proto) name proto -#define _DEFUN(name, arglist, args) name(args) -#define _DEFUN_VOID(name) name(_NOARGS) -#define _CAST_VOID (void) - - -struct _Jv_reent -{ - /* local copy of errno */ - int _errno; - - /* used by mprec routines */ - struct _Jv_Bigint *_result; - int _result_k; - struct _Jv_Bigint *_p5s; - - struct _Jv_Bigint _freelist[MAX_BIGNUMS]; - int _allocation_map; - - int num; -}; - - -typedef struct _Jv_Bigint _Jv_Bigint; - -#define Balloc _Jv_Balloc -#define Bfree _Jv_Bfree -#define multadd _Jv_multadd -#define s2b _Jv_s2b -#define lo0bits _Jv_lo0bits -#define hi0bits _Jv_hi0bits -#define i2b _Jv_i2b -#define mult _Jv_mult -#define pow5mult _Jv_pow5mult -#define lshift _Jv_lshift -#define cmp _Jv__mcmp -#define diff _Jv__mdiff -#define ulp _Jv_ulp -#define b2d _Jv_b2d -#define d2b _Jv_d2b -#define ratio _Jv_ratio - -#define tens _Jv__mprec_tens -#define bigtens _Jv__mprec_bigtens -#define tinytens _Jv__mprec_tinytens - -#define _dtoa _Jv_dtoa -#define _dtoa_r _Jv_dtoa_r -#define _strtod_r _Jv_strtod_r - -extern double _EXFUN(_strtod_r, (struct _Jv_reent *ptr, const char *s00, char **se)); -extern char* _EXFUN(_dtoa_r, (struct _Jv_reent *ptr, double d, - int mode, int ndigits, int *decpt, int *sign, - char **rve, int float_type)); -void _EXFUN(_dtoa, (double d, int mode, int ndigits, int *decpt, int *sign, - char **rve, char *buf, int float_type)); - -double _EXFUN(ulp,(double x)); -double _EXFUN(b2d,(_Jv_Bigint *a , int *e)); -_Jv_Bigint * _EXFUN(Balloc,(struct _Jv_reent *p, int k)); -void _EXFUN(Bfree,(struct _Jv_reent *p, _Jv_Bigint *v)); -_Jv_Bigint * _EXFUN(multadd,(struct _Jv_reent *p, _Jv_Bigint *, int, int)); -_Jv_Bigint * _EXFUN(s2b,(struct _Jv_reent *, const char*, int, int, unsigned long)); -_Jv_Bigint * _EXFUN(i2b,(struct _Jv_reent *,int)); -_Jv_Bigint * _EXFUN(mult, (struct _Jv_reent *, _Jv_Bigint *, _Jv_Bigint *)); -_Jv_Bigint * _EXFUN(pow5mult, (struct _Jv_reent *, _Jv_Bigint *, int k)); -int _EXFUN(hi0bits,(unsigned long)); -int _EXFUN(lo0bits,(unsigned long *)); -_Jv_Bigint * _EXFUN(d2b,(struct _Jv_reent *p, double d, int *e, int *bits)); -_Jv_Bigint * _EXFUN(lshift,(struct _Jv_reent *p, _Jv_Bigint *b, int k)); -_Jv_Bigint * _EXFUN(diff,(struct _Jv_reent *p, _Jv_Bigint *a, _Jv_Bigint *b)); -int _EXFUN(cmp,(_Jv_Bigint *a, _Jv_Bigint *b)); - -double _EXFUN(ratio,(_Jv_Bigint *a, _Jv_Bigint *b)); -#define Bcopy(x,y) memcpy((char *)&x->_sign, (char *)&y->_sign, y->_wds*sizeof(long) + 2*sizeof(int)) - -#if defined(_DOUBLE_IS_32BITS) && defined(__v800) -#define n_bigtens 2 -#else -#define n_bigtens 5 -#endif - -extern _CONST double tinytens[]; -extern _CONST double bigtens[]; -extern _CONST double tens[]; - -#ifdef __cplusplus -} -#endif diff --git a/libjava/java/lang/ref/PhantomReference.java b/libjava/java/lang/ref/PhantomReference.java deleted file mode 100644 index 4d929c29c58..00000000000 --- a/libjava/java/lang/ref/PhantomReference.java +++ /dev/null @@ -1,73 +0,0 @@ -/* java.lang.ref.PhantomReference - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang.ref; - -/** - * A phantom reference is useful, to get notified, when an object got - * finalized. You can't access that object though, since it is - * finalized. This is the reason, why <code>get()</code> always - * returns null. - * - * @author Jochen Hoenicke - */ -public class PhantomReference - extends Reference -{ - /** - * Creates a new phantom reference. - * @param referent the object that should be watched. - * @param q the queue that should be notified, if the referent was - * finalized. This mustn't be <code>null</code>. - * @exception NullPointerException if q is null. - */ - public PhantomReference(Object referent, ReferenceQueue q) - { - super(referent, q); - } - - /** - * Returns the object, this reference refers to. - * @return <code>null</code>, since the refered object may be - * finalized and thus not accessible. - */ - public Object get() - { - return null; - } -} diff --git a/libjava/java/lang/ref/ReferenceQueue.java b/libjava/java/lang/ref/ReferenceQueue.java deleted file mode 100644 index f4729f282be..00000000000 --- a/libjava/java/lang/ref/ReferenceQueue.java +++ /dev/null @@ -1,145 +0,0 @@ -/* java.lang.ref.ReferenceQueue - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang.ref; - -/** - * This is the queue, where references can enqueue themselve on. Each - * reference may be registered to a queue at initialization time and - * will be appended to the queue, when the enqueue method is called. - * - * The enqueue method may be automatically called by the garbage - * collector if it detects, that the object is only reachable through - * the Reference objects. - * - * @author Jochen Hoenicke - * @see Reference#enqueue() - */ -public class ReferenceQueue -{ - /** - * This is a linked list of references. If this is null, the list is - * empty. Otherwise this points to the first reference on the queue. - * The first reference will point to the next reference via the - * <code>nextOnQueue</code> field. The last reference will point to - * itself (not to null, since <code>nextOnQueue</code> is used to - * determine if a reference is enqueued). - */ - private Reference first; - - /** - * Creates a new empty reference queue. - */ - public ReferenceQueue() - { - } - - /** - * Checks if there is a reference on the queue, returning it - * immediately. The reference will be dequeued. - * - * @return a reference on the queue, if there is one, - * <code>null</code> otherwise. - */ - public synchronized Reference poll() - { - return dequeue(); - } - - /** - * This is called by reference to enqueue itself on this queue. - * @param ref the reference that should be enqueued. - */ - synchronized void enqueue(Reference ref) - { - /* last reference will point to itself */ - ref.nextOnQueue = first == null ? ref : first; - first = ref; - /* this wakes only one remove thread. */ - notify(); - } - - /** - * Remove a reference from the queue, if there is one. - * @return the first element of the queue, or null if there isn't any. - */ - private Reference dequeue() - { - if (first == null) - return null; - - Reference result = first; - first = (first == first.nextOnQueue) ? null : first.nextOnQueue; - result.nextOnQueue = null; - return result; - } - - /** - * Removes a reference from the queue, blocking for <code>timeout</code> - * until a reference is enqueued. - * @param timeout the timeout period in milliseconds, <code>0</code> means - * wait forever. - * @return the reference removed from the queue, or - * <code>null</code> if timeout period expired. - * @exception InterruptedException if the wait was interrupted. - */ - public synchronized Reference remove(long timeout) - throws InterruptedException - { - if (first == null) - { - wait(timeout); - } - - return dequeue(); - } - - - /** - * Removes a reference from the queue, blocking until a reference is - * enqueued. - * - * @return the reference removed from the queue. - * @exception InterruptedException if the wait was interrupted. - */ - public Reference remove() - throws InterruptedException - { - return remove(0L); - } -} diff --git a/libjava/java/lang/ref/SoftReference.java b/libjava/java/lang/ref/SoftReference.java deleted file mode 100644 index 97395eacdfa..00000000000 --- a/libjava/java/lang/ref/SoftReference.java +++ /dev/null @@ -1,84 +0,0 @@ -/* java.lang.ref.SoftReference - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang.ref; - -/** - * A soft reference will be cleared, if the object is only softly - * reachable and the garbage collection needs more memory. The garbage - * collection will use an intelligent strategy to determine which soft - * references it should clear. This makes a soft reference ideal for - * caches.<br> - * - * @author Jochen Hoenicke - */ -public class SoftReference - extends Reference -{ - /** - * Create a new soft reference, that is not registered to any queue. - * @param referent the object we refer to. - */ - public SoftReference(Object referent) - { - super(referent); - } - - /** - * Create a new soft reference. - * @param referent the object we refer to. - * @param q the reference queue to register on. - * @exception NullPointerException if q is null. - */ - public SoftReference(Object referent, ReferenceQueue q) - { - super(referent, q); - } - - /** - * Returns the object, this reference refers to. - * @return the object, this reference refers to, or null if the - * reference was cleared. - */ - public Object get() - { - /* Why is this overloaded??? - * Maybe for a kind of LRU strategy. */ - return super.get(); - } -} diff --git a/libjava/java/lang/ref/WeakReference.java b/libjava/java/lang/ref/WeakReference.java deleted file mode 100644 index 9f758ca1eab..00000000000 --- a/libjava/java/lang/ref/WeakReference.java +++ /dev/null @@ -1,79 +0,0 @@ -/* java.lang.ref.WeakReference - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang.ref; - -/** - * A weak reference will be cleared, if the object is only weakly - * reachable. It is useful for lookup tables, where you aren't - * interested in an entry, if the key isn't reachable anymore. - * <code>WeakHashtable</code> is a complete implementation of such a - * table. <br> - * - * It is also useful to make objects unique: You create a set of weak - * references to those objects, and when you create a new object you - * look in this set, if the object already exists and return it. If - * an object is not referenced anymore, the reference will - * automatically cleared, and you may remove it from the set. <br> - * - * @author Jochen Hoenicke - * @see java.util.WeakHashtable - */ -public class WeakReference - extends Reference -{ - /** - * Create a new weak reference, that is not registered to any queue. - * @param referent the object we refer to. - */ - public WeakReference(Object referent) - { - super(referent); - } - - /** - * Create a new weak reference. - * @param referent the object we refer to. - * @param q the reference queue to register on. - * @exception NullPointerException if q is null. - */ - public WeakReference(Object referent, ReferenceQueue q) - { - super(referent, q); - } -} diff --git a/libjava/java/lang/reflect/AccessibleObject.java b/libjava/java/lang/reflect/AccessibleObject.java deleted file mode 100644 index 24418c971c7..00000000000 --- a/libjava/java/lang/reflect/AccessibleObject.java +++ /dev/null @@ -1,159 +0,0 @@ -/* java.lang.reflect.AccessibleObject - Copyright (C) 2001, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang.reflect; - -/** - * This class is the superclass of various reflection classes, and - * allows sufficiently trusted code to bypass normal restrictions to - * do necessary things like invoke private methods outside of the - * class during Serialization. If you don't have a good reason - * to mess with this, don't try. Fortunately, there are adequate - * security checks before you can set a reflection object as accessible. - * - * @author Tom Tromey (tromey@cygnus.com) - * @author Eric Blake (ebb9@email.byu.edu) - * @see Field - * @see Constructor - * @see Method - * @see ReflectPermission - * @since 1.2 - * @status updated to 1.4 - */ -public class AccessibleObject -{ - /** - * True if this object is marked accessible, which means the reflected - * object bypasses normal security checks. - */ - // default visibility for use by inherited classes - boolean flag = false; - - /** - * Only the three reflection classes that extend this can create an - * accessible object. This is not serializable for security reasons. - */ - protected AccessibleObject() - { - } - - /** - * Return the accessibility status of this object. - * - * @return true if this object bypasses security checks - */ - public boolean isAccessible() - { - return flag; - } - - /** - * Convenience method to set the flag on a number of objects with a single - * security check. If a security manager exists, it is checked for - * <code>ReflectPermission("suppressAccessChecks")</code>.<p> - * - * It is forbidden to set the accessibility flag to true on any constructor - * for java.lang.Class. This will result in a SecurityException. If the - * SecurityException is thrown for any of the passed AccessibleObjects, - * the accessibility flag will be set on AccessibleObjects in the array prior - * to the one which resulted in the exception. - * - * @param array the array of accessible objects - * @param flag the desired state of accessibility, true to bypass security - * @throws NullPointerException if array is null - * @throws SecurityException if the request is denied - * @see SecurityManager#checkPermission(java.security.Permission) - * @see RuntimePermission - */ - public static void setAccessible(AccessibleObject[] array, boolean flag) - { - checkPermission(); - for (int i = 0; i < array.length; i++) - array[i].secureSetAccessible(flag); - } - - /** - * Sets the accessibility flag for this reflection object. If a security - * manager exists, it is checked for - * <code>ReflectPermission("suppressAccessChecks")</code>.<p> - * - * It is forbidden to set the accessibility flag to true on any constructor for - * java.lang.Class. This will result in a SecurityException. - * - * @param flag the desired state of accessibility, true to bypass security - * @throws NullPointerException if array is null - * @throws SecurityException if the request is denied - * @see SecurityManager#checkPermission(java.security.Permission) - * @see RuntimePermission - */ - public void setAccessible(boolean flag) - { - checkPermission(); - secureSetAccessible(flag); - } - - /** - * Performs the specified security check, for - * <code>ReflectPermission("suppressAccessChecks")</code>. - * - * @throws SecurityException if permission is denied - */ - private static void checkPermission() - { - SecurityManager sm = System.getSecurityManager(); - if (sm != null) - sm.checkPermission(new ReflectPermission("suppressAccessChecks")); - } - - /** - * Performs the actual accessibility change, this must always be invoked - * after calling checkPermission. - * - * @param flag the desired status - * @throws SecurityException if flag is true and this is a constructor - * for <code>java.lang.Class</code>. - */ - private void secureSetAccessible(boolean flag) - { - if (flag && - (this instanceof Constructor - && ((Constructor) this).getDeclaringClass() == Class.class)) - throw new SecurityException("Cannot make object accessible: " + this); - this.flag = flag; - } -} diff --git a/libjava/java/lang/reflect/InvocationHandler.java b/libjava/java/lang/reflect/InvocationHandler.java deleted file mode 100644 index 208e621eedc..00000000000 --- a/libjava/java/lang/reflect/InvocationHandler.java +++ /dev/null @@ -1,137 +0,0 @@ -/* java.lang.reflect.InvocationHandler - dynamically executes methods in - proxy instances - Copyright (C) 2001 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang.reflect; - -/** - * This interface defines an invocation handler. Suppose you are using - * reflection, and found a method that requires that its parameter - * be an object of a given interface. You want to call this method, - * but have no idea what classes implement that interface. So, you can - * create a {@link Proxy} instance, a convenient way to dynamically - * generate a class that meets all the necessary properties of that - * interface. But in order for the proxy instance to do any good, it - * needs to know what to do when interface methods are invoked! So, - * this interface is basically a cool wrapper that provides runtime - * code generation needed by proxy instances. - * - * <p>While this interface was designed for use by Proxy, it will also - * work on any object in general.</p> - * - * <p>Hints for implementing this class:</p> - * - * <ul> - * <li>Don't forget that Object.equals, Object.hashCode, and - * Object.toString will call this handler. In particular, - * a naive call to proxy.equals, proxy.hashCode, or proxy.toString - * will put you in an infinite loop. And remember that string - * concatenation also invokes toString.</li> - * <li>Obey the contract of the Method object you are handling, or - * the proxy instance will be forced to throw a - * {@link NullPointerException}, {@link ClassCastException}, - * or {@link UndeclaredThrowableException}.</li> - * <li>Be prepared to wrap/unwrap primitives as necessary.</li> - * <li>The Method object may be owned by a different interface than - * what was actually used as the qualifying type of the method - * invocation in the Java source code. This means that it might - * not always be safe to throw an exception listed as belonging - * to the method's throws clause.</li> - * </ul> - * - * <p><small>For a fun time, create an InvocationHandler that handles the - * methods of a proxy instance of the InvocationHandler interface!</small></p> - * - * @see Proxy - * @see UndeclaredThrowableException - * - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.3 - * @status updated to 1.4 - */ -public interface InvocationHandler -{ - /** - * When a method is invoked on a proxy instance, it is wrapped and - * this method is called instead, so that you may decide at runtime - * how the original method should behave. - * - * @param proxy the instance that the wrapped method should be - * invoked on. When this method is called by a Proxy object, - * `proxy' will be an instance of {@link Proxy}, and oddly enough, - * <code>Proxy.getInvocationHandler(proxy)</code> will return - * <code>this</code>! - * @param method the reflected method to invoke on the proxy. - * When this method is called by a Proxy object, 'method' - * will be the reflection object owned by the declaring - * class or interface, which may be a supertype of the - * interfaces the proxy directly implements. - * @param args the arguments passed to the original method, or - * <code>null</code> if the method takes no arguments. - * (But also be prepared to handle a 0-length array). - * Arguments of primitive type, such as <code>boolean</code> - * or <code>int</code>, are wrapped in the appropriate - * class such as {@link Boolean} or {@link Integer}. - * @return whatever is necessary to return from the wrapped method. - * If the wrapped method is <code>void</code>, the proxy - * instance will ignore it. If the wrapped method returns - * a primitive, this must be the correct wrapper type whose value - * is exactly assignable to the appropriate type (no widening - * will be performed); a null object in this case causes a - * {@link NullPointerException}. In all remaining cases, if - * the returned object is not assignment compatible to the - * declared type of the original method, the proxy instance - * will generate a {@link ClassCastException}. - * @throws Throwable this interface is listed as throwing anything, - * but the implementation should only throw unchecked - * exceptions and exceptions listed in the throws clause of - * all methods being overridden by the proxy instance. If - * something is thrown that is not compatible with the throws - * clause of all overridden methods, the proxy instance will - * wrap the exception in an UndeclaredThrowableException. - * Note that an exception listed in the throws clause of the - * `method' parameter might not be declared in additional - * interfaces also implemented by the proxy object. - * - * @see Proxy - * @see UndeclaredThrowableException - */ - Object invoke(Object proxy, Method method, Object[] args) - throws Throwable; - -} diff --git a/libjava/java/lang/reflect/InvocationTargetException.java b/libjava/java/lang/reflect/InvocationTargetException.java deleted file mode 100644 index af79d3a199d..00000000000 --- a/libjava/java/lang/reflect/InvocationTargetException.java +++ /dev/null @@ -1,123 +0,0 @@ -/* InvocationTargetException.java -- Wrapper exception for reflection - Copyright (C) 1998, 1999, 2000, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang.reflect; - -/** - * InvocationTargetException is sort of a way to "wrap" whatever exception - * comes up when a method or constructor is called via Reflection. As of - * JDK 1.4, it was retrofitted to match the exception chaining of all other - * exceptions, but <code>getTargetException()</code> still works. - * - * @author John Keiser - * @author Tom Tromey (tromey@cygnus.com) - * @author Eric Blake (ebb9@email.byu.edu) - * @see Method#invoke(Object,Object[]) - * @see Constructor#newInstance(Object[]) - * @since 1.1 - * @status updated to 1.4 - */ -public class InvocationTargetException extends Exception -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = 4085088731926701167L; - - /** - * The chained exception. This field is only around for serial compatibility. - * - * @serial the chained exception - */ - private final Throwable target; - - /** - * Construct an exception with null as the cause. The cause is initialized - * to null. - */ - protected InvocationTargetException() - { - this(null, null); - } - - /** - * Create an <code>InvocationTargetException</code> using another - * exception. - * - * @param targetException the exception to wrap - */ - public InvocationTargetException(Throwable targetException) - { - this(targetException, null); - } - - /** - * Create an <code>InvocationTargetException</code> using another - * exception and an error message. - * - * @param targetException the exception to wrap - * @param err an extra reason for the exception-throwing - */ - public InvocationTargetException(Throwable targetException, String err) - { - super(err, targetException); - target = targetException; - } - - /** - * Get the wrapped (targeted) exception. - * - * @return the targeted exception - * @see #getCause() - */ - public Throwable getTargetException() - { - return target; - } - - /** - * Returns the cause of this exception (which may be null). - * - * @return the cause - * @since 1.4 - */ - public Throwable getCause() - { - return target; - } -} diff --git a/libjava/java/lang/reflect/Member.java b/libjava/java/lang/reflect/Member.java deleted file mode 100644 index 9983b275a94..00000000000 --- a/libjava/java/lang/reflect/Member.java +++ /dev/null @@ -1,100 +0,0 @@ -/* java.lang.reflect.Member - common query methods in reflection - Copyright (C) 1998, 1999, 2001, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang.reflect; - -/** - * Member is an interface that represents any member of a class (field or - * method) or a constructor. You can get information about the declaring - * class, name or modifiers of the member with this interface. - * - * @author John Keiser - * @author Per Bothner (bothner@cygnus.com) - * @author Eric Blake (ebb9@email.byu.edu) - * @see Class - * @see Field - * @see Method - * @see Constructor - * @since 1.1 - * @status updated to 1.4 - */ -public interface Member -{ - /** - * Represents all members, whether public, private, protected or - * package-protected, but only which are declared in this class. - * Used in SecurityManager.checkMemberAccess() to determine the - * type of members to access. - * @see SecurityManager#checkMemberAccess() - */ - int DECLARED = 1; - - /** - * Represents public members only, but includes all inherited members. - * Used in SecurityManager.checkMemberAccess() to determine the type of - * members to access. - * @see SecurityManager#checkMemberAccess() - */ - int PUBLIC = 0; - - /** - * Gets the class that declared this member. This is not the class where - * this method was called, or even the class where this Member object - * came to life, but the class that declares the member this represents. - * - * @return the class that declared this member - */ - Class getDeclaringClass(); - - /** - * Gets the simple name of this member. This will be a valid Java - * identifier, with no qualification. - * - * @return the name of this member - */ - String getName(); - - /** - * Gets the modifiers this member uses. Use the <code>Modifier</code> - * class to interpret the values. - * - * @return an integer representing the modifiers to this Member - * @see Modifier - */ - int getModifiers(); -} diff --git a/libjava/java/lang/reflect/Proxy.java b/libjava/java/lang/reflect/Proxy.java deleted file mode 100644 index dc1ac87e4e1..00000000000 --- a/libjava/java/lang/reflect/Proxy.java +++ /dev/null @@ -1,1615 +0,0 @@ -/* Proxy.java -- build a proxy class that implements reflected interfaces - Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang.reflect; - -import gnu.classpath.Configuration; -import gnu.java.lang.reflect.TypeSignature; - -import java.io.Serializable; -import java.security.ProtectionDomain; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - -/** - * This class allows you to dynamically create an instance of any (or - * even multiple) interfaces by reflection, and decide at runtime - * how that instance will behave by giving it an appropriate - * {@link InvocationHandler}. Proxy classes serialize specially, so - * that the proxy object can be reused between VMs, without requiring - * a persistent copy of the generated class code. - * - * <h3>Creation</h3> - * To create a proxy for some interface Foo: - * - * <pre> - * InvocationHandler handler = new MyInvocationHandler(...); - * Class proxyClass = Proxy.getProxyClass( - * Foo.class.getClassLoader(), new Class[] { Foo.class }); - * Foo f = (Foo) proxyClass - * .getConstructor(new Class[] { InvocationHandler.class }) - * .newInstance(new Object[] { handler }); - * </pre> - * or more simply: - * <pre> - * Foo f = (Foo) Proxy.newProxyInstance(Foo.class.getClassLoader(), - * new Class[] { Foo.class }, - * handler); - * </pre> - * - * <h3>Dynamic Proxy Classes</h3> - * A dynamic proxy class is created at runtime, and has the following - * properties: - * <ul> - * <li>The class is <code>public</code> and <code>final</code>, - * and is neither <code>abstract</code> nor an inner class.</li> - * <li>The class has no canonical name (there is no formula you can use - * to determine or generate its name), but begins with the - * sequence "$Proxy". Abuse this knowledge at your own peril. - * (For now, '$' in user identifiers is legal, but it may not - * be that way forever. You weren't using '$' in your - * identifiers, were you?)</li> - * <li>The class extends Proxy, and explicitly implements all the - * interfaces specified at creation, in order (this is important - * for determining how method invocation is resolved). Note that - * a proxy class implements {@link Serializable}, at least - * implicitly, since Proxy does, but true serial behavior - * depends on using a serializable invocation handler as well.</li> - * <li>If at least one interface is non-public, the proxy class - * will be in the same package. Otherwise, the package is - * unspecified. This will work even if the package is sealed - * from user-generated classes, because Proxy classes are - * generated by a trusted source. Meanwhile, the proxy class - * belongs to the classloader you designated.</li> - * <li>Reflection works as expected: {@link Class#getInterfaces()} and - * {@link Class#getMethods()} work as they do on normal classes.</li> - * <li>The method {@link #isProxyClass()} will distinguish between - * true proxy classes and user extensions of this class. It only - * returns true for classes created by {@link #getProxyClass}.</li> - * <li>The {@link ProtectionDomain} of a proxy class is the same as for - * bootstrap classes, such as Object or Proxy, since it is created by - * a trusted source. This protection domain will typically be granted - * {@link java.security.AllPermission}. But this is not a security - * risk, since there are adequate permissions on reflection, which is - * the only way to create an instance of the proxy class.</li> - * <li>The proxy class contains a single constructor, which takes as - * its only argument an {@link InvocationHandler}. The method - * {@link #newInstance} is shorthand to do the necessary - * reflection.</li> - * </ul> - * - * <h3>Proxy Instances</h3> - * A proxy instance is an instance of a proxy class. It has the - * following properties, many of which follow from the properties of a - * proxy class listed above: - * <ul> - * <li>For a proxy class with Foo listed as one of its interfaces, the - * expression <code>proxy instanceof Foo</code> will return true, - * and the expression <code>(Foo) proxy</code> will succeed without - * a {@link ClassCastException}.</li> - * <li>Each proxy instance has an invocation handler, which can be - * accessed by {@link #getInvocationHandler(Object)}. Any call - * to an interface method, including {@link Object#hashcode()}, - * {@link Object#equals(Object)}, or {@link Object#toString()}, - * but excluding the public final methods of Object, will be - * encoded and passed to the {@link InvocationHandler#invoke} - * method of this handler.</li> - * </ul> - * - * <h3>Inheritance Issues</h3> - * A proxy class may inherit a method from more than one interface. - * The order in which interfaces are listed matters, because it determines - * which reflected {@link Method} object will be passed to the invocation - * handler. This means that the dynamically generated class cannot - * determine through which interface a method is being invoked.<p> - * - * In short, if a method is declared in Object (namely, hashCode, - * equals, or toString), then Object will be used; otherwise, the - * leftmost interface that inherits or declares a method will be used, - * even if it has a more permissive throws clause than what the proxy - * class is allowed. Thus, in the invocation handler, it is not always - * safe to assume that every class listed in the throws clause of the - * passed Method object can safely be thrown; fortunately, the Proxy - * instance is robust enough to wrap all illegal checked exceptions in - * {@link UndeclaredThrowableException}. - * - * @see InvocationHandler - * @see UndeclaredThrowableException - * @see Class - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.3 - * @status updated to 1.4, except for the use of ProtectionDomain - */ -public class Proxy implements Serializable -{ - /** - * Compatible with JDK 1.3+. - */ - private static final long serialVersionUID = -2222568056686623797L; - - /** - * Map of ProxyType to proxy class. - * - * @XXX This prevents proxy classes from being garbage collected. - * java.util.WeakHashSet is not appropriate, because that collects the - * keys, but we are interested in collecting the elements. - */ - private static final Map proxyClasses = new HashMap(); - - /** - * The invocation handler for this proxy instance. For Proxy, this - * field is unused, but it appears here in order to be serialized in all - * proxy classes. - * - * <em>NOTE</em>: This implementation is more secure for proxy classes - * than what Sun specifies. Sun does not require h to be immutable, but - * this means you could change h after the fact by reflection. However, - * by making h immutable, we may break non-proxy classes which extend - * Proxy. - * @serial invocation handler associated with this proxy instance - */ - protected InvocationHandler h; - - /** - * Constructs a new Proxy from a subclass (usually a proxy class), - * with the specified invocation handler. - * - * <em>NOTE</em>: This throws a NullPointerException if you attempt - * to create a proxy instance with a null handler using reflection. - * This behavior is not yet specified by Sun; see Sun Bug 4487672. - * - * @param handler the invocation handler, may be null if the subclass - * is not a proxy class - * @throws NullPointerException if handler is null and this is a proxy - * instance - */ - protected Proxy(InvocationHandler handler) - { - if (handler == null && isProxyClass(getClass())) - throw new NullPointerException("invalid handler"); - h = handler; - } - - /** - * Returns the proxy {@link Class} for the given ClassLoader and array - * of interfaces, dynamically generating it if necessary. - * - * <p>There are several restrictions on this method, the violation of - * which will result in an IllegalArgumentException or - * NullPointerException:</p> - * - * <ul> - * <li>All objects in `interfaces' must represent distinct interfaces. - * Classes, primitive types, null, and duplicates are forbidden.</li> - * <li>The interfaces must be visible in the specified ClassLoader. - * In other words, for each interface i: - * <code>Class.forName(i.getName(), false, loader) == i</code> - * must be true.</li> - * <li>All non-public interfaces (if any) must reside in the same - * package, or the proxy class would be non-instantiable. If - * there are no non-public interfaces, the package of the proxy - * class is unspecified.</li> - * <li>All interfaces must be compatible - if two declare a method - * with the same name and parameters, the return type must be - * the same and the throws clause of the proxy class will be - * the maximal subset of subclasses of the throws clauses for - * each method that is overridden.</li> - * <li>VM constraints limit the number of interfaces a proxy class - * may directly implement (however, the indirect inheritance - * of {@link Serializable} does not count against this limit). - * Even though most VMs can theoretically have 65535 - * superinterfaces for a class, the actual limit is smaller - * because a class's constant pool is limited to 65535 entries, - * and not all entries can be interfaces.</li> - * </ul> - * - * <p>Note that different orders of interfaces produce distinct classes.</p> - * - * @param loader the class loader to define the proxy class in; null - * implies the bootstrap class loader - * @param interfaces the array of interfaces the proxy class implements, - * may be empty, but not null - * @return the Class object of the proxy class - * @throws IllegalArgumentException if the constraints above were - * violated, except for problems with null - * @throws NullPointerException if `interfaces' is null or contains - * a null entry - */ - // synchronized so that we aren't trying to build the same class - // simultaneously in two threads - public static synchronized Class getProxyClass(ClassLoader loader, - Class[] interfaces) - { - interfaces = (Class[]) interfaces.clone(); - ProxyType pt = new ProxyType(loader, interfaces); - Class clazz = (Class) proxyClasses.get(pt); - if (clazz == null) - { - if (Configuration.HAVE_NATIVE_GET_PROXY_CLASS) - clazz = getProxyClass0(loader, interfaces); - else - { - ProxyData data = (Configuration.HAVE_NATIVE_GET_PROXY_DATA - ? getProxyData0(loader, interfaces) - : ProxyData.getProxyData(pt)); - - clazz = (Configuration.HAVE_NATIVE_GENERATE_PROXY_CLASS - ? generateProxyClass0(loader, data) - : new ClassFactory(data).generate(loader)); - } - - Object check = proxyClasses.put(pt, clazz); - // assert check == null && clazz != null; - if (check != null || clazz == null) - throw new InternalError(/*"Fatal flaw in getProxyClass"*/); - } - return clazz; - } - - /** - * Combines several methods into one. This is equivalent to: - * <pre> - * Proxy.getProxyClass(loader, interfaces) - * .getConstructor(new Class[] {InvocationHandler.class}) - * .newInstance(new Object[] {handler}); - * </pre> - * except that it will not fail with the normal problems caused - * by reflection. It can still fail for the same reasons documented - * in getProxyClass, or if handler is null. - * - * @param loader the class loader to define the proxy class in; null - * implies the bootstrap class loader - * @param interfaces the array of interfaces the proxy class implements, - * may be empty, but not null - * @param handler the invocation handler, may not be null - * @return a proxy instance implementing the specified interfaces - * @throws IllegalArgumentException if the constraints for getProxyClass - * were violated, except for problems with null - * @throws NullPointerException if `interfaces' is null or contains - * a null entry, or if handler is null - * @see #getProxyClass(ClassLoader, Class[]) - * @see Class#getConstructor(Class[]) - * @see Constructor#newInstance(Object[]) - */ - public static Object newProxyInstance(ClassLoader loader, - Class[] interfaces, - InvocationHandler handler) - { - try - { - // getProxyClass() and Proxy() throw the necessary exceptions - return getProxyClass(loader, interfaces) - .getConstructor(new Class[] {InvocationHandler.class}) - .newInstance(new Object[] {handler}); - } - catch (RuntimeException e) - { - // Let IllegalArgumentException, NullPointerException escape. - // assert e instanceof IllegalArgumentException - // || e instanceof NullPointerException; - throw e; - } - catch (InvocationTargetException e) - { - // Let wrapped NullPointerException escape. - // assert e.getTargetException() instanceof NullPointerException - throw (NullPointerException) e.getCause(); - } - catch (Exception e) - { - // Covers InstantiationException, IllegalAccessException, - // NoSuchMethodException, none of which should be generated - // if the proxy class was generated correctly. - // assert false; - throw (Error) new InternalError("Unexpected: " + e).initCause(e); - } - } - - /** - * Returns true if and only if the Class object is a dynamically created - * proxy class (created by <code>getProxyClass</code> or by the - * syntactic sugar of <code>newProxyInstance</code>). - * - * <p>This check is secure (in other words, it is not simply - * <code>clazz.getSuperclass() == Proxy.class</code>), it will not - * be spoofed by non-proxy classes that extend Proxy. - * - * @param clazz the class to check, must not be null - * @return true if the class represents a proxy class - * @throws NullPointerException if clazz is null - */ - // This is synchronized on the off chance that another thread is - // trying to add a class to the map at the same time we read it. - public static synchronized boolean isProxyClass(Class clazz) - { - if (! Proxy.class.isAssignableFrom(clazz)) - return false; - // This is a linear search, even though we could do an O(1) search - // using new ProxyType(clazz.getClassLoader(), clazz.getInterfaces()). - return proxyClasses.containsValue(clazz); - } - - /** - * Returns the invocation handler for the given proxy instance.<p> - * - * <em>NOTE</em>: We guarantee a non-null result if successful, - * but Sun allows the creation of a proxy instance with a null - * handler. See the comments for {@link #Proxy(InvocationHandler)}. - * - * @param proxy the proxy instance, must not be null - * @return the invocation handler, guaranteed non-null. - * @throws IllegalArgumentException if - * <code>Proxy.isProxyClass(proxy.getClass())</code> returns false. - * @throws NullPointerException if proxy is null - */ - public static InvocationHandler getInvocationHandler(Object proxy) - { - if (! isProxyClass(proxy.getClass())) - throw new IllegalArgumentException("not a proxy instance"); - return ((Proxy) proxy).h; - } - - /** - * Optional native method to replace (and speed up) the pure Java - * implementation of getProxyClass. Only needed if - * Configuration.HAVE_NATIVE_GET_PROXY_CLASS is true, this does the - * work of both getProxyData0 and generateProxyClass0 with no - * intermediate form in Java. The native code may safely assume that - * this class must be created, and does not already exist. - * - * @param loader the class loader to define the proxy class in; null - * implies the bootstrap class loader - * @param interfaces the interfaces the class will extend - * @return the generated proxy class - * @throws IllegalArgumentException if the constraints for getProxyClass - * were violated, except for problems with null - * @throws NullPointerException if `interfaces' is null or contains - * a null entry, or if handler is null - * @see Configuration#HAVE_NATIVE_GET_PROXY_CLASS - * @see #getProxyClass(ClassLoader, Class[]) - * @see #getProxyData0(ClassLoader, Class[]) - * @see #generateProxyClass0(ProxyData) - */ - private static native Class getProxyClass0(ClassLoader loader, - Class[] interfaces); - - /** - * Optional native method to replace (and speed up) the pure Java - * implementation of getProxyData. Only needed if - * Configuration.HAVE_NATIVE_GET_PROXY_DATA is true. The native code - * may safely assume that a new ProxyData object must be created which - * does not duplicate any existing ones. - * - * @param loader the class loader to define the proxy class in; null - * implies the bootstrap class loader - * @param interfaces the interfaces the class will extend - * @return all data that is required to make this proxy class - * @throws IllegalArgumentException if the constraints for getProxyClass - * were violated, except for problems with null - * @throws NullPointerException if `interfaces' is null or contains - * a null entry, or if handler is null - * @see Configuration.HAVE_NATIVE_GET_PROXY_DATA - * @see #getProxyClass(ClassLoader, Class[]) - * @see #getProxyClass0(ClassLoader, Class[]) - * @see ProxyType#getProxyData() - */ - private static native ProxyData getProxyData0(ClassLoader loader, - Class[] interfaces); - - /** - * Optional native method to replace (and speed up) the pure Java - * implementation of generateProxyClass. Only needed if - * Configuration.HAVE_NATIVE_GENERATE_PROXY_CLASS is true. The native - * code may safely assume that a new Class must be created, and that - * the ProxyData object does not describe any existing class. - * - * @param loader the class loader to define the proxy class in; null - * implies the bootstrap class loader - * @param data the struct of information to convert to a Class. This - * has already been verified for all problems except exceeding - * VM limitations - * @return the newly generated class - * @throws IllegalArgumentException if VM limitations are exceeded - * @see #getProxyClass(ClassLoader, Class[]) - * @see #getProxyClass0(ClassLoader, Class[]) - * @see ProxyData#generateProxyClass(ClassLoader) - */ - private static native Class generateProxyClass0(ClassLoader loader, - ProxyData data); - - /** - * Helper class for mapping unique ClassLoader and interface combinations - * to proxy classes. - * - * @author Eric Blake (ebb9@email.byu.edu) - */ - private static final class ProxyType - { - /** - * Store the class loader (may be null) - */ - final ClassLoader loader; - - /** - * Store the interfaces (never null, all elements are interfaces) - */ - final Class[] interfaces; - - /** - * Construct the helper object. - * - * @param loader the class loader to define the proxy class in; null - * implies the bootstrap class loader - * @param interfaces an array of interfaces - */ - ProxyType(ClassLoader loader, Class[] interfaces) - { - if (loader == null) - loader = ClassLoader.getSystemClassLoader(); - this.loader = loader; - this.interfaces = interfaces; - } - - /** - * Calculates the hash code. - * - * @return a combination of the classloader and interfaces hashcodes. - */ - public int hashCode() - { - //loader is always not null - int hash = loader.hashCode(); - for (int i = 0; i < interfaces.length; i++) - hash = hash * 31 + interfaces[i].hashCode(); - return hash; - } - - // A more comprehensive comparison of two arrays, - // ignore array element order, and - // ignore redundant elements - private static boolean sameTypes(Class arr1[], Class arr2[]) { - if (arr1.length == 1 && arr2.length == 1) { - return arr1[0] == arr2[0]; - } - - // total occurrance of elements of arr1 in arr2 - int total_occ_of_arr1_in_arr2 = 0; - each_type: - for (int i = arr1.length; --i >= 0; ) - { - Class t = arr1[i]; - for (int j = i; --j >= 0; ) - { - if (t == arr1[j]) - { //found duplicate type - continue each_type; - } - } - - // count c(a unique element of arr1)'s - // occurrences in arr2 - int occ_in_arr2 = 0; - for (int j = arr2.length; --j >= 0; ) - { - if (t == arr2[j]) - { - ++occ_in_arr2; - } - } - if (occ_in_arr2 == 0) - { // t does not occur in arr2 - return false; - } - - total_occ_of_arr1_in_arr2 += occ_in_arr2; - } - // now, each element of arr2 must have been visited - return total_occ_of_arr1_in_arr2 == arr2.length; - } - - /** - * Calculates equality. - * - * @param the object to compare to - * @return true if it is a ProxyType with same data - */ - public boolean equals(Object other) - { - ProxyType pt = (ProxyType) other; - if (loader != pt.loader || interfaces.length != pt.interfaces.length) - return false; - return sameTypes(interfaces, pt.interfaces); - } - } // class ProxyType - - /** - * Helper class which allows hashing of a method name and signature - * without worrying about return type, declaring class, or throws clause, - * and which reduces the maximally common throws clause between two methods - * - * @author Eric Blake (ebb9@email.byu.edu) - */ - private static final class ProxySignature - { - /** - * The core signatures which all Proxy instances handle. - */ - static final HashMap coreMethods = new HashMap(); - static - { - try - { - ProxySignature sig - = new ProxySignature(Object.class - .getMethod("equals", - new Class[] {Object.class})); - coreMethods.put(sig, sig); - sig = new ProxySignature(Object.class.getMethod("hashCode", null)); - coreMethods.put(sig, sig); - sig = new ProxySignature(Object.class.getMethod("toString", null)); - coreMethods.put(sig, sig); - } - catch (Exception e) - { - // assert false; - throw (Error) new InternalError("Unexpected: " + e).initCause(e); - } - } - - /** - * The underlying Method object, never null - */ - final Method method; - - /** - * The set of compatible thrown exceptions, may be empty - */ - final Set exceptions = new HashSet(); - - /** - * Construct a signature - * - * @param method the Method this signature is based on, never null - */ - ProxySignature(Method method) - { - this.method = method; - Class[] exc = method.getExceptionTypes(); - int i = exc.length; - while (--i >= 0) - { - // discard unchecked exceptions - if (Error.class.isAssignableFrom(exc[i]) - || RuntimeException.class.isAssignableFrom(exc[i])) - continue; - exceptions.add(exc[i]); - } - } - - /** - * Given a method, make sure it's return type is identical - * to this, and adjust this signature's throws clause appropriately - * - * @param other the signature to merge in - * @throws IllegalArgumentException if the return types conflict - */ - void checkCompatibility(ProxySignature other) - { - if (method.getReturnType() != other.method.getReturnType()) - throw new IllegalArgumentException("incompatible return types: " - + method + ", " + other.method); - - // if you can think of a more efficient way than this O(n^2) search, - // implement it! - int size1 = exceptions.size(); - int size2 = other.exceptions.size(); - boolean[] valid1 = new boolean[size1]; - boolean[] valid2 = new boolean[size2]; - Iterator itr = exceptions.iterator(); - int pos = size1; - while (--pos >= 0) - { - Class c1 = (Class) itr.next(); - Iterator itr2 = other.exceptions.iterator(); - int pos2 = size2; - while (--pos2 >= 0) - { - Class c2 = (Class) itr2.next(); - if (c2.isAssignableFrom(c1)) - valid1[pos] = true; - if (c1.isAssignableFrom(c2)) - valid2[pos2] = true; - } - } - pos = size1; - itr = exceptions.iterator(); - while (--pos >= 0) - { - itr.next(); - if (! valid1[pos]) - itr.remove(); - } - pos = size2; - itr = other.exceptions.iterator(); - while (--pos >= 0) - { - itr.next(); - if (! valid2[pos]) - itr.remove(); - } - exceptions.addAll(other.exceptions); - } - - /** - * Calculates the hash code. - * - * @return a combination of name and parameter types - */ - public int hashCode() - { - int hash = method.getName().hashCode(); - Class[] types = method.getParameterTypes(); - for (int i = 0; i < types.length; i++) - hash = hash * 31 + types[i].hashCode(); - return hash; - } - - /** - * Calculates equality. - * - * @param the object to compare to - * @return true if it is a ProxySignature with same data - */ - public boolean equals(Object other) - { - ProxySignature ps = (ProxySignature) other; - Class[] types1 = method.getParameterTypes(); - Class[] types2 = ps.method.getParameterTypes(); - if (! method.getName().equals(ps.method.getName()) - || types1.length != types2.length) - return false; - int i = types1.length; - while (--i >= 0) - if (types1[i] != types2[i]) - return false; - return true; - } - } // class ProxySignature - - /** - * A flat representation of all data needed to generate bytecode/instantiate - * a proxy class. This is basically a struct. - * - * @author Eric Blake (ebb9@email.byu.edu) - */ - private static final class ProxyData - { - /** - * The package this class is in <b>including the trailing dot</b> - * or an empty string for the unnamed (aka default) package. - */ - String pack; - - /** - * The interfaces this class implements. Non-null, but possibly empty. - */ - Class[] interfaces; - - /** - * The Method objects this class must pass as the second argument to - * invoke (also useful for determining what methods this class has). - * Non-null, non-empty (includes at least Object.hashCode, Object.equals, - * and Object.toString). - */ - Method[] methods; - - /** - * The exceptions that do not need to be wrapped in - * UndeclaredThrowableException. exceptions[i] is the same as, or a - * subset of subclasses, of methods[i].getExceptionTypes(), depending on - * compatible throws clauses with multiple inheritance. It is unspecified - * if these lists include or exclude subclasses of Error and - * RuntimeException, but excluding them is harmless and generates a - * smaller class. - */ - Class[][] exceptions; - - /** - * For unique id's - */ - private static int count; - - /** - * The id of this proxy class - */ - final int id = count++; - - /** - * Construct a ProxyData with uninitialized data members. - */ - ProxyData() - { - } - - /** - * Return the name of a package (including the trailing dot) - * given the name of a class. - * Returns an empty string if no package. We use this in preference to - * using Class.getPackage() to avoid problems with ClassLoaders - * that don't set the package. - */ - private static String getPackage(Class k) - { - String name = k.getName(); - int idx = name.lastIndexOf('.'); - return name.substring(0, idx + 1); - } - - /** - * Verifies that the arguments are legal, and sets up remaining data - * This should only be called when a class must be generated, as - * it is expensive. - * - * @param pt the ProxyType to convert to ProxyData - * @return the flattened, verified ProxyData structure for use in - * class generation - * @throws IllegalArgumentException if `interfaces' contains - * non-interfaces or incompatible combinations, and verify is true - * @throws NullPointerException if interfaces is null or contains null - */ - static ProxyData getProxyData(ProxyType pt) - { - Map method_set = (Map) ProxySignature.coreMethods.clone(); - boolean in_package = false; // true if we encounter non-public interface - - ProxyData data = new ProxyData(); - data.interfaces = pt.interfaces; - - // if interfaces is too large, we croak later on when the constant - // pool overflows - int i = data.interfaces.length; - while (--i >= 0) - { - Class inter = data.interfaces[i]; - if (! inter.isInterface()) - throw new IllegalArgumentException("not an interface: " + inter); - try - { - if (Class.forName(inter.getName(), false, pt.loader) != inter) - throw new IllegalArgumentException("not accessible in " - + "classloader: " + inter); - } - catch (ClassNotFoundException e) - { - throw new IllegalArgumentException("not accessible in " - + "classloader: " + inter); - } - if (! Modifier.isPublic(inter.getModifiers())) - if (in_package) - { - String p = getPackage(inter); - if (! data.pack.equals(p)) - throw new IllegalArgumentException("non-public interfaces " - + "from different " - + "packages"); - } - else - { - in_package = true; - data.pack = getPackage(inter); - } - for (int j = i-1; j >= 0; j--) - if (data.interfaces[j] == inter) - throw new IllegalArgumentException("duplicate interface: " - + inter); - Method[] methods = inter.getMethods(); - int j = methods.length; - while (--j >= 0) - { - ProxySignature sig = new ProxySignature(methods[j]); - ProxySignature old = (ProxySignature) method_set.put(sig, sig); - if (old != null) - sig.checkCompatibility(old); - } - } - - i = method_set.size(); - data.methods = new Method[i]; - data.exceptions = new Class[i][]; - Iterator itr = method_set.values().iterator(); - while (--i >= 0) - { - ProxySignature sig = (ProxySignature) itr.next(); - data.methods[i] = sig.method; - data.exceptions[i] = (Class[]) sig.exceptions - .toArray(new Class[sig.exceptions.size()]); - } - return data; - } - } // class ProxyData - - /** - * Does all the work of building a class. By making this a nested class, - * this code is not loaded in memory if the VM has a native - * implementation instead. - * - * @author Eric Blake (ebb9@email.byu.edu) - */ - private static final class ClassFactory - { - /** Constants for assisting the compilation */ - private static final byte POOL = 0; - private static final byte FIELD = 1; - private static final byte METHOD = 2; - private static final byte INTERFACE = 3; - private static final String CTOR_SIG - = "(Ljava/lang/reflect/InvocationHandler;)V"; - private static final String INVOKE_SIG = "(Ljava/lang/Object;" - + "Ljava/lang/reflect/Method;[Ljava/lang/Object;)Ljava/lang/Object;"; - - /** Bytecodes for insertion in the class definition byte[] */ - private static final char ACONST_NULL = 1; - private static final char ICONST_0 = 3; - private static final char BIPUSH = 16; - private static final char SIPUSH = 17; - private static final char ILOAD = 21; - private static final char ILOAD_0 = 26; - private static final char ALOAD_0 = 42; - private static final char ALOAD_1 = 43; - private static final char AALOAD = 50; - private static final char AASTORE = 83; - private static final char DUP = 89; - private static final char DUP_X1 = 90; - private static final char SWAP = 95; - private static final char IRETURN = 172; - private static final char LRETURN = 173; - private static final char FRETURN = 174; - private static final char DRETURN = 175; - private static final char ARETURN = 176; - private static final char RETURN = 177; - private static final char GETSTATIC = 178; - private static final char GETFIELD = 180; - private static final char INVOKEVIRTUAL = 182; - private static final char INVOKESPECIAL = 183; - private static final char INVOKESTATIC = 184; - private static final char INVOKEINTERFACE = 185; - private static final char NEW = 187; - private static final char ANEWARRAY = 189; - private static final char ATHROW = 191; - private static final char CHECKCAST = 192; - - // Implementation note: we use StringBuffers to hold the byte data, since - // they automatically grow. However, we only use the low 8 bits of - // every char in the array, so we are using twice the necessary memory - // for the ease StringBuffer provides. - - /** The constant pool. */ - private final StringBuffer pool = new StringBuffer(); - /** The rest of the class data. */ - private final StringBuffer stream = new StringBuffer(); - - /** Map of strings to byte sequences, to minimize size of pool. */ - private final Map poolEntries = new HashMap(); - - /** The VM name of this proxy class. */ - private final String qualName; - - /** - * The Method objects the proxy class refers to when calling the - * invocation handler. - */ - private final Method[] methods; - - /** - * Initializes the buffers with the bytecode contents for a proxy class. - * - * @param data the remainder of the class data - * @throws IllegalArgumentException if anything else goes wrong this - * late in the game; as far as I can tell, this will only happen - * if the constant pool overflows, which is possible even when - * the user doesn't exceed the 65535 interface limit - */ - ClassFactory(ProxyData data) - { - methods = data.methods; - - // magic = 0xcafebabe - // minor_version = 0 - // major_version = 46 - // constant_pool_count: place-holder for now - pool.append("\u00ca\u00fe\u00ba\u00be\0\0\0\56\0\0"); - // constant_pool[], filled in as we go - - // access_flags - putU2(Modifier.SUPER | Modifier.FINAL | Modifier.PUBLIC); - // this_class - qualName = (data.pack + "$Proxy" + data.id); - putU2(classInfo(TypeSignature.getEncodingOfClass(qualName, false))); - // super_class - putU2(classInfo("java/lang/reflect/Proxy")); - - // interfaces_count - putU2(data.interfaces.length); - // interfaces[] - for (int i = 0; i < data.interfaces.length; i++) - putU2(classInfo(data.interfaces[i])); - - // Recall that Proxy classes serialize specially, so we do not need - // to worry about a <clinit> method for this field. Instead, we - // just assign it by reflection after the class is successfully loaded. - // fields_count - private static Method[] m; - putU2(1); - // fields[] - // m.access_flags - putU2(Modifier.PRIVATE | Modifier.STATIC); - // m.name_index - putU2(utf8Info("m")); - // m.descriptor_index - putU2(utf8Info("[Ljava/lang/reflect/Method;")); - // m.attributes_count - putU2(0); - // m.attributes[] - - // methods_count - # handler methods, plus <init> - putU2(methods.length + 1); - // methods[] - // <init>.access_flags - putU2(Modifier.PUBLIC); - // <init>.name_index - putU2(utf8Info("<init>")); - // <init>.descriptor_index - putU2(utf8Info(CTOR_SIG)); - // <init>.attributes_count - only Code is needed - putU2(1); - // <init>.Code.attribute_name_index - putU2(utf8Info("Code")); - // <init>.Code.attribute_length = 18 - // <init>.Code.info: - // $Proxynn(InvocationHandler h) { super(h); } - // <init>.Code.max_stack = 2 - // <init>.Code.max_locals = 2 - // <init>.Code.code_length = 6 - // <init>.Code.code[] - stream.append("\0\0\0\22\0\2\0\2\0\0\0\6" + ALOAD_0 + ALOAD_1 - + INVOKESPECIAL); - putU2(refInfo(METHOD, "java/lang/reflect/Proxy", "<init>", CTOR_SIG)); - // <init>.Code.exception_table_length = 0 - // <init>.Code.exception_table[] - // <init>.Code.attributes_count = 0 - // <init>.Code.attributes[] - stream.append(RETURN + "\0\0\0\0"); - - for (int i = methods.length - 1; i >= 0; i--) - emitMethod(i, data.exceptions[i]); - - // attributes_count - putU2(0); - // attributes[] - empty; omit SourceFile attribute - // XXX should we mark this with a Synthetic attribute? - } - - /** - * Produce the bytecode for a single method. - * - * @param i the index of the method we are building - * @param e the exceptions possible for the method - */ - private void emitMethod(int i, Class[] e) - { - // First, we precalculate the method length and other information. - - Method m = methods[i]; - Class[] paramtypes = m.getParameterTypes(); - int wrap_overhead = 0; // max words taken by wrapped primitive - int param_count = 1; // 1 for this - int code_length = 16; // aload_0, getfield, aload_0, getstatic, const, - // aaload, const/aconst_null, invokeinterface - if (i > 5) - { - if (i > Byte.MAX_VALUE) - code_length += 2; // sipush - else - code_length++; // bipush - } - if (paramtypes.length > 0) - { - code_length += 3; // anewarray - if (paramtypes.length > Byte.MAX_VALUE) - code_length += 2; // sipush - else if (paramtypes.length > 5) - code_length++; // bipush - for (int j = 0; j < paramtypes.length; j++) - { - code_length += 4; // dup, const, load, store - Class type = paramtypes[j]; - if (j > 5) - { - if (j > Byte.MAX_VALUE) - code_length += 2; // sipush - else - code_length++; // bipush - } - if (param_count >= 4) - code_length++; // 2-byte load - param_count++; - if (type.isPrimitive()) - { - code_length += 7; // new, dup, invokespecial - if (type == long.class || type == double.class) - { - wrap_overhead = 3; - param_count++; - } - else if (wrap_overhead < 2) - wrap_overhead = 2; - } - } - } - int end_pc = code_length; - Class ret_type = m.getReturnType(); - if (ret_type == void.class) - code_length++; // return - else if (ret_type.isPrimitive()) - code_length += 7; // cast, invokevirtual, return - else - code_length += 4; // cast, return - int exception_count = 0; - boolean throws_throwable = false; - for (int j = 0; j < e.length; j++) - if (e[j] == Throwable.class) - { - throws_throwable = true; - break; - } - if (! throws_throwable) - { - exception_count = e.length + 3; // Throwable, Error, RuntimeException - code_length += 9; // new, dup_x1, swap, invokespecial, athrow - } - int handler_pc = code_length - 1; - StringBuffer signature = new StringBuffer("("); - for (int j = 0; j < paramtypes.length; j++) - signature.append(TypeSignature.getEncodingOfClass(paramtypes[j])); - signature.append(")").append(TypeSignature.getEncodingOfClass(ret_type)); - - // Now we have enough information to emit the method. - - // handler.access_flags - putU2(Modifier.PUBLIC | Modifier.FINAL); - // handler.name_index - putU2(utf8Info(m.getName())); - // handler.descriptor_index - putU2(utf8Info(signature.toString())); - // handler.attributes_count - Code is necessary, Exceptions possible - putU2(e.length > 0 ? 2 : 1); - - // handler.Code.info: - // type name(args) { - // try { - // return (type) h.invoke(this, methods[i], new Object[] {args}); - // } catch (<declared Exceptions> e) { - // throw e; - // } catch (Throwable t) { - // throw new UndeclaredThrowableException(t); - // } - // } - // Special cases: - // if arg_n is primitive, wrap it - // if method throws Throwable, try-catch is not needed - // if method returns void, return statement not needed - // if method returns primitive, unwrap it - // save space by sharing code for all the declared handlers - - // handler.Code.attribute_name_index - putU2(utf8Info("Code")); - // handler.Code.attribute_length - putU4(12 + code_length + 8 * exception_count); - // handler.Code.max_stack - putU2(param_count == 1 ? 4 : 7 + wrap_overhead); - // handler.Code.max_locals - putU2(param_count); - // handler.Code.code_length - putU4(code_length); - // handler.Code.code[] - putU1(ALOAD_0); - putU1(GETFIELD); - putU2(refInfo(FIELD, "java/lang/reflect/Proxy", "h", - "Ljava/lang/reflect/InvocationHandler;")); - putU1(ALOAD_0); - putU1(GETSTATIC); - putU2(refInfo(FIELD, TypeSignature.getEncodingOfClass(qualName, false), - "m", "[Ljava/lang/reflect/Method;")); - putConst(i); - putU1(AALOAD); - if (paramtypes.length > 0) - { - putConst(paramtypes.length); - putU1(ANEWARRAY); - putU2(classInfo("java/lang/Object")); - param_count = 1; - for (int j = 0; j < paramtypes.length; j++, param_count++) - { - putU1(DUP); - putConst(j); - if (paramtypes[j].isPrimitive()) - { - putU1(NEW); - putU2(classInfo(wrapper(paramtypes[j]))); - putU1(DUP); - } - putLoad(param_count, paramtypes[j]); - if (paramtypes[j].isPrimitive()) - { - putU1(INVOKESPECIAL); - putU2(refInfo(METHOD, wrapper(paramtypes[j]), "<init>", - '(' + (TypeSignature - .getEncodingOfClass(paramtypes[j]) - + ")V"))); - if (paramtypes[j] == long.class - || paramtypes[j] == double.class) - param_count++; - } - putU1(AASTORE); - } - } - else - putU1(ACONST_NULL); - putU1(INVOKEINTERFACE); - putU2(refInfo(INTERFACE, "java/lang/reflect/InvocationHandler", - "invoke", INVOKE_SIG)); - putU1(4); // InvocationHandler, this, Method, Object[] - putU1(0); - if (ret_type == void.class) - putU1(RETURN); - else if (ret_type.isPrimitive()) - { - putU1(CHECKCAST); - putU2(classInfo(wrapper(ret_type))); - putU1(INVOKEVIRTUAL); - putU2(refInfo(METHOD, wrapper(ret_type), - ret_type.getName() + "Value", - "()" + TypeSignature.getEncodingOfClass(ret_type))); - if (ret_type == long.class) - putU1(LRETURN); - else if (ret_type == float.class) - putU1(FRETURN); - else if (ret_type == double.class) - putU1(DRETURN); - else - putU1(IRETURN); - } - else - { - putU1(CHECKCAST); - putU2(classInfo(ret_type)); - putU1(ARETURN); - } - if (! throws_throwable) - { - putU1(NEW); - putU2(classInfo("java/lang/reflect/UndeclaredThrowableException")); - putU1(DUP_X1); - putU1(SWAP); - putU1(INVOKESPECIAL); - putU2(refInfo(METHOD, - "java/lang/reflect/UndeclaredThrowableException", - "<init>", "(Ljava/lang/Throwable;)V")); - putU1(ATHROW); - } - - // handler.Code.exception_table_length - putU2(exception_count); - // handler.Code.exception_table[] - if (! throws_throwable) - { - // handler.Code.exception_table.start_pc - putU2(0); - // handler.Code.exception_table.end_pc - putU2(end_pc); - // handler.Code.exception_table.handler_pc - putU2(handler_pc); - // handler.Code.exception_table.catch_type - putU2(classInfo("java/lang/Error")); - // handler.Code.exception_table.start_pc - putU2(0); - // handler.Code.exception_table.end_pc - putU2(end_pc); - // handler.Code.exception_table.handler_pc - putU2(handler_pc); - // handler.Code.exception_table.catch_type - putU2(classInfo("java/lang/RuntimeException")); - for (int j = 0; j < e.length; j++) - { - // handler.Code.exception_table.start_pc - putU2(0); - // handler.Code.exception_table.end_pc - putU2(end_pc); - // handler.Code.exception_table.handler_pc - putU2(handler_pc); - // handler.Code.exception_table.catch_type - putU2(classInfo(e[j])); - } - // handler.Code.exception_table.start_pc - putU2(0); - // handler.Code.exception_table.end_pc - putU2(end_pc); - // handler.Code.exception_table.handler_pc - - // -8 for undeclared handler, which falls thru to normal one - putU2(handler_pc - 8); - // handler.Code.exception_table.catch_type - putU2(0); - } - // handler.Code.attributes_count - putU2(0); - // handler.Code.attributes[] - - if (e.length > 0) - { - // handler.Exceptions.attribute_name_index - putU2(utf8Info("Exceptions")); - // handler.Exceptions.attribute_length - putU4(2 * e.length + 2); - // handler.Exceptions.number_of_exceptions - putU2(e.length); - // handler.Exceptions.exception_index_table[] - for (int j = 0; j < e.length; j++) - putU2(classInfo(e[j])); - } - } - - /** - * Creates the Class object that corresponds to the bytecode buffers - * built when this object was constructed. - * - * @param loader the class loader to define the proxy class in; null - * implies the bootstrap class loader - * @return the proxy class Class object - */ - Class generate(ClassLoader loader) - { - byte[] bytecode = new byte[pool.length() + stream.length()]; - // More efficient to bypass calling charAt() repetitively. - char[] c = pool.toString().toCharArray(); - int i = c.length; - while (--i >= 0) - bytecode[i] = (byte) c[i]; - c = stream.toString().toCharArray(); - i = c.length; - int j = bytecode.length; - while (i > 0) - bytecode[--j] = (byte) c[--i]; - - // Patch the constant pool size, which we left at 0 earlier. - int count = poolEntries.size() + 1; - bytecode[8] = (byte) (count >> 8); - bytecode[9] = (byte) count; - - try - { - Class vmClassLoader = Class.forName("java.lang.VMClassLoader"); - Class[] types = {ClassLoader.class, String.class, - byte[].class, int.class, int.class, - ProtectionDomain.class }; - Method m = vmClassLoader.getDeclaredMethod("defineClass", types); - // We can bypass the security check of setAccessible(true), since - // we're in the same package. - m.flag = true; - - Object[] args = {loader, qualName, bytecode, new Integer(0), - new Integer(bytecode.length), - Object.class.getProtectionDomain() }; - Class clazz = (Class) m.invoke(null, args); - - // Finally, initialize the m field of the proxy class, before - // returning it. - Field f = clazz.getDeclaredField("m"); - f.flag = true; - // we can share the array, because it is not publicized - f.set(null, methods); - - return clazz; - } - catch (Exception e) - { - // assert false; - throw (Error) new InternalError("Unexpected: " + e).initCause(e); - } - } - - /** - * Put a single byte on the stream. - * - * @param i the information to add (only lowest 8 bits are used) - */ - private void putU1(int i) - { - stream.append((char) i); - } - - /** - * Put two bytes on the stream. - * - * @param i the information to add (only lowest 16 bits are used) - */ - private void putU2(int i) - { - stream.append((char) (i >> 8)).append((char) i); - } - - /** - * Put four bytes on the stream. - * - * @param i the information to add (treated as unsigned) - */ - private void putU4(int i) - { - stream.append((char) (i >> 24)).append((char) (i >> 16)); - stream.append((char) (i >> 8)).append((char) i); - } - - /** - * Put bytecode to load a constant integer on the stream. This only - * needs to work for values less than Short.MAX_VALUE. - * - * @param i the int to add - */ - private void putConst(int i) - { - if (i >= -1 && i <= 5) - putU1(ICONST_0 + i); - else if (i >= Byte.MIN_VALUE && i <= Byte.MAX_VALUE) - { - putU1(BIPUSH); - putU1(i); - } - else - { - putU1(SIPUSH); - putU2(i); - } - } - - /** - * Put bytecode to load a given local variable on the stream. - * - * @param i the slot to load - * @param type the base type of the load - */ - private void putLoad(int i, Class type) - { - int offset = 0; - if (type == long.class) - offset = 1; - else if (type == float.class) - offset = 2; - else if (type == double.class) - offset = 3; - else if (! type.isPrimitive()) - offset = 4; - if (i < 4) - putU1(ILOAD_0 + 4 * offset + i); - else - { - putU1(ILOAD + offset); - putU1(i); - } - } - - /** - * Given a primitive type, return its wrapper class name. - * - * @param clazz the primitive type (but not void.class) - * @return the internal form of the wrapper class name - */ - private String wrapper(Class clazz) - { - if (clazz == boolean.class) - return "java/lang/Boolean"; - if (clazz == byte.class) - return "java/lang/Byte"; - if (clazz == short.class) - return "java/lang/Short"; - if (clazz == char.class) - return "java/lang/Character"; - if (clazz == int.class) - return "java/lang/Integer"; - if (clazz == long.class) - return "java/lang/Long"; - if (clazz == float.class) - return "java/lang/Float"; - if (clazz == double.class) - return "java/lang/Double"; - // assert false; - return null; - } - - /** - * Returns the entry of this String in the Constant pool, adding it - * if necessary. - * - * @param str the String to resolve - * @return the index of the String in the constant pool - */ - private char utf8Info(String str) - { - String utf8 = toUtf8(str); - int len = utf8.length(); - return poolIndex("\1" + (char) (len >> 8) + (char) (len & 0xff) + utf8); - } - - /** - * Returns the entry of the appropriate class info structure in the - * Constant pool, adding it if necessary. - * - * @param name the class name, in internal form - * @return the index of the ClassInfo in the constant pool - */ - private char classInfo(String name) - { - char index = utf8Info(name); - char[] c = {7, (char) (index >> 8), (char) (index & 0xff)}; - return poolIndex(new String(c)); - } - - /** - * Returns the entry of the appropriate class info structure in the - * Constant pool, adding it if necessary. - * - * @param clazz the class type - * @return the index of the ClassInfo in the constant pool - */ - private char classInfo(Class clazz) - { - return classInfo(TypeSignature.getEncodingOfClass(clazz.getName(), - false)); - } - - /** - * Returns the entry of the appropriate fieldref, methodref, or - * interfacemethodref info structure in the Constant pool, adding it - * if necessary. - * - * @param structure FIELD, METHOD, or INTERFACE - * @param clazz the class name, in internal form - * @param name the simple reference name - * @param type the type of the reference - * @return the index of the appropriate Info structure in the constant pool - */ - private char refInfo(byte structure, String clazz, String name, - String type) - { - char cindex = classInfo(clazz); - char ntindex = nameAndTypeInfo(name, type); - // relies on FIELD == 1, METHOD == 2, INTERFACE == 3 - char[] c = {(char) (structure + 8), - (char) (cindex >> 8), (char) (cindex & 0xff), - (char) (ntindex >> 8), (char) (ntindex & 0xff)}; - return poolIndex(new String(c)); - } - - /** - * Returns the entry of the appropriate nameAndTyperef info structure - * in the Constant pool, adding it if necessary. - * - * @param name the simple name - * @param type the reference type - * @return the index of the NameAndTypeInfo structure in the constant pool - */ - private char nameAndTypeInfo(String name, String type) - { - char nindex = utf8Info(name); - char tindex = utf8Info(type); - char[] c = {12, (char) (nindex >> 8), (char) (nindex & 0xff), - (char) (tindex >> 8), (char) (tindex & 0xff)}; - return poolIndex(new String(c)); - } - - /** - * Converts a regular string to a UTF8 string, where the upper byte - * of every char is 0, and '\\u0000' is not in the string. This is - * basically to use a String as a fancy byte[], and while it is less - * efficient in memory use, it is easier for hashing. - * - * @param str the original, in straight unicode - * @return a modified string, in UTF8 format in the low bytes - */ - private String toUtf8(String str) - { - final char[] ca = str.toCharArray(); - final int len = ca.length; - - // Avoid object creation, if str is already fits UTF8. - int i; - for (i = 0; i < len; i++) - if (ca[i] == 0 || ca[i] > '\u007f') - break; - if (i == len) - return str; - - final StringBuffer sb = new StringBuffer(str); - sb.setLength(i); - for ( ; i < len; i++) - { - final char c = ca[i]; - if (c > 0 && c <= '\u007f') - sb.append(c); - else if (c <= '\u07ff') // includes '\0' - { - sb.append((char) (0xc0 | (c >> 6))); - sb.append((char) (0x80 | (c & 0x6f))); - } - else - { - sb.append((char) (0xe0 | (c >> 12))); - sb.append((char) (0x80 | ((c >> 6) & 0x6f))); - sb.append((char) (0x80 | (c & 0x6f))); - } - } - return sb.toString(); - } - - /** - * Returns the location of a byte sequence (conveniently wrapped in - * a String with all characters between \u0001 and \u00ff inclusive) - * in the constant pool, adding it if necessary. - * - * @param sequence the byte sequence to look for - * @return the index of the sequence - * @throws IllegalArgumentException if this would make the constant - * pool overflow - */ - private char poolIndex(String sequence) - { - Integer i = (Integer) poolEntries.get(sequence); - if (i == null) - { - // pool starts at index 1 - int size = poolEntries.size() + 1; - if (size >= 65535) - throw new IllegalArgumentException("exceeds VM limitations"); - i = new Integer(size); - poolEntries.put(sequence, i); - pool.append(sequence); - } - return (char) i.intValue(); - } - } // class ClassFactory -} diff --git a/libjava/java/lang/reflect/ReflectPermission.java b/libjava/java/lang/reflect/ReflectPermission.java deleted file mode 100644 index 56eccf8130c..00000000000 --- a/libjava/java/lang/reflect/ReflectPermission.java +++ /dev/null @@ -1,102 +0,0 @@ -/* ReflectPermission.java - named permission for reflaction - Copyright (C) 2000, 2001, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.lang.reflect; - -import java.security.BasicPermission; - -/* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3 - * "The Java Language Specification", ISBN 0-201-63451-1 - * plus online API docs for JDK 1.2 beta from http://www.javasoft.com. - */ - -/** - * This class implements permissions for reflection. This is a named - * permission, and the only defined name is suppressAccessChecks, which - * allows suppression of normal Java objects when using reflection. - * - * <table> - * <tr> - * <th>Permission Target Name</th> - * <th>What Permission Allows</th> - * <th>Risk of Allowing Permission</th> - * </tr> - * <tr> - * <td><code>suppressAccessChecks</code></td> - * <td>Ability to access fields, invoke methods, and construct objects - * via reflection, including non-public members in contexts where - * such access is not legal at compile-time.</td> - * <td>This is dangerous. It exposes possibly confidential information, - * and malicious code could interfere with the internals of the Virtual - * Machine by corrupting private data.</td> - * </tr> - * </table> - * - * @author Tom Tromey (tromey@redhat.com) - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.2 - * @status updated to 1.4 - */ -public final class ReflectPermission - extends BasicPermission -{ - /** - * Compatible with JDK 1.2. - */ - private static final long serialVersionUID = 7412737110241507485L; - - /** - * Construct a ReflectPermission with the given name. - * - * @param name The permission name - */ - public ReflectPermission(String name) - { - super(name); - } - - /** - * Construct a ReflectPermission with the given name. - * - * @param name The permission name - * @param actions The actions; this is ignored and should be null - */ - public ReflectPermission(String name, String actions) - { - super(name, actions); - } -} diff --git a/libjava/java/lang/reflect/UndeclaredThrowableException.java b/libjava/java/lang/reflect/UndeclaredThrowableException.java deleted file mode 100644 index 6d5a8008459..00000000000 --- a/libjava/java/lang/reflect/UndeclaredThrowableException.java +++ /dev/null @@ -1,128 +0,0 @@ -/* UndeclaredThrowableException.java -- wraps an undeclared checked exception - thrown by a Proxy invocation handler - Copyright (C) 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.lang.reflect; - -/** - * This exception class is thrown by a {@link Proxy} instance if - * the {@link InvocationHandler#invoke(Object, Method, Object[]) invoke} - * method of that instance's InvocationHandler attempts to throw an - * exception that not declared by the throws clauses of all of the - * interface methods that the proxy instance is implementing. - * - * <p>When thrown by Proxy, this class will always wrap a checked - * exception, never {@link Error} or {@link RuntimeException}, - * which are unchecked. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @see Proxy - * @see InvocationHandler - * @since 1.3 - * @status updated to 1.4 - */ -public class UndeclaredThrowableException extends RuntimeException -{ - /** - * Compatible with JDK 1.3+. - */ - private static final long serialVersionUID = 330127114055056639L; - - /** - * The immutable exception that this wraps. This field is redundant - * with {@link Throwable#cause}, but is necessary for serial compatibility. - * - * @serial the chained exception - */ - private final Throwable undeclaredThrowable; - - /** - * Wraps the given checked exception into a RuntimeException, with no - * detail message. {@link Throwable#initCause(Throwable)} will fail - * on this instance. - * - * @param cause the undeclared throwable that caused this exception, - * may be null - */ - public UndeclaredThrowableException(Throwable cause) - { - this(cause, null); - } - - /** - * Wraps the given checked exception into a RuntimeException, with the - * specified detail message. {@link Throwable#initCause(Throwable)} will - * fail on this instance. - * - * @param cause the undeclared throwable that caused this exception, - * may be null - * @param message the message, may be null - */ - public UndeclaredThrowableException(Throwable cause, String message) - { - super(message, cause); - undeclaredThrowable = cause; - } - - /** - * Returns the cause of this exception. If this exception was created - * by a {@link Proxy} instance, it will be a non-null checked - * exception. This method pre-dates exception chaining, and is now - * simply a longer way to call <code>getCause()</code>. - * - * @return the cause of this exception, may be null - * @see #getCause() - */ - public Throwable getUndeclaredThrowable() - { - return undeclaredThrowable; - } - - /** - * Returns the cause of this exception. If this exception was created - * by a {@link Proxy} instance, it will be a non-null checked - * exception. - * - * @return the cause of this exception, may be null - * @since 1.4 - */ - public Throwable getCause() - { - return undeclaredThrowable; - } -} diff --git a/libjava/java/lang/s_atan.c b/libjava/java/lang/s_atan.c deleted file mode 100644 index 2ee74585423..00000000000 --- a/libjava/java/lang/s_atan.c +++ /dev/null @@ -1,181 +0,0 @@ - -/* @(#)s_atan.c 5.1 93/09/24 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - * - */ - -/* -FUNCTION - <<atan>>, <<atanf>>---arc tangent - -INDEX - atan -INDEX - atanf - -ANSI_SYNOPSIS - #include <math.h> - double atan(double <[x]>); - float atanf(float <[x]>); - -TRAD_SYNOPSIS - #include <math.h> - double atan(<[x]>); - double <[x]>; - - float atanf(<[x]>); - float <[x]>; - -DESCRIPTION - -<<atan>> computes the inverse tangent (arc tangent) of the input value. - -<<atanf>> is identical to <<atan>>, save that it operates on <<floats>>. - -RETURNS -@ifinfo -<<atan>> returns a value in radians, in the range of -pi/2 to pi/2. -@end ifinfo -@tex -<<atan>> returns a value in radians, in the range of $-\pi/2$ to $\pi/2$. -@end tex - -PORTABILITY -<<atan>> is ANSI C. <<atanf>> is an extension. - -*/ - -/* atan(x) - * Method - * 1. Reduce x to positive by atan(x) = -atan(-x). - * 2. According to the integer k=4t+0.25 chopped, t=x, the argument - * is further reduced to one of the following intervals and the - * arctangent of t is evaluated by the corresponding formula: - * - * [0,7/16] atan(x) = t-t^3*(a1+t^2*(a2+...(a10+t^2*a11)...) - * [7/16,11/16] atan(x) = atan(1/2) + atan( (t-0.5)/(1+t/2) ) - * [11/16.19/16] atan(x) = atan( 1 ) + atan( (t-1)/(1+t) ) - * [19/16,39/16] atan(x) = atan(3/2) + atan( (t-1.5)/(1+1.5t) ) - * [39/16,INF] atan(x) = atan(INF) + atan( -1/t ) - * - * Constants: - * The hexadecimal values are the intended ones for the following - * constants. The decimal values may be used, provided that the - * compiler will convert from decimal to binary accurately enough - * to produce the hexadecimal values shown. - */ - -#include "fdlibm.h" - -#ifndef _DOUBLE_IS_32BITS - -#ifdef __STDC__ -static const double atanhi[] = { -#else -static double atanhi[] = { -#endif - 4.63647609000806093515e-01, /* atan(0.5)hi 0x3FDDAC67, 0x0561BB4F */ - 7.85398163397448278999e-01, /* atan(1.0)hi 0x3FE921FB, 0x54442D18 */ - 9.82793723247329054082e-01, /* atan(1.5)hi 0x3FEF730B, 0xD281F69B */ - 1.57079632679489655800e+00, /* atan(inf)hi 0x3FF921FB, 0x54442D18 */ -}; - -#ifdef __STDC__ -static const double atanlo[] = { -#else -static double atanlo[] = { -#endif - 2.26987774529616870924e-17, /* atan(0.5)lo 0x3C7A2B7F, 0x222F65E2 */ - 3.06161699786838301793e-17, /* atan(1.0)lo 0x3C81A626, 0x33145C07 */ - 1.39033110312309984516e-17, /* atan(1.5)lo 0x3C700788, 0x7AF0CBBD */ - 6.12323399573676603587e-17, /* atan(inf)lo 0x3C91A626, 0x33145C07 */ -}; - -#ifdef __STDC__ -static const double aT[] = { -#else -static double aT[] = { -#endif - 3.33333333333329318027e-01, /* 0x3FD55555, 0x5555550D */ - -1.99999999998764832476e-01, /* 0xBFC99999, 0x9998EBC4 */ - 1.42857142725034663711e-01, /* 0x3FC24924, 0x920083FF */ - -1.11111104054623557880e-01, /* 0xBFBC71C6, 0xFE231671 */ - 9.09088713343650656196e-02, /* 0x3FB745CD, 0xC54C206E */ - -7.69187620504482999495e-02, /* 0xBFB3B0F2, 0xAF749A6D */ - 6.66107313738753120669e-02, /* 0x3FB10D66, 0xA0D03D51 */ - -5.83357013379057348645e-02, /* 0xBFADDE2D, 0x52DEFD9A */ - 4.97687799461593236017e-02, /* 0x3FA97B4B, 0x24760DEB */ - -3.65315727442169155270e-02, /* 0xBFA2B444, 0x2C6A6C2F */ - 1.62858201153657823623e-02, /* 0x3F90AD3A, 0xE322DA11 */ -}; - -#ifdef __STDC__ - static const double -#else - static double -#endif -one = 1.0, -huge = 1.0e300; - -#ifdef __STDC__ - double atan(double x) -#else - double atan(x) - double x; -#endif -{ - double w,s1,s2,z; - int32_t ix,hx,id; - - GET_HIGH_WORD(hx,x); - ix = hx&0x7fffffff; - if(ix>=0x44100000) { /* if |x| >= 2^66 */ - uint32_t low; - GET_LOW_WORD(low,x); - if(ix>0x7ff00000|| - (ix==0x7ff00000&&(low!=0))) - return x+x; /* NaN */ - if(hx>0) return atanhi[3]+atanlo[3]; - else return -atanhi[3]-atanlo[3]; - } if (ix < 0x3fdc0000) { /* |x| < 0.4375 */ - if (ix < 0x3e200000) { /* |x| < 2^-29 */ - if(huge+x>one) return x; /* raise inexact */ - } - id = -1; - } else { - x = fabs(x); - if (ix < 0x3ff30000) { /* |x| < 1.1875 */ - if (ix < 0x3fe60000) { /* 7/16 <=|x|<11/16 */ - id = 0; x = (2.0*x-one)/(2.0+x); - } else { /* 11/16<=|x|< 19/16 */ - id = 1; x = (x-one)/(x+one); - } - } else { - if (ix < 0x40038000) { /* |x| < 2.4375 */ - id = 2; x = (x-1.5)/(one+1.5*x); - } else { /* 2.4375 <= |x| < 2^66 */ - id = 3; x = -1.0/x; - } - }} - /* end of argument reduction */ - z = x*x; - w = z*z; - /* break sum from i=0 to 10 aT[i]z**(i+1) into odd and even poly */ - s1 = z*(aT[0]+w*(aT[2]+w*(aT[4]+w*(aT[6]+w*(aT[8]+w*aT[10]))))); - s2 = w*(aT[1]+w*(aT[3]+w*(aT[5]+w*(aT[7]+w*aT[9])))); - if (id<0) return x - x*(s1+s2); - else { - z = atanhi[id] - ((x*(s1+s2) - atanlo[id]) - x); - return (hx<0)? -z:z; - } -} - -#endif /* _DOUBLE_IS_32BITS */ diff --git a/libjava/java/lang/s_ceil.c b/libjava/java/lang/s_ceil.c deleted file mode 100644 index 250373b40d1..00000000000 --- a/libjava/java/lang/s_ceil.c +++ /dev/null @@ -1,80 +0,0 @@ - -/* @(#)s_ceil.c 5.1 93/09/24 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* - * ceil(x) - * Return x rounded toward -inf to integral value - * Method: - * Bit twiddling. - * Exception: - * Inexact flag raised if x not equal to ceil(x). - */ - -#include "fdlibm.h" - -#ifndef _DOUBLE_IS_32BITS - -#ifdef __STDC__ -static const double huge = 1.0e300; -#else -static double huge = 1.0e300; -#endif - -#ifdef __STDC__ - double ceil(double x) -#else - double ceil(x) - double x; -#endif -{ - int32_t i0,i1,j0; - uint32_t i,j; - EXTRACT_WORDS(i0,i1,x); - j0 = ((i0>>20)&0x7ff)-0x3ff; - if(j0<20) { - if(j0<0) { /* raise inexact if x != 0 */ - if(huge+x>0.0) {/* return 0*sign(x) if |x|<1 */ - if(i0<0) {i0=0x80000000;i1=0;} - else if((i0|i1)!=0) { i0=0x3ff00000;i1=0;} - } - } else { - i = (0x000fffff)>>j0; - if(((i0&i)|i1)==0) return x; /* x is integral */ - if(huge+x>0.0) { /* raise inexact flag */ - if(i0>0) i0 += (0x00100000)>>j0; - i0 &= (~i); i1=0; - } - } - } else if (j0>51) { - if(j0==0x400) return x+x; /* inf or NaN */ - else return x; /* x is integral */ - } else { - i = ((uint32_t)(0xffffffff))>>(j0-20); - if((i1&i)==0) return x; /* x is integral */ - if(huge+x>0.0) { /* raise inexact flag */ - if(i0>0) { - if(j0==20) i0+=1; - else { - j = i1 + (1<<(52-j0)); - if(j<(uint32_t)i1) i0+=1; /* got a carry */ - i1 = j; - } - } - i1 &= (~i); - } - } - INSERT_WORDS(x,i0,i1); - return x; -} - -#endif /* _DOUBLE_IS_32BITS */ diff --git a/libjava/java/lang/s_copysign.c b/libjava/java/lang/s_copysign.c deleted file mode 100644 index 4804df130dc..00000000000 --- a/libjava/java/lang/s_copysign.c +++ /dev/null @@ -1,82 +0,0 @@ - -/* @(#)s_copysign.c 5.1 93/09/24 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* -FUNCTION -<<copysign>>, <<copysignf>>---sign of <[y]>, magnitude of <[x]> - -INDEX - copysign -INDEX - copysignf - -ANSI_SYNOPSIS - #include <math.h> - double copysign (double <[x]>, double <[y]>); - float copysignf (float <[x]>, float <[y]>); - -TRAD_SYNOPSIS - #include <math.h> - double copysign (<[x]>, <[y]>) - double <[x]>; - double <[y]>; - - float copysignf (<[x]>, <[y]>) - float <[x]>; - float <[y]>; - -DESCRIPTION -<<copysign>> constructs a number with the magnitude (absolute value) -of its first argument, <[x]>, and the sign of its second argument, -<[y]>. - -<<copysignf>> does the same thing; the two functions differ only in -the type of their arguments and result. - -RETURNS -<<copysign>> returns a <<double>> with the magnitude of -<[x]> and the sign of <[y]>. -<<copysignf>> returns a <<float>> with the magnitude of -<[x]> and the sign of <[y]>. - -PORTABILITY -<<copysign>> is not required by either ANSI C or the System V Interface -Definition (Issue 2). - -*/ - -/* - * copysign(double x, double y) - * copysign(x,y) returns a value with the magnitude of x and - * with the sign bit of y. - */ - -#include "fdlibm.h" - -#ifndef _DOUBLE_IS_32BITS - -#ifdef __STDC__ - double copysign(double x, double y) -#else - double copysign(x,y) - double x,y; -#endif -{ - uint32_t hx,hy; - GET_HIGH_WORD(hx,x); - GET_HIGH_WORD(hy,y); - SET_HIGH_WORD(x,(hx&0x7fffffff)|(hy&0x80000000)); - return x; -} - -#endif /* _DOUBLE_IS_32BITS */ diff --git a/libjava/java/lang/s_cos.c b/libjava/java/lang/s_cos.c deleted file mode 100644 index be1538d4c0b..00000000000 --- a/libjava/java/lang/s_cos.c +++ /dev/null @@ -1,82 +0,0 @@ - -/* @(#)s_cos.c 5.1 93/09/24 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* cos(x) - * Return cosine function of x. - * - * kernel function: - * __kernel_sin ... sine function on [-pi/4,pi/4] - * __kernel_cos ... cosine function on [-pi/4,pi/4] - * __ieee754_rem_pio2 ... argument reduction routine - * - * Method. - * Let S,C and T denote the sin, cos and tan respectively on - * [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2 - * in [-pi/4 , +pi/4], and let n = k mod 4. - * We have - * - * n sin(x) cos(x) tan(x) - * ---------------------------------------------------------- - * 0 S C T - * 1 C -S -1/T - * 2 -S -C T - * 3 -C S -1/T - * ---------------------------------------------------------- - * - * Special cases: - * Let trig be any of sin, cos, or tan. - * trig(+-INF) is NaN, with signals; - * trig(NaN) is that NaN; - * - * Accuracy: - * TRIG(x) returns trig(x) nearly rounded - */ - -#include "fdlibm.h" - -#ifndef _DOUBLE_IS_32BITS - -#ifdef __STDC__ - double cos(double x) -#else - double cos(x) - double x; -#endif -{ - double y[2],z=0.0; - int32_t n,ix; - - /* High word of x. */ - GET_HIGH_WORD(ix,x); - - /* |x| ~< pi/4 */ - ix &= 0x7fffffff; - if(ix <= 0x3fe921fb) return __kernel_cos(x,z); - - /* cos(Inf or NaN) is NaN */ - else if (ix>=0x7ff00000) return x-x; - - /* argument reduction needed */ - else { - n = __ieee754_rem_pio2(x,y); - switch(n&3) { - case 0: return __kernel_cos(y[0],y[1]); - case 1: return -__kernel_sin(y[0],y[1],1); - case 2: return -__kernel_cos(y[0],y[1]); - default: - return __kernel_sin(y[0],y[1],1); - } - } -} - -#endif /* _DOUBLE_IS_32BITS */ diff --git a/libjava/java/lang/s_fabs.c b/libjava/java/lang/s_fabs.c deleted file mode 100644 index dfee33fecdb..00000000000 --- a/libjava/java/lang/s_fabs.c +++ /dev/null @@ -1,73 +0,0 @@ - -/* @(#)s_fabs.c 5.1 93/09/24 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* -FUNCTION - <<fabs>>, <<fabsf>>---absolute value (magnitude) -INDEX - fabs -INDEX - fabsf - -ANSI_SYNOPSIS - #include <math.h> - double fabs(double <[x]>); - float fabsf(float <[x]>); - -TRAD_SYNOPSIS - #include <math.h> - double fabs(<[x]>) - double <[x]>; - - float fabsf(<[x]>) - float <[x]>; - -DESCRIPTION -<<fabs>> and <<fabsf>> calculate -@tex -$|x|$, -@end tex -the absolute value (magnitude) of the argument <[x]>, by direct -manipulation of the bit representation of <[x]>. - -RETURNS -The calculated value is returned. No errors are detected. - -PORTABILITY -<<fabs>> is ANSI. -<<fabsf>> is an extension. - -*/ - -/* - * fabs(x) returns the absolute value of x. - */ - -#include "fdlibm.h" - -#ifndef _DOUBLE_IS_32BITS - -#ifdef __STDC__ - double fabs(double x) -#else - double fabs(x) - double x; -#endif -{ - uint32_t high; - GET_HIGH_WORD(high,x); - SET_HIGH_WORD(x,high&0x7fffffff); - return x; -} - -#endif /* _DOUBLE_IS_32BITS */ diff --git a/libjava/java/lang/s_floor.c b/libjava/java/lang/s_floor.c deleted file mode 100644 index 77e39cb7de0..00000000000 --- a/libjava/java/lang/s_floor.c +++ /dev/null @@ -1,134 +0,0 @@ - -/* @(#)s_floor.c 5.1 93/09/24 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* -FUNCTION -<<floor>>, <<floorf>>, <<ceil>>, <<ceilf>>---floor and ceiling -INDEX - floor -INDEX - floorf -INDEX - ceil -INDEX - ceilf - -ANSI_SYNOPSIS - #include <math.h> - double floor(double <[x]>); - float floorf(float <[x]>); - double ceil(double <[x]>); - float ceilf(float <[x]>); - -TRAD_SYNOPSIS - #include <math.h> - double floor(<[x]>) - double <[x]>; - float floorf(<[x]>) - float <[x]>; - double ceil(<[x]>) - double <[x]>; - float ceilf(<[x]>) - float <[x]>; - -DESCRIPTION -<<floor>> and <<floorf>> find -@tex -$\lfloor x \rfloor$, -@end tex -the nearest integer less than or equal to <[x]>. -<<ceil>> and <<ceilf>> find -@tex -$\lceil x\rceil$, -@end tex -the nearest integer greater than or equal to <[x]>. - -RETURNS -<<floor>> and <<ceil>> return the integer result as a double. -<<floorf>> and <<ceilf>> return the integer result as a float. - -PORTABILITY -<<floor>> and <<ceil>> are ANSI. -<<floorf>> and <<ceilf>> are extensions. - - -*/ - -/* - * floor(x) - * Return x rounded toward -inf to integral value - * Method: - * Bit twiddling. - * Exception: - * Inexact flag raised if x not equal to floor(x). - */ - -#include "fdlibm.h" - -#ifndef _DOUBLE_IS_32BITS - -#ifdef __STDC__ -static const double huge = 1.0e300; -#else -static double huge = 1.0e300; -#endif - -#ifdef __STDC__ - double floor(double x) -#else - double floor(x) - double x; -#endif -{ - int32_t i0,i1,j0; - uint32_t i,j; - EXTRACT_WORDS(i0,i1,x); - j0 = ((i0>>20)&0x7ff)-0x3ff; - if(j0<20) { - if(j0<0) { /* raise inexact if x != 0 */ - if(huge+x>0.0) {/* return 0*sign(x) if |x|<1 */ - if(i0>=0) {i0=i1=0;} - else if(((i0&0x7fffffff)|i1)!=0) - { i0=0xbff00000;i1=0;} - } - } else { - i = (0x000fffff)>>j0; - if(((i0&i)|i1)==0) return x; /* x is integral */ - if(huge+x>0.0) { /* raise inexact flag */ - if(i0<0) i0 += (0x00100000)>>j0; - i0 &= (~i); i1=0; - } - } - } else if (j0>51) { - if(j0==0x400) return x+x; /* inf or NaN */ - else return x; /* x is integral */ - } else { - i = ((uint32_t)(0xffffffff))>>(j0-20); - if((i1&i)==0) return x; /* x is integral */ - if(huge+x>0.0) { /* raise inexact flag */ - if(i0<0) { - if(j0==20) i0+=1; - else { - j = i1+(1<<(52-j0)); - if(j<(uint32_t)i1) i0 +=1 ; /* got a carry */ - i1=j; - } - } - i1 &= (~i); - } - } - INSERT_WORDS(x,i0,i1); - return x; -} - -#endif /* _DOUBLE_IS_32BITS */ diff --git a/libjava/java/lang/s_rint.c b/libjava/java/lang/s_rint.c deleted file mode 100644 index 5d3f8114e2b..00000000000 --- a/libjava/java/lang/s_rint.c +++ /dev/null @@ -1,87 +0,0 @@ - -/* @(#)s_rint.c 5.1 93/09/24 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* - * rint(x) - * Return x rounded to integral value according to the prevailing - * rounding mode. - * Method: - * Using floating addition. - * Exception: - * Inexact flag raised if x not equal to rint(x). - */ - -#include "fdlibm.h" - -#ifndef _DOUBLE_IS_32BITS - -#ifdef __STDC__ -static const double -#else -static double -#endif -TWO52[2]={ - 4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */ - -4.50359962737049600000e+15, /* 0xC3300000, 0x00000000 */ -}; - -#ifdef __STDC__ - double rint(double x) -#else - double rint(x) - double x; -#endif -{ - int32_t i0,j0,sx; - uint32_t i,i1; - double t; - volatile double w; - EXTRACT_WORDS(i0,i1,x); - sx = (i0>>31)&1; - j0 = ((i0>>20)&0x7ff)-0x3ff; - if(j0<20) { - if(j0<0) { - if(((i0&0x7fffffff)|i1)==0) return x; - i1 |= (i0&0x0fffff); - i0 &= 0xfffe0000; - i0 |= ((i1|-i1)>>12)&0x80000; - SET_HIGH_WORD(x,i0); - w = TWO52[sx]+x; - t = w-TWO52[sx]; - GET_HIGH_WORD(i0,t); - SET_HIGH_WORD(t,(i0&0x7fffffff)|(sx<<31)); - return t; - } else { - i = (0x000fffff)>>j0; - if(((i0&i)|i1)==0) return x; /* x is integral */ - i>>=1; - if(((i0&i)|i1)!=0) { - if(j0==19) i1 = 0x40000000; else - i0 = (i0&(~i))|((0x20000)>>j0); - } - } - } else if (j0>51) { - if(j0==0x400) return x+x; /* inf or NaN */ - else return x; /* x is integral */ - } else { - i = ((uint32_t)(0xffffffff))>>(j0-20); - if((i1&i)==0) return x; /* x is integral */ - i>>=1; - if((i1&i)!=0) i1 = (i1&(~i))|((0x40000000)>>(j0-20)); - } - INSERT_WORDS(x,i0,i1); - w = TWO52[sx]+x; - return w-TWO52[sx]; -} - -#endif /* _DOUBLE_IS_32BITS */ diff --git a/libjava/java/lang/s_scalbn.c b/libjava/java/lang/s_scalbn.c deleted file mode 100644 index 36ee88981ba..00000000000 --- a/libjava/java/lang/s_scalbn.c +++ /dev/null @@ -1,104 +0,0 @@ - -/* @(#)s_scalbn.c 5.1 93/09/24 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* -FUNCTION -<<scalbn>>, <<scalbnf>>---scale by integer -INDEX - scalbn -INDEX - scalbnf - -ANSI_SYNOPSIS - #include <math.h> - double scalbn(double <[x]>, int <[y]>); - float scalbnf(float <[x]>, int <[y]>); - -TRAD_SYNOPSIS - #include <math.h> - double scalbn(<[x]>,<[y]>) - double <[x]>; - int <[y]>; - float scalbnf(<[x]>,<[y]>) - float <[x]>; - int <[y]>; - -DESCRIPTION -<<scalbn>> and <<scalbnf>> scale <[x]> by <[n]>, returning <[x]> times -2 to the power <[n]>. The result is computed by manipulating the -exponent, rather than by actually performing an exponentiation or -multiplication. - -RETURNS -<[x]> times 2 to the power <[n]>. - -PORTABILITY -Neither <<scalbn>> nor <<scalbnf>> is required by ANSI C or by the System V -Interface Definition (Issue 2). - -*/ - -/* - * scalbn (double x, int n) - * scalbn(x,n) returns x* 2**n computed by exponent - * manipulation rather than by actually performing an - * exponentiation or a multiplication. - */ - -#include "fdlibm.h" - -#ifndef _DOUBLE_IS_32BITS - -#ifdef __STDC__ -static const double -#else -static double -#endif -two54 = 1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */ -twom54 = 5.55111512312578270212e-17, /* 0x3C900000, 0x00000000 */ -huge = 1.0e+300, -tiny = 1.0e-300; - -#ifdef __STDC__ - double scalbn (double x, int n) -#else - double scalbn (x,n) - double x; int n; -#endif -{ - int32_t k,hx,lx; - EXTRACT_WORDS(hx,lx,x); - k = (hx&0x7ff00000)>>20; /* extract exponent */ - if (k==0) { /* 0 or subnormal x */ - if ((lx|(hx&0x7fffffff))==0) return x; /* +-0 */ - x *= two54; - GET_HIGH_WORD(hx,x); - k = ((hx&0x7ff00000)>>20) - 54; - if (n< -50000) return tiny*x; /*underflow*/ - } - if (k==0x7ff) return x+x; /* NaN or Inf */ - k = k+n; - if (k > 0x7fe) return huge*copysign(huge,x); /* overflow */ - if (k > 0) /* normal result */ - {SET_HIGH_WORD(x,(hx&0x800fffff)|(k<<20)); return x;} - if (k <= -54) { - if (n > 50000) /* in case integer overflow in n+k */ - return huge*copysign(huge,x); /*overflow*/ - else return tiny*copysign(tiny,x); /*underflow*/ - } - k += 54; /* subnormal result */ - SET_HIGH_WORD(x,(hx&0x800fffff)|(k<<20)); - return x*twom54; -} - -#endif /* _DOUBLE_IS_32BITS */ diff --git a/libjava/java/lang/s_sin.c b/libjava/java/lang/s_sin.c deleted file mode 100644 index d315455549c..00000000000 --- a/libjava/java/lang/s_sin.c +++ /dev/null @@ -1,132 +0,0 @@ - -/* @(#)s_sin.c 5.1 93/09/24 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* -FUNCTION - <<sin>>, <<sinf>>, <<cos>>, <<cosf>>---sine or cosine -INDEX -sin -INDEX -sinf -INDEX -cos -INDEX -cosf -ANSI_SYNOPSIS - #include <math.h> - double sin(double <[x]>); - float sinf(float <[x]>); - double cos(double <[x]>); - float cosf(float <[x]>); - -TRAD_SYNOPSIS - #include <math.h> - double sin(<[x]>) - double <[x]>; - float sinf(<[x]>) - float <[x]>; - - double cos(<[x]>) - double <[x]>; - float cosf(<[x]>) - float <[x]>; - -DESCRIPTION - <<sin>> and <<cos>> compute (respectively) the sine and cosine - of the argument <[x]>. Angles are specified in radians. - - <<sinf>> and <<cosf>> are identical, save that they take and - return <<float>> values. - - -RETURNS - The sine or cosine of <[x]> is returned. - -PORTABILITY - <<sin>> and <<cos>> are ANSI C. - <<sinf>> and <<cosf>> are extensions. - -QUICKREF - sin ansi pure - sinf - pure -*/ - -/* sin(x) - * Return sine function of x. - * - * kernel function: - * __kernel_sin ... sine function on [-pi/4,pi/4] - * __kernel_cos ... cose function on [-pi/4,pi/4] - * __ieee754_rem_pio2 ... argument reduction routine - * - * Method. - * Let S,C and T denote the sin, cos and tan respectively on - * [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2 - * in [-pi/4 , +pi/4], and let n = k mod 4. - * We have - * - * n sin(x) cos(x) tan(x) - * ---------------------------------------------------------- - * 0 S C T - * 1 C -S -1/T - * 2 -S -C T - * 3 -C S -1/T - * ---------------------------------------------------------- - * - * Special cases: - * Let trig be any of sin, cos, or tan. - * trig(+-INF) is NaN, with signals; - * trig(NaN) is that NaN; - * - * Accuracy: - * TRIG(x) returns trig(x) nearly rounded - */ - -#include "fdlibm.h" - -#ifndef _DOUBLE_IS_32BITS - -#ifdef __STDC__ - double sin(double x) -#else - double sin(x) - double x; -#endif -{ - double y[2],z=0.0; - int32_t n,ix; - - /* High word of x. */ - GET_HIGH_WORD(ix,x); - - /* |x| ~< pi/4 */ - ix &= 0x7fffffff; - if(ix <= 0x3fe921fb) return __kernel_sin(x,z,0); - - /* sin(Inf or NaN) is NaN */ - else if (ix>=0x7ff00000) return x-x; - - /* argument reduction needed */ - else { - n = __ieee754_rem_pio2(x,y); - switch(n&3) { - case 0: return __kernel_sin(y[0],y[1],1); - case 1: return __kernel_cos(y[0],y[1]); - case 2: return -__kernel_sin(y[0],y[1],1); - default: - return -__kernel_cos(y[0],y[1]); - } - } -} - -#endif /* _DOUBLE_IS_32BITS */ diff --git a/libjava/java/lang/s_tan.c b/libjava/java/lang/s_tan.c deleted file mode 100644 index 20995fcbdee..00000000000 --- a/libjava/java/lang/s_tan.c +++ /dev/null @@ -1,114 +0,0 @@ - -/* @(#)s_tan.c 5.1 93/09/24 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - - -/* - -FUNCTION - <<tan>>, <<tanf>>---tangent - -INDEX -tan -INDEX -tanf - -ANSI_SYNOPSIS - #include <math.h> - double tan(double <[x]>); - float tanf(float <[x]>); - -TRAD_SYNOPSIS - #include <math.h> - double tan(<[x]>) - double <[x]>; - - float tanf(<[x]>) - float <[x]>; - - -DESCRIPTION -<<tan>> computes the tangent of the argument <[x]>. -Angles are specified in radians. - -<<tanf>> is identical, save that it takes and returns <<float>> values. - -RETURNS -The tangent of <[x]> is returned. - -PORTABILITY -<<tan>> is ANSI. <<tanf>> is an extension. -*/ - -/* tan(x) - * Return tangent function of x. - * - * kernel function: - * __kernel_tan ... tangent function on [-pi/4,pi/4] - * __ieee754_rem_pio2 ... argument reduction routine - * - * Method. - * Let S,C and T denote the sin, cos and tan respectively on - * [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2 - * in [-pi/4 , +pi/4], and let n = k mod 4. - * We have - * - * n sin(x) cos(x) tan(x) - * ---------------------------------------------------------- - * 0 S C T - * 1 C -S -1/T - * 2 -S -C T - * 3 -C S -1/T - * ---------------------------------------------------------- - * - * Special cases: - * Let trig be any of sin, cos, or tan. - * trig(+-INF) is NaN, with signals; - * trig(NaN) is that NaN; - * - * Accuracy: - * TRIG(x) returns trig(x) nearly rounded - */ - -#include "fdlibm.h" - -#ifndef _DOUBLE_IS_32BITS - -#ifdef __STDC__ - double tan(double x) -#else - double tan(x) - double x; -#endif -{ - double y[2],z=0.0; - int32_t n,ix; - - /* High word of x. */ - GET_HIGH_WORD(ix,x); - - /* |x| ~< pi/4 */ - ix &= 0x7fffffff; - if(ix <= 0x3fe921fb) return __kernel_tan(x,z,1); - - /* tan(Inf or NaN) is NaN */ - else if (ix>=0x7ff00000) return x-x; /* NaN */ - - /* argument reduction needed */ - else { - n = __ieee754_rem_pio2(x,y); - return __kernel_tan(y[0],y[1],1-((n&1)<<1)); /* 1 -- n even - -1 -- n odd */ - } -} - -#endif /* _DOUBLE_IS_32BITS */ diff --git a/libjava/java/lang/sf_fabs.c b/libjava/java/lang/sf_fabs.c deleted file mode 100644 index 34f88afc4e6..00000000000 --- a/libjava/java/lang/sf_fabs.c +++ /dev/null @@ -1,47 +0,0 @@ -/* sf_fabs.c -- float version of s_fabs.c. - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - */ - -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* - * fabsf(x) returns the absolute value of x. - */ - -#include "fdlibm.h" - -#ifdef __STDC__ - float fabsf(float x) -#else - float fabsf(x) - float x; -#endif -{ - uint32_t ix; - GET_FLOAT_WORD(ix,x); - SET_FLOAT_WORD(x,ix&0x7fffffff); - return x; -} - -#ifdef _DOUBLE_IS_32BITS - -#ifdef __STDC__ - double fabs(double x) -#else - double fabs(x) - double x; -#endif -{ - return (double) fabsf((float) x); -} - -#endif /* defined(_DOUBLE_IS_32BITS) */ diff --git a/libjava/java/lang/sf_rint.c b/libjava/java/lang/sf_rint.c deleted file mode 100644 index f442072874e..00000000000 --- a/libjava/java/lang/sf_rint.c +++ /dev/null @@ -1,80 +0,0 @@ -/* sf_rint.c -- float version of s_rint.c. - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - */ - -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#include "fdlibm.h" - -#ifdef __STDC__ -static const float -#else -static float -#endif -TWO23[2]={ - 8.3886080000e+06, /* 0x4b000000 */ - -8.3886080000e+06, /* 0xcb000000 */ -}; - -#ifdef __STDC__ - float rintf(float x) -#else - float rintf(x) - float x; -#endif -{ - int32_t i0,j0,sx; - uint32_t i,i1; - float w,t; - GET_FLOAT_WORD(i0,x); - sx = (i0>>31)&1; - j0 = ((i0>>23)&0xff)-0x7f; - if(j0<23) { - if(j0<0) { - if((i0&0x7fffffff)==0) return x; - i1 = (i0&0x07fffff); - i0 &= 0xfff00000; - i0 |= ((i1|-i1)>>9)&0x400000; - SET_FLOAT_WORD(x,i0); - w = TWO23[sx]+x; - t = w-TWO23[sx]; - GET_FLOAT_WORD(i0,t); - SET_FLOAT_WORD(t,(i0&0x7fffffff)|(sx<<31)); - return t; - } else { - i = (0x007fffff)>>j0; - if((i0&i)==0) return x; /* x is integral */ - i>>=1; - if((i0&i)!=0) i0 = (i0&(~i))|((0x100000)>>j0); - } - } else { - if(j0==0x80) return x+x; /* inf or NaN */ - else return x; /* x is integral */ - } - SET_FLOAT_WORD(x,i0); - w = TWO23[sx]+x; - return w-TWO23[sx]; -} - -#ifdef _DOUBLE_IS_32BITS - -#ifdef __STDC__ - double rint(double x) -#else - double rint(x) - double x; -#endif -{ - return (double) rintf((float) x); -} - -#endif /* defined(_DOUBLE_IS_32BITS) */ diff --git a/libjava/java/lang/strtod.c b/libjava/java/lang/strtod.c deleted file mode 100644 index b3e09124721..00000000000 --- a/libjava/java/lang/strtod.c +++ /dev/null @@ -1,719 +0,0 @@ -/* -FUNCTION - <<strtod>>, <<strtodf>>---string to double or float - -INDEX - strtod -INDEX - _strtod_r -INDEX - strtodf - -ANSI_SYNOPSIS - #include <stdlib.h> - double strtod(const char *<[str]>, char **<[tail]>); - float strtodf(const char *<[str]>, char **<[tail]>); - - double _strtod_r(void *<[reent]>, - const char *<[str]>, char **<[tail]>); - -TRAD_SYNOPSIS - #include <stdlib.h> - double strtod(<[str]>,<[tail]>) - char *<[str]>; - char **<[tail]>; - - float strtodf(<[str]>,<[tail]>) - char *<[str]>; - char **<[tail]>; - - double _strtod_r(<[reent]>,<[str]>,<[tail]>) - char *<[reent]>; - char *<[str]>; - char **<[tail]>; - -DESCRIPTION - The function <<strtod>> parses the character string <[str]>, - producing a substring which can be converted to a double - value. The substring converted is the longest initial - subsequence of <[str]>, beginning with the first - non-whitespace character, that has the format: - .[+|-]<[digits]>[.][<[digits]>][(e|E)[+|-]<[digits]>] - The substring contains no characters if <[str]> is empty, consists - entirely of whitespace, or if the first non-whitespace - character is something other than <<+>>, <<->>, <<.>>, or a - digit. If the substring is empty, no conversion is done, and - the value of <[str]> is stored in <<*<[tail]>>>. Otherwise, - the substring is converted, and a pointer to the final string - (which will contain at least the terminating null character of - <[str]>) is stored in <<*<[tail]>>>. If you want no - assignment to <<*<[tail]>>>, pass a null pointer as <[tail]>. - <<strtodf>> is identical to <<strtod>> except for its return type. - - This implementation returns the nearest machine number to the - input decimal string. Ties are broken by using the IEEE - round-even rule. - - The alternate function <<_strtod_r>> is a reentrant version. - The extra argument <[reent]> is a pointer to a reentrancy structure. - -RETURNS - <<strtod>> returns the converted substring value, if any. If - no conversion could be performed, 0 is returned. If the - correct value is out of the range of representable values, - plus or minus <<HUGE_VAL>> is returned, and <<ERANGE>> is - stored in errno. If the correct value would cause underflow, 0 - is returned and <<ERANGE>> is stored in errno. - -Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>, -<<lseek>>, <<read>>, <<sbrk>>, <<write>>. -*/ - -/**************************************************************** - * - * The author of this software is David M. Gay. - * - * Copyright (c) 1991 by AT&T. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose without fee is hereby granted, provided that this entire notice - * is included in all copies of any software which is or includes a copy - * or modification of this software and in all copies of the supporting - * documentation for such software. - * - * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED - * WARRANTY. IN PARTICULAR, NEITHER THE AUTHOR NOR AT&T MAKES ANY - * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY - * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. - * - ***************************************************************/ - -/* Please send bug reports to - David M. Gay - AT&T Bell Laboratories, Room 2C-463 - 600 Mountain Avenue - Murray Hill, NJ 07974-2070 - U.S.A. - dmg@research.att.com or research!dmg - */ - -#include <string.h> -#include <float.h> -#include <errno.h> -#include "mprec.h" - -double -_DEFUN (_strtod_r, (ptr, s00, se), - struct _Jv_reent *ptr _AND - _CONST char *s00 _AND - char **se) -{ - int bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, dsign, e1, esign, i, j, - k, nd, nd0, nf, nz, nz0, sign; - int digits = 0; /* Number of digits found in fraction part. */ - long e; - _CONST char *s, *s0, *s1; - double aadj, aadj1, adj; - long L; - unsigned long y, z; - union double_union rv, rv0; - - _Jv_Bigint *bb = NULL, *bb1, *bd = NULL, *bd0, *bs = NULL, *delta = NULL; - sign = nz0 = nz = 0; - rv.d = 0.; - for (s = s00;; s++) - switch (*s) - { - case '-': - sign = 1; - /* no break */ - case '+': - if (*++s) - goto break2; - /* no break */ - case 0: - s = s00; - goto ret; - case '\t': - case '\n': - case '\v': - case '\f': - case '\r': - case ' ': - continue; - default: - goto break2; - } -break2: - if (*s == '0') - { - digits++; - nz0 = 1; - while (*++s == '0') - digits++; - if (!*s) - goto ret; - } - s0 = s; - y = z = 0; - for (nd = nf = 0; (c = *s) >= '0' && c <= '9'; nd++, s++) - { - digits++; - if (nd < 9) - y = 10 * y + c - '0'; - else if (nd < 16) - z = 10 * z + c - '0'; - } - nd0 = nd; - if (c == '.') - { - c = *++s; - if (!nd) - { - for (; c == '0'; c = *++s) - { - digits++; - nz++; - } - if (c > '0' && c <= '9') - { - digits++; - s0 = s; - nf += nz; - nz = 0; - goto have_dig; - } - goto dig_done; - } - for (; c >= '0' && c <= '9'; c = *++s) - { - digits++; - have_dig: - nz++; - if (c -= '0') - { - nf += nz; - for (i = 1; i < nz; i++) - if (nd++ < 9) - y *= 10; - else if (nd <= DBL_DIG + 1) - z *= 10; - if (nd++ < 9) - y = 10 * y + c; - else if (nd <= DBL_DIG + 1) - z = 10 * z + c; - nz = 0; - } - } - } -dig_done: - e = 0; - if (c == 'e' || c == 'E') - { - if (!nd && !nz && !nz0) - { - s = s00; - goto ret; - } - s00 = s; - esign = 0; - switch (c = *++s) - { - case '-': - esign = 1; - case '+': - c = *++s; - } - if (c >= '0' && c <= '9') - { - while (c == '0') - c = *++s; - if (c > '0' && c <= '9') - { - e = c - '0'; - s1 = s; - while ((c = *++s) >= '0' && c <= '9') - e = 10 * e + c - '0'; - if (s - s1 > 8) - /* Avoid confusion from exponents - * so large that e might overflow. - */ - e = 9999999L; - if (esign) - e = -e; - } - } - else - { - /* No exponent after an 'E' : that's an error. */ - ptr->_errno = EINVAL; - e = 0; - s = s00; - goto ret; - } - } - if (!nd) - { - if (!nz && !nz0) - s = s00; - goto ret; - } - e1 = e -= nf; - - /* Now we have nd0 digits, starting at s0, followed by a - * decimal point, followed by nd-nd0 digits. The number we're - * after is the integer represented by those digits times - * 10**e */ - - if (!nd0) - nd0 = nd; - k = nd < DBL_DIG + 1 ? nd : DBL_DIG + 1; - rv.d = y; - if (k > 9) - rv.d = tens[k - 9] * rv.d + z; - bd0 = 0; - if (nd <= DBL_DIG -#ifndef RND_PRODQUOT - && FLT_ROUNDS == 1 -#endif - ) - { - if (!e) - goto ret; - if (e > 0) - { - if (e <= Ten_pmax) - { -#ifdef VAX - goto vax_ovfl_check; -#else - /* rv.d = */ rounded_product (rv.d, tens[e]); - goto ret; -#endif - } - i = DBL_DIG - nd; - if (e <= Ten_pmax + i) - { - /* A fancier test would sometimes let us do - * this for larger i values. - */ - e -= i; - rv.d *= tens[i]; -#ifdef VAX - /* VAX exponent range is so narrow we must - * worry about overflow here... - */ - vax_ovfl_check: - word0 (rv) -= P * Exp_msk1; - /* rv.d = */ rounded_product (rv.d, tens[e]); - if ((word0 (rv) & Exp_mask) - > Exp_msk1 * (DBL_MAX_EXP + Bias - 1 - P)) - goto ovfl; - word0 (rv) += P * Exp_msk1; -#else - /* rv.d = */ rounded_product (rv.d, tens[e]); -#endif - goto ret; - } - } -#ifndef Inaccurate_Divide - else if (e >= -Ten_pmax) - { - /* rv.d = */ rounded_quotient (rv.d, tens[-e]); - goto ret; - } -#endif - } - e1 += nd - k; - - /* Get starting approximation = rv.d * 10**e1 */ - - if (e1 > 0) - { - if ((i = e1 & 15)) - rv.d *= tens[i]; - - if (e1 &= ~15) - { - if (e1 > DBL_MAX_10_EXP) - { - ovfl: - ptr->_errno = ERANGE; - - /* Force result to IEEE infinity. */ - word0 (rv) = Exp_mask; - word1 (rv) = 0; - - if (bd0) - goto retfree; - goto ret; - } - if (e1 >>= 4) - { - for (j = 0; e1 > 1; j++, e1 >>= 1) - if (e1 & 1) - rv.d *= bigtens[j]; - /* The last multiplication could overflow. */ - word0 (rv) -= P * Exp_msk1; - rv.d *= bigtens[j]; - if ((z = word0 (rv) & Exp_mask) - > Exp_msk1 * (DBL_MAX_EXP + Bias - P)) - goto ovfl; - if (z > Exp_msk1 * (DBL_MAX_EXP + Bias - 1 - P)) - { - /* set to largest number */ - /* (Can't trust DBL_MAX) */ - word0 (rv) = Big0; -#ifndef _DOUBLE_IS_32BITS - word1 (rv) = Big1; -#endif - } - else - word0 (rv) += P * Exp_msk1; - } - - } - } - else if (e1 < 0) - { - e1 = -e1; - if ((i = e1 & 15)) - rv.d /= tens[i]; - if (e1 &= ~15) - { - e1 >>= 4; - if (e1 >= 1 << n_bigtens) - goto undfl; - for (j = 0; e1 > 1; j++, e1 >>= 1) - if (e1 & 1) - rv.d *= tinytens[j]; - /* The last multiplication could underflow. */ - rv0.d = rv.d; - rv.d *= tinytens[j]; - if (!rv.d) - { - rv.d = 2. * rv0.d; - rv.d *= tinytens[j]; - if (!rv.d) - { - undfl: - rv.d = 0.; - ptr->_errno = ERANGE; - if (bd0) - goto retfree; - goto ret; - } -#ifndef _DOUBLE_IS_32BITS - word0 (rv) = Tiny0; - word1 (rv) = Tiny1; -#else - word0 (rv) = Tiny1; -#endif - /* The refinement below will clean - * this approximation up. - */ - } - } - } - - /* Now the hard part -- adjusting rv to the correct value.*/ - - /* Put digits into bd: true value = bd * 10^e */ - - bd0 = s2b (ptr, s0, nd0, nd, y); - - for (;;) - { - bd = Balloc (ptr, bd0->_k); - Bcopy (bd, bd0); - bb = d2b (ptr, rv.d, &bbe, &bbbits); /* rv.d = bb * 2^bbe */ - bs = i2b (ptr, 1); - - if (e >= 0) - { - bb2 = bb5 = 0; - bd2 = bd5 = e; - } - else - { - bb2 = bb5 = -e; - bd2 = bd5 = 0; - } - if (bbe >= 0) - bb2 += bbe; - else - bd2 -= bbe; - bs2 = bb2; -#ifdef Sudden_Underflow -#ifdef IBM - j = 1 + 4 * P - 3 - bbbits + ((bbe + bbbits - 1) & 3); -#else - j = P + 1 - bbbits; -#endif -#else - i = bbe + bbbits - 1; /* logb(rv.d) */ - if (i < Emin) /* denormal */ - j = bbe + (P - Emin); - else - j = P + 1 - bbbits; -#endif - bb2 += j; - bd2 += j; - i = bb2 < bd2 ? bb2 : bd2; - if (i > bs2) - i = bs2; - if (i > 0) - { - bb2 -= i; - bd2 -= i; - bs2 -= i; - } - if (bb5 > 0) - { - bs = pow5mult (ptr, bs, bb5); - bb1 = mult (ptr, bs, bb); - Bfree (ptr, bb); - bb = bb1; - } - if (bb2 > 0) - bb = lshift (ptr, bb, bb2); - if (bd5 > 0) - bd = pow5mult (ptr, bd, bd5); - if (bd2 > 0) - bd = lshift (ptr, bd, bd2); - if (bs2 > 0) - bs = lshift (ptr, bs, bs2); - delta = diff (ptr, bb, bd); - dsign = delta->_sign; - delta->_sign = 0; - i = cmp (delta, bs); - if (i < 0) - { - /* Error is less than half an ulp -- check for - * special case of mantissa a power of two. - */ - if (dsign || word1 (rv) || word0 (rv) & Bndry_mask) - break; - delta = lshift (ptr, delta, Log2P); - if (cmp (delta, bs) > 0) - goto drop_down; - break; - } - if (i == 0) - { - /* exactly half-way between */ - if (dsign) - { - if ((word0 (rv) & Bndry_mask1) == Bndry_mask1 - && word1 (rv) == 0xffffffff) - { - /*boundary case -- increment exponent*/ - word0 (rv) = (word0 (rv) & Exp_mask) - + Exp_msk1 -#ifdef IBM - | Exp_msk1 >> 4 -#endif - ; -#ifndef _DOUBLE_IS_32BITS - word1 (rv) = 0; -#endif - break; - } - } - else if (!(word0 (rv) & Bndry_mask) && !word1 (rv)) - { - drop_down: - /* boundary case -- decrement exponent */ -#ifdef Sudden_Underflow - L = word0 (rv) & Exp_mask; -#ifdef IBM - if (L < Exp_msk1) -#else - if (L <= Exp_msk1) -#endif - goto undfl; - L -= Exp_msk1; -#else - L = (word0 (rv) & Exp_mask) - Exp_msk1; -#endif - word0 (rv) = L | Bndry_mask1; -#ifndef _DOUBLE_IS_32BITS - word1 (rv) = 0xffffffff; -#endif -#ifdef IBM - goto cont; -#else - break; -#endif - } -#ifndef ROUND_BIASED - if (!(word1 (rv) & LSB)) - break; -#endif - if (dsign) - rv.d += ulp (rv.d); -#ifndef ROUND_BIASED - else - { - rv.d -= ulp (rv.d); -#ifndef Sudden_Underflow - if (!rv.d) - goto undfl; -#endif - } -#endif - break; - } - if ((aadj = ratio (delta, bs)) <= 2.) - { - if (dsign) - aadj = aadj1 = 1.; - else if (word1 (rv) || word0 (rv) & Bndry_mask) - { -#ifndef Sudden_Underflow - if (word1 (rv) == Tiny1 && !word0 (rv)) - goto undfl; -#endif - aadj = 1.; - aadj1 = -1.; - } - else - { - /* special case -- power of FLT_RADIX to be */ - /* rounded down... */ - - if (aadj < 2. / FLT_RADIX) - aadj = 1. / FLT_RADIX; - else - aadj *= 0.5; - aadj1 = -aadj; - } - } - else - { - aadj *= 0.5; - aadj1 = dsign ? aadj : -aadj; -#ifdef Check_FLT_ROUNDS - switch (FLT_ROUNDS) - { - case 2: /* towards +infinity */ - aadj1 -= 0.5; - break; - case 0: /* towards 0 */ - case 3: /* towards -infinity */ - aadj1 += 0.5; - } -#else - if (FLT_ROUNDS == 0) - aadj1 += 0.5; -#endif - } - y = word0 (rv) & Exp_mask; - - /* Check for overflow */ - - if (y == Exp_msk1 * (DBL_MAX_EXP + Bias - 1)) - { - rv0.d = rv.d; - word0 (rv) -= P * Exp_msk1; - adj = aadj1 * ulp (rv.d); - rv.d += adj; - if ((word0 (rv) & Exp_mask) >= - Exp_msk1 * (DBL_MAX_EXP + Bias - P)) - { - if (word0 (rv0) == Big0 && word1 (rv0) == Big1) - goto ovfl; -#ifdef _DOUBLE_IS_32BITS - word0 (rv) = Big1; -#else - word0 (rv) = Big0; - word1 (rv) = Big1; -#endif - goto cont; - } - else - word0 (rv) += P * Exp_msk1; - } - else - { -#ifdef Sudden_Underflow - if ((word0 (rv) & Exp_mask) <= P * Exp_msk1) - { - rv0.d = rv.d; - word0 (rv) += P * Exp_msk1; - adj = aadj1 * ulp (rv.d); - rv.d += adj; -#ifdef IBM - if ((word0 (rv) & Exp_mask) < P * Exp_msk1) -#else - if ((word0 (rv) & Exp_mask) <= P * Exp_msk1) -#endif - { - if (word0 (rv0) == Tiny0 - && word1 (rv0) == Tiny1) - goto undfl; - word0 (rv) = Tiny0; - word1 (rv) = Tiny1; - goto cont; - } - else - word0 (rv) -= P * Exp_msk1; - } - else - { - adj = aadj1 * ulp (rv.d); - rv.d += adj; - } -#else - /* Compute adj so that the IEEE rounding rules will - * correctly round rv.d + adj in some half-way cases. - * If rv.d * ulp(rv.d) is denormalized (i.e., - * y <= (P-1)*Exp_msk1), we must adjust aadj to avoid - * trouble from bits lost to denormalization; - * example: 1.2e-307 . - */ - if (y <= (P - 1) * Exp_msk1 && aadj >= 1.) - { - aadj1 = (double) (int) (aadj + 0.5); - if (!dsign) - aadj1 = -aadj1; - } - adj = aadj1 * ulp (rv.d); - rv.d += adj; -#endif - } - z = word0 (rv) & Exp_mask; - if (y == z) - { - /* Can we stop now? */ - L = aadj; - aadj -= L; - /* The tolerances below are conservative. */ - if (dsign || word1 (rv) || word0 (rv) & Bndry_mask) - { - if (aadj < .4999999 || aadj > .5000001) - break; - } - else if (aadj < .4999999 / FLT_RADIX) - break; - } - cont: - Bfree (ptr, bb); - Bfree (ptr, bd); - Bfree (ptr, bs); - Bfree (ptr, delta); - } -retfree: - Bfree (ptr, bb); - Bfree (ptr, bd); - Bfree (ptr, bs); - Bfree (ptr, bd0); - Bfree (ptr, delta); -ret: - if (se) - *se = (char *) s; - if (digits == 0) - ptr->_errno = EINVAL; - return sign ? -rv.d : rv.d; -} - diff --git a/libjava/java/lang/w_acos.c b/libjava/java/lang/w_acos.c deleted file mode 100644 index c9ca99c4041..00000000000 --- a/libjava/java/lang/w_acos.c +++ /dev/null @@ -1,118 +0,0 @@ - -/* @(#)w_acos.c 5.1 93/09/24 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* -FUNCTION - <<acos>>, <<acosf>>---arc cosine - -INDEX - acos -INDEX - acosf - -ANSI_SYNOPSIS - #include <math.h> - double acos(double <[x]>); - float acosf(float <[x]>); - -TRAD_SYNOPSIS - #include <math.h> - double acos(<[x]>) - double <[x]>; - - float acosf(<[x]>) - float <[x]>; - - - -DESCRIPTION - - <<acos>> computes the inverse cosine (arc cosine) of the input value. - Arguments to <<acos>> must be in the range @minus{}1 to 1. - - <<acosf>> is identical to <<acos>>, except that it performs - its calculations on <<floats>>. - -RETURNS - @ifinfo - <<acos>> and <<acosf>> return values in radians, in the range of 0 to pi. - @end ifinfo - @tex - <<acos>> and <<acosf>> return values in radians, in the range of <<0>> to $\pi$. - @end tex - - If <[x]> is not between @minus{}1 and 1, the returned value is NaN - (not a number) the global variable <<errno>> is set to <<EDOM>>, and a - <<DOMAIN error>> message is sent as standard error output. - - You can modify error handling for these functions using <<matherr>>. - - -QUICKREF ANSI SVID POSIX RENTRANT - acos y,y,y,m - acosf n,n,n,m - -MATHREF - acos, [-1,1], acos(arg),,, - acos, NAN, arg,DOMAIN,EDOM - -MATHREF - acosf, [-1,1], acosf(arg),,, - acosf, NAN, argf,DOMAIN,EDOM - -*/ - -/* - * wrap_acos(x) - */ - -#include "fdlibm.h" -#include <errno.h> - -#ifndef _DOUBLE_IS_32BITS - -#ifdef __STDC__ - double acos(double x) /* wrapper acos */ -#else - double acos(x) /* wrapper acos */ - double x; -#endif -{ -#ifdef _IEEE_LIBM - return __ieee754_acos(x); -#else - double z; - struct exception exc; - z = __ieee754_acos(x); - if(_LIB_VERSION == _IEEE_ || isnan(x)) return z; - if(fabs(x)>1.0) { - /* acos(|x|>1) */ - exc.type = DOMAIN; - exc.name = "acos"; - exc.err = 0; - exc.arg1 = exc.arg2 = x; - exc.retval = 0.0; - if (_LIB_VERSION == _POSIX_) - errno = EDOM; - else if (!matherr(&exc)) { - errno = EDOM; - } - if (exc.err != 0) - errno = exc.err; - return exc.retval; - } else - return z; -#endif -} - -#endif /* defined(_DOUBLE_IS_32BITS) */ diff --git a/libjava/java/lang/w_asin.c b/libjava/java/lang/w_asin.c deleted file mode 100644 index f6cb271d392..00000000000 --- a/libjava/java/lang/w_asin.c +++ /dev/null @@ -1,121 +0,0 @@ - -/* @(#)w_asin.c 5.1 93/09/24 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - * - */ - -/* -FUNCTION - <<asin>>, <<asinf>>---arc sine - -INDEX - asin -INDEX - asinf - -ANSI_SYNOPSIS - #include <math.h> - double asin(double <[x]>); - float asinf(float <[x]>); - -TRAD_SYNOPSIS - #include <math.h> - double asin(<[x]>) - double <[x]>; - - float asinf(<[x]>) - float <[x]>; - - -DESCRIPTION - -<<asin>> computes the inverse sine (arc sine) of the argument <[x]>. -Arguments to <<asin>> must be in the range @minus{}1 to 1. - -<<asinf>> is identical to <<asin>>, other than taking and -returning floats. - -You can modify error handling for these routines using <<matherr>>. - -RETURNS -@ifinfo -<<asin>> returns values in radians, in the range of -pi/2 to pi/2. -@end ifinfo -@tex -<<asin>> returns values in radians, in the range of $-\pi/2$ to $\pi/2$. -@end tex - -If <[x]> is not in the range @minus{}1 to 1, <<asin>> and <<asinf>> -return NaN (not a number), set the global variable <<errno>> to -<<EDOM>>, and issue a <<DOMAIN error>> message. - -You can change this error treatment using <<matherr>>. - -QUICKREF ANSI SVID POSIX RENTRANT - asin y,y,y,m - asinf n,n,n,m - -MATHREF - asin, -1<=arg<=1, asin(arg),,, - asin, NAN, arg,EDOM, DOMAIN - -MATHREF - asinf, -1<=arg<=1, asin(arg),,, - asinf, NAN, arg,EDOM, DOMAIN - - -*/ - -/* - * wrapper asin(x) - */ - - -#include "fdlibm.h" -#include <errno.h> - -#ifndef _DOUBLE_IS_32BITS - -#ifdef __STDC__ - double asin(double x) /* wrapper asin */ -#else - double asin(x) /* wrapper asin */ - double x; -#endif -{ -#ifdef _IEEE_LIBM - return __ieee754_asin(x); -#else - double z; - struct exception exc; - z = __ieee754_asin(x); - if(_LIB_VERSION == _IEEE_ || isnan(x)) return z; - if(fabs(x)>1.0) { - /* asin(|x|>1) */ - exc.type = DOMAIN; - exc.name = "asin"; - exc.err = 0; - exc.arg1 = exc.arg2 = x; - exc.retval = 0.0; - if(_LIB_VERSION == _POSIX_) - errno = EDOM; - else if (!matherr(&exc)) { - errno = EDOM; - } - if (exc.err != 0) - errno = exc.err; - return exc.retval; - } else - return z; -#endif -} - -#endif /* defined(_DOUBLE_IS_32BITS) */ diff --git a/libjava/java/lang/w_atan2.c b/libjava/java/lang/w_atan2.c deleted file mode 100644 index 91742c72b91..00000000000 --- a/libjava/java/lang/w_atan2.c +++ /dev/null @@ -1,117 +0,0 @@ - -/* @(#)w_atan2.c 5.1 93/09/24 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - * - */ - -/* -FUNCTION - <<atan2>>, <<atan2f>>---arc tangent of y/x - -INDEX - atan2 -INDEX - atan2f - -ANSI_SYNOPSIS - #include <math.h> - double atan2(double <[y]>,double <[x]>); - float atan2f(float <[y]>,float <[x]>); - -TRAD_SYNOPSIS - #include <math.h> - double atan2(<[y]>,<[x]>); - double <[y]>; - double <[x]>; - - float atan2f(<[y]>,<[x]>); - float <[y]>; - float <[x]>; - -DESCRIPTION - -<<atan2>> computes the inverse tangent (arc tangent) of <[y]>/<[x]>. -<<atan2>> produces the correct result even for angles near -@ifinfo -pi/2 or -pi/2 -@end ifinfo -@tex -$\pi/2$ or $-\pi/2$ -@end tex -(that is, when <[x]> is near 0). - -<<atan2f>> is identical to <<atan2>>, save that it takes and returns -<<float>>. - -RETURNS -<<atan2>> and <<atan2f>> return a value in radians, in the range of -@ifinfo --pi to pi. -@end ifinfo -@tex -$-\pi$ to $\pi$. -@end tex - -If both <[x]> and <[y]> are 0.0, <<atan2>> causes a <<DOMAIN>> error. - -You can modify error handling for these functions using <<matherr>>. - -PORTABILITY -<<atan2>> is ANSI C. <<atan2f>> is an extension. - - -*/ - -/* - * wrapper atan2(y,x) - */ - -#include "fdlibm.h" -#include <errno.h> - -#ifndef _DOUBLE_IS_32BITS - -#ifdef __STDC__ - double atan2(double y, double x) /* wrapper atan2 */ -#else - double atan2(y,x) /* wrapper atan2 */ - double y,x; -#endif -{ -#ifdef _IEEE_LIBM - return __ieee754_atan2(y,x); -#else - double z; - struct exception exc; - z = __ieee754_atan2(y,x); - if(_LIB_VERSION == _IEEE_||isnan(x)||isnan(y)) return z; - if(x==0.0&&y==0.0) { - /* atan2(+-0,+-0) */ - exc.arg1 = y; - exc.arg2 = x; - exc.type = DOMAIN; - exc.name = "atan2"; - exc.err = 0; - exc.retval = 0.0; - if(_LIB_VERSION == _POSIX_) - errno = EDOM; - else if (!matherr(&exc)) { - errno = EDOM; - } - if (exc.err != 0) - errno = exc.err; - return exc.retval; - } else - return z; -#endif -} - -#endif /* defined(_DOUBLE_IS_32BITS) */ diff --git a/libjava/java/lang/w_exp.c b/libjava/java/lang/w_exp.c deleted file mode 100644 index 45e087b45f9..00000000000 --- a/libjava/java/lang/w_exp.c +++ /dev/null @@ -1,140 +0,0 @@ - -/* @(#)w_exp.c 5.1 93/09/24 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* -FUNCTION - <<exp>>, <<expf>>---exponential -INDEX - exp -INDEX - expf - -ANSI_SYNOPSIS - #include <math.h> - double exp(double <[x]>); - float expf(float <[x]>); - -TRAD_SYNOPSIS - #include <math.h> - double exp(<[x]>); - double <[x]>; - - float expf(<[x]>); - float <[x]>; - -DESCRIPTION - <<exp>> and <<expf>> calculate the exponential of <[x]>, that is, - @ifinfo - e raised to the power <[x]> (where e - @end ifinfo - @tex - $e^x$ (where $e$ - @end tex - is the base of the natural system of logarithms, approximately 2.71828). - - You can use the (non-ANSI) function <<matherr>> to specify - error handling for these functions. - -RETURNS - On success, <<exp>> and <<expf>> return the calculated value. - If the result underflows, the returned value is <<0>>. If the - result overflows, the returned value is <<HUGE_VAL>>. In - either case, <<errno>> is set to <<ERANGE>>. - -PORTABILITY - <<exp>> is ANSI C. <<expf>> is an extension. - -*/ - -/* - * wrapper exp(x) - */ - -#include "fdlibm.h" -#include <errno.h> - -#ifndef _DOUBLE_IS_32BITS - -#ifndef _IEEE_LIBM - -#ifdef __STDC__ -static const double -#else -static double -#endif -o_threshold= 7.09782712893383973096e+02, /* 0x40862E42, 0xFEFA39EF */ -u_threshold= -7.45133219101941108420e+02; /* 0xc0874910, 0xD52D3051 */ - -#endif - -#ifdef __STDC__ - double exp(double x) /* wrapper exp */ -#else - double exp(x) /* wrapper exp */ - double x; -#endif -{ -#ifdef _IEEE_LIBM - return __ieee754_exp(x); -#else - double z; - struct exception exc; - z = __ieee754_exp(x); - if(_LIB_VERSION == _IEEE_) return z; - if(finite(x)) { - if(x>o_threshold) { - /* exp(finite) overflow */ -#ifndef HUGE_VAL -#define HUGE_VAL inf - double inf = 0.0; - - SET_HIGH_WORD(inf,0x7ff00000); /* set inf to infinite */ -#endif - exc.type = OVERFLOW; - exc.name = "exp"; - exc.err = 0; - exc.arg1 = exc.arg2 = x; - if (_LIB_VERSION == _SVID_) - exc.retval = HUGE; - else - exc.retval = HUGE_VAL; - if (_LIB_VERSION == _POSIX_) - errno = ERANGE; - else if (!matherr(&exc)) { - errno = ERANGE; - } - if (exc.err != 0) - errno = exc.err; - return exc.retval; - } else if(x<u_threshold) { - /* exp(finite) underflow */ - exc.type = UNDERFLOW; - exc.name = "exp"; - exc.err = 0; - exc.arg1 = exc.arg2 = x; - exc.retval = 0.0; - if (_LIB_VERSION == _POSIX_) - errno = ERANGE; - else if (!matherr(&exc)) { - errno = ERANGE; - } - if (exc.err != 0) - errno = exc.err; - return exc.retval; - } - } - return z; -#endif -} - -#endif /* defined(_DOUBLE_IS_32BITS) */ diff --git a/libjava/java/lang/w_fmod.c b/libjava/java/lang/w_fmod.c deleted file mode 100644 index b6b36cb76ab..00000000000 --- a/libjava/java/lang/w_fmod.c +++ /dev/null @@ -1,107 +0,0 @@ - -/* @(#)w_fmod.c 5.1 93/09/24 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* -FUNCTION -<<fmod>>, <<fmodf>>---floating-point remainder (modulo) - -INDEX -fmod -INDEX -fmodf - -ANSI_SYNOPSIS -#include <math.h> -double fmod(double <[x]>, double <[y]>) -float fmodf(float <[x]>, float <[y]>) - -TRAD_SYNOPSIS -#include <math.h> -double fmod(<[x]>, <[y]>) -double (<[x]>, <[y]>); - -float fmodf(<[x]>, <[y]>) -float (<[x]>, <[y]>); - -DESCRIPTION -The <<fmod>> and <<fmodf>> functions compute the floating-point -remainder of <[x]>/<[y]> (<[x]> modulo <[y]>). - -RETURNS -The <<fmod>> function returns the value -@ifinfo -<[x]>-<[i]>*<[y]>, -@end ifinfo -@tex -$x-i\times y$, -@end tex -for the largest integer <[i]> such that, if <[y]> is nonzero, the -result has the same sign as <[x]> and magnitude less than the -magnitude of <[y]>. - -<<fmod(<[x]>,0)>> returns NaN, and sets <<errno>> to <<EDOM>>. - -You can modify error treatment for these functions using <<matherr>>. - -PORTABILITY -<<fmod>> is ANSI C. <<fmodf>> is an extension. -*/ - -/* - * wrapper fmod(x,y) - */ - -#include "fdlibm.h" -#include <errno.h> - -#ifndef _DOUBLE_IS_32BITS - -#ifdef __STDC__ - double fmod(double x, double y) /* wrapper fmod */ -#else - double fmod(x,y) /* wrapper fmod */ - double x,y; -#endif -{ -#ifdef _IEEE_LIBM - return __ieee754_fmod(x,y); -#else - double z; - struct exception exc; - z = __ieee754_fmod(x,y); - if(_LIB_VERSION == _IEEE_ ||isnan(y)||isnan(x)) return z; - if(y==0.0) { - /* fmod(x,0) */ - exc.type = DOMAIN; - exc.name = "fmod"; - exc.arg1 = x; - exc.arg2 = y; - exc.err = 0; - if (_LIB_VERSION == _SVID_) - exc.retval = x; - else - exc.retval = 0.0/0.0; - if (_LIB_VERSION == _POSIX_) - errno = EDOM; - else if (!matherr(&exc)) { - errno = EDOM; - } - if (exc.err != 0) - errno = exc.err; - return exc.retval; - } else - return z; -#endif -} - -#endif /* defined(_DOUBLE_IS_32BITS) */ diff --git a/libjava/java/lang/w_log.c b/libjava/java/lang/w_log.c deleted file mode 100644 index dcc8b9762ec..00000000000 --- a/libjava/java/lang/w_log.c +++ /dev/null @@ -1,115 +0,0 @@ - -/* @(#)w_log.c 5.1 93/09/24 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* -FUNCTION - <<log>>, <<logf>>---natural logarithms - -INDEX - log -INDEX - logf - -ANSI_SYNOPSIS - #include <math.h> - double log(double <[x]>); - float logf(float <[x]>); - -TRAD_SYNOPSIS - #include <math.h> - double log(<[x]>); - double <[x]>; - - float logf(<[x]>); - float <[x]>; - -DESCRIPTION -Return the natural logarithm of <[x]>, that is, its logarithm base e -(where e is the base of the natural system of logarithms, 2.71828@dots{}). -<<log>> and <<logf>> are identical save for the return and argument types. - -You can use the (non-ANSI) function <<matherr>> to specify error -handling for these functions. - -RETURNS -Normally, returns the calculated value. When <[x]> is zero, the -returned value is <<-HUGE_VAL>> and <<errno>> is set to <<ERANGE>>. -When <[x]> is negative, the returned value is <<-HUGE_VAL>> and -<<errno>> is set to <<EDOM>>. You can control the error behavior via -<<matherr>>. - -PORTABILITY -<<log>> is ANSI, <<logf>> is an extension. -*/ - -/* - * wrapper log(x) - */ - -#include "fdlibm.h" -#include <errno.h> - -#ifndef _DOUBLE_IS_32BITS - -#ifdef __STDC__ - double log(double x) /* wrapper log */ -#else - double log(x) /* wrapper log */ - double x; -#endif -{ -#ifdef _IEEE_LIBM - return __ieee754_log(x); -#else - double z; - struct exception exc; - z = __ieee754_log(x); - if(_LIB_VERSION == _IEEE_ || isnan(x) || x > 0.0) return z; -#ifndef HUGE_VAL -#define HUGE_VAL inf - double inf = 0.0; - - SET_HIGH_WORD(inf,0x7ff00000); /* set inf to infinite */ -#endif - exc.name = "log"; - exc.err = 0; - exc.arg1 = x; - exc.arg2 = x; - if (_LIB_VERSION == _SVID_) - exc.retval = -HUGE; - else - exc.retval = -HUGE_VAL; - if(x==0.0) { - /* log(0) */ - exc.type = SING; - if (_LIB_VERSION == _POSIX_) - errno = ERANGE; - else if (!matherr(&exc)) { - errno = EDOM; - } - } else { - /* log(x<0) */ - exc.type = DOMAIN; - if (_LIB_VERSION == _POSIX_) - errno = EDOM; - else if (!matherr(&exc)) { - errno = EDOM; - } - } - if (exc.err != 0) - errno = exc.err; - return exc.retval; -#endif -} - -#endif /* defined(_DOUBLE_IS_32BITS) */ diff --git a/libjava/java/lang/w_pow.c b/libjava/java/lang/w_pow.c deleted file mode 100644 index 3df099a1714..00000000000 --- a/libjava/java/lang/w_pow.c +++ /dev/null @@ -1,231 +0,0 @@ - - -/* @(#)w_pow.c 5.2 93/10/01 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* -FUNCTION - <<pow>>, <<powf>>---x to the power y -INDEX - pow -INDEX - powf - - -ANSI_SYNOPSIS - #include <math.h> - double pow(double <[x]>, double <[y]>); - float pow(float <[x]>, float <[y]>); - -TRAD_SYNOPSIS - #include <math.h> - double pow(<[x]>, <[y]>); - double <[x]>, <[y]>; - - float pow(<[x]>, <[y]>); - float <[x]>, <[y]>; - -DESCRIPTION - <<pow>> and <<powf>> calculate <[x]> raised to the exp1.0nt <[y]>. - @tex - (That is, $x^y$.) - @end tex - -RETURNS - On success, <<pow>> and <<powf>> return the value calculated. - - When the argument values would produce overflow, <<pow>> - returns <<HUGE_VAL>> and set <<errno>> to <<ERANGE>>. If the - argument <[x]> passed to <<pow>> or <<powf>> is a negative - noninteger, and <[y]> is also not an integer, then <<errno>> - is set to <<EDOM>>. If <[x]> and <[y]> are both 0, then - <<pow>> and <<powf>> return <<1>>. - - You can modify error handling for these functions using <<matherr>>. - -PORTABILITY - <<pow>> is ANSI C. <<powf>> is an extension. */ - -/* - * wrapper pow(x,y) return x**y - */ - -#include "fdlibm.h" -#include <errno.h> - -#ifndef _DOUBLE_IS_32BITS - -#ifdef __STDC__ - double pow(double x, double y) /* wrapper pow */ -#else - double pow(x,y) /* wrapper pow */ - double x,y; -#endif -{ -#ifdef _IEEE_LIBM - return __ieee754_pow(x,y); -#else - double z; -#ifndef HUGE_VAL -#define HUGE_VAL inf - double inf = 0.0; - - SET_HIGH_WORD(inf,0x7ff00000); /* set inf to infinite */ -#endif - struct exception exc; - z=__ieee754_pow(x,y); - if(_LIB_VERSION == _IEEE_|| isnan(y)) return z; - if(isnan(x)) { - if(y==0.0) { - /* pow(NaN,0.0) */ - /* error only if _LIB_VERSION == _SVID_ & _XOPEN_ */ - exc.type = DOMAIN; - exc.name = "pow"; - exc.err = 0; - exc.arg1 = x; - exc.arg2 = y; - exc.retval = x; - if (_LIB_VERSION == _IEEE_ || - _LIB_VERSION == _POSIX_) exc.retval = 1.0; - else if (!matherr(&exc)) { - errno = EDOM; - } - if (exc.err != 0) - errno = exc.err; - return exc.retval; - } else - return z; - } - if(x==0.0){ - if(y==0.0) { - /* pow(0.0,0.0) */ - /* error only if _LIB_VERSION == _SVID_ */ - exc.type = DOMAIN; - exc.name = "pow"; - exc.err = 0; - exc.arg1 = x; - exc.arg2 = y; - exc.retval = 0.0; - if (_LIB_VERSION != _SVID_) exc.retval = 1.0; - else if (!matherr(&exc)) { - errno = EDOM; - } - if (exc.err != 0) - errno = exc.err; - return exc.retval; - } - if(finite(y)&&y<0.0) { - /* 0**neg */ - exc.type = DOMAIN; - exc.name = "pow"; - exc.err = 0; - exc.arg1 = x; - exc.arg2 = y; - if (_LIB_VERSION == _SVID_) - exc.retval = 0.0; - else - exc.retval = -HUGE_VAL; - if (_LIB_VERSION == _POSIX_) - errno = EDOM; - else if (!matherr(&exc)) { - errno = EDOM; - } - if (exc.err != 0) - errno = exc.err; - return exc.retval; - } - return z; - } - if(!finite(z)) { - if(finite(x)&&finite(y)) { - if(isnan(z)) { - /* neg**non-integral */ - exc.type = DOMAIN; - exc.name = "pow"; - exc.err = 0; - exc.arg1 = x; - exc.arg2 = y; - if (_LIB_VERSION == _SVID_) - exc.retval = 0.0; - else - exc.retval = 0.0/0.0; /* X/Open allow NaN */ - if (_LIB_VERSION == _POSIX_) - errno = EDOM; - else if (!matherr(&exc)) { - errno = EDOM; - } - if (exc.err != 0) - errno = exc.err; - return exc.retval; - } else { - /* pow(x,y) overflow */ - exc.type = OVERFLOW; - exc.name = "pow"; - exc.err = 0; - exc.arg1 = x; - exc.arg2 = y; - if (_LIB_VERSION == _SVID_) { - exc.retval = HUGE; - y *= 0.5; - if(x<0.0&&rint(y)!=y) exc.retval = -HUGE; - } else { - exc.retval = HUGE_VAL; - y *= 0.5; - if(x<0.0&&rint(y)!=y) exc.retval = -HUGE_VAL; - } - if (_LIB_VERSION == _POSIX_) - errno = ERANGE; - else if (!matherr(&exc)) { - errno = ERANGE; - } - if (exc.err != 0) - errno = exc.err; - return exc.retval; - } - } - } - if(z==0.0&&finite(x)&&finite(y)) { - /* pow(x,y) underflow */ - exc.type = UNDERFLOW; - exc.name = "pow"; - exc.err = 0; - exc.arg1 = x; - exc.arg2 = y; - exc.retval = 0.0; - if (_LIB_VERSION == _POSIX_) - errno = ERANGE; - else if (!matherr(&exc)) { - errno = ERANGE; - } - if (exc.err != 0) - errno = exc.err; - return exc.retval; - } - return z; -#endif -} - -#endif /* defined(_DOUBLE_IS_32BITS) */ - - - - - - - - - - - - - - diff --git a/libjava/java/lang/w_remainder.c b/libjava/java/lang/w_remainder.c deleted file mode 100644 index a06be0e7b30..00000000000 --- a/libjava/java/lang/w_remainder.c +++ /dev/null @@ -1,119 +0,0 @@ - -/* @(#)w_remainder.c 5.1 93/09/24 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* -FUNCTION -<<rint>>, <<rintf>>, <<remainder>>, <<remainderf>>---round and remainder -INDEX - rint -INDEX - rintf -INDEX - remainder -INDEX - remainderf - -ANSI_SYNOPSIS - #include <math.h> - double rint(double <[x]>); - float rintf(float <[x]>); - double remainder(double <[x]>, double <[y]>); - float remainderf(float <[x]>, float <[y]>); - -TRAD_SYNOPSIS - #include <math.h> - double rint(<[x]>) - double <[x]>; - float rintf(<[x]>) - float <[x]>; - double remainder(<[x]>,<[y]>) - double <[x]>, <[y]>; - float remainderf(<[x]>,<[y]>) - float <[x]>, <[y]>; - -DESCRIPTION -<<rint>> and <<rintf>> returns their argument rounded to the nearest -integer. <<remainder>> and <<remainderf>> find the remainder of -<[x]>/<[y]>; this value is in the range -<[y]>/2 .. +<[y]>/2. - -RETURNS -<<rint>> and <<remainder>> return the integer result as a double. - -PORTABILITY -<<rint>> and <<remainder>> are System V release 4. <<rintf>> and -<<remainderf>> are extensions. - -*/ - -/* - * wrapper remainder(x,p) - */ - -#include "fdlibm.h" -#include <errno.h> - -#ifndef _DOUBLE_IS_32BITS - -#ifdef __STDC__ - double remainder(double x, double y) /* wrapper remainder */ -#else - double remainder(x,y) /* wrapper remainder */ - double x,y; -#endif -{ -#ifdef _IEEE_LIBM - return __ieee754_remainder(x,y); -#else - double z; - struct exception exc; - z = __ieee754_remainder(x,y); - if(_LIB_VERSION == _IEEE_ || isnan(y)) return z; - if(y==0.0) { - /* remainder(x,0) */ - exc.type = DOMAIN; - exc.name = "remainder"; - exc.err = 0; - exc.arg1 = x; - exc.arg2 = y; - exc.retval = 0.0/0.0; - if (_LIB_VERSION == _POSIX_) - errno = EDOM; - else if (!matherr(&exc)) { - errno = EDOM; - } - if (exc.err != 0) - errno = exc.err; - return exc.retval; - } else - return z; -#endif -} - -#endif /* defined(_DOUBLE_IS_32BITS) */ - - - - - - - - - - - - - - - - - diff --git a/libjava/java/lang/w_sqrt.c b/libjava/java/lang/w_sqrt.c deleted file mode 100644 index 23a793ce74a..00000000000 --- a/libjava/java/lang/w_sqrt.c +++ /dev/null @@ -1,93 +0,0 @@ - -/* @(#)w_sqrt.c 5.1 93/09/24 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -/* -FUNCTION - <<sqrt>>, <<sqrtf>>---positive square root - -INDEX - sqrt -INDEX - sqrtf - -ANSI_SYNOPSIS - #include <math.h> - double sqrt(double <[x]>); - float sqrtf(float <[x]>); - -TRAD_SYNOPSIS - #include <math.h> - double sqrt(<[x]>); - float sqrtf(<[x]>); - -DESCRIPTION - <<sqrt>> computes the positive square root of the argument. - You can modify error handling for this function with - <<matherr>>. - -RETURNS - On success, the square root is returned. If <[x]> is real and - positive, then the result is positive. If <[x]> is real and - negative, the global value <<errno>> is set to <<EDOM>> (domain error). - - -PORTABILITY - <<sqrt>> is ANSI C. <<sqrtf>> is an extension. -*/ - -/* - * wrapper sqrt(x) - */ - -#include "fdlibm.h" -#include <errno.h> - -#ifndef _DOUBLE_IS_32BITS - -#ifdef __STDC__ - double sqrt(double x) /* wrapper sqrt */ -#else - double sqrt(x) /* wrapper sqrt */ - double x; -#endif -{ -#ifdef _IEEE_LIBM - return __ieee754_sqrt(x); -#else - struct exception exc; - double z; - z = __ieee754_sqrt(x); - if(_LIB_VERSION == _IEEE_ || isnan(x)) return z; - if(x<0.0) { - exc.type = DOMAIN; - exc.name = "sqrt"; - exc.err = 0; - exc.arg1 = exc.arg2 = x; - if (_LIB_VERSION == _SVID_) - exc.retval = 0.0; - else - exc.retval = 0.0/0.0; - if (_LIB_VERSION == _POSIX_) - errno = EDOM; - else if (!matherr(&exc)) { - errno = EDOM; - } - if (exc.err != 0) - errno = exc.err; - return exc.retval; - } else - return z; -#endif -} - -#endif /* defined(_DOUBLE_IS_32BITS) */ diff --git a/libjava/java/math/BigDecimal.java b/libjava/java/math/BigDecimal.java deleted file mode 100644 index d99be0f56ba..00000000000 --- a/libjava/java/math/BigDecimal.java +++ /dev/null @@ -1,517 +0,0 @@ -/* java.math.BigDecimal -- Arbitrary precision decimals. - Copyright (C) 1999, 2000, 2001, 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.math; - -public class BigDecimal extends Number implements Comparable -{ - private BigInteger intVal; - private int scale; - private static final long serialVersionUID = 6108874887143696463L; - - private static final BigDecimal ZERO = - new BigDecimal (BigInteger.valueOf (0), 0); - - private static final BigDecimal ONE = - new BigDecimal (BigInteger.valueOf (1), 0); - - public static final int ROUND_UP = 0; - public static final int ROUND_DOWN = 1; - public static final int ROUND_CEILING = 2; - public static final int ROUND_FLOOR = 3; - public static final int ROUND_HALF_UP = 4; - public static final int ROUND_HALF_DOWN = 5; - public static final int ROUND_HALF_EVEN = 6; - public static final int ROUND_UNNECESSARY = 7; - - public BigDecimal (BigInteger num) - { - this (num, 0); - } - - public BigDecimal (BigInteger num, int scale) throws NumberFormatException - { - if (scale < 0) - throw new NumberFormatException ("scale of " + scale + " is < 0"); - this.intVal = num; - this.scale = scale; - } - - public BigDecimal (double num) throws NumberFormatException - { - if (Double.isInfinite (num) || Double.isNaN (num)) - throw new NumberFormatException ("invalid argument: " + num); - // Note we can't convert NUM to a String and then use the - // String-based constructor. The BigDecimal documentation makes - // it clear that the two constructors work differently. - - final int mantissaBits = 52; - final int exponentBits = 11; - final long mantMask = (1L << mantissaBits) - 1; - final long expMask = (1L << exponentBits) - 1; - - long bits = Double.doubleToLongBits (num); - long mantissa = bits & mantMask; - long exponent = (bits >>> mantissaBits) & expMask; - boolean denormal = exponent == 0; - // Correct the exponent for the bias. - exponent -= denormal ? 1022 : 1023; - // Now correct the exponent to account for the bits to the right - // of the decimal. - exponent -= mantissaBits; - // Ordinary numbers have an implied leading `1' bit. - if (! denormal) - mantissa |= (1L << mantissaBits); - - // Shave off factors of 10. - while (exponent < 0 && (mantissa & 1) == 0) - { - ++exponent; - mantissa >>= 1; - } - - intVal = BigInteger.valueOf (bits < 0 ? - mantissa : mantissa); - if (exponent < 0) - { - // We have MANTISSA * 2 ^ (EXPONENT). - // Since (1/2)^N == 5^N * 10^-N we can easily convert this - // into a power of 10. - scale = (int) (- exponent); - BigInteger mult = BigInteger.valueOf (5).pow (scale); - intVal = intVal.multiply (mult); - } - else - { - intVal = intVal.shiftLeft ((int) exponent); - scale = 0; - } - } - - public BigDecimal (String num) throws NumberFormatException - { - int len = num.length(); - int start = 0, point = 0; - int dot = -1; - boolean negative = false; - if (num.charAt(0) == '+') - { - ++start; - ++point; - } - else if (num.charAt(0) == '-') - { - ++start; - ++point; - negative = true; - } - - while (point < len) - { - char c = num.charAt (point); - if (c == '.') - { - if (dot >= 0) - throw new NumberFormatException ("multiple `.'s in number"); - dot = point; - } - else if (c == 'e' || c == 'E') - break; - else if (Character.digit (c, 10) < 0) - throw new NumberFormatException ("unrecognized character: " + c); - ++point; - } - - String val; - if (dot >= 0) - { - val = num.substring (start, dot) + num.substring (dot + 1, point); - scale = point - 1 - dot; - } - else - { - val = num.substring (start, point); - scale = 0; - } - if (val.length () == 0) - throw new NumberFormatException ("no digits seen"); - - if (negative) - val = "-" + val; - intVal = new BigInteger (val); - - // Now parse exponent. - if (point < len) - { - point++; - if (num.charAt(point) == '+') - point++; - - if (point >= len ) - throw new NumberFormatException ("no exponent following e or E"); - - try - { - int exp = Integer.parseInt (num.substring (point)); - exp -= scale; - if (signum () == 0) - scale = 0; - else if (exp > 0) - { - intVal = intVal.multiply (BigInteger.valueOf (10).pow (exp)); - scale = 0; - } - else - scale = - exp; - } - catch (NumberFormatException ex) - { - throw new NumberFormatException ("malformed exponent"); - } - } - } - - public static BigDecimal valueOf (long val) - { - return valueOf (val, 0); - } - - public static BigDecimal valueOf (long val, int scale) - throws NumberFormatException - { - if ((scale == 0) && ((int)val == val)) - switch ((int) val) - { - case 0: - return ZERO; - case 1: - return ONE; - } - - return new BigDecimal (BigInteger.valueOf (val), scale); - } - - public BigDecimal add (BigDecimal val) - { - // For addition, need to line up decimals. Note that the movePointRight - // method cannot be used for this as it might return a BigDecimal with - // scale == 0 instead of the scale we need. - BigInteger op1 = intVal; - BigInteger op2 = val.intVal; - if (scale < val.scale) - op1 = op1.multiply (BigInteger.valueOf (10).pow (val.scale - scale)); - else if (scale > val.scale) - op2 = op2.multiply (BigInteger.valueOf (10).pow (scale - val.scale)); - - return new BigDecimal (op1.add (op2), Math.max (scale, val.scale)); - } - - public BigDecimal subtract (BigDecimal val) - { - return this.add(val.negate()); - } - - public BigDecimal multiply (BigDecimal val) - { - return new BigDecimal (intVal.multiply (val.intVal), scale + val.scale); - } - - public BigDecimal divide (BigDecimal val, int roundingMode) - throws ArithmeticException, IllegalArgumentException - { - return divide (val, scale, roundingMode); - } - - public BigDecimal divide(BigDecimal val, int newScale, int roundingMode) - throws ArithmeticException, IllegalArgumentException - { - if (roundingMode < 0 || roundingMode > 7) - throw - new IllegalArgumentException("illegal rounding mode: " + roundingMode); - - if (newScale < 0) - throw new ArithmeticException ("scale is negative: " + newScale); - - if (intVal.signum () == 0) // handle special case of 0.0/0.0 - return newScale == 0 ? ZERO : new BigDecimal (ZERO.intVal, newScale); - - // Ensure that pow gets a non-negative value. - BigInteger valIntVal = val.intVal; - int power = newScale - (scale - val.scale); - if (power < 0) - { - // Effectively increase the scale of val to avoid an - // ArithmeticException for a negative power. - valIntVal = valIntVal.multiply (BigInteger.valueOf (10).pow (-power)); - power = 0; - } - - BigInteger dividend = intVal.multiply (BigInteger.valueOf (10).pow (power)); - - BigInteger parts[] = dividend.divideAndRemainder (valIntVal); - - BigInteger unrounded = parts[0]; - if (parts[1].signum () == 0) // no remainder, no rounding necessary - return new BigDecimal (unrounded, newScale); - - if (roundingMode == ROUND_UNNECESSARY) - throw new ArithmeticException ("newScale is not large enough"); - - int sign = intVal.signum () * valIntVal.signum (); - - if (roundingMode == ROUND_CEILING) - roundingMode = (sign > 0) ? ROUND_UP : ROUND_DOWN; - else if (roundingMode == ROUND_FLOOR) - roundingMode = (sign < 0) ? ROUND_UP : ROUND_DOWN; - else - { - // half is -1 if remainder*2 < positive intValue (*power), 0 if equal, - // 1 if >. This implies that the remainder to round is less than, - // equal to, or greater than half way to the next digit. - BigInteger posRemainder - = parts[1].signum () < 0 ? parts[1].negate() : parts[1]; - valIntVal = valIntVal.signum () < 0 ? valIntVal.negate () : valIntVal; - int half = posRemainder.shiftLeft(1).compareTo(valIntVal); - - switch(roundingMode) - { - case ROUND_HALF_UP: - roundingMode = (half < 0) ? ROUND_DOWN : ROUND_UP; - break; - case ROUND_HALF_DOWN: - roundingMode = (half > 0) ? ROUND_UP : ROUND_DOWN; - break; - case ROUND_HALF_EVEN: - if (half < 0) - roundingMode = ROUND_DOWN; - else if (half > 0) - roundingMode = ROUND_UP; - else if (unrounded.testBit(0)) // odd, then ROUND_HALF_UP - roundingMode = ROUND_UP; - else // even, ROUND_HALF_DOWN - roundingMode = ROUND_DOWN; - break; - } - } - - if (roundingMode == ROUND_UP) - unrounded = unrounded.add (BigInteger.valueOf (sign > 0 ? 1 : -1)); - - // roundingMode == ROUND_DOWN - return new BigDecimal (unrounded, newScale); - } - - public int compareTo (BigDecimal val) - { - if (scale == val.scale) - return intVal.compareTo (val.intVal); - - BigInteger thisParts[] = - intVal.divideAndRemainder (BigInteger.valueOf (10).pow (scale)); - BigInteger valParts[] = - val.intVal.divideAndRemainder (BigInteger.valueOf (10).pow (val.scale)); - - int compare; - if ((compare = thisParts[0].compareTo (valParts[0])) != 0) - return compare; - - // quotients are the same, so compare remainders - - // remove trailing zeros - if (thisParts[1].equals (BigInteger.valueOf (0)) == false) - while (thisParts[1].mod (BigInteger.valueOf (10)).equals - (BigInteger.valueOf (0))) - thisParts[1] = thisParts[1].divide (BigInteger.valueOf (10)); - // again... - if (valParts[1].equals(BigInteger.valueOf (0)) == false) - while (valParts[1].mod (BigInteger.valueOf (10)).equals - (BigInteger.valueOf (0))) - valParts[1] = valParts[1].divide (BigInteger.valueOf (10)); - - // and compare them - return thisParts[1].compareTo (valParts[1]); - } - - public int compareTo (Object val) - { - return(compareTo((BigDecimal)val)); - } - - public boolean equals (Object o) - { - return (o instanceof BigDecimal - && scale == ((BigDecimal) o).scale - && compareTo ((BigDecimal) o) == 0); - } - - public int hashCode() - { - return intValue() ^ scale; - } - - public BigDecimal max (BigDecimal val) - { - switch (compareTo (val)) - { - case 1: - return this; - default: - return val; - } - } - - public BigDecimal min (BigDecimal val) - { - switch (compareTo (val)) - { - case -1: - return this; - default: - return val; - } - } - - public BigDecimal movePointLeft (int n) - { - return (n < 0) ? movePointRight (-n) : new BigDecimal (intVal, scale + n); - } - - public BigDecimal movePointRight (int n) - { - if (n < 0) - return movePointLeft (-n); - - if (scale >= n) - return new BigDecimal (intVal, scale - n); - - return new BigDecimal (intVal.multiply - (BigInteger.valueOf (10).pow (n - scale)), 0); - } - - public int signum () - { - return intVal.signum (); - } - - public int scale () - { - return scale; - } - - public BigInteger unscaledValue() - { - return intVal; - } - - public BigDecimal abs () - { - return new BigDecimal (intVal.abs (), scale); - } - - public BigDecimal negate () - { - return new BigDecimal (intVal.negate (), scale); - } - - public String toString () - { - String bigStr = intVal.toString(); - if (scale == 0) - return bigStr; - - boolean negative = (bigStr.charAt(0) == '-'); - - int point = bigStr.length() - scale - (negative ? 1 : 0); - - StringBuffer sb = new StringBuffer(bigStr.length() + 2 + - (point <= 0 ? (-point + 1) : 0)); - if (point <= 0) - { - if (negative) - sb.append('-'); - sb.append('0').append('.'); - while (point < 0) - { - sb.append('0'); - point++; - } - sb.append(bigStr.substring(negative ? 1 : 0)); - } - else - { - sb.append(bigStr); - sb.insert(point + (negative ? 1 : 0), '.'); - } - return sb.toString(); - } - - public BigInteger toBigInteger () - { - return scale == 0 ? intVal : - intVal.divide (BigInteger.valueOf (10).pow (scale)); - } - - public int intValue () - { - return toBigInteger ().intValue (); - } - - public long longValue () - { - return toBigInteger().longValue(); - } - - public float floatValue() - { - return Float.valueOf(toString()).floatValue(); - } - - public double doubleValue() - { - return Double.valueOf(toString()).doubleValue(); - } - - public BigDecimal setScale (int scale) throws ArithmeticException - { - return setScale (scale, ROUND_UNNECESSARY); - } - - public BigDecimal setScale (int scale, int roundingMode) - throws ArithmeticException, IllegalArgumentException - { - return divide (ONE, scale, roundingMode); - } -} diff --git a/libjava/java/math/BigInteger.java b/libjava/java/math/BigInteger.java deleted file mode 100644 index 82f550d144c..00000000000 --- a/libjava/java/math/BigInteger.java +++ /dev/null @@ -1,2230 +0,0 @@ -/* java.math.BigInteger -- Arbitary precision integers - Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.math; - -import gnu.java.math.MPN; - -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.util.Random; - -/** - * Written using on-line Java Platform 1.2 API Specification, as well - * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998) and - * "Applied Cryptography, Second Edition" by Bruce Schneier (Wiley, 1996). - * - * Based primarily on IntNum.java BitOps.java by Per Bothner (per@bothner.com) - * (found in Kawa 1.6.62). - * - * @author Warren Levy (warrenl@cygnus.com) - * @date December 20, 1999. - * @status believed complete and correct. - */ -public class BigInteger extends Number implements Comparable -{ - /** All integers are stored in 2's-complement form. - * If words == null, the ival is the value of this BigInteger. - * Otherwise, the first ival elements of words make the value - * of this BigInteger, stored in little-endian order, 2's-complement form. */ - private transient int ival; - private transient int[] words; - - // Serialization fields. - private int bitCount = -1; - private int bitLength = -1; - private int firstNonzeroByteNum = -2; - private int lowestSetBit = -2; - private byte[] magnitude; - private int signum; - private static final long serialVersionUID = -8287574255936472291L; - - - /** We pre-allocate integers in the range minFixNum..maxFixNum. */ - private static final int minFixNum = -100; - private static final int maxFixNum = 1024; - private static final int numFixNum = maxFixNum-minFixNum+1; - private static final BigInteger[] smallFixNums = new BigInteger[numFixNum]; - - static { - for (int i = numFixNum; --i >= 0; ) - smallFixNums[i] = new BigInteger(i + minFixNum); - } - - // JDK1.2 - public static final BigInteger ZERO = smallFixNums[-minFixNum]; - - // JDK1.2 - public static final BigInteger ONE = smallFixNums[1 - minFixNum]; - - /* Rounding modes: */ - private static final int FLOOR = 1; - private static final int CEILING = 2; - private static final int TRUNCATE = 3; - private static final int ROUND = 4; - - /** When checking the probability of primes, it is most efficient to - * first check the factoring of small primes, so we'll use this array. - */ - private static final int[] primes = - { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, - 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, - 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, - 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251 }; - - /** HAC (Handbook of Applied Cryptography), Alfred Menezes & al. Table 4.4. */ - private static final int[] k = - {100,150,200,250,300,350,400,500,600,800,1250, Integer.MAX_VALUE}; - private static final int[] t = - { 27, 18, 15, 12, 9, 8, 7, 6, 5, 4, 3, 2}; - - private BigInteger() - { - } - - /* Create a new (non-shared) BigInteger, and initialize to an int. */ - private BigInteger(int value) - { - ival = value; - } - - public BigInteger(String val, int radix) - { - BigInteger result = valueOf(val, radix); - this.ival = result.ival; - this.words = result.words; - } - - public BigInteger(String val) - { - this(val, 10); - } - - /* Create a new (non-shared) BigInteger, and initialize from a byte array. */ - public BigInteger(byte[] val) - { - if (val == null || val.length < 1) - throw new NumberFormatException(); - - words = byteArrayToIntArray(val, val[0] < 0 ? -1 : 0); - BigInteger result = make(words, words.length); - this.ival = result.ival; - this.words = result.words; - } - - public BigInteger(int signum, byte[] magnitude) - { - if (magnitude == null || signum > 1 || signum < -1) - throw new NumberFormatException(); - - if (signum == 0) - { - int i; - for (i = magnitude.length - 1; i >= 0 && magnitude[i] == 0; --i) - ; - if (i >= 0) - throw new NumberFormatException(); - return; - } - - // Magnitude is always positive, so don't ever pass a sign of -1. - words = byteArrayToIntArray(magnitude, 0); - BigInteger result = make(words, words.length); - this.ival = result.ival; - this.words = result.words; - - if (signum < 0) - setNegative(); - } - - public BigInteger(int numBits, Random rnd) - { - if (numBits < 0) - throw new IllegalArgumentException(); - - init(numBits, rnd); - } - - private void init(int numBits, Random rnd) - { - int highbits = numBits & 31; - if (highbits > 0) - highbits = rnd.nextInt() >>> (32 - highbits); - int nwords = numBits / 32; - - while (highbits == 0 && nwords > 0) - { - highbits = rnd.nextInt(); - --nwords; - } - if (nwords == 0 && highbits >= 0) - { - ival = highbits; - } - else - { - ival = highbits < 0 ? nwords + 2 : nwords + 1; - words = new int[ival]; - words[nwords] = highbits; - while (--nwords >= 0) - words[nwords] = rnd.nextInt(); - } - } - - public BigInteger(int bitLength, int certainty, Random rnd) - { - this(bitLength, rnd); - - // Keep going until we find a probable prime. - while (true) - { - if (isProbablePrime(certainty)) - return; - - init(bitLength, rnd); - } - } - - /** - * Return a BigInteger that is bitLength bits long with a - * probability < 2^-100 of being composite. - * - * @param bitLength length in bits of resulting number - * @param rnd random number generator to use - * @throws ArithmeticException if bitLength < 2 - * @since 1.4 - */ - public static BigInteger probablePrime(int bitLength, Random rnd) - { - if (bitLength < 2) - throw new ArithmeticException(); - - return new BigInteger(bitLength, 100, rnd); - } - - /** Return a (possibly-shared) BigInteger with a given long value. */ - public static BigInteger valueOf(long val) - { - if (val >= minFixNum && val <= maxFixNum) - return smallFixNums[(int) val - minFixNum]; - int i = (int) val; - if ((long) i == val) - return new BigInteger(i); - BigInteger result = alloc(2); - result.ival = 2; - result.words[0] = i; - result.words[1] = (int)(val >> 32); - return result; - } - - /** Make a canonicalized BigInteger from an array of words. - * The array may be reused (without copying). */ - private static BigInteger make(int[] words, int len) - { - if (words == null) - return valueOf(len); - len = BigInteger.wordsNeeded(words, len); - if (len <= 1) - return len == 0 ? ZERO : valueOf(words[0]); - BigInteger num = new BigInteger(); - num.words = words; - num.ival = len; - return num; - } - - /** Convert a big-endian byte array to a little-endian array of words. */ - private static int[] byteArrayToIntArray(byte[] bytes, int sign) - { - // Determine number of words needed. - int[] words = new int[bytes.length/4 + 1]; - int nwords = words.length; - - // Create a int out of modulo 4 high order bytes. - int bptr = 0; - int word = sign; - for (int i = bytes.length % 4; i > 0; --i, bptr++) - word = (word << 8) | (bytes[bptr] & 0xff); - words[--nwords] = word; - - // Elements remaining in byte[] are a multiple of 4. - while (nwords > 0) - words[--nwords] = bytes[bptr++] << 24 | - (bytes[bptr++] & 0xff) << 16 | - (bytes[bptr++] & 0xff) << 8 | - (bytes[bptr++] & 0xff); - return words; - } - - /** Allocate a new non-shared BigInteger. - * @param nwords number of words to allocate - */ - private static BigInteger alloc(int nwords) - { - BigInteger result = new BigInteger(); - if (nwords > 1) - result.words = new int[nwords]; - return result; - } - - /** Change words.length to nwords. - * We allow words.length to be upto nwords+2 without reallocating. - */ - private void realloc(int nwords) - { - if (nwords == 0) - { - if (words != null) - { - if (ival > 0) - ival = words[0]; - words = null; - } - } - else if (words == null - || words.length < nwords - || words.length > nwords + 2) - { - int[] new_words = new int [nwords]; - if (words == null) - { - new_words[0] = ival; - ival = 1; - } - else - { - if (nwords < ival) - ival = nwords; - System.arraycopy(words, 0, new_words, 0, ival); - } - words = new_words; - } - } - - private boolean isNegative() - { - return (words == null ? ival : words[ival - 1]) < 0; - } - - public int signum() - { - int top = words == null ? ival : words[ival-1]; - if (top == 0 && words == null) - return 0; - return top < 0 ? -1 : 1; - } - - private static int compareTo(BigInteger x, BigInteger y) - { - if (x.words == null && y.words == null) - return x.ival < y.ival ? -1 : x.ival > y.ival ? 1 : 0; - boolean x_negative = x.isNegative(); - boolean y_negative = y.isNegative(); - if (x_negative != y_negative) - return x_negative ? -1 : 1; - int x_len = x.words == null ? 1 : x.ival; - int y_len = y.words == null ? 1 : y.ival; - if (x_len != y_len) - return (x_len > y_len) != x_negative ? 1 : -1; - return MPN.cmp(x.words, y.words, x_len); - } - - // JDK1.2 - public int compareTo(Object obj) - { - if (obj instanceof BigInteger) - return compareTo(this, (BigInteger) obj); - throw new ClassCastException(); - } - - public int compareTo(BigInteger val) - { - return compareTo(this, val); - } - - public BigInteger min(BigInteger val) - { - return compareTo(this, val) < 0 ? this : val; - } - - public BigInteger max(BigInteger val) - { - return compareTo(this, val) > 0 ? this : val; - } - - private boolean isZero() - { - return words == null && ival == 0; - } - - private boolean isOne() - { - return words == null && ival == 1; - } - - /** Calculate how many words are significant in words[0:len-1]. - * Returns the least value x such that x>0 && words[0:x-1]==words[0:len-1], - * when words is viewed as a 2's complement integer. - */ - private static int wordsNeeded(int[] words, int len) - { - int i = len; - if (i > 0) - { - int word = words[--i]; - if (word == -1) - { - while (i > 0 && (word = words[i - 1]) < 0) - { - i--; - if (word != -1) break; - } - } - else - { - while (word == 0 && i > 0 && (word = words[i - 1]) >= 0) i--; - } - } - return i + 1; - } - - private BigInteger canonicalize() - { - if (words != null - && (ival = BigInteger.wordsNeeded(words, ival)) <= 1) - { - if (ival == 1) - ival = words[0]; - words = null; - } - if (words == null && ival >= minFixNum && ival <= maxFixNum) - return smallFixNums[ival - minFixNum]; - return this; - } - - /** Add two ints, yielding a BigInteger. */ - private static BigInteger add(int x, int y) - { - return valueOf((long) x + (long) y); - } - - /** Add a BigInteger and an int, yielding a new BigInteger. */ - private static BigInteger add(BigInteger x, int y) - { - if (x.words == null) - return BigInteger.add(x.ival, y); - BigInteger result = new BigInteger(0); - result.setAdd(x, y); - return result.canonicalize(); - } - - /** Set this to the sum of x and y. - * OK if x==this. */ - private void setAdd(BigInteger x, int y) - { - if (x.words == null) - { - set((long) x.ival + (long) y); - return; - } - int len = x.ival; - realloc(len + 1); - long carry = y; - for (int i = 0; i < len; i++) - { - carry += ((long) x.words[i] & 0xffffffffL); - words[i] = (int) carry; - carry >>= 32; - } - if (x.words[len - 1] < 0) - carry--; - words[len] = (int) carry; - ival = wordsNeeded(words, len + 1); - } - - /** Destructively add an int to this. */ - private void setAdd(int y) - { - setAdd(this, y); - } - - /** Destructively set the value of this to a long. */ - private void set(long y) - { - int i = (int) y; - if ((long) i == y) - { - ival = i; - words = null; - } - else - { - realloc(2); - words[0] = i; - words[1] = (int) (y >> 32); - ival = 2; - } - } - - /** Destructively set the value of this to the given words. - * The words array is reused, not copied. */ - private void set(int[] words, int length) - { - this.ival = length; - this.words = words; - } - - /** Destructively set the value of this to that of y. */ - private void set(BigInteger y) - { - if (y.words == null) - set(y.ival); - else if (this != y) - { - realloc(y.ival); - System.arraycopy(y.words, 0, words, 0, y.ival); - ival = y.ival; - } - } - - /** Add two BigIntegers, yielding their sum as another BigInteger. */ - private static BigInteger add(BigInteger x, BigInteger y, int k) - { - if (x.words == null && y.words == null) - return valueOf((long) k * (long) y.ival + (long) x.ival); - if (k != 1) - { - if (k == -1) - y = BigInteger.neg(y); - else - y = BigInteger.times(y, valueOf(k)); - } - if (x.words == null) - return BigInteger.add(y, x.ival); - if (y.words == null) - return BigInteger.add(x, y.ival); - // Both are big - if (y.ival > x.ival) - { // Swap so x is longer then y. - BigInteger tmp = x; x = y; y = tmp; - } - BigInteger result = alloc(x.ival + 1); - int i = y.ival; - long carry = MPN.add_n(result.words, x.words, y.words, i); - long y_ext = y.words[i - 1] < 0 ? 0xffffffffL : 0; - for (; i < x.ival; i++) - { - carry += ((long) x.words[i] & 0xffffffffL) + y_ext;; - result.words[i] = (int) carry; - carry >>>= 32; - } - if (x.words[i - 1] < 0) - y_ext--; - result.words[i] = (int) (carry + y_ext); - result.ival = i+1; - return result.canonicalize(); - } - - public BigInteger add(BigInteger val) - { - return add(this, val, 1); - } - - public BigInteger subtract(BigInteger val) - { - return add(this, val, -1); - } - - private static BigInteger times(BigInteger x, int y) - { - if (y == 0) - return ZERO; - if (y == 1) - return x; - int[] xwords = x.words; - int xlen = x.ival; - if (xwords == null) - return valueOf((long) xlen * (long) y); - boolean negative; - BigInteger result = BigInteger.alloc(xlen + 1); - if (xwords[xlen - 1] < 0) - { - negative = true; - negate(result.words, xwords, xlen); - xwords = result.words; - } - else - negative = false; - if (y < 0) - { - negative = !negative; - y = -y; - } - result.words[xlen] = MPN.mul_1(result.words, xwords, xlen, y); - result.ival = xlen + 1; - if (negative) - result.setNegative(); - return result.canonicalize(); - } - - private static BigInteger times(BigInteger x, BigInteger y) - { - if (y.words == null) - return times(x, y.ival); - if (x.words == null) - return times(y, x.ival); - boolean negative = false; - int[] xwords; - int[] ywords; - int xlen = x.ival; - int ylen = y.ival; - if (x.isNegative()) - { - negative = true; - xwords = new int[xlen]; - negate(xwords, x.words, xlen); - } - else - { - negative = false; - xwords = x.words; - } - if (y.isNegative()) - { - negative = !negative; - ywords = new int[ylen]; - negate(ywords, y.words, ylen); - } - else - ywords = y.words; - // Swap if x is shorter then y. - if (xlen < ylen) - { - int[] twords = xwords; xwords = ywords; ywords = twords; - int tlen = xlen; xlen = ylen; ylen = tlen; - } - BigInteger result = BigInteger.alloc(xlen+ylen); - MPN.mul(result.words, xwords, xlen, ywords, ylen); - result.ival = xlen+ylen; - if (negative) - result.setNegative(); - return result.canonicalize(); - } - - public BigInteger multiply(BigInteger y) - { - return times(this, y); - } - - private static void divide(long x, long y, - BigInteger quotient, BigInteger remainder, - int rounding_mode) - { - boolean xNegative, yNegative; - if (x < 0) - { - xNegative = true; - if (x == Long.MIN_VALUE) - { - divide(valueOf(x), valueOf(y), - quotient, remainder, rounding_mode); - return; - } - x = -x; - } - else - xNegative = false; - - if (y < 0) - { - yNegative = true; - if (y == Long.MIN_VALUE) - { - if (rounding_mode == TRUNCATE) - { // x != Long.Min_VALUE implies abs(x) < abs(y) - if (quotient != null) - quotient.set(0); - if (remainder != null) - remainder.set(x); - } - else - divide(valueOf(x), valueOf(y), - quotient, remainder, rounding_mode); - return; - } - y = -y; - } - else - yNegative = false; - - long q = x / y; - long r = x % y; - boolean qNegative = xNegative ^ yNegative; - - boolean add_one = false; - if (r != 0) - { - switch (rounding_mode) - { - case TRUNCATE: - break; - case CEILING: - case FLOOR: - if (qNegative == (rounding_mode == FLOOR)) - add_one = true; - break; - case ROUND: - add_one = r > ((y - (q & 1)) >> 1); - break; - } - } - if (quotient != null) - { - if (add_one) - q++; - if (qNegative) - q = -q; - quotient.set(q); - } - if (remainder != null) - { - // The remainder is by definition: X-Q*Y - if (add_one) - { - // Subtract the remainder from Y. - r = y - r; - // In this case, abs(Q*Y) > abs(X). - // So sign(remainder) = -sign(X). - xNegative = ! xNegative; - } - else - { - // If !add_one, then: abs(Q*Y) <= abs(X). - // So sign(remainder) = sign(X). - } - if (xNegative) - r = -r; - remainder.set(r); - } - } - - /** Divide two integers, yielding quotient and remainder. - * @param x the numerator in the division - * @param y the denominator in the division - * @param quotient is set to the quotient of the result (iff quotient!=null) - * @param remainder is set to the remainder of the result - * (iff remainder!=null) - * @param rounding_mode one of FLOOR, CEILING, TRUNCATE, or ROUND. - */ - private static void divide(BigInteger x, BigInteger y, - BigInteger quotient, BigInteger remainder, - int rounding_mode) - { - if ((x.words == null || x.ival <= 2) - && (y.words == null || y.ival <= 2)) - { - long x_l = x.longValue(); - long y_l = y.longValue(); - if (x_l != Long.MIN_VALUE && y_l != Long.MIN_VALUE) - { - divide(x_l, y_l, quotient, remainder, rounding_mode); - return; - } - } - - boolean xNegative = x.isNegative(); - boolean yNegative = y.isNegative(); - boolean qNegative = xNegative ^ yNegative; - - int ylen = y.words == null ? 1 : y.ival; - int[] ywords = new int[ylen]; - y.getAbsolute(ywords); - while (ylen > 1 && ywords[ylen - 1] == 0) ylen--; - - int xlen = x.words == null ? 1 : x.ival; - int[] xwords = new int[xlen+2]; - x.getAbsolute(xwords); - while (xlen > 1 && xwords[xlen-1] == 0) xlen--; - - int qlen, rlen; - - int cmpval = MPN.cmp(xwords, xlen, ywords, ylen); - if (cmpval < 0) // abs(x) < abs(y) - { // quotient = 0; remainder = num. - int[] rwords = xwords; xwords = ywords; ywords = rwords; - rlen = xlen; qlen = 1; xwords[0] = 0; - } - else if (cmpval == 0) // abs(x) == abs(y) - { - xwords[0] = 1; qlen = 1; // quotient = 1 - ywords[0] = 0; rlen = 1; // remainder = 0; - } - else if (ylen == 1) - { - qlen = xlen; - // Need to leave room for a word of leading zeros if dividing by 1 - // and the dividend has the high bit set. It might be safe to - // increment qlen in all cases, but it certainly is only necessary - // in the following case. - if (ywords[0] == 1 && xwords[xlen-1] < 0) - qlen++; - rlen = 1; - ywords[0] = MPN.divmod_1(xwords, xwords, xlen, ywords[0]); - } - else // abs(x) > abs(y) - { - // Normalize the denominator, i.e. make its most significant bit set by - // shifting it normalization_steps bits to the left. Also shift the - // numerator the same number of steps (to keep the quotient the same!). - - int nshift = MPN.count_leading_zeros(ywords[ylen - 1]); - if (nshift != 0) - { - // Shift up the denominator setting the most significant bit of - // the most significant word. - MPN.lshift(ywords, 0, ywords, ylen, nshift); - - // Shift up the numerator, possibly introducing a new most - // significant word. - int x_high = MPN.lshift(xwords, 0, xwords, xlen, nshift); - xwords[xlen++] = x_high; - } - - if (xlen == ylen) - xwords[xlen++] = 0; - MPN.divide(xwords, xlen, ywords, ylen); - rlen = ylen; - MPN.rshift0 (ywords, xwords, 0, rlen, nshift); - - qlen = xlen + 1 - ylen; - if (quotient != null) - { - for (int i = 0; i < qlen; i++) - xwords[i] = xwords[i+ylen]; - } - } - - if (ywords[rlen-1] < 0) - { - ywords[rlen] = 0; - rlen++; - } - - // Now the quotient is in xwords, and the remainder is in ywords. - - boolean add_one = false; - if (rlen > 1 || ywords[0] != 0) - { // Non-zero remainder i.e. in-exact quotient. - switch (rounding_mode) - { - case TRUNCATE: - break; - case CEILING: - case FLOOR: - if (qNegative == (rounding_mode == FLOOR)) - add_one = true; - break; - case ROUND: - // int cmp = compareTo(remainder<<1, abs(y)); - BigInteger tmp = remainder == null ? new BigInteger() : remainder; - tmp.set(ywords, rlen); - tmp = shift(tmp, 1); - if (yNegative) - tmp.setNegative(); - int cmp = compareTo(tmp, y); - // Now cmp == compareTo(sign(y)*(remainder<<1), y) - if (yNegative) - cmp = -cmp; - add_one = (cmp == 1) || (cmp == 0 && (xwords[0]&1) != 0); - } - } - if (quotient != null) - { - quotient.set(xwords, qlen); - if (qNegative) - { - if (add_one) // -(quotient + 1) == ~(quotient) - quotient.setInvert(); - else - quotient.setNegative(); - } - else if (add_one) - quotient.setAdd(1); - } - if (remainder != null) - { - // The remainder is by definition: X-Q*Y - remainder.set(ywords, rlen); - if (add_one) - { - // Subtract the remainder from Y: - // abs(R) = abs(Y) - abs(orig_rem) = -(abs(orig_rem) - abs(Y)). - BigInteger tmp; - if (y.words == null) - { - tmp = remainder; - tmp.set(yNegative ? ywords[0] + y.ival : ywords[0] - y.ival); - } - else - tmp = BigInteger.add(remainder, y, yNegative ? 1 : -1); - // Now tmp <= 0. - // In this case, abs(Q) = 1 + floor(abs(X)/abs(Y)). - // Hence, abs(Q*Y) > abs(X). - // So sign(remainder) = -sign(X). - if (xNegative) - remainder.setNegative(tmp); - else - remainder.set(tmp); - } - else - { - // If !add_one, then: abs(Q*Y) <= abs(X). - // So sign(remainder) = sign(X). - if (xNegative) - remainder.setNegative(); - } - } - } - - public BigInteger divide(BigInteger val) - { - if (val.isZero()) - throw new ArithmeticException("divisor is zero"); - - BigInteger quot = new BigInteger(); - divide(this, val, quot, null, TRUNCATE); - return quot.canonicalize(); - } - - public BigInteger remainder(BigInteger val) - { - if (val.isZero()) - throw new ArithmeticException("divisor is zero"); - - BigInteger rem = new BigInteger(); - divide(this, val, null, rem, TRUNCATE); - return rem.canonicalize(); - } - - public BigInteger[] divideAndRemainder(BigInteger val) - { - if (val.isZero()) - throw new ArithmeticException("divisor is zero"); - - BigInteger[] result = new BigInteger[2]; - result[0] = new BigInteger(); - result[1] = new BigInteger(); - divide(this, val, result[0], result[1], TRUNCATE); - result[0].canonicalize(); - result[1].canonicalize(); - return result; - } - - public BigInteger mod(BigInteger m) - { - if (m.isNegative() || m.isZero()) - throw new ArithmeticException("non-positive modulus"); - - BigInteger rem = new BigInteger(); - divide(this, m, null, rem, FLOOR); - return rem.canonicalize(); - } - - /** Calculate the integral power of a BigInteger. - * @param exponent the exponent (must be non-negative) - */ - public BigInteger pow(int exponent) - { - if (exponent <= 0) - { - if (exponent == 0) - return ONE; - throw new ArithmeticException("negative exponent"); - } - if (isZero()) - return this; - int plen = words == null ? 1 : ival; // Length of pow2. - int blen = ((bitLength() * exponent) >> 5) + 2 * plen; - boolean negative = isNegative() && (exponent & 1) != 0; - int[] pow2 = new int [blen]; - int[] rwords = new int [blen]; - int[] work = new int [blen]; - getAbsolute(pow2); // pow2 = abs(this); - int rlen = 1; - rwords[0] = 1; // rwords = 1; - for (;;) // for (i = 0; ; i++) - { - // pow2 == this**(2**i) - // prod = this**(sum(j=0..i-1, (exponent>>j)&1)) - if ((exponent & 1) != 0) - { // r *= pow2 - MPN.mul(work, pow2, plen, rwords, rlen); - int[] temp = work; work = rwords; rwords = temp; - rlen += plen; - while (rwords[rlen - 1] == 0) rlen--; - } - exponent >>= 1; - if (exponent == 0) - break; - // pow2 *= pow2; - MPN.mul(work, pow2, plen, pow2, plen); - int[] temp = work; work = pow2; pow2 = temp; // swap to avoid a copy - plen *= 2; - while (pow2[plen - 1] == 0) plen--; - } - if (rwords[rlen - 1] < 0) - rlen++; - if (negative) - negate(rwords, rwords, rlen); - return BigInteger.make(rwords, rlen); - } - - private static int[] euclidInv(int a, int b, int prevDiv) - { - if (b == 0) - throw new ArithmeticException("not invertible"); - - if (b == 1) - // Success: values are indeed invertible! - // Bottom of the recursion reached; start unwinding. - return new int[] { -prevDiv, 1 }; - - int[] xy = euclidInv(b, a % b, a / b); // Recursion happens here. - a = xy[0]; // use our local copy of 'a' as a work var - xy[0] = a * -prevDiv + xy[1]; - xy[1] = a; - return xy; - } - - private static void euclidInv(BigInteger a, BigInteger b, - BigInteger prevDiv, BigInteger[] xy) - { - if (b.isZero()) - throw new ArithmeticException("not invertible"); - - if (b.isOne()) - { - // Success: values are indeed invertible! - // Bottom of the recursion reached; start unwinding. - xy[0] = neg(prevDiv); - xy[1] = ONE; - return; - } - - // Recursion happens in the following conditional! - - // If a just contains an int, then use integer math for the rest. - if (a.words == null) - { - int[] xyInt = euclidInv(b.ival, a.ival % b.ival, a.ival / b.ival); - xy[0] = new BigInteger(xyInt[0]); - xy[1] = new BigInteger(xyInt[1]); - } - else - { - BigInteger rem = new BigInteger(); - BigInteger quot = new BigInteger(); - divide(a, b, quot, rem, FLOOR); - // quot and rem may not be in canonical form. ensure - rem.canonicalize(); - quot.canonicalize(); - euclidInv(b, rem, quot, xy); - } - - BigInteger t = xy[0]; - xy[0] = add(xy[1], times(t, prevDiv), -1); - xy[1] = t; - } - - public BigInteger modInverse(BigInteger y) - { - if (y.isNegative() || y.isZero()) - throw new ArithmeticException("non-positive modulo"); - - // Degenerate cases. - if (y.isOne()) - return ZERO; - if (isOne()) - return ONE; - - // Use Euclid's algorithm as in gcd() but do this recursively - // rather than in a loop so we can use the intermediate results as we - // unwind from the recursion. - // Used http://www.math.nmsu.edu/~crypto/EuclideanAlgo.html as reference. - BigInteger result = new BigInteger(); - boolean swapped = false; - - if (y.words == null) - { - // The result is guaranteed to be less than the modulus, y (which is - // an int), so simplify this by working with the int result of this - // modulo y. Also, if this is negative, make it positive via modulo - // math. Note that BigInteger.mod() must be used even if this is - // already an int as the % operator would provide a negative result if - // this is negative, BigInteger.mod() never returns negative values. - int xval = (words != null || isNegative()) ? mod(y).ival : ival; - int yval = y.ival; - - // Swap values so x > y. - if (yval > xval) - { - int tmp = xval; xval = yval; yval = tmp; - swapped = true; - } - // Normally, the result is in the 2nd element of the array, but - // if originally x < y, then x and y were swapped and the result - // is in the 1st element of the array. - result.ival = - euclidInv(yval, xval % yval, xval / yval)[swapped ? 0 : 1]; - - // Result can't be negative, so make it positive by adding the - // original modulus, y.ival (not the possibly "swapped" yval). - if (result.ival < 0) - result.ival += y.ival; - } - else - { - // As above, force this to be a positive value via modulo math. - BigInteger x = isNegative() ? this.mod(y) : this; - - // Swap values so x > y. - if (x.compareTo(y) < 0) - { - result = x; x = y; y = result; // use 'result' as a work var - swapped = true; - } - // As above (for ints), result will be in the 2nd element unless - // the original x and y were swapped. - BigInteger rem = new BigInteger(); - BigInteger quot = new BigInteger(); - divide(x, y, quot, rem, FLOOR); - // quot and rem may not be in canonical form. ensure - rem.canonicalize(); - quot.canonicalize(); - BigInteger[] xy = new BigInteger[2]; - euclidInv(y, rem, quot, xy); - result = swapped ? xy[0] : xy[1]; - - // Result can't be negative, so make it positive by adding the - // original modulus, y (which is now x if they were swapped). - if (result.isNegative()) - result = add(result, swapped ? x : y, 1); - } - - return result; - } - - public BigInteger modPow(BigInteger exponent, BigInteger m) - { - if (m.isNegative() || m.isZero()) - throw new ArithmeticException("non-positive modulo"); - - if (exponent.isNegative()) - return modInverse(m); - if (exponent.isOne()) - return mod(m); - - // To do this naively by first raising this to the power of exponent - // and then performing modulo m would be extremely expensive, especially - // for very large numbers. The solution is found in Number Theory - // where a combination of partial powers and moduli can be done easily. - // - // We'll use the algorithm for Additive Chaining which can be found on - // p. 244 of "Applied Cryptography, Second Edition" by Bruce Schneier. - BigInteger s = ONE; - BigInteger t = this; - BigInteger u = exponent; - - while (!u.isZero()) - { - if (u.and(ONE).isOne()) - s = times(s, t).mod(m); - u = u.shiftRight(1); - t = times(t, t).mod(m); - } - - return s; - } - - /** Calculate Greatest Common Divisor for non-negative ints. */ - private static int gcd(int a, int b) - { - // Euclid's algorithm, copied from libg++. - int tmp; - if (b > a) - { - tmp = a; a = b; b = tmp; - } - for(;;) - { - if (b == 0) - return a; - if (b == 1) - return b; - tmp = b; - b = a % b; - a = tmp; - } - } - - public BigInteger gcd(BigInteger y) - { - int xval = ival; - int yval = y.ival; - if (words == null) - { - if (xval == 0) - return abs(y); - if (y.words == null - && xval != Integer.MIN_VALUE && yval != Integer.MIN_VALUE) - { - if (xval < 0) - xval = -xval; - if (yval < 0) - yval = -yval; - return valueOf(gcd(xval, yval)); - } - xval = 1; - } - if (y.words == null) - { - if (yval == 0) - return abs(this); - yval = 1; - } - int len = (xval > yval ? xval : yval) + 1; - int[] xwords = new int[len]; - int[] ywords = new int[len]; - getAbsolute(xwords); - y.getAbsolute(ywords); - len = MPN.gcd(xwords, ywords, len); - BigInteger result = new BigInteger(0); - result.ival = len; - result.words = xwords; - return result.canonicalize(); - } - - /** - * <p>Returns <code>true</code> if this BigInteger is probably prime, - * <code>false</code> if it's definitely composite. If <code>certainty</code> - * is <code><= 0</code>, <code>true</code> is returned.</p> - * - * @param certainty a measure of the uncertainty that the caller is willing - * to tolerate: if the call returns <code>true</code> the probability that - * this BigInteger is prime exceeds <code>(1 - 1/2<sup>certainty</sup>)</code>. - * The execution time of this method is proportional to the value of this - * parameter. - * @return <code>true</code> if this BigInteger is probably prime, - * <code>false</code> if it's definitely composite. - */ - public boolean isProbablePrime(int certainty) - { - if (certainty < 1) - return true; - - /** We'll use the Rabin-Miller algorithm for doing a probabilistic - * primality test. It is fast, easy and has faster decreasing odds of a - * composite passing than with other tests. This means that this - * method will actually have a probability much greater than the - * 1 - .5^certainty specified in the JCL (p. 117), but I don't think - * anyone will complain about better performance with greater certainty. - * - * The Rabin-Miller algorithm can be found on pp. 259-261 of "Applied - * Cryptography, Second Edition" by Bruce Schneier. - */ - - // First rule out small prime factors - BigInteger rem = new BigInteger(); - int i; - for (i = 0; i < primes.length; i++) - { - if (words == null && ival == primes[i]) - return true; - - divide(this, smallFixNums[primes[i] - minFixNum], null, rem, TRUNCATE); - if (rem.canonicalize().isZero()) - return false; - } - - // Now perform the Rabin-Miller test. - - // Set b to the number of times 2 evenly divides (this - 1). - // I.e. 2^b is the largest power of 2 that divides (this - 1). - BigInteger pMinus1 = add(this, -1); - int b = pMinus1.getLowestSetBit(); - - // Set m such that this = 1 + 2^b * m. - BigInteger m = pMinus1.divide(valueOf(2L << b - 1)); - - // The HAC (Handbook of Applied Cryptography), Alfred Menezes & al. Note - // 4.49 (controlling the error probability) gives the number of trials - // for an error probability of 1/2**80, given the number of bits in the - // number to test. we shall use these numbers as is if/when 'certainty' - // is less or equal to 80, and twice as much if it's greater. - int bits = this.bitLength(); - for (i = 0; i < k.length; i++) - if (bits <= k[i]) - break; - int trials = t[i]; - if (certainty > 80) - trials *= 2; - BigInteger z; - for (int t = 0; t < trials; t++) - { - // The HAC (Handbook of Applied Cryptography), Alfred Menezes & al. - // Remark 4.28 states: "...A strategy that is sometimes employed - // is to fix the bases a to be the first few primes instead of - // choosing them at random. - z = smallFixNums[primes[t] - minFixNum].modPow(m, this); - if (z.isOne() || z.equals(pMinus1)) - continue; // Passes the test; may be prime. - - for (i = 0; i < b; ) - { - if (z.isOne()) - return false; - i++; - if (z.equals(pMinus1)) - break; // Passes the test; may be prime. - - z = z.modPow(valueOf(2), this); - } - - if (i == b && !z.equals(pMinus1)) - return false; - } - return true; - } - - private void setInvert() - { - if (words == null) - ival = ~ival; - else - { - for (int i = ival; --i >= 0; ) - words[i] = ~words[i]; - } - } - - private void setShiftLeft(BigInteger x, int count) - { - int[] xwords; - int xlen; - if (x.words == null) - { - if (count < 32) - { - set((long) x.ival << count); - return; - } - xwords = new int[1]; - xwords[0] = x.ival; - xlen = 1; - } - else - { - xwords = x.words; - xlen = x.ival; - } - int word_count = count >> 5; - count &= 31; - int new_len = xlen + word_count; - if (count == 0) - { - realloc(new_len); - for (int i = xlen; --i >= 0; ) - words[i+word_count] = xwords[i]; - } - else - { - new_len++; - realloc(new_len); - int shift_out = MPN.lshift(words, word_count, xwords, xlen, count); - count = 32 - count; - words[new_len-1] = (shift_out << count) >> count; // sign-extend. - } - ival = new_len; - for (int i = word_count; --i >= 0; ) - words[i] = 0; - } - - private void setShiftRight(BigInteger x, int count) - { - if (x.words == null) - set(count < 32 ? x.ival >> count : x.ival < 0 ? -1 : 0); - else if (count == 0) - set(x); - else - { - boolean neg = x.isNegative(); - int word_count = count >> 5; - count &= 31; - int d_len = x.ival - word_count; - if (d_len <= 0) - set(neg ? -1 : 0); - else - { - if (words == null || words.length < d_len) - realloc(d_len); - MPN.rshift0 (words, x.words, word_count, d_len, count); - ival = d_len; - if (neg) - words[d_len-1] |= -2 << (31 - count); - } - } - } - - private void setShift(BigInteger x, int count) - { - if (count > 0) - setShiftLeft(x, count); - else - setShiftRight(x, -count); - } - - private static BigInteger shift(BigInteger x, int count) - { - if (x.words == null) - { - if (count <= 0) - return valueOf(count > -32 ? x.ival >> (-count) : x.ival < 0 ? -1 : 0); - if (count < 32) - return valueOf((long) x.ival << count); - } - if (count == 0) - return x; - BigInteger result = new BigInteger(0); - result.setShift(x, count); - return result.canonicalize(); - } - - public BigInteger shiftLeft(int n) - { - return shift(this, n); - } - - public BigInteger shiftRight(int n) - { - return shift(this, -n); - } - - private void format(int radix, StringBuffer buffer) - { - if (words == null) - buffer.append(Integer.toString(ival, radix)); - else if (ival <= 2) - buffer.append(Long.toString(longValue(), radix)); - else - { - boolean neg = isNegative(); - int[] work; - if (neg || radix != 16) - { - work = new int[ival]; - getAbsolute(work); - } - else - work = words; - int len = ival; - - if (radix == 16) - { - if (neg) - buffer.append('-'); - int buf_start = buffer.length(); - for (int i = len; --i >= 0; ) - { - int word = work[i]; - for (int j = 8; --j >= 0; ) - { - int hex_digit = (word >> (4 * j)) & 0xF; - // Suppress leading zeros: - if (hex_digit > 0 || buffer.length() > buf_start) - buffer.append(Character.forDigit(hex_digit, 16)); - } - } - } - else - { - int i = buffer.length(); - for (;;) - { - int digit = MPN.divmod_1(work, work, len, radix); - buffer.append(Character.forDigit(digit, radix)); - while (len > 0 && work[len-1] == 0) len--; - if (len == 0) - break; - } - if (neg) - buffer.append('-'); - /* Reverse buffer. */ - int j = buffer.length() - 1; - while (i < j) - { - char tmp = buffer.charAt(i); - buffer.setCharAt(i, buffer.charAt(j)); - buffer.setCharAt(j, tmp); - i++; j--; - } - } - } - } - - public String toString() - { - return toString(10); - } - - public String toString(int radix) - { - if (words == null) - return Integer.toString(ival, radix); - if (ival <= 2) - return Long.toString(longValue(), radix); - int buf_size = ival * (MPN.chars_per_word(radix) + 1); - StringBuffer buffer = new StringBuffer(buf_size); - format(radix, buffer); - return buffer.toString(); - } - - public int intValue() - { - if (words == null) - return ival; - return words[0]; - } - - public long longValue() - { - if (words == null) - return ival; - if (ival == 1) - return words[0]; - return ((long)words[1] << 32) + ((long)words[0] & 0xffffffffL); - } - - public int hashCode() - { - // FIXME: May not match hashcode of JDK. - return words == null ? ival : (words[0] + words[ival - 1]); - } - - /* Assumes x and y are both canonicalized. */ - private static boolean equals(BigInteger x, BigInteger y) - { - if (x.words == null && y.words == null) - return x.ival == y.ival; - if (x.words == null || y.words == null || x.ival != y.ival) - return false; - for (int i = x.ival; --i >= 0; ) - { - if (x.words[i] != y.words[i]) - return false; - } - return true; - } - - /* Assumes this and obj are both canonicalized. */ - public boolean equals(Object obj) - { - if (! (obj instanceof BigInteger)) - return false; - return equals(this, (BigInteger) obj); - } - - private static BigInteger valueOf(String s, int radix) - throws NumberFormatException - { - int len = s.length(); - // Testing (len < MPN.chars_per_word(radix)) would be more accurate, - // but slightly more expensive, for little practical gain. - if (len <= 15 && radix <= 16) - return valueOf(Long.parseLong(s, radix)); - - int byte_len = 0; - byte[] bytes = new byte[len]; - boolean negative = false; - for (int i = 0; i < len; i++) - { - char ch = s.charAt(i); - if (ch == '-') - negative = true; - else if (ch == '_' || (byte_len == 0 && (ch == ' ' || ch == '\t'))) - continue; - else - { - int digit = Character.digit(ch, radix); - if (digit < 0) - break; - bytes[byte_len++] = (byte) digit; - } - } - return valueOf(bytes, byte_len, negative, radix); - } - - private static BigInteger valueOf(byte[] digits, int byte_len, - boolean negative, int radix) - { - int chars_per_word = MPN.chars_per_word(radix); - int[] words = new int[byte_len / chars_per_word + 1]; - int size = MPN.set_str(words, digits, byte_len, radix); - if (size == 0) - return ZERO; - if (words[size-1] < 0) - words[size++] = 0; - if (negative) - negate(words, words, size); - return make(words, size); - } - - public double doubleValue() - { - if (words == null) - return (double) ival; - if (ival <= 2) - return (double) longValue(); - if (isNegative()) - return neg(this).roundToDouble(0, true, false); - return roundToDouble(0, false, false); - } - - public float floatValue() - { - return (float) doubleValue(); - } - - /** Return true if any of the lowest n bits are one. - * (false if n is negative). */ - private boolean checkBits(int n) - { - if (n <= 0) - return false; - if (words == null) - return n > 31 || ((ival & ((1 << n) - 1)) != 0); - int i; - for (i = 0; i < (n >> 5) ; i++) - if (words[i] != 0) - return true; - return (n & 31) != 0 && (words[i] & ((1 << (n & 31)) - 1)) != 0; - } - - /** Convert a semi-processed BigInteger to double. - * Number must be non-negative. Multiplies by a power of two, applies sign, - * and converts to double, with the usual java rounding. - * @param exp power of two, positive or negative, by which to multiply - * @param neg true if negative - * @param remainder true if the BigInteger is the result of a truncating - * division that had non-zero remainder. To ensure proper rounding in - * this case, the BigInteger must have at least 54 bits. */ - private double roundToDouble(int exp, boolean neg, boolean remainder) - { - // Compute length. - int il = bitLength(); - - // Exponent when normalized to have decimal point directly after - // leading one. This is stored excess 1023 in the exponent bit field. - exp += il - 1; - - // Gross underflow. If exp == -1075, we let the rounding - // computation determine whether it is minval or 0 (which are just - // 0x0000 0000 0000 0001 and 0x0000 0000 0000 0000 as bit - // patterns). - if (exp < -1075) - return neg ? -0.0 : 0.0; - - // gross overflow - if (exp > 1023) - return neg ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY; - - // number of bits in mantissa, including the leading one. - // 53 unless it's denormalized - int ml = (exp >= -1022 ? 53 : 53 + exp + 1022); - - // Get top ml + 1 bits. The extra one is for rounding. - long m; - int excess_bits = il - (ml + 1); - if (excess_bits > 0) - m = ((words == null) ? ival >> excess_bits - : MPN.rshift_long(words, ival, excess_bits)); - else - m = longValue() << (- excess_bits); - - // Special rounding for maxval. If the number exceeds maxval by - // any amount, even if it's less than half a step, it overflows. - if (exp == 1023 && ((m >> 1) == (1L << 53) - 1)) - { - if (remainder || checkBits(il - ml)) - return neg ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY; - else - return neg ? - Double.MAX_VALUE : Double.MAX_VALUE; - } - - // Normal round-to-even rule: round up if the bit dropped is a one, and - // the bit above it or any of the bits below it is a one. - if ((m & 1) == 1 - && ((m & 2) == 2 || remainder || checkBits(excess_bits))) - { - m += 2; - // Check if we overflowed the mantissa - if ((m & (1L << 54)) != 0) - { - exp++; - // renormalize - m >>= 1; - } - // Check if a denormalized mantissa was just rounded up to a - // normalized one. - else if (ml == 52 && (m & (1L << 53)) != 0) - exp++; - } - - // Discard the rounding bit - m >>= 1; - - long bits_sign = neg ? (1L << 63) : 0; - exp += 1023; - long bits_exp = (exp <= 0) ? 0 : ((long)exp) << 52; - long bits_mant = m & ~(1L << 52); - return Double.longBitsToDouble(bits_sign | bits_exp | bits_mant); - } - - /** Copy the abolute value of this into an array of words. - * Assumes words.length >= (this.words == null ? 1 : this.ival). - * Result is zero-extended, but need not be a valid 2's complement number. - */ - private void getAbsolute(int[] words) - { - int len; - if (this.words == null) - { - len = 1; - words[0] = this.ival; - } - else - { - len = this.ival; - for (int i = len; --i >= 0; ) - words[i] = this.words[i]; - } - if (words[len - 1] < 0) - negate(words, words, len); - for (int i = words.length; --i > len; ) - words[i] = 0; - } - - /** Set dest[0:len-1] to the negation of src[0:len-1]. - * Return true if overflow (i.e. if src is -2**(32*len-1)). - * Ok for src==dest. */ - private static boolean negate(int[] dest, int[] src, int len) - { - long carry = 1; - boolean negative = src[len-1] < 0; - for (int i = 0; i < len; i++) - { - carry += ((long) (~src[i]) & 0xffffffffL); - dest[i] = (int) carry; - carry >>= 32; - } - return (negative && dest[len-1] < 0); - } - - /** Destructively set this to the negative of x. - * It is OK if x==this.*/ - private void setNegative(BigInteger x) - { - int len = x.ival; - if (x.words == null) - { - if (len == Integer.MIN_VALUE) - set(- (long) len); - else - set(-len); - return; - } - realloc(len + 1); - if (negate(words, x.words, len)) - words[len++] = 0; - ival = len; - } - - /** Destructively negate this. */ - private void setNegative() - { - setNegative(this); - } - - private static BigInteger abs(BigInteger x) - { - return x.isNegative() ? neg(x) : x; - } - - public BigInteger abs() - { - return abs(this); - } - - private static BigInteger neg(BigInteger x) - { - if (x.words == null && x.ival != Integer.MIN_VALUE) - return valueOf(- x.ival); - BigInteger result = new BigInteger(0); - result.setNegative(x); - return result.canonicalize(); - } - - public BigInteger negate() - { - return neg(this); - } - - /** Calculates ceiling(log2(this < 0 ? -this : this+1)) - * See Common Lisp: the Language, 2nd ed, p. 361. - */ - public int bitLength() - { - if (words == null) - return MPN.intLength(ival); - return MPN.intLength(words, ival); - } - - public byte[] toByteArray() - { - // Determine number of bytes needed. The method bitlength returns - // the size without the sign bit, so add one bit for that and then - // add 7 more to emulate the ceil function using integer math. - byte[] bytes = new byte[(bitLength() + 1 + 7) / 8]; - int nbytes = bytes.length; - - int wptr = 0; - int word; - - // Deal with words array until one word or less is left to process. - // If BigInteger is an int, then it is in ival and nbytes will be <= 4. - while (nbytes > 4) - { - word = words[wptr++]; - for (int i = 4; i > 0; --i, word >>= 8) - bytes[--nbytes] = (byte) word; - } - - // Deal with the last few bytes. If BigInteger is an int, use ival. - word = (words == null) ? ival : words[wptr]; - for ( ; nbytes > 0; word >>= 8) - bytes[--nbytes] = (byte) word; - - return bytes; - } - - /** Return the boolean opcode (for bitOp) for swapped operands. - * I.e. bitOp(swappedOp(op), x, y) == bitOp(op, y, x). - */ - private static int swappedOp(int op) - { - return - "\000\001\004\005\002\003\006\007\010\011\014\015\012\013\016\017" - .charAt(op); - } - - /** Do one the the 16 possible bit-wise operations of two BigIntegers. */ - private static BigInteger bitOp(int op, BigInteger x, BigInteger y) - { - switch (op) - { - case 0: return ZERO; - case 1: return x.and(y); - case 3: return x; - case 5: return y; - case 15: return valueOf(-1); - } - BigInteger result = new BigInteger(); - setBitOp(result, op, x, y); - return result.canonicalize(); - } - - /** Do one the the 16 possible bit-wise operations of two BigIntegers. */ - private static void setBitOp(BigInteger result, int op, - BigInteger x, BigInteger y) - { - if (y.words == null) ; - else if (x.words == null || x.ival < y.ival) - { - BigInteger temp = x; x = y; y = temp; - op = swappedOp(op); - } - int xi; - int yi; - int xlen, ylen; - if (y.words == null) - { - yi = y.ival; - ylen = 1; - } - else - { - yi = y.words[0]; - ylen = y.ival; - } - if (x.words == null) - { - xi = x.ival; - xlen = 1; - } - else - { - xi = x.words[0]; - xlen = x.ival; - } - if (xlen > 1) - result.realloc(xlen); - int[] w = result.words; - int i = 0; - // Code for how to handle the remainder of x. - // 0: Truncate to length of y. - // 1: Copy rest of x. - // 2: Invert rest of x. - int finish = 0; - int ni; - switch (op) - { - case 0: // clr - ni = 0; - break; - case 1: // and - for (;;) - { - ni = xi & yi; - if (i+1 >= ylen) break; - w[i++] = ni; xi = x.words[i]; yi = y.words[i]; - } - if (yi < 0) finish = 1; - break; - case 2: // andc2 - for (;;) - { - ni = xi & ~yi; - if (i+1 >= ylen) break; - w[i++] = ni; xi = x.words[i]; yi = y.words[i]; - } - if (yi >= 0) finish = 1; - break; - case 3: // copy x - ni = xi; - finish = 1; // Copy rest - break; - case 4: // andc1 - for (;;) - { - ni = ~xi & yi; - if (i+1 >= ylen) break; - w[i++] = ni; xi = x.words[i]; yi = y.words[i]; - } - if (yi < 0) finish = 2; - break; - case 5: // copy y - for (;;) - { - ni = yi; - if (i+1 >= ylen) break; - w[i++] = ni; xi = x.words[i]; yi = y.words[i]; - } - break; - case 6: // xor - for (;;) - { - ni = xi ^ yi; - if (i+1 >= ylen) break; - w[i++] = ni; xi = x.words[i]; yi = y.words[i]; - } - finish = yi < 0 ? 2 : 1; - break; - case 7: // ior - for (;;) - { - ni = xi | yi; - if (i+1 >= ylen) break; - w[i++] = ni; xi = x.words[i]; yi = y.words[i]; - } - if (yi >= 0) finish = 1; - break; - case 8: // nor - for (;;) - { - ni = ~(xi | yi); - if (i+1 >= ylen) break; - w[i++] = ni; xi = x.words[i]; yi = y.words[i]; - } - if (yi >= 0) finish = 2; - break; - case 9: // eqv [exclusive nor] - for (;;) - { - ni = ~(xi ^ yi); - if (i+1 >= ylen) break; - w[i++] = ni; xi = x.words[i]; yi = y.words[i]; - } - finish = yi >= 0 ? 2 : 1; - break; - case 10: // c2 - for (;;) - { - ni = ~yi; - if (i+1 >= ylen) break; - w[i++] = ni; xi = x.words[i]; yi = y.words[i]; - } - break; - case 11: // orc2 - for (;;) - { - ni = xi | ~yi; - if (i+1 >= ylen) break; - w[i++] = ni; xi = x.words[i]; yi = y.words[i]; - } - if (yi < 0) finish = 1; - break; - case 12: // c1 - ni = ~xi; - finish = 2; - break; - case 13: // orc1 - for (;;) - { - ni = ~xi | yi; - if (i+1 >= ylen) break; - w[i++] = ni; xi = x.words[i]; yi = y.words[i]; - } - if (yi >= 0) finish = 2; - break; - case 14: // nand - for (;;) - { - ni = ~(xi & yi); - if (i+1 >= ylen) break; - w[i++] = ni; xi = x.words[i]; yi = y.words[i]; - } - if (yi < 0) finish = 2; - break; - default: - case 15: // set - ni = -1; - break; - } - // Here i==ylen-1; w[0]..w[i-1] have the correct result; - // and ni contains the correct result for w[i+1]. - if (i+1 == xlen) - finish = 0; - switch (finish) - { - case 0: - if (i == 0 && w == null) - { - result.ival = ni; - return; - } - w[i++] = ni; - break; - case 1: w[i] = ni; while (++i < xlen) w[i] = x.words[i]; break; - case 2: w[i] = ni; while (++i < xlen) w[i] = ~x.words[i]; break; - } - result.ival = i; - } - - /** Return the logical (bit-wise) "and" of a BigInteger and an int. */ - private static BigInteger and(BigInteger x, int y) - { - if (x.words == null) - return valueOf(x.ival & y); - if (y >= 0) - return valueOf(x.words[0] & y); - int len = x.ival; - int[] words = new int[len]; - words[0] = x.words[0] & y; - while (--len > 0) - words[len] = x.words[len]; - return make(words, x.ival); - } - - /** Return the logical (bit-wise) "and" of two BigIntegers. */ - public BigInteger and(BigInteger y) - { - if (y.words == null) - return and(this, y.ival); - else if (words == null) - return and(y, ival); - - BigInteger x = this; - if (ival < y.ival) - { - BigInteger temp = this; x = y; y = temp; - } - int i; - int len = y.isNegative() ? x.ival : y.ival; - int[] words = new int[len]; - for (i = 0; i < y.ival; i++) - words[i] = x.words[i] & y.words[i]; - for ( ; i < len; i++) - words[i] = x.words[i]; - return make(words, len); - } - - /** Return the logical (bit-wise) "(inclusive) or" of two BigIntegers. */ - public BigInteger or(BigInteger y) - { - return bitOp(7, this, y); - } - - /** Return the logical (bit-wise) "exclusive or" of two BigIntegers. */ - public BigInteger xor(BigInteger y) - { - return bitOp(6, this, y); - } - - /** Return the logical (bit-wise) negation of a BigInteger. */ - public BigInteger not() - { - return bitOp(12, this, ZERO); - } - - public BigInteger andNot(BigInteger val) - { - return and(val.not()); - } - - public BigInteger clearBit(int n) - { - if (n < 0) - throw new ArithmeticException(); - - return and(ONE.shiftLeft(n).not()); - } - - public BigInteger setBit(int n) - { - if (n < 0) - throw new ArithmeticException(); - - return or(ONE.shiftLeft(n)); - } - - public boolean testBit(int n) - { - if (n < 0) - throw new ArithmeticException(); - - return !and(ONE.shiftLeft(n)).isZero(); - } - - public BigInteger flipBit(int n) - { - if (n < 0) - throw new ArithmeticException(); - - return xor(ONE.shiftLeft(n)); - } - - public int getLowestSetBit() - { - if (isZero()) - return -1; - - if (words == null) - return MPN.findLowestBit(ival); - else - return MPN.findLowestBit(words); - } - - // bit4count[I] is number of '1' bits in I. - private static final byte[] bit4_count = { 0, 1, 1, 2, 1, 2, 2, 3, - 1, 2, 2, 3, 2, 3, 3, 4}; - - private static int bitCount(int i) - { - int count = 0; - while (i != 0) - { - count += bit4_count[i & 15]; - i >>>= 4; - } - return count; - } - - private static int bitCount(int[] x, int len) - { - int count = 0; - while (--len >= 0) - count += bitCount(x[len]); - return count; - } - - /** Count one bits in a BigInteger. - * If argument is negative, count zero bits instead. */ - public int bitCount() - { - int i, x_len; - int[] x_words = words; - if (x_words == null) - { - x_len = 1; - i = bitCount(ival); - } - else - { - x_len = ival; - i = bitCount(x_words, x_len); - } - return isNegative() ? x_len * 32 - i : i; - } - - private void readObject(ObjectInputStream s) - throws IOException, ClassNotFoundException - { - s.defaultReadObject(); - words = byteArrayToIntArray(magnitude, signum < 0 ? -1 : 0); - BigInteger result = make(words, words.length); - this.ival = result.ival; - this.words = result.words; - } - - private void writeObject(ObjectOutputStream s) - throws IOException, ClassNotFoundException - { - signum = signum(); - magnitude = toByteArray(); - s.defaultWriteObject(); - } -} diff --git a/libjava/java/net/Authenticator.java b/libjava/java/net/Authenticator.java deleted file mode 100644 index 229e140cc76..00000000000 --- a/libjava/java/net/Authenticator.java +++ /dev/null @@ -1,313 +0,0 @@ -/* Authenticator.java -- Abstract class for obtaining authentication info - Copyright (C) 1998, 2000, 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.net; - - -/** - * This abstract class provides a model for obtaining authentication - * information (in the form of a username and password) required by - * some network operations (such as hitting a password protected - * web site). - * <p> - * To make use of this feature, a programmer must create a subclass - * that knows how to obtain the necessary info. An example - * would be a class that popped up a dialog box to prompt the user. - * After creating an instance of that subclass, the static - * <code>setDefault</code> method of this class is called to set up - * that instance as the object to use on subsequent calls to obtain - * authorization. - * - * @since 1.2 - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @status Believed to be JDK 1.4 complete - */ -public abstract class Authenticator -{ - /* - * Class Variables - */ - - /** - * This is the default Authenticator object to use for password requests - */ - private static Authenticator defaultAuthenticator; - - /* - * Instance Variables - */ - - /** - * The hostname of the site requesting authentication - */ - private String host; - - /** - * InternetAddress of the site requesting authentication - */ - private InetAddress addr; - - /** - * The port number of the site requesting authentication - */ - private int port; - - /** - * The protocol name of the site requesting authentication - */ - private String protocol; - - /** - * The prompt to display to the user when requesting authentication info - */ - private String prompt; - - /** - * The authentication scheme in use - */ - private String scheme; - - /* - * Class Methods - */ - - /** - * This method sets the default <code>Authenticator</code> object (an - * instance of a subclass of <code>Authenticator</code>) to use when - * prompting the user for - * information. Note that this method checks to see if the caller is - * allowed to set this value (the "setDefaultAuthenticator" permission) - * and throws a <code>SecurityException</code> if it is not. - * - * @param defAuth The new default <code>Authenticator</code> object to use - * - * @exception SecurityException If the caller does not have permission - * to perform this operation - */ - public static void setDefault(Authenticator defAuth) - { - SecurityManager sm = System.getSecurityManager(); - if (sm != null) - sm.checkPermission(new NetPermission("setDefaultAuthenticator")); - - defaultAuthenticator = defAuth; - } - - /** - * This method is called whenever a username and password for a given - * network operation is required. First, a security check is made to see - * if the caller has the "requestPasswordAuthentication" - * permission. If not, the method thows an exception. If there is no - * default <code>Authenticator</code> object, the method then returns - * <code>null</code>. Otherwise, the default authenticators's instance - * variables are initialized and it's <code>getPasswordAuthentication</code> - * method is called to get the actual authentication information to return. - * - * @param addr The address requesting authentication - * @param port The port requesting authentication - * @param protocol The protocol requesting authentication - * @param prompt The prompt to display to the user when requesting - * authentication info - * @param scheme The authentication scheme in use - * - * @return A <code>PasswordAuthentication</code> object with the user's - * authentication info. - * - * @exception SecurityException If the caller does not have permission to - * perform this operation - */ - public static PasswordAuthentication requestPasswordAuthentication(InetAddress addr, - int port, - String protocol, - String prompt, - String scheme) - throws SecurityException - { - return requestPasswordAuthentication(null, addr, port, protocol, prompt, - scheme); - } - - /** - * This method is called whenever a username and password for a given - * network operation is required. First, a security check is made to see - * if the caller has the "requestPasswordAuthentication" - * permission. If not, the method thows an exception. If there is no - * default <code>Authenticator</code> object, the method then returns - * <code>null</code>. Otherwise, the default authenticators's instance - * variables are initialized and it's <code>getPasswordAuthentication</code> - * method is called to get the actual authentication information to return. - * This method is the preferred one as it can be used with hostname - * when addr is unknown. - * - * @param host The hostname requesting authentication - * @param addr The address requesting authentication - * @param port The port requesting authentication - * @param protocol The protocol requesting authentication - * @param prompt The prompt to display to the user when requesting - * authentication info - * @param scheme The authentication scheme in use - * - * @return A <code>PasswordAuthentication</code> object with the user's - * authentication info. - * - * @exception SecurityException If the caller does not have permission to - * perform this operation - * - * @since 1.4 - */ - public static PasswordAuthentication requestPasswordAuthentication(String host, - InetAddress addr, - int port, - String protocol, - String prompt, - String scheme) - throws SecurityException - { - SecurityManager sm = System.getSecurityManager(); - if (sm != null) - sm.checkPermission(new NetPermission("requestPasswordAuthentication")); - - if (defaultAuthenticator == null) - return null; - - defaultAuthenticator.host = host; - defaultAuthenticator.addr = addr; - defaultAuthenticator.port = port; - defaultAuthenticator.protocol = protocol; - defaultAuthenticator.prompt = prompt; - defaultAuthenticator.scheme = scheme; - - return defaultAuthenticator.getPasswordAuthentication(); - } - - /* - * Constructors - */ - - /** - * Default, no-argument constructor for subclasses to call. - */ - public Authenticator() - { - } - - /* - * Instance Methods - */ - - /** - * This method returns the address of the site that is requesting - * authentication. - * - * @return The requesting site's address - */ - protected final InetAddress getRequestingSite() - { - return addr; - } - - /** - * Returns the hostname of the host or proxy requesting authorization, - * or <code>null</code> if not available. - * - * @return The name of the host requesting authentication, or - * <code>null</code> if it is not available. - * - * @since 1.4 - */ - protected final String getRequestingHost() - { - return host; - } - - /** - * This method returns the port of the site that is requesting - * authentication. - * - * @return The requesting port - */ - protected final int getRequestingPort() - { - return port; - } - - /** - * This method returns the requesting protocol of the operation that is - * requesting authentication - * - * @return The requesting protocol - */ - protected final String getRequestingProtocol() - { - return protocol; - } - - /** - * Returns the prompt that should be used when requesting authentication - * information from the user - * - * @return The user prompt - */ - protected final String getRequestingPrompt() - { - return prompt; - } - - /** - * This method returns the authentication scheme in use - * - * @return The authentication scheme - */ - protected final String getRequestingScheme() - { - return scheme; - } - - /** - * This method is called whenever a request for authentication is made. It - * can call the other getXXX methods to determine the information relevant - * to this request. Subclasses should override this method, which returns - * <code>null</code> by default. - * - * @return The <code>PasswordAuthentication</code> information - */ - protected PasswordAuthentication getPasswordAuthentication() - { - return null; - } -} // class Authenticator diff --git a/libjava/java/net/BindException.java b/libjava/java/net/BindException.java deleted file mode 100644 index cfb509a708e..00000000000 --- a/libjava/java/net/BindException.java +++ /dev/null @@ -1,74 +0,0 @@ -/* BindException.java -- An exception occurred while binding to a socket - Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.net; - - -/** - * This exception indicates that an error occurred while attempting to bind - * socket to a particular port. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Warren Levy (warrenl@cygnus.com) - * @since 1.1 - * @status updated to 1.4 - */ -public class BindException extends SocketException -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = -5945005768251722951L; - - /** - * Create a new instance without a descriptive error message. - */ - public BindException() - { - } - - /** - * Create a new instance with a descriptive error message, such as the - * text from strerror(3). - * - * @param message a message describing the error that occurred - */ - public BindException(String message) - { - super(message); - } -} // class BindException diff --git a/libjava/java/net/ConnectException.java b/libjava/java/net/ConnectException.java deleted file mode 100644 index c115d2fe04e..00000000000 --- a/libjava/java/net/ConnectException.java +++ /dev/null @@ -1,75 +0,0 @@ -/* ConnectException.java -- An exception occurred while connecting to a host - Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.net; - - -/** - * This exception indicates that an error occurred while attempting to - * connect to a remote host. Often this indicates that the remote host - * refused the connection (ie, is not listening on the target socket). - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Warren Levy (warrenl@cygnus.com) - * @since 1.1 - * @status updated to 1.4 - */ -public class ConnectException extends SocketException -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = 3831404271622369215L; - - /** - * Create a new instance without a descriptive error message. - */ - public ConnectException() - { - } - - /** - * Create a new instance with a descriptive error message, such as the - * text from strerror(3). - * - * @param message a message describing the error that occurred - */ - public ConnectException(String message) - { - super(message); - } -} // class ConnectException diff --git a/libjava/java/net/ContentHandler.java b/libjava/java/net/ContentHandler.java deleted file mode 100644 index 7f63e740229..00000000000 --- a/libjava/java/net/ContentHandler.java +++ /dev/null @@ -1,126 +0,0 @@ -/* ContentHandler.java -- Abstract class for handling content from URL's - Copyright (C) 1998, 1999, 2000, 2001, 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.net; - -import java.io.IOException; - -/** - * Written using on-line Java Platform 1.2 API Specification, as well - * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998). - * Status: Believed complete and correct. - */ - -/** - * This is an abstract class that is the superclass for classes that read - * objects from URL's. Calling the <code>getContent()</code> method in the - * <code>URL</code> class or the <code>URLConnection</code> class will cause - * an instance of a subclass of <code>ContentHandler</code> to be created for - * the MIME type of the object being downloaded from the URL. Thus, this - * class is seldom needed by applications/applets directly, but only - * indirectly through methods in other classes. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Warren Levy (warrenl@cygnus.com) - */ -public abstract class ContentHandler -{ - /* - * Constructors - */ - - /** - * Default, no-argument constructor. - */ - public ContentHandler() - { - } - - /* - * Instance Methods - */ - - /** - * This method reads from the <code>InputStream</code> of the passed in URL - * connection and uses the data downloaded to create an <code>Object</code> - * represening the content. For example, if the URL is pointing to a GIF - * file, this method might return an <code>Image</code> object. This method - * must be implemented by subclasses. - * - * @param urlc A <code>URLConnection</code> object to read data from. - * - * @return An object representing the data read - * - * @exception IOException If an error occurs - */ - public abstract Object getContent(URLConnection urlc) - throws IOException; - - /** - * This method reads from the <code>InputStream</code> of the passed in URL - * connection and uses the data downloaded to create an <code>Object</code> - * represening the content. For example, if the URL is pointing to a GIF - * file, this method might return an <code>Image</code> object. This method - * must be implemented by subclasses. This method uses the list of - * supplied classes as candidate types. If the data read doesn't match - * any of the supplied type, <code>null</code> is returned. - * - * @param urlc A <code>URLConnection</code> object to read data from. - * @param classes An array of types of objects that are candidate types - * for the data to be read. - * - * @return An object representing the data read, or <code>null</code> - * if the data does not match any of the candidate types. - * - * @exception IOException If an error occurs - * - * @since 1.3 - */ - public Object getContent(URLConnection urlc, Class[] classes) - throws IOException - { - Object obj = getContent(urlc); - - for (int i = 0; i < classes.length; i++) - { - if (classes[i].isInstance(obj)) - return obj; - } - - return null; - } -} // class ContentHandler diff --git a/libjava/java/net/ContentHandlerFactory.java b/libjava/java/net/ContentHandlerFactory.java deleted file mode 100644 index 51a92cf1521..00000000000 --- a/libjava/java/net/ContentHandlerFactory.java +++ /dev/null @@ -1,65 +0,0 @@ -/* ContentHandlerFactory.java -- Interface for creating content handlers - Copyright (C) 1998, 1999, 2000, 2001, 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.net; - - -/** - * Written using on-line Java Platform 1.2 API Specification, as well - * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998). - * Status: Believed complete and correct. - */ -/** - * This interface maps MIME types to <code>ContentHandler</code> objects. - * It consists of one method that, when passed a MIME type, returns a - * handler for that type. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Warren Levy (warrenl@cygnus.com) - */ -public interface ContentHandlerFactory -{ - /** - * This method is passed a MIME type as a string and is responsible for - * returning the appropriate <code>ContentHandler</code> object. - * - * @param mimeType The MIME type to map to a <code>ContentHandler</code> - * - * @return The <code>ContentHandler</code> for the passed in MIME type - */ - ContentHandler createContentHandler(String mimeType); -} // interface ContentHandlerFactory diff --git a/libjava/java/net/DatagramPacket.java b/libjava/java/net/DatagramPacket.java deleted file mode 100644 index e642f889c32..00000000000 --- a/libjava/java/net/DatagramPacket.java +++ /dev/null @@ -1,391 +0,0 @@ -/* DatagramPacket.java -- Class to model a packet to be sent via UDP - Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.net; - - -/* - * Written using on-line Java Platform 1.2 API Specification, as well - * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998). - * Status: Believed complete and correct. - */ - -/** - * This class models a packet of data that is to be sent across the network - * using a connectionless protocol such as UDP. It contains the data - * to be send, as well as the destination address and port. Note that - * datagram packets can arrive in any order and are not guaranteed to be - * delivered at all. - * <p> - * This class can also be used for receiving data from the network. - * <p> - * Note that for all method below where the buffer length passed by the - * caller cannot exceed the actually length of the byte array passed as - * the buffer, if this condition is not true, then the method silently - * reduces the length value to maximum allowable value. - * - * Written using on-line Java Platform 1.2 API Specification, as well - * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998). - * Status: Believed complete and correct. - * - * @author Warren Levy (warrenl@cygnus.com) - * @author Aarom M. Renn (arenn@urbanophile.com) (Documentation comments) - * @date April 28, 1999. - */ -public final class DatagramPacket -{ - /** - * The data buffer to send - */ - private byte[] buffer; - - /** - * This is the offset into the buffer to start sending from or receiving to. - */ - private int offset; - - /** - * The length of the data buffer to send. - */ - int length; - - /** - * The maximal length of the buffer. - */ - int maxlen; - - /** - * The address to which the packet should be sent or from which it - * was received. - */ - private InetAddress address; - - /** - * The port to which the packet should be sent or from which it was - * was received. - */ - private int port; - - /** - * This method initializes a new instance of <code>DatagramPacket</code> - * which has the specified buffer, offset, and length. - * - * @param buf The buffer for holding the incoming datagram. - * @param offset The offset into the buffer to start writing. - * @param length The maximum number of bytes to read. - * - * @since 1.2 - */ - public DatagramPacket(byte[] buf, int offset, int length) - { - setData(buf, offset, length); - address = null; - port = -1; - } - - /** - * Initializes a new instance of <code>DatagramPacket</code> for - * receiving packets from the network. - * - * @param buf A buffer for storing the returned packet data - * @param length The length of the buffer (must be <= buf.length) - */ - public DatagramPacket(byte[] buf, int length) - { - this(buf, 0, length); - } - - /** - * Initializes a new instance of <code>DatagramPacket</code> for - * transmitting packets across the network. - * - * @param buf A buffer containing the data to send - * @param offset The offset into the buffer to start writing from. - * @param length The length of the buffer (must be <= buf.length) - * @param address The address to send to - * @param port The port to send to - * - * @since 1.2 - */ - public DatagramPacket(byte[] buf, int offset, int length, - InetAddress address, int port) - { - setData(buf, offset, length); - setAddress(address); - setPort(port); - } - - /** - * Initializes a new instance of <code>DatagramPacket</code> for - * transmitting packets across the network. - * - * @param buf A buffer containing the data to send - * @param length The length of the buffer (must be <= buf.length) - * @param address The address to send to - * @param port The port to send to - */ - public DatagramPacket(byte[] buf, int length, InetAddress address, int port) - { - this(buf, 0, length, address, port); - } - - /** - * Initializes a new instance of <code>DatagramPacket</code> for - * transmitting packets across the network. - * - * @param buf A buffer containing the data to send - * @param offset The offset into the buffer to start writing from. - * @param length The length of the buffer (must be <= buf.length) - * @param address The socket address to send to - * - * @exception SocketException If an error occurs - * @exception IllegalArgumentException If address type is not supported - * - * @since 1.4 - */ - public DatagramPacket(byte[] buf, int offset, int length, - SocketAddress address) throws SocketException - { - if (! (address instanceof InetSocketAddress)) - throw new IllegalArgumentException("unsupported address type"); - - InetSocketAddress tmp = (InetSocketAddress) address; - setData(buf, offset, length); - setAddress(tmp.getAddress()); - setPort(tmp.getPort()); - } - - /** - * Initializes a new instance of <code>DatagramPacket</code> for - * transmitting packets across the network. - * - * @param buf A buffer containing the data to send - * @param length The length of the buffer (must be <= buf.length) - * @param address The socket address to send to - * - * @exception SocketException If an error occurs - * @exception IllegalArgumentException If address type is not supported - * - * @since 1.4 - */ - public DatagramPacket(byte[] buf, int length, SocketAddress address) - throws SocketException - { - this(buf, 0, length, address); - } - - /** - * Returns the address that this packet is being sent to or, if it was used - * to receive a packet, the address that is was received from. If the - * constructor that doesn not take an address was used to create this object - * and no packet was actually read into this object, then this method - * returns <code>null</code>. - * - * @return The address for this packet. - */ - public synchronized InetAddress getAddress() - { - return address; - } - - /** - * Returns the port number this packet is being sent to or, if it was used - * to receive a packet, the port that it was received from. If the - * constructor that doesn not take an address was used to create this object - * and no packet was actually read into this object, then this method - * will return 0. - * - * @return The port number for this packet - */ - public synchronized int getPort() - { - return port; - } - - /** - * Returns the data buffer for this packet - * - * @return This packet's data buffer - */ - public synchronized byte[] getData() - { - return buffer; - } - - /** - * This method returns the current offset value into the data buffer - * where data will be sent from. - * - * @return The buffer offset. - * - * @since 1.2 - */ - public synchronized int getOffset() - { - return offset; - } - - /** - * Returns the length of the data in the buffer - * - * @return The length of the data - */ - public synchronized int getLength() - { - return length; - } - - /** - * This sets the address to which the data packet will be transmitted. - * - * @param address The destination address - * - * @since 1.1 - */ - public synchronized void setAddress(InetAddress address) - { - this.address = address; - } - - /** - * This sets the port to which the data packet will be transmitted. - * - * @param port The destination port - * - * @since 1.1 - */ - public synchronized void setPort(int port) - { - if (port < 0 || port > 65535) - throw new IllegalArgumentException("Invalid port: " + port); - - this.port = port; - } - - /** - * Sets the address of the remote host this package will be sent - * - * @param address The socket address of the remove host - * - * @exception IllegalArgumentException If address type is not supported - * - * @since 1.4 - */ - public void setSocketAddress(SocketAddress address) - throws IllegalArgumentException - { - if (address == null) - throw new IllegalArgumentException("address may not be null"); - - InetSocketAddress tmp = (InetSocketAddress) address; - this.address = tmp.getAddress(); - this.port = tmp.getPort(); - } - - /** - * Gets the socket address of the host this packet - * will be sent to/is coming from - * - * @return The socket address of the remote host - * - * @since 1.4 - */ - public SocketAddress getSocketAddress() - { - return new InetSocketAddress(address, port); - } - - /** - * Sets the data buffer for this packet. - * - * @param buf The new buffer for this packet - * - * @exception NullPointerException If the argument is null - * - * @since 1.1 - */ - public void setData(byte[] buf) - { - setData(buf, 0, buf.length); - } - - /** - * This method sets the data buffer for the packet. - * - * @param buf The byte array containing the data for this packet. - * @param offset The offset into the buffer to start reading data from. - * @param length The number of bytes of data in the buffer. - * - * @exception NullPointerException If the argument is null - * - * @since 1.2 - */ - public synchronized void setData(byte[] buf, int offset, int length) - { - // This form of setData must be used if offset is to be changed. - if (buf == null) - throw new NullPointerException("Null buffer"); - if (offset < 0) - throw new IllegalArgumentException("Invalid offset: " + offset); - - buffer = buf; - this.offset = offset; - setLength(length); - } - - /** - * Sets the length of the data in the buffer. - * - * @param length The new length. (Where len <= buf.length) - * - * @exception IllegalArgumentException If the length is negative or - * if the length is greater than the packet's data buffer length - * - * @since 1.1 - */ - public synchronized void setLength(int length) - { - if (length < 0) - throw new IllegalArgumentException("Invalid length: " + length); - if (offset + length > buffer.length) - throw new IllegalArgumentException("Potential buffer overflow - offset: " - + offset + " length: " + length); - - this.length = length; - this.maxlen = length; - } -} diff --git a/libjava/java/net/DatagramSocket.java b/libjava/java/net/DatagramSocket.java deleted file mode 100644 index d675cb1df00..00000000000 --- a/libjava/java/net/DatagramSocket.java +++ /dev/null @@ -1,931 +0,0 @@ -/* DatagramSocket.java -- A class to model UDP sockets - Copyright (C) 1998, 1999, 2000, 2002, 2003, 2004 - Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.net; - -import gnu.java.net.PlainDatagramSocketImpl; -import gnu.java.nio.DatagramChannelImpl; - -import java.io.IOException; -import java.nio.channels.DatagramChannel; -import java.nio.channels.IllegalBlockingModeException; - - -/** - * Written using on-line Java Platform 1.2 API Specification, as well - * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998). - * Status: Believed complete and correct. - */ -/** - * This class models a connectionless datagram socket that sends - * individual packets of data across the network. In the TCP/IP world, - * this means UDP. Datagram packets do not have guaranteed delivery, - * or any guarantee about the order the data will be received on the - * remote host. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Warren Levy (warrenl@cygnus.com) - * @date May 3, 1999. - */ -public class DatagramSocket -{ - /** - * This is the user DatagramSocketImplFactory for this class. If this - * variable is null, a default factory is used. - */ - private static DatagramSocketImplFactory factory; - - /** - * This is the implementation object used by this socket. - */ - private DatagramSocketImpl impl; - - /** - * True if socket implementation was created. - */ - private boolean implCreated; - - /** - * This is the address we are "connected" to - */ - private InetAddress remoteAddress; - - /** - * This is the port we are "connected" to - */ - private int remotePort = -1; - - /** - * True if socket is bound. - */ - private boolean bound; - - /** - * Creates a <code>DatagramSocket</code> from a specified - * <code>DatagramSocketImpl</code> instance - * - * @param impl The <code>DatagramSocketImpl</code> the socket will be - * created from - * - * @since 1.4 - */ - protected DatagramSocket(DatagramSocketImpl impl) - { - if (impl == null) - throw new NullPointerException("impl may not be null"); - - this.impl = impl; - this.remoteAddress = null; - this.remotePort = -1; - } - - /** - * Initializes a new instance of <code>DatagramSocket</code> that binds to - * a random port and every address on the local machine. - * - * @exception SocketException If an error occurs. - * @exception SecurityException If a security manager exists and - * its <code>checkListen</code> method doesn't allow the operation. - */ - public DatagramSocket() throws SocketException - { - this(new InetSocketAddress(0)); - } - - /** - * Initializes a new instance of <code>DatagramSocket</code> that binds to - * the specified port and every address on the local machine. - * - * @param port The local port number to bind to. - * - * @exception SecurityException If a security manager exists and its - * <code>checkListen</code> method doesn't allow the operation. - * @exception SocketException If an error occurs. - */ - public DatagramSocket(int port) throws SocketException - { - this(new InetSocketAddress(port)); - } - - /** - * Initializes a new instance of <code>DatagramSocket</code> that binds to - * the specified local port and address. - * - * @param port The local port number to bind to. - * @param addr The local address to bind to. - * - * @exception SecurityException If a security manager exists and its - * checkListen method doesn't allow the operation. - * @exception SocketException If an error occurs. - */ - public DatagramSocket(int port, InetAddress addr) throws SocketException - { - this(new InetSocketAddress(addr, port)); - } - - /** - * Initializes a new instance of <code>DatagramSocket</code> that binds to - * the specified local port and address. - * - * @param address The local address and port number to bind to. - * - * @exception SecurityException If a security manager exists and its - * <code>checkListen</code> method doesn't allow the operation. - * @exception SocketException If an error occurs. - * - * @since 1.4 - */ - public DatagramSocket(SocketAddress address) throws SocketException - { - String propVal = System.getProperty("impl.prefix"); - if (propVal == null || propVal.equals("")) - impl = new PlainDatagramSocketImpl(); - else - try - { - impl = - (DatagramSocketImpl) Class.forName("java.net." + propVal - + "DatagramSocketImpl") - .newInstance(); - } - catch (Exception e) - { - System.err.println("Could not instantiate class: java.net." - + propVal + "DatagramSocketImpl"); - impl = new PlainDatagramSocketImpl(); - } - - if (address != null) - bind(address); - } - - // This needs to be accessible from java.net.MulticastSocket - DatagramSocketImpl getImpl() throws SocketException - { - try - { - if (! implCreated) - { - impl.create(); - implCreated = true; - } - - return impl; - } - catch (IOException e) - { - throw new SocketException(e.getMessage()); - } - } - - /** - * Closes this datagram socket. - */ - public void close() - { - if (isClosed()) - return; - - try - { - getImpl().close(); - } - catch (SocketException e) - { - // Ignore this case, just close the socket in finally clause. - } - finally - { - remoteAddress = null; - remotePort = -1; - impl = null; - } - - try - { - if (getChannel() != null) - getChannel().close(); - } - catch (IOException e) - { - // Do nothing. - } - } - - /** - * This method returns the remote address to which this socket is - * connected. If this socket is not connected, then this method will - * return <code>null</code>. - * - * @return The remote address. - * - * @since 1.2 - */ - public InetAddress getInetAddress() - { - return remoteAddress; - } - - /** - * This method returns the remote port to which this socket is - * connected. If this socket is not connected, then this method will - * return -1. - * - * @return The remote port. - * - * @since 1.2 - */ - public int getPort() - { - return remotePort; - } - - /** - * Returns the local address this datagram socket is bound to. - * - * @return The local address is the socket is bound or null - * - * @since 1.1 - */ - public InetAddress getLocalAddress() - { - if (! isBound()) - return null; - - InetAddress localAddr; - - try - { - localAddr = - (InetAddress) getImpl().getOption(SocketOptions.SO_BINDADDR); - - SecurityManager s = System.getSecurityManager(); - if (s != null) - s.checkConnect(localAddr.getHostName(), -1); - } - catch (SecurityException e) - { - localAddr = InetAddress.ANY_IF; - } - catch (SocketException e) - { - // This cannot happen as we are bound. - return null; - } - - return localAddr; - } - - /** - * Returns the local port this socket is bound to. - * - * @return The local port number. - */ - public int getLocalPort() - { - if (isClosed()) - return -1; - - try - { - return getImpl().getLocalPort(); - } - catch (SocketException e) - { - // This cannot happen as we are bound. - return 0; - } - } - - /** - * Returns the value of the socket's SO_TIMEOUT setting. If this method - * returns 0 then SO_TIMEOUT is disabled. - * - * @return The current timeout in milliseconds. - * - * @exception SocketException If an error occurs. - * - * @since 1.1 - */ - public synchronized int getSoTimeout() throws SocketException - { - if (isClosed()) - throw new SocketException("socket is closed"); - - Object buf = getImpl().getOption(SocketOptions.SO_TIMEOUT); - - if (buf instanceof Integer) - return ((Integer) buf).intValue(); - - throw new SocketException("unexpected type"); - } - - /** - * Sets the value of the socket's SO_TIMEOUT value. A value of 0 will - * disable SO_TIMEOUT. Any other value is the number of milliseconds - * a socket read/write will block before timing out. - * - * @param timeout The new SO_TIMEOUT value in milliseconds. - * - * @exception SocketException If an error occurs. - * - * @since 1.1 - */ - public synchronized void setSoTimeout(int timeout) throws SocketException - { - if (isClosed()) - throw new SocketException("socket is closed"); - - if (timeout < 0) - throw new IllegalArgumentException("Invalid timeout: " + timeout); - - getImpl().setOption(SocketOptions.SO_TIMEOUT, new Integer(timeout)); - } - - /** - * This method returns the value of the system level socket option - * SO_SNDBUF, which is used by the operating system to tune buffer - * sizes for data transfers. - * - * @return The send buffer size. - * - * @exception SocketException If an error occurs. - * - * @since 1.2 - */ - public int getSendBufferSize() throws SocketException - { - if (isClosed()) - throw new SocketException("socket is closed"); - - Object buf = getImpl().getOption(SocketOptions.SO_SNDBUF); - - if (buf instanceof Integer) - return ((Integer) buf).intValue(); - - throw new SocketException("unexpected type"); - } - - /** - * This method sets the value for the system level socket option - * SO_SNDBUF to the specified value. Note that valid values for this - * option are specific to a given operating system. - * - * @param size The new send buffer size. - * - * @exception SocketException If an error occurs. - * @exception IllegalArgumentException If size is 0 or negative. - * - * @since 1.2 - */ - public void setSendBufferSize(int size) throws SocketException - { - if (isClosed()) - throw new SocketException("socket is closed"); - - if (size < 0) - throw new IllegalArgumentException("Buffer size is less than 0"); - - getImpl().setOption(SocketOptions.SO_SNDBUF, new Integer(size)); - } - - /** - * This method returns the value of the system level socket option - * SO_RCVBUF, which is used by the operating system to tune buffer - * sizes for data transfers. - * - * @return The receive buffer size. - * - * @exception SocketException If an error occurs. - * - * @since 1.2 - */ - public int getReceiveBufferSize() throws SocketException - { - if (isClosed()) - throw new SocketException("socket is closed"); - - Object buf = getImpl().getOption(SocketOptions.SO_RCVBUF); - - if (buf instanceof Integer) - return ((Integer) buf).intValue(); - - throw new SocketException("unexpected type"); - } - - /** - * This method sets the value for the system level socket option - * SO_RCVBUF to the specified value. Note that valid values for this - * option are specific to a given operating system. - * - * @param size The new receive buffer size. - * - * @exception SocketException If an error occurs. - * @exception IllegalArgumentException If size is 0 or negative. - * - * @since 1.2 - */ - public void setReceiveBufferSize(int size) throws SocketException - { - if (isClosed()) - throw new SocketException("socket is closed"); - - if (size < 0) - throw new IllegalArgumentException("Buffer size is less than 0"); - - getImpl().setOption(SocketOptions.SO_RCVBUF, new Integer(size)); - } - - /** - * This method connects this socket to the specified address and port. - * When a datagram socket is connected, it will only send or receive - * packets to and from the host to which it is connected. A multicast - * socket that is connected may only send and not receive packets. - * - * @param address The address to connect this socket to. - * @param port The port to connect this socket to. - * - * @exception SocketException If an error occurs. - * @exception IllegalArgumentException If address or port are invalid. - * @exception SecurityException If the caller is not allowed to send - * datagrams to or receive from this address and port. - * - * @since 1.2 - */ - public void connect(InetAddress address, int port) - { - if (address == null) - throw new IllegalArgumentException("Connect address may not be null"); - - if ((port < 1) || (port > 65535)) - throw new IllegalArgumentException("Port number is illegal: " + port); - - SecurityManager sm = System.getSecurityManager(); - if (sm != null) - sm.checkConnect(address.getHostName(), port); - - try - { - getImpl().connect(address, port); - remoteAddress = address; - remotePort = port; - } - catch (SocketException e) - { - // This means simply not connected or connect not implemented. - } - } - - /** - * This method disconnects this socket from the address/port it was - * connected to. If the socket was not connected in the first place, - * this method does nothing. - * - * @since 1.2 - */ - public void disconnect() - { - if (! isConnected()) - return; - - try - { - getImpl().disconnect(); - } - catch (SocketException e) - { - // This cannot happen as we are connected. - } - finally - { - remoteAddress = null; - remotePort = -1; - } - } - - /** - * Reads a datagram packet from the socket. Note that this method - * will block until a packet is received from the network. On return, - * the passed in <code>DatagramPacket</code> is populated with the data - * received and all the other information about the packet. - * - * @param p A <code>DatagramPacket</code> for storing the data - * - * @exception IOException If an error occurs. - * @exception SocketTimeoutException If setSoTimeout was previously called - * and the timeout has expired. - * @exception PortUnreachableException If the socket is connected to a - * currently unreachable destination. Note, there is no guarantee that the - * exception will be thrown. - * @exception IllegalBlockingModeException If this socket has an associated - * channel, and the channel is in non-blocking mode. - * @exception SecurityException If a security manager exists and its - * checkAccept method doesn't allow the receive. - */ - public synchronized void receive(DatagramPacket p) throws IOException - { - if (isClosed()) - throw new SocketException("socket is closed"); - - if (remoteAddress != null && remoteAddress.isMulticastAddress()) - throw new IOException - ("Socket connected to a multicast address my not receive"); - - if (getChannel() != null && ! getChannel().isBlocking() - && ! ((DatagramChannelImpl) getChannel()).isInChannelOperation()) - throw new IllegalBlockingModeException(); - - getImpl().receive(p); - - SecurityManager s = System.getSecurityManager(); - if (s != null && isConnected()) - s.checkAccept(p.getAddress().getHostName(), p.getPort()); - } - - /** - * Sends the specified packet. The host and port to which the packet - * are to be sent should be set inside the packet. - * - * @param p The datagram packet to send. - * - * @exception IOException If an error occurs. - * @exception SecurityException If a security manager exists and its - * checkMulticast or checkConnect method doesn't allow the send. - * @exception PortUnreachableException If the socket is connected to a - * currently unreachable destination. Note, there is no guarantee that the - * exception will be thrown. - * @exception IllegalBlockingModeException If this socket has an associated - * channel, and the channel is in non-blocking mode. - */ - public void send(DatagramPacket p) throws IOException - { - if (isClosed()) - throw new SocketException("socket is closed"); - - // JDK1.2: Don't do security checks if socket is connected; see jdk1.2 api. - SecurityManager s = System.getSecurityManager(); - if (s != null && ! isConnected()) - { - InetAddress addr = p.getAddress(); - if (addr.isMulticastAddress()) - s.checkMulticast(addr); - else - s.checkConnect(addr.getHostAddress(), p.getPort()); - } - - if (isConnected()) - { - if (p.getAddress() != null - && (remoteAddress != p.getAddress() || remotePort != p.getPort())) - throw new IllegalArgumentException - ("DatagramPacket address does not match remote address"); - } - - // FIXME: if this is a subclass of MulticastSocket, - // use getTimeToLive for TTL val. - if (getChannel() != null && ! getChannel().isBlocking() - && ! ((DatagramChannelImpl) getChannel()).isInChannelOperation()) - throw new IllegalBlockingModeException(); - - getImpl().send(p); - } - - /** - * Binds the socket to the given socket address. - * - * @param address The socket address to bind to. - * - * @exception SocketException If an error occurs. - * @exception SecurityException If a security manager exists and - * its checkListen method doesn't allow the operation. - * @exception IllegalArgumentException If address type is not supported. - * - * @since 1.4 - */ - public void bind(SocketAddress address) throws SocketException - { - if (isClosed()) - throw new SocketException("socket is closed"); - - if (! (address instanceof InetSocketAddress)) - throw new IllegalArgumentException("unsupported address type"); - - InetAddress addr = ((InetSocketAddress) address).getAddress(); - int port = ((InetSocketAddress) address).getPort(); - - if (port < 0 || port > 65535) - throw new IllegalArgumentException("Invalid port: " + port); - - SecurityManager s = System.getSecurityManager(); - if (s != null) - s.checkListen(port); - - if (addr == null) - addr = InetAddress.ANY_IF; - - try - { - getImpl().bind(port, addr); - bound = true; - } - catch (SocketException exception) - { - getImpl().close(); - throw exception; - } - catch (RuntimeException exception) - { - getImpl().close(); - throw exception; - } - catch (Error error) - { - getImpl().close(); - throw error; - } - } - - /** - * Checks if the datagram socket is closed. - * - * @return True if socket is closed, false otherwise. - * - * @since 1.4 - */ - public boolean isClosed() - { - return impl == null; - } - - /** - * Returns the datagram channel assoziated with this datagram socket. - * - * @return The associated <code>DatagramChannel</code> object or null - * - * @since 1.4 - */ - public DatagramChannel getChannel() - { - return null; - } - - /** - * Connects the datagram socket to a specified socket address. - * - * @param address The socket address to connect to. - * - * @exception SocketException If an error occurs. - * @exception IllegalArgumentException If address type is not supported. - * - * @since 1.4 - */ - public void connect(SocketAddress address) throws SocketException - { - if (isClosed()) - throw new SocketException("socket is closed"); - - if (! (address instanceof InetSocketAddress)) - throw new IllegalArgumentException("unsupported address type"); - - InetSocketAddress tmp = (InetSocketAddress) address; - connect(tmp.getAddress(), tmp.getPort()); - } - - /** - * Returns the binding state of the socket. - * - * @return True if socket bound, false otherwise. - * - * @since 1.4 - */ - public boolean isBound() - { - return bound; - } - - /** - * Returns the connection state of the socket. - * - * @return True if socket is connected, false otherwise. - * - * @since 1.4 - */ - public boolean isConnected() - { - return remoteAddress != null; - } - - /** - * Returns the SocketAddress of the host this socket is conneted to - * or null if this socket is not connected. - * - * @return The socket address of the remote host if connected or null - * - * @since 1.4 - */ - public SocketAddress getRemoteSocketAddress() - { - if (! isConnected()) - return null; - - return new InetSocketAddress(remoteAddress, remotePort); - } - - /** - * Returns the local SocketAddress this socket is bound to. - * - * @return The local SocketAddress or null if the socket is not bound. - * - * @since 1.4 - */ - public SocketAddress getLocalSocketAddress() - { - if (! isBound()) - return null; - - return new InetSocketAddress(getLocalAddress(), getLocalPort()); - } - - /** - * Enables/Disables SO_REUSEADDR. - * - * @param on Whether or not to have SO_REUSEADDR turned on. - * - * @exception SocketException If an error occurs. - * - * @since 1.4 - */ - public void setReuseAddress(boolean on) throws SocketException - { - if (isClosed()) - throw new SocketException("socket is closed"); - - getImpl().setOption(SocketOptions.SO_REUSEADDR, Boolean.valueOf(on)); - } - - /** - * Checks if SO_REUSEADDR is enabled. - * - * @return True if SO_REUSEADDR is set on the socket, false otherwise. - * - * @exception SocketException If an error occurs. - * - * @since 1.4 - */ - public boolean getReuseAddress() throws SocketException - { - if (isClosed()) - throw new SocketException("socket is closed"); - - Object buf = getImpl().getOption(SocketOptions.SO_REUSEADDR); - - if (buf instanceof Boolean) - return ((Boolean) buf).booleanValue(); - - throw new SocketException("unexpected type"); - } - - /** - * Enables/Disables SO_BROADCAST - * - * @param enable True if SO_BROADCAST should be enabled, false otherwise. - * - * @exception SocketException If an error occurs - * - * @since 1.4 - */ - public void setBroadcast(boolean enable) throws SocketException - { - if (isClosed()) - throw new SocketException("socket is closed"); - - getImpl().setOption(SocketOptions.SO_BROADCAST, Boolean.valueOf(enable)); - } - - /** - * Checks if SO_BROADCAST is enabled - * - * @return Whether SO_BROADCAST is set - * - * @exception SocketException If an error occurs - * - * @since 1.4 - */ - public boolean getBroadcast() throws SocketException - { - if (isClosed()) - throw new SocketException("socket is closed"); - - Object buf = getImpl().getOption(SocketOptions.SO_BROADCAST); - - if (buf instanceof Boolean) - return ((Boolean) buf).booleanValue(); - - throw new SocketException("unexpected type"); - } - - /** - * Sets the traffic class value - * - * @param tc The traffic class - * - * @exception SocketException If an error occurs - * @exception IllegalArgumentException If tc value is illegal - * - * @see DatagramSocket#getTrafficClass() - * - * @since 1.4 - */ - public void setTrafficClass(int tc) throws SocketException - { - if (isClosed()) - throw new SocketException("socket is closed"); - - if (tc < 0 || tc > 255) - throw new IllegalArgumentException(); - - getImpl().setOption(SocketOptions.IP_TOS, new Integer(tc)); - } - - /** - * Returns the current traffic class - * - * @return The current traffic class. - * - * @see DatagramSocket#setTrafficClass(int tc) - * - * @exception SocketException If an error occurs - * - * @since 1.4 - */ - public int getTrafficClass() throws SocketException - { - if (isClosed()) - throw new SocketException("socket is closed"); - - Object buf = getImpl().getOption(SocketOptions.IP_TOS); - - if (buf instanceof Integer) - return ((Integer) buf).intValue(); - - throw new SocketException("unexpected type"); - } - - /** - * Sets the datagram socket implementation factory for the application - * - * @param fac The factory to set - * - * @exception IOException If an error occurs - * @exception SocketException If the factory is already defined - * @exception SecurityException If a security manager exists and its - * checkSetFactory method doesn't allow the operation - */ - public static void setDatagramSocketImplFactory(DatagramSocketImplFactory fac) - throws IOException - { - if (factory != null) - throw new SocketException("DatagramSocketImplFactory already defined"); - - SecurityManager sm = System.getSecurityManager(); - if (sm != null) - sm.checkSetFactory(); - - factory = fac; - } -} diff --git a/libjava/java/net/DatagramSocketImpl.java b/libjava/java/net/DatagramSocketImpl.java deleted file mode 100644 index cfcde92e5fc..00000000000 --- a/libjava/java/net/DatagramSocketImpl.java +++ /dev/null @@ -1,296 +0,0 @@ -/* DatagramSocketImpl.java -- Abstract class for UDP socket implementations - Copyright (C) 1998, 1999 2000, 2001, - 2002, 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.net; - -import java.io.FileDescriptor; -import java.io.IOException; - - -/** - * This abstract class models a datagram socket implementation. An - * actual implementation class would implement these methods, probably - * via redirecting them to native code. - * <p> - * Written using on-line Java Platform 1.2 API Specification, as well - * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998). - * <p> - * Status: Believed complete and correct. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Warren Levy (warrenl@cygnus.com) - * @since 1.1 - */ -public abstract class DatagramSocketImpl implements SocketOptions -{ - /** - * The local port to which this socket is bound - */ - protected int localPort; - - /** - * The FileDescriptor object for this object. - */ - protected FileDescriptor fd; - - /** - * Default, no-argument constructor for subclasses to call. - */ - public DatagramSocketImpl() - { - } - - /** - * This method binds the socket to the specified local port and address. - * - * @param lport The port number to bind to - * @param laddr The address to bind to - * - * @exception SocketException If an error occurs - */ - protected abstract void bind(int lport, InetAddress laddr) - throws SocketException; - - /** - * This methods closes the socket - */ - protected abstract void close(); - - /** - * Creates a new datagram socket. - * - * @exception SocketException If an error occurs - */ - protected abstract void create() throws SocketException; - - /** - * Takes a peek at the next packet received in order to retrieve the - * address of the sender - * - * @param i The <code>InetAddress</code> to fill in with the information - * about the sender if the next packet - * - * @return The port number of the sender of the packet - * - * @exception IOException If an error occurs - * @exception PortUnreachableException May be thrown if the socket is - * connected to a currently unreachable destination. Note, there is no - * guarantee that the exception will be thrown. - */ - protected abstract int peek(InetAddress i) throws IOException; - - /** - * Takes a peek at the next packet received. This packet is not consumed. - * With the next peekData/receive operation this packet will be read again. - * - * @param p The <code>DatagramPacket</code> to fill in with the data sent. - * - * @return The port number of the sender of the packet. - * - * @exception IOException If an error occurs - * @exception PortUnreachableException May be thrown if the socket is - * connected to a currently unreachable destination. Note, there is no - * guarantee that the exception will be thrown. - * - * @since 1.4 - */ - protected abstract int peekData(DatagramPacket p) throws IOException; - - /** - * Transmits the specified packet of data to the network. The destination - * host and port should be encoded in the packet. - * - * @param p The packet to send - * - * @exception IOException If an error occurs - * @exception PortUnreachableException May be thrown if the socket is - * connected to a currently unreachable destination. Note, there is no - * guarantee that the exception will be thrown. - */ - protected abstract void send(DatagramPacket p) throws IOException; - - /** - * Receives a packet of data from the network Will block until a packet - * arrives. The packet info in populated into the passed in - * <code>DatagramPacket</code> object. - * - * @param p A place to store the incoming packet. - * - * @exception IOException If an error occurs - * @exception PortUnreachableException May be thrown if the socket is - * connected to a currently unreachable destination. Note, there is no - * guarantee that the exception will be thrown. - */ - protected abstract void receive(DatagramPacket p) throws IOException; - - /** - * Connects the socket to a host specified by address and port. - * - * @param address The <code>InetAddress</code> of the host to connect to - * @param port The port number of the host to connect to - * - * @exception SocketException If an error occurs - * - * @since 1.4 - */ - protected void connect(InetAddress address, int port) - throws SocketException - { - // This method has to be overwritten by real implementations - } - - /** - * Disconnects the socket. - * - * @since 1.4 - */ - protected void disconnect() - { - // This method has to be overwritten by real implementations - } - - /** - * Sets the Time to Live (TTL) setting on this socket to the specified - * value. <b>Use <code>setTimeToLive(int)</code></b> instead. - * - * @param ttl The new Time to Live value - * - * @exception IOException If an error occurs - * @deprecated - */ - protected abstract void setTTL(byte ttl) throws IOException; - - /** - * This method returns the current Time to Live (TTL) setting on this - * socket. <b>Use <code>getTimeToLive()</code></b> instead. - * - * @return the current time-to-live - * - * @exception IOException If an error occurs - * - * @deprecated // FIXME: when ? - */ - protected abstract byte getTTL() throws IOException; - - /** - * Sets the Time to Live (TTL) setting on this socket to the specified - * value. - * - * @param ttl The new Time to Live value - * - * @exception IOException If an error occurs - */ - protected abstract void setTimeToLive(int ttl) throws IOException; - - /** - * This method returns the current Time to Live (TTL) setting on this - * socket. - * - * @return the current time-to-live - * - * @exception IOException If an error occurs - */ - protected abstract int getTimeToLive() throws IOException; - - /** - * Causes this socket to join the specified multicast group - * - * @param inetaddr The multicast address to join with - * - * @exception IOException If an error occurs - */ - protected abstract void join(InetAddress inetaddr) throws IOException; - - /** - * Causes the socket to leave the specified multicast group. - * - * @param inetaddr The multicast address to leave - * - * @exception IOException If an error occurs - */ - protected abstract void leave(InetAddress inetaddr) throws IOException; - - /** - * Causes this socket to join the specified multicast group on a specified - * device - * - * @param mcastaddr The address to leave - * @param netIf The specified network interface to join the group at - * - * @exception IOException If an error occurs - * - * @since 1.4 - */ - protected abstract void joinGroup(SocketAddress mcastaddr, - NetworkInterface netIf) - throws IOException; - - /** - * Leaves a multicast group - * - * @param mcastaddr The address to join - * @param netIf The specified network interface to leave the group at - * - * @exception IOException If an error occurs - * - * @since 1.4 - */ - protected abstract void leaveGroup(SocketAddress mcastaddr, - NetworkInterface netIf) - throws IOException; - - /** - * Returns the FileDescriptor for this socket - * - * @return the file descriptor associated with this socket - */ - protected FileDescriptor getFileDescriptor() - { - return fd; - } - - /** - * Returns the local port this socket is bound to - * - * @return the local port - */ - protected int getLocalPort() - { - return localPort; - } -} diff --git a/libjava/java/net/DatagramSocketImplFactory.java b/libjava/java/net/DatagramSocketImplFactory.java deleted file mode 100644 index 014651aa899..00000000000 --- a/libjava/java/net/DatagramSocketImplFactory.java +++ /dev/null @@ -1,60 +0,0 @@ -/* DatagramSocketImplFactory.java -- - Copyright (C) 2002, 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.net; - - -/** Written using on-line Java Platform 1.4 API Specification. - * Status: Believed complete and correct. - */ -/** - * This interface defines one method which returns a - * <code>DatagramSocketImpl</code> object. - * This should not be needed by ordinary applications. - * - * @author Michael Koch (konqueror@gmx.de) - * @since 1.3 - */ -public interface DatagramSocketImplFactory -{ - /** - * This method returns an instance of the DatagramSocketImpl object - * - * @return A DatagramSocketImpl object - */ - DatagramSocketImpl createDatagramSocketImpl(); -} // interface DatagramSocketImplFactory diff --git a/libjava/java/net/FileNameMap.java b/libjava/java/net/FileNameMap.java deleted file mode 100644 index 6f1d25a6a52..00000000000 --- a/libjava/java/net/FileNameMap.java +++ /dev/null @@ -1,65 +0,0 @@ -/* FileNameMap.java -- Maps filenames to MIME types - Copyright (C) 1998, 1999, 2000, 2001, 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.net; - - -/** - * Written using on-line Java Platform 1.2 API Specification, as well - * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998). - * Status: Believed complete and correct. - */ -/** - * This interface has one method which, when passed a filename, returns - * the MIME type associated with that filename. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Warren Levy (warrenl@cygnus.com) - * @since 1.1 - */ -public interface FileNameMap -{ - /** - * This method is passed a filename and is responsible for determining - * the appropriate MIME type for that file. - * - * @param filename The name of the file to generate a MIME type for. - * - * @return The MIME type for the filename passed in. - */ - String getContentTypeFor(String filename); -} // interface FileNameMap diff --git a/libjava/java/net/HttpURLConnection.java b/libjava/java/net/HttpURLConnection.java deleted file mode 100644 index 07eae48e77a..00000000000 --- a/libjava/java/net/HttpURLConnection.java +++ /dev/null @@ -1,589 +0,0 @@ -/* HttpURLConnection.java -- Subclass of communications links using - Hypertext Transfer Protocol. - Copyright (C) 1998, 1999, 2000, 2002, 2003 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.net; - -import java.io.IOException; -import java.io.InputStream; -import java.io.PushbackInputStream; -import java.security.Permission; - - -/* - * Written using on-line Java Platform 1.2 API Specification, as well - * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998). - * Status: Believed complete and correct. - */ - -/** - * This class provides a common abstract implementation for those - * URL connection classes that will connect using the HTTP protocol. - * In addition to the functionality provided by the URLConnection - * class, it defines constants for HTTP return code values and - * methods for setting the HTTP request method and determining whether - * or not to follow redirects. - * - * @since 1.1 - * - * @author Warren Levy (warrenl@cygnus.com) - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public abstract class HttpURLConnection extends URLConnection -{ - /* HTTP Success Response Codes */ - - /** - * Indicates that the client may continue with its request. This value - * is specified as part of RFC 2068 but was not included in Sun's JDK, so - * beware of using this value - */ - static final int HTTP_CONTINUE = 100; - - /** - * Indicates the request succeeded. - */ - public static final int HTTP_OK = 200; - - /** - * The requested resource has been created. - */ - public static final int HTTP_CREATED = 201; - - /** - * The request has been accepted for processing but has not completed. - * There is no guarantee that the requested action will actually ever - * be completed succesfully, but everything is ok so far. - */ - public static final int HTTP_ACCEPTED = 202; - - /** - * The meta-information returned in the header is not the actual data - * from the original server, but may be from a local or other copy. - * Normally this still indicates a successful completion. - */ - public static final int HTTP_NOT_AUTHORITATIVE = 203; - - /** - * The server performed the request, but there is no data to send - * back. This indicates that the user's display should not be changed. - */ - public static final int HTTP_NO_CONTENT = 204; - - /** - * The server performed the request, but there is no data to sent back, - * however, the user's display should be "reset" to clear out any form - * fields entered. - */ - public static final int HTTP_RESET = 205; - - /** - * The server completed the partial GET request for the resource. - */ - public static final int HTTP_PARTIAL = 206; - - /* HTTP Redirection Response Codes */ - - /** - * There is a list of choices available for the requested resource. - */ - public static final int HTTP_MULT_CHOICE = 300; - - /** - * The resource has been permanently moved to a new location. - */ - public static final int HTTP_MOVED_PERM = 301; - - /** - * The resource requested has been temporarily moved to a new location. - */ - public static final int HTTP_MOVED_TEMP = 302; - - /** - * The response to the request issued is available at another location. - */ - public static final int HTTP_SEE_OTHER = 303; - - /** - * The document has not been modified since the criteria specified in - * a conditional GET. - */ - public static final int HTTP_NOT_MODIFIED = 304; - - /** - * The requested resource needs to be accessed through a proxy. - */ - public static final int HTTP_USE_PROXY = 305; - - /* HTTP Client Error Response Codes */ - - /** - * The request was misformed or could not be understood. - */ - public static final int HTTP_BAD_REQUEST = 400; - - /** - * The request made requires user authorization. Try again with - * a correct authentication header. - */ - public static final int HTTP_UNAUTHORIZED = 401; - - /** - * Code reserved for future use - I hope way in the future. - */ - public static final int HTTP_PAYMENT_REQUIRED = 402; - - /** - * There is no permission to access the requested resource. - */ - public static final int HTTP_FORBIDDEN = 403; - - /** - * The requested resource was not found. - */ - public static final int HTTP_NOT_FOUND = 404; - - /** - * The specified request method is not allowed for this resource. - */ - public static final int HTTP_BAD_METHOD = 405; - - /** - * Based on the input headers sent, the resource returned in response - * to the request would not be acceptable to the client. - */ - public static final int HTTP_NOT_ACCEPTABLE = 406; - - /** - * The client must authenticate with a proxy prior to attempting this - * request. - */ - public static final int HTTP_PROXY_AUTH = 407; - - /** - * The request timed out. - */ - public static final int HTTP_CLIENT_TIMEOUT = 408; - - /** - * There is a conflict between the current state of the resource and the - * requested action. - */ - public static final int HTTP_CONFLICT = 409; - - /** - * The requested resource is no longer available. This ususally indicates - * a permanent condition. - */ - public static final int HTTP_GONE = 410; - - /** - * A Content-Length header is required for this request, but was not - * supplied. - */ - public static final int HTTP_LENGTH_REQUIRED = 411; - - /** - * A client specified pre-condition was not met on the server. - */ - public static final int HTTP_PRECON_FAILED = 412; - - /** - * The request sent was too large for the server to handle. - */ - public static final int HTTP_ENTITY_TOO_LARGE = 413; - - /** - * The name of the resource specified was too long. - */ - public static final int HTTP_REQ_TOO_LONG = 414; - - /** - * The request is in a format not supported by the requested resource. - */ - public static final int HTTP_UNSUPPORTED_TYPE = 415; - - /* HTTP Server Error Response Codes */ - - /** - * This error code indicates that some sort of server error occurred. - * - * @deprecated - */ - public static final int HTTP_SERVER_ERROR = 500; - - /** - * The server encountered an unexpected error (such as a CGI script crash) - * that prevents the request from being fulfilled. - */ - public static final int HTTP_INTERNAL_ERROR = 500; - - /** - * The server does not support the requested functionality. - * @since 1.3 - */ - public static final int HTTP_NOT_IMPLEMENTED = 501; - - /** - * The proxy encountered a bad response from the server it was proxy-ing for - */ - public static final int HTTP_BAD_GATEWAY = 502; - - /** - * The HTTP service is not availalble, such as because it is overloaded - * and does not want additional requests. - */ - public static final int HTTP_UNAVAILABLE = 503; - - /** - * The proxy timed out getting a reply from the remote server it was - * proxy-ing for. - */ - public static final int HTTP_GATEWAY_TIMEOUT = 504; - - /** - * This server does not support the protocol version requested. - */ - public static final int HTTP_VERSION = 505; - - // Non-HTTP response static variables - - /** - * Flag to indicate whether or not redirects should be automatically - * followed by default. - */ - private static boolean followRedirects = true; - - /** - * This is a list of valid request methods, separated by "|" characters. - */ - private static final String valid_methods = - "|GET|POST|HEAD|OPTIONS|PUT|DELETE|TRACE|"; - - // Instance Variables - - /** - * The requested method in use for this connection. Default is GET. - */ - protected String method = "GET"; - - /** - * The response code received from the server - */ - protected int responseCode = -1; - - /** - * The response message string received from the server. - */ - protected String responseMessage; - - /** - * If this instance should follow redirect requests. - */ - protected boolean instanceFollowRedirects = followRedirects; - - /** - * Whether we already got a valid response code for this connection. - * Used by <code>getResponseCode()</code> and - * <code>getResponseMessage()</code>. - */ - private boolean gotResponseVals; - - /** - * Create an HttpURLConnection for the specified URL - * - * @param url The URL to create this connection for. - */ - protected HttpURLConnection(URL url) - { - super(url); - } - - /** - * Closes the connection to the server. - */ - public abstract void disconnect(); - - /** - * Returns a boolean indicating whether or not this connection is going - * through a proxy - * - * @return true if through a proxy, false otherwise - */ - public abstract boolean usingProxy(); - - /** - * Sets whether HTTP redirects (requests with response code 3xx) should be - * automatically followed by this class. True by default - * - * @param set true if redirects should be followed, false otherwis. - * - * @exception SecurityException If a security manager exists and its - * checkSetFactory method doesn't allow the operation - */ - public static void setFollowRedirects(boolean set) - { - // Throw an exception if an extant security mgr precludes - // setting the factory. - SecurityManager s = System.getSecurityManager(); - if (s != null) - s.checkSetFactory(); - - followRedirects = set; - } - - /** - * Returns a boolean indicating whether or not HTTP redirects will - * automatically be followed or not. - * - * @return true if redirects will be followed, false otherwise - */ - public static boolean getFollowRedirects() - { - return followRedirects; - } - - /** - * Returns the value of this HttpURLConnection's instanceFollowRedirects - * field - * - * @return true if following redirects is enabled, false otherwise - */ - public boolean getInstanceFollowRedirects() - { - return instanceFollowRedirects; - } - - /** - * Sets the value of this HttpURLConnection's instanceFollowRedirects field - * - * @param follow true to enable following redirects, false otherwise - */ - public void setInstanceFollowRedirects(boolean follow) - { - instanceFollowRedirects = follow; - } - - /** - * Set the method for the URL request, one of: - * GET POST HEAD OPTIONS PUT DELETE TRACE are legal - * - * @param method the method to use - * - * @exception ProtocolException If the method cannot be reset or if the - * requested method isn't valid for HTTP - */ - public void setRequestMethod(String method) throws ProtocolException - { - if (connected) - throw new ProtocolException("Already connected"); - - method = method.toUpperCase(); - if (valid_methods.indexOf("|" + method + "|") != -1) - this.method = method; - else - throw new ProtocolException("Invalid HTTP request method: " + method); - } - - /** - * The request method currently in use for this connection. - * - * @return The request method - */ - public String getRequestMethod() - { - return method; - } - - /** - * Gets the status code from an HTTP response message, or -1 if - * the response code could not be determined. - * Note that all valid response codes have class variables - * defined for them in this class. - * - * @return The response code - * - * @exception IOException If an error occurs - */ - public int getResponseCode() throws IOException - { - if (! gotResponseVals) - getResponseVals(); - return responseCode; - } - - /** - * Gets the HTTP response message, if any, returned along with the - * response code from a server. Null if no response message was set - * or an error occured while connecting. - * - * @return The response message - * - * @exception IOException If an error occurs - */ - public String getResponseMessage() throws IOException - { - if (! gotResponseVals) - getResponseVals(); - return responseMessage; - } - - private void getResponseVals() throws IOException - { - // getHeaderField() will connect for us, but do it here first in - // order to pick up IOExceptions. - if (! connected) - connect(); - - gotResponseVals = true; - - // If responseCode not yet explicitly set by subclass - if (responseCode == -1) - { - // Response is the first header received from the connection. - String respField = getHeaderField(0); - - if (respField == null || ! respField.startsWith("HTTP/")) - { - // Set to default values on failure. - responseCode = -1; - responseMessage = null; - return; - } - - int firstSpc; - int nextSpc; - firstSpc = respField.indexOf(' '); - nextSpc = respField.indexOf(' ', firstSpc + 1); - responseMessage = respField.substring(nextSpc + 1); - String codeStr = respField.substring(firstSpc + 1, nextSpc); - try - { - responseCode = Integer.parseInt(codeStr); - } - catch (NumberFormatException e) - { - // Set to default values on failure. - responseCode = -1; - responseMessage = null; - } - } - } - - /** - * Returns a permission object representing the permission necessary to make - * the connection represented by this object - * - * @return the permission necessary for this connection - * - * @exception IOException If an error occurs - */ - public Permission getPermission() throws IOException - { - URL url = getURL(); - String host = url.getHost(); - int port = url.getPort(); - if (port == -1) - port = 80; - - host = host + ":" + port; - - return new SocketPermission(host, "connect"); - } - - /** - * This method allows the caller to retrieve any data that might have - * been sent despite the fact that an error occurred. For example, the - * HTML page sent along with a 404 File Not Found error. If the socket - * is not connected, or if no error occurred or no data was returned, - * this method returns <code>null</code>. - * - * @return An <code>InputStream</code> for reading error data. - */ - public InputStream getErrorStream() - { - if (! connected) - return null; - - int code; - try - { - code = getResponseCode(); - } - catch (IOException e) - { - code = -1; - } - - if (code == -1) - return null; - - if (((code / 100) != 4) || ((code / 100) != 5)) - return null; - - try - { - PushbackInputStream pbis = new PushbackInputStream(getInputStream()); - - int i = pbis.read(); - if (i == -1) - return null; - - pbis.unread(i); - return pbis; - } - catch (IOException e) - { - return null; - } - } - - /** - * Returns the value of the named field parsed as date - * - * @param key the key of the header field - * @param value the default value if the header field is not present - * - * @return the value of the header field - */ - public long getHeaderFieldDate(String key, long value) - { - // FIXME: implement this correctly - // http://www.w3.org/Protocols/HTTP-NG/ng-notes.txt - return super.getHeaderFieldDate(key, value); - } -} diff --git a/libjava/java/net/Inet4Address.java b/libjava/java/net/Inet4Address.java deleted file mode 100644 index 00c6501de0c..00000000000 --- a/libjava/java/net/Inet4Address.java +++ /dev/null @@ -1,233 +0,0 @@ -/* Inet4Address.java -- - Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.net; - -import java.io.ObjectStreamException; - -/* - * Written using on-line Java Platform 1.4 API Specification and - * RFC 1884 (http://www.ietf.org/rfc/rfc1884.txt), - * RFC 1918 (http://www.ietf.org/rfc/rfc1918.txt), - * RFC 2365 (http://www.ietf.org/rfc/rfc2365.txt) - * - * @author Michael Koch - * @status Believed complete and correct. - */ -public final class Inet4Address extends InetAddress -{ - /** - * For compatability with Sun's JDK 1.4.2 rev. 5 - */ - static final long serialVersionUID = 3286316764910316507L; - - /** - * needed for serialization - */ - private Object writeReplace() throws ObjectStreamException - { - return new InetAddress(addr, hostName); - } - - /** - * Initializes this object's addr instance variable from the passed in - * byte array. Note that this constructor is protected and is called - * only by static methods in this class. - * - * @param addr The IP number of this address as an array of bytes - * @param hostname The hostname of this IP address. - */ - Inet4Address(byte[] addr, String host) - { - super(addr, host); - } - - /** - * Checks if the address is a multicast address - * - * @since 1.1 - */ - public boolean isMulticastAddress() - { - return super.isMulticastAddress(); - } - - /** - * Checks if this address is a loopback address - */ - public boolean isLoopbackAddress() - { - return super.isLoopbackAddress(); - } - - /** - * Checks if this address is a wildcard address - * - * @since 1.4 - */ - public boolean isAnyLocalAddress() - { - return super.isAnyLocalAddress(); - } - - /** - * Checks if this address is a link local address - * - * @since 1.4 - */ - public boolean isLinkLocalAddress() - { - return super.isLinkLocalAddress(); - } - - /** - * Checks if this address is a site local address - * - * @since 1.4 - */ - public boolean isSiteLocalAddress() - { - return super.isSiteLocalAddress(); - } - - /** - * Checks if this multicast address has global scope - * - * @since 1.4 - */ - public boolean isMCGlobal() - { - return super.isMCGlobal(); - } - - /** - * Checks if this multicast address has node scope - * - * @since 1.4 - */ - public boolean isMCNodeLocal() - { - return isMCNodeLocal(); - } - - /** - * Checks if this multicast address has link scope - * - * @since 1.4 - */ - public boolean isMCLinkLocal() - { - return super.isMCLinkLocal(); - } - - /** - * Checks if this multicast address has site scope - * - * @since 1.4 - */ - public boolean isMCSiteLocal() - { - return super.isMCSiteLocal(); - } - - /** - * Checks if this multicast address has organization scope - * - * @since 1.4 - */ - public boolean isMCOrgLocal() - { - return isMCOrgLocal(); - } - - /** - * Returns the address of the current instance - */ - public byte[] getAddress() - { - return (byte[]) addr.clone(); - } - - /** - * Returns the address as string - * - * @since 1.0.2 - */ - public String getHostAddress() - { - return super.getHostAddress(); - } - - /** - * Computes the hashcode of the instance - */ - public int hashCode() - { - int hash = 0; - int len = addr.length; - int i = len > 4 ? len - 4 : 0; - - for (; i < len; i++) - hash = (hash << 8) | (addr[i] & 0xFF); - - return hash; - } - - /** - * Compare the current Inet4Address instance with obj - * - * @param obj Object to compare with - */ - public boolean equals(Object obj) - { - if (! (obj instanceof InetAddress)) - return false; - - byte[] addr1 = addr; - byte[] addr2 = ((InetAddress) obj).addr; - - if (addr1.length != addr2.length) - return false; - - for (int i = addr1.length; --i >= 0;) - if (addr1[i] != addr2[i]) - return false; - - return true; - } -} diff --git a/libjava/java/net/Inet6Address.java b/libjava/java/net/Inet6Address.java deleted file mode 100644 index 0d62fe919a0..00000000000 --- a/libjava/java/net/Inet6Address.java +++ /dev/null @@ -1,261 +0,0 @@ -/* Inet6Address.java -- - Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.net; - -import java.util.Arrays; - -/* - * Written using on-line Java Platform 1.4 API Specification and - * RFC 1884 (http://www.ietf.org/rfc/rfc1884.txt) - * - * @author Michael Koch - * @status Believed complete and correct. - */ -public final class Inet6Address extends InetAddress -{ - static final long serialVersionUID = 6880410070516793377L; - - /** - * Needed for serialization - */ - byte[] ipaddress; - - /** - * Create an Inet6Address object - * - * @param addr The IP address - * @param host The hostname - */ - Inet6Address(byte[] addr, String host) - { - super(addr, host); - // Super constructor clones the addr. Get a reference to the clone. - this.ipaddress = this.addr; - } - - /** - * Utility routine to check if the InetAddress is an IP multicast address - * - * @since 1.1 - */ - public boolean isMulticastAddress() - { - return ipaddress[0] == 0xFF; - } - - /** - * Utility routine to check if the InetAddress in a wildcard address - * - * @since 1.4 - */ - public boolean isAnyLocalAddress() - { - byte[] anylocal = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - - return Arrays.equals(ipaddress, anylocal); - } - - /** - * Utility routine to check if the InetAddress is a loopback address - * - * @since 1.4 - */ - public boolean isLoopbackAddress() - { - byte[] loopback = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }; - - return Arrays.equals(ipaddress, loopback); - } - - /** - * Utility routine to check if the InetAddress is an link local address - * - * @since 1.4 - */ - public boolean isLinkLocalAddress() - { - return ipaddress[0] == 0xFA; - } - - /** - * Utility routine to check if the InetAddress is a site local address - * - * @since 1.4 - */ - public boolean isSiteLocalAddress() - { - return ipaddress[0] == 0xFB; - } - - /** - * Utility routine to check if the multicast address has global scope - * - * @since 1.4 - */ - public boolean isMCGlobal() - { - if (! isMulticastAddress()) - return false; - - return (ipaddress[1] & 0x0F) == 0xE; - } - - /** - * Utility routine to check if the multicast address has node scope - * - * @since 1.4 - */ - public boolean isMCNodeLocal() - { - if (! isMulticastAddress()) - return false; - - return (ipaddress[1] & 0x0F) == 0x1; - } - - /** - * Utility routine to check if the multicast address has link scope - * - * @since 1.4 - */ - public boolean isMCLinkLocal() - { - if (! isMulticastAddress()) - return false; - - return (ipaddress[1] & 0x0F) == 0x2; - } - - /** - * Utility routine to check if the multicast address has site scope - * - * @since 1.4 - */ - public boolean isMCSiteLocal() - { - if (! isMulticastAddress()) - return false; - - return (ipaddress[1] & 0x0F) == 0x5; - } - - /** - * Utility routine to check if the multicast address has organization scope - * - * @since 1.4 - */ - public boolean isMCOrgLocal() - { - if (! isMulticastAddress()) - return false; - - return (ipaddress[1] & 0x0F) == 0x8; - } - - /** - * Returns the raw IP address of this InetAddress object. The result is in - * network byte order: the highest order byte of the address is i - * n getAddress()[0] - */ - public byte[] getAddress() - { - return (byte[]) ipaddress.clone(); - } - - /** - * Returns the IP address string in textual presentation - */ - public String getHostAddress() - { - StringBuffer sbuf = new StringBuffer(40); - - for (int i = 0; i < 16; i += 2) - { - int x = ((ipaddress[i] & 0xFF) << 8) | (ipaddress[i + 1] & 0xFF); - - if (i > 0) - sbuf.append(':'); - - sbuf.append(Integer.toHexString(x)); - } - - return sbuf.toString(); - } - - /** - * Returns a hashcode for this IP address - */ - public int hashCode() - { - return super.hashCode(); - } - - /** - * Compares this object against the specified object - */ - public boolean equals(Object obj) - { - if (! (obj instanceof Inet6Address)) - return false; - - // this.ipaddress is never set in this class except to - // the value of the super class' addr. The super classes - // equals(Object) will do the compare. - return super.equals(obj); - } - - /** - * Utility routine to check if the InetAddress is an - * IPv4 compatible IPv6 address - * - * @since 1.4 - */ - public boolean isIPv4CompatibleAddress() - { - if (ipaddress[0] != 0x00 || ipaddress[1] != 0x00 || ipaddress[2] != 0x00 - || ipaddress[3] != 0x00 || ipaddress[4] != 0x00 - || ipaddress[5] != 0x00 || ipaddress[6] != 0x00 - || ipaddress[7] != 0x00 || ipaddress[8] != 0x00 - || ipaddress[9] != 0x00 || ipaddress[10] != 0x00 - || ipaddress[11] != 0x00) - return false; - - return true; - } -} diff --git a/libjava/java/net/InetSocketAddress.java b/libjava/java/net/InetSocketAddress.java deleted file mode 100644 index 30d34e7e808..00000000000 --- a/libjava/java/net/InetSocketAddress.java +++ /dev/null @@ -1,221 +0,0 @@ -/* InetSocketAddress.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.net; - - -/** - * InetSocketAddress instances represent socket addresses - * in the java.nio package. They encapsulate a InetAddress and - * a port number. - * - * @since 1.4 - */ -public class InetSocketAddress extends SocketAddress -{ - /** - * Compatible with JDK 1.4+ - */ - private static final long serialVersionUID = 5076001401234631237L; - - /** - * Name of host. - */ - private String hostname; - - /** - * Address of host. - */ - private InetAddress addr; - - /** - * Port of host. - */ - private int port; - - /** - * Constructs an InetSocketAddress instance. - * - * @param addr Address of the socket - * @param port Port if the socket - * - * @exception IllegalArgumentException If the port number is illegel - */ - public InetSocketAddress(InetAddress addr, int port) - throws IllegalArgumentException - { - if (port < 0 || port > 65535) - throw new IllegalArgumentException("Bad port number: " + port); - - if (addr == null) - addr = InetAddress.ANY_IF; - - this.addr = addr; - this.port = port; - this.hostname = addr.getHostName(); - } - - /** - * Constructs an InetSocketAddress instance. - * - * @param port Port if the socket - * - * @exception IllegalArgumentException If the port number is illegal - */ - public InetSocketAddress(int port) throws IllegalArgumentException - { - this((InetAddress) null, port); - } - - /** - * Constructs an InetSocketAddress instance. - * - * @param hostname The hostname for the socket address - * @param port The port for the socket address - * - * @exception IllegalArgumentException If the port number is illegal - */ - public InetSocketAddress(String hostname, int port) - throws IllegalArgumentException - { - if (hostname == null) - throw new IllegalArgumentException("Null host name value"); - - if (port < 0 || port > 65535) - throw new IllegalArgumentException("Bad port number: " + port); - - this.port = port; - this.hostname = hostname; - - try - { - this.addr = InetAddress.getByName(hostname); - } - catch (Exception e) // UnknownHostException, SecurityException - { - this.addr = null; - } - } - - /** - * Test if obj is a <code>InetSocketAddress</code> and - * has the same address and port - * - * @param obj The obj to compare this address with. - * - * @return True if obj is equal. - */ - public final boolean equals(Object obj) - { - // InetSocketAddress objects are equal when addr and port are equal. - // The hostname may differ. - if (obj instanceof InetSocketAddress) - { - InetSocketAddress sa = (InetSocketAddress) obj; - - if (addr == null && sa.addr != null) - return false; - else if (addr == null && sa.addr == null) - return hostname.equals(sa.hostname) && sa.port == port; - else - return addr.equals(sa.addr) && sa.port == port; - } - - return false; - } - - /** - * Returns the <code>InetAddress</code> or - * <code>null</code> if its unresolved - * - * @return The IP address of this address. - */ - public final InetAddress getAddress() - { - return addr; - } - - /** - * Returns <code>hostname</code> - * - * @return The hostname of this address. - */ - public final String getHostName() - { - return hostname; - } - - /** - * Returns the <code>port</code> - * - * @return The port of this address. - */ - public final int getPort() - { - return port; - } - - /** - * Returns the hashcode of the <code>InetSocketAddress</code> - * - * @return The hashcode for this address. - */ - public final int hashCode() - { - return port + addr.hashCode(); - } - - /** - * Checks wether the address has been resolved or not - * - * @return True if address is unresolved. - */ - public final boolean isUnresolved() - { - return addr == null; - } - - /** - * Returns the <code>InetSocketAddress</code> as string - * - * @return A string represenation of this address. - */ - public String toString() - { - return (addr == null ? hostname : addr.getHostName()) + ":" + port; - } -} diff --git a/libjava/java/net/MalformedURLException.java b/libjava/java/net/MalformedURLException.java deleted file mode 100644 index 27e201886a0..00000000000 --- a/libjava/java/net/MalformedURLException.java +++ /dev/null @@ -1,74 +0,0 @@ -/* MalformedURLException.java -- A URL was not in a valid format - Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.net; - -import java.io.IOException; - - -/** - * This exception indicates that a URL passed to an object was not in a - * valid format. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Warren Levy (warrenl@cygnus.com) - * @status updated to 1.4 - */ -public class MalformedURLException extends IOException -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = -182787522200415866L; - - /** - * Create a new instance without a descriptive error message. - */ - public MalformedURLException() - { - } - - /** - * Create a new instance with a descriptive error message. - * - * @param message a message describing the error that occurred - */ - public MalformedURLException(String message) - { - super(message); - } -} // class MalformedURLException diff --git a/libjava/java/net/MulticastSocket.java b/libjava/java/net/MulticastSocket.java deleted file mode 100644 index 03bdf1e77d9..00000000000 --- a/libjava/java/net/MulticastSocket.java +++ /dev/null @@ -1,486 +0,0 @@ -/* MulticastSocket.java -- Class for using multicast sockets - Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 - Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.net; - -import java.io.IOException; -import java.util.Enumeration; - - -/** - * Written using on-line Java Platform 1.2 API Specification, as well - * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998). - * Status: Believed complete and correct. - */ -/** - * This class models a multicast UDP socket. A multicast address is a - * class D internet address (one whose most significant bits are 1110). - * A multicast group consists of a multicast address and a well known - * port number. All members of the group listening on that address and - * port will receive all the broadcasts to the group. - * <p> - * Please note that applets are not allowed to use multicast sockets - * - * Written using on-line Java Platform 1.2 API Specification, as well - * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998). - * Status: Believed complete and correct. - * - * @author Warren Levy (warrenl@cygnus.com) - * @author Aaron M. Renn (arenn@urbanophile.com) (Documentation comments) - * @since 1.1 - * @date May 18, 1999. - */ -public class MulticastSocket extends DatagramSocket -{ - /** - * Create a MulticastSocket that this not bound to any address - * - * @exception IOException If an error occurs - * @exception SecurityException If a security manager exists and its - * checkListen method doesn't allow the operation - */ - public MulticastSocket() throws IOException - { - this(new InetSocketAddress(0)); - } - - /** - * Create a multicast socket bound to the specified port - * - * @param port The port to bind to - * - * @exception IOException If an error occurs - * @exception SecurityException If a security manager exists and its - * checkListen method doesn't allow the operation - */ - public MulticastSocket(int port) throws IOException - { - this(new InetSocketAddress(port)); - } - - /** - * Create a multicast socket bound to the specified SocketAddress. - * - * @param address The SocketAddress the multicast socket will be bound to - * - * @exception IOException If an error occurs - * @exception SecurityException If a security manager exists and its - * checkListen method doesn't allow the operation - * - * @since 1.4 - */ - public MulticastSocket(SocketAddress address) throws IOException - { - super((SocketAddress) null); - setReuseAddress(true); - if (address != null) - bind(address); - } - - /** - * Returns the interface being used for multicast packets - * - * @return The multicast interface - * - * @exception SocketException If an error occurs - */ - public InetAddress getInterface() throws SocketException - { - if (isClosed()) - throw new SocketException("socket is closed"); - - return (InetAddress) getImpl().getOption(SocketOptions.IP_MULTICAST_IF); - } - - /** - * Returns the current value of the "Time to Live" option. This is the - * number of hops a packet can make before it "expires". This method id - * deprecated. Use <code>getTimeToLive</code> instead. - * - * @return The TTL value - * - * @exception IOException If an error occurs - * - * @deprecated 1.2 Replaced by getTimeToLive() - * - * @see MulticastSocket#getTimeToLive() - */ - public byte getTTL() throws IOException - { - if (isClosed()) - throw new SocketException("socket is closed"); - - // Use getTTL here rather than getTimeToLive in case we're using an impl - // other than the default PlainDatagramSocketImpl and it doesn't have - // getTimeToLive yet. - return getImpl().getTTL(); - } - - /** - * Returns the current value of the "Time to Live" option. This is the - * number of hops a packet can make before it "expires". - * - * @return The TTL value - * - * @exception IOException If an error occurs - * - * @since 1.2 - */ - public int getTimeToLive() throws IOException - { - if (isClosed()) - throw new SocketException("socket is closed"); - - return getImpl().getTimeToLive(); - } - - /** - * Sets the interface to use for sending multicast packets. - * - * @param addr The new interface to use. - * - * @exception SocketException If an error occurs. - * - * @since 1.4 - */ - public void setInterface(InetAddress addr) throws SocketException - { - if (isClosed()) - throw new SocketException("socket is closed"); - - getImpl().setOption(SocketOptions.IP_MULTICAST_IF, addr); - } - - /** - * Sets the local network interface used to send multicast messages - * - * @param netIf The local network interface used to send multicast messages - * - * @exception SocketException If an error occurs - * - * @see MulticastSocket#getNetworkInterface() - * - * @since 1.4 - */ - public void setNetworkInterface(NetworkInterface netIf) - throws SocketException - { - if (isClosed()) - throw new SocketException("socket is closed"); - - Enumeration e = netIf.getInetAddresses(); - - if (! e.hasMoreElements()) - throw new SocketException("no network devices found"); - - InetAddress address = (InetAddress) e.nextElement(); - getImpl().setOption(SocketOptions.IP_MULTICAST_IF, address); - } - - /** - * Gets the local network interface which is used to send multicast messages - * - * @return The local network interface to send multicast messages - * - * @exception SocketException If an error occurs - * - * @see MulticastSocket#setNetworkInterface(NetworkInterface netIf) - * - * @since 1.4 - */ - public NetworkInterface getNetworkInterface() throws SocketException - { - if (isClosed()) - throw new SocketException("socket is closed"); - - InetAddress address = - (InetAddress) getImpl().getOption(SocketOptions.IP_MULTICAST_IF); - NetworkInterface netIf = NetworkInterface.getByInetAddress(address); - - return netIf; - } - - /** - * Disable/Enable local loopback of multicast packets. The option is used by - * the platform's networking code as a hint for setting whether multicast - * data will be looped back to the local socket. - * - * Because this option is a hint, applications that want to verify what - * loopback mode is set to should call #getLoopbackMode - * - * @param disable True to disable loopback mode - * - * @exception SocketException If an error occurs - * - * @since 1.4 - */ - public void setLoopbackMode(boolean disable) throws SocketException - { - if (isClosed()) - throw new SocketException("socket is closed"); - - getImpl().setOption(SocketOptions.IP_MULTICAST_LOOP, - Boolean.valueOf(disable)); - } - - /** - * Checks if local loopback mode is enabled - * - * @return true if loopback mode is enabled, false otherwise - * - * @exception SocketException If an error occurs - * - * @since 1.4 - */ - public boolean getLoopbackMode() throws SocketException - { - if (isClosed()) - throw new SocketException("socket is closed"); - - Object buf = getImpl().getOption(SocketOptions.IP_MULTICAST_LOOP); - - if (buf instanceof Boolean) - return ((Boolean) buf).booleanValue(); - - throw new SocketException("unexpected type"); - } - - /** - * Sets the "Time to Live" value for a socket. The value must be between - * 1 and 255. - * - * @param ttl The new TTL value - * - * @exception IOException If an error occurs - * - * @deprecated 1.2 Replaced by <code>setTimeToLive</code> - * - * @see MulticastSocket#setTimeToLive(int ttl) - */ - public void setTTL(byte ttl) throws IOException - { - if (isClosed()) - throw new SocketException("socket is closed"); - - // Use setTTL here rather than setTimeToLive in case we're using an impl - // other than the default PlainDatagramSocketImpl and it doesn't have - // setTimeToLive yet. - getImpl().setTTL(ttl); - } - - /** - * Sets the "Time to Live" value for a socket. The value must be between - * 1 and 255. - * - * @param ttl The new TTL value - * - * @exception IOException If an error occurs - * - * @since 1.2 - */ - public void setTimeToLive(int ttl) throws IOException - { - if (isClosed()) - throw new SocketException("socket is closed"); - - if (ttl <= 0 || ttl > 255) - throw new IllegalArgumentException("Invalid ttl: " + ttl); - - getImpl().setTimeToLive(ttl); - } - - /** - * Joins the specified multicast group. - * - * @param mcastaddr The address of the group to join - * - * @exception IOException If an error occurs - * @exception SecurityException If a security manager exists and its - * checkMulticast method doesn't allow the operation - */ - public void joinGroup(InetAddress mcastaddr) throws IOException - { - if (isClosed()) - throw new SocketException("socket is closed"); - - if (! mcastaddr.isMulticastAddress()) - throw new IOException("Not a Multicast address"); - - SecurityManager s = System.getSecurityManager(); - if (s != null) - s.checkMulticast(mcastaddr); - - getImpl().join(mcastaddr); - } - - /** - * Leaves the specified multicast group - * - * @param mcastaddr The address of the group to leave - * - * @exception IOException If an error occurs - * @exception SecurityException If a security manager exists and its - * checkMulticast method doesn't allow the operation - */ - public void leaveGroup(InetAddress mcastaddr) throws IOException - { - if (isClosed()) - throw new SocketException("socket is closed"); - - if (! mcastaddr.isMulticastAddress()) - throw new IOException("Not a Multicast address"); - - SecurityManager s = System.getSecurityManager(); - if (s != null) - s.checkMulticast(mcastaddr); - - getImpl().leave(mcastaddr); - } - - /** - * Joins the specified mulitcast group on a specified interface. - * - * @param mcastaddr The multicast address to join - * @param netIf The local network interface to receive the multicast - * messages on or null to defer the interface set by #setInterface or - * #setNetworkInterface - * - * @exception IOException If an error occurs - * @exception IllegalArgumentException If address type is not supported - * @exception SecurityException If a security manager exists and its - * checkMulticast method doesn't allow the operation - * - * @see MulticastSocket#setInterface(InetAddress addr) - * @see MulticastSocket#setNetworkInterface(NetworkInterface netIf) - * - * @since 1.4 - */ - public void joinGroup(SocketAddress mcastaddr, NetworkInterface netIf) - throws IOException - { - if (isClosed()) - throw new SocketException("socket is closed"); - - if (! (mcastaddr instanceof InetSocketAddress)) - throw new IllegalArgumentException("SocketAddress type not supported"); - - InetSocketAddress tmp = (InetSocketAddress) mcastaddr; - - if (! tmp.getAddress().isMulticastAddress()) - throw new IOException("Not a Multicast address"); - - SecurityManager s = System.getSecurityManager(); - if (s != null) - s.checkMulticast(tmp.getAddress()); - - getImpl().joinGroup(mcastaddr, netIf); - } - - /** - * Leaves the specified mulitcast group on a specified interface. - * - * @param mcastaddr The multicast address to leave - * @param netIf The local networki interface or null to defer to the - * interface set by setInterface or setNetworkInterface - * - * @exception IOException If an error occurs - * @exception IllegalArgumentException If address type is not supported - * @exception SecurityException If a security manager exists and its - * checkMulticast method doesn't allow the operation - * - * @see MulticastSocket#setInterface(InetAddress addr) - * @see MulticastSocket#setNetworkInterface(NetworkInterface netIf) - * - * @since 1.4 - */ - public void leaveGroup(SocketAddress mcastaddr, NetworkInterface netIf) - throws IOException - { - if (isClosed()) - throw new SocketException("socket is closed"); - - InetSocketAddress tmp = (InetSocketAddress) mcastaddr; - - if (! tmp.getAddress().isMulticastAddress()) - throw new IOException("Not a Multicast address"); - - SecurityManager s = System.getSecurityManager(); - if (s != null) - s.checkMulticast(tmp.getAddress()); - - getImpl().leaveGroup(mcastaddr, netIf); - } - - /** - * Sends a packet of data to a multicast address with a TTL that is - * different from the default TTL on this socket. The default TTL for - * the socket is not changed. - * - * @param packet The packet of data to send - * @param ttl The TTL for this packet - * - * @exception IOException If an error occurs - * @exception SecurityException If a security manager exists and its - * checkConnect or checkMulticast method doesn't allow the operation - * - * @deprecated - */ - public synchronized void send(DatagramPacket packet, byte ttl) - throws IOException - { - if (isClosed()) - throw new SocketException("socket is closed"); - - SecurityManager s = System.getSecurityManager(); - if (s != null) - { - InetAddress addr = packet.getAddress(); - if (addr.isMulticastAddress()) - s.checkPermission(new SocketPermission(addr.getHostName() - + packet.getPort(), - "accept,connect")); - else - s.checkConnect(addr.getHostAddress(), packet.getPort()); - } - - int oldttl = getImpl().getTimeToLive(); - getImpl().setTimeToLive(((int) ttl) & 0xFF); - getImpl().send(packet); - getImpl().setTimeToLive(oldttl); - } -} diff --git a/libjava/java/net/NetPermission.java b/libjava/java/net/NetPermission.java deleted file mode 100644 index cabe54e065c..00000000000 --- a/libjava/java/net/NetPermission.java +++ /dev/null @@ -1,90 +0,0 @@ -/* NetPermission.java -- A class for basic miscellaneous network permission - Copyright (C) 1998, 2000, 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.net; - -import java.security.BasicPermission; - - -/** - * This class is used to model miscellaneous network permissions. It is - * a subclass of <code>BasicPermission</code>. This means that it models a - * "boolean" permission. One that you either have or do not have. Thus - * there is no permitted action list associated with this object. - * - * The following permission names are defined for this class: - * - * <ul> - * <li>setDefaultAuthenticator - Grants the ability to install a facility - * to collect username and password information when requested by a - * web site or proxy server.</li> - * <li>requestPasswordAuthentication - Grants the ability to ask the - * authentication facility for the user's password.</li> - * <li>specifyStreamHandler - Grants the permission to specify the - * stream handler class used when loading from a URL.</li> - * </ul> - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public final class NetPermission extends BasicPermission -{ - static final long serialVersionUID = -8343910153355041693L; - - /** - * Initializes a new instance of <code>NetPermission</code> with the - * specified name. - * - * @param name The name of this permission. - */ - public NetPermission(String name) - { - super(name); - } - - /** - * Initializes a new instance of <code>NetPermission</code> with the - * specified name and perms. Note that the perms field is irrelevant and is - * ignored. This constructor should never need to be used. - * - * @param name The name of this permission - * @param perms The permitted actions of this permission (ignored) - */ - public NetPermission(String name, String perms) - { - super(name); - } -} diff --git a/libjava/java/net/NetworkInterface.java b/libjava/java/net/NetworkInterface.java deleted file mode 100644 index eccd2dac9fb..00000000000 --- a/libjava/java/net/NetworkInterface.java +++ /dev/null @@ -1,259 +0,0 @@ -/* NetworkInterface.java -- - Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.net; - -import java.util.Enumeration; -import java.util.Vector; - -/** - * This class models a network interface on the host computer. A network - * interface contains a name (typically associated with a specific - * hardware adapter) and a list of addresses that are bound to it. - * For example, an ethernet interface may be named "eth0" and have the - * address 192.168.1.101 assigned to it. - * - * @author Michael Koch (konqueror@gmx.de) - * @since 1.4 - */ -public final class NetworkInterface -{ - private String name; - private Vector inetAddresses; - - NetworkInterface(String name, InetAddress address) - { - this.name = name; - this.inetAddresses = new Vector(1, 1); - this.inetAddresses.add(address); - } - - NetworkInterface(String name, InetAddress[] addresses) - { - this.name = name; - this.inetAddresses = new Vector(addresses.length, 1); - - for (int i = 0; i < addresses.length; i++) - this.inetAddresses.add(addresses[i]); - } - - /** - * Returns the name of the network interface - * - * @return The name of the interface. - */ - public String getName() - { - return name; - } - - /** - * Returns all available addresses of the network interface - * - * If a @see SecurityManager is available all addresses are checked - * with @see SecurityManager::checkConnect() if they are available. - * Only <code>InetAddresses</code> are returned where the security manager - * doesn't throw an exception. - * - * @return An enumeration of all addresses. - */ - public Enumeration getInetAddresses() - { - SecurityManager s = System.getSecurityManager(); - - if (s == null) - return inetAddresses.elements(); - - Vector tmpInetAddresses = new Vector(1, 1); - - for (Enumeration addresses = inetAddresses.elements(); - addresses.hasMoreElements();) - { - InetAddress addr = (InetAddress) addresses.nextElement(); - try - { - s.checkConnect(addr.getHostAddress(), 58000); - tmpInetAddresses.add(addr); - } - catch (SecurityException e) - { - // Ignore. - } - } - - return tmpInetAddresses.elements(); - } - - /** - * Returns the display name of the interface - * - * @return The display name of the interface - */ - public String getDisplayName() - { - return name; - } - - /** - * Returns an network interface by name - * - * @param name The name of the interface to return - * - * @return a <code>NetworkInterface</code> object representing the interface, - * or null if there is no interface with that name. - * - * @exception SocketException If an error occurs - * @exception NullPointerException If the specified name is null - */ - public static NetworkInterface getByName(String name) - throws SocketException - { - Vector networkInterfaces = VMNetworkInterface.getInterfaces(); - - for (Enumeration e = networkInterfaces.elements(); e.hasMoreElements();) - { - NetworkInterface tmp = (NetworkInterface) e.nextElement(); - - if (name.equals(tmp.getName())) - return tmp; - } - - // No interface with the given name found. - return null; - } - - /** - * Return a network interface by its address - * - * @param addr The address of the interface to return - * - * @return the interface, or <code>null</code> if none found - * - * @exception SocketException If an error occurs - * @exception NullPointerException If the specified addess is null - */ - public static NetworkInterface getByInetAddress(InetAddress addr) - throws SocketException - { - Vector networkInterfaces = VMNetworkInterface.getInterfaces(); - - for (Enumeration interfaces = networkInterfaces.elements(); - interfaces.hasMoreElements();) - { - NetworkInterface tmp = (NetworkInterface) interfaces.nextElement(); - - for (Enumeration addresses = tmp.inetAddresses.elements(); - addresses.hasMoreElements();) - { - if (addr.equals((InetAddress) addresses.nextElement())) - return tmp; - } - } - - throw new SocketException("no network interface is bound to such an IP address"); - } - - /** - * Return an <code>Enumeration</code> of all available network interfaces - * - * @return all interfaces - * - * @exception SocketException If an error occurs - */ - public static Enumeration getNetworkInterfaces() throws SocketException - { - Vector networkInterfaces = VMNetworkInterface.getInterfaces(); - - if (networkInterfaces.isEmpty()) - return null; - - return networkInterfaces.elements(); - } - - /** - * Checks if the current instance is equal to obj - * - * @param obj The object to compare with - * - * @return <code>true</code> if equal, <code>false</code> otherwise - */ - public boolean equals(Object obj) - { - if (! (obj instanceof NetworkInterface)) - return false; - - NetworkInterface tmp = (NetworkInterface) obj; - - return (name.equals(tmp.name) && inetAddresses.equals(tmp.inetAddresses)); - } - - /** - * Returns the hashcode of the current instance - * - * @return the hashcode - */ - public int hashCode() - { - // FIXME: hash correctly - return name.hashCode() + inetAddresses.hashCode(); - } - - /** - * Returns a string representation of the interface - * - * @return the string - */ - public String toString() - { - // FIXME: check if this is correct - String result; - String separator = System.getProperty("line.separator"); - - result = - "name: " + getDisplayName() + " (" + getName() + ") addresses:" - + separator; - - for (Enumeration e = inetAddresses.elements(); e.hasMoreElements();) - { - InetAddress address = (InetAddress) e.nextElement(); - result += address.toString() + ";" + separator; - } - - return result; - } -} diff --git a/libjava/java/net/NoRouteToHostException.java b/libjava/java/net/NoRouteToHostException.java deleted file mode 100644 index 48c3a8e604e..00000000000 --- a/libjava/java/net/NoRouteToHostException.java +++ /dev/null @@ -1,74 +0,0 @@ -/* NoRouteToHostException.java -- Cannot connect to a host - Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.net; - - -/** - * This exception indicates that there is no TCP/IP route to the requested - * host. This is often due to a misconfigured routing table. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Warren Levy (warrenl@cygnus.com) - * @since 1.1 - * @status updated to 1.4 - */ -public class NoRouteToHostException extends SocketException -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = -1897550894873493790L; - - /** - * Create an instance without a descriptive error message. - */ - public NoRouteToHostException() - { - } - - /** - * Create an instance with a descriptive error message, such as the text - * from strerror(3). - * - * @param message a message describing the error that occurred - */ - public NoRouteToHostException(String message) - { - super(message); - } -} // class NoRouteToHostException diff --git a/libjava/java/net/PasswordAuthentication.java b/libjava/java/net/PasswordAuthentication.java deleted file mode 100644 index 1d4ec89611d..00000000000 --- a/libjava/java/net/PasswordAuthentication.java +++ /dev/null @@ -1,92 +0,0 @@ -/* PasswordAuthentication.java -- Container class for username/password pairs - Copyright (C) 1998, 2000, 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.net; - - -/** - * This class serves a container for username/password pairs. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * - * @since 1.2 - */ -public final class PasswordAuthentication -{ - /** - * The username - */ - private String username; - - /** - * The password - */ - private char[] password; - - /** - * Creates a new <code>PasswordAuthentication</code> object from the - * specified username and password. - * - * @param username The username for this object - * @param password The password for this object - */ - public PasswordAuthentication(String username, char[] password) - { - this.username = username; - this.password = password; - } - - /** - * Returns the username associated with this object - * - * @return The username - */ - public String getUserName() - { - return username; - } - - /** - * Returns the password associated with this object - * - * @return The password - */ - public char[] getPassword() - { - return password; - } -} diff --git a/libjava/java/net/PortUnreachableException.java b/libjava/java/net/PortUnreachableException.java deleted file mode 100644 index 49a8c9ea103..00000000000 --- a/libjava/java/net/PortUnreachableException.java +++ /dev/null @@ -1,72 +0,0 @@ -/* PortUnreachableException.java -- received an ICMP port unreachable datagram - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.net; - - -/** - * This exception signals that an ICMP port unreachable datagram has been - * received. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.4 - * @status updated to 1.4 - */ -public class PortUnreachableException extends SocketException -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = 8462541992376507323L; - - /** - * Create a new instance without a descriptive error message. - */ - public PortUnreachableException() - { - } - - /** - * Create a new instance with a descriptive error message. - * - * @param message a message describing the error that occurred - */ - public PortUnreachableException(String message) - { - super(message); - } -} // class PortUnreachableException diff --git a/libjava/java/net/ProtocolException.java b/libjava/java/net/ProtocolException.java deleted file mode 100644 index 27718a9793d..00000000000 --- a/libjava/java/net/ProtocolException.java +++ /dev/null @@ -1,75 +0,0 @@ -/* ProtocolException.java -- a low level protocol error occurred - Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.net; - -import java.io.IOException; - - -/** - * This exception indicates that some sort of low level protocol - * exception occurred. Look in the descriptive message (if any) for - * details on what went wrong. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Warren Levy (warrenl@cygnus.com) - * @status updated to 1.4 - */ -public class ProtocolException extends IOException -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = -6098449442062388080L; - - /** - * Create a new instance without a descriptive error message. - */ - public ProtocolException() - { - } - - /** - * Create a new instance with a descriptive error message. - * - * @param message a message describing the error that occurred - */ - public ProtocolException(String message) - { - super(message); - } -} // class ProtocolException diff --git a/libjava/java/net/Socket.java b/libjava/java/net/Socket.java deleted file mode 100644 index 9432a6be1d8..00000000000 --- a/libjava/java/net/Socket.java +++ /dev/null @@ -1,1284 +0,0 @@ -/* Socket.java -- Client socket implementation - Copyright (C) 1998, 1999, 2000, 2002, 2003, 2004 - Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.net; - -import gnu.java.net.PlainSocketImpl; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.nio.channels.IllegalBlockingModeException; -import java.nio.channels.SocketChannel; - - -/* Written using on-line Java Platform 1.2 API Specification. - * Status: I believe all methods are implemented. - */ - -/** - * This class models a client site socket. A socket is a TCP/IP endpoint - * for network communications conceptually similar to a file handle. - * <p> - * This class does not actually do any work. Instead, it redirects all of - * its calls to a socket implementation object which implements the - * <code>SocketImpl</code> interface. The implementation class is - * instantiated by factory class that implements the - * <code>SocketImplFactory interface</code>. A default - * factory is provided, however the factory may be set by a call to - * the <code>setSocketImplFactory</code> method. Note that this may only be - * done once per virtual machine. If a subsequent attempt is made to set the - * factory, a <code>SocketException</code> will be thrown. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Per Bothner (bothner@cygnus.com) - */ -public class Socket -{ - /** - * This is the user SocketImplFactory for this class. If this variable is - * null, a default factory is used. - */ - static SocketImplFactory factory; - - /** - * The implementation object to which calls are redirected - */ - // package-private because ServerSocket.implAccept() needs to access it. - SocketImpl impl; - - /** - * True if socket implementation was created by calling their - * create() method. - */ - // package-private because ServerSocket.implAccept() needs to access it. - boolean implCreated; - - /** - * True if the socket is bound. - */ - private boolean bound; - - /** - * True if input is shutdown. - */ - private boolean inputShutdown; - - /** - * True if output is shutdown. - */ - private boolean outputShutdown; - - /** - * Initializes a new instance of <code>Socket</code> object without - * connecting to a remote host. This useful for subclasses of socket that - * might want this behavior. - * - * @specnote This constructor is public since JDK 1.4 - * @since 1.1 - */ - public Socket() - { - if (factory != null) - impl = factory.createSocketImpl(); - else - impl = new PlainSocketImpl(); - } - - /** - * Initializes a new instance of <code>Socket</code> object without - * connecting to a remote host. This is useful for subclasses of socket - * that might want this behavior. - * <p> - * Additionally, this socket will be created using the supplied - * implementation class instead the default class or one returned by a - * factory. If this value is <code>null</code>, the default Socket - * implementation is used. - * - * @param impl The <code>SocketImpl</code> to use for this - * <code>Socket</code> - * - * @exception SocketException If an error occurs - * - * @since 1.1 - */ - protected Socket(SocketImpl impl) throws SocketException - { - if (impl == null) - this.impl = new PlainSocketImpl(); - else - this.impl = impl; - } - - /** - * Initializes a new instance of <code>Socket</code> and connects to the - * hostname and port specified as arguments. - * - * @param host The name of the host to connect to - * @param port The port number to connect to - * - * @exception UnknownHostException If the hostname cannot be resolved to a - * network address. - * @exception IOException If an error occurs - * @exception SecurityException If a security manager exists and its - * checkConnect method doesn't allow the operation - */ - public Socket(String host, int port) - throws UnknownHostException, IOException - { - this(InetAddress.getByName(host), port, null, 0, true); - } - - /** - * Initializes a new instance of <code>Socket</code> and connects to the - * address and port number specified as arguments. - * - * @param address The address to connect to - * @param port The port number to connect to - * - * @exception IOException If an error occurs - * @exception SecurityException If a security manager exists and its - * checkConnect method doesn't allow the operation - */ - public Socket(InetAddress address, int port) throws IOException - { - this(address, port, null, 0, true); - } - - /** - * Initializes a new instance of <code>Socket</code> that connects to the - * named host on the specified port and binds to the specified local address - * and port. - * - * @param host The name of the remote host to connect to. - * @param port The remote port to connect to. - * @param localAddr The local address to bind to. - * @param localPort The local port to bind to. - * - * @exception SecurityException If the <code>SecurityManager</code> - * exists and does not allow a connection to the specified host/port or - * binding to the specified local host/port. - * @exception IOException If a connection error occurs. - * - * @since 1.1 - */ - public Socket(String host, int port, InetAddress localAddr, int localPort) - throws IOException - { - this(InetAddress.getByName(host), port, localAddr, localPort, true); - } - - /** - * Initializes a new instance of <code>Socket</code> and connects to the - * address and port number specified as arguments, plus binds to the - * specified local address and port. - * - * @param address The remote address to connect to - * @param port The remote port to connect to - * @param localAddr The local address to connect to - * @param localPort The local port to connect to - * - * @exception IOException If an error occurs - * @exception SecurityException If a security manager exists and its - * checkConnect method doesn't allow the operation - * - * @since 1.1 - */ - public Socket(InetAddress address, int port, InetAddress localAddr, - int localPort) throws IOException - { - this(address, port, localAddr, localPort, true); - } - - /** - * Initializes a new instance of <code>Socket</code> and connects to the - * hostname and port specified as arguments. If the stream argument is set - * to <code>true</code>, then a stream socket is created. If it is - * <code>false</code>, a datagram socket is created. - * - * @param host The name of the host to connect to - * @param port The port to connect to - * @param stream <code>true</code> for a stream socket, <code>false</code> - * for a datagram socket - * - * @exception IOException If an error occurs - * @exception SecurityException If a security manager exists and its - * checkConnect method doesn't allow the operation - * - * @deprecated Use the <code>DatagramSocket</code> class to create - * datagram oriented sockets. - */ - public Socket(String host, int port, boolean stream) - throws IOException - { - this(InetAddress.getByName(host), port, null, 0, stream); - } - - /** - * Initializes a new instance of <code>Socket</code> and connects to the - * address and port number specified as arguments. If the stream param is - * <code>true</code>, a stream socket will be created, otherwise a datagram - * socket is created. - * - * @param host The address to connect to - * @param port The port number to connect to - * @param stream <code>true</code> to create a stream socket, - * <code>false</code> to create a datagram socket. - * - * @exception IOException If an error occurs - * @exception SecurityException If a security manager exists and its - * checkConnect method doesn't allow the operation - * - * @deprecated Use the <code>DatagramSocket</code> class to create - * datagram oriented sockets. - */ - public Socket(InetAddress host, int port, boolean stream) - throws IOException - { - this(host, port, null, 0, stream); - } - - /** - * This constructor is where the real work takes place. Connect to the - * specified address and port. Use default local values if not specified, - * otherwise use the local host and port passed in. Create as stream or - * datagram based on "stream" argument. - * <p> - * - * @param raddr The remote address to connect to - * @param rport The remote port to connect to - * @param laddr The local address to connect to - * @param lport The local port to connect to - * @param stream true for a stream socket, false for a datagram socket - * - * @exception IOException If an error occurs - * @exception SecurityException If a security manager exists and its - * checkConnect method doesn't allow the operation - */ - private Socket(InetAddress raddr, int rport, InetAddress laddr, int lport, - boolean stream) throws IOException - { - this(); - - SecurityManager sm = System.getSecurityManager(); - if (sm != null) - sm.checkConnect(raddr.getHostName(), rport); - - // bind socket - SocketAddress bindaddr = - laddr == null ? null : new InetSocketAddress(laddr, lport); - bind(bindaddr); - - // connect socket - connect(new InetSocketAddress(raddr, rport)); - - // FIXME: JCL p. 1586 says if localPort is unspecified, bind to any port, - // i.e. '0' and if localAddr is unspecified, use getLocalAddress() as - // that default. JDK 1.2 doc infers not to do a bind. - } - - private SocketImpl getImpl() throws SocketException - { - try - { - if (! implCreated) - { - impl.create(true); - implCreated = true; - } - } - catch (IOException e) - { - throw new SocketException(e.getMessage()); - } - - return impl; - } - - /** - * Binds the socket to the givent local address/port - * - * @param bindpoint The address/port to bind to - * - * @exception IOException If an error occurs - * @exception SecurityException If a security manager exists and its - * checkConnect method doesn't allow the operation - * @exception IllegalArgumentException If the address type is not supported - * - * @since 1.4 - */ - public void bind(SocketAddress bindpoint) throws IOException - { - if (isClosed()) - throw new SocketException("socket is closed"); - - // XXX: JDK 1.4.1 API documentation says that if bindpoint is null the - // socket will be bound to an ephemeral port and a valid local address. - if (bindpoint == null) - bindpoint = new InetSocketAddress(InetAddress.ANY_IF, 0); - - if (! (bindpoint instanceof InetSocketAddress)) - throw new IllegalArgumentException(); - - InetSocketAddress tmp = (InetSocketAddress) bindpoint; - - // bind to address/port - try - { - getImpl().bind(tmp.getAddress(), tmp.getPort()); - bound = true; - } - catch (IOException exception) - { - close(); - throw exception; - } - catch (RuntimeException exception) - { - close(); - throw exception; - } - catch (Error error) - { - close(); - throw error; - } - } - - /** - * Connects the socket with a remote address. - * - * @param endpoint The address to connect to - * - * @exception IOException If an error occurs - * @exception IllegalArgumentException If the addess type is not supported - * @exception IllegalBlockingModeException If this socket has an associated - * channel, and the channel is in non-blocking mode - * - * @since 1.4 - */ - public void connect(SocketAddress endpoint) throws IOException - { - connect(endpoint, 0); - } - - /** - * Connects the socket with a remote address. A timeout of zero is - * interpreted as an infinite timeout. The connection will then block - * until established or an error occurs. - * - * @param endpoint The address to connect to - * @param timeout The length of the timeout in milliseconds, or - * 0 to indicate no timeout. - * - * @exception IOException If an error occurs - * @exception IllegalArgumentException If the address type is not supported - * @exception IllegalBlockingModeException If this socket has an associated - * channel, and the channel is in non-blocking mode - * @exception SocketTimeoutException If the timeout is reached - * - * @since 1.4 - */ - public void connect(SocketAddress endpoint, int timeout) - throws IOException - { - if (isClosed()) - throw new SocketException("socket is closed"); - - if (! (endpoint instanceof InetSocketAddress)) - throw new IllegalArgumentException("unsupported address type"); - - // The Sun spec says that if we have an associated channel and - // it is in non-blocking mode, we throw an IllegalBlockingModeException. - // However, in our implementation if the channel itself initiated this - // operation, then we must honor it regardless of its blocking mode. - if (getChannel() != null && ! getChannel().isBlocking() - && ! ((PlainSocketImpl) getImpl()).isInChannelOperation()) - throw new IllegalBlockingModeException(); - - if (! isBound()) - bind(null); - - try - { - getImpl().connect(endpoint, timeout); - } - catch (IOException exception) - { - close(); - throw exception; - } - catch (RuntimeException exception) - { - close(); - throw exception; - } - catch (Error error) - { - close(); - throw error; - } - } - - /** - * Returns the address of the remote end of the socket. If this socket - * is not connected, then <code>null</code> is returned. - * - * @return The remote address this socket is connected to - */ - public InetAddress getInetAddress() - { - if (! isConnected()) - return null; - - try - { - return getImpl().getInetAddress(); - } - catch (SocketException e) - { - // This cannot happen as we are connected. - } - - return null; - } - - /** - * Returns the local address to which this socket is bound. If this socket - * is not connected, then a wildcard address, for which - * @see isAnyLocalAddress() is <code>true</code>, is returned. - * - * @return The local address - * - * @since 1.1 - */ - public InetAddress getLocalAddress() - { - if (! isBound()) - return InetAddress.ANY_IF; - - InetAddress addr = null; - - try - { - addr = (InetAddress) getImpl().getOption(SocketOptions.SO_BINDADDR); - } - catch (SocketException e) - { - // (hopefully) shouldn't happen - // throw new java.lang.InternalError - // ("Error in PlainSocketImpl.getOption"); - return null; - } - - // FIXME: According to libgcj, checkConnect() is supposed to be called - // before performing this operation. Problems: 1) We don't have the - // addr until after we do it, so we do a post check. 2). The docs I - // see don't require this in the Socket case, only DatagramSocket, but - // we'll assume they mean both. - SecurityManager sm = System.getSecurityManager(); - if (sm != null) - sm.checkConnect(addr.getHostName(), getLocalPort()); - - return addr; - } - - /** - * Returns the port number of the remote end of the socket connection. If - * this socket is not connected, then 0 is returned. - * - * @return The remote port this socket is connected to - */ - public int getPort() - { - if (! isConnected()) - return 0; - - try - { - return getImpl().getPort(); - } - catch (SocketException e) - { - // This cannot happen as we are connected. - } - - return 0; - } - - /** - * Returns the local port number to which this socket is bound. If this - * socket is not connected, then -1 is returned. - * - * @return The local port - */ - public int getLocalPort() - { - if (! isBound()) - return -1; - - try - { - if (getImpl() != null) - return getImpl().getLocalPort(); - } - catch (SocketException e) - { - // This cannot happen as we are bound. - } - - return -1; - } - - /** - * Returns local socket address. - * - * @return the local socket address, null if not bound - * - * @since 1.4 - */ - public SocketAddress getLocalSocketAddress() - { - if (! isBound()) - return null; - - InetAddress addr = getLocalAddress(); - - try - { - return new InetSocketAddress(addr, getImpl().getLocalPort()); - } - catch (SocketException e) - { - // This cannot happen as we are bound. - return null; - } - } - - /** - * Returns the remote socket address. - * - * @return the remote socket address, null of not connected - * - * @since 1.4 - */ - public SocketAddress getRemoteSocketAddress() - { - if (! isConnected()) - return null; - - try - { - return new InetSocketAddress(getImpl().getInetAddress(), - getImpl().getPort()); - } - catch (SocketException e) - { - // This cannot happen as we are connected. - return null; - } - } - - /** - * Returns an InputStream for reading from this socket. - * - * @return The InputStream object - * - * @exception IOException If an error occurs or Socket is not connected - */ - public InputStream getInputStream() throws IOException - { - if (isClosed()) - throw new SocketException("socket is closed"); - - if (! isConnected()) - throw new IOException("not connected"); - - return getImpl().getInputStream(); - } - - /** - * Returns an OutputStream for writing to this socket. - * - * @return The OutputStream object - * - * @exception IOException If an error occurs or Socket is not connected - */ - public OutputStream getOutputStream() throws IOException - { - if (isClosed()) - throw new SocketException("socket is closed"); - - if (! isConnected()) - throw new IOException("not connected"); - - return getImpl().getOutputStream(); - } - - /** - * Sets the TCP_NODELAY option on the socket. - * - * @param on true to enable, false to disable - * - * @exception SocketException If an error occurs or Socket is not connected - * - * @since 1.1 - */ - public void setTcpNoDelay(boolean on) throws SocketException - { - if (isClosed()) - throw new SocketException("socket is closed"); - - getImpl().setOption(SocketOptions.TCP_NODELAY, Boolean.valueOf(on)); - } - - /** - * Tests whether or not the TCP_NODELAY option is set on the socket. - * Returns true if enabled, false if disabled. When on it disables the - * Nagle algorithm which means that packets are always send immediatly and - * never merged together to reduce network trafic. - * - * @return Whether or not TCP_NODELAY is set - * - * @exception SocketException If an error occurs or Socket not connected - * - * @since 1.1 - */ - public boolean getTcpNoDelay() throws SocketException - { - if (isClosed()) - throw new SocketException("socket is closed"); - - Object on = getImpl().getOption(SocketOptions.TCP_NODELAY); - - if (on instanceof Boolean) - return (((Boolean) on).booleanValue()); - else - throw new SocketException("Internal Error"); - } - - /** - * Sets the value of the SO_LINGER option on the socket. If the - * SO_LINGER option is set on a socket and there is still data waiting to - * be sent when the socket is closed, then the close operation will block - * until either that data is delivered or until the timeout period - * expires. The linger interval is specified in hundreths of a second - * (platform specific?) - * - * @param on true to enable SO_LINGER, false to disable - * @param linger The SO_LINGER timeout in hundreths of a second or -1 if - * SO_LINGER not set. - * - * @exception SocketException If an error occurs or Socket not connected - * @exception IllegalArgumentException If linger is negative - * - * @since 1.1 - */ - public void setSoLinger(boolean on, int linger) throws SocketException - { - if (isClosed()) - throw new SocketException("socket is closed"); - - if (on) - { - if (linger < 0) - throw new IllegalArgumentException("SO_LINGER must be >= 0"); - - if (linger > 65535) - linger = 65535; - - getImpl().setOption(SocketOptions.SO_LINGER, new Integer(linger)); - } - else - getImpl().setOption(SocketOptions.SO_LINGER, Boolean.valueOf(false)); - } - - /** - * Returns the value of the SO_LINGER option on the socket. If the - * SO_LINGER option is set on a socket and there is still data waiting to - * be sent when the socket is closed, then the close operation will block - * until either that data is delivered or until the timeout period - * expires. This method either returns the timeouts (in hundredths of - * of a second (platform specific?)) if SO_LINGER is set, or -1 if - * SO_LINGER is not set. - * - * @return The SO_LINGER timeout in hundreths of a second or -1 - * if SO_LINGER not set - * - * @exception SocketException If an error occurs or Socket is not connected - * - * @since 1.1 - */ - public int getSoLinger() throws SocketException - { - if (isClosed()) - throw new SocketException("socket is closed"); - - Object linger = getImpl().getOption(SocketOptions.SO_LINGER); - - if (linger instanceof Integer) - return (((Integer) linger).intValue()); - else - return -1; - } - - /** - * Sends urgent data through the socket - * - * @param data The data to send. - * Only the lowest eight bits of data are sent - * - * @exception IOException If an error occurs - * - * @since 1.4 - */ - public void sendUrgentData(int data) throws IOException - { - if (isClosed()) - throw new SocketException("socket is closed"); - - getImpl().sendUrgentData(data); - } - - /** - * Enables/disables the SO_OOBINLINE option - * - * @param on True if SO_OOBLINE should be enabled - * - * @exception SocketException If an error occurs - * - * @since 1.4 - */ - public void setOOBInline(boolean on) throws SocketException - { - if (isClosed()) - throw new SocketException("socket is closed"); - - getImpl().setOption(SocketOptions.SO_OOBINLINE, Boolean.valueOf(on)); - } - - /** - * Returns the current setting of the SO_OOBINLINE option for this socket - * - * @return True if SO_OOBINLINE is set, false otherwise. - * - * @exception SocketException If an error occurs - * - * @since 1.4 - */ - public boolean getOOBInline() throws SocketException - { - if (isClosed()) - throw new SocketException("socket is closed"); - - Object buf = getImpl().getOption(SocketOptions.SO_OOBINLINE); - - if (buf instanceof Boolean) - return (((Boolean) buf).booleanValue()); - else - throw new SocketException("Internal Error: Unexpected type"); - } - - /** - * Sets the value of the SO_TIMEOUT option on the socket. If this value - * is set, and an read/write is performed that does not complete within - * the timeout period, a short count is returned (or an EWOULDBLOCK signal - * would be sent in Unix if no data had been read). A value of 0 for - * this option implies that there is no timeout (ie, operations will - * block forever). On systems that have separate read and write timeout - * values, this method returns the read timeout. This - * value is in milliseconds. - * - * @param timeout The length of the timeout in milliseconds, or - * 0 to indicate no timeout. - * - * @exception SocketException If an error occurs or Socket not connected - * - * @since 1.1 - */ - public synchronized void setSoTimeout(int timeout) throws SocketException - { - if (isClosed()) - throw new SocketException("socket is closed"); - - if (timeout < 0) - throw new IllegalArgumentException("SO_TIMEOUT value must be >= 0"); - - getImpl().setOption(SocketOptions.SO_TIMEOUT, new Integer(timeout)); - } - - /** - * Returns the value of the SO_TIMEOUT option on the socket. If this value - * is set, and an read/write is performed that does not complete within - * the timeout period, a short count is returned (or an EWOULDBLOCK signal - * would be sent in Unix if no data had been read). A value of 0 for - * this option implies that there is no timeout (ie, operations will - * block forever). On systems that have separate read and write timeout - * values, this method returns the read timeout. This - * value is in thousandths of a second (implementation specific?). - * - * @return The length of the timeout in thousandth's of a second or 0 - * if not set - * - * @exception SocketException If an error occurs or Socket not connected - * - * @since 1.1 - */ - public synchronized int getSoTimeout() throws SocketException - { - if (isClosed()) - throw new SocketException("socket is closed"); - - Object timeout = getImpl().getOption(SocketOptions.SO_TIMEOUT); - if (timeout instanceof Integer) - return (((Integer) timeout).intValue()); - else - return 0; - } - - /** - * This method sets the value for the system level socket option - * SO_SNDBUF to the specified value. Note that valid values for this - * option are specific to a given operating system. - * - * @param size The new send buffer size. - * - * @exception SocketException If an error occurs or Socket not connected - * @exception IllegalArgumentException If size is 0 or negative - * - * @since 1.2 - */ - public void setSendBufferSize(int size) throws SocketException - { - if (isClosed()) - throw new SocketException("socket is closed"); - - if (size <= 0) - throw new IllegalArgumentException("SO_SNDBUF value must be > 0"); - - getImpl().setOption(SocketOptions.SO_SNDBUF, new Integer(size)); - } - - /** - * This method returns the value of the system level socket option - * SO_SNDBUF, which is used by the operating system to tune buffer - * sizes for data transfers. - * - * @return The send buffer size. - * - * @exception SocketException If an error occurs or socket not connected - * - * @since 1.2 - */ - public int getSendBufferSize() throws SocketException - { - if (isClosed()) - throw new SocketException("socket is closed"); - - Object buf = getImpl().getOption(SocketOptions.SO_SNDBUF); - - if (buf instanceof Integer) - return (((Integer) buf).intValue()); - else - throw new SocketException("Internal Error: Unexpected type"); - } - - /** - * This method sets the value for the system level socket option - * SO_RCVBUF to the specified value. Note that valid values for this - * option are specific to a given operating system. - * - * @param size The new receive buffer size. - * - * @exception SocketException If an error occurs or Socket is not connected - * @exception IllegalArgumentException If size is 0 or negative - * - * @since 1.2 - */ - public void setReceiveBufferSize(int size) throws SocketException - { - if (isClosed()) - throw new SocketException("socket is closed"); - - if (size <= 0) - throw new IllegalArgumentException("SO_RCVBUF value must be > 0"); - - getImpl().setOption(SocketOptions.SO_RCVBUF, new Integer(size)); - } - - /** - * This method returns the value of the system level socket option - * SO_RCVBUF, which is used by the operating system to tune buffer - * sizes for data transfers. - * - * @return The receive buffer size. - * - * @exception SocketException If an error occurs or Socket is not connected - * - * @since 1.2 - */ - public int getReceiveBufferSize() throws SocketException - { - if (isClosed()) - throw new SocketException("socket is closed"); - - Object buf = getImpl().getOption(SocketOptions.SO_RCVBUF); - - if (buf instanceof Integer) - return (((Integer) buf).intValue()); - else - throw new SocketException("Internal Error: Unexpected type"); - } - - /** - * This method sets the value for the socket level socket option - * SO_KEEPALIVE. - * - * @param on True if SO_KEEPALIVE should be enabled - * - * @exception SocketException If an error occurs or Socket is not connected - * - * @since 1.3 - */ - public void setKeepAlive(boolean on) throws SocketException - { - if (isClosed()) - throw new SocketException("socket is closed"); - - getImpl().setOption(SocketOptions.SO_KEEPALIVE, Boolean.valueOf(on)); - } - - /** - * This method returns the value of the socket level socket option - * SO_KEEPALIVE. - * - * @return The setting - * - * @exception SocketException If an error occurs or Socket is not connected - * - * @since 1.3 - */ - public boolean getKeepAlive() throws SocketException - { - if (isClosed()) - throw new SocketException("socket is closed"); - - Object buf = getImpl().getOption(SocketOptions.SO_KEEPALIVE); - - if (buf instanceof Boolean) - return (((Boolean) buf).booleanValue()); - else - throw new SocketException("Internal Error: Unexpected type"); - } - - /** - * Closes the socket. - * - * @exception IOException If an error occurs - */ - public synchronized void close() throws IOException - { - if (isClosed()) - return; - - getImpl().close(); - impl = null; - bound = false; - - if (getChannel() != null) - getChannel().close(); - } - - /** - * Converts this <code>Socket</code> to a <code>String</code>. - * - * @return The <code>String</code> representation of this <code>Socket</code> - */ - public String toString() - { - try - { - if (isConnected()) - return ("Socket[addr=" + getImpl().getInetAddress() + ",port=" - + getImpl().getPort() + ",localport=" - + getImpl().getLocalPort() + "]"); - } - catch (SocketException e) - { - // This cannot happen as we are connected. - } - - return "Socket[unconnected]"; - } - - /** - * Sets the <code>SocketImplFactory</code>. This may be done only once per - * virtual machine. Subsequent attempts will generate a - * <code>SocketException</code>. Note that a <code>SecurityManager</code> - * check is made prior to setting the factory. If - * insufficient privileges exist to set the factory, then an - * <code>IOException</code> will be thrown. - * - * @param fac the factory to set - * - * @exception SecurityException If the <code>SecurityManager</code> does - * not allow this operation. - * @exception SocketException If the SocketImplFactory is already defined - * @exception IOException If any other error occurs - */ - public static synchronized void setSocketImplFactory(SocketImplFactory fac) - throws IOException - { - // See if already set - if (factory != null) - throw new SocketException("SocketImplFactory already defined"); - - // Check permissions - SecurityManager sm = System.getSecurityManager(); - if (sm != null) - sm.checkSetFactory(); - - if (fac == null) - throw new SocketException("SocketImplFactory cannot be null"); - - factory = fac; - } - - /** - * Closes the input side of the socket stream. - * - * @exception IOException If an error occurs. - * - * @since 1.3 - */ - public void shutdownInput() throws IOException - { - if (isClosed()) - throw new SocketException("socket is closed"); - - getImpl().shutdownInput(); - inputShutdown = true; - } - - /** - * Closes the output side of the socket stream. - * - * @exception IOException If an error occurs. - * - * @since 1.3 - */ - public void shutdownOutput() throws IOException - { - if (isClosed()) - throw new SocketException("socket is closed"); - - getImpl().shutdownOutput(); - outputShutdown = true; - } - - /** - * Returns the socket channel associated with this socket. - * - * @return the associated socket channel, - * null if no associated channel exists - * - * @since 1.4 - */ - public SocketChannel getChannel() - { - return null; - } - - /** - * Checks if the SO_REUSEADDR option is enabled - * - * @return True if SO_REUSEADDR is set, false otherwise. - * - * @exception SocketException If an error occurs - * - * @since 1.4 - */ - public boolean getReuseAddress() throws SocketException - { - if (isClosed()) - throw new SocketException("socket is closed"); - - Object reuseaddr = getImpl().getOption(SocketOptions.SO_REUSEADDR); - - if (! (reuseaddr instanceof Boolean)) - throw new SocketException("Internal Error"); - - return ((Boolean) reuseaddr).booleanValue(); - } - - /** - * Enables/Disables the SO_REUSEADDR option - * - * @param reuseAddress true if SO_REUSEADDR should be enabled, - * false otherwise - * - * @exception SocketException If an error occurs - * - * @since 1.4 - */ - public void setReuseAddress(boolean reuseAddress) throws SocketException - { - if (isClosed()) - throw new SocketException("socket is closed"); - - getImpl().setOption(SocketOptions.SO_REUSEADDR, - Boolean.valueOf(reuseAddress)); - } - - /** - * Returns the current traffic class - * - * @return The current traffic class. - * - * @exception SocketException If an error occurs - * - * @see Socket#setTrafficClass(int tc) - * - * @since 1.4 - */ - public int getTrafficClass() throws SocketException - { - if (isClosed()) - throw new SocketException("socket is closed"); - - Object obj = getImpl().getOption(SocketOptions.IP_TOS); - - if (obj instanceof Integer) - return ((Integer) obj).intValue(); - else - throw new SocketException("Unexpected type"); - } - - /** - * Sets the traffic class value - * - * @param tc The traffic class - * - * @exception SocketException If an error occurs - * @exception IllegalArgumentException If tc value is illegal - * - * @see Socket#getTrafficClass() - * - * @since 1.4 - */ - public void setTrafficClass(int tc) throws SocketException - { - if (isClosed()) - throw new SocketException("socket is closed"); - - if (tc < 0 || tc > 255) - throw new IllegalArgumentException(); - - getImpl().setOption(SocketOptions.IP_TOS, new Integer(tc)); - } - - /** - * Checks if the socket is connected - * - * @return True if socket is connected, false otherwise. - * - * @since 1.4 - */ - public boolean isConnected() - { - try - { - if (getImpl() == null) - return false; - - return getImpl().getInetAddress() != null; - } - catch (SocketException e) - { - return false; - } - } - - /** - * Checks if the socket is already bound. - * - * @return True if socket is bound, false otherwise. - * - * @since 1.4 - */ - public boolean isBound() - { - return bound; - } - - /** - * Checks if the socket is closed. - * - * @return True if socket is closed, false otherwise. - * - * @since 1.4 - */ - public boolean isClosed() - { - return impl == null; - } - - /** - * Checks if the socket's input stream is shutdown - * - * @return True if input is shut down. - * - * @since 1.4 - */ - public boolean isInputShutdown() - { - return inputShutdown; - } - - /** - * Checks if the socket's output stream is shutdown - * - * @return True if output is shut down. - * - * @since 1.4 - */ - public boolean isOutputShutdown() - { - return outputShutdown; - } -} diff --git a/libjava/java/net/SocketAddress.java b/libjava/java/net/SocketAddress.java deleted file mode 100644 index 48ab010097f..00000000000 --- a/libjava/java/net/SocketAddress.java +++ /dev/null @@ -1,63 +0,0 @@ -/* SocketAddress.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.net; - -import java.io.Serializable; - - -/** - * Abstract base class for InetSocketAddress. - * InetSocketAddress is to my knowledge the only derived - * class. [Ronald] - * - * @since 1.4 - */ -public abstract class SocketAddress implements Serializable -{ - /** - * Compatible with JDK 1.4+ - */ - static final long serialVersionUID = 5215720748342549866L; - - /** - * Initializes the socket address. - */ - public SocketAddress() - { - } -} diff --git a/libjava/java/net/SocketException.java b/libjava/java/net/SocketException.java deleted file mode 100644 index 37b2f6fba43..00000000000 --- a/libjava/java/net/SocketException.java +++ /dev/null @@ -1,75 +0,0 @@ -/* SocketException.java -- An exception occurred while performing a socket op - Copyright (C) 1998, 1999, 2001, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.net; - -import java.io.IOException; - - -/** - * This exception indicates that a generic error occurred related to an - * operation on a socket. Check the descriptive message (if any) for - * details on the nature of this error - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Per Bothner - * @status updated to 1.4 - */ -public class SocketException extends IOException -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = -5935874303556886934L; - - /** - * Create a new instance without a descriptive error message. - */ - public SocketException() - { - } - - /** - * Create a new instance with a descriptive error message. - * - * @param message a message describing the error that occurred - */ - public SocketException(String message) - { - super(message); - } -} // class SocketException diff --git a/libjava/java/net/SocketImpl.java b/libjava/java/net/SocketImpl.java deleted file mode 100644 index 77f470be332..00000000000 --- a/libjava/java/net/SocketImpl.java +++ /dev/null @@ -1,321 +0,0 @@ -/* SocketImpl.java -- Abstract socket implementation class - Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 - Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.net; - -import java.io.FileDescriptor; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - - -/* Written using on-line Java Platform 1.2 API Specification. - * Believed complete and correct. - */ - -/** - * This abstract class serves as the parent class for socket implementations. - * The implementation class serves an intermediary to native routines that - * perform system specific socket operations. - * <p> - * A default implementation is provided by the system, but this can be - * changed via installing a <code>SocketImplFactory</code> (through a call - * to the static method <code>Socket.setSocketImplFactory</code>). A - * subclass of <code>Socket</code> can also pass in a <code>SocketImpl</code> - * to the <code>Socket(SocketImpl)</code> constructor to use an - * implementation different from the system default without installing - * a factory. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Per Bothner (bothner@cygnus.com) - */ -public abstract class SocketImpl implements SocketOptions -{ - /** - * The address of the remote end of the socket connection - */ - protected InetAddress address; - - /** - * A FileDescriptor object representing this socket connection. - */ - protected FileDescriptor fd; - - /** - * The port number the socket is bound to locally - */ - protected int localport = -1; - - /** - * The port number of the remote end of the socket connection - */ - protected int port; - - /** - * Default, no-argument constructor for use by subclasses. - */ - public SocketImpl() - { - } - - /** - * Creates a new socket that is not bound to any local address/port and - * is not connected to any remote address/port. This will be created as - * a stream socket if the stream parameter is true, or a datagram socket - * if the stream parameter is false. - * - * @param stream true for a stream socket, false for a datagram socket - * - * @exception IOException If an error occurs - */ - protected abstract void create(boolean stream) throws IOException; - - /** - * Connects to the remote hostname and port specified as arguments. - * - * @param host The remote hostname to connect to - * @param port The remote port to connect to - * - * @exception IOException If an error occurs - */ - protected abstract void connect(String host, int port) - throws IOException; - - /** - * Connects to the remote address and port specified as arguments. - * - * @param host The remote address to connect to - * @param port The remote port to connect to - * - * @exception IOException If an error occurs - */ - protected abstract void connect(InetAddress host, int port) - throws IOException; - - /** - * Connects to the socket to the host specified in address. This - * method blocks until successful connected or the timeout occurs. - * A timeout of zero means no timout. - * - * @param address Data of remote host - * @param timeout time to wait to stop connecting - * - * @exception IOException If an error occurs - * - * @since 1.4 - */ - protected abstract void connect(SocketAddress address, int timeout) - throws IOException; - - /** - * Binds to the specified port on the specified addr. Note that this addr - * must represent a local IP address. - * <p> - * Note that it is unspecified how to bind to all interfaces on the localhost - * (INADDR_ANY). - * - * @param host The address to bind to - * @param port The port number to bind to - * - * @exception IOException If an error occurs - */ - protected abstract void bind(InetAddress host, int port) - throws IOException; - - /** - * Starts listening for connections on a socket. The backlog parameter - * is how many pending connections will queue up waiting to be serviced - * before being accept'ed. If the queue of pending requests exceeds this - * number, additional connections will be refused. - * - * @param backlog The length of the pending connection queue - * - * @exception IOException If an error occurs - */ - protected abstract void listen(int backlog) throws IOException; - - /** - * Accepts a connection on this socket. - * - * @param s The implementation object for the accepted connection. - * - * @exception IOException If an error occurs - */ - protected abstract void accept(SocketImpl s) throws IOException; - - /** - * Returns an <code>InputStream</code> object for reading from this socket. - * - * @return An <code>InputStream</code> for reading from this socket. - * - * @exception IOException If an error occurs - */ - protected abstract InputStream getInputStream() throws IOException; - - /** - * Returns an <code>OutputStream</code> object for writing to this socket - * - * @return An <code>OutputStream</code> for writing to this socket. - * - * @exception IOException If an error occurs. - */ - protected abstract OutputStream getOutputStream() throws IOException; - - /** - * Returns the number of bytes that the caller can read from this socket - * without blocking. - * - * @return The number of readable bytes before blocking - * - * @exception IOException If an error occurs - */ - protected abstract int available() throws IOException; - - /** - * Closes the socket. This will normally cause any resources, such as the - * InputStream, OutputStream and associated file descriptors to be freed. - * <p> - * Note that if the SO_LINGER option is set on this socket, then the - * operation could block. - * - * @exception IOException If an error occurs - */ - protected abstract void close() throws IOException; - - /** - * Returns the FileDescriptor objects for this socket. - * - * @return A FileDescriptor for this socket. - */ - protected FileDescriptor getFileDescriptor() - { - return fd; - } - - /** - * Returns the remote address this socket is connected to - * - * @return The remote address - */ - protected InetAddress getInetAddress() - { - return address; - } - - /** - * Returns the remote port this socket is connected to - * - * @return The remote port - */ - protected int getPort() - { - return port; - } - - /** - * Returns true or false when this socket supports sending urgent data - * or not. - * - * @return true if the socket implementation supports sending urgent data, - * false otherwise - * - * @since 1.4 - */ - protected boolean supportsUrgentData() - { - // This method has to be overwritten by socket classes that support - // sending urgend data. - return false; - } - - /** - * Sends one byte of urgent data to the socket. - * - * @param data The byte to send, the low eight bits of it - * - * @exception IOException If an error occurs - * - * @since 1.4 - */ - protected abstract void sendUrgentData(int data) throws IOException; - - /** - * Returns the local port this socket is bound to - * - * @return The local port - */ - protected int getLocalPort() - { - return localport; - } - - /** - * Returns a <code>String</code> representing the remote host and port of - * this socket. - * - * @return A <code>String</code> for this socket. - */ - public String toString() - { - return "[addr=" - + ((address == null) ? "0.0.0.0/0.0.0.0" : address.toString()) - + ",port=" + port + ",localport=" + localport + "]"; - } - - /** - * Shut down the input side of this socket. Subsequent reads will - * return end-of-file. - * - * @exception IOException if an error occurs - */ - protected void shutdownInput() throws IOException - { - throw new IOException("Not implemented in this socket class"); - } - - /** - * Shut down the output side of this socket. Subsequent writes will - * fail with an IOException. - * - * @exception IOException if an error occurs - */ - protected void shutdownOutput() throws IOException - { - throw new IOException("Not implemented in this socket class"); - } -} diff --git a/libjava/java/net/SocketImplFactory.java b/libjava/java/net/SocketImplFactory.java deleted file mode 100644 index b7cb10ca65f..00000000000 --- a/libjava/java/net/SocketImplFactory.java +++ /dev/null @@ -1,59 +0,0 @@ -/* SocketImplFactory.java -- Interface to create a SocketImpl object - Copyright (C) 1998, 1999, 2000, 2001, 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.net; - - -/** Written using on-line Java Platform 1.2 API Specification. - * Status: Believed complete and correct. - */ -/** - * This interface defines one method which returns a <code>SocketImpl</code> - * object. This should not be needed by ordinary applications. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Per Bothner (bothner@cygnus.com) - */ -public interface SocketImplFactory -{ - /** - * This method returns an instance of the <code>SocketImpl</code> object - * - * @return A <code>SocketImpl</code> object - */ - SocketImpl createSocketImpl(); -} // interface SocketImplFactory diff --git a/libjava/java/net/SocketOptions.java b/libjava/java/net/SocketOptions.java deleted file mode 100644 index 659bf750c3b..00000000000 --- a/libjava/java/net/SocketOptions.java +++ /dev/null @@ -1,166 +0,0 @@ -/* SocketOptions.java -- Implements options for sockets (duh!) - Copyright (C) 1998, 1999, 2000, 2001, - 2002, 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.net; - - -/** - * Written using on-line Java Platform 1.2 API Specification. - * Status: Believed complete and correct. - */ -/** - * This interface is used by <code>SocketImpl</code> and - * <code>DatagramSocketImpl</code> to implement options - * on sockets. - * - * @since 1.2 - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Warren Levy (warrenl@cygnus.com) - * @status should be completely JDK 1.4 compatible - */ -public interface SocketOptions -{ - /** - * Option id for the SO_KEEPALIVE value - * @since 1.3 - */ - int SO_KEEPALIVE = 0x8; - - /** - * Option id for the SO_LINGER value - */ - int SO_LINGER = 0x80; // 128 - - /** - * Option id for the SO_TIMEOUT value - */ - int SO_TIMEOUT = 0x1006; // 4102 - - /** - * Retrieve the local address to which the socket is bound. - */ - int SO_BINDADDR = 0x0F; // 15 - - /** - * Option id for the send buffer size - * @since 1.2 - */ - int SO_SNDBUF = 0x1001; // 4097 - - /** - * Option id for the receive buffer size - * @since 1.2 - */ - int SO_RCVBUF = 0x1002; // 4098 - - /** - * Sets the SO_REUSEADDR parameter on a socket - */ - int SO_REUSEADDR = 0x04; // 4 - - /** - * Sets SO_BROADCAST for a socket - * @since 1.4 - */ - int SO_BROADCAST = 0x20; // 32 - - /** - * Sets SO_OOBINLINE for a socket - * @since 1.4 - */ - int SO_OOBINLINE = 0x1003; // 4099 - - /** - * Option id for the TCP_NODELAY value - */ - int TCP_NODELAY = 0x01; // 1 - - /** - * Options id for the IP_MULTICAST_IF value - */ - int IP_MULTICAST_IF = 0x10; // 16 - - /** - * same as above - * @since 1.4 - */ - int IP_MULTICAST_IF2 = 0x1F; // 31 - - /** - * This option enables or disables local loopback of multicast datagrams. - * @since 1.4 - */ - int IP_MULTICAST_LOOP = 0x12; // 18 - - /** - * This option sets the type-of-service or traffic class field in the - * IP header for a TCP or UDP socket. - * @since 1.4 - */ - int IP_TOS = 0x03; // 3 - - /** - * Sets the specified option on a socket to the passed in object. For - * options that take an integer argument, the passed in object is an - * <code>Integer</code>. For options that are set to on or off, the - * value passed will be a <code>Boolean</code>. The <code>optionId</code> - * parameter is one of the defined constants in this interface. - * - * @param optionId The identifier of the option - * @param val The value to set the option to - * - * @exception SocketException If an error occurs - */ - void setOption(int optionId, Object val) throws SocketException; - - /** - * Returns the current setting of the specified option. The - * <code>Object</code> returned will be an <code>Integer</code> for options - * that have integer values. For options that are set to on or off, a - * <code>Boolean</code> will be returned. The <code>optionId</code> - * parameter is one of the defined constants in this interface. - * - * @param optionId The option identifier - * - * @return The current value of the option - * - * @exception SocketException If an error occurs - */ - Object getOption(int optionId) throws SocketException; -} // interface SocketOptions diff --git a/libjava/java/net/SocketPermission.java b/libjava/java/net/SocketPermission.java deleted file mode 100644 index 8ccd01baec5..00000000000 --- a/libjava/java/net/SocketPermission.java +++ /dev/null @@ -1,408 +0,0 @@ -/* SocketPermission.java -- Class modeling permissions for socket operations - Copyright (C) 1998, 2000, 2001, 2002, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.net; - -import java.io.Serializable; -import java.security.Permission; -import java.security.PermissionCollection; - - -/** - * This class models a specific set of permssions for connecting to a - * host. There are two elements to this, the host/port combination and - * the permission list. - * <p> - * The host/port combination is specified as followed - * <p> - * <pre> - * hostname[:[-]port[-[port]]] - * </pre> - * <p> - * The hostname portion can be either a hostname or IP address. If it is - * a hostname, a wildcard is allowed in hostnames. This wildcard is a "*" - * and matches one or more characters. Only one "*" may appear in the - * host and it must be the leftmost character. For example, - * "*.urbanophile.com" matches all hosts in the "urbanophile.com" domain. - * <p> - * The port portion can be either a single value, or a range of values - * treated as inclusive. The first or the last port value in the range - * can be omitted in which case either the minimum or maximum legal - * value for a port (respectively) is used by default. Here are some - * examples: - * <p><ul> - * <li>8080 - Represents port 8080 only</li> - * <li>2000-3000 - Represents ports 2000 through 3000 inclusive</li> - * <li>-4000 - Represents ports 0 through 4000 inclusive</li> - * <li>1024- - Represents ports 1024 through 65535 inclusive</li> - * </ul><p> - * The permission list is a comma separated list of individual permissions. - * These individual permissions are: - * <p> - * <pre> - * accept - * connect - * listen - * resolve - * </pre> - * <p> - * The "listen" permission is only relevant if the host is localhost. If - * any permission at all is specified, then resolve permission is implied to - * exist. - * <p> - * Here are a variety of examples of how to create SocketPermission's - * <p><pre> - * SocketPermission("www.urbanophile.com", "connect"); - * Can connect to any port on www.urbanophile.com - * SocketPermission("www.urbanophile.com:80", "connect,accept"); - * Can connect to or accept connections from www.urbanophile.com on port 80 - * SocketPermission("localhost:1024-", "listen,accept,connect"); - * Can connect to, accept from, an listen on any local port number 1024 - * and up. - * SocketPermission("*.edu", "connect"); - * Can connect to any host in the edu domain - * SocketPermission("197.197.20.1", "accept"); - * Can accept connections from 197.197.20.1 - * </pre><p> - * - * This class also supports IPv6 addresses. These should be specified - * in either RFC 2732 format or in full uncompressed form. - * - * @since 1.2 - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public final class SocketPermission extends Permission implements Serializable -{ - static final long serialVersionUID = -7204263841984476862L; - -// FIXME: Needs serialization work, including readObject/writeObject methods. - - /** - * A hostname/port combination as described above - */ - private transient String hostport; - - /** - * A comma separated list of actions for which we have permission - */ - private String actions; - - /** - * Initializes a new instance of <code>SocketPermission</code> with the - * specified host/port combination and actions string. - * - * @param hostport The hostname/port number combination - * @param actions The actions string - */ - public SocketPermission(String hostport, String actions) - { - super(hostport); - - this.hostport = hostport; - this.actions = actions; - } - - /** - * Tests this object for equality against another. This will be true if - * and only if the passed object is an instance of - * <code>SocketPermission</code> and both its hostname/port combination - * and permissions string are identical. - * - * @param obj The object to test against for equality - * - * @return <code>true</code> if object is equal to this object, - * <code>false</code> otherwise. - */ - public boolean equals(Object obj) - { - if (! (obj instanceof SocketPermission)) - return false; - - if (((SocketPermission) obj).hostport.equals(hostport)) - if (((SocketPermission) obj).actions.equals(actions)) - return true; - - return false; - } - - /** - * Returns a hash code value for this object. Overrides the - * <code>Permission.hashCode()</code>. - * - * @return A hash code - */ - public int hashCode() - { - int hash = 100; - if (hostport != null) - hash += hostport.hashCode(); - if (actions != null) - hash += actions.hashCode(); - return hash; - } - - /** - * Returns the list of permission actions in this object in canonical - * order. The canonical order is "connect,listen,accept,resolve" - * - * @return The permitted action string. - */ - public String getActions() - { - boolean found = false; - StringBuffer sb = new StringBuffer(""); - - if (actions.indexOf("connect") != -1) - { - sb.append("connect"); - found = true; - } - - if (actions.indexOf("listen") != -1) - if (found) - sb.append(",listen"); - else - { - sb.append("listen"); - found = true; - } - - if (actions.indexOf("accept") != -1) - if (found) - sb.append(",accept"); - else - { - sb.append("accept"); - found = true; - } - - if (found) - sb.append(",resolve"); - else if (actions.indexOf("resolve") != -1) - sb.append("resolve"); - - return sb.toString(); - } - - /** - * Returns a new <code>PermissionCollection</code> object that can hold - * <code>SocketPermission</code>'s. - * - * @return A new <code>PermissionCollection</code>. - */ - public PermissionCollection newPermissionCollection() - { - // FIXME: Implement - - return null; - } - - /** - * Returns true if the permission object passed it is implied by the - * this permission. This will be true if: - * - * <ul> - * <li>The argument is of type <code>SocketPermission</code></li> - * <li>The actions list of the argument are in this object's actions</li> - * <li>The port range of the argument is within this objects port range</li> - * <li>The hostname is equal to or a subset of this objects hostname</li> - * </ul> - * - * <p>The argument's hostname will be a subset of this object's hostname if:</p> - * - * <ul> - * <li>The argument's hostname or IP address is equal to this object's.</li> - * <li>The argument's canonical hostname is equal to this object's.</li> - * <li>The argument's canonical name matches this domains hostname with - * wildcards</li> - * </ul> - * - * @param perm The <code>Permission</code> to check against - * - * @return <code>true</code> if the <code>Permission</code> is implied by - * this object, <code>false</code> otherwise. - */ - public boolean implies(Permission perm) - { - SocketPermission p; - - // First make sure we are the right object type - if (perm instanceof SocketPermission) - p = (SocketPermission) perm; - else - return false; - - // Next check the actions - String ourlist = getActions(); - String theirlist = p.getActions(); - - if (! ourlist.startsWith(theirlist)) - return false; - - // Now check ports - int ourfirstport = 0; - - // Now check ports - int ourlastport = 0; - - // Now check ports - int theirfirstport = 0; - - // Now check ports - int theirlastport = 0; - - // Get ours - if (hostport.indexOf(":") == -1) - { - ourfirstport = 0; - ourlastport = 65535; - } - else - { - // FIXME: Needs bulletproofing. - // This will dump if hostport if all sorts of bad data was passed to - // the constructor - String range = hostport.substring(hostport.indexOf(":") + 1); - if (range.startsWith("-")) - ourfirstport = 0; - else if (range.indexOf("-") == -1) - ourfirstport = Integer.parseInt(range); - else - ourfirstport = - Integer.parseInt(range.substring(0, range.indexOf("-"))); - - if (range.endsWith("-")) - ourlastport = 65535; - else if (range.indexOf("-") == -1) - ourlastport = Integer.parseInt(range); - else - ourlastport = - Integer.parseInt(range.substring(range.indexOf("-") + 1, - range.length())); - } - - // Get theirs - if (p.hostport.indexOf(":") == -1) - { - theirfirstport = 0; - ourlastport = 65535; - } - else - { - // This will dump if hostport if all sorts of bad data was passed to - // the constructor - String range = p.hostport.substring(hostport.indexOf(":") + 1); - if (range.startsWith("-")) - theirfirstport = 0; - else if (range.indexOf("-") == -1) - theirfirstport = Integer.parseInt(range); - else - theirfirstport = - Integer.parseInt(range.substring(0, range.indexOf("-"))); - - if (range.endsWith("-")) - theirlastport = 65535; - else if (range.indexOf("-") == -1) - theirlastport = Integer.parseInt(range); - else - theirlastport = - Integer.parseInt(range.substring(range.indexOf("-") + 1, - range.length())); - } - - // Now check them - if ((theirfirstport < ourfirstport) || (theirlastport > ourlastport)) - return false; - - // Finally we can check the hosts - String ourhost; - - // Finally we can check the hosts - String theirhost; - - // Get ours - if (hostport.indexOf(":") == -1) - ourhost = hostport; - else - ourhost = hostport.substring(0, hostport.indexOf(":")); - - // Get theirs - if (p.hostport.indexOf(":") == -1) - theirhost = p.hostport; - else - theirhost = p.hostport.substring(0, p.hostport.indexOf(":")); - - // Are they equal? - if (ourhost.equals(theirhost)) - return true; - - // Try the canonical names - String ourcanonical = null; - - // Try the canonical names - String theircanonical = null; - try - { - ourcanonical = InetAddress.getByName(ourhost).getHostName(); - theircanonical = InetAddress.getByName(theirhost).getHostName(); - } - catch (UnknownHostException e) - { - // Who didn't resolve? Just assume current address is canonical enough - // Is this ok to do? - if (ourcanonical == null) - ourcanonical = ourhost; - if (theircanonical == null) - theircanonical = theirhost; - } - - if (ourcanonical.equals(theircanonical)) - return true; - - // Well, last chance. Try for a wildcard - if (ourhost.indexOf("*.") != -1) - { - String wild_domain = ourhost.substring(ourhost.indexOf("*" + 1)); - if (theircanonical.endsWith(wild_domain)) - return true; - } - - // Didn't make it - return false; - } -} diff --git a/libjava/java/net/SocketTimeoutException.java b/libjava/java/net/SocketTimeoutException.java deleted file mode 100644 index 21b0dcd86c2..00000000000 --- a/libjava/java/net/SocketTimeoutException.java +++ /dev/null @@ -1,73 +0,0 @@ -/* SocketTimeoutException.java -- the socket timed out - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.net; - -import java.io.InterruptedIOException; - - -/** - * This exception signals that a socket read or accept timed out. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.4 - * @status updated to 1.4 - */ -public class SocketTimeoutException extends InterruptedIOException -{ - /** - * Compatible with JDK 1.4+. - */ - private static final long serialVersionUID = -8846654841826352300L; - - /** - * Create a new instance without a descriptive error message. - */ - public SocketTimeoutException() - { - } - - /** - * Create a new instance with a descriptive error message. - * - * @param message a message describing the error that occurred - */ - public SocketTimeoutException(String message) - { - super(message); - } -} // class SocketTimeoutException diff --git a/libjava/java/net/URI.java b/libjava/java/net/URI.java deleted file mode 100644 index 75c2ec97336..00000000000 --- a/libjava/java/net/URI.java +++ /dev/null @@ -1,893 +0,0 @@ -/* URI.java -- An URI class - Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.net; - -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * <p> - * A URI instance represents that defined by - * <a href="http://www.ietf.org/rfc/rfc3986.txt">RFC2396</a>, - * with some deviations. - * </p> - * <p> - * At its highest level, a URI consists of: - * </p> - * <code>[<em>scheme</em><strong>:</strong>]<em>scheme-specific-part</em> - * [<strong>#</strong><em>fragment</em>]</code> - * </p> - * <p> - * where <strong>#</strong> and <strong>:</strong> are literal characters, - * and those parts enclosed in square brackets are optional. - * </p> - * <p> - * There are two main types of URI. An <em>opaque</em> URI is one - * which just consists of the above three parts, and is not further - * defined. An example of such a URI would be <em>mailto:</em> URI. - * In contrast, <em>hierarchical</em> URIs give further definition - * to the scheme-specific part, so as represent some part of a hierarchical - * structure. - * </p> - * <p> - * <code>[<strong>//</strong><em>authority</em>][<em>path</em>] - * [<strong>?</strong><em>query</em>]</code> - * </p> - * <p> - * with <strong>/</strong> and <strong>?</strong> being literal characters. - * When server-based, the authority section is further subdivided into: - * </p> - * <p> - * <code>[<em>user-info</em><strong>@</strong>]<em>host</em> - * [<strong>:</strong><em>port</em>]</code> - * </p> - * <p> - * with <strong>@</strong> and <strong>:</strong> as literal characters. - * Authority sections that are not server-based are said to be registry-based. - * </p> - * <p> - * Hierarchical URIs can be either relative or absolute. Absolute URIs - * always start with a `<strong>/</strong>', while relative URIs don't - * specify a scheme. Opaque URIs are always absolute. - * </p> - * <p> - * Each part of the URI may have one of three states: undefined, empty - * or containing some content. The former two of these are represented - * by <code>null</code> and the empty string in Java, respectively. - * The scheme-specific part may never be undefined. It also follows from - * this that the path sub-part may also not be undefined, so as to ensure - * the former. - * </p> - * - * @author Ito Kazumitsu (ito.kazumitsu@hitachi-cable.co.jp) - * @author Dalibor Topic (robilad@kaffe.org) - * @author Michael Koch (konqueror@gmx.de) - * @author Andrew John Hughes (gnu_andrew@member.fsf.org) - * @since 1.4 - */ -public final class URI - implements Comparable, Serializable -{ - static final long serialVersionUID = -6052424284110960213L; - - /** - * Regular expression for parsing URIs. - * - * Taken from RFC 2396, Appendix B. - * This expression doesn't parse IPv6 addresses. - */ - private static final String URI_REGEXP = - "^(([^:/?#]+):)?((//([^/?#]*))?([^?#]*)(\\?([^#]*))?)?(#(.*))?"; - - private static final String AUTHORITY_REGEXP = - "(([^?#]*)@)?([^?#:]*)(:([^?#]*))?"; - - /** - * Valid characters (taken from rfc2396) - */ - private static final String RFC2396_DIGIT = "0123456789"; - private static final String RFC2396_LOWALPHA = "abcdefghijklmnopqrstuvwxyz"; - private static final String RFC2396_UPALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - private static final String RFC2396_ALPHA = - RFC2396_LOWALPHA + RFC2396_UPALPHA; - private static final String RFC2396_ALPHANUM = RFC2396_DIGIT + RFC2396_ALPHA; - private static final String RFC2396_MARK = "-_.!~*'()"; - private static final String RFC2396_UNRESERVED = - RFC2396_ALPHANUM + RFC2396_MARK; - private static final String RFC2396_REG_NAME = - RFC2396_UNRESERVED + "$,;:@&=+"; - private static final String RFC2396_PCHAR = RFC2396_UNRESERVED + ":@&=+$,"; - private static final String RFC2396_SEGMENT = RFC2396_PCHAR + ";"; - private static final String RFC2396_PATH_SEGMENTS = RFC2396_SEGMENT + "/"; - - /** - * Index of scheme component in parsed URI. - */ - private static final int SCHEME_GROUP = 2; - - /** - * Index of scheme-specific-part in parsed URI. - */ - private static final int SCHEME_SPEC_PART_GROUP = 3; - - /** - * Index of authority component in parsed URI. - */ - private static final int AUTHORITY_GROUP = 5; - - /** - * Index of path component in parsed URI. - */ - private static final int PATH_GROUP = 6; - - /** - * Index of query component in parsed URI. - */ - private static final int QUERY_GROUP = 8; - - /** - * Index of fragment component in parsed URI. - */ - private static final int FRAGMENT_GROUP = 10; - - private static final int AUTHORITY_USERINFO_GROUP = 2; - private static final int AUTHORITY_HOST_GROUP = 3; - private static final int AUTHORITY_PORT_GROUP = 5; - - private transient String scheme; - private transient String rawSchemeSpecificPart; - private transient String schemeSpecificPart; - private transient String rawAuthority; - private transient String authority; - private transient String rawUserInfo; - private transient String userInfo; - private transient String rawHost; - private transient String host; - private transient int port = -1; - private transient String rawPath; - private transient String path; - private transient String rawQuery; - private transient String query; - private transient String rawFragment; - private transient String fragment; - private String string; - - private void readObject(ObjectInputStream is) - throws ClassNotFoundException, IOException - { - this.string = (String) is.readObject(); - try - { - parseURI(this.string); - } - catch (URISyntaxException x) - { - // Should not happen. - throw new RuntimeException(x); - } - } - - private void writeObject(ObjectOutputStream os) throws IOException - { - if (string == null) - string = toString(); - os.writeObject(string); - } - - private static String getURIGroup(Matcher match, int group) - { - String matched = match.group(group); - return matched.length() == 0 ? null : matched; - } - - /** - * Sets fields of this URI by parsing the given string. - * - * @param str The string to parse - * - * @exception URISyntaxException If the given string violates RFC 2396 - */ - private void parseURI(String str) throws URISyntaxException - { - Pattern pattern = Pattern.compile(URI_REGEXP); - Matcher matcher = pattern.matcher(str); - - if (matcher.matches()) - { - scheme = getURIGroup(matcher, SCHEME_GROUP); - rawSchemeSpecificPart = matcher.group(SCHEME_SPEC_PART_GROUP); - schemeSpecificPart = unquote(rawSchemeSpecificPart); - if (!isOpaque()) - { - rawAuthority = getURIGroup(matcher, AUTHORITY_GROUP); - rawPath = matcher.group(PATH_GROUP); - rawQuery = getURIGroup(matcher, QUERY_GROUP); - } - rawFragment = getURIGroup(matcher, FRAGMENT_GROUP); - } - else - throw new URISyntaxException(str, "doesn't match URI regular expression"); - - if (rawAuthority != null) - { - pattern = Pattern.compile(AUTHORITY_REGEXP); - matcher = pattern.matcher(rawAuthority); - - if (matcher.matches()) - { - rawUserInfo = getURIGroup(matcher, AUTHORITY_USERINFO_GROUP); - rawHost = getURIGroup(matcher, AUTHORITY_HOST_GROUP); - - String portStr = getURIGroup(matcher, AUTHORITY_PORT_GROUP); - - if (portStr != null) - try - { - port = Integer.parseInt(portStr); - } - catch (NumberFormatException e) - { - URISyntaxException use = - new URISyntaxException - (str, "doesn't match URI regular expression"); - use.initCause(e); - throw use; - } - } - else - throw new URISyntaxException(str, "doesn't match URI regular expression"); - } - - // We must eagerly unquote the parts, because this is the only time - // we may throw an exception. - authority = unquote(rawAuthority); - userInfo = unquote(rawUserInfo); - host = unquote(rawHost); - path = unquote(rawPath); - query = unquote(rawQuery); - fragment = unquote(rawFragment); - } - - /** - * Unquote "%" + hex quotes characters - * - * @param str The string to unquote or null. - * - * @return The unquoted string or null if str was null. - * - * @exception URISyntaxException If the given string contains invalid - * escape sequences. - */ - private static String unquote(String str) throws URISyntaxException - { - if (str == null) - return null; - byte[] buf = new byte[str.length()]; - int pos = 0; - for (int i = 0; i < str.length(); i++) - { - char c = str.charAt(i); - if (c > 127) - throw new URISyntaxException(str, "Invalid character"); - if (c == '%') - { - if (i + 2 >= str.length()) - throw new URISyntaxException(str, "Invalid quoted character"); - int hi = Character.digit(str.charAt(++i), 16); - int lo = Character.digit(str.charAt(++i), 16); - if (lo < 0 || hi < 0) - throw new URISyntaxException(str, "Invalid quoted character"); - buf[pos++] = (byte) (hi * 16 + lo); - } - else - buf[pos++] = (byte) c; - } - try - { - return new String(buf, 0, pos, "utf-8"); - } - catch (java.io.UnsupportedEncodingException x2) - { - throw (Error) new InternalError().initCause(x2); - } - } - - /** - * Quote characters illegal in URIs in given string. - * - * Replace illegal characters by encoding their UTF-8 - * representation as "%" + hex code for each resulting - * UTF-8 character. - * - * @param str The string to quote - * - * @return The quoted string. - */ - private static String quote(String str) - { - // FIXME: unimplemented. - return str; - } - - /** - * Quote characters illegal in URI authorities in given string. - * - * Replace illegal characters by encoding their UTF-8 - * representation as "%" + hex code for each resulting - * UTF-8 character. - * - * @param str The string to quote - * - * @return The quoted string. - */ - private static String quoteAuthority(String str) - { - // Technically, we should be using RFC2396_AUTHORITY, but - // it contains no additional characters. - return quote(str, RFC2396_REG_NAME); - } - - /** - * Quote characters in str that are not part of legalCharacters. - * - * Replace illegal characters by encoding their UTF-8 - * representation as "%" + hex code for each resulting - * UTF-8 character. - * - * @param str The string to quote - * @param legalCharacters The set of legal characters - * - * @return The quoted string. - */ - private static String quote(String str, String legalCharacters) - { - StringBuffer sb = new StringBuffer(str.length()); - for (int i = 0; i < str.length(); i++) - { - char c = str.charAt(i); - if (legalCharacters.indexOf(c) == -1) - { - String hex = "0123456789ABCDEF"; - if (c <= 127) - sb.append('%').append(hex.charAt(c / 16)).append(hex.charAt(c % 16)); - else - { - try - { - // this is far from optimal, but it works - byte[] utf8 = str.substring(i, i + 1).getBytes("utf-8"); - for (int j = 0; j < utf8.length; j++) - sb.append('%').append(hex.charAt((utf8[j] & 0xff) / 16)) - .append(hex.charAt((utf8[j] & 0xff) % 16)); - } - catch (java.io.UnsupportedEncodingException x) - { - throw (Error) new InternalError().initCause(x); - } - } - } - else - sb.append(c); - } - return sb.toString(); - } - - /** - * Quote characters illegal in URI hosts in given string. - * - * Replace illegal characters by encoding their UTF-8 - * representation as "%" + hex code for each resulting - * UTF-8 character. - * - * @param str The string to quote - * - * @return The quoted string. - */ - private static String quoteHost(String str) - { - // FIXME: unimplemented. - return str; - } - - /** - * Quote characters illegal in URI paths in given string. - * - * Replace illegal characters by encoding their UTF-8 - * representation as "%" + hex code for each resulting - * UTF-8 character. - * - * @param str The string to quote - * - * @return The quoted string. - */ - private static String quotePath(String str) - { - // Technically, we should be using RFC2396_PATH, but - // it contains no additional characters. - return quote(str, RFC2396_PATH_SEGMENTS); - } - - /** - * Quote characters illegal in URI user infos in given string. - * - * Replace illegal characters by encoding their UTF-8 - * representation as "%" + hex code for each resulting - * UTF-8 character. - * - * @param str The string to quote - * - * @return The quoted string. - */ - private static String quoteUserInfo(String str) - { - // FIXME: unimplemented. - return str; - } - - /** - * Creates an URI from the given string - * - * @param str The string to create the URI from - * - * @exception URISyntaxException If the given string violates RFC 2396 - * @exception NullPointerException If str is null - */ - public URI(String str) throws URISyntaxException - { - this.string = str; - parseURI(str); - } - - /** - * Create an URI from the given components - * - * @param scheme The scheme name - * @param userInfo The username and authorization info - * @param host The hostname - * @param port The port number - * @param path The path - * @param query The query - * @param fragment The fragment - * - * @exception URISyntaxException If the given string violates RFC 2396 - */ - public URI(String scheme, String userInfo, String host, int port, - String path, String query, String fragment) - throws URISyntaxException - { - this((scheme == null ? "" : scheme + ":") - + (userInfo == null && host == null && port == -1 ? "" : "//") - + (userInfo == null ? "" : quoteUserInfo(userInfo) + "@") - + (host == null ? "" : quoteHost(host)) - + (port == -1 ? "" : ":" + String.valueOf(port)) - + (path == null ? "" : quotePath(path)) - + (query == null ? "" : "?" + quote(query)) - + (fragment == null ? "" : "#" + quote(fragment))); - - parseServerAuthority(); - } - - /** - * Create an URI from the given components - * - * @param scheme The scheme name - * @param authority The authority - * @param path The apth - * @param query The query - * @param fragment The fragment - * - * @exception URISyntaxException If the given string violates RFC 2396 - */ - public URI(String scheme, String authority, String path, String query, - String fragment) throws URISyntaxException - { - this((scheme == null ? "" : scheme + ":") - + (authority == null ? "" : "//" + quoteAuthority(authority)) - + (path == null ? "" : quotePath(path)) - + (query == null ? "" : "?" + quote(query)) - + (fragment == null ? "" : "#" + quote(fragment))); - } - - /** - * Create an URI from the given components - * - * @param scheme The scheme name - * @param host The hostname - * @param path The path - * @param fragment The fragment - * - * @exception URISyntaxException If the given string violates RFC 2396 - */ - public URI(String scheme, String host, String path, String fragment) - throws URISyntaxException - { - this(scheme, null, host, -1, path, null, fragment); - } - - /** - * Create an URI from the given components - * - * @param scheme The scheme name - * @param ssp The scheme specific part - * @param fragment The fragment - * - * @exception URISyntaxException If the given string violates RFC 2396 - */ - public URI(String scheme, String ssp, String fragment) - throws URISyntaxException - { - this((scheme == null ? "" : scheme + ":") - + (ssp == null ? "" : quote(ssp)) - + (fragment == null ? "" : "#" + quote(fragment))); - } - - /** - * Create an URI from the given string - * - * @param str The string to create the URI from - * - * @exception IllegalArgumentException If the given string violates RFC 2396 - * @exception NullPointerException If str is null - */ - public static URI create(String str) - { - try - { - return new URI(str); - } - catch (URISyntaxException e) - { - throw (IllegalArgumentException) new IllegalArgumentException() - .initCause(e); - } - } - - /** - * Attempts to parse this URI's authority component, if defined, - * into user-information, host, and port components - * - * @exception URISyntaxException If the given string violates RFC 2396 - */ - public URI parseServerAuthority() throws URISyntaxException - { - return null; - } - - /** - * Returns a normalizes versions of the URI - */ - public URI normalize() - { - return null; - } - - /** - * Resolves the given URI against this URI - * - * @param uri The URI to resolve against this URI - * - * @return The resulting URI, or null when it couldn't be resolved - * for some reason. - * - * @exception NullPointerException If uri is null - */ - public URI resolve(URI uri) - { - if (uri.isAbsolute()) - return uri; - if (uri.isOpaque()) - return uri; - - String scheme = uri.getScheme(); - String schemeSpecificPart = uri.getSchemeSpecificPart(); - String authority = uri.getAuthority(); - String path = uri.getPath(); - String query = uri.getQuery(); - String fragment = uri.getFragment(); - - try - { - if (fragment != null && path != null && path.equals("") - && scheme == null && authority == null && query == null) - return new URI(this.scheme, this.schemeSpecificPart, fragment); - - if (authority == null) - { - authority = this.authority; - if (path == null) - path = ""; - if (! (path.startsWith("/"))) - { - StringBuffer basepath = new StringBuffer(this.path); - int i = this.path.lastIndexOf('/'); - - if (i >= 0) - basepath.delete(i + 1, basepath.length()); - - basepath.append(path); - path = basepath.toString(); - // FIXME We must normalize the path here. - // Normalization process omitted. - } - } - return new URI(this.scheme, authority, path, query, fragment); - } - catch (URISyntaxException e) - { - return null; - } - } - - /** - * Resolves the given URI string against this URI - * - * @param str The URI as string to resolve against this URI - * - * @return The resulting URI - * - * @exception IllegalArgumentException If the given URI string - * violates RFC 2396 - * @exception NullPointerException If uri is null - */ - public URI resolve(String str) throws IllegalArgumentException - { - return resolve(create(str)); - } - - /** - * Relativizes the given URI against this URI - * - * @param uri The URI to relativize this URI - * - * @return The resulting URI - * - * @exception NullPointerException If uri is null - */ - public URI relativize(URI uri) - { - return null; - } - - /** - * Creates an URL from an URI - * - * @exception MalformedURLException If a protocol handler for the URL could - * not be found, or if some other error occurred while constructing the URL - * @exception IllegalArgumentException If the URI is not absolute - */ - public URL toURL() throws IllegalArgumentException, MalformedURLException - { - if (isAbsolute()) - return new URL(this.toString()); - - throw new IllegalArgumentException("not absolute"); - } - - /** - * Returns the scheme of the URI - */ - public String getScheme() - { - return scheme; - } - - /** - * Tells whether this URI is absolute or not - */ - public boolean isAbsolute() - { - return scheme != null; - } - - /** - * Tell whether this URI is opaque or not - */ - public boolean isOpaque() - { - return ((scheme != null) && ! (schemeSpecificPart.startsWith("/"))); - } - - /** - * Returns the raw scheme specific part of this URI. - * The scheme-specific part is never undefined, though it may be empty - */ - public String getRawSchemeSpecificPart() - { - return rawSchemeSpecificPart; - } - - /** - * Returns the decoded scheme specific part of this URI. - */ - public String getSchemeSpecificPart() - { - return schemeSpecificPart; - } - - /** - * Returns the rae authority part of this URI - */ - public String getRawAuthority() - { - return rawAuthority; - } - - /** - * Returns the decoded authority part of this URI - */ - public String getAuthority() - { - return authority; - } - - /** - * Returns the raw user info part of this URI - */ - public String getRawUserInfo() - { - return rawUserInfo; - } - - /** - * Returns the decoded user info part of this URI - */ - public String getUserInfo() - { - return userInfo; - } - - /** - * Returns the hostname of the URI - */ - public String getHost() - { - return host; - } - - /** - * Returns the port number of the URI - */ - public int getPort() - { - return port; - } - - /** - * Returns the raw path part of this URI - */ - public String getRawPath() - { - return rawPath; - } - - /** - * Returns the path of the URI - */ - public String getPath() - { - return path; - } - - /** - * Returns the raw query part of this URI - */ - public String getRawQuery() - { - return rawQuery; - } - - /** - * Returns the query of the URI - */ - public String getQuery() - { - return query; - } - - /** - * Return the raw fragment part of this URI - */ - public String getRawFragment() - { - return rawFragment; - } - - /** - * Returns the fragment of the URI - */ - public String getFragment() - { - return fragment; - } - - /** - * Compares the URI with a given object - * - * @param obj The obj to compare the URI with - */ - public boolean equals(Object obj) - { - return false; - } - - /** - * Computes the hascode of the URI - */ - public int hashCode() - { - return 0; - } - - /** - * Compare the URI with another object that must be an URI too - * - * @param obj This object to compare this URI with - * - * @exception ClassCastException If given object ist not an URI - */ - public int compareTo(Object obj) throws ClassCastException - { - return 0; - } - - /** - * Returns the URI as a String. If the URI was created using a constructor, - * then this will be the same as the original input string. - * - * @return a string representation of the URI. - */ - public String toString() - { - return (getScheme() == null ? "" : getScheme() + ":") - + getRawSchemeSpecificPart() - + (getRawFragment() == null ? "" : "#" + getRawFragment()); - } - - /** - * Returns the URI as US-ASCII string - */ - public String toASCIIString() - { - return ""; - } -} diff --git a/libjava/java/net/URISyntaxException.java b/libjava/java/net/URISyntaxException.java deleted file mode 100644 index 27a70bdb717..00000000000 --- a/libjava/java/net/URISyntaxException.java +++ /dev/null @@ -1,144 +0,0 @@ -/* URISyntaxException.java -- a string could not be parsed as a URI - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.net; - - -/** - * This exception is thrown when a String cannot be parsed as a URI. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @see URI - * @since 1.4 - * @status updated to 1.4 - */ -public class URISyntaxException extends Exception -{ - /** - * Compatible with JDK 1.4+. - */ - private static final long serialVersionUID = 2137979680897488891L; - - /** - * The failed input. - * - * @serial the bad URI - */ - private final String input; - - /** - * The index of failure. - * - * @serial the location of the problem - */ - private final int index; - - /** - * Create an exception from the invalid string, with the index set to -1. - * - * @param input the bad URI - * @param msg the descriptive error message - * @throws NullPointerException if input or msg are null - */ - public URISyntaxException(String input, String msg) - { - this(input, msg, -1); - } - - /** - * Create an exception from the invalid string, with the index of the - * point of failure. - * - * @param input the bad URI - * @param msg the descriptive error message - * @param index the index of the parse error, or -1 - * @throws NullPointerException if input or msg are null - * @throws IllegalArgumentException if index < -1 - */ - public URISyntaxException(String input, String msg, int index) - { - // The toString() hack checks for null. - super(msg.toString()); - this.input = input.toString(); - this.index = index; - if (index < -1) - throw new IllegalArgumentException(); - } - - /** - * Returns the bad input string. - * - * @return the bad URI, guaranteed non-null - */ - public String getInput() - { - return input; - } - - /** - * Returns the reason for the failure. - * - * @return the message, guaranteed non-null - */ - public String getReason() - { - return super.getMessage(); - } - - /** - * Returns the index of the failure, or -1. - * - * @return the index of failure - */ - public int getIndex() - { - return index; - } - - /** - * Returns a message describing the parse error, as if by - * <code>getReason() + (getIndex() >= 0 ? " at index " + getIndex() : "") - * + ": " + getInput()</code>. - * - * @return the message string - */ - public String getMessage() - { - return (super.getMessage() + (index >= 0 ? " at index " + index : "") - + ": " + input); - } -} diff --git a/libjava/java/net/URLDecoder.java b/libjava/java/net/URLDecoder.java deleted file mode 100644 index ca40c386a52..00000000000 --- a/libjava/java/net/URLDecoder.java +++ /dev/null @@ -1,180 +0,0 @@ -/* URLDecoder.java -- Class to decode URL's from encoded form. - Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.net; - -import java.io.UnsupportedEncodingException; - - -/** - * This utility class contains static methods that converts a - * string encoded in the x-www-form-urlencoded format to the original - * text. The x-www-form-urlencoded format replaces certain disallowed - * characters with encoded equivalents. All upper case and lower case - * letters in the US alphabet remain as is, the space character (' ') - * is replaced with '+' sign, and all other characters are converted to a - * "%XX" format where XX is the hexadecimal representation of that character - * in a given character encoding (default is "UTF-8"). - * <p> - * This method is very useful for decoding strings sent to CGI scripts - * - * Written using on-line Java Platform 1.2/1.4 API Specification. - * Status: Believed complete and correct. - * - * @since 1.2 - * - * @author Warren Levy (warrenl@cygnus.com) - * @author Aaron M. Renn (arenn@urbanophile.com) (documentation comments) - * @author Mark Wielaard (mark@klomp.org) - */ -public class URLDecoder -{ - /** - * Public contructor. Note that this class has only static methods. - */ - public URLDecoder() - { - } - - /** - * This method translates the passed in string from x-www-form-urlencoded - * format using the default encoding "UTF-8" to decode the hex encoded - * unsafe characters. - * - * @param s the String to convert - * - * @return the converted String - * - * @deprecated - */ - public static String decode(String s) - { - try - { - return decode(s, "UTF-8"); - } - catch (UnsupportedEncodingException uee) - { - // Should never happen since UTF-8 encoding should always be supported - return s; - } - } - - /** - * This method translates the passed in string from x-www-form-urlencoded - * format using the given character encoding to decode the hex encoded - * unsafe characters. - * - * This implementation will decode the string even if it contains - * unsafe characters (characters that should have been encoded) or if the - * two characters following a % do not represent a hex encoded byte. - * In those cases the unsafe character or the % character will be added - * verbatim to the decoded result. - * - * @param s the String to convert - * @param encoding the character encoding to use the decode the hex encoded - * unsafe characters - * - * @return the converted String - * - * @exception UnsupportedEncodingException If the named encoding is not - * supported - * - * @since 1.4 - */ - public static String decode(String s, String encoding) - throws UnsupportedEncodingException - { - // First convert all '+' characters to spaces. - String str = s.replace('+', ' '); - - // Then go through the whole string looking for byte encoded characters - int i; - int start = 0; - byte[] bytes = null; - int length = str.length(); - StringBuffer result = new StringBuffer(length); - while ((i = str.indexOf('%', start)) >= 0) - { - // Add all non-encoded characters to the result buffer - result.append(str.substring(start, i)); - start = i; - - // Get all consecutive encoded bytes - while ((i + 2 < length) && (str.charAt(i) == '%')) - i += 3; - - // Decode all these bytes - if ((bytes == null) || (bytes.length < ((i - start) / 3))) - bytes = new byte[((i - start) / 3)]; - - int index = 0; - try - { - while (start < i) - { - String sub = str.substring(start + 1, start + 3); - bytes[index] = (byte) Integer.parseInt(sub, 16); - index++; - start += 3; - } - } - catch (NumberFormatException nfe) - { - // One of the hex encoded strings was bad - } - - // Add the bytes as characters according to the given encoding - result.append(new String(bytes, 0, index, encoding)); - - // Make sure we skip to just after a % sign - // There might not have been enough encoded characters after the % - // or the hex chars were not actually hex chars (NumberFormatException) - if (start < length && s.charAt(start) == '%') - { - result.append('%'); - start++; - } - } - - // Add any characters left - if (start < str.length()) - result.append(str.substring(start)); - - return result.toString(); - } -} // class URLDecoder diff --git a/libjava/java/net/URLEncoder.java b/libjava/java/net/URLEncoder.java deleted file mode 100644 index dacc3848e37..00000000000 --- a/libjava/java/net/URLEncoder.java +++ /dev/null @@ -1,184 +0,0 @@ -/* URLEncoder.java -- Class to convert strings to a properly encoded URL - Copyright (C) 1998, 1999, 2001, 2002, 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.net; - -import java.io.UnsupportedEncodingException; - - -/* - * Written using on-line Java Platform 1.2/1.4 API Specification, as well - * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998). - * Status: Believed complete and correct. - */ - -/** - * This utility class contains static methods that converts a - * string into a fully encoded URL string in x-www-form-urlencoded - * format. This format replaces certain disallowed characters with - * encoded equivalents. All upper case and lower case letters in the - * US alphabet remain as is, the space character (' ') is replaced with - * '+' sign, and all other characters are converted to a "%XX" format - * where XX is the hexadecimal representation of that character in a - * certain encoding (by default, the platform encoding, though the - * standard is "UTF-8"). - * <p> - * This method is very useful for encoding strings to be sent to CGI scripts - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Warren Levy (warrenl@cygnus.com) - * @author Mark Wielaard (mark@klomp.org) - */ -public class URLEncoder -{ - /** - * This method translates the passed in string into x-www-form-urlencoded - * format using the default encoding. The standard encoding is - * "UTF-8", and the two-argument form of this method should be used - * instead. - * - * @param s The String to convert - * - * @return The converted String - * - * @deprecated - */ - public static String encode(String s) - { - try - { - // We default to 8859_1 for compatibility with the same - // default elsewhere in the library. - return encode(s, System.getProperty("file.encoding", "8859_1")); - } - catch (UnsupportedEncodingException uee) - { - // Should never happen since default should always be supported - return s; - } - } - - /** - * This method translates the passed in string into x-www-form-urlencoded - * format using the character encoding to hex-encode the unsafe characters. - * - * @param s The String to convert - * @param encoding The encoding to use for unsafe characters - * - * @return The converted String - * - * @exception UnsupportedEncodingException If the named encoding is not - * supported - * - * @since 1.4 - */ - public static String encode(String s, String encoding) - throws UnsupportedEncodingException - { - int length = s.length(); - int start = 0; - int i = 0; - - StringBuffer result = new StringBuffer(length); - while (true) - { - while (i < length && isSafe(s.charAt(i))) - i++; - - // Safe character can just be added - result.append(s.substring(start, i)); - - // Are we done? - if (i >= length) - return result.toString(); - else if (s.charAt(i) == ' ') - { - result.append('+'); // Replace space char with plus symbol. - i++; - } - else - { - // Get all unsafe characters - start = i; - char c; - while (i < length && (c = s.charAt(i)) != ' ' && ! isSafe(c)) - i++; - - // Convert them to %XY encoded strings - String unsafe = s.substring(start, i); - byte[] bytes = unsafe.getBytes(encoding); - for (int j = 0; j < bytes.length; j++) - { - result.append('%'); - int val = bytes[j]; - result.append(hex.charAt((val & 0xf0) >> 4)); - result.append(hex.charAt(val & 0x0f)); - } - } - start = i; - } - } - - /** - * Private static method that returns true if the given char is either - * a uppercase or lowercase letter from 'a' till 'z', or a digit froim - * '0' till '9', or one of the characters '-', '_', '.' or '*'. Such - * 'safe' character don't have to be url encoded. - */ - private static boolean isSafe(char c) - { - return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') - || (c >= '0' && c <= '9') || c == '-' || c == '_' || c == '.' - || c == '*'); - } - - /** - * Private constructor that does nothing. Included to avoid a default - * public constructor being created by the compiler. - */ - private URLEncoder() - { - } - - /** - * Used to convert to hex. We don't use Integer.toHexString, since - * it converts to lower case (and the Sun docs pretty clearly - * specify upper case here), and because it doesn't provide a - * leading 0. - */ - private static final String hex = "0123456789ABCDEF"; -} diff --git a/libjava/java/net/URLStreamHandler.java b/libjava/java/net/URLStreamHandler.java deleted file mode 100644 index 57ce2dfa290..00000000000 --- a/libjava/java/net/URLStreamHandler.java +++ /dev/null @@ -1,532 +0,0 @@ -/* URLStreamHandler.java -- Abstract superclass for all protocol handlers - Copyright (C) 1998, 1999, 2002, 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.net; - -import java.io.File; -import java.io.IOException; - - -/* - * Written using on-line Java Platform 1.2 API Specification, as well - * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998). - * Status: Believed complete and correct. - */ - -/** - * This class is the superclass of all URL protocol handlers. The URL - * class loads the appropriate protocol handler to establish a connection - * to a (possibly) remote service (eg, "http", "ftp") and to do protocol - * specific parsing of URL's. Refer to the URL class documentation for - * details on how that class locates and loads protocol handlers. - * <p> - * A protocol handler implementation should override the openConnection() - * method, and optionally override the parseURL() and toExternalForm() - * methods if necessary. (The default implementations will parse/write all - * URL's in the same form as http URL's). A protocol specific subclass - * of URLConnection will most likely need to be created as well. - * <p> - * Note that the instance methods in this class are called as if they - * were static methods. That is, a URL object to act on is passed with - * every call rather than the caller assuming the URL is stored in an - * instance variable of the "this" object. - * <p> - * The methods in this class are protected and accessible only to subclasses. - * URLStreamConnection objects are intended for use by the URL class only, - * not by other classes (unless those classes are implementing protocols). - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Warren Levy (warrenl@cygnus.com) - * - * @see URL - */ -public abstract class URLStreamHandler -{ - /** - * Creates a URLStreamHander - */ - public URLStreamHandler() - { - } - - /** - * Returns a URLConnection for the passed in URL. Note that this should - * not actually create the connection to the (possibly) remote host, but - * rather simply return a URLConnection object. The connect() method of - * URL connection is used to establish the actual connection, possibly - * after the caller sets up various connection options. - * - * @param url The URL to get a connection object for - * - * @return A URLConnection object for the given URL - * - * @exception IOException If an error occurs - */ - protected abstract URLConnection openConnection(URL url) - throws IOException; - - /** - * This method parses the string passed in as a URL and set's the - * instance data fields in the URL object passed in to the various values - * parsed out of the string. The start parameter is the position to start - * scanning the string. This is usually the position after the ":" which - * terminates the protocol name. The end parameter is the position to - * stop scanning. This will be either the end of the String, or the - * position of the "#" character, which separates the "file" portion of - * the URL from the "anchor" portion. - * <p> - * This method assumes URL's are formatted like http protocol URL's, so - * subclasses that implement protocols with URL's the follow a different - * syntax should override this method. The lone exception is that if - * the protocol name set in the URL is "file", this method will accept - * an empty hostname (i.e., "file:///"), which is legal for that protocol - * - * @param url The URL object in which to store the results - * @param spec The String-ized URL to parse - * @param start The position in the string to start scanning from - * @param end The position in the string to stop scanning - */ - protected void parseURL(URL url, String spec, int start, int end) - { - String host = url.getHost(); - int port = url.getPort(); - String file = url.getFile(); - String ref = url.getRef(); - String userInfo = url.getUserInfo(); - String authority = url.getAuthority(); - String query = null; - - // On Windows we need to change \ to / for file URLs - char separator = File.separatorChar; - if (url.getProtocol().equals("file") && separator != '/') - { - file = file.replace(separator, '/'); - spec = spec.replace(separator, '/'); - } - - if (spec.regionMatches(start, "//", 0, 2)) - { - String genuineHost; - int hostEnd; - int colon; - int at_host; - - start += 2; - int slash = spec.indexOf('/', start); - if (slash >= 0) - hostEnd = slash; - else - hostEnd = end; - - authority = host = spec.substring(start, hostEnd); - - // We first need a genuine host name (with userinfo). - // So we check for '@': if it's present check the port in the - // section after '@' in the other case check it in the full string. - // P.S.: We don't care having '@' at the beginning of the string. - if ((at_host = host.indexOf('@')) >= 0) - { - genuineHost = host.substring(at_host); - userInfo = host.substring(0, at_host); - } - else - genuineHost = host; - - // Look for optional port number. It is valid for the non-port - // part of the host name to be null (e.g. a URL "http://:80"). - // TBD: JDK 1.2 in this case sets host to null rather than ""; - // this is undocumented and likely an unintended side effect in 1.2 - // so we'll be simple here and stick with "". Note that - // "http://" or "http:///" produce a "" host in JDK 1.2. - if ((colon = genuineHost.indexOf(':')) >= 0) - { - try - { - port = Integer.parseInt(genuineHost.substring(colon + 1)); - } - catch (NumberFormatException e) - { - // Ignore invalid port values; port is already set to u's - // port. - } - - // Now we must cut the port number in the original string. - if (at_host >= 0) - host = host.substring(0, at_host + colon); - else - host = host.substring(0, colon); - } - file = null; - start = hostEnd; - } - else if (host == null) - host = ""; - - if (file == null || file.length() == 0 - || (start < end && spec.charAt(start) == '/')) - { - // No file context available; just spec for file. - // Or this is an absolute path name; ignore any file context. - file = spec.substring(start, end); - ref = null; - } - else if (start < end) - { - // Context is available, but only override it if there is a new file. - int lastSlash = file.lastIndexOf('/'); - if (lastSlash < 0) - file = spec.substring(start, end); - else - file = (file.substring(0, lastSlash) - + '/' + spec.substring(start, end)); - - // For URLs constructed relative to a context, we - // need to canonicalise the file path. - file = canonicalizeFilename(file); - - ref = null; - } - - if (ref == null) - { - // Normally there should be no '#' in the file part, - // but we are nice. - int hash = file.indexOf('#'); - if (hash != -1) - { - ref = file.substring(hash + 1, file.length()); - file = file.substring(0, hash); - } - } - - // We care about the query tag only if there is no reference at all. - if (ref == null) - { - int queryTag = file.indexOf('?'); - if (queryTag != -1) - { - query = file.substring(queryTag + 1); - file = file.substring(0, queryTag); - } - } - - // XXX - Classpath used to call PlatformHelper.toCanonicalForm() on - // the file part. It seems like overhead, but supposedly there is some - // benefit in windows based systems (it also lowercased the string). - setURL(url, url.getProtocol(), host, port, authority, userInfo, file, query, ref); - } - - /* - * Canonicalize a filename. - */ - private static String canonicalizeFilename(String file) - { - // XXX - GNU Classpath has an implementation that might be more appropriate - // for Windows based systems (gnu.java.io.PlatformHelper.toCanonicalForm) - int index; - - // Replace "/./" with "/". This probably isn't very efficient in - // the general case, but it's probably not bad most of the time. - while ((index = file.indexOf("/./")) >= 0) - file = file.substring(0, index) + file.substring(index + 2); - - // Process "/../" correctly. This probably isn't very efficient in - // the general case, but it's probably not bad most of the time. - while ((index = file.indexOf("/../")) >= 0) - { - // Strip of the previous directory - if it exists. - int previous = file.lastIndexOf('/', index - 1); - if (previous >= 0) - file = file.substring(0, previous) + file.substring(index + 3); - else - break; - } - return file; - } - - /** - * Compares two URLs, excluding the fragment component - * - * @param url1 The first url - * @param url2 The second url to compare with the first - * - * @return True if both URLs point to the same file, false otherwise. - * - * @specnote Now protected - */ - protected boolean sameFile(URL url1, URL url2) - { - if (url1 == url2) - return true; - - // This comparison is very conservative. It assumes that any - // field can be null. - if (url1 == null || url2 == null) - return false; - int p1 = url1.getPort(); - if (p1 == -1) - p1 = url1.ph.getDefaultPort(); - int p2 = url2.getPort(); - if (p2 == -1) - p2 = url2.ph.getDefaultPort(); - if (p1 != p2) - return false; - String s1; - String s2; - s1 = url1.getProtocol(); - s2 = url2.getProtocol(); - if (s1 != s2 && (s1 == null || ! s1.equals(s2))) - return false; - s1 = url1.getHost(); - s2 = url2.getHost(); - if (s1 != s2 && (s1 == null || ! s1.equals(s2))) - return false; - s1 = canonicalizeFilename(url1.getFile()); - s2 = canonicalizeFilename(url2.getFile()); - if (s1 != s2 && (s1 == null || ! s1.equals(s2))) - return false; - return true; - } - - /** - * This methods sets the instance variables representing the various fields - * of the URL to the values passed in. - * - * @param u The URL to modify - * @param protocol The protocol to set - * @param host The host name to et - * @param port The port number to set - * @param file The filename to set - * @param ref The reference - * - * @exception SecurityException If the protocol handler of the URL is - * different from this one - * - * @deprecated 1.2 Please use - * #setURL(URL,String,String,int,String,String,String,String); - */ - protected void setURL(URL u, String protocol, String host, int port, - String file, String ref) - { - u.set(protocol, host, port, file, ref); - } - - /** - * Sets the fields of the URL argument to the indicated values - * - * @param u The URL to modify - * @param protocol The protocol to set - * @param host The host name to set - * @param port The port number to set - * @param authority The authority to set - * @param userInfo The user information to set - * @param path The path/filename to set - * @param query The query part to set - * @param ref The reference - * - * @exception SecurityException If the protocol handler of the URL is - * different from this one - */ - protected void setURL(URL u, String protocol, String host, int port, - String authority, String userInfo, String path, - String query, String ref) - { - u.set(protocol, host, port, authority, userInfo, path, query, ref); - } - - /** - * Provides the default equals calculation. May be overidden by handlers for - * other protocols that have different requirements for equals(). This method - * requires that none of its arguments is null. This is guaranteed by the - * fact that it is only called by java.net.URL class. - * - * @param url1 An URL object - * @param url2 An URL object - * - * @return True if both given URLs are equal, false otherwise. - */ - protected boolean equals(URL url1, URL url2) - { - // This comparison is very conservative. It assumes that any - // field can be null. - return (url1.getPort() == url2.getPort() - && ((url1.getProtocol() == null && url2.getProtocol() == null) - || (url1.getProtocol() != null - && url1.getProtocol().equals(url2.getProtocol()))) - && ((url1.getUserInfo() == null && url2.getUserInfo() == null) - || (url1.getUserInfo() != null - && url1.getUserInfo().equals(url2.getUserInfo()))) - && ((url1.getAuthority() == null && url2.getAuthority() == null) - || (url1.getAuthority() != null - && url1.getAuthority().equals(url2.getAuthority()))) - && ((url1.getHost() == null && url2.getHost() == null) - || (url1.getHost() != null && url1.getHost().equals(url2.getHost()))) - && ((url1.getPath() == null && url2.getPath() == null) - || (url1.getPath() != null && url1.getPath().equals(url2.getPath()))) - && ((url1.getQuery() == null && url2.getQuery() == null) - || (url1.getQuery() != null - && url1.getQuery().equals(url2.getQuery()))) - && ((url1.getRef() == null && url2.getRef() == null) - || (url1.getRef() != null && url1.getRef().equals(url2.getRef())))); - } - - /** - * Compares the host components of two URLs. - * - * @param url1 The first URL. - * @param url2 The second URL. - * - * @return True if both URLs contain the same host. - * - * @exception UnknownHostException If an unknown host is found - */ - protected boolean hostsEqual(URL url1, URL url2) - { - InetAddress addr1 = getHostAddress(url1); - InetAddress addr2 = getHostAddress(url2); - - if (addr1 != null && addr2 != null) - return addr1.equals(addr2); - - String host1 = url1.getHost(); - String host2 = url2.getHost(); - - if (host1 != null && host2 != null) - return host1.equalsIgnoreCase(host2); - - return host1 == null && host2 == null; - } - - /** - * Get the IP address of our host. An empty host field or a DNS failure will - * result in a null return. - * - * @param url The URL to return the host address for. - * - * @return The address of the hostname in url. - */ - protected InetAddress getHostAddress(URL url) - { - String hostname = url.getHost(); - - if (hostname.equals("")) - return null; - - try - { - return InetAddress.getByName(hostname); - } - catch (UnknownHostException e) - { - return null; - } - } - - /** - * Returns the default port for a URL parsed by this handler. This method is - * meant to be overidden by handlers with default port numbers. - * - * @return The default port number. - */ - protected int getDefaultPort() - { - return -1; - } - - /** - * Provides the default hash calculation. May be overidden by handlers for - * other protocols that have different requirements for hashCode calculation. - * - * @param url The URL to calc the hashcode for. - * - * @return The hashcode for the given URL. - */ - protected int hashCode(URL url) - { - return url.getProtocol().hashCode() - + ((url.getHost() == null) ? 0 : url.getHost().hashCode()) - + url.getFile().hashCode() + url.getPort(); - } - - /** - * This method converts a URL object into a String. This method creates - * Strings in the mold of http URL's, so protocol handlers which use URL's - * that have a different syntax should override this method - * - * @param url The URL object to convert - * - * @return A string representation of the url - */ - protected String toExternalForm(URL url) - { - String protocol; - String file; - String ref; - String authority; - - protocol = url.getProtocol(); - authority = url.getAuthority(); - if (authority == null) - authority = ""; - - file = url.getFile(); - ref = url.getRef(); - - // Guess a reasonable size for the string buffer so we have to resize - // at most once. - int size = protocol.length() + authority.length() + file.length() + 24; - StringBuffer sb = new StringBuffer(size); - - if (protocol != null && protocol.length() > 0) - { - sb.append(protocol); - sb.append(":"); - } - - if (authority.length() != 0) - { - sb.append("//").append(authority); - } - - sb.append(file); - - if (ref != null) - sb.append('#').append(ref); - - return sb.toString(); - } -} diff --git a/libjava/java/net/URLStreamHandlerFactory.java b/libjava/java/net/URLStreamHandlerFactory.java deleted file mode 100644 index c92c71fb2b3..00000000000 --- a/libjava/java/net/URLStreamHandlerFactory.java +++ /dev/null @@ -1,65 +0,0 @@ -/* URLStreamHandlerFactory.java -- Maps protocols to URLStreamHandlers - Copyright (C) 1998, 1999, 2000, 2001, 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.net; - - -/** - * Written using on-line Java Platform 1.2 API Specification, as well - * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998). - * Status: Believed complete and correct. - */ -/** - * This interface contains one method which maps the protocol portion of - * a URL (eg, "http" in "http://www.urbanophile.com/arenn/") to a - * <code>URLStreamHandler</code> object. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Warren Levy (warrenl@cygnus.com) - */ -public interface URLStreamHandlerFactory -{ - /** - * This method maps the protocol portion of a URL to a - * <code>URLStreamHandler</code> object. - * - * @param protocol The protocol name to map ("http", "ftp", etc). - * - * @return The <code>URLStreamHandler</code> for the specified protocol - */ - URLStreamHandler createURLStreamHandler(String protocol); -} // interface URLStreamHandlerFactory diff --git a/libjava/java/net/UnknownHostException.java b/libjava/java/net/UnknownHostException.java deleted file mode 100644 index c5ba18330d3..00000000000 --- a/libjava/java/net/UnknownHostException.java +++ /dev/null @@ -1,77 +0,0 @@ -/* UnknownHostException.java -- The hostname is unknown - Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.net; - -import java.io.IOException; - - -/** - * This exception indicates that an attempt was made to reference a hostname - * or IP address that is not valid. This could possibly indicate that a - * DNS problem has occurred, but most often means that the host was not - * correctly specified. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Per Bothner - * @status updated to 1.4 - */ -public class UnknownHostException extends IOException -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = -4639126076052875403L; - - /** - * Create a new instance without a descriptive error message. - */ - public UnknownHostException() - { - } - - /** - * Create a new instance with a descriptive error message, such as the - * name of the host that could not be resolved. - * - * @param message a message describing the error that occurred - */ - public UnknownHostException(String message) - { - super(message); - } -} // class UnknownHostException diff --git a/libjava/java/net/UnknownServiceException.java b/libjava/java/net/UnknownServiceException.java deleted file mode 100644 index 65cc8f59225..00000000000 --- a/libjava/java/net/UnknownServiceException.java +++ /dev/null @@ -1,76 +0,0 @@ -/* UnknownServiceException.java -- A service error occurred - Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.net; - -import java.io.IOException; - - -/** - * Contrary to what you might think, this does not indicate that the - * TCP/IP service name specified was invalid. Instead it indicates that - * the MIME type returned from a URL could not be determined or that an - * attempt was made to write to a read-only URL. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Warren Levy (warrenl@cygnus.com) - * @status updated to 1.4 - */ -public class UnknownServiceException extends IOException -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = -4169033248853639508L; - - /** - * Create a new instance without a descriptive error message. - */ - public UnknownServiceException() - { - } - - /** - * Create a new instance with a descriptive error message. - * - * @param message a message describing the error that occurred - */ - public UnknownServiceException(String message) - { - super(message); - } -} // class UnknownServiceException diff --git a/libjava/java/nio/BufferOverflowException.java b/libjava/java/nio/BufferOverflowException.java deleted file mode 100644 index 588c03290a1..00000000000 --- a/libjava/java/nio/BufferOverflowException.java +++ /dev/null @@ -1,51 +0,0 @@ -/* BufferOverflowException.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.nio; - -/** - * @since 1.4 - */ -public class BufferOverflowException extends RuntimeException -{ - /** - * Creates the exception - */ - public BufferOverflowException () - { - } -} diff --git a/libjava/java/nio/BufferUnderflowException.java b/libjava/java/nio/BufferUnderflowException.java deleted file mode 100644 index 4b4161c647c..00000000000 --- a/libjava/java/nio/BufferUnderflowException.java +++ /dev/null @@ -1,51 +0,0 @@ -/* BufferUnderflowException.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.nio; - -/** - * @since 1.4 - */ -public class BufferUnderflowException extends RuntimeException -{ - /** - * Creates the exception - */ - public BufferUnderflowException () - { - } -} diff --git a/libjava/java/nio/ByteBuffer.java b/libjava/java/nio/ByteBuffer.java deleted file mode 100644 index 0ccf7663cfa..00000000000 --- a/libjava/java/nio/ByteBuffer.java +++ /dev/null @@ -1,651 +0,0 @@ -/* ByteBuffer.java -- - Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.nio; - -/** - * @since 1.4 - */ -public abstract class ByteBuffer extends Buffer - implements Comparable -{ - ByteOrder endian = ByteOrder.BIG_ENDIAN; - - int array_offset; - byte[] backing_buffer; - - ByteBuffer (int capacity, int limit, int position, int mark) - { - super (capacity, limit, position, mark); - } - - /** - * Allocates a new direct byte buffer. - */ - public static ByteBuffer allocateDirect (int capacity) - { - return DirectByteBufferImpl.allocate (capacity); - } - - /** - * Allocates a new <code>ByteBuffer</code> object with a given capacity. - */ - public static ByteBuffer allocate (int capacity) - { - return wrap(new byte[capacity], 0, capacity); - } - - /** - * Wraps a <code>byte</code> array into a <code>ByteBuffer</code> - * object. - * - * @exception IndexOutOfBoundsException If the preconditions on the offset - * and length parameters do not hold - */ - public static final ByteBuffer wrap (byte[] array, int offset, int length) - { - // FIXME: In GCJ and other implementations where arrays may not - // move we might consider, at least when offset==0: - // return new DirectByteBufferImpl(array, - // address_of_data(array) + offset, - // length, length, 0, false); - // This may be more efficient, mainly because we can then use the - // same logic for all ByteBuffers. - - return new ByteBufferImpl (array, 0, array.length, offset + length, offset, -1, false); - } - - /** - * Wraps a <code>byte</code> array into a <code>ByteBuffer</code> - * object. - */ - public static final ByteBuffer wrap (byte[] array) - { - return wrap (array, 0, array.length); - } - - /** - * This method transfers <code>byte</code>s from this buffer into the given - * destination array. Before the transfer, it checks if there are fewer than - * length <code>byte</code>s remaining in this buffer. - * - * @param dst The destination array - * @param offset The offset within the array of the first <code>byte</code> - * to be written; must be non-negative and no larger than dst.length. - * @param length The maximum number of bytes to be written to the given array; - * must be non-negative and no larger than dst.length - offset. - * - * @exception BufferUnderflowException If there are fewer than length - * <code>byte</code>s remaining in this buffer. - * @exception IndexOutOfBoundsException If the preconditions on the offset - * and length parameters do not hold. - */ - public ByteBuffer get (byte[] dst, int offset, int length) - { - checkArraySize(dst.length, offset, length); - checkForUnderflow(length); - - for (int i = offset; i < offset + length; i++) - { - dst [i] = get (); - } - - return this; - } - - /** - * This method transfers <code>byte</code>s from this buffer into the given - * destination array. - * - * @param dst The byte array to write into. - * - * @exception BufferUnderflowException If there are fewer than dst.length - * <code>byte</code>s remaining in this buffer. - */ - public ByteBuffer get (byte[] dst) - { - return get (dst, 0, dst.length); - } - - /** - * Writes the content of the the <code>ByteBUFFER</code> src - * into the buffer. Before the transfer, it checks if there is fewer than - * <code>src.remaining()</code> space remaining in this buffer. - * - * @param src The source data. - * - * @exception BufferOverflowException If there is insufficient space in this - * buffer for the remaining <code>byte</code>s in the source buffer. - * @exception IllegalArgumentException If the source buffer is this buffer. - * @exception ReadOnlyBufferException If this buffer is read-only. - */ - public ByteBuffer put (ByteBuffer src) - { - if (src == this) - throw new IllegalArgumentException (); - - checkForOverflow(src.remaining()); - - if (src.remaining () > 0) - { - byte[] toPut = new byte [src.remaining ()]; - src.get (toPut); - put (toPut); - } - - return this; - } - - /** - * Writes the content of the the <code>byte array</code> src - * into the buffer. Before the transfer, it checks if there is fewer than - * length space remaining in this buffer. - * - * @param src The array to copy into the buffer. - * @param offset The offset within the array of the first byte to be read; - * must be non-negative and no larger than src.length. - * @param length The number of bytes to be read from the given array; - * must be non-negative and no larger than src.length - offset. - * - * @exception BufferOverflowException If there is insufficient space in this - * buffer for the remaining <code>byte</code>s in the source array. - * @exception IndexOutOfBoundsException If the preconditions on the offset - * and length parameters do not hold - * @exception ReadOnlyBufferException If this buffer is read-only. - */ - public ByteBuffer put (byte[] src, int offset, int length) - { - checkArraySize(src.length, offset, length); - checkForOverflow(length); - - for (int i = offset; i < offset + length; i++) - put (src [i]); - - return this; - } - - /** - * Writes the content of the the <code>byte array</code> src - * into the buffer. - * - * @param src The array to copy into the buffer. - * - * @exception BufferOverflowException If there is insufficient space in this - * buffer for the remaining <code>byte</code>s in the source array. - * @exception ReadOnlyBufferException If this buffer is read-only. - */ - public final ByteBuffer put (byte[] src) - { - return put (src, 0, src.length); - } - - /** - * Tells whether ot not this buffer is backed by an accessible - * <code>byte</code> array. - */ - public final boolean hasArray () - { - return (backing_buffer != null - && !isReadOnly ()); - } - - /** - * Returns the <code>byte</code> array that backs this buffer. - * - * @exception ReadOnlyBufferException If this buffer is read-only. - * @exception UnsupportedOperationException If this buffer is not backed - * by an accessible array. - */ - public final byte[] array () - { - if (backing_buffer == null) - throw new UnsupportedOperationException (); - - checkIfReadOnly(); - - return backing_buffer; - } - - /** - * Returns the offset within this buffer's backing array of the first element. - * - * @exception ReadOnlyBufferException If this buffer is read-only. - * @exception UnsupportedOperationException If this buffer is not backed - * by an accessible array. - */ - public final int arrayOffset () - { - if (backing_buffer == null) - throw new UnsupportedOperationException (); - - checkIfReadOnly(); - - return array_offset; - } - - /** - * Calculates a hash code for this buffer. - * - * This is done with <code>int</code> arithmetic, - * where ** represents exponentiation, by this formula:<br> - * <code>s[position()] + 31 + (s[position()+1] + 30)*31**1 + ... + - * (s[limit()-1]+30)*31**(limit()-1)</code>. - * Where s is the buffer data. Note that the hashcode is dependent - * on buffer content, and therefore is not useful if the buffer - * content may change. - * - * @return the hash code - */ - public int hashCode () - { - int hashCode = get(position()) + 31; - int multiplier = 1; - for (int i = position() + 1; i < limit(); ++i) - { - multiplier *= 31; - hashCode += (get(i) + 30)*multiplier; - } - return hashCode; - } - - /** - * Checks if this buffer is equal to obj. - */ - public boolean equals (Object obj) - { - if (obj instanceof ByteBuffer) - { - return compareTo (obj) == 0; - } - - return false; - } - - /** - * Compares two <code>ByteBuffer</code> objects. - * - * @exception ClassCastException If obj is not an object derived from - * <code>ByteBuffer</code>. - */ - public int compareTo (Object obj) - { - ByteBuffer other = (ByteBuffer) obj; - - int num = Math.min(remaining(), other.remaining()); - int pos_this = position(); - int pos_other = other.position(); - - for (int count = 0; count < num; count++) - { - byte a = get(pos_this++); - byte b = other.get(pos_other++); - - if (a == b) - continue; - - if (a < b) - return -1; - - return 1; - } - - return remaining() - other.remaining(); - } - - /** - * Returns the byte order of this buffer. - */ - public final ByteOrder order () - { - return endian; - } - - /** - * Modifies this buffer's byte order. - */ - public final ByteBuffer order (ByteOrder endian) - { - this.endian = endian; - return this; - } - - /** - * Reads the <code>byte</code> at this buffer's current position, - * and then increments the position. - * - * @exception BufferUnderflowException If there are no remaining - * <code>byte</code>s in this buffer. - */ - public abstract byte get (); - - /** - * Writes the <code>byte</code> at this buffer's current position, - * and then increments the position. - * - * @exception BufferOverflowException If there no remaining - * <code>byte</code>s in this buffer. - * @exception ReadOnlyBufferException If this buffer is read-only. - */ - public abstract ByteBuffer put (byte b); - - /** - * Absolute get method. - * - * @exception IndexOutOfBoundsException If index is negative or not smaller - * than the buffer's limit. - */ - public abstract byte get (int index); - - /** - * Absolute put method. - * - * @exception IndexOutOfBoundsException If index is negative or not smaller - * than the buffer's limit. - * @exception ReadOnlyBufferException If this buffer is read-only. - */ - public abstract ByteBuffer put (int index, byte b); - - /** - * Compacts this buffer. - * - * @exception ReadOnlyBufferException If this buffer is read-only. - */ - public abstract ByteBuffer compact (); - - void shiftDown (int dst_offset, int src_offset, int count) - { - for (int i = 0; i < count; i++) - put(dst_offset + i, get(src_offset + i)); - } - - /** - * Tells whether or not this buffer is direct. - */ - public abstract boolean isDirect (); - - /** - * Creates a new <code>ByteBuffer</code> whose content is a shared - * subsequence of this buffer's content. - */ - public abstract ByteBuffer slice (); - - /** - * Creates a new <code>ByteBuffer</code> that shares this buffer's - * content. - */ - public abstract ByteBuffer duplicate (); - - /** - * Creates a new read-only <code>ByteBuffer</code> that shares this - * buffer's content. - */ - public abstract ByteBuffer asReadOnlyBuffer (); - - /** - * Creates a view of this byte buffer as a short buffer. - */ - public abstract ShortBuffer asShortBuffer (); - - /** - * Creates a view of this byte buffer as a char buffer. - */ - public abstract CharBuffer asCharBuffer (); - - /** - * Creates a view of this byte buffer as an integer buffer. - */ - public abstract IntBuffer asIntBuffer (); - - /** - * Creates a view of this byte buffer as a long buffer. - */ - public abstract LongBuffer asLongBuffer (); - - /** - * Creates a view of this byte buffer as a float buffer. - */ - public abstract FloatBuffer asFloatBuffer (); - - /** - * Creates a view of this byte buffer as a double buffer. - */ - public abstract DoubleBuffer asDoubleBuffer (); - - /** - * Relative get method for reading a character value. - * - * @exception BufferUnderflowException If there are fewer than two bytes - * remaining in this buffer. - */ - public abstract char getChar (); - - /** - * Relative put method for writing a character value. - * - * @exception BufferOverflowException If this buffer's current position is - * not smaller than its limit. - */ - public abstract ByteBuffer putChar (char value); - - /** - * Absolute get method for reading a character value. - * - * @exception IndexOutOfBoundsException If there are fewer than two bytes - * remaining in this buffer - */ - public abstract char getChar (int index); - - /** - * Absolute put method for writing a character value. - * - * @exception IndexOutOfBoundsException If index is negative or not smaller - * than the buffer's limit, minus one. - */ - public abstract ByteBuffer putChar (int index, char value); - - /** - * Relative get method for reading a short value. - * - * @exception BufferUnderflowException If index is negative or not smaller - * than the buffer's limit, minus one. - */ - public abstract short getShort (); - - /** - * Relative put method for writing a short value. - * - * @exception BufferOverflowException If this buffer's current position is - * not smaller than its limit. - */ - public abstract ByteBuffer putShort (short value); - - /** - * Absolute get method for reading a short value. - * - * @exception IndexOutOfBoundsException If there are fewer than two bytes - * remaining in this buffer - */ - public abstract short getShort (int index); - - /** - * Absolute put method for writing a short value. - * - * @exception IndexOutOfBoundsException If index is negative or not smaller - * than the buffer's limit, minus one. - */ - public abstract ByteBuffer putShort (int index, short value); - - /** - * Relative get method for reading an integer value. - * - * @exception BufferUnderflowException If there are fewer than four bytes - * remaining in this buffer. - */ - public abstract int getInt (); - - /** - * Relative put method for writing an integer value. - * - * @exception BufferOverflowException If this buffer's current position is - * not smaller than its limit. - */ - public abstract ByteBuffer putInt (int value); - - /** - * Absolute get method for reading an integer value. - * - * @exception IndexOutOfBoundsException If index is negative or not smaller - * than the buffer's limit, minus three. - */ - public abstract int getInt (int index); - - /** - * Absolute put method for writing an integer value. - * - * @exception IndexOutOfBoundsException If index is negative or not smaller - * than the buffer's limit, minus three. - */ - public abstract ByteBuffer putInt (int index, int value); - - /** - * Relative get method for reading a long value. - * - * @exception BufferUnderflowException If there are fewer than eight bytes - * remaining in this buffer. - */ - public abstract long getLong (); - - /** - * Relative put method for writing a long value. - * - * @exception BufferOverflowException If this buffer's current position is - * not smaller than its limit. - */ - public abstract ByteBuffer putLong (long value); - - /** - * Absolute get method for reading a long value. - * - * @exception IndexOutOfBoundsException If index is negative or not smaller - * than the buffer's limit, minus seven. - */ - public abstract long getLong (int index); - - /** - * Absolute put method for writing a float value. - * - * @exception IndexOutOfBoundsException If index is negative or not smaller - * than the buffer's limit, minus seven. - */ - public abstract ByteBuffer putLong (int index, long value); - - /** - * Relative get method for reading a float value. - * - * @exception BufferUnderflowException If there are fewer than four bytes - * remaining in this buffer. - */ - public abstract float getFloat (); - - /** - * Relative put method for writing a float value. - * - * @exception BufferOverflowException If there are fewer than four bytes - * remaining in this buffer. - */ - public abstract ByteBuffer putFloat (float value); - - /** - * Absolute get method for reading a float value. - * - * @exception IndexOutOfBoundsException If index is negative or not smaller - * than the buffer's limit, minus three. - */ - public abstract float getFloat (int index); - - /** - * Relative put method for writing a float value. - * - * @exception IndexOutOfBoundsException If index is negative or not smaller - * than the buffer's limit, minus three. - */ - public abstract ByteBuffer putFloat (int index, float value); - - /** - * Relative get method for reading a double value. - * - * @exception BufferUnderflowException If there are fewer than eight bytes - * remaining in this buffer. - */ - public abstract double getDouble (); - - /** - * Relative put method for writing a double value. - * - * @exception BufferOverflowException If this buffer's current position is - * not smaller than its limit. - */ - public abstract ByteBuffer putDouble (double value); - - /** - * Absolute get method for reading a double value. - * - * @exception IndexOutOfBoundsException If index is negative or not smaller - * than the buffer's limit, minus seven. - */ - public abstract double getDouble (int index); - - /** - * Absolute put method for writing a double value. - * - * @exception IndexOutOfBoundsException If index is negative or not smaller - * than the buffer's limit, minus seven. - */ - public abstract ByteBuffer putDouble (int index, double value); - - /** - * Returns a string summarizing the state of this buffer. - */ - public String toString () - { - return getClass ().getName () + - "[pos=" + position () + - " lim=" + limit () + - " cap=" + capacity () + "]"; - } -} diff --git a/libjava/java/nio/ByteBufferHelper.java b/libjava/java/nio/ByteBufferHelper.java deleted file mode 100644 index 6c46ca5d7ab..00000000000 --- a/libjava/java/nio/ByteBufferHelper.java +++ /dev/null @@ -1,344 +0,0 @@ -/* ByteBufferImpl.java -- - Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.nio; - -/** - * @author Michael Koch (konqueror@gmx.de) - */ -final class ByteBufferHelper -{ - public static char getChar (ByteBuffer buffer, ByteOrder order) - { - return (char) getShort (buffer, order); - } - - public static void putChar (ByteBuffer buffer, char value, ByteOrder order) - { - putShort (buffer, (short) value, order); - } - - public static char getChar (ByteBuffer buffer, int index, ByteOrder order) - { - return (char) getShort (buffer, index, order); - } - - public static void putChar (ByteBuffer buffer, int index, - char value, ByteOrder order) - { - putShort (buffer, index, (short) value, order); - } - - public static short getShort (ByteBuffer buffer, ByteOrder order) - { - buffer.checkForUnderflow(2); - - if (order == ByteOrder.LITTLE_ENDIAN) - { - return (short) ((buffer.get() & 0xff) - + (buffer.get() << 8)); - } - - return (short) ((buffer.get() << 8) - + (buffer.get() & 0xff)); - } - - public static void putShort (ByteBuffer buffer, short value, ByteOrder order) - { - buffer.checkForOverflow(2); - - if (order == ByteOrder.LITTLE_ENDIAN) - { - buffer.put ((byte) value); - buffer.put ((byte) (value >> 8)); - } - else - { - buffer.put ((byte) (value >> 8)); - buffer.put ((byte) value); - } - } - - public static short getShort (ByteBuffer buffer, - int index, ByteOrder order) - { - if (order == ByteOrder.LITTLE_ENDIAN) - { - return (short) ((buffer.get (index) & 0xff) - + (buffer.get (++index) << 8)); - } - - return (short) ((buffer.get (index) << 8) - + (buffer.get (++index) & 0xff)); - } - - public static void putShort (ByteBuffer buffer, int index, - short value, ByteOrder order) - { - if (order == ByteOrder.LITTLE_ENDIAN) - { - buffer.put (index, (byte) value); - buffer.put (++index, (byte) (value >> 8)); - } - else - { - buffer.put (index, (byte) (value >> 8)); - buffer.put (++index, (byte) value); - } - } - - public static int getInt (ByteBuffer buffer, ByteOrder order) - { - buffer.checkForUnderflow(4); - - if (order == ByteOrder.LITTLE_ENDIAN) - { - return ((buffer.get() & 0xff) - + ((buffer.get() & 0xff) << 8) - + ((buffer.get() & 0xff) << 16) - + (buffer.get() << 24)); - } - - return (int) ((buffer.get() << 24) - + ((buffer.get() & 0xff) << 16) - + ((buffer.get() & 0xff) << 8) - + (buffer.get() & 0xff)); - } - - public static void putInt (ByteBuffer buffer, int value, ByteOrder order) - { - buffer.checkForOverflow(4); - - if (order == ByteOrder.LITTLE_ENDIAN) - { - buffer.put ((byte) value); - buffer.put ((byte) (value >> 8)); - buffer.put ((byte) (value >> 16)); - buffer.put ((byte) (value >> 24)); - } - else - { - buffer.put ((byte) (value >> 24)); - buffer.put ((byte) (value >> 16)); - buffer.put ((byte) (value >> 8)); - buffer.put ((byte) value); - } - } - - public static int getInt (ByteBuffer buffer, int index, ByteOrder order) - { - if (order == ByteOrder.LITTLE_ENDIAN) - { - return ((buffer.get (index) & 0xff) - + ((buffer.get (++index) & 0xff) << 8) - + ((buffer.get (++index) & 0xff) << 16) - + (buffer.get (++index) << 24)); - } - - return ((buffer.get (index) << 24) - + ((buffer.get (++index) & 0xff) << 16) - + ((buffer.get (++index) & 0xff) << 8) - + (buffer.get (++index) & 0xff)); - } - - public static void putInt (ByteBuffer buffer, int index, - int value, ByteOrder order) - { - if (order == ByteOrder.LITTLE_ENDIAN) - { - buffer.put (index, (byte) value); - buffer.put (++index, (byte) (value >> 8)); - buffer.put (++index, (byte) (value >> 16)); - buffer.put (++index, (byte) (value >> 24)); - } - else - { - buffer.put (index, (byte) (value >> 24)); - buffer.put (++index, (byte) (value >> 16)); - buffer.put (++index, (byte) (value >> 8)); - buffer.put (++index, (byte) value); - } - } - - public static long getLong (ByteBuffer buffer, ByteOrder order) - { - buffer.checkForUnderflow(8); - - if (order == ByteOrder.LITTLE_ENDIAN) - { - return ((buffer.get() & 0xff) - + (((buffer.get() & 0xff)) << 8) - + (((buffer.get() & 0xff)) << 16) - + (((buffer.get() & 0xffL)) << 24) - + (((buffer.get() & 0xffL)) << 32) - + (((buffer.get() & 0xffL)) << 40) - + (((buffer.get() & 0xffL)) << 48) - + (((long) buffer.get()) << 56)); - } - - return ((((long) buffer.get()) << 56) - + ((buffer.get() & 0xffL) << 48) - + ((buffer.get() & 0xffL) << 40) - + ((buffer.get() & 0xffL) << 32) - + ((buffer.get() & 0xffL) << 24) - + ((buffer.get() & 0xff) << 16) - + ((buffer.get() & 0xff) << 8) - + (buffer.get() & 0xff)); - } - - public static void putLong (ByteBuffer buffer, long value, ByteOrder order) - { - buffer.checkForOverflow(8); - - if (order == ByteOrder.LITTLE_ENDIAN) - { - buffer.put ((byte) value); - buffer.put ((byte) (value >> 8)); - buffer.put ((byte) (value >> 16)); - buffer.put ((byte) (value >> 24)); - buffer.put ((byte) (value >> 32)); - buffer.put ((byte) (value >> 40)); - buffer.put ((byte) (value >> 48)); - buffer.put ((byte) (value >> 56)); - } - else - { - buffer.put ((byte) (value >> 56)); - buffer.put ((byte) (value >> 48)); - buffer.put ((byte) (value >> 40)); - buffer.put ((byte) (value >> 32)); - buffer.put ((byte) (value >> 24)); - buffer.put ((byte) (value >> 16)); - buffer.put ((byte) (value >> 8)); - buffer.put ((byte) value); - } - } - - public static long getLong (ByteBuffer buffer, int index, ByteOrder order) - { - if (order == ByteOrder.LITTLE_ENDIAN) - { - return ((buffer.get (index) & 0xff) - + ((buffer.get (++index) & 0xff) << 8) - + ((buffer.get (++index) & 0xff) << 16) - + ((buffer.get (++index) & 0xffL) << 24) - + ((buffer.get (++index) & 0xffL) << 32) - + ((buffer.get (++index) & 0xffL) << 40) - + ((buffer.get (++index) & 0xffL) << 48) - + (((long) buffer.get (++index)) << 56)); - } - - return ((((long) buffer.get (index)) << 56) - + ((buffer.get (++index) & 0xffL) << 48) - + ((buffer.get (++index) & 0xffL) << 40) - + ((buffer.get (++index) & 0xffL) << 32) - + ((buffer.get (++index) & 0xffL) << 24) - + ((buffer.get (++index) & 0xff) << 16) - + ((buffer.get (++index) & 0xff) << 8) - + (buffer.get (++index) & 0xff)); - } - - public static void putLong (ByteBuffer buffer, int index, - long value, ByteOrder order) - { - if (order == ByteOrder.LITTLE_ENDIAN) - { - buffer.put (index, (byte) value); - buffer.put (++index, (byte) (value >> 8)); - buffer.put (++index, (byte) (value >> 16)); - buffer.put (++index, (byte) (value >> 24)); - buffer.put (++index, (byte) (value >> 32)); - buffer.put (++index, (byte) (value >> 40)); - buffer.put (++index, (byte) (value >> 48)); - buffer.put (++index, (byte) (value >> 56)); - } - else - { - buffer.put (index, (byte) (value >> 56)); - buffer.put (++index, (byte) (value >> 48)); - buffer.put (++index, (byte) (value >> 40)); - buffer.put (++index, (byte) (value >> 32)); - buffer.put (++index, (byte) (value >> 24)); - buffer.put (++index, (byte) (value >> 16)); - buffer.put (++index, (byte) (value >> 8)); - buffer.put (++index, (byte) value); - } - } - - public static float getFloat (ByteBuffer buffer, ByteOrder order) - { - return Float.intBitsToFloat (getInt (buffer, order)); - } - - public static void putFloat (ByteBuffer buffer, float value, ByteOrder order) - { - putInt (buffer, Float.floatToRawIntBits (value), order); - } - - public static float getFloat (ByteBuffer buffer, int index, ByteOrder order) - { - return Float.intBitsToFloat (getInt (buffer, index, order)); - } - - public static void putFloat (ByteBuffer buffer, int index, - float value, ByteOrder order) - { - putInt (buffer, index, Float.floatToRawIntBits (value), order); - } - - public static double getDouble (ByteBuffer buffer, ByteOrder order) - { - return Double.longBitsToDouble (getLong (buffer, order)); - } - - public static void putDouble (ByteBuffer buffer, double value, ByteOrder order) - { - putLong (buffer, Double.doubleToRawLongBits (value), order); - } - - public static double getDouble (ByteBuffer buffer, int index, ByteOrder order) - { - return Double.longBitsToDouble (getLong (buffer, index, order)); - } - - public static void putDouble (ByteBuffer buffer, int index, - double value, ByteOrder order) - { - putLong (buffer, index, Double.doubleToRawLongBits (value), order); - } -} // ByteBufferHelper - diff --git a/libjava/java/nio/ByteBufferImpl.java b/libjava/java/nio/ByteBufferImpl.java deleted file mode 100644 index 48d7152000b..00000000000 --- a/libjava/java/nio/ByteBufferImpl.java +++ /dev/null @@ -1,379 +0,0 @@ -/* ByteBufferImpl.java -- - Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.nio; - -/** - * This is a Heap memory implementation - */ -final class ByteBufferImpl extends ByteBuffer -{ - private boolean readOnly; - - ByteBufferImpl (byte[] buffer, int offset, int capacity, int limit, int position, int mark, boolean readOnly) - { - super (capacity, limit, position, mark); - this.backing_buffer = buffer; - this.array_offset = offset; - this.readOnly = readOnly; - } - - public CharBuffer asCharBuffer () - { - return new CharViewBufferImpl (this, remaining() >> 1); - } - - public ShortBuffer asShortBuffer () - { - return new ShortViewBufferImpl (this, remaining() >> 1); - } - - public IntBuffer asIntBuffer () - { - return new IntViewBufferImpl (this, remaining() >> 2); - } - - public LongBuffer asLongBuffer () - { - return new LongViewBufferImpl (this, remaining() >> 3); - } - - public FloatBuffer asFloatBuffer () - { - return new FloatViewBufferImpl (this, remaining() >> 2); - } - - public DoubleBuffer asDoubleBuffer () - { - return new DoubleViewBufferImpl (this, remaining() >> 3); - } - - public boolean isReadOnly () - { - return readOnly; - } - - public ByteBuffer slice () - { - return new ByteBufferImpl (backing_buffer, array_offset + position (), remaining (), remaining (), 0, -1, isReadOnly ()); - } - - public ByteBuffer duplicate () - { - return new ByteBufferImpl (backing_buffer, array_offset, capacity (), limit (), position (), mark, isReadOnly ()); - } - - public ByteBuffer asReadOnlyBuffer () - { - return new ByteBufferImpl (backing_buffer, array_offset, capacity (), limit (), position (), mark, true); - } - - void shiftDown (int dst_offset, int src_offset, int count) - { - System.arraycopy(backing_buffer, array_offset + src_offset, - backing_buffer, array_offset + dst_offset, - count); - } - - public ByteBuffer compact () - { - checkIfReadOnly(); - mark = -1; - int pos = position(); - if (pos > 0) - { - int count = remaining(); - shiftDown(0, pos, count); - position(count); - limit(capacity()); - } - else - { - position(limit()); - limit(capacity()); - } - return this; - } - - public boolean isDirect () - { - return false; - } - - /** - * Reads the <code>byte</code> at this buffer's current position, - * and then increments the position. - * - * @exception BufferUnderflowException If there are no remaining - * <code>bytes</code> in this buffer. - */ - public byte get () - { - if (pos >= limit) - throw new BufferUnderflowException(); - - return backing_buffer [(pos++) + array_offset]; - } - - /** - * Bulk get - */ - public ByteBuffer get (byte[] dst, int offset, int length) - { - checkArraySize(dst.length, offset, length); - if ( (limit - pos) < length) // check for overflow - throw new BufferUnderflowException(); - - System.arraycopy(backing_buffer, pos + array_offset, - dst, offset, length); - pos += length; - - return this; - } - - /** - * Relative bulk put(), overloads the ByteBuffer impl. - */ - public ByteBuffer put (byte[] src, int offset, int length) - { - if ( (limit - pos) < length) // check for overflow - throw new BufferOverflowException(); - checkArraySize(src.length, offset, length); - - System.arraycopy(src, offset, backing_buffer, pos + array_offset, length); - pos += length; - - return this; - } - - /** - * Relative put method. Writes <code>value</code> to the next position - * in the buffer. - * - * @exception BufferOverflowException If there is no remaining - * space in this buffer. - * @exception ReadOnlyBufferException If this buffer is read-only. - */ - public ByteBuffer put (byte value) - { - if (readOnly) - throw new ReadOnlyBufferException(); - if (pos >= limit) - throw new BufferOverflowException(); - - backing_buffer [(pos++) + array_offset] = value; - return this; - } - - /** - * Absolute get method. Reads the <code>byte</code> at position - * <code>index</code>. - * - * @exception IndexOutOfBoundsException If index is negative or not smaller - * than the buffer's limit. - */ - public byte get (int index) - { - checkIndex(index); - - return backing_buffer [index + array_offset]; - } - - /** - * Absolute put method. Writes <code>value</code> to position - * <code>index</code> in the buffer. - * - * @exception IndexOutOfBoundsException If index is negative or not smaller - * than the buffer's limit. - * @exception ReadOnlyBufferException If this buffer is read-only. - */ - public ByteBuffer put (int index, byte value) - { - checkIfReadOnly(); - checkIndex(index); - - backing_buffer [index + array_offset] = value; - return this; - } - - public char getChar () - { - return ByteBufferHelper.getChar(this, order()); - } - - public ByteBuffer putChar (char value) - { - if (readOnly) - throw new ReadOnlyBufferException (); - if ( (limit-pos) < 2) - throw new BufferOverflowException(); - - if (endian == ByteOrder.LITTLE_ENDIAN) - { - backing_buffer [(pos++) + array_offset] = (byte)(value&0xFF); - backing_buffer [(pos++) + array_offset] = (byte)(value>>8); - } - else - { - backing_buffer [(pos++) + array_offset] = (byte)(value>>8); - backing_buffer [(pos++) + array_offset] = (byte)(value&0xFF); - } - return this; - } - - public char getChar (int index) - { - return ByteBufferHelper.getChar(this, index, order()); - } - - public ByteBuffer putChar (int index, char value) - { - ByteBufferHelper.putChar(this, index, value, order()); - return this; - } - - public short getShort () - { - return ByteBufferHelper.getShort(this, order()); - } - - public ByteBuffer putShort (short value) - { - ByteBufferHelper.putShort(this, value, order()); - return this; - } - - public short getShort (int index) - { - return ByteBufferHelper.getShort(this, index, order()); - } - - public ByteBuffer putShort (int index, short value) - { - ByteBufferHelper.putShort(this, index, value, order()); - return this; - } - - public int getInt () - { - return ByteBufferHelper.getInt(this, order()); - } - - public ByteBuffer putInt (int value) - { - ByteBufferHelper.putInt(this, value, order()); - return this; - } - - public int getInt (int index) - { - return ByteBufferHelper.getInt(this, index, order()); - } - - public ByteBuffer putInt (int index, int value) - { - ByteBufferHelper.putInt(this, index, value, order()); - return this; - } - - public long getLong () - { - return ByteBufferHelper.getLong(this, order()); - } - - public ByteBuffer putLong (long value) - { - ByteBufferHelper.putLong (this, value, order()); - return this; - } - - public long getLong (int index) - { - return ByteBufferHelper.getLong (this, index, order()); - } - - public ByteBuffer putLong (int index, long value) - { - ByteBufferHelper.putLong (this, index, value, order()); - return this; - } - - public float getFloat () - { - return ByteBufferHelper.getFloat (this, order()); - } - - public ByteBuffer putFloat (float value) - { - ByteBufferHelper.putFloat (this, value, order()); - return this; - } - - public float getFloat (int index) - { - return ByteBufferHelper.getFloat (this, index, order()); - } - - public ByteBuffer putFloat (int index, float value) - { - ByteBufferHelper.putFloat (this, index, value, order()); - return this; - } - - public double getDouble () - { - return ByteBufferHelper.getDouble (this, order()); - } - - public ByteBuffer putDouble (double value) - { - ByteBufferHelper.putDouble (this, value, order()); - return this; - } - - public double getDouble (int index) - { - return ByteBufferHelper.getDouble (this, index, order()); - } - - public ByteBuffer putDouble (int index, double value) - { - ByteBufferHelper.putDouble (this, index, value, order()); - return this; - } -} diff --git a/libjava/java/nio/ByteOrder.java b/libjava/java/nio/ByteOrder.java deleted file mode 100644 index 39a3ff893bd..00000000000 --- a/libjava/java/nio/ByteOrder.java +++ /dev/null @@ -1,82 +0,0 @@ -/* ByteOrder.java -- - Copyright (C) 2002, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.nio; - -/** - * @author Michael Koch (konqueror@gmx.de) - * @since 1.4 - */ -public final class ByteOrder -{ - /** - * Constant indicating big endian byte order. - */ - public static final ByteOrder BIG_ENDIAN = new ByteOrder(); - - /** - * Constant indicating little endian byte order. - */ - public static final ByteOrder LITTLE_ENDIAN = new ByteOrder(); - - /** - * Returns the native byte order of the platform currently running. - * - * @return the native byte order - */ - public static ByteOrder nativeOrder() - { - return (System.getProperty ("gnu.cpu.endian").equals("big") - ? BIG_ENDIAN : LITTLE_ENDIAN); - } - - /** - * Returns a string representation of the byte order. - * - * @return the string - */ - public String toString() - { - return this == BIG_ENDIAN ? "BIG_ENDIAN" : "LITTLE_ENDIAN"; - } - - // This class can only be instantiated here. - private ByteOrder() - { - } -} diff --git a/libjava/java/nio/CharBuffer.java b/libjava/java/nio/CharBuffer.java deleted file mode 100644 index 6551555e20b..00000000000 --- a/libjava/java/nio/CharBuffer.java +++ /dev/null @@ -1,508 +0,0 @@ -/* CharBuffer.java -- - Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.nio; - -/** - * @since 1.4 - */ -public abstract class CharBuffer extends Buffer - implements Comparable, CharSequence -{ - int array_offset; - char[] backing_buffer; - - CharBuffer (int capacity, int limit, int position, int mark) - { - super (capacity, limit, position, mark); - array_offset = 0; - } - - /** - * Allocates a new <code>CharBuffer</code> object with a given capacity. - */ - public static CharBuffer allocate (int capacity) - { - return new CharBufferImpl (capacity); - } - - /** - * Wraps a <code>char</code> array into a <code>CharBuffer</code> - * object. - * - * @param array the array to wrap - * @param offset the offset of the region in the array to wrap - * @param length the length of the region in the array to wrap - * - * @return a new <code>CharBuffer</code> object - * - * @exception IndexOutOfBoundsException If the preconditions on the offset - * and length parameters do not hold - */ - public static final CharBuffer wrap(char[] array, int offset, int length) - { - return new CharBufferImpl(array, 0, array.length, offset + length, offset, -1, false); - } - - /** - * Wraps a character sequence into a <code>CharBuffer</code> object. - * - * @param seq the sequence to wrap - * - * @return a new <code>CharBuffer</code> object - */ - public static final CharBuffer wrap(CharSequence seq) - { - return wrap(seq, 0, seq.length()); - } - - /** - * Wraps a character sequence into a <code>CharBuffer</code> object. - * - * @param seq the sequence to wrap - * @param start the index of the first character to wrap - * @param end the index of the first character not to wrap - * - * @return a new <code>CharBuffer</code> object - * - * @exception IndexOutOfBoundsException If the preconditions on the offset - * and length parameters do not hold - */ - public static final CharBuffer wrap(CharSequence seq, int start, int end) - { - // FIXME: implement better handling of java.lang.String. - // Probably share data with String via reflection. - - if ((start < 0) - || (start > seq.length()) - || (end < start) - || (end > (seq.length() - start))) - throw new IndexOutOfBoundsException(); - - int len = end - start; - char[] buffer = new char[len]; - - for (int i = 0; i < len; i++) - buffer[i] = seq.charAt(i + start); - - return wrap(buffer, 0, len).asReadOnlyBuffer(); - } - - /** - * Wraps a <code>char</code> array into a <code>CharBuffer</code> - * object. - * - * @param array the array to wrap - * - * @return a new <code>CharBuffer</code> object - */ - public static final CharBuffer wrap(char[] array) - { - return wrap(array, 0, array.length); - } - - /** - * This method transfers <code>char</code>s from this buffer into the given - * destination array. Before the transfer, it checks if there are fewer than - * length <code>char</code>s remaining in this buffer. - * - * @param dst The destination array - * @param offset The offset within the array of the first <code>char</code> - * to be written; must be non-negative and no larger than dst.length. - * @param length The maximum number of bytes to be written to the given array; - * must be non-negative and no larger than dst.length - offset. - * - * @exception BufferUnderflowException If there are fewer than length - * <code>char</code>s remaining in this buffer. - * @exception IndexOutOfBoundsException If the preconditions on the offset - * and length parameters do not hold. - */ - public CharBuffer get (char[] dst, int offset, int length) - { - checkArraySize(dst.length, offset, length); - checkForUnderflow(length); - - for (int i = offset; i < offset + length; i++) - { - dst [i] = get (); - } - - return this; - } - - /** - * This method transfers <code>char</code>s from this buffer into the given - * destination array. - * - * @param dst The byte array to write into. - * - * @exception BufferUnderflowException If there are fewer than dst.length - * <code>char</code>s remaining in this buffer. - */ - public CharBuffer get (char[] dst) - { - return get (dst, 0, dst.length); - } - - /** - * Writes the content of the the <code>CharBUFFER</code> src - * into the buffer. Before the transfer, it checks if there is fewer than - * <code>src.remaining()</code> space remaining in this buffer. - * - * @param src The source data. - * - * @exception BufferOverflowException If there is insufficient space in this - * buffer for the remaining <code>char</code>s in the source buffer. - * @exception IllegalArgumentException If the source buffer is this buffer. - * @exception ReadOnlyBufferException If this buffer is read-only. - */ - public CharBuffer put (CharBuffer src) - { - if (src == this) - throw new IllegalArgumentException (); - - checkForOverflow(src.remaining()); - - if (src.remaining () > 0) - { - char[] toPut = new char [src.remaining ()]; - src.get (toPut); - put (toPut); - } - - return this; - } - - /** - * Writes the content of the the <code>char array</code> src - * into the buffer. Before the transfer, it checks if there is fewer than - * length space remaining in this buffer. - * - * @param src The array to copy into the buffer. - * @param offset The offset within the array of the first byte to be read; - * must be non-negative and no larger than src.length. - * @param length The number of bytes to be read from the given array; - * must be non-negative and no larger than src.length - offset. - * - * @exception BufferOverflowException If there is insufficient space in this - * buffer for the remaining <code>char</code>s in the source array. - * @exception IndexOutOfBoundsException If the preconditions on the offset - * and length parameters do not hold - * @exception ReadOnlyBufferException If this buffer is read-only. - */ - public CharBuffer put (char[] src, int offset, int length) - { - checkArraySize(src.length, offset, length); - checkForOverflow(length); - - for (int i = offset; i < offset + length; i++) - put (src [i]); - - return this; - } - - /** - * Writes the content of the the <code>char array</code> src - * into the buffer. - * - * @param src The array to copy into the buffer. - * - * @exception BufferOverflowException If there is insufficient space in this - * buffer for the remaining <code>char</code>s in the source array. - * @exception ReadOnlyBufferException If this buffer is read-only. - */ - public final CharBuffer put (char[] src) - { - return put (src, 0, src.length); - } - - /** - * Tells whether ot not this buffer is backed by an accessible - * <code>char</code> array. - */ - public final boolean hasArray () - { - return (backing_buffer != null - && !isReadOnly ()); - } - - /** - * Returns the <code>char</code> array that backs this buffer. - * - * @exception ReadOnlyBufferException If this buffer is read-only. - * @exception UnsupportedOperationException If this buffer is not backed - * by an accessible array. - */ - public final char[] array () - { - if (backing_buffer == null) - throw new UnsupportedOperationException (); - - checkIfReadOnly(); - - return backing_buffer; - } - - /** - * Returns the offset within this buffer's backing array of the first element. - * - * @exception ReadOnlyBufferException If this buffer is read-only. - * @exception UnsupportedOperationException If this buffer is not backed - * by an accessible array. - */ - public final int arrayOffset () - { - if (backing_buffer == null) - throw new UnsupportedOperationException (); - - checkIfReadOnly(); - - return array_offset; - } - - /** - * Calculates a hash code for this buffer. - * - * This is done with int arithmetic, - * where ** represents exponentiation, by this formula:<br> - * <code>s[position()] + 31 + (s[position()+1] + 30)*31**1 + ... + - * (s[limit()-1]+30)*31**(limit()-1)</code>. - * Where s is the buffer data. Note that the hashcode is dependent - * on buffer content, and therefore is not useful if the buffer - * content may change. - */ - public int hashCode () - { - int hashCode = get(position()) + 31; - int multiplier = 1; - for (int i = position() + 1; i < limit(); ++i) - { - multiplier *= 31; - hashCode += (get(i) + 30)*multiplier; - } - return hashCode; - } - - /** - * Checks if this buffer is equal to obj. - */ - public boolean equals (Object obj) - { - if (obj instanceof CharBuffer) - { - return compareTo (obj) == 0; - } - - return false; - } - - /** - * Compares two <code>CharBuffer</code> objects. - * - * @exception ClassCastException If obj is not an object derived from - * <code>CharBuffer</code>. - */ - public int compareTo (Object obj) - { - CharBuffer other = (CharBuffer) obj; - - int num = Math.min(remaining(), other.remaining()); - int pos_this = position(); - int pos_other = other.position(); - - for (int count = 0; count < num; count++) - { - char a = get(pos_this++); - char b = other.get(pos_other++); - - if (a == b) - continue; - - if (a < b) - return -1; - - return 1; - } - - return remaining() - other.remaining(); - } - - /** - * Returns the byte order of this buffer. - */ - public abstract ByteOrder order (); - - /** - * Reads the <code>char</code> at this buffer's current position, - * and then increments the position. - * - * @exception BufferUnderflowException If there are no remaining - * <code>char</code>s in this buffer. - */ - public abstract char get (); - - /** - * Writes the <code>char</code> at this buffer's current position, - * and then increments the position. - * - * @exception BufferOverflowException If there no remaining - * <code>char</code>s in this buffer. - * @exception ReadOnlyBufferException If this buffer is read-only. - */ - public abstract CharBuffer put (char b); - - /** - * Absolute get method. - * - * @exception IndexOutOfBoundsException If index is negative or not smaller - * than the buffer's limit. - */ - public abstract char get (int index); - - /** - * Absolute put method. - * - * @exception IndexOutOfBoundsException If index is negative or not smaller - * than the buffer's limit. - * @exception ReadOnlyBufferException If this buffer is read-only. - */ - public abstract CharBuffer put (int index, char b); - - /** - * Compacts this buffer. - * - * @exception ReadOnlyBufferException If this buffer is read-only. - */ - public abstract CharBuffer compact (); - - /** - * Tells wether or not this buffer is direct. - */ - public abstract boolean isDirect (); - - /** - * Creates a new <code>CharBuffer</code> whose content is a shared - * subsequence of this buffer's content. - */ - public abstract CharBuffer slice (); - - /** - * Creates a new <code>CharBuffer</code> that shares this buffer's - * content. - */ - public abstract CharBuffer duplicate (); - - /** - * Creates a new read-only <code>CharBuffer</code> that shares this - * buffer's content. - */ - public abstract CharBuffer asReadOnlyBuffer (); - - /** - * Returns the remaining content of the buffer as a string. - */ - public String toString () - { - if (hasArray ()) - return new String (array (), position (), length ()); - - char[] buf = new char [length ()]; - int pos = position (); - get (buf, 0, buf.length); - position (pos); - return new String (buf); - } - - /** - * Returns the length of the remaining chars in this buffer. - */ - public final int length () - { - return remaining (); - } - - /** - * Creates a new character buffer that represents the specified subsequence - * of this buffer, relative to the current position. - * - * @exception IndexOutOfBoundsException If the preconditions on start and - * end do not hold. - */ - public abstract CharSequence subSequence (int start, int length); - - /** - * Relative put method. - * - * @exception BufferOverflowException If there is insufficient space in this - * buffer. - * @exception IndexOutOfBoundsException If the preconditions on the start - * and end parameters do not hold. - * @exception ReadOnlyBufferException If this buffer is read-only. - */ - public CharBuffer put (String str, int start, int length) - { - return put (str.toCharArray (), start, length); - } - - /** - * Relative put method. - * - * @exception BufferOverflowException If there is insufficient space in this - * buffer. - * @exception ReadOnlyBufferException If this buffer is read-only. - */ - public final CharBuffer put (String str) - { - return put (str.toCharArray (), 0, str.length ()); - } - - /** - * Returns the character at <code>position() + index</code>. - * - * @exception IndexOutOfBoundsException If index is negative not smaller than - * <code>remaining()</code>. - */ - public final char charAt (int index) - { - if (index < 0 - || index >= remaining ()) - throw new IndexOutOfBoundsException (); - - return get (position () + index); - } -} diff --git a/libjava/java/nio/CharBufferImpl.java b/libjava/java/nio/CharBufferImpl.java deleted file mode 100644 index 33f8dab983f..00000000000 --- a/libjava/java/nio/CharBufferImpl.java +++ /dev/null @@ -1,219 +0,0 @@ -/* CharBufferImpl.java -- - Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.nio; - -/** - * This is a Heap memory implementation - */ -final class CharBufferImpl extends CharBuffer -{ - private boolean readOnly; - - CharBufferImpl (int capacity) - { - this (new char [capacity], 0, capacity, capacity, 0, -1, false); - } - - CharBufferImpl (char[] buffer, int offset, int capacity, int limit, int position, int mark, boolean readOnly) - { - super (capacity, limit, position, mark); - this.backing_buffer = buffer; - this.array_offset = offset; - this.readOnly = readOnly; - } - - public CharBufferImpl (CharBufferImpl copy) - { - super (copy.capacity (), copy.limit (), copy.position (), 0); - backing_buffer = copy.backing_buffer; - array_offset = copy.array_offset; - readOnly = copy.isReadOnly (); - } - - public boolean isReadOnly () - { - return readOnly; - } - - public CharBuffer slice () - { - return new CharBufferImpl (backing_buffer, array_offset + position (), remaining (), remaining (), 0, -1, isReadOnly ()); - } - - public CharBuffer duplicate () - { - return new CharBufferImpl (backing_buffer, array_offset, capacity (), limit (), position (), mark, isReadOnly ()); - } - - public CharBuffer asReadOnlyBuffer () - { - return new CharBufferImpl (backing_buffer, array_offset, capacity (), limit (), position (), mark, true); - } - - public CharBuffer compact () - { - checkIfReadOnly(); - mark = -1; - int copied = 0; - - while (remaining () > 0) - { - put (copied, get ()); - copied++; - } - - position (copied); - limit(capacity()); - return this; - } - - public boolean isDirect () - { - return false; - } - - public CharSequence subSequence (int start, int end) - { - if (start < 0 - || start > length () - || end < start - || end > length ()) - throw new IndexOutOfBoundsException (); - - return new CharBufferImpl (backing_buffer, array_offset, capacity (), position () + end, position () + start, -1, isReadOnly ()); - } - - /** - * Reads the <code>char</code> at this buffer's current position, - * and then increments the position. - * - * @exception BufferUnderflowException If there are no remaining - * <code>char</code>s in this buffer. - */ - public char get () - { - if (pos >= limit) - throw new BufferUnderflowException(); - - return backing_buffer [(pos++) + array_offset]; - } - - /** - * Relative put method. Writes <code>value</code> to the next position - * in the buffer. - * - * @exception ReadOnlyBufferException If this buffer is read-only. - */ - public CharBuffer put (char value) - { - if (readOnly) - throw new ReadOnlyBufferException(); - if (pos >= limit) - throw new BufferOverflowException(); - - backing_buffer [(pos++) + array_offset] = value; - return this; - } - - /** - * Absolute get method. Reads the <code>char</code> at position - * <code>index</code>. - * - * @param index Position to read the <code>char</code> from. - * - * @exception IndexOutOfBoundsException If index is negative or not smaller - * than the buffer's limit. - */ - public char get (int index) - { - checkIndex(index); - - return backing_buffer [index + array_offset]; - } - - /** - * Bulk get, overloaded for speed. - */ - public CharBuffer get (char[] dst, int offset, int length) - { - checkArraySize(dst.length, offset, length); - checkForUnderflow(length); - - System.arraycopy(backing_buffer, pos + array_offset, - dst, offset, length); - pos += length; - return this; - } - - /** - * Bulk put, overloaded for speed. - */ - public CharBuffer put (char[] src, int offset, int length) - { - checkArraySize(src.length, offset, length); - checkForOverflow(length); - - System.arraycopy(src, offset, - backing_buffer, pos + array_offset, length); - pos += length; - return this; - } - - /** - * Absolute put method. Writes <code>value</code> to position - * <code>index</code> in the buffer. - * - * @exception IndexOutOfBoundsException If index is negative or not smaller - * than the buffer's limit. - * @exception ReadOnlyBufferException If this buffer is read-only. - */ - public CharBuffer put (int index, char value) - { - checkIndex(index); - checkIfReadOnly(); - - backing_buffer [index + array_offset] = value; - return this; - } - - public ByteOrder order () - { - return ByteOrder.nativeOrder (); - } -} diff --git a/libjava/java/nio/CharViewBufferImpl.java b/libjava/java/nio/CharViewBufferImpl.java deleted file mode 100644 index 31983154461..00000000000 --- a/libjava/java/nio/CharViewBufferImpl.java +++ /dev/null @@ -1,187 +0,0 @@ -/* CharViewBufferImpl.java -- - Copyright (C) 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.nio; - -class CharViewBufferImpl extends CharBuffer -{ - /** Position in bb (i.e. a byte offset) where this buffer starts. */ - private int offset; - private ByteBuffer bb; - private boolean readOnly; - private ByteOrder endian; - - CharViewBufferImpl (ByteBuffer bb, int capacity) - { - super (capacity, capacity, 0, -1); - this.bb = bb; - this.offset = bb.position(); - this.readOnly = bb.isReadOnly(); - this.endian = bb.order(); - if (bb.isDirect()) - this.address = VMDirectByteBuffer.adjustAddress(bb.address, offset); - } - - public CharViewBufferImpl (ByteBuffer bb, int offset, int capacity, - int limit, int position, int mark, - boolean readOnly, ByteOrder endian) - { - super (capacity, limit, position, mark); - this.bb = bb; - this.offset = offset; - this.readOnly = readOnly; - this.endian = endian; - if (bb.isDirect()) - this.address = VMDirectByteBuffer.adjustAddress(bb.address, offset); - } - - /** - * Reads the <code>char</code> at this buffer's current position, - * and then increments the position. - * - * @exception BufferUnderflowException If there are no remaining - * <code>char</code>s in this buffer. - */ - public char get () - { - int p = position(); - char result = ByteBufferHelper.getChar(bb, (p << 1) + offset, endian); - position(p + 1); - return result; - } - - /** - * Absolute get method. Reads the <code>char</code> at position - * <code>index</code>. - * - * @param index Position to read the <code>char</code> from. - * - * @exception IndexOutOfBoundsException If index is negative or not smaller - * than the buffer's limit. - */ - public char get (int index) - { - return ByteBufferHelper.getChar(bb, (index << 1) + offset, endian); - } - - public CharBuffer put (char value) - { - int p = position(); - ByteBufferHelper.putChar(bb, (p << 1) + offset, value, endian); - position(p + 1); - return this; - } - - public CharBuffer put (int index, char value) - { - ByteBufferHelper.putChar(bb, (index << 1) + offset, value, endian); - return this; - } - - public CharBuffer compact () - { - if (position () > 0) - { - int count = limit () - position (); - bb.shiftDown(offset, offset + 2 * position(), 2 * count); - position (count); - limit (capacity ()); - } - else - { - position(limit()); - limit(capacity()); - } - return this; - } - - public CharBuffer slice () - { - // Create a sliced copy of this object that shares its content. - return new CharViewBufferImpl (bb, (position () >> 1) + offset, - remaining (), remaining (), 0, -1, - isReadOnly (), endian); - } - - CharBuffer duplicate (boolean readOnly) - { - int pos = position(); - reset(); - int mark = position(); - position(pos); - return new CharViewBufferImpl (bb, offset, capacity(), limit(), - pos, mark, readOnly, endian); - } - - public CharBuffer duplicate () - { - return duplicate(readOnly); - } - - public CharBuffer asReadOnlyBuffer () - { - return duplicate(true); - } - - public CharSequence subSequence (int start, int end) - { - if (start < 0 - || end < start - || end > length ()) - throw new IndexOutOfBoundsException (); - - return new CharViewBufferImpl (bb, array_offset, capacity (), - position () + end, position () + start, - -1, isReadOnly (), endian); - } - - public boolean isReadOnly () - { - return readOnly; - } - - public boolean isDirect () - { - return bb.isDirect (); - } - - public ByteOrder order () - { - return endian; - } -} diff --git a/libjava/java/nio/DoubleBuffer.java b/libjava/java/nio/DoubleBuffer.java deleted file mode 100644 index 381bb716636..00000000000 --- a/libjava/java/nio/DoubleBuffer.java +++ /dev/null @@ -1,383 +0,0 @@ -/* DoubleBuffer.java -- - Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.nio; - -/** - * @since 1.4 - */ -public abstract class DoubleBuffer extends Buffer - implements Comparable -{ - int array_offset; - double[] backing_buffer; - - DoubleBuffer (int capacity, int limit, int position, int mark) - { - super (capacity, limit, position, mark); - array_offset = 0; - } - - /** - * Allocates a new <code>DoubleBuffer</code> object with a given capacity. - */ - public static DoubleBuffer allocate (int capacity) - { - return new DoubleBufferImpl (capacity); - } - - /** - * Wraps a <code>double</code> array into a <code>DoubleBuffer</code> - * object. - * - * @exception IndexOutOfBoundsException If the preconditions on the offset - * and length parameters do not hold - */ - public static final DoubleBuffer wrap (double[] array, int offset, int length) - { - return new DoubleBufferImpl (array, 0, array.length, offset + length, offset, -1, false); - } - - /** - * Wraps a <code>double</code> array into a <code>DoubleBuffer</code> - * object. - */ - public static final DoubleBuffer wrap (double[] array) - { - return wrap (array, 0, array.length); - } - - /** - * This method transfers <code>double</code>s from this buffer into the given - * destination array. Before the transfer, it checks if there are fewer than - * length <code>double</code>s remaining in this buffer. - * - * @param dst The destination array - * @param offset The offset within the array of the first <code>double</code> - * to be written; must be non-negative and no larger than dst.length. - * @param length The maximum number of bytes to be written to the given array; - * must be non-negative and no larger than dst.length - offset. - * - * @exception BufferUnderflowException If there are fewer than length - * <code>double</code>s remaining in this buffer. - * @exception IndexOutOfBoundsException If the preconditions on the offset - * and length parameters do not hold. - */ - public DoubleBuffer get (double[] dst, int offset, int length) - { - checkArraySize(dst.length, offset, length); - checkForUnderflow(length); - - for (int i = offset; i < offset + length; i++) - { - dst [i] = get (); - } - - return this; - } - - /** - * This method transfers <code>double</code>s from this buffer into the given - * destination array. - * - * @param dst The byte array to write into. - * - * @exception BufferUnderflowException If there are fewer than dst.length - * <code>double</code>s remaining in this buffer. - */ - public DoubleBuffer get (double[] dst) - { - return get (dst, 0, dst.length); - } - - /** - * Writes the content of the the <code>DoubleBUFFER</code> src - * into the buffer. Before the transfer, it checks if there is fewer than - * <code>src.remaining()</code> space remaining in this buffer. - * - * @param src The source data. - * - * @exception BufferOverflowException If there is insufficient space in this - * buffer for the remaining <code>double</code>s in the source buffer. - * @exception IllegalArgumentException If the source buffer is this buffer. - * @exception ReadOnlyBufferException If this buffer is read-only. - */ - public DoubleBuffer put (DoubleBuffer src) - { - if (src == this) - throw new IllegalArgumentException (); - - checkForOverflow(src.remaining ()); - - if (src.remaining () > 0) - { - double[] toPut = new double [src.remaining ()]; - src.get (toPut); - put (toPut); - } - - return this; - } - - /** - * Writes the content of the the <code>double array</code> src - * into the buffer. Before the transfer, it checks if there is fewer than - * length space remaining in this buffer. - * - * @param src The array to copy into the buffer. - * @param offset The offset within the array of the first byte to be read; - * must be non-negative and no larger than src.length. - * @param length The number of bytes to be read from the given array; - * must be non-negative and no larger than src.length - offset. - * - * @exception BufferOverflowException If there is insufficient space in this - * buffer for the remaining <code>double</code>s in the source array. - * @exception IndexOutOfBoundsException If the preconditions on the offset - * and length parameters do not hold - * @exception ReadOnlyBufferException If this buffer is read-only. - */ - public DoubleBuffer put (double[] src, int offset, int length) - { - checkArraySize(src.length, offset, length); - checkForOverflow(length); - - for (int i = offset; i < offset + length; i++) - put (src [i]); - - return this; - } - - /** - * Writes the content of the the <code>double array</code> src - * into the buffer. - * - * @param src The array to copy into the buffer. - * - * @exception BufferOverflowException If there is insufficient space in this - * buffer for the remaining <code>double</code>s in the source array. - * @exception ReadOnlyBufferException If this buffer is read-only. - */ - public final DoubleBuffer put (double[] src) - { - return put (src, 0, src.length); - } - - /** - * Tells whether ot not this buffer is backed by an accessible - * <code>double</code> array. - */ - public final boolean hasArray () - { - return (backing_buffer != null - && !isReadOnly ()); - } - - /** - * Returns the <code>double</code> array that backs this buffer. - * - * @exception ReadOnlyBufferException If this buffer is read-only. - * @exception UnsupportedOperationException If this buffer is not backed - * by an accessible array. - */ - public final double[] array () - { - if (backing_buffer == null) - throw new UnsupportedOperationException (); - - checkIfReadOnly(); - - return backing_buffer; - } - - /** - * Returns the offset within this buffer's backing array of the first element. - * - * @exception ReadOnlyBufferException If this buffer is read-only. - * @exception UnsupportedOperationException If this buffer is not backed - * by an accessible array. - */ - public final int arrayOffset () - { - if (backing_buffer == null) - throw new UnsupportedOperationException (); - - checkIfReadOnly(); - - return array_offset; - } - - /** - * Calculates a hash code for this buffer. - * - * This is done with <code>long</code> arithmetic, - * where ** represents exponentiation, by this formula:<br> - * <code>s[position()] + 31 + (s[position()+1] + 30)*31**1 + ... + - * (s[limit()-1]+30)*31**(limit()-1)</code>. - * Where s is the buffer data, in Double.doubleToLongBits() form - * Note that the hashcode is dependent on buffer content, - * and therefore is not useful if the buffer content may change. - * - * @return the hash code (casted to int) - */ - public int hashCode () - { - long hashCode = Double.doubleToLongBits(get(position())) + 31; - long multiplier = 1; - for (int i = position() + 1; i < limit(); ++i) - { - multiplier *= 31; - hashCode += (Double.doubleToLongBits(get(i)) + 30)*multiplier; - } - return ((int)hashCode); - } - - /** - * Checks if this buffer is equal to obj. - */ - public boolean equals (Object obj) - { - if (obj instanceof DoubleBuffer) - { - return compareTo (obj) == 0; - } - - return false; - } - - /** - * Compares two <code>DoubleBuffer</code> objects. - * - * @exception ClassCastException If obj is not an object derived from - * <code>DoubleBuffer</code>. - */ - public int compareTo (Object obj) - { - DoubleBuffer other = (DoubleBuffer) obj; - - int num = Math.min(remaining(), other.remaining()); - int pos_this = position(); - int pos_other = other.position(); - - for (int count = 0; count < num; count++) - { - double a = get(pos_this++); - double b = other.get(pos_other++); - - if (a == b) - continue; - - if (a < b) - return -1; - - return 1; - } - - return remaining() - other.remaining(); - } - - /** - * Returns the byte order of this buffer. - */ - public abstract ByteOrder order (); - - /** - * Reads the <code>double</code> at this buffer's current position, - * and then increments the position. - * - * @exception BufferUnderflowException If there are no remaining - * <code>double</code>s in this buffer. - */ - public abstract double get (); - - /** - * Writes the <code>double</code> at this buffer's current position, - * and then increments the position. - * - * @exception BufferOverflowException If there no remaining - * <code>double</code>s in this buffer. - * @exception ReadOnlyBufferException If this buffer is read-only. - */ - public abstract DoubleBuffer put (double b); - - /** - * Absolute get method. - * - * @exception IndexOutOfBoundsException If index is negative or not smaller - * than the buffer's limit. - */ - public abstract double get (int index); - - /** - * Absolute put method. - * - * @exception IndexOutOfBoundsException If index is negative or not smaller - * than the buffer's limit. - * @exception ReadOnlyBufferException If this buffer is read-only. - */ - public abstract DoubleBuffer put (int index, double b); - - /** - * Compacts this buffer. - * - * @exception ReadOnlyBufferException If this buffer is read-only. - */ - public abstract DoubleBuffer compact (); - - /** - * Tells wether or not this buffer is direct. - */ - public abstract boolean isDirect (); - - /** - * Creates a new <code>DoubleBuffer</code> whose content is a shared - * subsequence of this buffer's content. - */ - public abstract DoubleBuffer slice (); - - /** - * Creates a new <code>DoubleBuffer</code> that shares this buffer's - * content. - */ - public abstract DoubleBuffer duplicate (); - - /** - * Creates a new read-only <code>DoubleBuffer</code> that shares this - * buffer's content. - */ - public abstract DoubleBuffer asReadOnlyBuffer (); -} diff --git a/libjava/java/nio/DoubleBufferImpl.java b/libjava/java/nio/DoubleBufferImpl.java deleted file mode 100644 index 248ab45e7c2..00000000000 --- a/libjava/java/nio/DoubleBufferImpl.java +++ /dev/null @@ -1,172 +0,0 @@ -/* DoubleBufferImpl.java -- - Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.nio; - -/** - * This is a Heap memory implementation - */ -final class DoubleBufferImpl extends DoubleBuffer -{ - private boolean readOnly; - - DoubleBufferImpl (int capacity) - { - this (new double [capacity], 0, capacity, capacity, 0, -1, false); - } - - DoubleBufferImpl (double[] buffer, int offset, int capacity, int limit, int position, int mark, boolean readOnly) - { - super (capacity, limit, position, mark); - this.backing_buffer = buffer; - this.array_offset = offset; - this.readOnly = readOnly; - } - - public boolean isReadOnly () - { - return readOnly; - } - - public DoubleBuffer slice () - { - return new DoubleBufferImpl (backing_buffer, array_offset + position (), remaining (), remaining (), 0, -1, isReadOnly ()); - } - - public DoubleBuffer duplicate () - { - return new DoubleBufferImpl (backing_buffer, array_offset, capacity (), limit (), position (), mark, isReadOnly ()); - } - - public DoubleBuffer asReadOnlyBuffer () - { - return new DoubleBufferImpl (backing_buffer, array_offset, capacity (), limit (), position (), mark, true); - } - - public DoubleBuffer compact () - { - checkIfReadOnly(); - mark = -1; - int copied = 0; - - while (remaining () > 0) - { - put (copied, get ()); - copied++; - } - - position (copied); - limit(capacity()); - return this; - } - - public boolean isDirect () - { - return false; - } - - /** - * Reads the <code>double</code> at this buffer's current position, - * and then increments the position. - * - * @exception BufferUnderflowException If there are no remaining - * <code>double</code>s in this buffer. - */ - public double get () - { - checkForUnderflow(); - - double result = backing_buffer [position ()]; - position (position () + 1); - return result; - } - - /** - * Relative put method. Writes <code>value</code> to the next position - * in the buffer. - * - * @exception BufferOverflowException If there no remaining - * space in this buffer. - * @exception ReadOnlyBufferException If this buffer is read-only. - */ - public DoubleBuffer put (double value) - { - checkIfReadOnly(); - checkForOverflow(); - - backing_buffer [position ()] = value; - position (position () + 1); - return this; - } - - /** - * Absolute get method. Reads the <code>double</code> at position - * <code>index</code>. - * - * @exception IndexOutOfBoundsException If index is negative or not smaller - * than the buffer's limit. - */ - public double get (int index) - { - checkIndex(index); - - return backing_buffer [index]; - } - - /** - * Absolute put method. Writes <code>value</code> to position - * <code>index</code> in the buffer. - * - * @exception IndexOutOfBoundsException If index is negative or not smaller - * than the buffer's limit. - * @exception ReadOnlyBufferException If this buffer is read-only. - */ - public DoubleBuffer put (int index, double value) - { - checkIfReadOnly(); - checkIndex(index); - - backing_buffer [index] = value; - return this; - } - - public ByteOrder order () - { - return ByteOrder.nativeOrder (); - } -} diff --git a/libjava/java/nio/DoubleViewBufferImpl.java b/libjava/java/nio/DoubleViewBufferImpl.java deleted file mode 100644 index e860f2f808d..00000000000 --- a/libjava/java/nio/DoubleViewBufferImpl.java +++ /dev/null @@ -1,172 +0,0 @@ -/* DoubleViewBufferImpl.java -- - Copyright (C) 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.nio; - -final class DoubleViewBufferImpl extends DoubleBuffer -{ - /** Position in bb (i.e. a byte offset) where this buffer starts. */ - private int offset; - private ByteBuffer bb; - private boolean readOnly; - private ByteOrder endian; - - DoubleViewBufferImpl (ByteBuffer bb, int capacity) - { - super (capacity, capacity, 0, -1); - this.bb = bb; - this.offset = bb.position(); - this.readOnly = bb.isReadOnly(); - this.endian = bb.order(); - if (bb.isDirect()) - this.address = VMDirectByteBuffer.adjustAddress(bb.address, offset); - } - - public DoubleViewBufferImpl (ByteBuffer bb, int offset, int capacity, - int limit, int position, int mark, - boolean readOnly, ByteOrder endian) - { - super (capacity, limit, position, mark); - this.bb = bb; - this.offset = offset; - this.readOnly = readOnly; - this.endian = endian; - if (bb.isDirect()) - this.address = VMDirectByteBuffer.adjustAddress(bb.address, offset); - } - - /** - * Reads the <code>double</code> at this buffer's current position, - * and then increments the position. - * - * @exception BufferUnderflowException If there are no remaining - * <code>double</code>s in this buffer. - */ - public double get () - { - int p = position(); - double result = ByteBufferHelper.getDouble(bb, (p << 3) + offset, endian); - position(p + 1); - return result; - } - - /** - * Absolute get method. Reads the <code>double</code> at position - * <code>index</code>. - * - * @exception IndexOutOfBoundsException If index is negative or not smaller - * than the buffer's limit. - */ - public double get (int index) - { - return ByteBufferHelper.getDouble(bb, (index << 3) + offset, endian); - } - - public DoubleBuffer put (double value) - { - int p = position(); - ByteBufferHelper.putDouble(bb, (p << 3) + offset, value, endian); - position(p + 1); - return this; - } - - public DoubleBuffer put (int index, double value) - { - ByteBufferHelper.putDouble(bb, (index << 3) + offset, value, endian); - return this; - } - - public DoubleBuffer compact () - { - if (position () > 0) - { - int count = limit () - position (); - bb.shiftDown(offset, offset + 8 * position(), 8 * count); - position (count); - limit (capacity ()); - } - else - { - position(limit()); - limit(capacity()); - } - return this; - } - - public DoubleBuffer slice () - { - return new DoubleViewBufferImpl (bb, (position () >> 3) + offset, - remaining(), remaining(), 0, -1, - readOnly, endian); - } - - DoubleBuffer duplicate (boolean readOnly) - { - int pos = position(); - reset(); - int mark = position(); - position(pos); - return new DoubleViewBufferImpl (bb, offset, capacity(), limit(), - pos, mark, readOnly, endian); - } - - public DoubleBuffer duplicate () - { - return duplicate(readOnly); - } - - public DoubleBuffer asReadOnlyBuffer () - { - return duplicate(true); - } - - public boolean isReadOnly () - { - return readOnly; - } - - public boolean isDirect () - { - return bb.isDirect (); - } - - public ByteOrder order () - { - return endian; - } -} diff --git a/libjava/java/nio/FloatBuffer.java b/libjava/java/nio/FloatBuffer.java deleted file mode 100644 index 8042333cbac..00000000000 --- a/libjava/java/nio/FloatBuffer.java +++ /dev/null @@ -1,383 +0,0 @@ -/* FloatBuffer.java -- - Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.nio; - -/** - * @since 1.4 - */ -public abstract class FloatBuffer extends Buffer - implements Comparable -{ - int array_offset; - float[] backing_buffer; - - FloatBuffer (int capacity, int limit, int position, int mark) - { - super (capacity, limit, position, mark); - array_offset = 0; - } - - /** - * Allocates a new <code>FloatBuffer</code> object with a given capacity. - */ - public static FloatBuffer allocate (int capacity) - { - return new FloatBufferImpl (capacity); - } - - /** - * Wraps a <code>float</code> array into a <code>FloatBuffer</code> - * object. - * - * @exception IndexOutOfBoundsException If the preconditions on the offset - * and length parameters do not hold - */ - public static final FloatBuffer wrap (float[] array, int offset, int length) - { - return new FloatBufferImpl (array, 0, array.length, offset + length, offset, -1, false); - } - - /** - * Wraps a <code>float</code> array into a <code>FloatBuffer</code> - * object. - */ - public static final FloatBuffer wrap (float[] array) - { - return wrap (array, 0, array.length); - } - - /** - * This method transfers <code>float</code>s from this buffer into the given - * destination array. Before the transfer, it checks if there are fewer than - * length <code>float</code>s remaining in this buffer. - * - * @param dst The destination array - * @param offset The offset within the array of the first <code>float</code> - * to be written; must be non-negative and no larger than dst.length. - * @param length The maximum number of bytes to be written to the given array; - * must be non-negative and no larger than dst.length - offset. - * - * @exception BufferUnderflowException If there are fewer than length - * <code>float</code>s remaining in this buffer. - * @exception IndexOutOfBoundsException If the preconditions on the offset - * and length parameters do not hold. - */ - public FloatBuffer get (float[] dst, int offset, int length) - { - checkArraySize(dst.length, offset, length); - checkForUnderflow(length); - - for (int i = offset; i < offset + length; i++) - { - dst [i] = get (); - } - - return this; - } - - /** - * This method transfers <code>float</code>s from this buffer into the given - * destination array. - * - * @param dst The byte array to write into. - * - * @exception BufferUnderflowException If there are fewer than dst.length - * <code>float</code>s remaining in this buffer. - */ - public FloatBuffer get (float[] dst) - { - return get (dst, 0, dst.length); - } - - /** - * Writes the content of the the <code>FloatBUFFER</code> src - * into the buffer. Before the transfer, it checks if there is fewer than - * <code>src.remaining()</code> space remaining in this buffer. - * - * @param src The source data. - * - * @exception BufferOverflowException If there is insufficient space in this - * buffer for the remaining <code>float</code>s in the source buffer. - * @exception IllegalArgumentException If the source buffer is this buffer. - * @exception ReadOnlyBufferException If this buffer is read-only. - */ - public FloatBuffer put (FloatBuffer src) - { - if (src == this) - throw new IllegalArgumentException (); - - checkForOverflow(src.remaining()); - - if (src.remaining () > 0) - { - float[] toPut = new float [src.remaining ()]; - src.get (toPut); - put (toPut); - } - - return this; - } - - /** - * Writes the content of the the <code>float array</code> src - * into the buffer. Before the transfer, it checks if there is fewer than - * length space remaining in this buffer. - * - * @param src The array to copy into the buffer. - * @param offset The offset within the array of the first byte to be read; - * must be non-negative and no larger than src.length. - * @param length The number of bytes to be read from the given array; - * must be non-negative and no larger than src.length - offset. - * - * @exception BufferOverflowException If there is insufficient space in this - * buffer for the remaining <code>float</code>s in the source array. - * @exception IndexOutOfBoundsException If the preconditions on the offset - * and length parameters do not hold - * @exception ReadOnlyBufferException If this buffer is read-only. - */ - public FloatBuffer put (float[] src, int offset, int length) - { - checkArraySize(src.length, offset, length); - checkForOverflow(length); - - for (int i = offset; i < offset + length; i++) - put (src [i]); - - return this; - } - - /** - * Writes the content of the the <code>float array</code> src - * into the buffer. - * - * @param src The array to copy into the buffer. - * - * @exception BufferOverflowException If there is insufficient space in this - * buffer for the remaining <code>float</code>s in the source array. - * @exception ReadOnlyBufferException If this buffer is read-only. - */ - public final FloatBuffer put (float[] src) - { - return put (src, 0, src.length); - } - - /** - * Tells whether ot not this buffer is backed by an accessible - * <code>float</code> array. - */ - public final boolean hasArray () - { - return (backing_buffer != null - && !isReadOnly ()); - } - - /** - * Returns the <code>float</code> array that backs this buffer. - * - * @exception ReadOnlyBufferException If this buffer is read-only. - * @exception UnsupportedOperationException If this buffer is not backed - * by an accessible array. - */ - public final float[] array () - { - if (backing_buffer == null) - throw new UnsupportedOperationException (); - - checkIfReadOnly(); - - return backing_buffer; - } - - /** - * Returns the offset within this buffer's backing array of the first element. - * - * @exception ReadOnlyBufferException If this buffer is read-only. - * @exception UnsupportedOperationException If this buffer is not backed - * by an accessible array. - */ - public final int arrayOffset () - { - if (backing_buffer == null) - throw new UnsupportedOperationException (); - - checkIfReadOnly(); - - return array_offset; - } - - /** - * Calculates a hash code for this buffer. - * - * This is done with <code>int</code> arithmetic, - * where ** represents exponentiation, by this formula:<br> - * <code>s[position()] + 31 + (s[position()+1] + 30)*31**1 + ... + - * (s[limit()-1]+30)*31**(limit()-1)</code>. - * Where s is the buffer data, in Float.floatToIntBits() form - * Note that the hashcode is dependent on buffer content, - * and therefore is not useful if the buffer content may change. - * - * @return the hash code - */ - public int hashCode () - { - int hashCode = Float.floatToIntBits(get(position())) + 31; - int multiplier = 1; - for (int i = position() + 1; i < limit(); ++i) - { - multiplier *= 31; - hashCode += (Float.floatToIntBits(get(i)) + 30)*multiplier; - } - return hashCode; - } - - /** - * Checks if this buffer is equal to obj. - */ - public boolean equals (Object obj) - { - if (obj instanceof FloatBuffer) - { - return compareTo (obj) == 0; - } - - return false; - } - - /** - * Compares two <code>FloatBuffer</code> objects. - * - * @exception ClassCastException If obj is not an object derived from - * <code>FloatBuffer</code>. - */ - public int compareTo (Object obj) - { - FloatBuffer other = (FloatBuffer) obj; - - int num = Math.min(remaining(), other.remaining()); - int pos_this = position(); - int pos_other = other.position(); - - for (int count = 0; count < num; count++) - { - float a = get(pos_this++); - float b = other.get(pos_other++); - - if (a == b) - continue; - - if (a < b) - return -1; - - return 1; - } - - return remaining() - other.remaining(); - } - - /** - * Returns the byte order of this buffer. - */ - public abstract ByteOrder order (); - - /** - * Reads the <code>float</code> at this buffer's current position, - * and then increments the position. - * - * @exception BufferUnderflowException If there are no remaining - * <code>float</code>s in this buffer. - */ - public abstract float get (); - - /** - * Writes the <code>float</code> at this buffer's current position, - * and then increments the position. - * - * @exception BufferOverflowException If there no remaining - * <code>float</code>s in this buffer. - * @exception ReadOnlyBufferException If this buffer is read-only. - */ - public abstract FloatBuffer put (float b); - - /** - * Absolute get method. - * - * @exception IndexOutOfBoundsException If index is negative or not smaller - * than the buffer's limit. - */ - public abstract float get (int index); - - /** - * Absolute put method. - * - * @exception IndexOutOfBoundsException If index is negative or not smaller - * than the buffer's limit. - * @exception ReadOnlyBufferException If this buffer is read-only. - */ - public abstract FloatBuffer put (int index, float b); - - /** - * Compacts this buffer. - * - * @exception ReadOnlyBufferException If this buffer is read-only. - */ - public abstract FloatBuffer compact (); - - /** - * Tells wether or not this buffer is direct. - */ - public abstract boolean isDirect (); - - /** - * Creates a new <code>FloatBuffer</code> whose content is a shared - * subsequence of this buffer's content. - */ - public abstract FloatBuffer slice (); - - /** - * Creates a new <code>FloatBuffer</code> that shares this buffer's - * content. - */ - public abstract FloatBuffer duplicate (); - - /** - * Creates a new read-only <code>FloatBuffer</code> that shares this - * buffer's content. - */ - public abstract FloatBuffer asReadOnlyBuffer (); -} diff --git a/libjava/java/nio/FloatBufferImpl.java b/libjava/java/nio/FloatBufferImpl.java deleted file mode 100644 index b4868780c42..00000000000 --- a/libjava/java/nio/FloatBufferImpl.java +++ /dev/null @@ -1,172 +0,0 @@ -/* FloatBufferImpl.java -- - Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.nio; - -/** - * This is a Heap memory implementation - */ -final class FloatBufferImpl extends FloatBuffer -{ - private boolean readOnly; - - FloatBufferImpl (int capacity) - { - this (new float [capacity], 0, capacity, capacity, 0, -1, false); - } - - FloatBufferImpl (float[] buffer, int offset, int capacity, int limit, int position, int mark, boolean readOnly) - { - super (capacity, limit, position, mark); - this.backing_buffer = buffer; - this.array_offset = offset; - this.readOnly = readOnly; - } - - public boolean isReadOnly () - { - return readOnly; - } - - public FloatBuffer slice () - { - return new FloatBufferImpl (backing_buffer, array_offset + position (), remaining (), remaining (), 0, -1, isReadOnly ()); - } - - public FloatBuffer duplicate () - { - return new FloatBufferImpl (backing_buffer, array_offset, capacity (), limit (), position (), mark, isReadOnly ()); - } - - public FloatBuffer asReadOnlyBuffer () - { - return new FloatBufferImpl (backing_buffer, array_offset, capacity (), limit (), position (), mark, true); - } - - public FloatBuffer compact () - { - checkIfReadOnly(); - mark = -1; - int copied = 0; - - while (remaining () > 0) - { - put (copied, get ()); - copied++; - } - - position (copied); - limit(capacity()); - return this; - } - - public boolean isDirect () - { - return false; - } - - /** - * Reads the <code>float</code> at this buffer's current position, - * and then increments the position. - * - * @exception BufferUnderflowException If there are no remaining - * <code>floats</code> in this buffer. - */ - public float get () - { - checkForUnderflow(); - - float result = backing_buffer [position ()]; - position (position () + 1); - return result; - } - - /** - * Relative put method. Writes <code>value</code> to the next position - * in the buffer. - * - * @exception BufferOverflowException If there no remaining - * space in this buffer. - * @exception ReadOnlyBufferException If this buffer is read-only. - */ - public FloatBuffer put (float value) - { - checkIfReadOnly(); - checkForOverflow(); - - backing_buffer [position ()] = value; - position (position () + 1); - return this; - } - - /** - * Absolute get method. Reads the <code>float</code> at position - * <code>index</code>. - * - * @exception IndexOutOfBoundsException If index is negative or not smaller - * than the buffer's limit. - */ - public float get (int index) - { - checkIndex(index); - - return backing_buffer [index]; - } - - /** - * Absolute put method. Writes <code>value</code> to position - * <code>index</code> in the buffer. - * - * @exception IndexOutOfBoundsException If index is negative or not smaller - * than the buffer's limit. - * @exception ReadOnlyBufferException If this buffer is read-only. - */ - public FloatBuffer put (int index, float value) - { - checkIfReadOnly(); - checkIndex(index); - - backing_buffer [index] = value; - return this; - } - - public ByteOrder order () - { - return ByteOrder.nativeOrder (); - } -} diff --git a/libjava/java/nio/FloatViewBufferImpl.java b/libjava/java/nio/FloatViewBufferImpl.java deleted file mode 100644 index 55770d52a29..00000000000 --- a/libjava/java/nio/FloatViewBufferImpl.java +++ /dev/null @@ -1,173 +0,0 @@ -/* FloatViewBufferImpl.java -- - Copyright (C) 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.nio; - -final class FloatViewBufferImpl extends FloatBuffer -{ - /** Position in bb (i.e. a byte offset) where this buffer starts. */ - private int offset; - private ByteBuffer bb; - private boolean readOnly; - private ByteOrder endian; - - FloatViewBufferImpl (ByteBuffer bb, int capacity) - { - super (capacity, capacity, 0, -1); - this.bb = bb; - this.offset = bb.position(); - this.readOnly = bb.isReadOnly(); - this.endian = bb.order(); - if (bb.isDirect()) - this.address = VMDirectByteBuffer.adjustAddress(bb.address, offset); - } - - public FloatViewBufferImpl (ByteBuffer bb, int offset, int capacity, - int limit, int position, int mark, - boolean readOnly, ByteOrder endian) - { - super (capacity, limit, position, mark); - this.bb = bb; - this.offset = offset; - this.readOnly = readOnly; - this.endian = endian; - if (bb.isDirect()) - this.address = VMDirectByteBuffer.adjustAddress(bb.address, offset); - } - - /** - * Reads the <code>float</code> at this buffer's current position, - * and then increments the position. - * - * @exception BufferUnderflowException If there are no remaining - * <code>floats</code> in this buffer. - */ - public float get () - { - int p = position(); - float result = ByteBufferHelper.getFloat(bb, (p << 2) + offset, endian); - position(p + 1); - return result; - } - - /** - * Absolute get method. Reads the <code>float</code> at position - * <code>index</code>. - * - * @exception IndexOutOfBoundsException If index is negative or not smaller - * than the buffer's limit. - */ - public float get (int index) - { - return ByteBufferHelper.getFloat(bb, (index << 2) + offset, endian); - } - - public FloatBuffer put (float value) - { - int p = position(); - ByteBufferHelper.putFloat(bb, (p << 2) + offset, value, endian); - position(p + 1); - return this; - } - - public FloatBuffer put (int index, float value) - { - ByteBufferHelper.putFloat(bb, (index << 2) + offset, value, endian); - return this; - } - - public FloatBuffer compact () - { - if (position () > 0) - { - int count = limit () - position (); - bb.shiftDown(offset, offset + 4 * position(), 4 * count); - position (count); - limit (capacity ()); - } - else - { - position(limit()); - limit(capacity()); - } - return this; - } - - public FloatBuffer slice () - { - // Create a sliced copy of this object that shares its content. - return new FloatViewBufferImpl (bb, (position () >> 2) + offset, - remaining(), remaining(), 0, -1, - readOnly, endian); - } - - FloatBuffer duplicate (boolean readOnly) - { - int pos = position(); - reset(); - int mark = position(); - position(pos); - return new FloatViewBufferImpl (bb, offset, capacity(), limit(), - pos, mark, readOnly, endian); - } - - public FloatBuffer duplicate () - { - return duplicate(readOnly); - } - - public FloatBuffer asReadOnlyBuffer () - { - return duplicate(true); - } - - public boolean isReadOnly () - { - return readOnly; - } - - public boolean isDirect () - { - return bb.isDirect (); - } - - public ByteOrder order () - { - return endian; - } -} diff --git a/libjava/java/nio/IntBuffer.java b/libjava/java/nio/IntBuffer.java deleted file mode 100644 index 1e1fe9c7565..00000000000 --- a/libjava/java/nio/IntBuffer.java +++ /dev/null @@ -1,383 +0,0 @@ -/* IntBuffer.java -- - Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.nio; - -/** - * @since 1.4 - */ -public abstract class IntBuffer extends Buffer - implements Comparable -{ - int array_offset; - int[] backing_buffer; - - IntBuffer (int capacity, int limit, int position, int mark) - { - super (capacity, limit, position, mark); - array_offset = 0; - } - - /** - * Allocates a new <code>IntBuffer</code> object with a given capacity. - */ - public static IntBuffer allocate (int capacity) - { - return new IntBufferImpl (capacity); - } - - /** - * Wraps a <code>int</code> array into a <code>IntBuffer</code> - * object. - * - * @exception IndexOutOfBoundsException If the preconditions on the offset - * and length parameters do not hold - */ - public static final IntBuffer wrap (int[] array, int offset, int length) - { - return new IntBufferImpl (array, 0, array.length, offset + length, offset, -1, false); - } - - /** - * Wraps a <code>int</code> array into a <code>IntBuffer</code> - * object. - */ - public static final IntBuffer wrap (int[] array) - { - return wrap (array, 0, array.length); - } - - /** - * This method transfers <code>int</code>s from this buffer into the given - * destination array. Before the transfer, it checks if there are fewer than - * length <code>int</code>s remaining in this buffer. - * - * @param dst The destination array - * @param offset The offset within the array of the first <code>int</code> - * to be written; must be non-negative and no larger than dst.length. - * @param length The maximum number of bytes to be written to the given array; - * must be non-negative and no larger than dst.length - offset. - * - * @exception BufferUnderflowException If there are fewer than length - * <code>int</code>s remaining in this buffer. - * @exception IndexOutOfBoundsException If the preconditions on the offset - * and length parameters do not hold. - */ - public IntBuffer get (int[] dst, int offset, int length) - { - checkArraySize(dst.length, offset, length); - checkForUnderflow(length); - - for (int i = offset; i < offset + length; i++) - { - dst [i] = get (); - } - - return this; - } - - /** - * This method transfers <code>int</code>s from this buffer into the given - * destination array. - * - * @param dst The byte array to write into. - * - * @exception BufferUnderflowException If there are fewer than dst.length - * <code>int</code>s remaining in this buffer. - */ - public IntBuffer get (int[] dst) - { - return get (dst, 0, dst.length); - } - - /** - * Writes the content of the the <code>IntBUFFER</code> src - * into the buffer. Before the transfer, it checks if there is fewer than - * <code>src.remaining()</code> space remaining in this buffer. - * - * @param src The source data. - * - * @exception BufferOverflowException If there is insufficient space in this - * buffer for the remaining <code>int</code>s in the source buffer. - * @exception IllegalArgumentException If the source buffer is this buffer. - * @exception ReadOnlyBufferException If this buffer is read-only. - */ - public IntBuffer put (IntBuffer src) - { - if (src == this) - throw new IllegalArgumentException (); - - checkForOverflow(src.remaining ()); - - if (src.remaining () > 0) - { - int[] toPut = new int [src.remaining ()]; - src.get (toPut); - put (toPut); - } - - return this; - } - - /** - * Writes the content of the the <code>int array</code> src - * into the buffer. Before the transfer, it checks if there is fewer than - * length space remaining in this buffer. - * - * @param src The array to copy into the buffer. - * @param offset The offset within the array of the first byte to be read; - * must be non-negative and no larger than src.length. - * @param length The number of bytes to be read from the given array; - * must be non-negative and no larger than src.length - offset. - * - * @exception BufferOverflowException If there is insufficient space in this - * buffer for the remaining <code>int</code>s in the source array. - * @exception IndexOutOfBoundsException If the preconditions on the offset - * and length parameters do not hold - * @exception ReadOnlyBufferException If this buffer is read-only. - */ - public IntBuffer put (int[] src, int offset, int length) - { - checkArraySize(src.length, offset, length); - checkForOverflow(length); - - for (int i = offset; i < offset + length; i++) - put (src [i]); - - return this; - } - - /** - * Writes the content of the the <code>int array</code> src - * into the buffer. - * - * @param src The array to copy into the buffer. - * - * @exception BufferOverflowException If there is insufficient space in this - * buffer for the remaining <code>int</code>s in the source array. - * @exception ReadOnlyBufferException If this buffer is read-only. - */ - public final IntBuffer put (int[] src) - { - return put (src, 0, src.length); - } - - /** - * Tells whether ot not this buffer is backed by an accessible - * <code>int</code> array. - */ - public final boolean hasArray () - { - return (backing_buffer != null - && !isReadOnly ()); - } - - /** - * Returns the <code>int</code> array that backs this buffer. - * - * @exception ReadOnlyBufferException If this buffer is read-only. - * @exception UnsupportedOperationException If this buffer is not backed - * by an accessible array. - */ - public final int[] array () - { - if (backing_buffer == null) - throw new UnsupportedOperationException (); - - checkIfReadOnly(); - - return backing_buffer; - } - - /** - * Returns the offset within this buffer's backing array of the first element. - * - * @exception ReadOnlyBufferException If this buffer is read-only. - * @exception UnsupportedOperationException If this buffer is not backed - * by an accessible array. - */ - public final int arrayOffset () - { - if (backing_buffer == null) - throw new UnsupportedOperationException (); - - checkIfReadOnly(); - - return array_offset; - } - - /** - * Calculates a hash code for this buffer. - * - * This is done with <code>int</code> arithmetic, - * where ** represents exponentiation, by this formula:<br> - * <code>s[position()] + 31 + (s[position()+1] + 30)*31**1 + ... + - * (s[limit()-1]+30)*31**(limit()-1)</code>. - * Where s is the buffer data. Note that the hashcode is dependent - * on buffer content, and therefore is not useful if the buffer - * content may change. - * - * @return the hash code - */ - public int hashCode () - { - int hashCode = get(position()) + 31; - int multiplier = 1; - for (int i = position() + 1; i < limit(); ++i) - { - multiplier *= 31; - hashCode += (get(i) + 30)*multiplier; - } - return hashCode; - } - - /** - * Checks if this buffer is equal to obj. - */ - public boolean equals (Object obj) - { - if (obj instanceof IntBuffer) - { - return compareTo (obj) == 0; - } - - return false; - } - - /** - * Compares two <code>IntBuffer</code> objects. - * - * @exception ClassCastException If obj is not an object derived from - * <code>IntBuffer</code>. - */ - public int compareTo (Object obj) - { - IntBuffer other = (IntBuffer) obj; - - int num = Math.min(remaining(), other.remaining()); - int pos_this = position(); - int pos_other = other.position(); - - for (int count = 0; count < num; count++) - { - int a = get(pos_this++); - int b = other.get(pos_other++); - - if (a == b) - continue; - - if (a < b) - return -1; - - return 1; - } - - return remaining() - other.remaining(); - } - - /** - * Returns the byte order of this buffer. - */ - public abstract ByteOrder order (); - - /** - * Reads the <code>int</code> at this buffer's current position, - * and then increments the position. - * - * @exception BufferUnderflowException If there are no remaining - * <code>int</code>s in this buffer. - */ - public abstract int get (); - - /** - * Writes the <code>int</code> at this buffer's current position, - * and then increments the position. - * - * @exception BufferOverflowException If there no remaining - * <code>int</code>s in this buffer. - * @exception ReadOnlyBufferException If this buffer is read-only. - */ - public abstract IntBuffer put (int b); - - /** - * Absolute get method. - * - * @exception IndexOutOfBoundsException If index is negative or not smaller - * than the buffer's limit. - */ - public abstract int get (int index); - - /** - * Absolute put method. - * - * @exception IndexOutOfBoundsException If index is negative or not smaller - * than the buffer's limit. - * @exception ReadOnlyBufferException If this buffer is read-only. - */ - public abstract IntBuffer put (int index, int b); - - /** - * Compacts this buffer. - * - * @exception ReadOnlyBufferException If this buffer is read-only. - */ - public abstract IntBuffer compact (); - - /** - * Tells wether or not this buffer is direct. - */ - public abstract boolean isDirect (); - - /** - * Creates a new <code>IntBuffer</code> whose content is a shared - * subsequence of this buffer's content. - */ - public abstract IntBuffer slice (); - - /** - * Creates a new <code>IntBuffer</code> that shares this buffer's - * content. - */ - public abstract IntBuffer duplicate (); - - /** - * Creates a new read-only <code>IntBuffer</code> that shares this - * buffer's content. - */ - public abstract IntBuffer asReadOnlyBuffer (); -} diff --git a/libjava/java/nio/IntBufferImpl.java b/libjava/java/nio/IntBufferImpl.java deleted file mode 100644 index 22657482b42..00000000000 --- a/libjava/java/nio/IntBufferImpl.java +++ /dev/null @@ -1,172 +0,0 @@ -/* IntBufferImpl.java -- - Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.nio; - -/** - * This is a Heap memory implementation - */ -final class IntBufferImpl extends IntBuffer -{ - private boolean readOnly; - - IntBufferImpl (int capacity) - { - this (new int [capacity], 0, capacity, capacity, 0, -1, false); - } - - IntBufferImpl (int[] buffer, int offset, int capacity, int limit, int position, int mark, boolean readOnly) - { - super (capacity, limit, position, mark); - this.backing_buffer = buffer; - this.array_offset = offset; - this.readOnly = readOnly; - } - - public boolean isReadOnly () - { - return readOnly; - } - - public IntBuffer slice () - { - return new IntBufferImpl (backing_buffer, array_offset + position (), remaining (), remaining (), 0, -1, isReadOnly ()); - } - - public IntBuffer duplicate () - { - return new IntBufferImpl (backing_buffer, array_offset, capacity (), limit (), position (), mark, isReadOnly ()); - } - - public IntBuffer asReadOnlyBuffer () - { - return new IntBufferImpl (backing_buffer, array_offset, capacity (), limit (), position (), mark, true); - } - - public IntBuffer compact () - { - checkIfReadOnly(); - mark = -1; - int copied = 0; - - while (remaining () > 0) - { - put (copied, get ()); - copied++; - } - - position (copied); - limit(capacity()); - return this; - } - - public boolean isDirect () - { - return false; - } - - /** - * Reads the <code>int</code> at this buffer's current position, - * and then increments the position. - * - * @exception BufferUnderflowException If there are no remaining - * <code>ints</code> in this buffer. - */ - public int get () - { - checkForUnderflow(); - - int result = backing_buffer [position ()]; - position (position () + 1); - return result; - } - - /** - * Relative put method. Writes <code>value</code> to the next position - * in the buffer. - * - * @exception BufferOverflowException If there no remaining - * space in this buffer. - * @exception ReadOnlyBufferException If this buffer is read-only. - */ - public IntBuffer put (int value) - { - checkIfReadOnly(); - checkForOverflow(); - - backing_buffer [position ()] = value; - position (position () + 1); - return this; - } - - /** - * Absolute get method. Reads the <code>int</code> at position - * <code>index</code>. - * - * @exception IndexOutOfBoundsException If index is negative or not smaller - * than the buffer's limit. - */ - public int get (int index) - { - checkIndex(index); - - return backing_buffer [index]; - } - - /** - * Absolute put method. Writes <code>value</code> to position - * <code>index</code> in the buffer. - * - * @exception IndexOutOfBoundsException If index is negative or not smaller - * than the buffer's limit. - * @exception ReadOnlyBufferException If this buffer is read-only. - */ - public IntBuffer put (int index, int value) - { - checkIfReadOnly(); - checkIndex(index); - - backing_buffer [index] = value; - return this; - } - - public ByteOrder order () - { - return ByteOrder.nativeOrder (); - } -} diff --git a/libjava/java/nio/IntViewBufferImpl.java b/libjava/java/nio/IntViewBufferImpl.java deleted file mode 100644 index d0b0057c117..00000000000 --- a/libjava/java/nio/IntViewBufferImpl.java +++ /dev/null @@ -1,173 +0,0 @@ -/* IntViewBufferImpl.java -- - Copyright (C) 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.nio; - -final class IntViewBufferImpl extends IntBuffer -{ - /** Position in bb (i.e. a byte offset) where this buffer starts. */ - private int offset; - private ByteBuffer bb; - private boolean readOnly; - private ByteOrder endian; - - IntViewBufferImpl (ByteBuffer bb, int capacity) - { - super (capacity, capacity, 0, -1); - this.bb = bb; - this.offset = bb.position(); - this.readOnly = bb.isReadOnly(); - this.endian = bb.order(); - if (bb.isDirect()) - this.address = VMDirectByteBuffer.adjustAddress(bb.address, offset); - } - - public IntViewBufferImpl (ByteBuffer bb, int offset, int capacity, - int limit, int position, int mark, - boolean readOnly, ByteOrder endian) - { - super (capacity, limit, position, mark); - this.bb = bb; - this.offset = offset; - this.readOnly = readOnly; - this.endian = endian; - if (bb.isDirect()) - this.address = VMDirectByteBuffer.adjustAddress(bb.address, offset); - } - - /** - * Reads the <code>int</code> at this buffer's current position, - * and then increments the position. - * - * @exception BufferUnderflowException If there are no remaining - * <code>ints</code> in this buffer. - */ - public int get () - { - int p = position(); - int result = ByteBufferHelper.getInt(bb, (p << 2) + offset, endian); - position(p + 1); - return result; - } - - /** - * Absolute get method. Reads the <code>int</code> at position - * <code>index</code>. - * - * @exception IndexOutOfBoundsException If index is negative or not smaller - * than the buffer's limit. - */ - public int get (int index) - { - return ByteBufferHelper.getInt(bb, (index << 2) + offset, endian); - } - - public IntBuffer put (int value) - { - int p = position(); - ByteBufferHelper.putInt(bb, (p << 2) + offset, value, endian); - position(p + 1); - return this; - } - - public IntBuffer put (int index, int value) - { - ByteBufferHelper.putInt(bb, (index << 2) + offset, value, endian); - return this; - } - - public IntBuffer compact () - { - if (position () > 0) - { - int count = limit () - position (); - bb.shiftDown(offset, offset + 4 * position(), 4 * count); - position (count); - limit (capacity ()); - } - else - { - position(limit()); - limit(capacity()); - } - return this; - } - - public IntBuffer slice () - { - // Create a sliced copy of this object that shares its content. - return new IntViewBufferImpl (bb, (position () >> 2) + offset, - remaining(), remaining(), 0, -1, - readOnly, endian); - } - - IntBuffer duplicate (boolean readOnly) - { - int pos = position(); - reset(); - int mark = position(); - position(pos); - return new IntViewBufferImpl (bb, offset, capacity(), limit(), - pos, mark, readOnly, endian); - } - - public IntBuffer duplicate () - { - return duplicate(readOnly); - } - - public IntBuffer asReadOnlyBuffer () - { - return duplicate(true); - } - - public boolean isReadOnly () - { - return readOnly; - } - - public boolean isDirect () - { - return bb.isDirect (); - } - - public ByteOrder order () - { - return endian; - } -} diff --git a/libjava/java/nio/InvalidMarkException.java b/libjava/java/nio/InvalidMarkException.java deleted file mode 100644 index 937d417ab13..00000000000 --- a/libjava/java/nio/InvalidMarkException.java +++ /dev/null @@ -1,52 +0,0 @@ -/* InvalidMarkException.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.nio; - -/** - * @author Michael Koch - * @since 1.4 - */ -public class InvalidMarkException extends IllegalStateException -{ - /** - * Creates the exception - */ - public InvalidMarkException () - { - } -} diff --git a/libjava/java/nio/LongBuffer.java b/libjava/java/nio/LongBuffer.java deleted file mode 100644 index b3d3557edcf..00000000000 --- a/libjava/java/nio/LongBuffer.java +++ /dev/null @@ -1,383 +0,0 @@ -/* LongBuffer.java -- - Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.nio; - -/** - * @since 1.4 - */ -public abstract class LongBuffer extends Buffer - implements Comparable -{ - int array_offset; - long[] backing_buffer; - - LongBuffer (int capacity, int limit, int position, int mark) - { - super (capacity, limit, position, mark); - array_offset = 0; - } - - /** - * Allocates a new <code>LongBuffer</code> object with a given capacity. - */ - public static LongBuffer allocate (int capacity) - { - return new LongBufferImpl (capacity); - } - - /** - * Wraps a <code>long</code> array into a <code>LongBuffer</code> - * object. - * - * @exception IndexOutOfBoundsException If the preconditions on the offset - * and length parameters do not hold - */ - public static final LongBuffer wrap (long[] array, int offset, int length) - { - return new LongBufferImpl (array, 0, array.length, offset + length, offset, -1, false); - } - - /** - * Wraps a <code>long</code> array into a <code>LongBuffer</code> - * object. - */ - public static final LongBuffer wrap (long[] array) - { - return wrap (array, 0, array.length); - } - - /** - * This method transfers <code>long</code>s from this buffer into the given - * destination array. Before the transfer, it checks if there are fewer than - * length <code>long</code>s remaining in this buffer. - * - * @param dst The destination array - * @param offset The offset within the array of the first <code>long</code> - * to be written; must be non-negative and no larger than dst.length. - * @param length The maximum number of bytes to be written to the given array; - * must be non-negative and no larger than dst.length - offset. - * - * @exception BufferUnderflowException If there are fewer than length - * <code>long</code>s remaining in this buffer. - * @exception IndexOutOfBoundsException If the preconditions on the offset - * and length parameters do not hold. - */ - public LongBuffer get (long[] dst, int offset, int length) - { - checkArraySize(dst.length, offset, length); - checkForUnderflow(length); - - for (int i = offset; i < offset + length; i++) - { - dst [i] = get (); - } - - return this; - } - - /** - * This method transfers <code>long</code>s from this buffer into the given - * destination array. - * - * @param dst The byte array to write into. - * - * @exception BufferUnderflowException If there are fewer than dst.length - * <code>long</code>s remaining in this buffer. - */ - public LongBuffer get (long[] dst) - { - return get (dst, 0, dst.length); - } - - /** - * Writes the content of the the <code>LongBUFFER</code> src - * into the buffer. Before the transfer, it checks if there is fewer than - * <code>src.remaining()</code> space remaining in this buffer. - * - * @param src The source data. - * - * @exception BufferOverflowException If there is insufficient space in this - * buffer for the remaining <code>long</code>s in the source buffer. - * @exception IllegalArgumentException If the source buffer is this buffer. - * @exception ReadOnlyBufferException If this buffer is read-only. - */ - public LongBuffer put (LongBuffer src) - { - if (src == this) - throw new IllegalArgumentException (); - - checkForOverflow(src.remaining ()); - - if (src.remaining () > 0) - { - long[] toPut = new long [src.remaining ()]; - src.get (toPut); - put (toPut); - } - - return this; - } - - /** - * Writes the content of the the <code>long array</code> src - * into the buffer. Before the transfer, it checks if there is fewer than - * length space remaining in this buffer. - * - * @param src The array to copy into the buffer. - * @param offset The offset within the array of the first byte to be read; - * must be non-negative and no larger than src.length. - * @param length The number of bytes to be read from the given array; - * must be non-negative and no larger than src.length - offset. - * - * @exception BufferOverflowException If there is insufficient space in this - * buffer for the remaining <code>long</code>s in the source array. - * @exception IndexOutOfBoundsException If the preconditions on the offset - * and length parameters do not hold - * @exception ReadOnlyBufferException If this buffer is read-only. - */ - public LongBuffer put (long[] src, int offset, int length) - { - checkArraySize(src.length, offset, length); - checkForOverflow(length); - - for (int i = offset; i < offset + length; i++) - put (src [i]); - - return this; - } - - /** - * Writes the content of the the <code>long array</code> src - * into the buffer. - * - * @param src The array to copy into the buffer. - * - * @exception BufferOverflowException If there is insufficient space in this - * buffer for the remaining <code>long</code>s in the source array. - * @exception ReadOnlyBufferException If this buffer is read-only. - */ - public final LongBuffer put (long[] src) - { - return put (src, 0, src.length); - } - - /** - * Tells whether ot not this buffer is backed by an accessible - * <code>long</code> array. - */ - public final boolean hasArray () - { - return (backing_buffer != null - && !isReadOnly ()); - } - - /** - * Returns the <code>long</code> array that backs this buffer. - * - * @exception ReadOnlyBufferException If this buffer is read-only. - * @exception UnsupportedOperationException If this buffer is not backed - * by an accessible array. - */ - public final long[] array () - { - if (backing_buffer == null) - throw new UnsupportedOperationException (); - - checkIfReadOnly(); - - return backing_buffer; - } - - /** - * Returns the offset within this buffer's backing array of the first element. - * - * @exception ReadOnlyBufferException If this buffer is read-only. - * @exception UnsupportedOperationException If this buffer is not backed - * by an accessible array. - */ - public final int arrayOffset () - { - if (backing_buffer == null) - throw new UnsupportedOperationException (); - - checkIfReadOnly(); - - return array_offset; - } - - /** - * Calculates a hash code for this buffer. - * - * This is done with <code>long</code> arithmetic, - * where ** represents exponentiation, by this formula:<br> - * <code>s[position()] + 31 + (s[position()+1] + 30)*31**1 + ... + - * (s[limit()-1]+30)*31**(limit()-1)</code>. - * Where s is the buffer data. Note that the hashcode is dependent - * on buffer content, and therefore is not useful if the buffer - * content may change. - * - * @return the hash code (casted to int) - */ - public int hashCode () - { - long hashCode = get(position()) + 31; - long multiplier = 1; - for (int i = position() + 1; i < limit(); ++i) - { - multiplier *= 31; - hashCode += (get(i) + 30)*multiplier; - } - return ((int)hashCode); - } - - /** - * Checks if this buffer is equal to obj. - */ - public boolean equals (Object obj) - { - if (obj instanceof LongBuffer) - { - return compareTo (obj) == 0; - } - - return false; - } - - /** - * Compares two <code>LongBuffer</code> objects. - * - * @exception ClassCastException If obj is not an object derived from - * <code>LongBuffer</code>. - */ - public int compareTo (Object obj) - { - LongBuffer other = (LongBuffer) obj; - - int num = Math.min(remaining(), other.remaining()); - int pos_this = position(); - int pos_other = other.position(); - - for (int count = 0; count < num; count++) - { - long a = get(pos_this++); - long b = other.get(pos_other++); - - if (a == b) - continue; - - if (a < b) - return -1; - - return 1; - } - - return remaining() - other.remaining(); - } - - /** - * Returns the byte order of this buffer. - */ - public abstract ByteOrder order (); - - /** - * Reads the <code>long</code> at this buffer's current position, - * and then increments the position. - * - * @exception BufferUnderflowException If there are no remaining - * <code>long</code>s in this buffer. - */ - public abstract long get (); - - /** - * Writes the <code>long</code> at this buffer's current position, - * and then increments the position. - * - * @exception BufferOverflowException If there no remaining - * <code>long</code>s in this buffer. - * @exception ReadOnlyBufferException If this buffer is read-only. - */ - public abstract LongBuffer put (long b); - - /** - * Absolute get method. - * - * @exception IndexOutOfBoundsException If index is negative or not smaller - * than the buffer's limit. - */ - public abstract long get (int index); - - /** - * Absolute put method. - * - * @exception IndexOutOfBoundsException If index is negative or not smaller - * than the buffer's limit. - * @exception ReadOnlyBufferException If this buffer is read-only. - */ - public abstract LongBuffer put (int index, long b); - - /** - * Compacts this buffer. - * - * @exception ReadOnlyBufferException If this buffer is read-only. - */ - public abstract LongBuffer compact (); - - /** - * Tells wether or not this buffer is direct. - */ - public abstract boolean isDirect (); - - /** - * Creates a new <code>LongBuffer</code> whose content is a shared - * subsequence of this buffer's content. - */ - public abstract LongBuffer slice (); - - /** - * Creates a new <code>LongBuffer</code> that shares this buffer's - * content. - */ - public abstract LongBuffer duplicate (); - - /** - * Creates a new read-only <code>LongBuffer</code> that shares this - * buffer's content. - */ - public abstract LongBuffer asReadOnlyBuffer (); -} diff --git a/libjava/java/nio/LongBufferImpl.java b/libjava/java/nio/LongBufferImpl.java deleted file mode 100644 index 8772f618c19..00000000000 --- a/libjava/java/nio/LongBufferImpl.java +++ /dev/null @@ -1,172 +0,0 @@ -/* LongBufferImpl.java -- - Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.nio; - -/** - * This is a Heap memory implementation - */ -final class LongBufferImpl extends LongBuffer -{ - private boolean readOnly; - - LongBufferImpl (int capacity) - { - this (new long [capacity], 0, capacity, capacity, 0, -1, false); - } - - LongBufferImpl (long[] buffer, int offset, int capacity, int limit, int position, int mark, boolean readOnly) - { - super (capacity, limit, position, mark); - this.backing_buffer = buffer; - this.array_offset = offset; - this.readOnly = readOnly; - } - - public boolean isReadOnly () - { - return readOnly; - } - - public LongBuffer slice () - { - return new LongBufferImpl (backing_buffer, array_offset + position (), remaining (), remaining (), 0, -1, isReadOnly ()); - } - - public LongBuffer duplicate () - { - return new LongBufferImpl (backing_buffer, array_offset, capacity (), limit (), position (), mark, isReadOnly ()); - } - - public LongBuffer asReadOnlyBuffer () - { - return new LongBufferImpl (backing_buffer, array_offset, capacity (), limit (), position (), mark, true); - } - - public LongBuffer compact () - { - checkIfReadOnly(); - mark = -1; - int copied = 0; - - while (remaining () > 0) - { - put (copied, get ()); - copied++; - } - - position (copied); - limit(capacity()); - return this; - } - - public boolean isDirect () - { - return false; - } - - /** - * Reads the <code>long</code> at this buffer's current position, - * and then increments the position. - * - * @exception BufferUnderflowException If there are no remaining - * <code>longs</code> in this buffer. - */ - public long get () - { - checkForUnderflow(); - - long result = backing_buffer [position ()]; - position (position () + 1); - return result; - } - - /** - * Relative put method. Writes <code>value</code> to the next position - * in the buffer. - * - * @exception BufferOverflowException If there is insufficient space in this - * buffer. - * @exception ReadOnlyBufferException If this buffer is read-only. - */ - public LongBuffer put (long value) - { - checkIfReadOnly(); - checkForOverflow(); - - backing_buffer [position ()] = value; - position (position () + 1); - return this; - } - - /** - * Absolute get method. Reads the <code>long</code> at position - * <code>index</code>. - * - * @exception IndexOutOfBoundsException If index is negative or not smaller - * than the buffer's limit. - */ - public long get (int index) - { - checkIndex(index); - - return backing_buffer [index]; - } - - /** - * Absolute put method. Writes <code>value</code> to position - * <code>index</code> in the buffer. - * - * @exception IndexOutOfBoundsException If index is negative or not smaller - * than the buffer's limit. - * @exception ReadOnlyBufferException If this buffer is read-only. - */ - public LongBuffer put (int index, long value) - { - checkIfReadOnly(); - checkIndex(index); - - backing_buffer [index] = value; - return this; - } - - public ByteOrder order () - { - return ByteOrder.nativeOrder (); - } -} diff --git a/libjava/java/nio/LongViewBufferImpl.java b/libjava/java/nio/LongViewBufferImpl.java deleted file mode 100644 index 9c3452ae809..00000000000 --- a/libjava/java/nio/LongViewBufferImpl.java +++ /dev/null @@ -1,173 +0,0 @@ -/* LongViewBufferImpl.java -- - Copyright (C) 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.nio; - -final class LongViewBufferImpl extends LongBuffer -{ - /** Position in bb (i.e. a byte offset) where this buffer starts. */ - private int offset; - private ByteBuffer bb; - private boolean readOnly; - private ByteOrder endian; - - LongViewBufferImpl (ByteBuffer bb, int capacity) - { - super (capacity, capacity, 0, -1); - this.bb = bb; - this.offset = bb.position(); - this.readOnly = bb.isReadOnly(); - this.endian = bb.order(); - if (bb.isDirect()) - this.address = VMDirectByteBuffer.adjustAddress(bb.address, offset); - } - - public LongViewBufferImpl (ByteBuffer bb, int offset, int capacity, - int limit, int position, int mark, - boolean readOnly, ByteOrder endian) - { - super (capacity, limit, position, mark); - this.bb = bb; - this.offset = offset; - this.readOnly = readOnly; - this.endian = endian; - if (bb.isDirect()) - this.address = VMDirectByteBuffer.adjustAddress(bb.address, offset); - } - - /** - * Reads the <code>long</code> at this buffer's current position, - * and then increments the position. - * - * @exception BufferUnderflowException If there are no remaining - * <code>longs</code> in this buffer. - */ - public long get () - { - int p = position(); - long result = ByteBufferHelper.getLong(bb, (p << 3) + offset, endian); - position(p + 1); - return result; - } - - /** - * Absolute get method. Reads the <code>long</code> at position - * <code>index</code>. - * - * @exception IndexOutOfBoundsException If index is negative or not smaller - * than the buffer's limit. - */ - public long get (int index) - { - return ByteBufferHelper.getLong(bb, (index << 3) + offset, endian); - } - - public LongBuffer put (long value) - { - int p = position(); - ByteBufferHelper.putLong(bb, (p << 3) + offset, value, endian); - position(p + 1); - return this; - } - - public LongBuffer put (int index, long value) - { - ByteBufferHelper.putLong(bb, (index << 3) + offset, value, endian); - return this; - } - - public LongBuffer compact () - { - if (position () > 0) - { - int count = limit () - position (); - bb.shiftDown(offset, offset + 8 * position(), 8 * count); - position (count); - limit (capacity ()); - } - else - { - position(limit()); - limit(capacity()); - } - return this; - } - - public LongBuffer slice () - { - // Create a sliced copy of this object that shares its content. - return new LongViewBufferImpl (bb, (position () >> 3) + offset, - remaining(), remaining(), 0, -1, - readOnly, endian); - } - - LongBuffer duplicate (boolean readOnly) - { - int pos = position(); - reset(); - int mark = position(); - position(pos); - return new LongViewBufferImpl (bb, offset, capacity(), limit(), - pos, mark, readOnly, endian); - } - - public LongBuffer duplicate () - { - return duplicate(readOnly); - } - - public LongBuffer asReadOnlyBuffer () - { - return duplicate(true); - } - - public boolean isReadOnly () - { - return readOnly; - } - - public boolean isDirect () - { - return bb.isDirect (); - } - - public ByteOrder order () - { - return endian; - } -} diff --git a/libjava/java/nio/ReadOnlyBufferException.java b/libjava/java/nio/ReadOnlyBufferException.java deleted file mode 100644 index d710e1b26a1..00000000000 --- a/libjava/java/nio/ReadOnlyBufferException.java +++ /dev/null @@ -1,52 +0,0 @@ -/* ReadOnlyBufferException.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.nio; - -/** - * @author Michael Koch - * @since 1.4 - */ -public class ReadOnlyBufferException extends UnsupportedOperationException -{ - /** - * Creates the exception - */ - public ReadOnlyBufferException () - { - } -} diff --git a/libjava/java/nio/ShortBuffer.java b/libjava/java/nio/ShortBuffer.java deleted file mode 100644 index 958fe8cd6b6..00000000000 --- a/libjava/java/nio/ShortBuffer.java +++ /dev/null @@ -1,383 +0,0 @@ -/* ShortBuffer.java -- - Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.nio; - -/** - * @since 1.4 - */ -public abstract class ShortBuffer extends Buffer - implements Comparable -{ - int array_offset; - short[] backing_buffer; - - ShortBuffer (int capacity, int limit, int position, int mark) - { - super (capacity, limit, position, mark); - array_offset = 0; - } - - /** - * Allocates a new <code>ShortBuffer</code> object with a given capacity. - */ - public static ShortBuffer allocate (int capacity) - { - return new ShortBufferImpl (capacity); - } - - /** - * Wraps a <code>short</code> array into a <code>ShortBuffer</code> - * object. - * - * @exception IndexOutOfBoundsException If the preconditions on the offset - * and length parameters do not hold - */ - public static final ShortBuffer wrap (short[] array, int offset, int length) - { - return new ShortBufferImpl (array, 0, array.length, offset + length, offset, -1, false); - } - - /** - * Wraps a <code>short</code> array into a <code>ShortBuffer</code> - * object. - */ - public static final ShortBuffer wrap (short[] array) - { - return wrap (array, 0, array.length); - } - - /** - * This method transfers <code>short</code>s from this buffer into the given - * destination array. Before the transfer, it checks if there are fewer than - * length <code>short</code>s remaining in this buffer. - * - * @param dst The destination array - * @param offset The offset within the array of the first <code>short</code> - * to be written; must be non-negative and no larger than dst.length. - * @param length The maximum number of bytes to be written to the given array; - * must be non-negative and no larger than dst.length - offset. - * - * @exception BufferUnderflowException If there are fewer than length - * <code>short</code>s remaining in this buffer. - * @exception IndexOutOfBoundsException If the preconditions on the offset - * and length parameters do not hold. - */ - public ShortBuffer get (short[] dst, int offset, int length) - { - checkArraySize(dst.length, offset, length); - checkForUnderflow(length); - - for (int i = offset; i < offset + length; i++) - { - dst [i] = get (); - } - - return this; - } - - /** - * This method transfers <code>short</code>s from this buffer into the given - * destination array. - * - * @param dst The byte array to write into. - * - * @exception BufferUnderflowException If there are fewer than dst.length - * <code>short</code>s remaining in this buffer. - */ - public ShortBuffer get (short[] dst) - { - return get (dst, 0, dst.length); - } - - /** - * Writes the content of the the <code>ShortBUFFER</code> src - * into the buffer. Before the transfer, it checks if there is fewer than - * <code>src.remaining()</code> space remaining in this buffer. - * - * @param src The source data. - * - * @exception BufferOverflowException If there is insufficient space in this - * buffer for the remaining <code>short</code>s in the source buffer. - * @exception IllegalArgumentException If the source buffer is this buffer. - * @exception ReadOnlyBufferException If this buffer is read-only. - */ - public ShortBuffer put (ShortBuffer src) - { - if (src == this) - throw new IllegalArgumentException (); - - checkForOverflow(src.remaining ()); - - if (src.remaining () > 0) - { - short[] toPut = new short [src.remaining ()]; - src.get (toPut); - put (toPut); - } - - return this; - } - - /** - * Writes the content of the the <code>short array</code> src - * into the buffer. Before the transfer, it checks if there is fewer than - * length space remaining in this buffer. - * - * @param src The array to copy into the buffer. - * @param offset The offset within the array of the first byte to be read; - * must be non-negative and no larger than src.length. - * @param length The number of bytes to be read from the given array; - * must be non-negative and no larger than src.length - offset. - * - * @exception BufferOverflowException If there is insufficient space in this - * buffer for the remaining <code>short</code>s in the source array. - * @exception IndexOutOfBoundsException If the preconditions on the offset - * and length parameters do not hold - * @exception ReadOnlyBufferException If this buffer is read-only. - */ - public ShortBuffer put (short[] src, int offset, int length) - { - checkArraySize(src.length, offset, length); - checkForOverflow(length); - - for (int i = offset; i < offset + length; i++) - put (src [i]); - - return this; - } - - /** - * Writes the content of the the <code>short array</code> src - * into the buffer. - * - * @param src The array to copy into the buffer. - * - * @exception BufferOverflowException If there is insufficient space in this - * buffer for the remaining <code>short</code>s in the source array. - * @exception ReadOnlyBufferException If this buffer is read-only. - */ - public final ShortBuffer put (short[] src) - { - return put (src, 0, src.length); - } - - /** - * Tells whether ot not this buffer is backed by an accessible - * <code>short</code> array. - */ - public final boolean hasArray () - { - return (backing_buffer != null - && !isReadOnly ()); - } - - /** - * Returns the <code>short</code> array that backs this buffer. - * - * @exception ReadOnlyBufferException If this buffer is read-only. - * @exception UnsupportedOperationException If this buffer is not backed - * by an accessible array. - */ - public final short[] array () - { - if (backing_buffer == null) - throw new UnsupportedOperationException (); - - checkIfReadOnly(); - - return backing_buffer; - } - - /** - * Returns the offset within this buffer's backing array of the first element. - * - * @exception ReadOnlyBufferException If this buffer is read-only. - * @exception UnsupportedOperationException If this buffer is not backed - * by an accessible array. - */ - public final int arrayOffset () - { - if (backing_buffer == null) - throw new UnsupportedOperationException (); - - checkIfReadOnly(); - - return array_offset; - } - - /** - * Calculates a hash code for this buffer. - * - * This is done with <code>int</code> arithmetic, - * where ** represents exponentiation, by this formula:<br> - * <code>s[position()] + 31 + (s[position()+1] + 30)*31**1 + ... + - * (s[limit()-1]+30)*31**(limit()-1)</code>. - * Where s is the buffer data. Note that the hashcode is dependent - * on buffer content, and therefore is not useful if the buffer - * content may change. - * - * @return the hash code - */ - public int hashCode () - { - int hashCode = get(position()) + 31; - int multiplier = 1; - for (int i = position() + 1; i < limit(); ++i) - { - multiplier *= 31; - hashCode += (get(i) + 30)*multiplier; - } - return hashCode; - } - - /** - * Checks if this buffer is equal to obj. - */ - public boolean equals (Object obj) - { - if (obj instanceof ShortBuffer) - { - return compareTo (obj) == 0; - } - - return false; - } - - /** - * Compares two <code>ShortBuffer</code> objects. - * - * @exception ClassCastException If obj is not an object derived from - * <code>ShortBuffer</code>. - */ - public int compareTo (Object obj) - { - ShortBuffer other = (ShortBuffer) obj; - - int num = Math.min(remaining(), other.remaining()); - int pos_this = position(); - int pos_other = other.position(); - - for (int count = 0; count < num; count++) - { - short a = get(pos_this++); - short b = other.get(pos_other++); - - if (a == b) - continue; - - if (a < b) - return -1; - - return 1; - } - - return remaining() - other.remaining(); - } - - /** - * Returns the byte order of this buffer. - */ - public abstract ByteOrder order (); - - /** - * Reads the <code>short</code> at this buffer's current position, - * and then increments the position. - * - * @exception BufferUnderflowException If there are no remaining - * <code>short</code>s in this buffer. - */ - public abstract short get (); - - /** - * Writes the <code>short</code> at this buffer's current position, - * and then increments the position. - * - * @exception BufferOverflowException If there no remaining - * <code>short</code>s in this buffer. - * @exception ReadOnlyBufferException If this buffer is read-only. - */ - public abstract ShortBuffer put (short b); - - /** - * Absolute get method. - * - * @exception IndexOutOfBoundsException If index is negative or not smaller - * than the buffer's limit. - */ - public abstract short get (int index); - - /** - * Absolute put method. - * - * @exception IndexOutOfBoundsException If index is negative or not smaller - * than the buffer's limit. - * @exception ReadOnlyBufferException If this buffer is read-only. - */ - public abstract ShortBuffer put (int index, short b); - - /** - * Compacts this buffer. - * - * @exception ReadOnlyBufferException If this buffer is read-only. - */ - public abstract ShortBuffer compact (); - - /** - * Tells wether or not this buffer is direct. - */ - public abstract boolean isDirect (); - - /** - * Creates a new <code>ShortBuffer</code> whose content is a shared - * subsequence of this buffer's content. - */ - public abstract ShortBuffer slice (); - - /** - * Creates a new <code>ShortBuffer</code> that shares this buffer's - * content. - */ - public abstract ShortBuffer duplicate (); - - /** - * Creates a new read-only <code>ShortBuffer</code> that shares this - * buffer's content. - */ - public abstract ShortBuffer asReadOnlyBuffer (); -} diff --git a/libjava/java/nio/ShortBufferImpl.java b/libjava/java/nio/ShortBufferImpl.java deleted file mode 100644 index ee5bff2f95b..00000000000 --- a/libjava/java/nio/ShortBufferImpl.java +++ /dev/null @@ -1,172 +0,0 @@ -/* ShortBufferImpl.java -- - Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.nio; - -/** - * This is a Heap memory implementation - */ -final class ShortBufferImpl extends ShortBuffer -{ - private boolean readOnly; - - ShortBufferImpl (int capacity) - { - this (new short [capacity], 0, capacity, capacity, 0, -1, false); - } - - ShortBufferImpl (short[] buffer, int offset, int capacity, int limit, int position, int mark, boolean readOnly) - { - super (capacity, limit, position, mark); - this.backing_buffer = buffer; - this.array_offset = offset; - this.readOnly = readOnly; - } - - public boolean isReadOnly () - { - return readOnly; - } - - public ShortBuffer slice () - { - return new ShortBufferImpl (backing_buffer, array_offset + position (), remaining (), remaining (), 0, -1, isReadOnly ()); - } - - public ShortBuffer duplicate () - { - return new ShortBufferImpl (backing_buffer, array_offset, capacity (), limit (), position (), mark, isReadOnly ()); - } - - public ShortBuffer asReadOnlyBuffer () - { - return new ShortBufferImpl (backing_buffer, array_offset, capacity (), limit (), position (), mark, true); - } - - public ShortBuffer compact () - { - checkIfReadOnly(); - mark = -1; - int copied = 0; - - while (remaining () > 0) - { - put (copied, get ()); - copied++; - } - - position (copied); - limit(capacity()); - return this; - } - - public boolean isDirect () - { - return false; - } - - /** - * Reads the <code>short</code> at this buffer's current position, - * and then increments the position. - * - * @exception BufferUnderflowException If there are no remaining - * <code>short</code>s in this buffer. - */ - public short get () - { - checkForUnderflow(); - - short result = backing_buffer [position ()]; - position (position () + 1); - return result; - } - - /** - * Relative put method. Writes <code>value</code> to the next position - * in the buffer. - * - * @exception BufferOverflowException If there no remaining - * space in this buffer. - * @exception ReadOnlyBufferException If this buffer is read-only. - */ - public ShortBuffer put (short value) - { - checkIfReadOnly(); - checkForOverflow(); - - backing_buffer [position ()] = value; - position (position () + 1); - return this; - } - - /** - * Absolute get method. Reads the <code>short</code> at position - * <code>index</code>. - * - * @exception IndexOutOfBoundsException If index is negative or not smaller - * than the buffer's limit. - */ - public short get (int index) - { - checkIndex(index); - - return backing_buffer [index]; - } - - /** - * Absolute put method. Writes <code>value</code> to position - * <code>index</code> in the buffer. - * - * @exception IndexOutOfBoundsException If index is negative or not smaller - * than the buffer's limit. - * @exception ReadOnlyBufferException If this buffer is read-only. - */ - public ShortBuffer put (int index, short value) - { - checkIfReadOnly(); - checkIndex(index); - - backing_buffer [index] = value; - return this; - } - - public ByteOrder order () - { - return ByteOrder.nativeOrder (); - } -} diff --git a/libjava/java/nio/ShortViewBufferImpl.java b/libjava/java/nio/ShortViewBufferImpl.java deleted file mode 100644 index cdd559522ff..00000000000 --- a/libjava/java/nio/ShortViewBufferImpl.java +++ /dev/null @@ -1,173 +0,0 @@ -/* ShortViewBufferImpl.java -- - Copyright (C) 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.nio; - -final class ShortViewBufferImpl extends ShortBuffer -{ - /** Position in bb (i.e. a byte offset) where this buffer starts. */ - private int offset; - private ByteBuffer bb; - private boolean readOnly; - private ByteOrder endian; - - ShortViewBufferImpl (ByteBuffer bb, int capacity) - { - super (capacity, capacity, 0, -1); - this.bb = bb; - this.offset = bb.position(); - this.readOnly = bb.isReadOnly(); - this.endian = bb.order(); - if (bb.isDirect()) - this.address = VMDirectByteBuffer.adjustAddress(bb.address, offset); - } - - public ShortViewBufferImpl (ByteBuffer bb, int offset, int capacity, - int limit, int position, int mark, - boolean readOnly, ByteOrder endian) - { - super (capacity, limit, position, mark); - this.bb = bb; - this.offset = offset; - this.readOnly = readOnly; - this.endian = endian; - if (bb.isDirect()) - this.address = VMDirectByteBuffer.adjustAddress(bb.address, offset); - } - - /** - * Reads the <code>short</code> at this buffer's current position, - * and then increments the position. - * - * @exception BufferUnderflowException If there are no remaining - * <code>short</code>s in this buffer. - */ - public short get () - { - int p = position(); - short result = ByteBufferHelper.getShort(bb, (p << 1) + offset, endian); - position(p + 1); - return result; - } - - /** - * Absolute get method. Reads the <code>short</code> at position - * <code>index</code>. - * - * @exception IndexOutOfBoundsException If index is negative or not smaller - * than the buffer's limit. - */ - public short get (int index) - { - return ByteBufferHelper.getShort(bb, (index << 1) + offset, endian); - } - - public ShortBuffer put (short value) - { - int p = position(); - ByteBufferHelper.putShort(bb, (p << 1) + offset, value, endian); - position(p + 1); - return this; - } - - public ShortBuffer put (int index, short value) - { - ByteBufferHelper.putShort(bb, (index << 1) + offset, value, endian); - return this; - } - - public ShortBuffer compact () - { - if (position () > 0) - { - int count = limit () - position (); - bb.shiftDown(offset, offset + 2 * position(), 2 * count); - position (count); - limit (capacity ()); - } - else - { - position(limit()); - limit(capacity()); - } - return this; - } - - public ShortBuffer slice () - { - // Create a sliced copy of this object that shares its content. - return new ShortViewBufferImpl (bb, (position () >> 1) + offset, - remaining(), remaining(), 0, -1, - readOnly, endian); - } - - ShortBuffer duplicate (boolean readOnly) - { - int pos = position(); - reset(); - int mark = position(); - position(pos); - return new ShortViewBufferImpl (bb, offset, capacity(), limit(), - pos, mark, readOnly, endian); - } - - public ShortBuffer duplicate () - { - return duplicate(readOnly); - } - - public ShortBuffer asReadOnlyBuffer () - { - return duplicate(true); - } - - public boolean isReadOnly () - { - return readOnly; - } - - public boolean isDirect () - { - return bb.isDirect (); - } - - public ByteOrder order () - { - return endian; - } -} diff --git a/libjava/java/nio/channels/AlreadyConnectedException.java b/libjava/java/nio/channels/AlreadyConnectedException.java deleted file mode 100644 index 133547ef308..00000000000 --- a/libjava/java/nio/channels/AlreadyConnectedException.java +++ /dev/null @@ -1,48 +0,0 @@ -/* AlreadyConnectedException.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.nio.channels; - -public class AlreadyConnectedException extends IllegalStateException -{ - /** - * Creates the exception - */ - public AlreadyConnectedException() - { - } -} diff --git a/libjava/java/nio/channels/AsynchronousCloseException.java b/libjava/java/nio/channels/AsynchronousCloseException.java deleted file mode 100644 index f45fdd81ab4..00000000000 --- a/libjava/java/nio/channels/AsynchronousCloseException.java +++ /dev/null @@ -1,53 +0,0 @@ -/* AsynchronousCloseException.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.nio.channels; - - -/** - * @author Michael Koch - * @since 1.4 - */ -public class AsynchronousCloseException extends ClosedChannelException -{ - /** - * Creates the exception - */ - public AsynchronousCloseException() - { - } -} diff --git a/libjava/java/nio/channels/ByteChannel.java b/libjava/java/nio/channels/ByteChannel.java deleted file mode 100644 index d7d7a451b4d..00000000000 --- a/libjava/java/nio/channels/ByteChannel.java +++ /dev/null @@ -1,43 +0,0 @@ -/* ByteChannel.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.nio.channels; - -public interface ByteChannel extends ReadableByteChannel, - WritableByteChannel -{ -} diff --git a/libjava/java/nio/channels/CancelledKeyException.java b/libjava/java/nio/channels/CancelledKeyException.java deleted file mode 100644 index 02108f6c7b3..00000000000 --- a/libjava/java/nio/channels/CancelledKeyException.java +++ /dev/null @@ -1,53 +0,0 @@ -/* CancelledKeyException.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.nio.channels; - - -/** - * @author Michael Koch - * @since 1.4 - */ -public class CancelledKeyException extends IllegalStateException -{ - /** - * Creates the exception - */ - public CancelledKeyException() - { - } -} diff --git a/libjava/java/nio/channels/Channel.java b/libjava/java/nio/channels/Channel.java deleted file mode 100644 index d488bd27dd0..00000000000 --- a/libjava/java/nio/channels/Channel.java +++ /dev/null @@ -1,59 +0,0 @@ -/* Channel.java -- - Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.nio.channels; - -import java.io.IOException; - -public interface Channel -{ - /** - * Tells whether this channel is open or not - * - * @return <code>true</code>if channel is open, - * <code>false</code> otherwise - */ - boolean isOpen(); - - /** - * Closes this channel - * - * @exception IOException If an error occurs - */ - void close() throws IOException; -} diff --git a/libjava/java/nio/channels/ClosedByInterruptException.java b/libjava/java/nio/channels/ClosedByInterruptException.java deleted file mode 100644 index 17858f613c6..00000000000 --- a/libjava/java/nio/channels/ClosedByInterruptException.java +++ /dev/null @@ -1,53 +0,0 @@ -/* ClosedByInterruptException.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.nio.channels; - - -/** - * @author Michael Koch - * @since 1.4 - */ -public class ClosedByInterruptException extends AsynchronousCloseException -{ - /** - * Creates the exception - */ - public ClosedByInterruptException() - { - } -} diff --git a/libjava/java/nio/channels/ClosedChannelException.java b/libjava/java/nio/channels/ClosedChannelException.java deleted file mode 100644 index 0f8df9b26c4..00000000000 --- a/libjava/java/nio/channels/ClosedChannelException.java +++ /dev/null @@ -1,55 +0,0 @@ -/* ClosedChannelException.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.nio.channels; - -import java.io.IOException; - - -/** - * @author Michael Koch - * @since 1.4 - */ -public class ClosedChannelException extends IOException -{ - /** - * Creates the exception - */ - public ClosedChannelException() - { - } -} diff --git a/libjava/java/nio/channels/ClosedSelectorException.java b/libjava/java/nio/channels/ClosedSelectorException.java deleted file mode 100644 index e1b7a8ce939..00000000000 --- a/libjava/java/nio/channels/ClosedSelectorException.java +++ /dev/null @@ -1,53 +0,0 @@ -/* ClosedSelectorException.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.nio.channels; - - -/** - * @author Michael Koch - * @since 1.4 - */ -public class ClosedSelectorException extends IllegalStateException -{ - /** - * Creates the exception - */ - public ClosedSelectorException() - { - } -} diff --git a/libjava/java/nio/channels/ConnectionPendingException.java b/libjava/java/nio/channels/ConnectionPendingException.java deleted file mode 100644 index b0b71294f7e..00000000000 --- a/libjava/java/nio/channels/ConnectionPendingException.java +++ /dev/null @@ -1,53 +0,0 @@ -/* ConnectionPendingException.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.nio.channels; - - -/** - * @author Michael Koch - * @since 1.4 - */ -public class ConnectionPendingException extends IllegalStateException -{ - /** - * Creates the exception - */ - public ConnectionPendingException() - { - } -} diff --git a/libjava/java/nio/channels/DatagramChannel.java b/libjava/java/nio/channels/DatagramChannel.java deleted file mode 100644 index d257ff33865..00000000000 --- a/libjava/java/nio/channels/DatagramChannel.java +++ /dev/null @@ -1,210 +0,0 @@ -/* DatagramChannel.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.nio.channels; - -import java.io.IOException; -import java.net.DatagramSocket; -import java.net.SocketAddress; -import java.nio.ByteBuffer; -import java.nio.channels.spi.AbstractSelectableChannel; -import java.nio.channels.spi.SelectorProvider; - - -/** - * @since 1.4 - */ -public abstract class DatagramChannel extends AbstractSelectableChannel - implements ByteChannel, ScatteringByteChannel, GatheringByteChannel -{ - /** - * Initializes the channel. - */ - protected DatagramChannel(SelectorProvider provider) - { - super(provider); - } - - /** - * Opens a datagram channel. - * - * @exception IOException If an error occurs - */ - public static DatagramChannel open() throws IOException - { - return SelectorProvider.provider().openDatagramChannel(); - } - - /** - * Reads data from this channel. - */ - public final long read(ByteBuffer[] dsts) throws IOException - { - long b = 0; - - for (int i = 0; i < dsts.length; i++) - b += read(dsts[i]); - - return b; - } - - /** - * Writes data to this channel. - * - * @exception IOException If an error occurs - * @exception NotYetConnectedException The channel's socket is not connected. - */ - public final long write(ByteBuffer[] srcs) throws IOException - { - long b = 0; - - for (int i = 0; i < srcs.length; i++) - b += write(srcs[i]); - - return b; - } - - /** - * Connects this channel's socket. - * - * @exception AsynchronousCloseException If another thread closes this channel - * while the connect operation is in progress. - * @exception ClosedByInterruptException If another thread interrupts the - * current thread while the read operation is in progress, thereby closing the - * channel and setting the current thread's interrupt status. - * @exception ClosedChannelException If this channel is closed. - * @exception IOException If an error occurs. - * @exception SecurityException If a security manager has been installed and - * it does not permit datagrams to be sent to the given address. - */ - public abstract DatagramChannel connect(SocketAddress remote) - throws IOException; - - /** - * Disonnects this channel's socket. - * - * @exception IOException If an error occurs - */ - public abstract DatagramChannel disconnect() throws IOException; - - /** - * Tells whether or not this channel's socket is connected. - * - * @exception IOException If an error occurs. - * @exception NotYetConnectedException The channel's socket is not connected. - */ - public abstract boolean isConnected(); - - /** - * Reads data from this channel. - */ - public abstract int read(ByteBuffer dst) throws IOException; - - /** - * Reads data from this channel. - * - * @exception IOException If an error occurs. - * @exception NotYetConnectedException The channel's socket is not connected. - */ - public abstract long read(ByteBuffer[] dsts, int offset, int length) - throws IOException; - - /** - * Receives a datagram via this channel. - * - * @exception AsynchronousCloseException If another thread closes this channel - * while the connect operation is in progress. - * @exception ClosedByInterruptException If another thread interrupts the - * current thread while the read operation is in progress, thereby closing the - * channel and setting the current thread's interrupt status. - * @exception ClosedChannelException If this channel is closed. - * @exception IOException If an error occurs - * @exception SecurityException If a security manager has been installed and - * it does not permit datagrams to be sent to the given address. - */ - public abstract SocketAddress receive(ByteBuffer dst) - throws IOException; - - /** - * Sends a datagram via this channel. - * - * @exception AsynchronousCloseException If another thread closes this channel - * while the connect operation is in progress. - * @exception ClosedByInterruptException If another thread interrupts the - * current thread while the read operation is in progress, thereby closing the - * channel and setting the current thread's interrupt status. - * @exception ClosedChannelException If this channel is closed. - * @exception IOException If an error occurs - * @exception SecurityException If a security manager has been installed and - * it does not permit datagrams to be sent to the given address. - */ - public abstract int send(ByteBuffer src, SocketAddress target) - throws IOException; - - /** - * Retrieves the channel's socket. - */ - public abstract DatagramSocket socket(); - - /** - * Writes data to this channel. - * - * @exception IOException If an error occurs. - * @exception NotYetConnectedException The channel's socket is not connected. - */ - public abstract int write(ByteBuffer src) throws IOException; - - /** - * Writes data to this channel. - * - * @exception IOException If an error occurs. - * @exception NotYetConnectedException The channel's socket is not connected. - */ - public abstract long write(ByteBuffer[] srcs, int offset, int length) - throws IOException; - - /** - * Retrieves the valid operations for this channel. - * - * @exception IOException If an error occurs. - * @exception NotYetConnectedException The channel's socket is not connected. - */ - public final int validOps() - { - return SelectionKey.OP_READ | SelectionKey.OP_WRITE; - } -} diff --git a/libjava/java/nio/channels/FileChannel.java b/libjava/java/nio/channels/FileChannel.java deleted file mode 100644 index 944ec0b8f3e..00000000000 --- a/libjava/java/nio/channels/FileChannel.java +++ /dev/null @@ -1,367 +0,0 @@ -/* FileChannel.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.nio.channels; - -import java.io.IOException; -import java.nio.ByteBuffer; -import java.nio.MappedByteBuffer; -import java.nio.channels.spi.AbstractInterruptibleChannel; - - -/** - * @author Michael Koch - * @since 1.4 - */ -public abstract class FileChannel extends AbstractInterruptibleChannel - implements ByteChannel, GatheringByteChannel, ScatteringByteChannel -{ - public static class MapMode - { - int m; - public static final MapMode READ_ONLY = new MapMode(0); - public static final MapMode READ_WRITE = new MapMode(1); - public static final MapMode PRIVATE = new MapMode(2); - - /** - * Initializes the MapMode. - */ - MapMode(int a) - { - m = a; - } - - /** - * Returns a string representation of the <code>MapMode</code> object. - */ - public String toString() - { - if (this == READ_ONLY) - return "READ_ONLY"; - else if (this == READ_WRITE) - return "READ_WRITE"; - - return "PRIVATE"; - } - } - - /** - * Initializes the channel. - */ - protected FileChannel() - { - } - - /** - * Maps the file into the memory. - * - * @exception IllegalArgumentException If the preconditions on the parameters - * do not hold. - * @exception IOException If an I/O error occurs. - * @exception NonReadableChannelException If mode is READ_ONLY but this channel was - * not opened for reading. - * @exception NonWritableChannelException If mode is READ_WRITE or PRIVATE but this - * channel was not opened for writing. - */ - public abstract MappedByteBuffer map(MapMode mode, long position, long size) - throws IOException; - - /** - * Return the size of the file thus far - * - * @exception ClosedChannelException If this channel is closed. - */ - public abstract long size() throws IOException; - - /** - * Writes data to the channel. - * - * @exception IOException If an I/O error occurs. - */ - public final long write(ByteBuffer[] srcs) throws IOException - { - long result = 0; - - for (int i = 0; i < srcs.length; i++) - result += write(srcs[i]); - - return result; - } - - /** - * Writes data to the channel. - * - * @exception IOException If an I/O error occurs. - */ - public abstract int write(ByteBuffer src) throws IOException; - - /** - * Writes data to the channel. - * - * @exception AsynchronousCloseException If another thread closes this channel - * while the transfer is in progress. - * @exception ClosedByInterruptException If another thread interrupts the - * current thread while the transfer is in progress, thereby closing both - * channels and setting the current thread's interrupt status. - * @exception ClosedChannelException If this channel is closed. - * @exception IllegalArgumentException If position is negative. - * @exception IOException If an I/O error occurs. - * @exception NonWritableChannelException If this channel was not opened for - * writing. - */ - public abstract int write(ByteBuffer srcs, long position) - throws IOException; - - /** - * Writes data to the channel. - * - * @exception IOException If an I/O error occurs. - */ - public abstract long write(ByteBuffer[] srcs, int offset, int length) - throws IOException; - - /** - * Reads data from the channel. - * - * @exception IOException If an I/O error occurs. - */ - public abstract long read(ByteBuffer[] dsts, int offset, int length) - throws IOException; - - /** - * Reads data from the channel. - * - * @exception IOException If an I/O error occurs. - */ - public final long read(ByteBuffer[] dsts) throws IOException - { - long result = 0; - - for (int i = 0; i < dsts.length; i++) - read(dsts[i]); - - return result; - } - - /** - * Reads data from the channel. - * - * @exception IOException If an I/O error occurs. - */ - public abstract int read(ByteBuffer dst) throws IOException; - - /** - * Reads data from the channel. - * - * @exception AsynchronousCloseException If another thread closes this channel - * while the transfer is in progress. - * @exception ClosedByInterruptException If another thread interrupts the - * current thread while the transfer is in progress, thereby closing both - * channels and setting the current thread's interrupt status. - * @exception ClosedChannelException If this channel is closed. - * @exception IllegalArgumentException If position is negative. - * @exception IOException If an I/O error occurs. - * @exception NonReadableChannelException If this channel was not opened for - * reading. - */ - public abstract int read(ByteBuffer dst, long position) - throws IOException; - - /** - * Closes the channel. - * - * This is called from @see close. - * - * @exception IOException If an I/O error occurs. - */ - protected abstract void implCloseChannel() throws IOException; - - /** - * msync with the disk - * - * @exception ClosedChannelException If this channel is closed. - * @exception IOException If an I/O error occurs. - */ - public abstract void force(boolean metaData) throws IOException; - - /** - * Creates a file lock for the whole assoziated file. - * - * @exception AsynchronousCloseException If another thread closes this channel - * while the transfer is in progress. - * @exception ClosedChannelException If this channel is closed. - * @exception FileLockInterruptionException If the invoking thread is - * interrupted while blocked in this method. - * @exception IOException If an I/O error occurs. - * @exception NonReadableChannelException If shared is true and this channel - * was not opened for reading. - * @exception NonWritableChannelException If shared is false and this channel - * was not opened for writing. - * @exception OverlappingFileLockException If a lock that overlaps the - * requested region is already held by this Java virtual machine, or if - * another thread is already blocked in this method and is attempting to lock - * an overlapping region. - */ - public final FileLock lock() throws IOException - { - return lock(0, Long.MAX_VALUE, false); - } - - /** - * Creates a file lock for a region of the assoziated file. - * - * @exception AsynchronousCloseException If another thread closes this channel - * while the transfer is in progress. - * @exception ClosedChannelException If this channel is closed. - * @exception FileLockInterruptionException If the invoking thread is - * interrupted while blocked in this method. - * @exception IllegalArgumentException If the preconditions on the parameters - * do not hold. - * @exception IOException If an I/O error occurs. - * @exception OverlappingFileLockException If a lock that overlaps the - * requested region is already held by this Java virtual machine, or if - * another thread is already blocked in this method and is attempting to lock - * an overlapping region. - * @exception NonReadableChannelException If shared is true and this channel - * was not opened for reading. - * @exception NonWritableChannelException If shared is false and this channel - * was not opened for writing. - */ - public abstract FileLock lock(long position, long size, boolean shared) - throws IOException; - - /** - * Tries to aqquire alock on the whole assoziated file. - * - * @exception ClosedChannelException If this channel is closed. - * @exception IOException If an I/O error occurs. - * @exception OverlappingFileLockException If a lock that overlaps the - * requested region is already held by this Java virtual machine, or if - * another thread is already blocked in this method and is attempting to lock - * an overlapping region. - */ - public final FileLock tryLock() throws IOException - { - return tryLock(0, Long.MAX_VALUE, false); - } - - /** - * Tries to aqquire a lock on a region of the assoziated file. - * - * @exception ClosedChannelException If this channel is closed. - * @exception IllegalArgumentException If the preconditions on the parameters - * do not hold. - * @exception IOException If an I/O error occurs. - * @exception OverlappingFileLockException If a lock that overlaps the - * requested region is already held by this Java virtual machine, or if - * another thread is already blocked in this method and is attempting to lock - * an overlapping region. - */ - public abstract FileLock tryLock(long position, long size, boolean shared) - throws IOException; - - /** - * Returns the current position on the file. - * - * @exception ClosedChannelException If this channel is closed. - * @exception IOException If an I/O error occurs. - */ - public abstract long position() throws IOException; - - /** - * Sets the position of the channel on the assoziated file. - * - * @exception ClosedChannelException If this channel is closed. - * @exception IllegalArgumentException If newPosition is negative. - * @exception IOException If an I/O error occurs. - */ - public abstract FileChannel position(long newPosition) - throws IOException; - - /** - * Transfers bytes from this channel's file to the given writable byte - * channel. - * - * @exception AsynchronousCloseException If another thread closes this channel - * while the transfer is in progress. - * @exception ClosedByInterruptException If another thread interrupts the - * current thread while the transfer is in progress, thereby closing both - * channels and setting the current thread's interrupt status. - * @exception ClosedChannelException If this channel is closed. - * @exception IllegalArgumentException If the preconditions on the parameters - * do not hold. - * @exception IOException If an I/O error occurs. - * @exception NonReadableChannelException If this channel was not opened for - * reading. - * @exception NonWritableChannelException If the target channel was not - * opened for writing. - */ - public abstract long transferTo(long position, long count, - WritableByteChannel target) - throws IOException; - - /** - * Transfers bytes from the given readable channel into this channel. - * - * @exception AsynchronousCloseException If another thread closes this channel - * while the transfer is in progress. - * @exception ClosedByInterruptException If another thread interrupts the - * current thread while the transfer is in progress, thereby closing both - * channels and setting the current thread's interrupt status. - * @exception ClosedChannelException If this channel is closed. - * @exception IllegalArgumentException If the preconditions on the parameters - * do not hold. - * @exception IOException If an I/O error occurs. - * @exception NonReadableChannelException If the source channel was not - * opened for reading. - * @exception NonWritableChannelException If this channel was not opened for - * writing. - */ - public abstract long transferFrom(ReadableByteChannel src, long position, - long count) throws IOException; - - /** - * Truncates the channel's file at <code>size</code>. - * - * @exception ClosedChannelException If this channel is closed. - * @exception IllegalArgumentException If size is negative. - * @exception IOException If an I/O error occurs. - * @exception NonWritableChannelException If this channel was not opened for - * writing. - */ - public abstract FileChannel truncate(long size) throws IOException; -} diff --git a/libjava/java/nio/channels/FileLock.java b/libjava/java/nio/channels/FileLock.java deleted file mode 100644 index 151c23f9f6b..00000000000 --- a/libjava/java/nio/channels/FileLock.java +++ /dev/null @@ -1,150 +0,0 @@ -/* FileLock.java -- - Copyright (C) 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.nio.channels; - -import java.io.IOException; - - -/** - * @since 1.4 - */ -public abstract class FileLock -{ - FileChannel channel; - long position; - long size; - boolean shared; - - /** - * Initializes the file lock. - * - * @exception IllegalArgumentException If the preconditions on the parameters do not hold - */ - protected FileLock(FileChannel channel, long position, long size, - boolean shared) - { - if (position < 0 || size < 0) - throw new IllegalArgumentException(); - - this.channel = channel; - this.position = position; - this.size = size; - this.shared = shared; - } - - /** - * Tells whether or not this lock is valid. - */ - public abstract boolean isValid(); - - /** - * Releases this lock. - * - * @exception IOException If an error occurs - * @exception ClosedChannelException If the locked channel is no longer open. - */ - public abstract void release() throws IOException; - - /** - * Returns the file channel upon whose file this lock is held. - */ - public final FileChannel channel() - { - return channel; - } - - /** - * Tells whether this lock is shared. - */ - public final boolean isShared() - { - return shared; - } - - /** - * Tells whether or not this lock overlaps the given lock range. - */ - public final boolean overlaps(long position, long size) - { - if (position > this.position + this.size) - return false; - - if (position + size < this.position) - return false; - - return true; - } - - /** - * Returns the position within the file of the first byte of the - * locked region. - */ - public final long position() - { - return position; - } - - /** - * Returns the size of the locked region in bytes. - */ - public final long size() - { - return size; - } - - /** - * Returns a string describing the range, type, and validity of this lock. - */ - public final String toString() - { - StringBuffer buf = new StringBuffer(getClass().getName()); - buf.append("["); - buf.append(position); - buf.append(":"); - buf.append(size); - if (shared) - buf.append(" shared"); - else - buf.append(" exclusive"); - if (isValid()) - buf.append(" valid]"); - else - buf.append(" invalid]"); - return buf.toString(); - } -} diff --git a/libjava/java/nio/channels/FileLockInterruptionException.java b/libjava/java/nio/channels/FileLockInterruptionException.java deleted file mode 100644 index 7d9e620464f..00000000000 --- a/libjava/java/nio/channels/FileLockInterruptionException.java +++ /dev/null @@ -1,55 +0,0 @@ -/* FileLockInterruptionException.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.nio.channels; - -import java.io.IOException; - - -/** - * @author Michael Koch - * @since 1.4 - */ -public class FileLockInterruptionException extends IOException -{ - /** - * Creates the exception - */ - public FileLockInterruptionException() - { - } -} diff --git a/libjava/java/nio/channels/GatheringByteChannel.java b/libjava/java/nio/channels/GatheringByteChannel.java deleted file mode 100644 index 822ea232a5c..00000000000 --- a/libjava/java/nio/channels/GatheringByteChannel.java +++ /dev/null @@ -1,79 +0,0 @@ -/* GatheringByteChannel.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.nio.channels; - -import java.io.IOException; -import java.nio.ByteBuffer; - - -public interface GatheringByteChannel extends WritableByteChannel -{ - /** - * Writes a sequence of bytes to this channel from a subsequence of - * the given buffers - * - * @exception AsynchronousCloseException If another thread closes this - * channel while the write operation is in progress - * @exception ClosedByInterruptException If another thread interrupts the - * current thread while the write operation is in progress, thereby closing - * the channel and setting the current thread's interrupt status - * @exception ClosedChannelException If this channel is closed - * @exception IndexOutOfBoundsException If the preconditions on the offset - * and length parameters do not hold - * @exception IOException If an error occurs - * @exception NonWritableChannelException If this channel was not opened for - * writing - */ - long write(ByteBuffer[] srcs, int offset, int length) - throws IOException; - - /** - * Writes a sequence of bytes to this channel from the given buffers - * - * @exception AsynchronousCloseException If another thread closes this - * channel while the write operation is in progress - * @exception ClosedByInterruptException If another thread interrupts the - * current thread while the write operation is in progress, thereby closing - * the channel and setting the current thread's interrupt status - * @exception ClosedChannelException If this channel is closed - * @exception IOException If an error occurs - * @exception NonWritableChannelException If this channel was not opened for - * writing - */ - long write(ByteBuffer[] srcs) throws IOException; -} diff --git a/libjava/java/nio/channels/IllegalBlockingModeException.java b/libjava/java/nio/channels/IllegalBlockingModeException.java deleted file mode 100644 index 7352b54f7f1..00000000000 --- a/libjava/java/nio/channels/IllegalBlockingModeException.java +++ /dev/null @@ -1,57 +0,0 @@ -/* IllegalBlockingModeException.java -- - Copyright (C) 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.nio.channels; - - -/** - * @author Michael Koch (konqueror@gmx.de) - * @since 1.4 - * - * Written using JDK 1.4.1 Online API from Sun - * Status: JDK 1.4 complete - */ -public class IllegalBlockingModeException extends IllegalStateException -{ - /** - * Creates the exception - */ - public IllegalBlockingModeException() - { - super(); - } -} diff --git a/libjava/java/nio/channels/IllegalSelectorException.java b/libjava/java/nio/channels/IllegalSelectorException.java deleted file mode 100644 index 049a8d594f4..00000000000 --- a/libjava/java/nio/channels/IllegalSelectorException.java +++ /dev/null @@ -1,53 +0,0 @@ -/* IllegalSelectorException.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.nio.channels; - - -/** - * @author Michael Koch - * @since 1.4 - */ -public class IllegalSelectorException extends IllegalArgumentException -{ - /** - * Creates the exception - */ - public IllegalSelectorException() - { - } -} diff --git a/libjava/java/nio/channels/InterruptibleChannel.java b/libjava/java/nio/channels/InterruptibleChannel.java deleted file mode 100644 index 54122ceadbc..00000000000 --- a/libjava/java/nio/channels/InterruptibleChannel.java +++ /dev/null @@ -1,51 +0,0 @@ -/* InterruptibleChannel.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.nio.channels; - -import java.io.IOException; - - -public interface InterruptibleChannel extends Channel -{ - /** - * Closes this channel - * - * @exception IOException If an error occurs - */ - void close() throws IOException; -} diff --git a/libjava/java/nio/channels/NoConnectionPendingException.java b/libjava/java/nio/channels/NoConnectionPendingException.java deleted file mode 100644 index afefebf9807..00000000000 --- a/libjava/java/nio/channels/NoConnectionPendingException.java +++ /dev/null @@ -1,53 +0,0 @@ -/* NoConnectionPendingException.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.nio.channels; - - -/** - * @author Michael Koch - * @since 1.4 - */ -public class NoConnectionPendingException extends IllegalStateException -{ - /** - * Creates the exception - */ - public NoConnectionPendingException() - { - } -} diff --git a/libjava/java/nio/channels/NonReadableChannelException.java b/libjava/java/nio/channels/NonReadableChannelException.java deleted file mode 100644 index e6852a73d3f..00000000000 --- a/libjava/java/nio/channels/NonReadableChannelException.java +++ /dev/null @@ -1,53 +0,0 @@ -/* NonReadableChannelException.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.nio.channels; - - -/** - * @author Michael Koch - * @since 1.4 - */ -public class NonReadableChannelException extends IllegalStateException -{ - /** - * Creates the exception - */ - public NonReadableChannelException() - { - } -} diff --git a/libjava/java/nio/channels/NonWritableChannelException.java b/libjava/java/nio/channels/NonWritableChannelException.java deleted file mode 100644 index 61d40bbc4d6..00000000000 --- a/libjava/java/nio/channels/NonWritableChannelException.java +++ /dev/null @@ -1,53 +0,0 @@ -/* NonWritableChannelException.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.nio.channels; - - -/** - * @author Michael Koch - * @since 1.4 - */ -public class NonWritableChannelException extends IllegalStateException -{ - /** - * Creates the exception - */ - public NonWritableChannelException() - { - } -} diff --git a/libjava/java/nio/channels/NotYetBoundException.java b/libjava/java/nio/channels/NotYetBoundException.java deleted file mode 100644 index 7d0c66388cd..00000000000 --- a/libjava/java/nio/channels/NotYetBoundException.java +++ /dev/null @@ -1,53 +0,0 @@ -/* NotYetBoundException.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.nio.channels; - - -/** - * @author Michael Koch - * @since 1.4 - */ -public class NotYetBoundException extends IllegalStateException -{ - /** - * Creates the exception - */ - public NotYetBoundException() - { - } -} diff --git a/libjava/java/nio/channels/NotYetConnectedException.java b/libjava/java/nio/channels/NotYetConnectedException.java deleted file mode 100644 index 463e05934a8..00000000000 --- a/libjava/java/nio/channels/NotYetConnectedException.java +++ /dev/null @@ -1,53 +0,0 @@ -/* NotYetConnectedException.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.nio.channels; - - -/** - * @author Michael Koch - * @since 1.4 - */ -public class NotYetConnectedException extends IllegalStateException -{ - /** - * Creates the exception - */ - public NotYetConnectedException() - { - } -} diff --git a/libjava/java/nio/channels/OverlappingFileLockException.java b/libjava/java/nio/channels/OverlappingFileLockException.java deleted file mode 100644 index ce0900c6a49..00000000000 --- a/libjava/java/nio/channels/OverlappingFileLockException.java +++ /dev/null @@ -1,53 +0,0 @@ -/* OverlappingFileLockException.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.nio.channels; - - -/** - * @author Michael Koch - * @since 1.4 - */ -public class OverlappingFileLockException extends IllegalStateException -{ - /** - * Creates the exception - */ - public OverlappingFileLockException() - { - } -} diff --git a/libjava/java/nio/channels/Pipe.java b/libjava/java/nio/channels/Pipe.java deleted file mode 100644 index c7b04c88c8f..00000000000 --- a/libjava/java/nio/channels/Pipe.java +++ /dev/null @@ -1,121 +0,0 @@ -/* Pipe.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.nio.channels; - -import java.io.IOException; -import java.nio.channels.spi.AbstractSelectableChannel; -import java.nio.channels.spi.SelectorProvider; - - -/** - * @author Michael Koch - * @since 1.4 - */ -public abstract class Pipe -{ - public abstract static class SinkChannel extends AbstractSelectableChannel - implements WritableByteChannel, GatheringByteChannel - { - /** - * Initializes the channel. - */ - protected SinkChannel(SelectorProvider provider) - { - super(provider); - } - - /** - * Returns an operation set that is valid on this channel. - * - * The only valid operation on this channel is @see SelectionKey.OP_WRITE. - */ - public final int validOps() - { - return SelectionKey.OP_WRITE; - } - } - - public abstract static class SourceChannel extends AbstractSelectableChannel - implements ReadableByteChannel, ScatteringByteChannel - { - /** - * Initializes the channel. - */ - protected SourceChannel(SelectorProvider provider) - { - super(provider); - } - - /** - * Returns an operation set that is valid on this channel. - * - * The only valid operation on this channel is @see SelectionKey.OP_READ. - */ - public final int validOps() - { - return SelectionKey.OP_READ; - } - } - - /** - * Initializes the pipe. - */ - protected Pipe() - { - } - - /** - * Opens a pipe. - * - * @exception IOException If an error occurs - */ - public static Pipe open() throws IOException - { - return SelectorProvider.provider().openPipe(); - } - - /** - * Returns a pipe's sink channel. - */ - public abstract Pipe.SinkChannel sink(); - - /** - * Returns a pipe's source channel - */ - public abstract Pipe.SourceChannel source(); -} diff --git a/libjava/java/nio/channels/ReadableByteChannel.java b/libjava/java/nio/channels/ReadableByteChannel.java deleted file mode 100644 index 889662de054..00000000000 --- a/libjava/java/nio/channels/ReadableByteChannel.java +++ /dev/null @@ -1,64 +0,0 @@ -/* ReadableByteChannel.java -- - Copyright (C) 2002, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.nio.channels; - -import java.io.IOException; -import java.nio.ByteBuffer; - - -public interface ReadableByteChannel extends Channel -{ - /** - * Reads a sequence of bytes from this channel into the given buffer - * - * @param dst the buffer to put the read data into - * - * @return the numer of bytes read - * - * @exception AsynchronousCloseException If another thread closes this - * channel while the read operation is in progress - * @exception ClosedByInterruptException If another thread interrupts the - * current thread while the read operation is in progress, thereby closing - * the channel and setting the current thread's interrupt status - * @exception ClosedChannelException If this channel is closed - * @exception IOException If an error occurs - * @exception NonReadableChannelException If this channel was not opened for - * reading - */ - int read(ByteBuffer dst) throws IOException; -} diff --git a/libjava/java/nio/channels/ScatteringByteChannel.java b/libjava/java/nio/channels/ScatteringByteChannel.java deleted file mode 100644 index 5437ea15818..00000000000 --- a/libjava/java/nio/channels/ScatteringByteChannel.java +++ /dev/null @@ -1,79 +0,0 @@ -/* ScatteringByteChannel.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.nio.channels; - -import java.io.IOException; -import java.nio.ByteBuffer; - - -public interface ScatteringByteChannel extends ReadableByteChannel -{ - /** - * Reads a sequence of bytes from this channel into a subsequence of the - * given buffers - * - * @exception AsynchronousCloseException If another thread closes this - * channel while the write operation is in progress - * @exception ClosedByInterruptException If another thread interrupts the - * current thread while the write operation is in progress, thereby closing - * the channel and setting the current thread's interrupt status - * @exception ClosedChannelException If this channel is closed - * @exception IndexOutOfBoundsException If the preconditions on the offset - * and length parameters do not hold - * @exception IOException If an error occurs - * @exception NonReadableChannelException If this channel was not opened for - * reading - */ - long read(ByteBuffer[] srcs, int offset, int length) - throws IOException; - - /** - * Reads a sequence of bytes from this channel into the given buffers - * - * @exception AsynchronousCloseException If another thread closes this - * channel while the write operation is in progress - * @exception ClosedByInterruptException If another thread interrupts the - * current thread while the write operation is in progress, thereby closing - * the channel and setting the current thread's interrupt status - * @exception ClosedChannelException If this channel is closed - * @exception IOException If an error occurs - * @exception NonReadableChannelException If this channel was not opened for - * reading - */ - long read(ByteBuffer[] srcs) throws IOException; -} diff --git a/libjava/java/nio/channels/SelectableChannel.java b/libjava/java/nio/channels/SelectableChannel.java deleted file mode 100644 index 70fa785ce54..00000000000 --- a/libjava/java/nio/channels/SelectableChannel.java +++ /dev/null @@ -1,140 +0,0 @@ -/* SelectableChannel.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.nio.channels; - -import java.io.IOException; -import java.nio.channels.spi.AbstractInterruptibleChannel; -import java.nio.channels.spi.SelectorProvider; - - -/** - * @author Michael Koch - * @since 1.4 - */ -public abstract class SelectableChannel extends AbstractInterruptibleChannel -{ - /** - * Initializes the channel. - */ - protected SelectableChannel() - { - } - - /** - * Returns the lock of this channel. - */ - public abstract Object blockingLock(); - - /** - * Adjusts this channel's blocking mode. - * - * @exception ClosedChannelException If this channel is closed. - * @exception IllegalBlockingModeException If block is true and this channel - * is registered with one or more selectors. - * @exception IOException If an error occurs. - */ - public abstract SelectableChannel configureBlocking(boolean block) - throws IOException; - - /** - * Tells whether this channel is blocking or not. - */ - public abstract boolean isBlocking(); - - /** - * Tells whether or not this channel is currently registered with - * any selectors. - */ - public abstract boolean isRegistered(); - - /** - * Retrieves the key representing the channel's registration with - * the given selector. - */ - public abstract SelectionKey keyFor(Selector sel); - - /** - * Returns the provider that created this channel. - */ - public abstract SelectorProvider provider(); - - /** - * Registers this channel with the given selector, - * returning a selection key. - * - * @exception CancelledKeyException If this channel is currently registered - * with the given selector but the corresponding key has already been cancelled - * @exception ClosedChannelException If this channel is closed. - * @exception IllegalArgumentException If a bit in ops does not correspond - * to an operation that is supported by this channel, that is, if - * set & ~validOps() != 0. - * @exception IllegalBlockingModeException If block is true and this channel - * is registered with one or more selectors. - * @exception IllegalSelectorException If this channel was not created by - * the same provider as the given selector. - */ - public final SelectionKey register(Selector sel, int ops) - throws ClosedChannelException - { - return register(sel, ops, null); - } - - /** - * Registers this channel with the given selector, - * returning a selection key. - * - * @exception CancelledKeyException If this channel is currently registered - * with the given selector but the corresponding key has already been - * cancelled. - * @exception ClosedChannelException If this channel is closed. - * @exception IllegalArgumentException If a bit in ops does not correspond - * to an operation that is supported by this channel, that is, if - * set & ~validOps() != 0. - * @exception IllegalBlockingModeException If block is true and this channel - * is registered with one or more selectors. - * @exception IllegalSelectorException If this channel was not created by - * the same provider as the given selector. - */ - public abstract SelectionKey register(Selector sel, int ops, Object att) - throws ClosedChannelException; - - /** - * Returns a set of valid operations on this channel. - */ - public abstract int validOps(); -} diff --git a/libjava/java/nio/channels/SelectionKey.java b/libjava/java/nio/channels/SelectionKey.java deleted file mode 100644 index 5219b6bff84..00000000000 --- a/libjava/java/nio/channels/SelectionKey.java +++ /dev/null @@ -1,164 +0,0 @@ -/* SelectionKey.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.nio.channels; - - -/** - * @author Michael Koch - * @since 1.4 - */ -public abstract class SelectionKey -{ - public static final int OP_ACCEPT = 16; - public static final int OP_CONNECT = 8; - public static final int OP_READ = 1; - public static final int OP_WRITE = 4; - Object attached; - - /** - * Initializes the selection key. - */ - protected SelectionKey() - { - } - - /** - * Attaches obj to the key and returns the old attached object. - */ - public final Object attach(Object obj) - { - Object old = attached; - attached = obj; - return old; - } - - /** - * Returns the object attached to the key. - */ - public final Object attachment() - { - return attached; - } - - /** - * Tests if the channel attached to this key is ready to accept - * a new socket connection. - * - * @exception CancelledKeyException If this key has been cancelled - */ - public final boolean isAcceptable() - { - return (readyOps() & OP_ACCEPT) != 0; - } - - /** - * Tests whether this key's channel has either finished, - * or failed to finish, its socket-connection operation. - * - * @exception CancelledKeyException If this key has been cancelled - */ - public final boolean isConnectable() - { - return (readyOps() & OP_CONNECT) != 0; - } - - /** - * Tests if the channel attached to the key is readable. - * - * @exception CancelledKeyException If this key has been cancelled - */ - public final boolean isReadable() - { - return (readyOps() & OP_READ) != 0; - } - - /** - * Tests if the channel attached to the key is writable. - * - * @exception CancelledKeyException If this key has been cancelled - */ - public final boolean isWritable() - { - return (readyOps() & OP_WRITE) != 0; - } - - /** - * Requests that the registration of this key's channel with - * its selector be cancelled. - */ - public abstract void cancel(); - - /** - * return the channel attached to the key. - */ - public abstract SelectableChannel channel(); - - /** - * Returns the key's interest set. - * - * @exception CancelledKeyException If this key has been cancelled - */ - public abstract int interestOps(); - - /** - * Sets this key's interest set to the given value. - * - * @exception CancelledKeyException If this key has been cancelled - * @exception IllegalArgumentException If a bit in the set does not - * correspond to an operation that is supported by this key's channel, - * that is, if set & ~(channel().validOps()) != 0 - */ - public abstract SelectionKey interestOps(int ops); - - /** - * Tells whether or not this key is valid. - */ - public abstract boolean isValid(); - - /** - * Retrieves this key's ready-operation set. - * - * @exception CancelledKeyException If this key has been cancelled - */ - public abstract int readyOps(); - - /** - * Returns the selector for which this key was created. - */ - public abstract Selector selector(); -} diff --git a/libjava/java/nio/channels/Selector.java b/libjava/java/nio/channels/Selector.java deleted file mode 100644 index 2c883efd1a1..00000000000 --- a/libjava/java/nio/channels/Selector.java +++ /dev/null @@ -1,134 +0,0 @@ -/* Selector.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.nio.channels; - -import java.io.IOException; -import java.nio.channels.spi.SelectorProvider; -import java.util.Set; - - -/** - * @author Michael Koch - * @since 1.4 - */ -public abstract class Selector -{ - /** - * Initializes the selector. - */ - protected Selector() - { - } - - /** - * Opens a selector. - * - * @exception IOException If an error occurs - */ - public static Selector open() throws IOException - { - return SelectorProvider.provider().openSelector(); - } - - /** - * Closes the selector. - * - * @exception IOException If an error occurs - */ - public abstract void close() throws IOException; - - /** - * Tells whether the selector is open or not. - */ - public abstract boolean isOpen(); - - /** - * Returns this selector's key set. - * - * @exception ClosedSelectorException If this selector is closed. - */ - public abstract Set keys(); - - /** - * Returns the SelectorProvider that created the selector. - */ - public abstract SelectorProvider provider(); - - /** - * Selects a set of keys whose corresponding channels are ready - * for I/O operations. - * - * @exception ClosedSelectorException If this selector is closed. - * @exception IOException If an error occurs - */ - public abstract int select() throws IOException; - - /** - * Selects a set of keys whose corresponding channels are ready - * for I/O operations. - * - * @param timeout The timeout to use. - * - * @exception ClosedSelectorException If this selector is closed. - * @exception IllegalArgumentException If the timeout value is negative. - * @exception IOException If an error occurs - */ - public abstract int select(long timeout) throws IOException; - - /** - * Returns this selector's selected-key set. - * - * @exception ClosedSelectorException If this selector is closed. - */ - public abstract Set selectedKeys(); - - /** - * Selects a set of keys whose corresponding channels are ready - * for I/O operations. - * - * @exception ClosedSelectorException If this selector is closed. - * @exception IOException If an error occurs - */ - public abstract int selectNow() throws IOException; - - /** - * Causes the first selection operation that has not yet returned to - * return immediately. - */ - public abstract Selector wakeup(); -} diff --git a/libjava/java/nio/channels/ServerSocketChannel.java b/libjava/java/nio/channels/ServerSocketChannel.java deleted file mode 100644 index 105d17f94ec..00000000000 --- a/libjava/java/nio/channels/ServerSocketChannel.java +++ /dev/null @@ -1,98 +0,0 @@ -/* ServerSocketChannel.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.nio.channels; - -import java.io.IOException; -import java.net.ServerSocket; -import java.nio.channels.spi.AbstractSelectableChannel; -import java.nio.channels.spi.SelectorProvider; - - -/** - * @author Michael Koch - * @since 1.4 - */ -public abstract class ServerSocketChannel extends AbstractSelectableChannel -{ - /** - * Initializes this channel. - */ - protected ServerSocketChannel(SelectorProvider provider) - { - super(provider); - } - - /** - * Accepts a connection made to this channel's socket. - * - * @exception IOException If an error occurs - * @exception AsynchronousCloseException If another thread closes this - * channel while the accept operation is in progress. - * @exception ClosedByInterruptException If another thread interrupts the - * current thread while the accept operation is in progress, thereby closing - * the channel and setting the current thread's interrupt status. - * @exception ClosedChannelException If the channel is closed. - * @exception NotYetBoundException If the channel's socket is not yet bound. - * @exception SecurityException If a security manager has been installed and - * it does not permit access to the remote endpoint of the new connection. - */ - public abstract SocketChannel accept() throws IOException; - - /** - * Retrieves the channels socket. - */ - public abstract ServerSocket socket(); - - /** - * Opens a server socket channel. - * - * @exception IOException If an error occurs - */ - public static ServerSocketChannel open() throws IOException - { - return SelectorProvider.provider().openServerSocketChannel(); - } - - /** - * Retrieves the valid operations for this channel. - */ - public final int validOps() - { - return SelectionKey.OP_ACCEPT; - } -} diff --git a/libjava/java/nio/channels/SocketChannel.java b/libjava/java/nio/channels/SocketChannel.java deleted file mode 100644 index 50f21368c88..00000000000 --- a/libjava/java/nio/channels/SocketChannel.java +++ /dev/null @@ -1,248 +0,0 @@ -/* SocketChannel.java -- - Copyright (C) 2002, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.nio.channels; - -import java.io.IOException; -import java.net.Socket; -import java.net.SocketAddress; -import java.nio.ByteBuffer; -import java.nio.channels.spi.AbstractSelectableChannel; -import java.nio.channels.spi.SelectorProvider; - -/** - * @author Michael Koch (konqueror@gmx.de) - * @since 1.4 - */ -public abstract class SocketChannel extends AbstractSelectableChannel - implements ByteChannel, ScatteringByteChannel, GatheringByteChannel -{ - /** - * Initializes this socket channel. - */ - protected SocketChannel(SelectorProvider provider) - { - super(provider); - } - - /** - * Opens a socket channel. - * - * @return the new <code>SocketChannel</code> object - * - * @exception IOException If an error occurs - */ - public static SocketChannel open() throws IOException - { - return SelectorProvider.provider().openSocketChannel(); - } - - /** - * Opens a channel and connects it to a remote address. - * - * @return the new <code>SocketChannel</code> object - * - * @exception AsynchronousCloseException If this channel is already connected. - * @exception ClosedByInterruptException If another thread interrupts the - * current thread while the connect operation is in progress, thereby closing - * the channel and setting the current thread's interrupt status. - * @exception IOException If an error occurs - * @exception SecurityException If a security manager has been installed and - * it does not permit access to the given remote endpoint. - * @exception UnresolvedAddressException If the given remote address is not - * fully resolved. - * @exception UnsupportedAddressTypeException If the type of the given remote - * address is not supported. - */ - public static SocketChannel open(SocketAddress remote) - throws IOException - { - SocketChannel ch = open(); - ch.connect(remote); - return ch; - } - - /** - * Reads data from the channel. - * - * @return the number of bytes read, zero is valid too, -1 if end of stream - * is reached - * - * @exception IOException If an error occurs - * @exception NotYetConnectedException If this channel is not yet connected. - */ - public final long read(ByteBuffer[] dsts) throws IOException - { - long b = 0; - - for (int i = 0; i < dsts.length; i++) - b += read(dsts[i]); - - return b; - } - - /** - * Writes data to the channel. - * - * @return the number of bytes written, zero is valid too - * - * @exception IOException If an error occurs - * @exception NotYetConnectedException If this channel is not yet connected. - */ - public final long write(ByteBuffer[] dsts) throws IOException - { - long b = 0; - - for (int i = 0; i < dsts.length; i++) - b += write(dsts[i]); - - return b; - } - - /** - * Retrieves the valid operations for this channel. - * - * @return the valid operations - */ - public final int validOps() - { - return SelectionKey.OP_CONNECT | SelectionKey.OP_READ - | SelectionKey.OP_WRITE; - } - - /** - * Reads data from the channel. - * - * @return the number of bytes read, zero is valid too, -1 if end of stream - * is reached - * - * @exception IOException If an error occurs - * @exception NotYetConnectedException If this channel is not yet connected. - */ - public abstract int read(ByteBuffer dst) throws IOException; - - /** - * Connects the channel's socket to the remote address. - * - * @return <code>true</code> if the channel got successfully connected, - * <code>false</code> if the channel is in non-blocking mode and connection - * operation is still in progress. - * - * @exception AlreadyConnectedException If this channel is already connected. - * @exception AsynchronousCloseException If this channel is already connected. - * @exception ClosedByInterruptException If another thread interrupts the - * current thread while the connect operation is in progress, thereby closing - * the channel and setting the current thread's interrupt status. - * @exception ClosedChannelException If this channel is closed. - * @exception ConnectionPendingException If a non-blocking connection - * operation is already in progress on this channel. - * @exception IOException If an error occurs - * @exception SecurityException If a security manager has been installed and - * it does not permit access to the given remote endpoint. - * @exception UnresolvedAddressException If the given remote address is not - * fully resolved. - * @exception UnsupportedAddressTypeException If the type of the given remote - * address is not supported. - */ - public abstract boolean connect(SocketAddress remote) - throws IOException; - - /** - * Finishes the process of connecting a socket channel. - * - * @exception AsynchronousCloseException If this channel is already connected. - * @exception ClosedByInterruptException If another thread interrupts the - * current thread while the connect operation is in progress, thereby closing - * the channel and setting the current thread's interrupt status. - * @exception ClosedChannelException If this channel is closed. - * @exception IOException If an error occurs - * @exception NoConnectionPendingException If this channel is not connected - * and a connection operation has not been initiated. - */ - public abstract boolean finishConnect() throws IOException; - - /** - * Tells whether or not the channel's socket is connected. - */ - public abstract boolean isConnected(); - - /** - * Tells whether or not a connection operation is in progress on this channel. - */ - public abstract boolean isConnectionPending(); - - /** - * Reads data from the channel. - * - * @return the number of bytes read, zero is valid too, -1 if end of stream - * is reached - * - * @exception IOException If an error occurs - * @exception NotYetConnectedException If this channel is not yet connected. - */ - public abstract long read(ByteBuffer[] dsts, int offset, int length) - throws IOException; - - /** - * Retrieves the channel's socket. - * - * @return the socket - */ - public abstract Socket socket(); - - /** - * Writes data to the channel. - * - * @return the number of bytes written, zero is valid too - * - * @exception IOException If an error occurs - * @exception NotYetConnectedException If this channel is not yet connected. - */ - public abstract int write(ByteBuffer src) throws IOException; - - /** - * Writes data to the channel. - * - * @return the number of bytes written, zero is valid too - * - * @exception IOException If an error occurs - * @exception NotYetConnectedException If this channel is not yet connected. - */ - public abstract long write(ByteBuffer[] srcs, int offset, int length) - throws IOException; -} diff --git a/libjava/java/nio/channels/UnresolvedAddressException.java b/libjava/java/nio/channels/UnresolvedAddressException.java deleted file mode 100644 index 4db95a7ffdd..00000000000 --- a/libjava/java/nio/channels/UnresolvedAddressException.java +++ /dev/null @@ -1,53 +0,0 @@ -/* UnresolvedAddressException.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.nio.channels; - - -/** - * @author Michael Koch - * @since 1.4 - */ -public class UnresolvedAddressException extends IllegalArgumentException -{ - /** - * Creates the exception - */ - public UnresolvedAddressException() - { - } -} diff --git a/libjava/java/nio/channels/UnsupportedAddressTypeException.java b/libjava/java/nio/channels/UnsupportedAddressTypeException.java deleted file mode 100644 index 7c16c813fb0..00000000000 --- a/libjava/java/nio/channels/UnsupportedAddressTypeException.java +++ /dev/null @@ -1,53 +0,0 @@ -/* UnsupportedAddressTypeException.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.nio.channels; - - -/** - * @author Michael Koch - * @since 1.4 - */ -public class UnsupportedAddressTypeException extends IllegalArgumentException -{ - /** - * Creates the exception - */ - public UnsupportedAddressTypeException() - { - } -} diff --git a/libjava/java/nio/channels/WritableByteChannel.java b/libjava/java/nio/channels/WritableByteChannel.java deleted file mode 100644 index 3845723bca0..00000000000 --- a/libjava/java/nio/channels/WritableByteChannel.java +++ /dev/null @@ -1,60 +0,0 @@ -/* WritableByteChannel.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.nio.channels; - -import java.io.IOException; -import java.nio.ByteBuffer; - - -public interface WritableByteChannel extends Channel -{ - /** - * Writes a sequence of bytes to this channel from the given buffer - * - * @exception AsynchronousCloseException If another thread closes this - * channel while the write operation is in progress - * @exception ClosedByInterruptException If another thread interrupts the - * current thread while the write operation is in progress, thereby closing - * the channel and setting the current thread's interrupt status - * @exception ClosedChannelException If this channel is closed - * @exception IOException If an error occurs - * @exception NonWritableChannelException If this channel was not opened for - * writing - */ - int write(ByteBuffer src) throws IOException; -} diff --git a/libjava/java/nio/channels/spi/AbstractInterruptibleChannel.java b/libjava/java/nio/channels/spi/AbstractInterruptibleChannel.java deleted file mode 100644 index 25e8785c08e..00000000000 --- a/libjava/java/nio/channels/spi/AbstractInterruptibleChannel.java +++ /dev/null @@ -1,119 +0,0 @@ -/* AbstractInterruptibleChannel.java -- - Copyright (C) 2002, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.nio.channels.spi; - -import java.io.IOException; -import java.nio.channels.AsynchronousCloseException; -import java.nio.channels.Channel; -import java.nio.channels.InterruptibleChannel; - - -/** - * @author Michael Koch - * @since 1.4 - */ -public abstract class AbstractInterruptibleChannel - implements Channel, InterruptibleChannel -{ - private boolean closed; - - /** - * Initializes the channel. - */ - protected AbstractInterruptibleChannel() - { - } - - /** - * Marks the beginning of an I/O operation that might block indefinitely. - */ - protected final void begin() - { - } - - /** - * Closes the channel. - * - * @exception IOException If an error occurs - */ - public final void close() throws IOException - { - if (! closed) - { - closed = true; - implCloseChannel(); - } - } - - /** - * Marks the end of an I/O operation that might block indefinitely. - * - * @param completed true if the task completed successfully, - * false otherwise - * - * @exception IOException if an error occurs - * @exception AsynchronousCloseException If the channel was asynchronously - * closed. - * @exception ClosedByInterruptException If the thread blocked in the - * I/O operation was interrupted. - */ - protected final void end(boolean completed) - throws AsynchronousCloseException - { - // FIXME: check more here. - - if (closed) throw new AsynchronousCloseException(); - } - - /** - * Closes the channel. - * - * @exception IOException If an error occurs - */ - protected abstract void implCloseChannel() throws IOException; - - /** - * Tells whether or not this channel is open. - * - * @return true if the channel is open, false otherwise - */ - public final boolean isOpen() - { - return ! closed; - } -} diff --git a/libjava/java/nio/channels/spi/AbstractSelectableChannel.java b/libjava/java/nio/channels/spi/AbstractSelectableChannel.java deleted file mode 100644 index 42ceab7e2c1..00000000000 --- a/libjava/java/nio/channels/spi/AbstractSelectableChannel.java +++ /dev/null @@ -1,256 +0,0 @@ -/* AbstractSelectableChannel.java - Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.nio.channels.spi; - -import java.io.IOException; -import java.nio.channels.ClosedChannelException; -import java.nio.channels.SelectableChannel; -import java.nio.channels.SelectionKey; -import java.nio.channels.Selector; -import java.util.LinkedList; -import java.util.ListIterator; - -public abstract class AbstractSelectableChannel extends SelectableChannel -{ - private boolean blocking = true; - private Object LOCK = new Object(); - private SelectorProvider provider; - private LinkedList keys = new LinkedList(); - - /** - * Initializes the channel - * - * @param provider the provider that created this channel - */ - protected AbstractSelectableChannel(SelectorProvider provider) - { - this.provider = provider; - } - - /** - * Retrieves the object upon which the configureBlocking and register - * methods synchronize. - * - * @return the blocking lock - */ - public final Object blockingLock() - { - return LOCK; - } - - /** - * Adjusts this channel's blocking mode. - * - * @param blocking true if blocking should be enabled, false otherwise - * - * @return this channel - * - * @exception IOException If an error occurs - */ - public final SelectableChannel configureBlocking(boolean blocking) - throws IOException - { - synchronized (blockingLock()) - { - if (this.blocking != blocking) - { - implConfigureBlocking(blocking); - this.blocking = blocking; - } - } - - return this; - } - - /** - * Closes this channel. - * - * @exception IOException If an error occurs - */ - protected final void implCloseChannel() throws IOException - { - implCloseSelectableChannel(); - } - - /** - * Closes this selectable channel. - * - * @exception IOException If an error occurs - */ - protected abstract void implCloseSelectableChannel() - throws IOException; - - /** - * Adjusts this channel's blocking mode. - * - * @param blocking true if blocking should be enabled, false otherwise - * - * @exception IOException If an error occurs - */ - protected abstract void implConfigureBlocking(boolean blocking) - throws IOException; - - /** - * Tells whether or not every I/O operation on this channel will block - * until it completes. - * - * @return true of this channel is blocking, false otherwise - */ - public final boolean isBlocking() - { - return blocking; - } - - /** - * Tells whether or not this channel is currently registered with - * any selectors. - * - * @return true if this channel is registered, false otherwise - */ - public final boolean isRegistered() - { - return ! keys.isEmpty(); - } - - /** - * Retrieves the key representing the channel's registration with the - * given selector. - * - * @param selector the selector to get a selection key for - * - * @return the selection key this channel is registered with - */ - public final SelectionKey keyFor(Selector selector) - { - if (! isOpen()) - return null; - - try - { - synchronized (blockingLock()) - { - return locate(selector); - } - } - catch (Exception e) - { - return null; - } - } - - /** - * Returns the provider that created this channel. - * - * @return the selector provider that created this channel - */ - public final SelectorProvider provider() - { - return provider; - } - - private SelectionKey locate(Selector selector) - { - ListIterator it = keys.listIterator(); - - while (it.hasNext()) - { - SelectionKey key = (SelectionKey) it.next(); - - if (key.selector() == selector) - return key; - } - - return null; - } - - /** - * Registers this channel with the given selector, returning a selection key. - * - * @param selin the seletor to use - * @param ops the interested operations - * @param att an attachment for the returned selection key - * - * @return the registered selection key - * - * @exception ClosedChannelException If the channel is already closed. - */ - public final SelectionKey register(Selector selin, int ops, Object att) - throws ClosedChannelException - { - if (! isOpen()) - throw new ClosedChannelException(); - - if ((ops & ~validOps()) != 0) - throw new IllegalArgumentException(); - - SelectionKey key = null; - AbstractSelector selector = (AbstractSelector) selin; - - synchronized (blockingLock()) - { - key = locate(selector); - - if (key != null && key.isValid()) - { - if (att != null) - key.attach(att); - } - else - { - key = selector.register(this, ops, att); - - if (key != null) - addSelectionKey(key); - } - } - - return key; - } - - void addSelectionKey(SelectionKey key) - { - keys.add(key); - } - - // This method gets called by AbstractSelector.deregister(). - void removeSelectionKey(SelectionKey key) - { - keys.remove(key); - } -} diff --git a/libjava/java/nio/channels/spi/AbstractSelectionKey.java b/libjava/java/nio/channels/spi/AbstractSelectionKey.java deleted file mode 100644 index 5ab8468bf2e..00000000000 --- a/libjava/java/nio/channels/spi/AbstractSelectionKey.java +++ /dev/null @@ -1,78 +0,0 @@ -/* AbstractSelectionKey.java -- - Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.nio.channels.spi; - -import java.nio.channels.SelectionKey; - - -/** - * @since 1.4 - */ -public abstract class AbstractSelectionKey extends SelectionKey -{ - private boolean cancelled; - - /** - * Initializes the key. - */ - protected AbstractSelectionKey() - { - } - - /** - * Cancels this key. - */ - public final void cancel() - { - if (isValid()) - { - ((AbstractSelector) selector()).cancelKey(this); - cancelled = true; - } - } - - /** - * Tells whether this key is valid or not. - * - * @return true if this key is valid, false otherwise - */ - public final boolean isValid() - { - return ! cancelled; - } -} diff --git a/libjava/java/nio/channels/spi/AbstractSelector.java b/libjava/java/nio/channels/spi/AbstractSelector.java deleted file mode 100644 index 78380738a2c..00000000000 --- a/libjava/java/nio/channels/spi/AbstractSelector.java +++ /dev/null @@ -1,167 +0,0 @@ -/* AbstractSelector.java -- - Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.nio.channels.spi; - -import java.io.IOException; -import java.nio.channels.ClosedSelectorException; -import java.nio.channels.SelectionKey; -import java.nio.channels.Selector; -import java.util.HashSet; -import java.util.Set; - - -public abstract class AbstractSelector extends Selector -{ - private boolean closed; - private SelectorProvider provider; - private HashSet cancelledKeys; - - /** - * Initializes the slector. - * - * @param provider the provider that created this selector - */ - protected AbstractSelector(SelectorProvider provider) - { - this.provider = provider; - this.cancelledKeys = new HashSet(); - } - - /** - * Closes the channel. - * - * @exception IOException If an error occurs - */ - public final synchronized void close() throws IOException - { - if (closed) - return; - - implCloseSelector(); - closed = true; - } - - /** - * Tells whether this channel is open or not. - * - * @return true if channel is open, false otherwise. - */ - public final boolean isOpen() - { - return ! closed; - } - - /** - * Marks the beginning of an I/O operation that might block indefinitely. - */ - protected final void begin() - { - } - - /** - * Marks the end of an I/O operation that might block indefinitely. - */ - protected final void end() - { - } - - /** - * Returns the provider for this selector object. - * - * @return the SelectorProvider object that created this seletor - */ - public final SelectorProvider provider() - { - return provider; - } - - /** - * Returns the cancelled keys set. - * - * @return the cancelled keys set - */ - protected final Set cancelledKeys() - { - if (! isOpen()) - throw new ClosedSelectorException(); - - return cancelledKeys; - } - - /** - * Cancels a selection key. - */ - - // This method is only called by AbstractSelectionKey.cancel(). - final void cancelKey(AbstractSelectionKey key) - { - synchronized (cancelledKeys) - { - cancelledKeys.add(key); - } - } - - /** - * Closes the channel. - * - * @exception IOException if an error occurs - */ - protected abstract void implCloseSelector() throws IOException; - - /** - * Registers a channel for the selection process. - * - * @param ch the channel register - * @param ops the interested operations - * @param att an attachement to the selection key - * - * @return the registered selection key - */ - protected abstract SelectionKey register(AbstractSelectableChannel ch, - int ops, Object att); - - /** - * Deregisters the given selection key. - * - * @param key the key to deregister - */ - protected final void deregister(AbstractSelectionKey key) - { - ((AbstractSelectableChannel) key.channel()).removeSelectionKey(key); - } -} diff --git a/libjava/java/nio/channels/spi/SelectorProvider.java b/libjava/java/nio/channels/spi/SelectorProvider.java deleted file mode 100644 index db4e65fe14e..00000000000 --- a/libjava/java/nio/channels/spi/SelectorProvider.java +++ /dev/null @@ -1,151 +0,0 @@ -/* SelectorProvider.java - Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.nio.channels.spi; - -import gnu.java.nio.SelectorProviderImpl; - -import java.io.IOException; -import java.nio.channels.DatagramChannel; -import java.nio.channels.Pipe; -import java.nio.channels.ServerSocketChannel; -import java.nio.channels.SocketChannel; - - -/** - * @author Michael Koch - * @since 1.4 - */ -public abstract class SelectorProvider -{ - private static SelectorProvider systemDefaultProvider; - - /** - * Initializes the selector provider. - * - * @exception SecurityException If a security manager has been installed and - * it denies @see RuntimePermission ("selectorProvider"). - */ - protected SelectorProvider() - { - SecurityManager sm = System.getSecurityManager(); - if (sm != null) - sm.checkPermission(new RuntimePermission("selectorProvider")); - } - - /** - * Opens a datagram channel. - * - * @return a new datagram channel object - * - * @exception IOException if an error occurs - */ - public abstract DatagramChannel openDatagramChannel() - throws IOException; - - /** - * Opens a pipe. - * - * @return a new pipe object - * - * @exception IOException if an error occurs - */ - public abstract Pipe openPipe() throws IOException; - - /** - * Opens a selector. - * - * @return a new selector object - * - * @exception IOException if an error occurs - */ - public abstract AbstractSelector openSelector() throws IOException; - - /** - * Opens a server socket channel. - * - * @return a new server socket channel object - * - * @exception IOException if an error occurs - */ - public abstract ServerSocketChannel openServerSocketChannel() - throws IOException; - - /** - * Opens a socket channel. - * - * @return a new socket channel object - * - * @exception IOException if an error occurs - */ - public abstract SocketChannel openSocketChannel() throws IOException; - - /** - * Returns the system-wide default selector provider for this invocation - * of the Java virtual machine. - * - * @return the default seletor provider - */ - public static synchronized SelectorProvider provider() - { - if (systemDefaultProvider == null) - { - String propertyValue = - System.getProperty("java.nio.channels.spi.SelectorProvider"); - - if (propertyValue == null || propertyValue.equals("")) - systemDefaultProvider = new SelectorProviderImpl(); - else - { - try - { - systemDefaultProvider = - (SelectorProvider) Class.forName(propertyValue) - .newInstance(); - } - catch (Exception e) - { - System.err.println("Could not instantiate class: " - + propertyValue); - systemDefaultProvider = new SelectorProviderImpl(); - } - } - } - - return systemDefaultProvider; - } -} diff --git a/libjava/java/nio/charset/CharacterCodingException.java b/libjava/java/nio/charset/CharacterCodingException.java deleted file mode 100644 index 6812ebb18a9..00000000000 --- a/libjava/java/nio/charset/CharacterCodingException.java +++ /dev/null @@ -1,53 +0,0 @@ -/* CharacterCodingException.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.nio.charset; - -import java.io.IOException; - -/** - * @since 1.4 - */ -public class CharacterCodingException extends IOException -{ - /** - * Creates the exception - */ - public CharacterCodingException() - { - } -} diff --git a/libjava/java/nio/charset/CharsetDecoder.java b/libjava/java/nio/charset/CharsetDecoder.java deleted file mode 100644 index 0203c8803a1..00000000000 --- a/libjava/java/nio/charset/CharsetDecoder.java +++ /dev/null @@ -1,313 +0,0 @@ -/* CharsetDecoder.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.nio.charset; - -import java.nio.ByteBuffer; -import java.nio.CharBuffer; - -/** - * @author Jesse Rosenstock - * @since 1.4 - */ -public abstract class CharsetDecoder -{ - private static final int STATE_RESET = 0; - private static final int STATE_CODING = 1; - private static final int STATE_END = 2; - private static final int STATE_FLUSHED = 3; - - private static final String DEFAULT_REPLACEMENT = "\uFFFD"; - - private final Charset charset; - private final float averageCharsPerByte; - private final float maxCharsPerByte; - private String replacement; - - private int state = STATE_RESET; - - private CodingErrorAction malformedInputAction - = CodingErrorAction.REPORT; - private CodingErrorAction unmappableCharacterAction - = CodingErrorAction.REPORT; - - private CharsetDecoder (Charset cs, float averageCharsPerByte, - float maxCharsPerByte, String replacement) - { - if (averageCharsPerByte <= 0.0f) - throw new IllegalArgumentException ("Non-positive averageCharsPerByte"); - if (maxCharsPerByte <= 0.0f) - throw new IllegalArgumentException ("Non-positive maxCharsPerByte"); - - this.charset = cs; - this.averageCharsPerByte - = averageCharsPerByte; - this.maxCharsPerByte - = maxCharsPerByte; - this.replacement = replacement; - implReplaceWith (replacement); - } - - protected CharsetDecoder (Charset cs, float averageCharsPerByte, - float maxCharsPerByte) - { - this (cs, averageCharsPerByte, maxCharsPerByte, DEFAULT_REPLACEMENT); - } - - public final float averageCharsPerByte () - { - return averageCharsPerByte; - } - - public final Charset charset () - { - return charset; - } - - public final CharBuffer decode (ByteBuffer in) - throws CharacterCodingException - { - // XXX: Sun's Javadoc seems to contradict itself saying an - // IllegalStateException is thrown "if a decoding operation is already - // in progress" and also that "it resets this Decoder". - // Should we check to see that the state is reset, or should we - // call reset()? - if (state != STATE_RESET) - throw new IllegalStateException (); - - // REVIEW: Using max instead of average may allocate a very large - // buffer. Maybe we should do something more efficient? - int remaining = in.remaining (); - int n = (int) (remaining * maxCharsPerByte ()); - CharBuffer out = CharBuffer.allocate (n); - - if (remaining == 0) - { - state = STATE_FLUSHED; - return out; - } - - CoderResult cr = decode (in, out, true); - if (cr.isError ()) - cr.throwException (); - - cr = flush (out); - if (cr.isError ()) - cr.throwException (); - - reset(); - out.flip (); - return out; - } - - public final CoderResult decode (ByteBuffer in, CharBuffer out, - boolean endOfInput) - { - int newState = endOfInput ? STATE_END : STATE_CODING; - // XXX: Need to check for "previous step was an invocation [not] of - // this method with a value of true for the endOfInput parameter but - // a return value indicating an incomplete decoding operation" - // XXX: We will not check the previous return value, just - // that the previous call passed true for endOfInput - if (state != STATE_RESET && state != STATE_CODING - && !(endOfInput && state == STATE_END)) - throw new IllegalStateException (); - state = newState; - - for (;;) - { - CoderResult cr; - try - { - cr = decodeLoop (in, out); - } - catch (RuntimeException e) - { - throw new CoderMalfunctionError (e); - } - - if (cr.isOverflow ()) - return cr; - - if (cr.isUnderflow ()) - { - if (endOfInput && in.hasRemaining ()) - cr = CoderResult.malformedForLength (in.remaining ()); - else - return cr; - } - - CodingErrorAction action = cr.isMalformed () - ? malformedInputAction - : unmappableCharacterAction; - - if (action == CodingErrorAction.REPORT) - return cr; - - if (action == CodingErrorAction.REPLACE) - { - if (out.remaining () < replacement.length ()) - return CoderResult.OVERFLOW; - out.put (replacement); - } - - in.position (in.position () + cr.length ()); - } - } - - protected abstract CoderResult decodeLoop (ByteBuffer in, CharBuffer out); - - public Charset detectedCharset () - { - throw new UnsupportedOperationException (); - } - - public final CoderResult flush (CharBuffer out) - { - // It seems weird that you can flush after reset, but Sun's javadoc - // says an IllegalStateException is thrown "If the previous step of the - // current decoding operation was an invocation neither of the reset - // method nor ... of the three-argument decode method with a value of - // true for the endOfInput parameter." - // Further note that flush() only requires that there not be - // an IllegalStateException if the previous step was a call to - // decode with true as the last argument. It does not require - // that the call succeeded. decode() does require that it succeeded. - // XXX: test this to see if reality matches javadoc - if (state != STATE_RESET && state != STATE_END) - throw new IllegalStateException (); - - state = STATE_FLUSHED; - return implFlush (out); - } - - protected CoderResult implFlush (CharBuffer out) - { - return CoderResult.UNDERFLOW; - } - - public final CharsetDecoder onMalformedInput (CodingErrorAction newAction) - { - if (newAction == null) - throw new IllegalArgumentException ("Null action"); - - malformedInputAction = newAction; - implOnMalformedInput (newAction); - return this; - } - - protected void implOnMalformedInput (CodingErrorAction newAction) - { - // default implementation does nothing - } - - protected void implOnUnmappableCharacter (CodingErrorAction newAction) - { - // default implementation does nothing - } - - protected void implReplaceWith (String newReplacement) - { - // default implementation does nothing - } - - protected void implReset () - { - // default implementation does nothing - } - - public boolean isAutoDetecting () - { - return false; - } - - public boolean isCharsetDetected () - { - throw new UnsupportedOperationException (); - } - - public CodingErrorAction malformedInputAction () - { - return malformedInputAction; - } - - public final float maxCharsPerByte () - { - return maxCharsPerByte; - } - - public final CharsetDecoder onUnmappableCharacter - (CodingErrorAction newAction) - { - if (newAction == null) - throw new IllegalArgumentException ("Null action"); - - unmappableCharacterAction = newAction; - implOnUnmappableCharacter (newAction); - return this; - } - - public final String replacement () - { - return replacement; - } - - public final CharsetDecoder replaceWith (String newReplacement) - { - if (newReplacement == null) - throw new IllegalArgumentException ("Null replacement"); - if (newReplacement.length () == 0) - throw new IllegalArgumentException ("Empty replacement"); - // XXX: what about maxCharsPerByte? - - this.replacement = newReplacement; - implReplaceWith (newReplacement); - return this; - } - - public final CharsetDecoder reset () - { - state = STATE_RESET; - implReset (); - return this; - } - - public CodingErrorAction unmappableCharacterAction () - { - return unmappableCharacterAction; - } -} diff --git a/libjava/java/nio/charset/CharsetEncoder.java b/libjava/java/nio/charset/CharsetEncoder.java deleted file mode 100644 index 0c6184f2989..00000000000 --- a/libjava/java/nio/charset/CharsetEncoder.java +++ /dev/null @@ -1,365 +0,0 @@ -/* CharsetEncoder.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.nio.charset; - -import java.nio.ByteBuffer; -import java.nio.CharBuffer; - -/** - * @author Jesse Rosenstock - * @since 1.4 - */ -public abstract class CharsetEncoder -{ - private static final int STATE_RESET = 0; - private static final int STATE_CODING = 1; - private static final int STATE_END = 2; - private static final int STATE_FLUSHED = 3; - - private static final byte[] DEFAULT_REPLACEMENT = {(byte)'?'}; - - private final Charset charset; - private final float averageBytesPerChar; - private final float maxBytesPerChar; - private byte[] replacement; - - private int state = STATE_RESET; - - private CodingErrorAction malformedInputAction - = CodingErrorAction.REPORT; - private CodingErrorAction unmappableCharacterAction - = CodingErrorAction.REPORT; - - protected CharsetEncoder (Charset cs, float averageBytesPerChar, - float maxBytesPerChar) - { - this (cs, averageBytesPerChar, maxBytesPerChar, DEFAULT_REPLACEMENT); - } - - protected CharsetEncoder (Charset cs, float averageBytesPerChar, - float maxBytesPerChar, byte[] replacement) - { - if (averageBytesPerChar <= 0.0f) - throw new IllegalArgumentException ("Non-positive averageBytesPerChar"); - if (maxBytesPerChar <= 0.0f) - throw new IllegalArgumentException ("Non-positive maxBytesPerChar"); - - this.charset = cs; - this.averageBytesPerChar - = averageBytesPerChar; - this.maxBytesPerChar - = maxBytesPerChar; - this.replacement = replacement; - implReplaceWith (replacement); - } - - public final float averageBytesPerChar () - { - return averageBytesPerChar; - } - - public boolean canEncode (char c) - { - CharBuffer cb = CharBuffer.allocate (1).put (c); - cb.flip (); - return canEncode (cb); - } - - public boolean canEncode (CharSequence cs) - { - CharBuffer cb; - if (cs instanceof CharBuffer) - cb = ((CharBuffer) cs).duplicate (); - else - cb = CharBuffer.wrap (cs); - return canEncode (cb); - } - - private boolean canEncode (CharBuffer cb) - { - // It is an error if a coding operation is "in progress" - // I take that to mean the state is not reset or flushed. - // XXX: check "in progress" everywhere - if (state == STATE_FLUSHED) - reset (); - else if (state != STATE_RESET) - throw new IllegalStateException (); - - CodingErrorAction oldMalformedInputAction = malformedInputAction; - CodingErrorAction oldUnmappableCharacterAction - = unmappableCharacterAction; - - try - { - if (oldMalformedInputAction != CodingErrorAction.REPORT) - onMalformedInput (CodingErrorAction.REPORT); - if (oldUnmappableCharacterAction != CodingErrorAction.REPORT) - onUnmappableCharacter (CodingErrorAction.REPORT); - } - catch (Exception e) - { - return false; - } - finally - { - if (oldMalformedInputAction != CodingErrorAction.REPORT) - onMalformedInput (oldMalformedInputAction); - if (oldUnmappableCharacterAction != CodingErrorAction.REPORT) - onUnmappableCharacter (oldUnmappableCharacterAction); - } - - return true; - } - - public final Charset charset () - { - return charset; - } - - public final ByteBuffer encode (CharBuffer in) - throws CharacterCodingException - { - // XXX: Sun's Javadoc seems to contradict itself saying an - // IllegalStateException is thrown "if a decoding operation is already - // in progress" and also that "it resets this Encoder". - // Should we check to see that the state is reset, or should we - // call reset()? - if (state != STATE_RESET) - throw new IllegalStateException (); - - // REVIEW: Using max instead of average may allocate a very large - // buffer. Maybe we should do something more efficient? - int remaining = in.remaining (); - int n = (int) (remaining * maxBytesPerChar ()); - ByteBuffer out = ByteBuffer.allocate (n); - - if (remaining == 0) - { - state = STATE_FLUSHED; - return out; - } - - CoderResult cr = encode (in, out, true); - if (cr.isError ()) - cr.throwException (); - - cr = flush (out); - if (cr.isError ()) - cr.throwException (); - - out.flip (); - return out; - } - - public final CoderResult encode (CharBuffer in, ByteBuffer out, - boolean endOfInput) - { - int newState = endOfInput ? STATE_END : STATE_CODING; - // XXX: Need to check for "previous step was an invocation [not] of - // this method with a value of true for the endOfInput parameter but - // a return value indicating an incomplete decoding operation" - // XXX: We will not check the previous return value, just - // that the previous call passed true for endOfInput - if (state != STATE_RESET && state != STATE_CODING - && !(endOfInput && state == STATE_END)) - throw new IllegalStateException (); - state = newState; - - for (;;) - { - CoderResult cr; - try - { - cr = encodeLoop (in, out); - } - catch (RuntimeException e) - { - throw new CoderMalfunctionError (e); - } - - if (cr.isOverflow ()) - return cr; - - if (cr.isUnderflow ()) - { - if (endOfInput && in.hasRemaining ()) - cr = CoderResult.malformedForLength (in.remaining ()); - else - return cr; - } - - CodingErrorAction action = cr.isMalformed () - ? malformedInputAction - : unmappableCharacterAction; - - if (action == CodingErrorAction.REPORT) - return cr; - - if (action == CodingErrorAction.REPLACE) - { - if (out.remaining () < replacement.length) - return CoderResult.OVERFLOW; - out.put (replacement); - } - - in.position (in.position () + cr.length ()); - } - } - - protected abstract CoderResult encodeLoop (CharBuffer in, ByteBuffer out); - - public final CoderResult flush (ByteBuffer out) - { - // It seems weird that you can flush after reset, but Sun's javadoc - // says an IllegalStateException is thrown "If the previous step of the - // current decoding operation was an invocation neither of the reset - // method nor ... of the three-argument encode method with a value of - // true for the endOfInput parameter." - // Further note that flush() only requires that there not be - // an IllegalStateException if the previous step was a call to - // encode with true as the last argument. It does not require - // that the call succeeded. encode() does require that it succeeded. - // XXX: test this to see if reality matches javadoc - if (state != STATE_RESET && state != STATE_END) - throw new IllegalStateException (); - - state = STATE_FLUSHED; - return implFlush (out); - } - - protected CoderResult implFlush (ByteBuffer out) - { - return CoderResult.UNDERFLOW; - } - - protected void implOnMalformedInput (CodingErrorAction newAction) - { - // default implementation does nothing - } - - protected void implOnUnmappableCharacter (CodingErrorAction newAction) - { - // default implementation does nothing - } - - protected void implReplaceWith (byte[] newReplacement) - { - // default implementation does nothing - } - - protected void implReset () - { - // default implementation does nothing - } - - public boolean isLegalReplacement (byte[] replacement) - { - // TODO: cache the decoder - // error actions will be REPORT after construction - CharsetDecoder decoder = charset.newDecoder (); - ByteBuffer bb = ByteBuffer.wrap (replacement); - CharBuffer cb - = CharBuffer.allocate ((int) (replacement.length - * decoder.maxCharsPerByte ())); - return !decoder.decode (bb, cb, true).isError (); - } - - public CodingErrorAction malformedInputAction () - { - return malformedInputAction; - } - - public final float maxBytesPerChar () - { - return maxBytesPerChar; - } - - public final CharsetEncoder onMalformedInput (CodingErrorAction newAction) - { - if (newAction == null) - throw new IllegalArgumentException ("Null action"); - - malformedInputAction = newAction; - implOnMalformedInput (newAction); - return this; - } - - public CodingErrorAction unmappableCharacterAction () - { - return unmappableCharacterAction; - } - - public final CharsetEncoder onUnmappableCharacter - (CodingErrorAction newAction) - { - if (newAction == null) - throw new IllegalArgumentException ("Null action"); - - unmappableCharacterAction = newAction; - implOnUnmappableCharacter (newAction); - return this; - } - - public final byte[] replacement () - { - return replacement; - } - - public final CharsetEncoder replaceWith (byte[] newReplacement) - { - if (newReplacement == null) - throw new IllegalArgumentException ("Null replacement"); - if (newReplacement.length == 0) - throw new IllegalArgumentException ("Empty replacement"); - // XXX: what about maxBytesPerChar? - - if (!isLegalReplacement (newReplacement)) - throw new IllegalArgumentException ("Illegal replacement"); - - this.replacement = newReplacement; - implReplaceWith (newReplacement); - return this; - } - - public final CharsetEncoder reset () - { - state = STATE_RESET; - implReset (); - return this; - } -} diff --git a/libjava/java/nio/charset/CoderMalfunctionError.java b/libjava/java/nio/charset/CoderMalfunctionError.java deleted file mode 100644 index 08294cafb20..00000000000 --- a/libjava/java/nio/charset/CoderMalfunctionError.java +++ /dev/null @@ -1,52 +0,0 @@ -/* CoderMalfunctionError.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.nio.charset; - -/** - * @since 1.4 - */ -public class CoderMalfunctionError extends Error -{ - /** - * Creates the error - */ - public CoderMalfunctionError(Exception cause) - { - super (cause); - } -} diff --git a/libjava/java/nio/charset/CoderResult.java b/libjava/java/nio/charset/CoderResult.java deleted file mode 100644 index 664215d9a68..00000000000 --- a/libjava/java/nio/charset/CoderResult.java +++ /dev/null @@ -1,189 +0,0 @@ -/* CoderResult.java -- - Copyright (C) 2002, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.nio.charset; - -import java.lang.ref.WeakReference; -import java.nio.BufferOverflowException; -import java.nio.BufferUnderflowException; -import java.util.HashMap; - -/** - * @author Jesse Rosenstock - * @since 1.4 - */ -public class CoderResult -{ - private static final int TYPE_MALFORMED = 0; - private static final int TYPE_OVERFLOW = 1; - private static final int TYPE_UNDERFLOW = 2; - private static final int TYPE_UNMAPPABLE = 3; - - public static final CoderResult OVERFLOW - = new CoderResult (TYPE_OVERFLOW, 0); - public static final CoderResult UNDERFLOW - = new CoderResult (TYPE_UNDERFLOW, 0); - - private static final String[] names - = { "MALFORMED", "OVERFLOW", "UNDERFLOW", "UNMAPPABLE" }; - - private static final Cache malformedCache - = new Cache () - { - protected CoderResult make (int length) - { - return new CoderResult (TYPE_MALFORMED, length); - } - }; - - private static final Cache unmappableCache - = new Cache () - { - protected CoderResult make (int length) - { - return new CoderResult (TYPE_UNMAPPABLE, length); - } - }; - - private final int type; - private final int length; - - // Package-private to avoid a trampoline constructor. - CoderResult (int type, int length) - { - this.type = type; - this.length = length; - } - - public boolean isError () - { - return length > 0; - } - - public boolean isMalformed () - { - return type == TYPE_MALFORMED; - } - - public boolean isOverflow () - { - return type == TYPE_OVERFLOW; - } - - public boolean isUnderflow () - { - return type == TYPE_UNDERFLOW; - } - - public boolean isUnmappable () - { - return type == TYPE_UNMAPPABLE; - } - - public int length () - { - if (length <= 0) - throw new UnsupportedOperationException (); - else - return length; - } - - public static CoderResult malformedForLength (int length) - { - return malformedCache.get (length); - } - - public void throwException () - throws CharacterCodingException - { - switch (type) - { - case TYPE_MALFORMED: - throw new MalformedInputException (length); - case TYPE_OVERFLOW: - throw new BufferOverflowException (); - case TYPE_UNDERFLOW: - throw new BufferUnderflowException (); - case TYPE_UNMAPPABLE: - throw new UnmappableCharacterException (length); - } - } - - public String toString () - { - String name = names[type]; - return (length > 0) ? name + '[' + length + ']' : name; - } - - public static CoderResult unmappableForLength (int length) - { - return unmappableCache.get (length); - } - - private abstract static class Cache - { - private final HashMap cache; - - // Package-private to avoid a trampoline constructor. - Cache () - { - cache = new HashMap (); - } - - // Package-private to avoid a trampoline. - synchronized CoderResult get (int length) - { - if (length <= 0) - throw new IllegalArgumentException ("Non-positive length"); - - Integer len = new Integer (length); - CoderResult cr = null; - Object o; - if ((o = cache.get (len)) != null) - cr = (CoderResult) ((WeakReference) o).get (); - if (cr == null) - { - cr = make (length); - cache.put (len, new WeakReference (cr)); - } - - return cr; - } - - protected abstract CoderResult make (int length); - } -} diff --git a/libjava/java/nio/charset/CodingErrorAction.java b/libjava/java/nio/charset/CodingErrorAction.java deleted file mode 100644 index 592c15934ac..00000000000 --- a/libjava/java/nio/charset/CodingErrorAction.java +++ /dev/null @@ -1,66 +0,0 @@ -/* CodingErrorAction.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.nio.charset; - -public class CodingErrorAction -{ - public static final CodingErrorAction IGNORE - = new CodingErrorAction("ignore"); - public static final CodingErrorAction REPLACE - = new CodingErrorAction("replace"); - public static final CodingErrorAction REPORT - = new CodingErrorAction("report"); - - private final String name; - - /** - * Private constructor only used to create the constant CodingErrorActions. - */ - private CodingErrorAction(String name) - { - this.name = name; - } - - /** - * Returns the name of the CodingErrorAction. - */ - public String toString () - { - return name; - } -} diff --git a/libjava/java/nio/charset/IllegalCharsetNameException.java b/libjava/java/nio/charset/IllegalCharsetNameException.java deleted file mode 100644 index 7baeac3234e..00000000000 --- a/libjava/java/nio/charset/IllegalCharsetNameException.java +++ /dev/null @@ -1,73 +0,0 @@ -/* IllegalCharsetNameException.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.nio.charset; - -/** - * @author Michael Koch - * @since 1.4 - */ -public class IllegalCharsetNameException extends IllegalArgumentException -{ - /** - * Compatible with JDK 1.4+ - */ - private static final long serialVersionUID = 1457525358470002989L; - - private String charsetName; - - /** - * Creates the exception - * - * @param charsetName name of the illegal charset - */ - public IllegalCharsetNameException (String charsetName) - { - super (); - this.charsetName = charsetName; - } - - /** - * Retrieves the illegal charset name - * - * @return the illegal charset name - */ - public String getCharsetName () - { - return charsetName; - } -} diff --git a/libjava/java/nio/charset/MalformedInputException.java b/libjava/java/nio/charset/MalformedInputException.java deleted file mode 100644 index 0beceb40cb3..00000000000 --- a/libjava/java/nio/charset/MalformedInputException.java +++ /dev/null @@ -1,77 +0,0 @@ -/* MalformedInputException.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.nio.charset; - -/** - * @since 1.4 - */ -public class MalformedInputException extends CharacterCodingException -{ - private int inputLength; - - /** - * Creates the exception - * - * @param inputLength the position of malformed input in the input stream - */ - public MalformedInputException (int inputLength) - { - super (); - this.inputLength = inputLength; - } - - /** - * Retrieves the position of the malformed input in the input stream. - * - * @return the position - */ - public int getInputLength () - { - return inputLength; - } - - /** - * Returns the detail message string of this throwable - * - * @return the message - */ - public String getMessage () - { - return "Input length = " + inputLength; - } -} diff --git a/libjava/java/nio/charset/UnmappableCharacterException.java b/libjava/java/nio/charset/UnmappableCharacterException.java deleted file mode 100644 index 71906510849..00000000000 --- a/libjava/java/nio/charset/UnmappableCharacterException.java +++ /dev/null @@ -1,71 +0,0 @@ -/* UnmappableCharacterException.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.nio.charset; - -/** - * @since 1.4 - */ -public class UnmappableCharacterException extends CharacterCodingException -{ - private int inputLength; - - /** - * Creates the exception - */ - public UnmappableCharacterException (int inputLength) - { - super (); - this.inputLength = inputLength; - } - - /** - * Retrieves the illegal charset name - */ - public int getInputLength () - { - return inputLength; - } - - /** - * Returns the detail message string of this throwable - */ - public String getMessage () - { - return "Input length = " + inputLength; - } -} diff --git a/libjava/java/nio/charset/UnsupportedCharsetException.java b/libjava/java/nio/charset/UnsupportedCharsetException.java deleted file mode 100644 index 39536baa563..00000000000 --- a/libjava/java/nio/charset/UnsupportedCharsetException.java +++ /dev/null @@ -1,69 +0,0 @@ -/* UnsupportedCharsetException.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.nio.charset; - -/** - * @author Michael Koch - * @since 1.4 - */ -public class UnsupportedCharsetException extends IllegalArgumentException -{ - /** - * Compatible with JDK 1.4+ - */ - private static final long serialVersionUID = 1490765524727386367L; - - String charsetName; - - /** - * Creates the exception - */ - public UnsupportedCharsetException (String charsetName) - { - super (); - this.charsetName = charsetName; - } - - /** - * Retrieves the illegal charset name - */ - public String getCharsetName () - { - return charsetName; - } -} diff --git a/libjava/java/nio/charset/spi/CharsetProvider.java b/libjava/java/nio/charset/spi/CharsetProvider.java deleted file mode 100644 index f0d40ab8591..00000000000 --- a/libjava/java/nio/charset/spi/CharsetProvider.java +++ /dev/null @@ -1,91 +0,0 @@ -/* CharsetProvider.java -- charset service provider interface - Copyright (C) 2002 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.nio.charset.spi; - -import java.nio.charset.Charset; -import java.util.Iterator; - - -/** - * This class allows an implementor to provide additional character sets. The - * subclass must have a nullary constructor, and be attached to charset - * implementation classes. These extensions are loaded via the context class - * loader. To provide the charset extension, all files named - * <code>META-INF/services/java.nio.charset.spi.CharsetProvider</code> are - * read from the classpath. Each one should be a UTF-8 encoded list of - * fully-qualified names of concrete subclasses of this class; whitespace is - * ignored, and '#' starts comments. Duplicates are ignored. The - * implementations must be accessible to the classloader that requests them. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @see Charset - * @since 1.4 - * @status updated to 1.4 - */ -public abstract class CharsetProvider -{ - /** - * Initialize a new charset provider. This performs a security check on - * RuntimePermission("charsetProvider"). - * - * @throws SecurityException if building a new set is not allowed - */ - protected CharsetProvider() - { - SecurityManager s = System.getSecurityManager(); - if (s != null) - s.checkPermission(new RuntimePermission("charsetProvider")); - } - - /** - * Returns an iterator over the charsets defined by this provider. - * - * @return the iterator - * @see Charset#availableCharsets() - */ - public abstract Iterator charsets(); - - /** - * Returns the named charset, by canonical name or alias. - * - * @param name the name of the character - * - * @return the charset, or null if not supported - */ - public abstract Charset charsetForName(String name); -} // class CharsetProvider diff --git a/libjava/java/rmi/AccessException.java b/libjava/java/rmi/AccessException.java deleted file mode 100644 index b470780046c..00000000000 --- a/libjava/java/rmi/AccessException.java +++ /dev/null @@ -1,76 +0,0 @@ -/* AccessException.java -- thrown if the caller does not have access - Copyright (c) 1996, 1997, 1998, 1999, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.rmi; - -/** - * Thrown to indicate that the caller does not have permission to access - * certain data, such as <code>bind</code> in an ActivationSystem. - * - * @author unknown - * @see Naming - * @see ActivationSystem - * @since 1.1 - */ -public class AccessException extends RemoteException -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = 6314925228044966088l; - - /** - * Create an exception with a message. - * - * @param s the message - */ - public AccessException(String s) - { - super(s); - } - - /** - * Create an exception with a message and a cause. - * - * @param s the message - * @param e the cause - */ - public AccessException(String s, Exception e) - { - super(s, e); - } -} diff --git a/libjava/java/rmi/AlreadyBoundException.java b/libjava/java/rmi/AlreadyBoundException.java deleted file mode 100644 index 091c0ee5862..00000000000 --- a/libjava/java/rmi/AlreadyBoundException.java +++ /dev/null @@ -1,73 +0,0 @@ -/* AlreadyBoundException.java -- thrown if a binding is already bound - Copyright (c) 1996, 1997, 1998, 1999, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.rmi; - -/** - * Thrown on an attempt to bind an object in the registry that is already - * bound. - * - * @author unknown - * @see Naming#bind(String, Remote) - * @see Registry#bind(String, Remote) - * @since 1.1 - * @status updated to 1.4 - */ -public class AlreadyBoundException extends Exception -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = 9218657361741657110L; - - /** - * Create an exception with no message. - */ - public AlreadyBoundException() - { - } - - /** - * Create an exception with a message. - * - * @param s the message - */ - public AlreadyBoundException(String s) - { - super(s); - } -} diff --git a/libjava/java/rmi/ConnectException.java b/libjava/java/rmi/ConnectException.java deleted file mode 100644 index dc3abd19741..00000000000 --- a/libjava/java/rmi/ConnectException.java +++ /dev/null @@ -1,74 +0,0 @@ -/* ConnectException.java -- thrown if a connection is refused - Copyright (c) 1996, 1997, 1998, 1999, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.rmi; - -/** - * Thrown if a connection is refused for a remote call. - * - * @author unknown - * @since 1.1 - * @status updated to 1.4 - */ -public class ConnectException extends RemoteException -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = 4863550261346652506L; - - /** - * Create an exception with a message. - * - * @param s the message - */ - public ConnectException(String s) - { - super(s); - } - - /** - * Create an exception with a message and a cause. - * - * @param s the message - * @param e the cause - */ - public ConnectException(String s, Exception e) - { - super(s, e); - } -} diff --git a/libjava/java/rmi/ConnectIOException.java b/libjava/java/rmi/ConnectIOException.java deleted file mode 100644 index dde753ad558..00000000000 --- a/libjava/java/rmi/ConnectIOException.java +++ /dev/null @@ -1,74 +0,0 @@ -/* ConnectIOException.java -- thrown if an IO exception occurs during connect - Copyright (c) 1996, 1997, 1998, 1999, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.rmi; - -/** - * Wraps an I/O Exception thrown while connecting for a remote call. - * - * @author unknown - * @since 1.1 - * @status updated to 1.4 - */ -public class ConnectIOException extends RemoteException -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = -8087809532704668744L; - - /** - * Create an exception with a message. - * - * @param s the message - */ - public ConnectIOException(String s) - { - super(s); - } - - /** - * Create an exception with a message and a cause. - * - * @param s the message - * @param e the cause - */ - public ConnectIOException(String s, Exception e) - { - super(s, e); - } -} diff --git a/libjava/java/rmi/MarshalException.java b/libjava/java/rmi/MarshalException.java deleted file mode 100644 index e5c10a4bf79..00000000000 --- a/libjava/java/rmi/MarshalException.java +++ /dev/null @@ -1,76 +0,0 @@ -/* MarshalException.java -- wraps error while marshalling parameters - Copyright (c) 1996, 1997, 1998, 1999, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.rmi; - -/** - * Thrown if an exception occurs while marshalling data to send in a remote - * call. The call may not be retransmitted, if the "at most once" semantics - * are to be preserved. - * - * @author unknown - * @since 1.1 - * @status updated to 1.4 - */ -public class MarshalException extends RemoteException -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = 6223554758134037936L; - - /** - * Create an exception with a message. - * - * @param s the message - */ - public MarshalException(String s) - { - super(s); - } - - /** - * Create an exception with a message and a cause. - * - * @param s the message - * @param e the cause - */ - public MarshalException(String s, Exception e) - { - super(s, e); - } -} diff --git a/libjava/java/rmi/MarshalledObject.java b/libjava/java/rmi/MarshalledObject.java deleted file mode 100644 index 9ec0ace0e70..00000000000 --- a/libjava/java/rmi/MarshalledObject.java +++ /dev/null @@ -1,113 +0,0 @@ -/* MarshalledObject.java -- - Copyright (c) 1996, 1997, 1998, 1999, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.rmi; - -import gnu.java.rmi.RMIMarshalledObjectInputStream; -import gnu.java.rmi.RMIMarshalledObjectOutputStream; - -import java.io.ByteArrayOutputStream; -import java.io.Serializable; - -/** - * FIXME - doc missing - */ -public final class MarshalledObject implements Serializable -{ - //The following fields are from Java API Documentation "Serialized form" - private static final long serialVersionUID = 8988374069173025854L; - byte[] objBytes; - byte[] locBytes; - int hash; - - public MarshalledObject(Object obj) throws java.io.IOException - { - ByteArrayOutputStream objStream = new ByteArrayOutputStream(); - RMIMarshalledObjectOutputStream stream = new RMIMarshalledObjectOutputStream(objStream); - stream.writeObject(obj); - stream.flush(); - objBytes = objStream.toByteArray(); - locBytes = stream.getLocBytes(); - - //The following algorithm of calculating hashCode is similar to String - hash = 0; - for (int i = 0; i < objBytes.length; i++) - hash = hash * 31 + objBytes[i]; - if(locBytes != null) - for (int i = 0; i < locBytes.length; i++) - hash = hash * 31 + locBytes[i]; - } - - public boolean equals(Object obj) - { - if (! (obj instanceof MarshalledObject)) - return false; - - // hashCode even differs, don't do the time-consuming comparisons - if (obj.hashCode() != hash) - return false; - - MarshalledObject aobj = (MarshalledObject)obj; - if (objBytes == null || aobj.objBytes == null) - return objBytes == aobj.objBytes; - if (objBytes.length != aobj.objBytes.length) - return false; - for (int i = 0; i < objBytes.length; i++) - { - if (objBytes[i] != aobj.objBytes[i]) - return false; - } - // Ignore comparison of locBytes(annotation) - return true; - } - -public Object get() - throws java.io.IOException, java.lang.ClassNotFoundException -{ - if(objBytes == null) - return null; - RMIMarshalledObjectInputStream stream = - new RMIMarshalledObjectInputStream(objBytes, locBytes); - return stream.readObject(); -} - - public int hashCode() { - return hash; - } - -} diff --git a/libjava/java/rmi/Naming.java b/libjava/java/rmi/Naming.java deleted file mode 100644 index d48df069d8d..00000000000 --- a/libjava/java/rmi/Naming.java +++ /dev/null @@ -1,220 +0,0 @@ -/* Naming.java -- - Copyright (c) 1996, 1997, 1998, 1999, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.rmi; - -import java.net.MalformedURLException; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.URL; -import java.rmi.registry.LocateRegistry; -import java.rmi.registry.Registry; - -/** - * <p> - * The <code>Naming</code> class handles interactions with RMI registries. - * Each method takes a URL in <code>String</code> form, which points to - * the RMI registry. The scheme of the URL is irrelevant. The relevant - * part is: - * </p> - * <p> - * <code>//host:port/name</code> - * </p> - * <p> - * which tells the method how to locate and access the registry. The host - * and port are both optional, and default to `localhost' and the standard - * RMI registry port (1099) respectively. The name is simply a string - * used to refer to a particular service hosted by the registry. The - * registry does not attempt to interpret this further. - * </p> - * <p> - * RMI services are registered using one of these names, and the same name - * is later used by the client to lookup the service and access its methods. - * Registries can be shared by multiple services, or a service can create - * its own registry using <code>createRegistry()</code>. - * </p> - * - * @author Original author unknown. - * @author Ingo Proetel (proetel@aicas.com) - * @author Guilhem Lavaux (guilhem@kaffe.org) - * @author Jeroen Frijters (jeroen@frijters.net) - * @author Andrew John Hughes (gnu_andrew@member.fsf.org) - * @since 1.1 - */ -public final class Naming { - - /** - * This class isn't intended to be instantiated. - */ - private Naming() {} - -/** - * Looks for the remote object that is associated with the named service. - * Name and location is given in form of a URL without a scheme: - * - * <pre> - * //host:port/service-name - * </pre> - * - * The port is optional. - * - * @param name the service name and location - * @return Remote-object that implements the named service - * @throws NotBoundException if no object implements the service - * @throws MalformedURLException - * @throws RemoteException - */ -public static Remote lookup(String name) throws NotBoundException, MalformedURLException, RemoteException { - URL u = parseURL(name); - String serviceName = getName(u); - return (getRegistry(u).lookup(serviceName)); -} - -/** - * Try to bind the given object to the given service name. - * @param name - * @param obj - * @throws AlreadyBoundException - * @throws MalformedURLException - * @throws RemoteException - */ -public static void bind(String name, Remote obj) throws AlreadyBoundException, MalformedURLException, RemoteException { - URL u = parseURL(name); - String serviceName = getName(u); - getRegistry(u).bind(serviceName, obj); -} - -/** - * Remove a binding for a given service name. - * @param name - * @throws RemoteException - * @throws NotBoundException - * @throws MalformedURLException - */ -public static void unbind(String name) throws RemoteException, NotBoundException, MalformedURLException { - URL u = parseURL(name); - String serviceName = getName(u); - getRegistry(u).unbind(serviceName); -} - -/** - * Forces the binding between the given Remote-object and the given service name, even - * if there was already an object bound to this name. - * @param name - * @param obj - * @throws RemoteException - * @throws MalformedURLException - */ -public static void rebind(String name, Remote obj) throws RemoteException, MalformedURLException { - URL u = parseURL(name); - String serviceName = getName(u); - getRegistry(u).rebind(serviceName, obj); -} - -/** - * Lists all services at the named registry. - * @param name url that specifies the registry - * @return list of services at the name registry - * @throws RemoteException - * @throws MalformedURLException - */ -public static String[] list(String name) throws RemoteException, MalformedURLException { - return (getRegistry(parseURL(name)).list()); -} - -private static Registry getRegistry(URL u) throws RemoteException { - if (u.getPort() == -1) { - return (LocateRegistry.getRegistry(u.getHost())); - } - else { - return (LocateRegistry.getRegistry(u.getHost(), u.getPort())); - } -} - - /** - * Parses the supplied URL and converts it to use the HTTP - * protocol. From an RMI perspective, the scheme is irrelevant - * and we want to be able to create a URL for which a handler is - * available. - * - * @param name the URL in String form. - * @throws MalformedURLException if the URL is invalid. - */ - private static URL parseURL(String name) - throws MalformedURLException - { - try - { - URI uri = new URI(name); - String host = uri.getHost(); - int port = uri.getPort(); - String query = uri.getQuery(); - String path = uri.getPath(); - return new URL("http", - (host == null ? "localhost" : host), - (port == -1 ? 1099 : port), - uri.getPath() + (query == null ? "" : query)); - } - catch (URISyntaxException e) - { - throw new MalformedURLException("The URL syntax was invalid: " + - e.getMessage()); - } - } - - /** - * Checks that the URL contains a name, and removes any leading - * slashes. - * - * @param url the URL to check. - * @throws MalformedURLException if no name is specified. - */ - private static String getName(URL url) - throws MalformedURLException - { - String filename = url.getFile(); - if (filename.length() == 0) - throw new MalformedURLException("No path specified: " + url); - // If the filename begins with a slash we must cut it for - // name resolution. - if (filename.charAt(0) == '/') - return filename.substring(1); - return filename; - } - -} diff --git a/libjava/java/rmi/NoSuchObjectException.java b/libjava/java/rmi/NoSuchObjectException.java deleted file mode 100644 index 69f7d6c52fb..00000000000 --- a/libjava/java/rmi/NoSuchObjectException.java +++ /dev/null @@ -1,68 +0,0 @@ -/* NoSuchObjectException.java -- thrown if the remote object no longer exists - Copyright (c) 1996, 1997, 1998, 1999, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.rmi; - -/** - * Thrown on an attempt to invoke a call on an object that no longer exists - * in the remote Virtual Machine. The call may be retransmitted and still - * obey the semantics of "at most once". - * - * @author unknown - * @see RemoteObject#toStub(Remote) - * @see UnicastRemoteObject#unexportObject(Remote, boolean) - * @see Activatable#unexportObject(Remote, boolean) - * @since 1.1 - * @status updated to 1.4 - */ -public class NoSuchObjectException extends RemoteException -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = 6619395951570472985L; - - /** - * Create an exception with a message. - * - * @param s the message - */ - public NoSuchObjectException(String s) - { - super(s); - } -} diff --git a/libjava/java/rmi/NotBoundException.java b/libjava/java/rmi/NotBoundException.java deleted file mode 100644 index b8bc0a5320a..00000000000 --- a/libjava/java/rmi/NotBoundException.java +++ /dev/null @@ -1,75 +0,0 @@ -/* NotBoundException.java -- attempt to use a registry name with no binding - Copyright (c) 1996, 1997, 1998, 1999, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.rmi; - -/** - * Thrown on an attempt to lookup or unbind a registry name that has no - * associated binding. - * - * @author unknown - * @see Naming#lookup(String) - * @see Naming#unbind(String) - * @see Registry#lookup(String) - * @see Registry#unbind(String) - * @since 1.1 - * @status updated to 1.4 - */ -public class NotBoundException extends Exception -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = -1857741824849069317l; - - /** - * Create an exception with no message. - */ - public NotBoundException() - { - } - - /** - * Create an exception with a message. - * - * @param s the message - */ - public NotBoundException(String s) - { - super(s); - } -} diff --git a/libjava/java/rmi/RMISecurityException.java b/libjava/java/rmi/RMISecurityException.java deleted file mode 100644 index a44a67e2a02..00000000000 --- a/libjava/java/rmi/RMISecurityException.java +++ /dev/null @@ -1,77 +0,0 @@ -/* RMISecurityException.java -- deprecated version of SecurityException - Copyright (c) 1996, 1997, 1998, 1999, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.rmi; - -/** - * Never thrown, but originally intended to wrap a java.lang.SecurityException. - * - * @author unknown - * @since 1.1 - * @deprecated use {@link SecurityException} instead - * @status updated to 1.4 - */ -public class RMISecurityException extends SecurityException -{ - /** - * Compatible with JDK 1.1. - */ - private static final long serialVersionUID = -8433406075740433514L; - - /** - * Create an exception with a message. - * - * @param s the message - * @deprecated no longer needed - */ - public RMISecurityException(String n) - { - super(n); - } - - /** - * Create an exception with a message and a cause. - * - * @param s the message - * @param e the cause - * @deprecated no longer needed - */ - public RMISecurityException(String n, String a) - { - super(n); - } -} diff --git a/libjava/java/rmi/RMISecurityManager.java b/libjava/java/rmi/RMISecurityManager.java deleted file mode 100644 index a8eb13e1a0a..00000000000 --- a/libjava/java/rmi/RMISecurityManager.java +++ /dev/null @@ -1,48 +0,0 @@ -/* RMISecurityManager.java -- - Copyright (c) 1996, 1997, 1998, 1999, 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.rmi; - -/** - * @since 1.1 - */ -public class RMISecurityManager extends SecurityManager -{ - public RMISecurityManager() - { - } -} diff --git a/libjava/java/rmi/Remote.java b/libjava/java/rmi/Remote.java deleted file mode 100644 index 93c8d0aa127..00000000000 --- a/libjava/java/rmi/Remote.java +++ /dev/null @@ -1,41 +0,0 @@ -/* Remote.java - Copyright (c) 1996, 1997, 1998, 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.rmi; - -public interface Remote { -} diff --git a/libjava/java/rmi/RemoteException.java b/libjava/java/rmi/RemoteException.java deleted file mode 100644 index cbbb26299c3..00000000000 --- a/libjava/java/rmi/RemoteException.java +++ /dev/null @@ -1,127 +0,0 @@ -/* RemoteException.java -- common superclass for exceptions in java.rmi - Copyright (c) 1996, 1997, 1998, 1999, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.rmi; - -import java.io.IOException; - -/** - * The superclass of exceptions related to RMI (remote method invocation). - * Classes that implement <code>java.rmi.Remote</code> should list this - * exception in their throws clause. - * - * @author unknown - * @since 1.1 - * @status updated to 1.4 - */ -public class RemoteException extends IOException -{ - /** - * Compatible with JDK 1.2+. - */ - private static final long serialVersionUID = -5148567311918794206l; - - /** - * The cause of this exception. This pre-dates the exception chaining - * of Throwable; and although you can change this field, you are wiser - * to leave it alone. - * - * @serial the exception cause - */ - public Throwable detail; - - /** - * Create an exception with no message, and cause initialized to null. - */ - public RemoteException() - { - this(null, null); - } - - /** - * Create an exception with the given message, and cause initialized to null. - * - * @param s the message - */ - public RemoteException(String s) - { - this(s, null); - } - - /** - * Create an exception with the given message and cause. - * - * @param s the message - * @param ex the cause - */ - public RemoteException(String s, Throwable e) - { - super(s); - initCause(e); - detail = e; - } - - /** - * This method returns a message indicating what went wrong, in this - * format: - * <code>super.getMessage() + (detail == null ? "" - * : "; nested exception is:\n\t" + detail)</code>. - * - * @return the chained message - */ - public String getMessage() - { - if (detail == this || detail == null) - return super.getMessage(); - return super.getMessage() + "; nested exception is:\n\t" + detail; - } - - /** - * Returns the cause of this exception. Note that this may not be the - * original cause, thanks to the <code>detail</code> field being public - * and non-final (yuck). However, to avoid violating the contract of - * Throwable.getCause(), this returns null if <code>detail == this</code>, - * as no exception can be its own cause. - * - * @return the cause - * @since 1.4 - */ - public Throwable getCause() - { - return detail == this ? null : detail; - } -} diff --git a/libjava/java/rmi/ServerError.java b/libjava/java/rmi/ServerError.java deleted file mode 100644 index b1a15b02e74..00000000000 --- a/libjava/java/rmi/ServerError.java +++ /dev/null @@ -1,64 +0,0 @@ -/* ServerError.java -- wraps an error while creating the server - Copyright (c) 1996, 1997, 1998, 1999, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.rmi; - -/** - * Wraps any error thrown while processing the server of a remote call. - * - * @author unknown - * @since 1.1 - * @status updated to 1.4 - */ -public class ServerError extends RemoteException -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = 8455284893909696482L; - - /** - * Create an exception with a message and a cause. - * - * @param s the message - * @param e the cause - */ - public ServerError(String s, Error e) - { - super(s, e); - } -} diff --git a/libjava/java/rmi/ServerException.java b/libjava/java/rmi/ServerException.java deleted file mode 100644 index 5170aa7b0b5..00000000000 --- a/libjava/java/rmi/ServerException.java +++ /dev/null @@ -1,74 +0,0 @@ -/* ServerException.java -- wraps an exception while creating the server - Copyright (c) 1996, 1997, 1998, 1999, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.rmi; - -/** - * Wraps any exception thrown while processing the server of a remote call. - * - * @author unknown - * @since 1.1 - * @status updated to 1.4 - */ -public class ServerException extends RemoteException -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = -4775845313121906682l; - - /** - * Create an exception with a message. - * - * @param s the message - */ - public ServerException(String s) - { - super(s); - } - - /** - * Create an exception with a message and a cause. - * - * @param s the message - * @param e the cause - */ - public ServerException(String s, Exception e) - { - super(s, e); - } -} diff --git a/libjava/java/rmi/ServerRuntimeException.java b/libjava/java/rmi/ServerRuntimeException.java deleted file mode 100644 index 1f0813739a6..00000000000 --- a/libjava/java/rmi/ServerRuntimeException.java +++ /dev/null @@ -1,67 +0,0 @@ -/* ServerRuntimeException.java -- wraps an exception while creating the server - Copyright (c) 1996, 1997, 1998, 1999, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.rmi; - -/** - * Wraps any runtime exception thrown while processing the server of a - * remote call. Note, this exception is no longer used. - * - * @author unknown - * @since 1.1 - * @deprecated no replacement - * @status updated to 1.4 - */ -public class ServerRuntimeException extends RemoteException -{ - /** - * Compatible with JDK 1.1. - */ - private static final long serialVersionUID = 7054464920481467219L; - - /** - * Create an exception with a message and a cause. - * - * @param s the message - * @param e the cause - * @deprecated no longer needed - */ - public ServerRuntimeException(String s, Exception e) - { - super(s, e); - } -} diff --git a/libjava/java/rmi/StubNotFoundException.java b/libjava/java/rmi/StubNotFoundException.java deleted file mode 100644 index 2f9e0f5ff59..00000000000 --- a/libjava/java/rmi/StubNotFoundException.java +++ /dev/null @@ -1,77 +0,0 @@ -/* StubNotFoundException.java -- thrown if a valid stub is not found - Copyright (c) 1996, 1997, 1998, 1999, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.rmi; - -/** - * Thrown if a valid stub class is not found for an object when it is exported. - * - * @author unknown - * @see UnicastRemoteObject - * @see Activatable - * @since 1.1 - * @status updated to 1.4 - */ -public class StubNotFoundException extends RemoteException -{ - /** - * Compatible with JDK 1.2+. - */ - private static final long serialVersionUID = -7088199405468872373L; - - - /** - * Create an exception with a message. - * - * @param s the message - */ - public StubNotFoundException(String s) - { - super(s); - } - - /** - * Create an exception with a message and a cause. - * - * @param s the message - * @param e the cause - */ - public StubNotFoundException(String s, Exception e) - { - super(s, e); - } -} diff --git a/libjava/java/rmi/UnexpectedException.java b/libjava/java/rmi/UnexpectedException.java deleted file mode 100644 index e9e0d6a9d48..00000000000 --- a/libjava/java/rmi/UnexpectedException.java +++ /dev/null @@ -1,75 +0,0 @@ -/* UnexpectedException.java -- an unexpected checked exception was received - Copyright (c) 1996, 1997, 1998, 1999, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.rmi; - -/** - * Thrown if an unexpected checked exception was received in a remote - * procedure call. - * - * @author unknown - * @since 1.1 - * @status updated to 1.4 - */ -public class UnexpectedException extends RemoteException -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = 1800467484195073863L; - - /** - * Create an exception with a message. - * - * @param s the message - */ - public UnexpectedException(String s) - { - super(s); - } - - /** - * Create an exception with a message and a cause. - * - * @param s the message - * @param e the cause - */ - public UnexpectedException(String s, Exception e) - { - super(s, e); - } -} diff --git a/libjava/java/rmi/UnknownHostException.java b/libjava/java/rmi/UnknownHostException.java deleted file mode 100644 index e21b9944c6b..00000000000 --- a/libjava/java/rmi/UnknownHostException.java +++ /dev/null @@ -1,75 +0,0 @@ -/* UnknownHostException.java -- wraps java.net.UnknownHostException in RMI - Copyright (c) 1996, 1997, 1998, 1999, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.rmi; - -/** - * Thrown if a java.net.UnknownHostException occurs during a remote - * procedure call. - * - * @author unknown - * @since 1.1 - * @status updated to 1.4 - */ -public class UnknownHostException extends RemoteException -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = -8152710247442114228L; - - /** - * Create an exception with a message. - * - * @param s the message - */ - public UnknownHostException(String s) - { - super(s); - } - - /** - * Create an exception with a message and a cause. - * - * @param s the message - * @param e the cause - */ - public UnknownHostException(String s, Exception e) - { - super(s, e); - } -} diff --git a/libjava/java/rmi/UnmarshalException.java b/libjava/java/rmi/UnmarshalException.java deleted file mode 100644 index 6567062a523..00000000000 --- a/libjava/java/rmi/UnmarshalException.java +++ /dev/null @@ -1,88 +0,0 @@ -/* UnmarshalException.java -- wraps error while unmarshalling parameters - Copyright (c) 1996, 1997, 1998, 1999, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.rmi; - -/** - * Thrown if an exception occurs while unmarshalling parameters or results - * of a remote method call. This includes:<br><ul> - * <li>if an exception occurs while unmarshalling the call header</li> - * <li>if the protocol for the return value is invalid</li> - * <li>if a java.io.IOException occurs unmarshalling parameters (on the - * server side) or the return value (on the client side).</li> - * <li>if a java.lang.ClassNotFoundException occurs during unmarshalling - * parameters or return values</li> - * <li>if no skeleton can be loaded on the server-side; note that skeletons - * are required in the 1.1 stub protocol, but not in the 1.2 stub - * protocol.</li> - * <li>if the method hash is invalid (i.e., missing method).</li> - * <li>if there is a failure to create a remote reference object for a remote - * object's stub when it is unmarshalled.</li> - * </ul> - * - * @author unknown - * @since 1.1 - * @status updated to 1.4 - */ -public class UnmarshalException extends RemoteException -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = 594380845140740218l; - - /** - * Create an exception with a message. - * - * @param s the message - */ - public UnmarshalException(String s) - { - super(s); - } - - /** - * Create an exception with a message and a cause. - * - * @param s the message - * @param e the cause - */ - public UnmarshalException(String s, Exception e) - { - super(s, e); - } -} diff --git a/libjava/java/rmi/activation/Activatable.java b/libjava/java/rmi/activation/Activatable.java deleted file mode 100644 index b4c38bf61a8..00000000000 --- a/libjava/java/rmi/activation/Activatable.java +++ /dev/null @@ -1,105 +0,0 @@ -/* Activatable.java -- - Copyright (c) 1996, 1997, 1998, 1999, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.rmi.activation; - -import java.rmi.MarshalledObject; -import java.rmi.NoSuchObjectException; -import java.rmi.Remote; -import java.rmi.RemoteException; -import java.rmi.server.RMIClientSocketFactory; -import java.rmi.server.RMIServerSocketFactory; -import java.rmi.server.RemoteServer; - -public abstract class Activatable extends RemoteServer -{ -static final long serialVersionUID = -3120617863591563455L; - -protected Activatable(String location, MarshalledObject data, boolean restart, int port) throws ActivationException, RemoteException { - throw new Error("Not implemented"); -} - -protected Activatable(String location, MarshalledObject data, boolean restart, int port, RMIClientSocketFactory csf, RMIServerSocketFactory ssf) throws ActivationException, RemoteException { - throw new Error("Not implemented"); -} - -protected Activatable(ActivationID id, int port) throws RemoteException { - throw new Error("Not implemented"); -} - -protected Activatable(ActivationID id, int port, RMIClientSocketFactory csf, RMIServerSocketFactory ssf) throws RemoteException { - throw new Error("Not implemented"); -} - -protected ActivationID getID() { - throw new Error("Not implemented"); -} - -public static Remote register(ActivationDesc desc) throws UnknownGroupException, ActivationException, RemoteException { - throw new Error("Not implemented"); -} - -public static boolean inactive(ActivationID id) throws UnknownObjectException, ActivationException, RemoteException { - throw new Error("Not implemented"); -} - -public static void unregister(ActivationID id) throws UnknownObjectException, ActivationException, RemoteException { - throw new Error("Not implemented"); -} - -public static ActivationID exportObject(Remote obj, String location, MarshalledObject data, boolean restart, int port) throws ActivationException, RemoteException { - throw new Error("Not implemented"); -} - -public static ActivationID exportObject(Remote obj, String location, MarshalledObject data, boolean restart, int port, RMIClientSocketFactory csf, RMIServerSocketFactory ssf) throws ActivationException, RemoteException { - throw new Error("Not implemented"); -} - -public static Remote exportObject(Remote obj, ActivationID id, int port) throws RemoteException { - throw new Error("Not implemented"); -} - -public static Remote exportObject(Remote obj, ActivationID id, int port, RMIClientSocketFactory csf, RMIServerSocketFactory ssf) throws RemoteException { - throw new Error("Not implemented"); -} - -public static boolean unexportObject(Remote obj, boolean force) throws NoSuchObjectException { - throw new Error("Not implemented"); -} - -} diff --git a/libjava/java/rmi/activation/ActivateFailedException.java b/libjava/java/rmi/activation/ActivateFailedException.java deleted file mode 100644 index 1c2e10ee3e6..00000000000 --- a/libjava/java/rmi/activation/ActivateFailedException.java +++ /dev/null @@ -1,76 +0,0 @@ -/* ActivateFailedException.java -- thrown when activation fails - Copyright (c) 1996, 1997, 1998, 1999, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.rmi.activation; - -import java.rmi.RemoteException; - -/** - * Thrown when activation fails on a remote call to an activatable object. - * - * @author unknown - * @since 1.2 - * @status updated to 1.4 - */ -public class ActivateFailedException extends RemoteException -{ - /** - * Compatible with JDK 1.2+. - */ - private static final long serialVersionUID = 4863550261346652506L; - - /** - * Create an exception with a message. - * - * @param s the message - */ - public ActivateFailedException(String s) - { - super(s); - } - - /** - * Create an exception with a message and a cause. - * - * @param s the message - * @param ex the cause - */ - public ActivateFailedException(String s, Exception ex) - { - super(s, ex); - } -} diff --git a/libjava/java/rmi/activation/ActivationDesc.java b/libjava/java/rmi/activation/ActivationDesc.java deleted file mode 100644 index 65894f808d2..00000000000 --- a/libjava/java/rmi/activation/ActivationDesc.java +++ /dev/null @@ -1,113 +0,0 @@ -/* ActivationDecc.java -- - Copyright (c) 1996, 1997, 1998, 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.rmi.activation; - -import java.io.Serializable; -import java.rmi.MarshalledObject; - -public final class ActivationDesc implements Serializable -{ - static final long serialVersionUID = 7455834104417690957L; - -private ActivationGroupID groupid; -private String classname; -private String location; -private MarshalledObject data; -private boolean restart; - -public ActivationDesc(String className, String location, MarshalledObject data) throws ActivationException { - this(ActivationGroup.currentGroupID(), className, location, data, false); -} - -public ActivationDesc(String className, String location, MarshalledObject data, boolean restart) throws ActivationException { - this(ActivationGroup.currentGroupID(), className, location, data, restart); -} - -public ActivationDesc(ActivationGroupID groupID, String className, String location, MarshalledObject data) { - this(groupID, className, location, data, false); -} - -public ActivationDesc(ActivationGroupID groupID, String className, String location, MarshalledObject data, boolean restart) { - this.groupid = groupID; - this.classname = className; - this.location = location; - this.data = data; - this.restart = restart; -} - -public ActivationGroupID getGroupID() { - return (groupid); -} - -public String getClassName() { - return (classname); -} - -public String getLocation() { - return (location); -} - -public MarshalledObject getData() { - return (data); -} - -public boolean getRestartMode() { - return (restart); -} - -public boolean equals(Object obj) { - if (!(obj instanceof ActivationDesc)) { - return (false); - } - ActivationDesc that = (ActivationDesc)obj; - - if (this.groupid.equals(that.groupid) && - this.classname.equals(that.classname) && - this.location.equals(that.location) && - this.data.equals(that.data) && - this.restart == that.restart) { - return (true); - } - return (false); -} - -public int hashCode() { - return (groupid.hashCode() ^ classname.hashCode() ^ location.hashCode() ^ data.hashCode()); -} - -} diff --git a/libjava/java/rmi/activation/ActivationException.java b/libjava/java/rmi/activation/ActivationException.java deleted file mode 100644 index 418f4385757..00000000000 --- a/libjava/java/rmi/activation/ActivationException.java +++ /dev/null @@ -1,122 +0,0 @@ -/* ActivationException.java -- general Activation exception - Copyright (c) 1996, 1997, 1998, 1999, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.rmi.activation; - -/** - * General exception class for <code>java.rmi.activation</code>. - * - * @author unknown - * @since 1.2 - * @status updated to 1.4 - */ -public class ActivationException extends Exception -{ - /** - * Compatible with JDK 1.2+. - */ - private static final long serialVersionUID = -4320118837291406071L; - - /** - * The cause of this exception. This pre-dates the exception chaining - * of Throwable; and although you can change this field, you are wiser - * to leave it alone. - * - * @serial the exception cause - */ - public Throwable detail; - - /** - * Create an exception with no message, and cause initialized to null. - */ - public ActivationException() - { - this(null, null); - } - - /** - * Create an exception with the given message, and cause initialized to null. - * - * @param s the message - */ - public ActivationException(String s) - { - this(s, null); - } - - /** - * Create an exception with the given message and cause. - * - * @param s the message - * @param ex the cause - */ - public ActivationException(String s, Throwable ex) - { - super(s, ex); - detail = ex; - } - - /** - * This method returns a message indicating what went wrong, in this - * format: - * <code>super.getMessage() + (detail == null ? "" - * : "; nested exception is:\n\t" + detail)</code>. - * - * @return the chained message - */ - public String getMessage() - { - if (detail == this || detail == null) - return super.getMessage(); - return super.getMessage() + "; nested exception is:\n\t" + detail; - } - - /** - * Returns the cause of this exception. Note that this may not be the - * original cause, thanks to the <code>detail</code> field being public - * and non-final (yuck). However, to avoid violating the contract of - * Throwable.getCause(), this returns null if <code>detail == this</code>, - * as no exception can be its own cause. - * - * @return the cause - * @since 1.4 - */ - public Throwable getCause() - { - return detail == this ? null : detail; - } -} diff --git a/libjava/java/rmi/activation/ActivationGroup.java b/libjava/java/rmi/activation/ActivationGroup.java deleted file mode 100644 index e5774a1b961..00000000000 --- a/libjava/java/rmi/activation/ActivationGroup.java +++ /dev/null @@ -1,85 +0,0 @@ -/* ActivationGroup.java -- - Copyright (c) 1996, 1997, 1998, 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.rmi.activation; - -import java.rmi.MarshalledObject; -import java.rmi.Remote; -import java.rmi.RemoteException; -import java.rmi.server.UnicastRemoteObject; - -public abstract class ActivationGroup extends UnicastRemoteObject - implements ActivationInstantiator -{ -static final long serialVersionUID = -7696947875314805420L; - -protected ActivationGroup(ActivationGroupID groupID) throws RemoteException { - throw new Error("Not implemented"); -} - -public boolean inactiveObject(ActivationID id) throws ActivationException, UnknownObjectException, RemoteException { - throw new Error("Not implemented"); -} - -public abstract void activeObject(ActivationID id, Remote obj) throws ActivationException, UnknownObjectException, RemoteException; - -public static ActivationGroup createGroup(ActivationGroupID id, ActivationGroupDesc desc, long incarnation) throws ActivationException { - throw new Error("Not implemented"); -} - -public static ActivationGroupID currentGroupID() { - throw new Error("Not implemented"); -} - -public static void setSystem(ActivationSystem system) throws ActivationException { - throw new Error("Not implemented"); -} - -public static ActivationSystem getSystem() throws ActivationException { - throw new Error("Not implemented"); -} - -protected void activeObject(ActivationID id, MarshalledObject mobj) throws ActivationException, UnknownObjectException, RemoteException { - throw new Error("Not implemented"); -} - -protected void inactiveGroup() throws UnknownGroupException, RemoteException { - throw new Error("Not implemented"); -} - -} diff --git a/libjava/java/rmi/activation/ActivationGroupDesc.java b/libjava/java/rmi/activation/ActivationGroupDesc.java deleted file mode 100644 index 35b546e3294..00000000000 --- a/libjava/java/rmi/activation/ActivationGroupDesc.java +++ /dev/null @@ -1,134 +0,0 @@ -/* ActivationGroupDesc.java -- - Copyright (c) 1996, 1997, 1998, 1999, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.rmi.activation; - -import java.io.Serializable; -import java.rmi.MarshalledObject; -import java.util.Properties; - -public final class ActivationGroupDesc implements Serializable -{ - static final long serialVersionUID = -4936225423168276595L; - -public static class CommandEnvironment - implements Serializable { - -static final long serialVersionUID = 6165754737887770191L; - -private String cmdpath; -private String[] argv; - -public CommandEnvironment(String cmdpath, String[] argv) { - this.cmdpath = cmdpath; - this.argv = argv; -} - -public String getCommandPath() { - return (cmdpath); -} - -public String[] getCommandOptions() { - return (argv); -} - -public boolean equals(Object obj) { - if (!(obj instanceof CommandEnvironment)) { - return (false); - } - CommandEnvironment that = (CommandEnvironment)obj; - - if (!this.cmdpath.equals(that.cmdpath)) { - return (false); - } - - int len = this.argv.length; - if (len != that.argv.length) { - return (false); - } - for (int i = 0; i < len; i++) { - if (!this.argv[i].equals(that.argv[i])) { - return (false); - } - } - return (true); -} - -public int hashCode() { - return (cmdpath.hashCode()); // Not a very good hash code. -} - -} - -public ActivationGroupDesc(Properties overrides, ActivationGroupDesc.CommandEnvironment cmd) { - throw new Error("Not implemented"); -} - -public ActivationGroupDesc(String className, String location, MarshalledObject data, Properties overrides, ActivationGroupDesc.CommandEnvironment cmd) { - throw new Error("Not implemented"); -} - -public String getClassName() { - throw new Error("Not implemented"); -} - -public String getLocation() { - throw new Error("Not implemented"); -} - -public MarshalledObject getData() { - throw new Error("Not implemented"); -} - -public Properties getPropertyOverrides() { - throw new Error("Not implemented"); -} - -public ActivationGroupDesc.CommandEnvironment getCommandEnvironment() { - throw new Error("Not implemented"); -} - -public boolean equals(Object obj) { - throw new Error("Not implemented"); -} - -public int hashCode() { - throw new Error("Not implemented"); -} - -} diff --git a/libjava/java/rmi/activation/ActivationGroupID.java b/libjava/java/rmi/activation/ActivationGroupID.java deleted file mode 100644 index 5e0b96442e8..00000000000 --- a/libjava/java/rmi/activation/ActivationGroupID.java +++ /dev/null @@ -1,70 +0,0 @@ -/* ActivationGroupID.java -- - Copyright (c) 1996, 1997, 1998, 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.rmi.activation; - -import java.io.Serializable; - -public class ActivationGroupID implements Serializable -{ - static final long serialVersionUID = -1648432278909740833L; - -private ActivationSystem system; - -public ActivationGroupID(ActivationSystem system) { - this.system = system; -} - -public ActivationSystem getSystem() { - return (system); -} - -public int hashCode() { - return (system.hashCode()); -} - -public boolean equals(Object obj) { - if (obj instanceof ActivationGroupID) { - ActivationGroupID that = (ActivationGroupID)obj; - if (this.system.equals(that.system)) { - return (true); - } - } - return (false); -} - -} diff --git a/libjava/java/rmi/activation/ActivationID.java b/libjava/java/rmi/activation/ActivationID.java deleted file mode 100644 index 23ed853a478..00000000000 --- a/libjava/java/rmi/activation/ActivationID.java +++ /dev/null @@ -1,72 +0,0 @@ -/* ActivationID.java -- - Copyright (c) 1996, 1997, 1998, 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.rmi.activation; - -import java.io.Serializable; -import java.rmi.Remote; -import java.rmi.RemoteException; - -public class ActivationID implements Serializable -{ - static final long serialVersionUID = -4608673054848209235L; - -private Activator activator; - -public ActivationID(Activator activator) { - this.activator = activator; -} - -public Remote activate(boolean force) throws ActivationException, UnknownObjectException, RemoteException { - throw new Error("Not implemented"); -} - -public int hashCode() { - return (activator.hashCode()); -} - -public boolean equals(Object obj) { - if (obj instanceof ActivationID) { - ActivationID that = (ActivationID)obj; - if (this.activator.equals(that.activator)) { - return (true); - } - } - return (false); -} - -} diff --git a/libjava/java/rmi/activation/ActivationInstantiator.java b/libjava/java/rmi/activation/ActivationInstantiator.java deleted file mode 100644 index 0aceb7a4ad6..00000000000 --- a/libjava/java/rmi/activation/ActivationInstantiator.java +++ /dev/null @@ -1,50 +0,0 @@ -/* ActivationInstantiator.java -- - Copyright (c) 1996, 1997, 1998, 1999, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.rmi.activation; - -import java.rmi.MarshalledObject; -import java.rmi.Remote; -import java.rmi.RemoteException; - -public interface ActivationInstantiator - extends Remote -{ - MarshalledObject newInstance (ActivationID id, ActivationDesc desc) - throws ActivationException, RemoteException; -} diff --git a/libjava/java/rmi/activation/ActivationMonitor.java b/libjava/java/rmi/activation/ActivationMonitor.java deleted file mode 100644 index 1e64257edd1..00000000000 --- a/libjava/java/rmi/activation/ActivationMonitor.java +++ /dev/null @@ -1,55 +0,0 @@ -/* ActivationMonitor.java -- - Copyright (c) 1996, 1997, 1998, 1999, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.rmi.activation; - -import java.rmi.MarshalledObject; -import java.rmi.Remote; -import java.rmi.RemoteException; - -public interface ActivationMonitor extends Remote -{ - void inactiveObject (ActivationID id) - throws UnknownObjectException, RemoteException; - - void activeObject (ActivationID id, MarshalledObject obj) - throws UnknownObjectException, RemoteException; - - void inactiveGroup (ActivationGroupID id, long incarnation) - throws UnknownGroupException, RemoteException; -} diff --git a/libjava/java/rmi/activation/ActivationSystem.java b/libjava/java/rmi/activation/ActivationSystem.java deleted file mode 100644 index 4b92d40cb44..00000000000 --- a/libjava/java/rmi/activation/ActivationSystem.java +++ /dev/null @@ -1,78 +0,0 @@ -/* ActivationSystem.java -- - Copyright (c) 1996, 1997, 1998, 1999, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.rmi.activation; - -import java.rmi.Remote; -import java.rmi.RemoteException; - -public interface ActivationSystem extends Remote -{ - int SYSTEM_PORT = 1098; - - ActivationID registerObject (ActivationDesc desc) - throws ActivationException, UnknownGroupException, RemoteException; - - void unregisterObject (ActivationID id) - throws ActivationException, UnknownObjectException, RemoteException; - - ActivationGroupID registerGroup (ActivationGroupDesc desc) - throws ActivationException, RemoteException; - - ActivationMonitor activeGroup (ActivationGroupID id, - ActivationInstantiator group, long incarnation) - throws UnknownGroupException, ActivationException, RemoteException; - - void unregisterGroup (ActivationGroupID id) - throws ActivationException, UnknownGroupException, RemoteException; - - void shutdown() - throws RemoteException; - - ActivationDesc setActivationDesc (ActivationID id, ActivationDesc desc) - throws ActivationException, UnknownObjectException, UnknownGroupException, - RemoteException; - - ActivationGroupDesc setActivationGroupDesc (ActivationGroupID id, - ActivationGroupDesc desc) - throws ActivationException, UnknownGroupException, RemoteException; - - ActivationDesc getActivationDesc (ActivationID id) throws ActivationException, UnknownObjectException, RemoteException; - - ActivationGroupDesc getActivationGroupDesc (ActivationGroupID id) throws ActivationException, UnknownGroupException, RemoteException; -} diff --git a/libjava/java/rmi/activation/Activator.java b/libjava/java/rmi/activation/Activator.java deleted file mode 100644 index 2fb5a581002..00000000000 --- a/libjava/java/rmi/activation/Activator.java +++ /dev/null @@ -1,50 +0,0 @@ -/* Activator.java -- - Copyright (c) 1996, 1997, 1998, 1999, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.rmi.activation; - -import java.rmi.MarshalledObject; -import java.rmi.Remote; -import java.rmi.RemoteException; - -public interface Activator - extends Remote -{ - MarshalledObject activate (ActivationID id, boolean force) - throws ActivationException, UnknownObjectException, RemoteException; -} diff --git a/libjava/java/rmi/activation/UnknownGroupException.java b/libjava/java/rmi/activation/UnknownGroupException.java deleted file mode 100644 index 91890a9073d..00000000000 --- a/libjava/java/rmi/activation/UnknownGroupException.java +++ /dev/null @@ -1,69 +0,0 @@ -/* UnknownGroupException.java -- thrown on an invalid ActivationGroupID - Copyright (c) 1996, 1997, 1998, 1999, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.rmi.activation; - -/** - * Thrown when an <code>ActivationGroupID</code> parameter is invalid or - * unknown. - * - * @author unknown - * @see Activatable - * @see ActivationGroup - * @see ActivationID - * @see ActivationMonitor - * @see ActivationSystem - * @since 1.2 - * @status updated to 1.4 - */ -public class UnknownGroupException extends ActivationException -{ - /** - * Compatible with JDK 1.2+. - */ - private static final long serialVersionUID = 7056094974750002460L; - - /** - * Create an exception with a message. - * - * @param s the message - */ - public UnknownGroupException(String s) - { - super(s); - } -} diff --git a/libjava/java/rmi/activation/UnknownObjectException.java b/libjava/java/rmi/activation/UnknownObjectException.java deleted file mode 100644 index 8dbeb0e6050..00000000000 --- a/libjava/java/rmi/activation/UnknownObjectException.java +++ /dev/null @@ -1,69 +0,0 @@ -/* UnknownObjectException.java -- thrown on an invalid ActivationID - Copyright (c) 1996, 1997, 1998, 1999, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.rmi.activation; - -/** - * Thrown when an <code>ActivationID</code> parameter is invalid or unknown. - * - * @author unknown - * @see Activatable - * @see ActivationGroup - * @see ActivationID - * @see ActivationMonitor - * @see ActivationSystem - * @see Activator - * @since 1.2 - * @status updated to 1.4 - */ -public class UnknownObjectException extends ActivationException -{ - /** - * Compatible with JDK 1.2+. - */ - private static final long serialVersionUID = 3425547551622251430L; - - /** - * Create an exception with an error message. - * - * @param s the message - */ - public UnknownObjectException(String s) - { - super(s); - } -} diff --git a/libjava/java/rmi/dgc/DGC.java b/libjava/java/rmi/dgc/DGC.java deleted file mode 100644 index e78ec2a3aa7..00000000000 --- a/libjava/java/rmi/dgc/DGC.java +++ /dev/null @@ -1,51 +0,0 @@ -/* DGC.java -- - Copyright (c) 1996, 1997, 1998, 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.rmi.dgc; - -import java.rmi.Remote; -import java.rmi.RemoteException; -import java.rmi.server.ObjID; - -public interface DGC extends Remote -{ - Lease dirty (ObjID[] ids, long sequenceNum, Lease lease) - throws RemoteException; - - void clean (ObjID[] ids, long sequenceNum, VMID vmid, boolean strong) - throws RemoteException; -} diff --git a/libjava/java/rmi/dgc/Lease.java b/libjava/java/rmi/dgc/Lease.java deleted file mode 100644 index d3d7f695216..00000000000 --- a/libjava/java/rmi/dgc/Lease.java +++ /dev/null @@ -1,67 +0,0 @@ -/* Lease.java - Copyright (c) 1996, 1997, 1998, 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.rmi.dgc; - -import java.io.Serializable; - -public final class Lease - implements Serializable { - -static final long serialVersionUID = -5713411624328831948L; - -private VMID vmid; -private long value; - -public Lease(VMID id, long duration) { - vmid = id; - value = duration; -} - -public VMID getVMID() { - return (vmid); -} - -public long getValue() { - return (value); -} - -public String toString() { - return ("[" + vmid.toString() + ", " + Long.toString(value) + "]"); -} - -} diff --git a/libjava/java/rmi/dgc/VMID.java b/libjava/java/rmi/dgc/VMID.java deleted file mode 100644 index f960d9ccd79..00000000000 --- a/libjava/java/rmi/dgc/VMID.java +++ /dev/null @@ -1,138 +0,0 @@ -/* VMID.java - Copyright (c) 1996, 1997, 1998, 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.rmi.dgc; - -import java.io.Serializable; -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.rmi.server.UID; - -public final class VMID implements Serializable -{ - static final long serialVersionUID = -538642295484486218L; - - static final boolean areWeUnique; - - static byte[] localAddr; - - private byte[] addr; - - private UID uid; - - static - { - byte[] addr; - boolean awu = true; - try { - addr = InetAddress.getLocalHost().getAddress(); - if (addr[0] == 127 && addr[1] == 0 && addr[2] == 0 && addr[3] == 1) { - awu = false; - } - } - catch (UnknownHostException _) { - addr = new byte[]{ 127, 0, 0, 1 }; - awu = false; - } - localAddr = addr; - areWeUnique = awu; - } - - public VMID() - { - addr = localAddr; - uid = new UID(); - } - - /** - * @deprecated - */ - public static boolean isUnique () - { - return areWeUnique; - } - - public int hashCode () - { - return super.hashCode(); - } - - public boolean equals (Object obj) - { - if (!(obj instanceof VMID)) - { - return false; - } - - VMID other = (VMID) obj; - if (addr.length != other.addr.length) - { - return false; - } - - for (int i = addr.length - 1; i >= 0; i--) - { - if (addr[i] != other.addr[i]) - { - return false; - } - } - - return uid.equals(other.uid); - } - - public String toString () - { - StringBuffer buf = new StringBuffer ("[VMID: "); - - for (int i = 0; i < addr.length; i++) - { - if (i > 0) - { - buf.append ("."); - } - - buf.append (Integer.toString (addr [i])); - } - - buf.append (" "); - buf.append (uid.toString ()); - buf.append ("]"); - - return buf.toString(); - } -} diff --git a/libjava/java/rmi/registry/LocateRegistry.java b/libjava/java/rmi/registry/LocateRegistry.java deleted file mode 100644 index 3547a7ad0f4..00000000000 --- a/libjava/java/rmi/registry/LocateRegistry.java +++ /dev/null @@ -1,87 +0,0 @@ -/* LocateRegistry.java -- - Copyright (c) 1996, 1997, 1998, 1999, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.rmi.registry; - -import gnu.java.rmi.registry.RegistryImpl; -import gnu.java.rmi.registry.RegistryImpl_Stub; -import gnu.java.rmi.server.UnicastRef; - -import java.rmi.RemoteException; -import java.rmi.server.ObjID; -import java.rmi.server.RMIClientSocketFactory; -import java.rmi.server.RMIServerSocketFactory; -import java.rmi.server.RMISocketFactory; -import java.rmi.server.RemoteRef; - -public final class LocateRegistry { - /** - * This class isn't intended to be instantiated. - */ - private LocateRegistry() {} - -public static Registry getRegistry() throws RemoteException { - return (getRegistry("localhost", Registry.REGISTRY_PORT)); -} - -public static Registry getRegistry(int port) throws RemoteException { - return (getRegistry("localhost", port)); -} - -public static Registry getRegistry(String host) throws RemoteException { - return (getRegistry(host, Registry.REGISTRY_PORT)); -} - -public static Registry getRegistry(String host, int port) throws RemoteException { - return (getRegistry(host, port, RMISocketFactory.getSocketFactory())); -} - -public static Registry getRegistry(String host, int port, RMIClientSocketFactory csf) throws RemoteException { - RemoteRef ref = new UnicastRef(new ObjID(ObjID.REGISTRY_ID), host, port, csf); - return (new RegistryImpl_Stub(ref)); -} - -public static Registry createRegistry(int port) throws RemoteException { - return (createRegistry(port, RMISocketFactory.getSocketFactory(), RMISocketFactory.getSocketFactory())); -} - -public static Registry createRegistry(int port, RMIClientSocketFactory csf, RMIServerSocketFactory ssf) throws RemoteException { - return (new RegistryImpl(port, csf, ssf)); -} - -} diff --git a/libjava/java/rmi/registry/Registry.java b/libjava/java/rmi/registry/Registry.java deleted file mode 100644 index 6cd2a04a685..00000000000 --- a/libjava/java/rmi/registry/Registry.java +++ /dev/null @@ -1,65 +0,0 @@ -/* Registry.java -- - Copyright (c) 1996, 1997, 1998, 1999, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.rmi.registry; - -import java.rmi.AccessException; -import java.rmi.AlreadyBoundException; -import java.rmi.NotBoundException; -import java.rmi.Remote; -import java.rmi.RemoteException; - -public interface Registry extends Remote -{ - int REGISTRY_PORT = 1099; - - Remote lookup(String name) - throws RemoteException, NotBoundException, AccessException; - - void bind(String name, Remote obj) - throws RemoteException, AlreadyBoundException, AccessException; - - void unbind(String name) - throws RemoteException, NotBoundException, AccessException; - - void rebind(String name, Remote obj) - throws RemoteException, AccessException; - - String[] list() - throws RemoteException, AccessException; -} diff --git a/libjava/java/rmi/registry/RegistryHandler.java b/libjava/java/rmi/registry/RegistryHandler.java deleted file mode 100644 index b9b45092305..00000000000 --- a/libjava/java/rmi/registry/RegistryHandler.java +++ /dev/null @@ -1,58 +0,0 @@ -/* RegistryHandler.java -- - Copyright (c) 1996, 1997, 1998, 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.rmi.registry; - -import java.rmi.RemoteException; -import java.rmi.UnknownHostException; - -/** - * @deprecated - */ -public interface RegistryHandler -{ - /** - * @deprecated - */ - Registry registryStub (String host, int port) - throws RemoteException, UnknownHostException; - - /** - * @deprecated - */ - Registry registryImpl (int port) throws RemoteException; -} diff --git a/libjava/java/rmi/server/ExportException.java b/libjava/java/rmi/server/ExportException.java deleted file mode 100644 index b2d5bfca52e..00000000000 --- a/libjava/java/rmi/server/ExportException.java +++ /dev/null @@ -1,78 +0,0 @@ -/* ExportException.java -- an export attempt failed - Copyright (c) 1996, 1997, 1998, 1999, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.rmi.server; - -import java.rmi.RemoteException; - -/** - * Thrown if an attempt to export a remote object fails. - * - * @author unknown - * @see UnicastRemoteObject - * @see Activatable - * @since 1.1 - * @status updated to 1.4 - */ -public class ExportException extends RemoteException -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = -9155485338494060170L; - - /** - * Create an exception with the specified message. - * - * @param s the message - */ - public ExportException(String s) - { - super(s); - } - - /** - * Create an exception with the specified message and cause. - * - * @param s the message - * @param e the cause - */ - public ExportException(String s, Exception e) - { - super(s, e); - } -} diff --git a/libjava/java/rmi/server/LoaderHandler.java b/libjava/java/rmi/server/LoaderHandler.java deleted file mode 100644 index 189085710b4..00000000000 --- a/libjava/java/rmi/server/LoaderHandler.java +++ /dev/null @@ -1,66 +0,0 @@ -/* LoaderHandler.java -- - Copyright (c) 1996, 1997, 1998, 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.rmi.server; - -import java.net.MalformedURLException; -import java.net.URL; - -/** - * @deprecated - */ -public interface LoaderHandler -{ - String packagePrefix = ""; - - /** - * @deprecated - */ - Class loadClass(String name) - throws MalformedURLException, ClassNotFoundException; - - /** - * @deprecated - */ - Class loadClass(URL codebase, String name) - throws MalformedURLException, ClassNotFoundException; - - /** - * @deprecated - */ - Object getSecurityContext(ClassLoader loader); -} diff --git a/libjava/java/rmi/server/LogStream.java b/libjava/java/rmi/server/LogStream.java deleted file mode 100644 index a2dfbb47fcc..00000000000 --- a/libjava/java/rmi/server/LogStream.java +++ /dev/null @@ -1,146 +0,0 @@ -/* LogStream.java -- - Copyright (c) 1996, 1997, 1998, 1999, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.rmi.server; - -import java.io.OutputStream; -import java.io.PrintStream; - -/** - * @deprecated - */ -public class LogStream extends PrintStream -{ - public static final int SILENT = 0; - public static final int BRIEF = 10; - public static final int VERBOSE = 20; - - private static PrintStream defStream; - - private LogStream (OutputStream s) - { - super (s); - } - - /** - * @deprecated - */ - public static LogStream log (String name) - { - throw new Error ("Not implemented"); - } - - /** - * @deprecated - */ - public static PrintStream getDefaultStream () - { - return defStream; - } - - /** - * @deprecated - */ - public static void setDefaultStream (PrintStream s) - { - defStream = s; - } - - /** - * @deprecated - */ - public OutputStream getOutputStream () - { - return out; - } - - /** - * @deprecated - */ - public void setOutputStream (OutputStream s) - { - out = s; - } - - /** - * @deprecated - */ - public void write (int buffer) - { - super.write (buffer); - } - - /** - * @deprecated - */ - public void write (byte[] buffer, int offset, int len) - { - super.write (buffer, offset, len); - } - - /** - * @deprecated - */ - public String toString () - { - throw new Error ("Not implemented"); - } - - /** - * @deprecated - */ - public static int parseLevel (String s) - { - if (s.equalsIgnoreCase ("silent")) - { - return SILENT; - } - - if (s.equalsIgnoreCase ("brief")) - { - return BRIEF; - } - - if (s.equalsIgnoreCase ("verbose")) - { - return VERBOSE; - } - - return SILENT; - } -} diff --git a/libjava/java/rmi/server/ObjID.java b/libjava/java/rmi/server/ObjID.java deleted file mode 100644 index 07cbbde3a62..00000000000 --- a/libjava/java/rmi/server/ObjID.java +++ /dev/null @@ -1,103 +0,0 @@ -/* ObjID.java -- - Copyright (c) 1996, 1997, 1998, 1999, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.rmi.server; - -import java.io.DataInput; -import java.io.DataOutput; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.io.Serializable; - -public final class ObjID implements Serializable -{ -static final long serialVersionUID = -6386392263968365220L; - -private static long next = 0x8000000000000000L; -private static final Object lock = ObjID.class; - -public static final int REGISTRY_ID = 0; -public static final int ACTIVATOR_ID = 1; -public static final int DGC_ID = 2; - -private long objNum; -private UID space; - -public ObjID() { - synchronized (lock) { - objNum = next++; - } - space = new UID(); -} - -public ObjID(int num) { - objNum = (long)num; - space = new UID((short)0); -} - -public void write(ObjectOutput out) throws IOException { - DataOutput dout = (DataOutput)out; - dout.writeLong(objNum); - space.write(dout); -} - -public static ObjID read(ObjectInput in) throws IOException { - DataInput din = (DataInput)in; - ObjID id = new ObjID(); - id.objNum = din.readLong(); - id.space = UID.read(din); - return (id); -} - -public int hashCode() { - return ((int)objNum); -} - -public boolean equals(Object obj) { - if (obj instanceof ObjID && this.objNum == ((ObjID)obj).objNum) { - return (true); - } - return (false); -} - -public String toString() { - return ("[objNum: " + objNum + ", " + space + "]"); -} - -} diff --git a/libjava/java/rmi/server/Operation.java b/libjava/java/rmi/server/Operation.java deleted file mode 100644 index 64faf66e2f8..00000000000 --- a/libjava/java/rmi/server/Operation.java +++ /dev/null @@ -1,70 +0,0 @@ -/* Operation.java -- - Copyright (c) 1996, 1997, 1998, 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.rmi.server; - -/** - * @deprecated - */ -public class Operation -{ - private String operation; - - /** - * @deprecated - */ - public Operation (String op) - { - operation = op; - } - - /** - * @deprecated - */ - public String getOperation () - { - return operation; - } - - /** - * @deprecated - */ - public String toString () - { - return operation; - } -} diff --git a/libjava/java/rmi/server/RMIClassLoader.java b/libjava/java/rmi/server/RMIClassLoader.java deleted file mode 100644 index 1a2e2837dd8..00000000000 --- a/libjava/java/rmi/server/RMIClassLoader.java +++ /dev/null @@ -1,339 +0,0 @@ -/* RMIClassLoader.java -- - Copyright (c) 1996, 1997, 1998, 1999, 2002, 2003, 2004 - Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.rmi.server; - -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.ArrayList; -import java.util.Hashtable; -import java.util.Map; -import java.util.StringTokenizer; - - -/** - * This class provides a set of public static utility methods for supporting - * network-based class loading in RMI. These methods are called by RMI's - * internal marshal streams to implement the dynamic class loading of types for - * RMI parameters and return values. - */ -public class RMIClassLoader -{ - /** - * This class isn't intended to be instantiated. - */ - private RMIClassLoader() {} - - private static class MyClassLoader extends URLClassLoader - { - // Package-private to avoid a trampoline constructor. - MyClassLoader (URL[] urls, ClassLoader parent, String annotation) - { - super (urls, parent); - this.annotation = annotation; - } - - private MyClassLoader (URL[] urls, ClassLoader parent) - { - super (urls, parent); - this.annotation = urlToAnnotation (urls); - } - - public static String urlToAnnotation (URL[] urls) - { - if (urls.length == 0) - return null; - - StringBuffer annotation = new StringBuffer (64 * urls.length); - - for (int i = 0; i < urls.length; i++) - { - annotation.append (urls [i].toExternalForm()); - annotation.append (' '); - } - - return annotation.toString(); - } - - public final String getClassAnnotation() - { - return annotation; - } - - private final String annotation; - } - - /** - * This class is used to identify a cached classloader by its codebase and - * the context classloader that is its parent. - */ - private static class CacheKey - { - private String mCodeBase; - private ClassLoader mContextClassLoader; - - public CacheKey (String theCodebase, ClassLoader theContextClassLoader) - { - mCodeBase = theCodebase; - mContextClassLoader = theContextClassLoader; - } - - /** - * @return true if the codebase and the context classloader are equal - */ - public boolean equals (Object theOther) - { - if (theOther instanceof CacheKey) - { - CacheKey key = (CacheKey) theOther; - - return (equals (this.mCodeBase,key.mCodeBase) - && equals (this.mContextClassLoader, key.mContextClassLoader)); - } - return false; - } - - /** - * Test if the two objects are equal or both null. - * @param theOne - * @param theOther - * @return - */ - private boolean equals (Object theOne, Object theOther) - { - return theOne != null ? theOne.equals (theOther) : theOther == null; - } - - /** - * @return hashCode - */ - public int hashCode() - { - return ((mCodeBase != null ? mCodeBase.hashCode() : 0) - ^(mContextClassLoader != null ? mContextClassLoader.hashCode() : -1)); - } - - public String toString() - { - return "[" + mCodeBase + "," + mContextClassLoader + "]"; - } - - } - - private static Map cacheLoaders; //map annotations to loaders - private static Map cacheAnnotations; //map loaders to annotations - - //defaultAnnotation is got from system property - // "java.rmi.server.defaultAnnotation" - private static String defaultAnnotation; - - //URL object for defaultAnnotation - private static URL defaultCodebase; - - //class loader for defaultAnnotation - private static MyClassLoader defaultLoader; - - static - { - // 89 is a nice prime number for Hashtable initial capacity - cacheLoaders = new Hashtable (89); - cacheAnnotations = new Hashtable (89); - - defaultAnnotation = System.getProperty ("java.rmi.server.defaultAnnotation"); - - try - { - if (defaultAnnotation != null) - defaultCodebase = new URL (defaultAnnotation); - } - catch (Exception _) - { - defaultCodebase = null; - } - - if (defaultCodebase != null) - { - defaultLoader = new MyClassLoader (new URL[] { defaultCodebase }, null, - defaultAnnotation); - cacheLoaders.put (new CacheKey (defaultAnnotation, - Thread.currentThread().getContextClassLoader()), - defaultLoader); - } - } - - /** - * @deprecated - */ - public static Class loadClass (String name) - throws MalformedURLException, ClassNotFoundException - { - return loadClass ("", name); - } - - public static Class loadClass (String codebases, String name) - throws MalformedURLException, ClassNotFoundException - { - ClassLoader loader = Thread.currentThread().getContextClassLoader(); - - //try context class loader first - try - { - return loader.loadClass (name); - } - catch (ClassNotFoundException e) - { - // class not found in the local classpath - } - - if (codebases.length() == 0) //=="" - { - loader = defaultLoader; - } - else - { - loader = getClassLoader(codebases); - } - - if (loader == null) - { - //do not throw NullPointerException - throw new ClassNotFoundException ("Could not find class (" + name + - ") at codebase (" + codebases + ")"); - } - - return loader.loadClass (name); - } - - /** - * Gets a classloader for the given codebase and with the current - * context classloader as parent. - * - * @param codebases - * - * @return a classloader for the given codebase - * - * @throws MalformedURLException if the codebase contains a malformed URL - */ - public static ClassLoader getClassLoader (String codebases) - throws MalformedURLException - { - ClassLoader loader; - CacheKey loaderKey = new CacheKey - (codebases, Thread.currentThread().getContextClassLoader()); - loader = (ClassLoader) cacheLoaders.get (loaderKey); - - if (loader == null) - { - //create an entry in cacheLoaders mapping a loader to codebases. - // codebases are separated by " " - StringTokenizer tok = new StringTokenizer (codebases, " "); - ArrayList urls = new ArrayList(); - - while (tok.hasMoreTokens()) - urls.add (new URL (tok.nextToken())); - - loader = new MyClassLoader ((URL[]) urls.toArray (new URL [urls.size()]), - Thread.currentThread().getContextClassLoader(), - codebases); - cacheLoaders.put (loaderKey, loader); - } - - return loader; - } - - /** - * Returns a string representation of the network location where a remote - * endpoint can get the class-definition of the given class. - * - * @param cl - * - * @return a space seperated list of URLs where the class-definition - * of cl may be found - */ - public static String getClassAnnotation (Class cl) - { - ClassLoader loader = cl.getClassLoader(); - - if (loader == null - || loader == ClassLoader.getSystemClassLoader()) - { - return System.getProperty ("java.rmi.server.codebase"); - } - - if (loader instanceof MyClassLoader) - { - return ((MyClassLoader) loader).getClassAnnotation(); - } - - String s = (String) cacheAnnotations.get (loader); - - if (s != null) - return s; - - if (loader instanceof URLClassLoader) - { - URL[] urls = ((URLClassLoader) loader).getURLs(); - - if (urls.length == 0) - return null; - - StringBuffer annotation = new StringBuffer (64 * urls.length); - - for (int i = 0; i < urls.length; i++) - { - annotation.append (urls [i].toExternalForm()); - annotation.append (' '); - } - - s = annotation.toString(); - cacheAnnotations.put (loader, s); - return s; - } - - return System.getProperty ("java.rmi.server.codebase"); - } - - /** - * @deprecated - */ - public static Object getSecurityContext (ClassLoader loader) - { - throw new Error ("Not implemented"); - } -} diff --git a/libjava/java/rmi/server/RMIClassLoaderSpi.java b/libjava/java/rmi/server/RMIClassLoaderSpi.java deleted file mode 100644 index 372d81879f9..00000000000 --- a/libjava/java/rmi/server/RMIClassLoaderSpi.java +++ /dev/null @@ -1,64 +0,0 @@ -/* RMIClassLoaderSpi.java -- - Copyright (c) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.rmi.server; - -import java.net.MalformedURLException; - -/** - * @author Michael Koch - * @since 1.4 - */ -public abstract class RMIClassLoaderSpi -{ - public RMIClassLoaderSpi() - { - } - - public abstract Class loadClass (String codeBase, String name, - ClassLoader defaultLoader) - throws MalformedURLException, ClassNotFoundException; - - public abstract Class loadProxyClass (String codeBase, String[] interfaces, - ClassLoader defaultLoader) - throws MalformedURLException, ClassNotFoundException; - - public abstract ClassLoader getClassLoader (String codebase) - throws MalformedURLException; - - public abstract String getClassAnnotation (Class cl); -} diff --git a/libjava/java/rmi/server/RMIClientSocketFactory.java b/libjava/java/rmi/server/RMIClientSocketFactory.java deleted file mode 100644 index a54d11175e0..00000000000 --- a/libjava/java/rmi/server/RMIClientSocketFactory.java +++ /dev/null @@ -1,47 +0,0 @@ -/* RMIClientSocketFactory.java -- - Copyright (c) 1996, 1997, 1998, 1999, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.rmi.server; - -import java.io.IOException; -import java.net.Socket; - -public interface RMIClientSocketFactory -{ - Socket createSocket (String host, int port) throws IOException; -} diff --git a/libjava/java/rmi/server/RMIFailureHandler.java b/libjava/java/rmi/server/RMIFailureHandler.java deleted file mode 100644 index 3496cd6a073..00000000000 --- a/libjava/java/rmi/server/RMIFailureHandler.java +++ /dev/null @@ -1,46 +0,0 @@ -/* RMIFailureHandler.java -- - Copyright (c) 1996, 1997, 1998, 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.rmi.server; - -public interface RMIFailureHandler -{ - /** - * @exception IOException If an error occurs - */ - boolean failure (Exception ex); -} diff --git a/libjava/java/rmi/server/RMIServerSocketFactory.java b/libjava/java/rmi/server/RMIServerSocketFactory.java deleted file mode 100644 index 88eaff32dbc..00000000000 --- a/libjava/java/rmi/server/RMIServerSocketFactory.java +++ /dev/null @@ -1,47 +0,0 @@ -/* RMIServerSocketFactory.java -- - Copyright (c) 1996, 1997, 1998, 1999, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.rmi.server; - -import java.io.IOException; -import java.net.ServerSocket; - -public interface RMIServerSocketFactory -{ - ServerSocket createServerSocket(int port) throws IOException; -} diff --git a/libjava/java/rmi/server/RMISocketFactory.java b/libjava/java/rmi/server/RMISocketFactory.java deleted file mode 100644 index 953f1ef33ce..00000000000 --- a/libjava/java/rmi/server/RMISocketFactory.java +++ /dev/null @@ -1,108 +0,0 @@ -/* RMISocketFactory.java -- - Copyright (c) 1996, 1997, 1998, 1999, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.rmi.server; - -import gnu.java.rmi.server.RMIDefaultSocketFactory; - -import java.io.IOException; -import java.net.ServerSocket; -import java.net.Socket; - -public abstract class RMISocketFactory - implements RMIClientSocketFactory, RMIServerSocketFactory -{ - private static RMISocketFactory defaultFactory; - private static RMISocketFactory currentFactory; - private static RMIFailureHandler currentHandler; - - static - { - defaultFactory = new RMIDefaultSocketFactory(); - currentFactory = defaultFactory; - } - - public RMISocketFactory () - { - } - - /** - * @exception IOException If an error occurs - */ - public abstract Socket createSocket (String host, int port) - throws IOException; - - /** - * @exception IOException If an error occurs - */ - public abstract ServerSocket createServerSocket (int port) - throws IOException; - - /** - * @exception IOException If an error occurs - * @exception SecurityException FIXME - */ - public static void setSocketFactory (RMISocketFactory fac) - throws IOException - { - currentFactory = fac; - } - - public static RMISocketFactory getSocketFactory () - { - return currentFactory; - } - - public static RMISocketFactory getDefaultSocketFactory () - { - return defaultFactory; - } - - /** - * @exception SecurityException FIXME - */ - public static void setFailureHandler (RMIFailureHandler fh) - { - currentHandler = fh; - } - - public static RMIFailureHandler getFailureHandler () - { - return currentHandler; - } -} diff --git a/libjava/java/rmi/server/RemoteCall.java b/libjava/java/rmi/server/RemoteCall.java deleted file mode 100644 index 35f3bf1a655..00000000000 --- a/libjava/java/rmi/server/RemoteCall.java +++ /dev/null @@ -1,86 +0,0 @@ -/* RemoteCall.java -- - Copyright (c) 1996, 1997, 1998, 1999, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.rmi.server; - -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.io.StreamCorruptedException; - -/** - * @deprecated - */ -public interface RemoteCall -{ - /** - * @deprecated - */ - ObjectOutput getOutputStream () throws IOException; - - /** - * @deprecated - */ - void releaseOutputStream () throws IOException; - - /** - * @deprecated - */ - ObjectInput getInputStream () throws IOException; - - /** - * @deprecated - */ - void releaseInputStream () throws IOException; - - /** - * @deprecated - */ - ObjectOutput getResultStream (boolean success) - throws IOException, StreamCorruptedException; - - /** - * @deprecated - */ - void executeCall () throws Exception; - - /** - * @deprecated - */ - void done () throws IOException; -} diff --git a/libjava/java/rmi/server/RemoteObject.java b/libjava/java/rmi/server/RemoteObject.java deleted file mode 100644 index 0b3c229c9d9..00000000000 --- a/libjava/java/rmi/server/RemoteObject.java +++ /dev/null @@ -1,160 +0,0 @@ -/* RemoteObject.java -- - Copyright (c) 1996, 1997, 1998, 1999, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.rmi.server; - -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; -import java.rmi.NoSuchObjectException; -import java.rmi.Remote; -import java.rmi.UnmarshalException; -import java.util.WeakHashMap; - -public abstract class RemoteObject - implements Remote, Serializable { - -private static final long serialVersionUID = -3215090123894869218l; - -protected transient RemoteRef ref; - -private static final WeakHashMap stubs = new WeakHashMap(); - -protected RemoteObject() { - this(null); -} - -protected RemoteObject(RemoteRef newref) { - ref = newref; -} - -public RemoteRef getRef() { - return (ref); -} - -synchronized static void addStub(Remote obj, Remote stub) -{ - stubs.put(obj, stub); -} - -synchronized static void deleteStub(Remote obj) -{ - stubs.remove(obj); -} - - public static Remote toStub(Remote obj) throws NoSuchObjectException - { - Remote stub = (Remote)stubs.get(obj); - - if (stub == null) - throw new NoSuchObjectException(obj.getClass().getName()); - - return stub; - } - -public int hashCode() { - if (ref == null) { - return (0); - } - else { - return (ref.hashCode()); - } -} - -public boolean equals(Object obj) { - // We only compare references. - return (this == obj); -} - - public String toString() - { - if (ref == null) - return getClass ().toString (); - return (ref.toString ()); - } - - private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException - { - String cname = in.readUTF(); - if (!cname.equals("")) - { - if (cname.equals ("UnicastRef2")) - { - // hack for interoperating with JDK - cname = "UnicastRef"; - in.read (); //some unknown UnicastRef2 field - } - - cname = RemoteRef.packagePrefix + '.' + cname; - try - { - Class cls = Class.forName(cname); - ref = (RemoteRef)cls.newInstance(); - } - catch (InstantiationException e1) - { - throw new UnmarshalException("failed to create ref", e1); - } - catch (IllegalAccessException e2) - { - throw new UnmarshalException("failed to create ref", e2); - } - ref.readExternal(in); - } - else - { - ref = (RemoteRef)in.readObject(); - } - } - -private void writeObject(ObjectOutputStream out) throws IOException, ClassNotFoundException { - if (ref == null) { - throw new UnmarshalException("no ref to serialize"); - } - String cname = ref.getRefClass(out); - if (cname != null && cname.length() > 0) { - out.writeUTF(cname); - ref.writeExternal(out); - } - else { - out.writeUTF(""); - out.writeObject(ref); - } -} - -} diff --git a/libjava/java/rmi/server/RemoteRef.java b/libjava/java/rmi/server/RemoteRef.java deleted file mode 100644 index 7e34db39e89..00000000000 --- a/libjava/java/rmi/server/RemoteRef.java +++ /dev/null @@ -1,79 +0,0 @@ -/* RemoteRef.java -- - Copyright (c) 1996, 1997, 1998, 1999, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.rmi.server; - -import java.io.Externalizable; -import java.io.ObjectOutput; -import java.lang.reflect.Method; -import java.rmi.Remote; -import java.rmi.RemoteException; - -public interface RemoteRef extends Externalizable -{ - long serialVersionUID = 3632638527362204081L; - - String packagePrefix = "gnu.java.rmi.server"; - - /** - * @deprecated - */ - void invoke (RemoteCall call) throws Exception; - - Object invoke (Remote obj, Method method, Object[] params, long opnum) - throws Exception; - - /** - * @deprecated - */ - RemoteCall newCall (RemoteObject obj, Operation[] op, int opnum, long hash) - throws RemoteException; - - /** - * @deprecated - */ - void done (RemoteCall call) throws RemoteException; - - boolean remoteEquals (RemoteRef ref); - - int remoteHashCode(); - - String getRefClass (ObjectOutput out); - - String remoteToString(); -} diff --git a/libjava/java/rmi/server/RemoteServer.java b/libjava/java/rmi/server/RemoteServer.java deleted file mode 100644 index 9efb12a782d..00000000000 --- a/libjava/java/rmi/server/RemoteServer.java +++ /dev/null @@ -1,76 +0,0 @@ -/* RemoteServer.java -- - Copyright (c) 1996, 1997, 1998, 1999, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.rmi.server; - -import gnu.java.rmi.server.RMIIncomingThread; - -import java.io.OutputStream; -import java.io.PrintStream; - -public abstract class RemoteServer extends RemoteObject -{ -private static final long serialVersionUID = -4100238210092549637L; - -protected RemoteServer() { - super(); -} - -protected RemoteServer(RemoteRef ref) { - super(ref); -} - -public static String getClientHost() throws ServerNotActiveException { - Thread currThread = Thread.currentThread(); - if (currThread instanceof RMIIncomingThread) { - RMIIncomingThread incomingThread = (RMIIncomingThread) currThread; - return incomingThread.getClientHost(); - } else { - throw new ServerNotActiveException( - "Unknown client host - current thread not instance of 'RMIIncomingThread'"); - } -} - -public static void setLog(OutputStream out) { - throw new Error("Not implemented"); -} - -public static PrintStream getLog() { - throw new Error("Not implemented"); -} - -} diff --git a/libjava/java/rmi/server/RemoteStub.java b/libjava/java/rmi/server/RemoteStub.java deleted file mode 100644 index 18c614b54a8..00000000000 --- a/libjava/java/rmi/server/RemoteStub.java +++ /dev/null @@ -1,61 +0,0 @@ -/* RemoteStub.java -- - Copyright (c) 1996, 1997, 1998, 1999, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.rmi.server; - -public abstract class RemoteStub extends RemoteObject -{ - static final long serialVersionUID = -1585587260594494182l; - - protected RemoteStub () - { - super (); - } - - protected RemoteStub (RemoteRef ref) - { - super (ref); - } - - /** - * @deprecated - */ - protected static void setRef (RemoteStub stub, RemoteRef ref) - { - stub.ref = ref; - } -} // class RemoteSub diff --git a/libjava/java/rmi/server/ServerCloneException.java b/libjava/java/rmi/server/ServerCloneException.java deleted file mode 100644 index bda41b3ce91..00000000000 --- a/libjava/java/rmi/server/ServerCloneException.java +++ /dev/null @@ -1,117 +0,0 @@ -/* ServerCloneException.java -- a UnicastRemoteObject could not be cloned - Copyright (c) 1996, 1997, 1998, 1999, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.rmi.server; - -/** - * Thrown if a remote exception occurs during the cloning process of a - * <code>UnicastRemoteObject</code>. - * - * @author unknown - * @see UnicastRemoteObject#clone() - * @since 1.1 - * @status updated to 1.4 - */ -public class ServerCloneException extends CloneNotSupportedException -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = 6617456357664815945L; - - /** - * The cause of this exception. This pre-dates the exception chaining - * of Throwable; and although you can change this field, you are wiser - * to leave it alone. - * - * @serial the exception cause - */ - public Exception detail; - - /** - * Create an exception with a message. - * - * @param s the message - */ - public ServerCloneException(String s) - { - this(s, null); - } - - /** - * Create an exception with a message and a cause. - * - * @param s the message - * @param e the cause - */ - public ServerCloneException(String s, Exception e) - { - super(s); - initCause(e); - detail = e; - } - - /** - * This method returns a message indicating what went wrong, in this - * format: - * <code>super.getMessage() + (detail == null ? "" - * : "; nested exception is:\n\t" + detail)</code>. - * - * @return the chained message - */ - public String getMessage() - { - if (detail == this || detail == null) - return super.getMessage(); - return super.getMessage() + "; nested exception is:\n\t" + detail; - } - - /** - * Returns the cause of this exception. Note that this may not be the - * original cause, thanks to the <code>detail</code> field being public - * and non-final (yuck). However, to avoid violating the contract of - * Throwable.getCause(), this returns null if <code>detail == this</code>, - * as no exception can be its own cause. - * - * @return the cause - * @since 1.4 - */ - public Throwable getCause() - { - return detail == this ? null : detail; - } -} diff --git a/libjava/java/rmi/server/ServerNotActiveException.java b/libjava/java/rmi/server/ServerNotActiveException.java deleted file mode 100644 index 0581b63bc82..00000000000 --- a/libjava/java/rmi/server/ServerNotActiveException.java +++ /dev/null @@ -1,72 +0,0 @@ -/* ServerNotActiveException.java -- the method is not servicing a remote call - Copyright (c) 1996, 1997, 1998, 1999, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.rmi.server; - -/** - * Thrown during <code>RemoteServer.getClientHost</code> if the host is - * not servicing a remote method call. - * - * @author unknown - * @see RemoteServer#getClientHost() - * @since 1.1 - * @status updated to 1.4 - */ -public class ServerNotActiveException extends Exception -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = 4687940720827538231L; - - /** - * Create an exception with no message. - */ - public ServerNotActiveException() - { - } - - /** - * Create an exception with a message. - * - * @param s the message - */ - public ServerNotActiveException(String s) - { - super(s); - } -} diff --git a/libjava/java/rmi/server/ServerRef.java b/libjava/java/rmi/server/ServerRef.java deleted file mode 100644 index cf1013cf02b..00000000000 --- a/libjava/java/rmi/server/ServerRef.java +++ /dev/null @@ -1,51 +0,0 @@ -/* ServerRef.java -- - Copyright (c) 1996, 1997, 1998, 1999, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.rmi.server; - -import java.rmi.Remote; -import java.rmi.RemoteException; - -public interface ServerRef extends RemoteRef -{ - long serialVersionUID = -4557750989390278438L; - - RemoteStub exportObject(Remote obj, Object data) throws RemoteException; - - String getClientHost() throws ServerNotActiveException; -} diff --git a/libjava/java/rmi/server/Skeleton.java b/libjava/java/rmi/server/Skeleton.java deleted file mode 100644 index 82f5d3837f4..00000000000 --- a/libjava/java/rmi/server/Skeleton.java +++ /dev/null @@ -1,57 +0,0 @@ -/* Skeleton.java -- - Copyright (c) 1996, 1997, 1998, 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.rmi.server; - -import java.rmi.Remote; - -/** - * @deprecated - */ -public interface Skeleton -{ - /** - * @deprecated - */ - void dispatch (Remote obj, RemoteCall theCall, int opnum, long hash) - throws Exception; - - /** - * @deprecated - */ - Operation[] getOperations(); -} diff --git a/libjava/java/rmi/server/SkeletonMismatchException.java b/libjava/java/rmi/server/SkeletonMismatchException.java deleted file mode 100644 index 9c0206ab3bc..00000000000 --- a/libjava/java/rmi/server/SkeletonMismatchException.java +++ /dev/null @@ -1,68 +0,0 @@ -/* SkeletonMismatchException.java -- thrown when stub class versions mismatch - Copyright (c) 1996, 1997, 1998, 1999, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.rmi.server; - -import java.rmi.RemoteException; - -/** - * Thrown if a call is received that does not match a Skeleton. Note that - * Skeletons are no longer required. - * - * @author unknown - * @since 1.1 - * @deprecated no replacement. Skeletons are no longer required. - * @status updated to 1.4 - */ -public class SkeletonMismatchException extends RemoteException -{ - /** - * Compatible with JDK 1.1. - */ - private static final long serialVersionUID = -7780460454818859281l; - - /** - * Create an exception with the specified message. - * - * @param s the message - * @deprecated no longer needed - */ - public SkeletonMismatchException(String s) - { - super(s); - } -} diff --git a/libjava/java/rmi/server/SkeletonNotFoundException.java b/libjava/java/rmi/server/SkeletonNotFoundException.java deleted file mode 100644 index 596aae15417..00000000000 --- a/libjava/java/rmi/server/SkeletonNotFoundException.java +++ /dev/null @@ -1,79 +0,0 @@ -/* SkeletonNotFoundException.java -- thrown if a Skeleton is not found - Copyright (c) 1996, 1997, 1998, 1999, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.rmi.server; - -import java.rmi.RemoteException; - -/** - * Thrown if a Skeleton corresponding to the remote object is not found. - * Note that Skeletons are no longer required. - * - * @author unknown - * @since 1.1 - * @deprecated no replacement. Skeletons are no longer required. - * @status updated to 1.4 - */ -public class SkeletonNotFoundException extends RemoteException -{ - /** - * Compatible with JDK 1.1. - */ - private static final long serialVersionUID = -7860299673822761231L; - - /** - * Create an exception with the specified message. - * - * @param s the message - */ - public SkeletonNotFoundException(String s) - { - super(s); - } - - /** - * Create an exception with the specified message and cause. - * - * @param s the message - * @param e the cause - */ - public SkeletonNotFoundException(String s, Exception e) - { - super(s, e); - } -} diff --git a/libjava/java/rmi/server/SocketSecurityException.java b/libjava/java/rmi/server/SocketSecurityException.java deleted file mode 100644 index aaf7698f4bc..00000000000 --- a/libjava/java/rmi/server/SocketSecurityException.java +++ /dev/null @@ -1,75 +0,0 @@ -/* SocketSecurityException.java -- the socket could not be created - Copyright (c) 1996, 1997, 1998, 1999, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.rmi.server; - -/** - * Thrown during remote object export if the code does not have permission - * to create a <code>java.net.ServerSocket</code> on the specified port. - * - * @author unknown - * @since 1.1 - * @status updated to 1.4 - */ -public class SocketSecurityException extends ExportException -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = -7622072999407781979L; - - /** - * Create an exception with the specified message. - * - * @param s the message - */ - public SocketSecurityException(String s) - { - super(s); - } - - /** - * Create an exception with the specified message and cause. - * - * @param s the message - * @param e the cause - */ - public SocketSecurityException(String s, Exception e) - { - super(s, e); - } -} diff --git a/libjava/java/rmi/server/UID.java b/libjava/java/rmi/server/UID.java deleted file mode 100644 index 0f492bae77a..00000000000 --- a/libjava/java/rmi/server/UID.java +++ /dev/null @@ -1,127 +0,0 @@ -/* UID.java -- - Copyright (c) 1996, 1997, 1998, 1999, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.rmi.server; - -import java.io.DataInput; -import java.io.DataOutput; -import java.io.IOException; -import java.io.Serializable; - -public final class UID implements Serializable -{ -private static final long serialVersionUID = 1086053664494604050L; - -private static final Object lock = UID.class; -private static long baseTime = System.currentTimeMillis(); -private static short nextCount = Short.MIN_VALUE; -// This is sun's algorithm - don't ask me why ... -private static final int uniqueNr = (new Object()).hashCode(); - -private int unique; -private long time; -private short count; - -/** - * This is sun's algorithm - don't ask me why ... - */ -public UID() { - synchronized (lock) { - if (nextCount == Short.MAX_VALUE) { - long newtime; - for (;;) { - newtime = System.currentTimeMillis(); - if (newtime - baseTime > 1000) { - break; - } - try { - Thread.sleep(1000); - } - catch (InterruptedException _) { - } - } - baseTime = newtime; - nextCount = Short.MIN_VALUE; - } - count = nextCount++; - unique = uniqueNr; - time = baseTime; - } -} - -public UID(short num) { - unique = (int)num; - time = 0; - count = 0; -} - -public int hashCode() { - return (unique); -} - -public boolean equals(Object obj) { - if (obj instanceof UID) { - UID uid = (UID)obj; - if (this.unique == uid.unique && - this.time == uid.time && - this.count == uid.count) { - return (true); - } - } - return (false); -} - -public String toString() { - return ("[UID: " + unique + "," + time + "," + count + "]"); -} - -public void write(DataOutput out) throws IOException { - out.writeInt(unique); - out.writeLong(time); - out.writeShort(count); -} - -public static UID read(DataInput in) throws IOException { - UID id = new UID(); - id.unique = in.readInt(); - id.time = in.readLong(); - id.count = in.readShort(); - return (id); -} - -} diff --git a/libjava/java/rmi/server/UnicastRemoteObject.java b/libjava/java/rmi/server/UnicastRemoteObject.java deleted file mode 100644 index dbe25bda3fd..00000000000 --- a/libjava/java/rmi/server/UnicastRemoteObject.java +++ /dev/null @@ -1,133 +0,0 @@ -/* UnicastRemoteObject.java -- - Copyright (c) 1996, 1997, 1998, 1999, 2002, 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.rmi.server; - -import gnu.java.rmi.server.UnicastServerRef; - -import java.rmi.NoSuchObjectException; -import java.rmi.Remote; -import java.rmi.RemoteException; - -public class UnicastRemoteObject extends RemoteServer -{ -private static final long serialVersionUID = 4974527148936298033L; -//The following serialized fields are from Java API Documentation "Serialized form" -private int port = 0; -private RMIClientSocketFactory csf = null; -private RMIServerSocketFactory ssf = null; - -protected UnicastRemoteObject() throws RemoteException { - this(0); -} - -protected UnicastRemoteObject(int port) throws RemoteException { - this(port, RMISocketFactory.getSocketFactory(), RMISocketFactory.getSocketFactory()); -} - -protected UnicastRemoteObject(int port, RMIClientSocketFactory csf, RMIServerSocketFactory ssf) throws RemoteException { - this.port = port; - //Is RMIXXXSocketFactory serializable - //this.csf = csf; - //this.ssf = ssf; - this.ref = new UnicastServerRef(new ObjID(), port, ssf); - exportObject(this); -} - -protected UnicastRemoteObject(RemoteRef ref) throws RemoteException { - super((UnicastServerRef)ref); - exportObject(this); -} - -public Object clone() throws CloneNotSupportedException { - throw new Error("Not implemented"); -} - -public static RemoteStub exportObject(Remote obj) throws RemoteException { - UnicastServerRef sref = (UnicastServerRef)((RemoteObject)obj).getRef(); - return (sref.exportObject(obj)); -} - - public static Remote exportObject(Remote obj, int port) throws RemoteException - { - return exportObject(obj, port, null); - } - - static Remote exportObject(Remote obj, int port, RMIServerSocketFactory ssf) - throws RemoteException - { - UnicastServerRef sref = null; - if (obj instanceof RemoteObject) - sref = (UnicastServerRef)((RemoteObject)obj).getRef (); - if(sref == null) - { - sref = new UnicastServerRef(new ObjID (), port, ssf); - } - Remote stub = sref.exportObject (obj); - addStub(obj, stub); - return stub; - } - - /** - * FIXME - */ - public static Remote exportObject(Remote obj, int port, RMIClientSocketFactory csf, - RMIServerSocketFactory ssf) - throws RemoteException - { - return (exportObject(obj, port, ssf)); - } - - public static boolean unexportObject(Remote obj, boolean force) - throws NoSuchObjectException - { - if (obj instanceof RemoteObject) - { - deleteStub(obj); - UnicastServerRef sref = (UnicastServerRef)((RemoteObject)obj).getRef(); - return sref.unexportObject(obj, force); - } - else - { - //FIX ME - ; - } - return true; - } - -} diff --git a/libjava/java/rmi/server/Unreferenced.java b/libjava/java/rmi/server/Unreferenced.java deleted file mode 100644 index 982aa64458f..00000000000 --- a/libjava/java/rmi/server/Unreferenced.java +++ /dev/null @@ -1,43 +0,0 @@ -/* Unreferenced.java -- - Copyright (c) 1996, 1997, 1998, 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.rmi.server; - -public interface Unreferenced -{ - void unreferenced(); -} diff --git a/libjava/java/security/AccessControlException.java b/libjava/java/security/AccessControlException.java deleted file mode 100644 index 27aee7c869a..00000000000 --- a/libjava/java/security/AccessControlException.java +++ /dev/null @@ -1,97 +0,0 @@ -/* AccessControlException.java -- Permission is denied - Copyright (C) 1998, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security; - -/** - * This exception is thrown when the <code>AccessController</code> denies - * an attempt to perform an operation. This often keeps track of the - * permission that was not granted. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @see AccessController - * @status updated to 1.4 - */ -public class AccessControlException extends SecurityException -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = 5138225684096988535L; - - /** - * The <code>Permission</code> associated with this exception. - * - * @serial the permission - */ - private final Permission perm; - - /** - * Create a new instance with a descriptive error message, and a null - * <code>Permission</code> object. - * - * @param msg the descriptive error message - */ - public AccessControlException(String msg) - { - this(msg, null); - } - - /** - * Create a new instance with a descriptive error message and an associated - * <code>Permission</code> object. - * - * @param msg the descriptive error message - * @param perm the permission that caused this - */ - public AccessControlException(String msg, Permission perm) - { - super(msg); - this.perm = perm; - } - - /** - * This method returns the <code>Permission</code> object that caused - * this exception to be thrown. - * - * @return the denied permission, or null - */ - public Permission getPermission() - { - return perm; - } -} diff --git a/libjava/java/security/AlgorithmParameterGenerator.java b/libjava/java/security/AlgorithmParameterGenerator.java deleted file mode 100644 index 5dc9e3bb274..00000000000 --- a/libjava/java/security/AlgorithmParameterGenerator.java +++ /dev/null @@ -1,302 +0,0 @@ -/* AlgorithmParameterGenerator.java --- Algorithm Parameter Generator - Copyright (C) 1999, 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security; - -import gnu.java.security.Engine; - -import java.security.spec.AlgorithmParameterSpec; - -/** - * <p>The <code>AlgorithmParameterGenerator</code> class is used to generate a - * set of parameters to be used with a certain algorithm. Parameter generators - * are constructed using the <code>getInstance()</code> factory methods (static - * methods that return instances of a given class).</p> - * - * <p>The object that will generate the parameters can be initialized in two - * different ways: in an algorithm-independent manner, or in an - * algorithm-specific manner:</p> - * - * <ul> - * <li>The algorithm-independent approach uses the fact that all parameter - * generators share the concept of a <i>"size"</i> and a <i>source of - * randomness</i>. The measure of <i>size</i> is universally shared by all - * algorithm parameters, though it is interpreted differently for different - * algorithms. For example, in the case of parameters for the <i>DSA</i> - * algorithm, <i>"size"</i> corresponds to the size of the prime modulus (in - * bits). When using this approach, algorithm-specific parameter generation - * values - if any - default to some standard values, unless they can be - * derived from the specified size.</li> - * <li>The other approach initializes a parameter generator object using - * algorithm-specific semantics, which are represented by a set of - * algorithm-specific parameter generation values. To generate Diffie-Hellman - * system parameters, for example, the parameter generation values usually - * consist of the size of the prime modulus and the size of the random - * exponent, both specified in number of bits.</li> - * </ul> - * - * <p>In case the client does not explicitly initialize the - * <code>AlgorithmParameterGenerator</code> (via a call to an <code>init()</code> - * method), each provider must supply (and document) a default initialization. - * For example, the <b>GNU</b> provider uses a default modulus prime size of - * <code>1024</code> bits for the generation of <i>DSA</i> parameters. - * - * @author Mark Benvenuto - * @since 1.2 - * @see AlgorithmParameters - * @see AlgorithmParameterSpec - */ -public class AlgorithmParameterGenerator -{ - /** Service name for algorithm parameter generators. */ - private static final String ALGORITHM_PARAMETER_GENERATOR = - "AlgorithmParameterGenerator"; - - private AlgorithmParameterGeneratorSpi paramGenSpi; - private Provider provider; - private String algorithm; - - /** - * Creates an <code>AlgorithmParameterGenerator</code> object. - * - * @param paramGenSpi the delegate. - * @param provider the provider. - * @param algorithm the algorithm. - */ - protected AlgorithmParameterGenerator(AlgorithmParameterGeneratorSpi - paramGenSpi, Provider provider, - String algorithm) - { - this.paramGenSpi = paramGenSpi; - this.provider = provider; - this.algorithm = algorithm; - } - - /** - * Returns the standard name of the algorithm this parameter generator is - * associated with. - * - * @return the string name of the algorithm. - */ - public final String getAlgorithm() - { - return algorithm; - } - - /** - * Generates an <code>AlgorithmParameterGenerator</code> object that - * implements the specified digest algorithm. If the default provider package - * provides an implementation of the requested digest algorithm, an instance - * of <code>AlgorithmParameterGenerator</code> containing that implementation - * is returned. If the algorithm is not available in the default package, - * other packages are searched. - * - * @param algorithm the string name of the algorithm this parameter generator - * is associated with. - * @return the new <code>AlgorithmParameterGenerator</code> object. - * @throws NoSuchAlgorithmException if the algorithm is not available in the - * environment. - */ - public static AlgorithmParameterGenerator getInstance(String algorithm) - throws NoSuchAlgorithmException - { - Provider[] p = Security.getProviders(); - for (int i = 0; i < p.length; i++) - try - { - return getInstance(algorithm, p[i]); - } - catch (NoSuchAlgorithmException e) - { - // Ignore. - } - - throw new NoSuchAlgorithmException(algorithm); - } - - /** - * Generates an <code>AlgorithmParameterGenerator</code> object for the - * requested algorithm, as supplied from the specified provider, if such a - * parameter generator is available from the provider. - * - * @param algorithm the string name of the algorithm. - * @param provider the string name of the provider. - * @return the new <code>AlgorithmParameterGenerator</code> object. - * @throws NoSuchAlgorithmException if the <code>algorithm</code> is not - * available from the <code>provider</code>. - * @throws NoSuchProviderException if the <code>provider</code> is not - * available in the environment. - * @throws IllegalArgumentException if the <code>provider</code> name is - * <code>null</code> or empty. - * @see Provider - */ - public static AlgorithmParameterGenerator getInstance(String algorithm, - String provider) - throws NoSuchAlgorithmException, NoSuchProviderException - { - if (provider == null || provider.length() == 0) - throw new IllegalArgumentException("Illegal provider"); - - Provider p = Security.getProvider(provider); - if (p == null) - throw new NoSuchProviderException(provider); - - return getInstance(algorithm, p); - } - - /** - * Generates an AlgorithmParameterGenerator object for the requested - * algorithm, as supplied from the specified provider, if such a parameter - * generator is available from the provider. Note: the <code>provider</code> - * doesn't have to be registered. - * - * @param algorithm the string name of the algorithm. - * @param provider the provider. - * @return the new AlgorithmParameterGenerator object. - * @throws NoSuchAlgorithmException if the algorithm is not available from - * the provider. - * @throws IllegalArgumentException if the provider is null. - * @since 1.4 - * @see Provider - */ - public static AlgorithmParameterGenerator getInstance(String algorithm, - Provider provider) - throws NoSuchAlgorithmException - { - if (provider == null) - throw new IllegalArgumentException("Illegal provider"); - - try - { - return new AlgorithmParameterGenerator( - (AlgorithmParameterGeneratorSpi) Engine.getInstance( - ALGORITHM_PARAMETER_GENERATOR, algorithm, provider), - provider, algorithm); - } - catch (java.lang.reflect.InvocationTargetException ite) - { - throw new NoSuchAlgorithmException(algorithm); - } - catch (ClassCastException cce) - { - throw new NoSuchAlgorithmException(algorithm); - } - } - - /** - * Returns the provider of this algorithm parameter generator object. - * - * @return the provider of this algorithm parameter generator object. - */ - public final Provider getProvider() - { - return provider; - } - - /** - * Initializes this parameter generator for a certain <i>size</i>. To create - * the parameters, the {@link SecureRandom} implementation of the - * highest-priority installed provider is used as the source of randomness. - * (If none of the installed providers supply an implementation of - * {@link SecureRandom}, a system-provided source of randomness is used.) - * - * @param size the size (number of bits). - */ - public final void init(int size) - { - init(size, new SecureRandom()); - } - - /** - * Initializes this parameter generator for a certain size and source of - * randomness. - * - * @param size the size (number of bits). - * @param random the source of randomness. - */ - public final void init(int size, SecureRandom random) - { - paramGenSpi.engineInit(size, random); - } - - /** - * Initializes this parameter generator with a set of algorithm-specific - * parameter generation values. To generate the parameters, the {@link - * SecureRandom} implementation of the highest-priority installed provider is - * used as the source of randomness. (If none of the installed providers - * supply an implementation of {@link SecureRandom}, a system-provided source - * of randomness is used.) - * - * @param genParamSpec the set of algorithm-specific parameter generation - * values. - * @throws InvalidAlgorithmParameterException if the given parameter - * generation values are inappropriate for this parameter generator. - */ - public final void init(AlgorithmParameterSpec genParamSpec) - throws InvalidAlgorithmParameterException - { - init(genParamSpec, new SecureRandom()); - } - - /** - * Initializes this parameter generator with a set of algorithm-specific - * parameter generation values. - * - * @param genParamSpec the set of algorithm-specific parameter generation - * values. - * @param random the source of randomness. - * @throws InvalidAlgorithmParameterException if the given parameter - * generation values are inappropriate for this parameter generator. - */ - public final void init(AlgorithmParameterSpec genParamSpec, - SecureRandom random) - throws InvalidAlgorithmParameterException - { - paramGenSpi.engineInit(genParamSpec, random); - } - - /** - * Generates the parameters. - * - * @return the new {@link AlgorithmParameters} object. - */ - public final AlgorithmParameters generateParameters() - { - return paramGenSpi.engineGenerateParameters(); - } -} diff --git a/libjava/java/security/AlgorithmParameterGeneratorSpi.java b/libjava/java/security/AlgorithmParameterGeneratorSpi.java deleted file mode 100644 index 3143ea76b8b..00000000000 --- a/libjava/java/security/AlgorithmParameterGeneratorSpi.java +++ /dev/null @@ -1,94 +0,0 @@ -/* AlgorithmParameterGeneratorSpi.java --- Algorithm Parameter Generator SPI - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security; -import java.security.spec.AlgorithmParameterSpec; - -/** - AlgorithmParameterGeneratorSpi is the Service Provider - Interface for the AlgorithmParameterGenerator class. - This class is used to generate the algorithm parameters - for a specific algorithm. - - @since JDK 1.2 - @author Mark Benvenuto - */ -public abstract class AlgorithmParameterGeneratorSpi -{ - - /** - Constructs a new AlgorithmParameterGeneratorSpi - */ - public AlgorithmParameterGeneratorSpi() - { - } - - /** - Initializes the parameter generator with the specified size - and SecureRandom - - @param size the size( in number of bits) - @param random the SecureRandom class to use for randomness - */ - protected abstract void engineInit(int size, SecureRandom random); - - /** - Initializes the parameter generator with the specified - AlgorithmParameterSpec and SecureRandom classes. - - If genParamSpec is an invalid AlgorithmParameterSpec for this - AlgorithmParameterGeneratorSpi then it throws - InvalidAlgorithmParameterException - - @param genParamSpec the AlgorithmParameterSpec class to use - @param random the SecureRandom class to use for randomness - - @throws InvalidAlgorithmParameterException genParamSpec is invalid - */ - protected abstract void engineInit(AlgorithmParameterSpec genParamSpec, - SecureRandom random) throws - InvalidAlgorithmParameterException; - - - /** - Generate a new set of AlgorithmParameters. - - @returns a new set of algorithm parameters - */ - protected abstract AlgorithmParameters engineGenerateParameters(); - -} diff --git a/libjava/java/security/AlgorithmParameters.java b/libjava/java/security/AlgorithmParameters.java deleted file mode 100644 index 038fbb4bd64..00000000000 --- a/libjava/java/security/AlgorithmParameters.java +++ /dev/null @@ -1,340 +0,0 @@ -/* AlgorithmParameters.java --- Algorithm Parameters Implementation Class - Copyright (C) 1999, 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security; - -import gnu.java.security.Engine; - -import java.io.IOException; -import java.security.spec.AlgorithmParameterSpec; -import java.security.spec.InvalidParameterSpecException; - -/** - * <p>This class is used as an opaque representation of cryptographic - * parameters.</p> - * - * <p>An <code>AlgorithmParameters</code> object for managing the parameters - * for a particular algorithm can be obtained by calling one of the - * <code>getInstance()</code> factory methods (static methods that return - * instances of a given class).</p> - * - * <p>There are two ways to request such an implementation: by specifying - * either just an algorithm name, or both an algorithm name and a package - * provider.</p> - * - * <ul> - * <li>If just an algorithm name is specified, the system will determine if - * there is an AlgorithmParameters implementation for the algorithm requested - * available in the environment, and if there is more than one, if there is - * a preferred one.</li> - * <li>If both an algorithm name and a package provider are specified, the - * system will determine if there is an implementation in the package - * requested, and throw an exception if there is not.</li> - * </ul> - * - * <p>Once an <code>AlgorithmParameters</code> object is returned, it must be - * initialized via a call to <code>init()</code>, using an appropriate - * parameter specification or parameter encoding.</p> - * - * <p>A transparent parameter specification is obtained from an - * <code>AlgorithmParameters</code> object via a call to - * <code>getParameterSpec()</code>, and a byte encoding of the parameters is - * obtained via a call to <code>getEncoded()</code>.</p> - * - * @author Mark Benvenuto - * @since 1.2 - * @see AlgorithmParameterSpec - * @see java.security.spec.DSAParameterSpec - * @see KeyPairGenerator - */ -public class AlgorithmParameters -{ - /** Service name for algorithm parameters. */ - private static final String ALGORITHM_PARAMETERS = "AlgorithmParameters"; - - private AlgorithmParametersSpi paramSpi; - private Provider provider; - private String algorithm; - - /** - * Creates an <code>AlgorithmParameters</code> object. - * - * @param paramSpi the delegate. - * @param provider the provider. - * @param algorithm the algorithm. - */ - protected AlgorithmParameters(AlgorithmParametersSpi paramSpi, - Provider provider, String algorithm) - { - this.paramSpi = paramSpi; - this.provider = provider; - this.algorithm = algorithm; - } - - /** - * Returns the name of the algorithm associated with this parameter object. - * - * @return the algorithm name. - */ - public final String getAlgorithm() - { - return algorithm; - } - - /** - * <p>Generates a parameter object for the specified algorithm.</p> - * - * <p>If the default provider package provides an implementation of the - * requested algorithm, an instance of <code>AlgorithmParameters</code> - * containing that implementation is returned. If the algorithm is not - * available in the default package, other packages are searched.</p> - * - * <p>The returned parameter object must be initialized via a call to - * <code>init()</code>, using an appropriate parameter specification or - * parameter encoding.</p> - * - * @param algorithm the name of the algorithm requested. - * @return the new parameter object. - * @throws NoSuchAlgorithmException if the algorithm is not available in the - * environment. - */ - public static AlgorithmParameters getInstance(String algorithm) - throws NoSuchAlgorithmException - { - Provider[] p = Security.getProviders(); - - for (int i = 0; i < p.length; i++) - try - { - return getInstance(algorithm, p[i]); - } - catch (NoSuchAlgorithmException e) - { - // Ignore this. - } - - throw new NoSuchAlgorithmException(algorithm); - } - - /** - * <p>Generates a parameter object for the specified algorithm, as supplied - * by the specified provider, if such an algorithm is available from the - * provider.</p> - * - * <p>The returned parameter object must be initialized via a call to - * <code>init()</code>, using an appropriate parameter specification or - * parameter encoding.</p> - * - * @param algorithm the name of the algorithm requested. - * @param provider the name of the provider. - * @return the new parameter object. - * @throws NoSuchAlgorithmException if the algorithm is not available in the - * package supplied by the requested provider. - * @throws NoSuchProviderException if the provider is not available in the - * environment. - * @throws IllegalArgumentException if the provider name is null or empty. - * @see Provider - */ - public static AlgorithmParameters getInstance(String algorithm, String provider) - throws NoSuchAlgorithmException, NoSuchProviderException - { - if (provider == null || provider.length() == 0) - throw new IllegalArgumentException("Illegal provider"); - - Provider p = Security.getProvider(provider); - if (p == null) - throw new NoSuchProviderException(provider); - - return getInstance(algorithm, p); - } - - /** - * Generates an <code>AlgorithmParameterGenerator</code> object for the - * requested algorithm, as supplied from the specified provider, if such a - * parameter generator is available from the provider. Note: the - * <code>provider</code> doesn't have to be registered. - * - * @param algorithm the string name of the algorithm. - * @param provider the provider. - * @return the new <code>AlgorithmParameterGenerator</code> object. - * @throws NoSuchAlgorithmException if the <code>algorithm</code> is not - * available from the <code>provider</code>. - * @throws IllegalArgumentException if the <code>provider</code> is - * <code>null</code>. - * @since 1.4 - */ - public static AlgorithmParameters getInstance(String algorithm, - Provider provider) - throws NoSuchAlgorithmException - { - if (provider == null) - throw new IllegalArgumentException("Illegal provider"); - - try - { - return new AlgorithmParameters((AlgorithmParametersSpi) - Engine.getInstance(ALGORITHM_PARAMETERS, algorithm, provider), - provider, algorithm); - } - catch (java.lang.reflect.InvocationTargetException ite) - { - throw new NoSuchAlgorithmException(algorithm); - } - catch (ClassCastException cce) - { - throw new NoSuchAlgorithmException(algorithm); - } - } - - /** - * Returns the provider of this parameter object. - * - * @return the provider of this parameter object. - */ - public final Provider getProvider() - { - return provider; - } - - /** - * Initializes this parameter object using the parameters specified in - * <code>paramSpec</code>. - * - * @param paramSpec the parameter specification. - * @throws InvalidParameterSpecException if the given parameter specification - * is inappropriate for the initialization of this parameter object, or if - * this parameter object has already been initialized. - */ - public final void init(AlgorithmParameterSpec paramSpec) - throws InvalidParameterSpecException - { - paramSpi.engineInit(paramSpec); - } - - /** - * Imports the specified parameters and decodes them according to the primary - * decoding format for parameters. The primary decoding format for parameters - * is ASN.1, if an ASN.1 specification for this type of parameters exists. - * - * @param params the encoded parameters. - * @throws IOException on decoding errors, or if this parameter object has - * already been initialized. - */ - public final void init(byte[]params) throws IOException - { - paramSpi.engineInit(params); - } - - /** - * Imports the parameters from params and decodes them according to the - * specified decoding scheme. If <code>format</code> is <code>null</code>, - * the primary decoding format for parameters is used. The primary decoding - * format is ASN.1, if an ASN.1 specification for these parameters exists. - * - * @param params the encoded parameters. - * @param format the name of the decoding scheme. - * @throws IOException on decoding errors, or if this parameter object has - * already been initialized. - */ - public final void init(byte[]params, String format) throws IOException - { - paramSpi.engineInit(params, format); - } - - /** - * Returns a (transparent) specification of this parameter object. - * <code>paramSpec</code> identifies the specification class in which the - * parameters should be returned. It could, for example, be - * <code>DSAParameterSpec.class</code>, to indicate that the parameters should - * be returned in an instance of the {@link java.security.spec.DSAParameterSpec} - * class. - * - * @param paramSpec the specification class in which the parameters should be - * returned. - * @return the parameter specification. - * @throws InvalidParameterSpecException if the requested parameter - * specification is inappropriate for this parameter object, or if this - * parameter object has not been initialized. - */ - public final AlgorithmParameterSpec getParameterSpec(Class paramSpec) - throws InvalidParameterSpecException - { - return paramSpi.engineGetParameterSpec(paramSpec); - } - - /** - * Returns the parameters in their primary encoding format. The primary - * encoding format for parameters is ASN.1, if an ASN.1 specification for - * this type of parameters exists. - * - * @return the parameters encoded using their primary encoding format. - * @throws IOException on encoding errors, or if this parameter object has not - * been initialized. - */ - public final byte[] getEncoded() throws IOException - { - return paramSpi.engineGetEncoded(); - } - - /** - * Returns the parameters encoded in the specified scheme. If format is - * <code>null</code>, the primary encoding format for parameters is used. The - * primary encoding format is ASN.1, if an ASN.1 specification for these - * parameters exists. - * - * @param format the name of the encoding format. - * @return the parameters encoded using the specified encoding scheme. - * @throws IOException on encoding errors, or if this parameter object has - * not been initialized. - */ - public final byte[] getEncoded(String format) throws IOException - { - return paramSpi.engineGetEncoded(format); - } - - /** - * Returns a formatted string describing the parameters. - * - * @return a formatted string describing the parameters, or <code>null</code> - * if this parameter object has not been initialized. - */ - public final String toString() - { - return paramSpi.engineToString(); - } -} diff --git a/libjava/java/security/AlgorithmParametersSpi.java b/libjava/java/security/AlgorithmParametersSpi.java deleted file mode 100644 index a9faa154374..00000000000 --- a/libjava/java/security/AlgorithmParametersSpi.java +++ /dev/null @@ -1,149 +0,0 @@ -/* AlgorithmParametersSpi.java --- Algorithm Parameters SPI - Copyright (C) 1999, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security; - -import java.io.IOException; -import java.security.spec.AlgorithmParameterSpec; -import java.security.spec.InvalidParameterSpecException; - -/** - * AlgorithmParametersSpi is the Service Provider Interface - * for the Algorithm Parameters class. This class is used - * to manage the algorithm parameters. - * - * @since 1.2 - * @author Mark Benvenuto - */ -public abstract class AlgorithmParametersSpi -{ - /** - * Creates a new instance of AlgorithmParametersSpi - */ - public AlgorithmParametersSpi() - { - } - - /** - * Initializes the engine with the specified - * AlgorithmParameterSpec class. - * - * @param paramSpec A AlgorithmParameterSpec to initialize with - * - * @throws InvalidParameterSpecException For an inapporiate - * ParameterSpec class - */ - protected abstract void engineInit(AlgorithmParameterSpec paramSpec) - throws InvalidParameterSpecException; - - /** - * Initializes the engine with the specified - * parameters stored in the byte array and decodes them - * according to the ASN.1 specification. If the ASN.1 - * specification exists then it succeeds or else it throws - * IOException. - * - * @param params Parameters to initialize with - * - * @throws IOException Decoding Error - */ - protected abstract void engineInit(byte[]params) throws IOException; - - /** - * Initializes the engine with the specified - * parameters stored in the byte array and decodes them - * according to the specified decoding specification. - * If format is null, then it is decoded using the ASN.1 - * specification if it exists or else it throws - * IOException. - * - * @param params Parameters to initialize with - * @param format Name of decoding format to use - * - * @throws IOException Decoding Error - */ - protected abstract void engineInit(byte[]params, String format) - throws IOException; - - - /** - * Returns a specification of this AlgorithmParameters object. - * paramSpec identifies the class to return the AlgortihmParameters - * in. - * - * @param paramSpec Class to return AlgorithmParameters in - * - * @return the parameter specification - * - * @throws InvalidParameterSpecException if the paramSpec is an - * invalid parameter class - */ - protected abstract AlgorithmParameterSpec engineGetParameterSpec(Class - paramSpec) - throws InvalidParameterSpecException; - - - /** - * Returns the parameters in the default encoding format. - * The primary encoding format is ASN.1 format if it exists - * for the specified type. - * - * @return byte array representing the parameters - */ - protected abstract byte[] engineGetEncoded() throws IOException; - - - /** - * Returns the parameters in the specified encoding format. - * If <code>format</code> is <code>null</code> then the - * primary encoding format is used, the ASN.1 format, - * if it exists for the specified type. - * - * @return byte array representing the parameters - */ - protected abstract byte[] engineGetEncoded(String format) - throws IOException; - - /** - * Returns a string describing the parameters in the - * AlgorithmParametersSpi class. - * - * @return A string representing the format of the parameters. - */ - protected abstract String engineToString(); -} diff --git a/libjava/java/security/AllPermission.java b/libjava/java/security/AllPermission.java deleted file mode 100644 index 6adcd8c9c96..00000000000 --- a/libjava/java/security/AllPermission.java +++ /dev/null @@ -1,198 +0,0 @@ -/* AllPermission.java -- Permission to do anything - Copyright (C) 1998, 2001, 2002, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security; - -import gnu.java.util.EmptyEnumeration; - -import java.util.Collections; -import java.util.Enumeration; - -/** - * This class is a permission that implies all other permissions. Granting - * this permission effectively grants all others. Extreme caution should - * be exercised in granting this permission. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Eric Blake (ebb9@email.byu.edu) - * @see AccessController - * @see Permissions - * @see SecurityManager - * @since 1.1 - * @status updated to 1.4 - */ -public final class AllPermission extends Permission -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = -2916474571451318075L; - - /** - * Create a new AllPermission object. - */ - public AllPermission() - { - super("*"); - } - - /** - * Create a new AllPermission object. The parameters are ignored, as all - * permission implies ALL PERMISSION. - * - * @param name ignored - * @param actions ignored - */ - public AllPermission(String name, String actions) - { - super("*"); - } - - /** - * This method always returns <code>true</code> to indicate that this - * permission always implies that any other permission is also granted. - * - * @param perm ignored - * @return true, the permission is implied - */ - public boolean implies(Permission perm) - { - return true; - } - - /** - * Checks an object for equality. All AllPermissions are equal. - * - * @param obj the <code>Object</code> to test for equality - */ - public boolean equals(Object obj) - { - return obj instanceof AllPermission; - } - - /** - * This method returns a hash code for this object. This returns 1. - * - * @return a hash value for this object - */ - public int hashCode() - { - return 1; - } - - /** - * This method returns the list of actions associated with this object. - * This will always be the empty string ("") for this class. - * - * @return the action list - */ - public String getActions() - { - return ""; - } - - /** - * Returns a PermissionCollection which can hold AllPermission. - * - * @return a permission collection - */ - public PermissionCollection newPermissionCollection() - { - return new AllPermissionCollection(); - } - - /** - * Implements AllPermission.newPermissionCollection, and obeys serialization - * of JDK. - * - * @author Eric Blake (ebb9@email.byu.edu) - */ - private static final class AllPermissionCollection extends PermissionCollection - { - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = -4023755556366636806L; - - /** - * Whether an AllPermission has been added to the collection. - * - * @serial if all permission is in the collection yet - */ - private boolean all_allowed; - - /** - * Add an AllPermission. - * - * @param perm the permission to add - * @throws IllegalArgumentException if perm is not an AllPermission - * @throws SecurityException if the collection is read-only - */ - public void add(Permission perm) - { - if (isReadOnly()) - throw new SecurityException(); - if (! (perm instanceof AllPermission)) - throw new IllegalArgumentException(); - all_allowed = true; - } - - /** - * Returns true if this collection implies a permission. - * - * @param perm the permission to check - * @return true if this collection contains an AllPermission - */ - public boolean implies(Permission perm) - { - return all_allowed; - } - - /** - * Returns an enumeration of the elements in the collection. - * - * @return the elements in the collection - */ - public Enumeration elements() - { - return all_allowed - ? Collections.enumeration(Collections.singleton(new AllPermission())) - : EmptyEnumeration.getInstance(); - } - } // class AllPermissionCollection -} // class AllPermission diff --git a/libjava/java/security/BasicPermission.java b/libjava/java/security/BasicPermission.java deleted file mode 100644 index 267a6e292ab..00000000000 --- a/libjava/java/security/BasicPermission.java +++ /dev/null @@ -1,308 +0,0 @@ -/* BasicPermission.java -- implements a simple named permission - Copyright (C) 1998, 1999, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security; - -import java.io.Serializable; -import java.util.Enumeration; -import java.util.Hashtable; - -/** - * This class implements a simple model for named permissions without an - * associated action list. That is, either the named permission is granted - * or it is not. - * - * <p>It also supports trailing wildcards to allow the easy granting of - * permissions in a hierarchical fashion. (For example, the name "org.gnu.*" - * might grant all permissions under the "org.gnu" permissions hierarchy). - * The only valid wildcard character is a '*' which matches anything. It - * must be the rightmost element in the permission name and must follow a - * '.' or else the Permission name must consist of only a '*'. Any other - * occurrence of a '*' is not valid. - * - * <p>This class ignores the action list. Subclasses can choose to implement - * actions on top of this class if desired. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Eric Blake (ebb9@email.byu.edu) - * @see Permission - * @see Permissions - * @see PermissionCollection - * @see RuntimePermission - * @see SecurityPermission - * @see PropertyPermission - * @see AWTPermission - * @see NetPermission - * @see SecurityManager - * @since 1.1 - * @status updated to 1.4 - */ -public abstract class BasicPermission extends java.security.Permission - implements Serializable - // FIXME extends with fully qualified classname as workaround for gcj 3.3. -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = 6279438298436773498L; - - /** - * Create a new instance with the specified permission name. If the - * name is empty an exception is thrown. - * - * @param name the name of this permission - * @throws NullPointerException if name is null - * @throws IllegalArgumentException if name is invalid - */ - public BasicPermission(String name) - { - super(name); - - // This routine used to check for illegal wildcards, but no such - // requirement exists in the specification and Sun's runtime - // doesn't appear to do it. - - if ("".equals(name)) - throw new IllegalArgumentException("Empty name"); - } - - /** - * Create a new instance with the specified permission name. If the name - * is empty, or contains an illegal wildcard character, an exception is - * thrown. The actions parameter is ignored. - * - * @param name the name of this permission - * @param actions ignored - * @throws NullPointerException if name is null - * @throws IllegalArgumentException if name is invalid - */ - public BasicPermission(String name, String actions) - { - this(name); - } - - /** - * This method tests to see if the specified permission is implied by this - * permission. This will be true if the following conditions are met:<ul> - * <li>The specified object is an instance of the same class as this - * object.</li> - * <li>The name of the specified permission is implied by this permission's - * name based on wildcard matching. For example, "a.*" implies "a.b".</li> - * </ul> - * - * @param perm the <code>Permission</code> object to test against - * @return true if the specified permission is implied - */ - public boolean implies(Permission perm) - { - if (! getClass().isInstance(perm)) - return false; - - String otherName = perm.getName(); - String name = getName(); - - if (name.equals(otherName)) - return true; - - int last = name.length() - 1; - return name.charAt(last) == '*' - && otherName.startsWith(name.substring(0, last)); - } - - /** - * This method tests to see if this object is equal to the specified - * <code>Object</code>. This will be true if and only if the specified - * object meets the following conditions:<ul> - * <li>It is an instance of the same class as this.</li> - * <li>It has the same name as this permission.</li> - * </ul> - * - * @param obj the <code>Object</code> to test for equality - * @return true if obj is semantically equal to this - */ - public boolean equals(Object obj) - { - return getClass().isInstance(obj) - && getName().equals(((BasicPermission) obj).getName()); - } - - /** - * This method returns a hash code for this permission object. The hash - * code returned is the value returned by calling the <code>hashCode</code> - * method on the <code>String</code> that is the name of this permission. - * - * @return a hash value for this object - */ - public int hashCode() - { - return getName().hashCode(); - } - - /** - * This method returns a list of the actions associated with this - * permission. This method always returns the empty string ("") since - * this class ignores actions. - * - * @return the action list - */ - public String getActions() - { - return ""; - } - - /** - * This method returns an instance of <code>PermissionCollection</code> - * suitable for storing <code>BasicPermission</code> objects. The - * collection returned can only store objects of the same type as this. - * Subclasses which use actions must override this method; but a class with - * no actions will work fine with this. - * - * @return a new empty <code>PermissionCollection</code> object - */ - public PermissionCollection newPermissionCollection() - { - return new BasicPermissionCollection(getClass()); - } - - /** - * Implements AllPermission.newPermissionCollection, and obeys serialization - * of JDK. - * - * @author Eric Blake (ebb9@email.byu.edu) - */ - private static final class BasicPermissionCollection extends PermissionCollection - { - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = 739301742472979399L; - - /** - * The permissions in the collection. - * - * @serial a hash mapping name to permissions, all of type permClass - */ - private final Hashtable permissions = new Hashtable(); - - /** - * If "*" is in the collection. - * - * @serial true if a permission named "*" is in the collection - */ - private boolean all_allowed; - - /** - * The runtime class which all entries in the table must belong to. - * - * @serial the limiting subclass of this collection - */ - private final Class permClass; - - /** - * Construct a collection over the given runtime class. - * - * @param c the class - */ - BasicPermissionCollection(Class c) - { - permClass = c; - } - - /** - * Add a Permission. It must be of the same type as the permission which - * created this collection. - * - * @param perm the permission to add - * @throws IllegalArgumentException if perm is not the correct type - * @throws SecurityException if the collection is read-only - */ - public void add(Permission perm) - { - if (isReadOnly()) - throw new SecurityException("readonly"); - if (! permClass.isInstance(perm)) - throw new IllegalArgumentException("Expecting instance of " + permClass); - BasicPermission bp = (BasicPermission) perm; - String name = bp.getName(); - if (name.equals("*")) - all_allowed = true; - permissions.put(name, bp); - } - - /** - * Returns true if this collection implies the given permission. - * - * @param permission the permission to check - * @return true if it is implied by this - */ - public boolean implies(Permission permission) - { - if (! permClass.isInstance(permission)) - return false; - if (all_allowed) - return true; - BasicPermission toImply = (BasicPermission) permission; - String name = toImply.getName(); - if (name.equals("*")) - return false; - int prefixLength = name.length(); - if (name.endsWith("*")) - prefixLength -= 2; - - while (true) - { - if (permissions.get(name) != null) - return true; - prefixLength = name.lastIndexOf('.', prefixLength); - if (prefixLength < 0) - return false; - name = name.substring(0, prefixLength + 1) + '*'; - } - } - - /** - * Enumerate over the collection. - * - * @return an enumeration of the collection contents - */ - public Enumeration elements() - { - return permissions.elements(); - } - } // class BasicPermissionCollection -} // class BasicPermission diff --git a/libjava/java/security/Certificate.java b/libjava/java/security/Certificate.java deleted file mode 100644 index 5cdba6e101b..00000000000 --- a/libjava/java/security/Certificate.java +++ /dev/null @@ -1,125 +0,0 @@ -/* Certificate.java -- deprecated interface for modeling digital certificates - Copyright (C) 1998, 2002, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -/** - * This interface models a digital certificate which verifies the - * authenticity of a party. This class simply allows certificate - * information to be queried, it does not guarantee that the certificate - * is valid. - * - * <p>This class is deprecated in favor of the new java.security.cert package. - * It exists for backward compatibility only. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @since 1.1 - * @deprecated use {@link java.security.cert} instead - * @status updated to 1.4 - */ -public interface Certificate -{ - /** - * This method returns the <code>Principal</code> that is guaranteeing - * this certificate. - * - * @return the <code>Principal</code> guaranteeing the certificate - */ - Principal getGuarantor(); - - /** - * This method returns the <code>Principal</code> being guaranteed by - * this certificate. - * - * @return the <code>Principal</code> guaranteed by this certificate - */ - Principal getPrincipal(); - - /** - * This method returns the public key for the <code>Principal</code> that - * is being guaranteed. - * - * @return the <code>PublicKey</code> of the Principal being guaranteed - */ - PublicKey getPublicKey(); - - /** - * This method writes the certificate to an <code>OutputStream</code> in - * a format that can be understood by the <code>decode</code> method. - * - * @param out the <code>OutputStream</code> to write to - * @throws KeyException if there is a problem with the certificate - * @throws IOException if an error occurs writing to the stream - * @see #decode(InputStream) - * @see #getFormat() - */ - void encode(OutputStream out) throws KeyException, IOException; - - /** - * This method reads an encoded certificate from an <code>InputStream</code>. - * - * @param in the <code>InputStream</code> to read from - * @throws KeyException if there is a problem with the certificate data - * @throws IOException if an error occurs reading from the stream - * @see #encode(OutputStream) - * @see #getFormat() - */ - void decode(InputStream in) throws KeyException, IOException; - - /** - * This method returns the encoding format of the certificate (e.g., "PGP", - * "X.509"). This format is used by the <code>encode</code> and - * <code>decode</code> methods. - * - * @return the encoding format being used - */ - String getFormat(); - - /** - * This method returns a <code>String</code> representation of the contents - * of this certificate. - * - * @param detail true to provided more detailed information - * @return the string representation - */ - String toString(boolean detail); -} // interface Certificate diff --git a/libjava/java/security/CodeSource.java b/libjava/java/security/CodeSource.java deleted file mode 100644 index b516170281c..00000000000 --- a/libjava/java/security/CodeSource.java +++ /dev/null @@ -1,354 +0,0 @@ -/* CodeSource.java -- Code location and certifcates - Copyright (C) 1998, 2002, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; -import java.net.SocketPermission; -import java.net.URL; -// Note that this overrides Certificate in this package. -import java.security.cert.Certificate; -import java.security.cert.CertificateEncodingException; -import java.security.cert.CertificateException; -import java.security.cert.CertificateFactory; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Iterator; - -/** - * This class represents a location from which code is loaded (as - * represented by a URL), and the list of certificates that are used to - * check the signatures of signed code loaded from this source. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.1 - * @status updated to 1.4 - */ -public class CodeSource implements Serializable -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = 4977541819976013951L; - - /** - * This is the URL that represents the code base from which code will - * be loaded. - * - * @serial the code location - */ - private final URL location; - - /** The set of certificates for this code base. */ - private transient HashSet certs; - - /** - * This creates a new instance of <code>CodeSource</code> that loads code - * from the specified URL location and which uses the specified certificates - * for verifying signatures. - * - * @param location the location from which code will be loaded - * @param certs the list of certificates - */ - public CodeSource(URL location, Certificate[] certs) - { - this.location = location; - if (certs != null) - this.certs = new HashSet(Arrays.asList(certs)); - } - - /** - * This method returns a hash value for this object. - * - * @return a hash value for this object - */ - public int hashCode() - { - return (location == null ? 0 : location.hashCode()) - ^ (certs == null ? 0 : certs.hashCode()); - } - - /** - * This method tests the specified <code>Object</code> for equality with - * this object. This will be true if and only if the locations are equal - * and the certificate sets are identical (ignoring order). - * - * @param obj the <code>Object</code> to test against - * @return true if the specified object is equal to this one - */ - public boolean equals(Object obj) - { - if (! (obj instanceof CodeSource)) - return false; - CodeSource cs = (CodeSource) obj; - return (certs == null ? cs.certs == null : certs.equals(cs.certs)) - && (location == null ? cs.location == null - : location.equals(cs.location)); - } - - /** - * This method returns the URL specifying the location from which code - * will be loaded under this <code>CodeSource</code>. - * - * @return the code location for this <code>CodeSource</code> - */ - public final URL getLocation() - { - return location; - } - - /** - * This method returns the list of digital certificates that can be used - * to verify the signatures of code loaded under this - * <code>CodeSource</code>. - * - * @return the certifcate list for this <code>CodeSource</code> - */ - public final Certificate[] getCertificates() - { - if (certs == null) - return null; - Certificate[] c = new Certificate[certs.size()]; - certs.toArray(c); - return c; - } - - /** - * This method tests to see if a specified <code>CodeSource</code> is - * implied by this object. Effectively, to meet this test, the specified - * object must have all the certifcates this object has (but may have more), - * and must have a location that is a subset of this object's. In order - * for this object to imply the specified object, the following must be - * true: - * - * <ol> - * <li><em>codesource</em> must not be <code>null</code>.</li> - * <li>If <em>codesource</em> has a certificate list, all of it's - * certificates must be present in the certificate list of this - * code source.</li> - * <li>If this object does not have a <code>null</code> location, then - * the following addtional tests must be passed. - * - * <ol> - * <li><em>codesource</em> must not have a <code>null</code> - * location.</li> - * <li><em>codesource</em>'s location must be equal to this object's - * location, or - * <ul> - * <li><em>codesource</em>'s location protocol, port, and ref (aka, - * anchor) must equal this objects</li> - * <li><em>codesource</em>'s location host must imply this object's - * location host, as determined by contructing - * <code>SocketPermission</code> objects from each with no - * action list and using that classes's <code>implies</code> - * method</li> - * <li>If this object's location file ends with a '/', then the - * specified object's location file must start with this - * object's location file. Otherwise, the specified object's - * location file must start with this object's location file - * with the '/' character appended to it.</li> - * </ul></li> - * </ol></li> - * </ol> - * - * <p>For example, each of these locations imply the location - * "http://java.sun.com/classes/foo.jar":</p> - * - * <pre> - * http: - * http://*.sun.com/classes/* - * http://java.sun.com/classes/- - * http://java.sun.com/classes/foo.jar - * </pre> - * - * <p>Note that the code source with null location and null certificates implies - * all other code sources.</p> - * - * @param cs the <code>CodeSource</code> to test against this object - * @return true if this specified <code>CodeSource</code> is implied - */ - public boolean implies(CodeSource cs) - { - if (cs == null) - return false; - // First check the certificate list. - if (certs != null && (cs.certs == null || ! certs.containsAll(cs.certs))) - return false; - // Next check the location. - if (location == null) - return true; - if (cs.location == null - || ! location.getProtocol().equals(cs.location.getProtocol()) - || (location.getPort() != -1 - && location.getPort() != cs.location.getPort()) - || (location.getRef() != null - && ! location.getRef().equals(cs.location.getRef()))) - return false; - if (location.getHost() != null) - { - String their_host = cs.location.getHost(); - if (their_host == null) - return false; - SocketPermission our_sockperm = - new SocketPermission(location.getHost(), "accept"); - SocketPermission their_sockperm = - new SocketPermission(their_host, "accept"); - if (! our_sockperm.implies(their_sockperm)) - return false; - } - String our_file = location.getFile(); - if (our_file != null) - { - if (! our_file.endsWith("/")) - our_file += "/"; - String their_file = cs.location.getFile(); - if (their_file == null - || ! their_file.startsWith(our_file)) - return false; - } - return true; - } - - /** - * This method returns a <code>String</code> that represents this object. - * The result is in the format <code>"(" + getLocation()</code> followed - * by a space separated list of certificates (or "<no certificates>"), - * followed by <code>")"</code>. - * - * @return a <code>String</code> for this object - */ - public String toString() - { - StringBuffer sb = new StringBuffer("(").append(location); - if (certs == null || certs.isEmpty()) - sb.append(" <no certificates>"); - else - { - Iterator iter = certs.iterator(); - for (int i = certs.size(); --i >= 0; ) - sb.append(' ').append(iter.next()); - } - return sb.append(")").toString(); - } - - /** - * Reads this object from a serialization stream. - * - * @param s the input stream - * @throws IOException if reading fails - * @throws ClassNotFoundException if deserialization fails - * @serialData this reads the location, then expects an int indicating the - * number of certificates. Each certificate is a String type - * followed by an int encoding length, then a byte[] encoding - */ - private void readObject(ObjectInputStream s) - throws IOException, ClassNotFoundException - { - s.defaultReadObject(); - int count = s.readInt(); - certs = new HashSet(); - while (--count >= 0) - { - String type = (String) s.readObject(); - int bytes = s.readInt(); - byte[] encoded = new byte[bytes]; - for (int i = 0; i < bytes; i++) - encoded[i] = s.readByte(); - ByteArrayInputStream stream = new ByteArrayInputStream(encoded); - try - { - CertificateFactory factory = CertificateFactory.getInstance(type); - certs.add(factory.generateCertificate(stream)); - } - catch (CertificateException e) - { - // XXX Should we ignore this certificate? - } - } - } - - /** - * Writes this object to a serialization stream. - * - * @param s the output stream - * @throws IOException if writing fails - * @serialData this writes the location, then writes an int indicating the - * number of certificates. Each certificate is a String type - * followed by an int encoding length, then a byte[] encoding - */ - private void writeObject(ObjectOutputStream s) throws IOException - { - s.defaultWriteObject(); - if (certs == null) - s.writeInt(0); - else - { - int count = certs.size(); - s.writeInt(count); - Iterator iter = certs.iterator(); - while (--count >= 0) - { - Certificate c = (Certificate) iter.next(); - s.writeObject(c.getType()); - byte[] encoded; - try - { - encoded = c.getEncoded(); - } - catch (CertificateEncodingException e) - { - // XXX Should we ignore this certificate? - encoded = null; - } - if (encoded == null) - s.writeInt(0); - else - { - s.writeInt(encoded.length); - for (int i = 0; i < encoded.length; i++) - s.writeByte(encoded[i]); - } - } - } - } -} // class CodeSource diff --git a/libjava/java/security/DigestException.java b/libjava/java/security/DigestException.java deleted file mode 100644 index 6393e0cc834..00000000000 --- a/libjava/java/security/DigestException.java +++ /dev/null @@ -1,70 +0,0 @@ -/* DigestException.java -- A generic message digest exception - Copyright (C) 1998, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security; - -/** - * This exception indicates that a generic message digest exception has - * occurred. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @status updated to 1.4 - */ -public class DigestException extends GeneralSecurityException -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = 5821450303093652515L; - - /** - * Create a new instance with no descriptive message. - */ - public DigestException() - { - } - - /** - * Create a new instance with a descriptive error message. - * - * @param msg the descriptive message - */ - public DigestException(String msg) - { - super(msg); - } -} diff --git a/libjava/java/security/DigestInputStream.java b/libjava/java/security/DigestInputStream.java deleted file mode 100644 index 0d4a9d05dc6..00000000000 --- a/libjava/java/security/DigestInputStream.java +++ /dev/null @@ -1,167 +0,0 @@ -/* DigestInputStream.java --- An Input stream tied to a message digest - Copyright (C) 1999, 2003, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security; - -import java.io.FilterInputStream; -import java.io.IOException; -import java.io.InputStream; - -/** - * DigestInputStream is a class that ties an InputStream with a - * MessageDigest. The Message Digest is used by the class to - * update it self as bytes are read from the InputStream. - * - * The updating to the digest depends on the on flag which is set - * to true by default to tell the class to update the data - * in the message digest. - * - * @version 0.0 - * @author Mark Benvenuto (ivymccough@worldnet.att.net) - */ -public class DigestInputStream extends FilterInputStream -{ - /** - * The message digest for the DigestInputStream - */ - protected MessageDigest digest; - - //Manages the on flag - private boolean state = true; - - /** - * Constructs a new DigestInputStream. - * It associates a MessageDigest with the stream to - * compute the stream as data is written. - * - * @param stream An InputStream to associate this stream with - * @param digest A MessageDigest to hash the stream with - */ - public DigestInputStream(InputStream stream, MessageDigest digest) - { - super(stream); - //this.in = stream; - this.digest = digest; - } - - /** - * Returns the MessageDigest associated with this DigestInputStream - * - * @return The MessageDigest used to hash this stream - */ - public MessageDigest getMessageDigest() - { - return digest; - } - - /** - * Sets the current MessageDigest to current parameter - * - * @param digest A MessageDigest to associate with this stream - */ - public void setMessageDigest(MessageDigest digest) - { - this.digest = digest; - } - - /** - * Reads a byte from the input stream and updates the digest. - * This method reads the underlying input stream and if the - * on flag is true then updates the message digest. - * - * @return Returns a byte from the input stream, -1 is returned to indicate that - * the end of stream was reached before this read call - * - * @throws IOException if an IO error occurs in the underlying input stream, - * this error is thrown - */ - public int read() throws IOException - { - int temp = in.read(); - - if (state == true && temp != -1) - digest.update((byte) temp); - - return temp; - } - - /** - * Reads bytes from the input stream and updates the digest. - * This method reads the underlying input stream and if the - * on flag is true then updates the message digest. - * - * @param b a byte array to store the data from the input stream - * @param off an offset to start at in the array - * @param len length of data to read - * @return Returns count of bytes read, -1 is returned to indicate that - * the end of stream was reached before this read call - * - * @throws IOException if an IO error occurs in the underlying input stream, - * this error is thrown - */ - public int read(byte[]b, int off, int len) throws IOException - { - int temp = in.read(b, off, len); - - if (state == true && temp != -1) - digest.update(b, off, temp); - - return temp; - } - - /** - * Sets the flag specifing if this DigestInputStream updates the - * digest in the write() methods. The default is on; - * - * @param on True means it digests stream, false means it does not - */ - public void on(boolean on) - { - state = on; - } - - /** - * Converts the input stream and underlying message digest to a string. - * - * @return A string representing the input stream and message digest. - */ - public String toString() - { - return "[Digest Input Stream] " + digest.toString(); - } -} diff --git a/libjava/java/security/DigestOutputStream.java b/libjava/java/security/DigestOutputStream.java deleted file mode 100644 index 037b39e789c..00000000000 --- a/libjava/java/security/DigestOutputStream.java +++ /dev/null @@ -1,158 +0,0 @@ -/* DigestOutputStream.java --- An output stream tied to a message digest - Copyright (C) 1999, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security; - -import java.io.FilterOutputStream; -import java.io.IOException; -import java.io.OutputStream; - -/** - * DigestOutputStream is a class that ties an OutputStream with a - * MessageDigest. The Message Digest is used by the class to update it - * self as bytes are written to the OutputStream. - * - * The updating to the digest depends on the on flag which is set to - * true by default that tells the class to update the data in the - * message digest. - * - * @version 0.0 - * @author Mark Benvenuto (ivymccough@worldnet.att.net) - */ -public class DigestOutputStream extends FilterOutputStream -{ - /** - * The message digest for the DigestOutputStream - */ - protected MessageDigest digest; - - //Manages the on flag - private boolean state = true; - - /** - * Constructs a new DigestOutputStream. It associates a - * MessageDigest with the stream to compute the stream as data is - * written. - * - * @param stream An OutputStream to associate this stream with - * @param digest A MessageDigest to hash the stream with - */ - public DigestOutputStream(OutputStream stream, MessageDigest digest) - { - super(stream); - this.digest = digest; - } - - /** - * Returns the MessageDigest associated with this DigestOutputStream - * - * @return The MessageDigest used to hash this stream - */ - public MessageDigest getMessageDigest() - { - return digest; - } - - /** - * Sets the current MessageDigest to current parameter - * - * @param digest A MessageDigest to associate with this stream - */ - public void setMessageDigest(MessageDigest digest) - { - this.digest = digest; - } - - - /** - * Updates the hash if the on flag is true and then writes a byte to - * the underlying output stream. - * - * @param b A byte to write to the output stream - * - * @exception IOException if the underlying output stream - * cannot write the byte, this is thrown. - */ - public void write(int b) throws IOException - { - if (state) - digest.update((byte) b); - - out.write(b); - } - - /** - * Updates the hash if the on flag is true and then writes the bytes - * to the underlying output stream. - * - * @param b Bytes to write to the output stream - * @param off Offset to start to start at in array - * @param len Length of data to write - * - * @exception IOException if the underlying output stream - * cannot write the bytes, this is thrown. - */ - public void write(byte[]b, int off, int len) throws IOException - { - if (state) - digest.update(b, off, len); - - out.write(b, off, len); - } - - /** - * Sets the flag specifying if this DigestOutputStream updates the - * digest in the write() methods. The default is on; - * - * @param on True means it digests stream, false means it does not - */ - public void on(boolean on) - { - state = on; - } - - /** - * Converts the output stream and underlying message digest to a string. - * - * @return A string representing the output stream and message digest. - */ - public String toString() - { - return "[Digest Output Stream] " + digest.toString(); - } -} diff --git a/libjava/java/security/DomainCombiner.java b/libjava/java/security/DomainCombiner.java deleted file mode 100644 index 9ec680c63af..00000000000 --- a/libjava/java/security/DomainCombiner.java +++ /dev/null @@ -1,67 +0,0 @@ -/* DomainCombiner.java -- Combines ProtectionDomains - Copyright (C) 1999, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security; - -/** - * A public interface used to combine two ProtectionDomains in a new - * ProtectionDomain and update the current Protection Domains - * associated with the current AccessControlContext. - * - * It can add, subtract, or update ProtectionDomains or possibly - * remove duplicates or any possible complex action but just not add - * ones that do not already exist in either array. - * - * @author Mark Benvenuto - * @see AccessControlContext - * @see AccessController - * @since 1.3 - * @status updated to 1.4 - */ -public interface DomainCombiner -{ - /** - * Combines the current ProtectionDomains of the Thread with new - * ProtectionDomains. - * - * @param currentDomains - the ProtectionDomains for the current thread. - * @param assignedDomains - ProtectionsDomains to add - * @return a new array of all the ProtectionDomains - */ - ProtectionDomain[] combine(ProtectionDomain[] currentDomains, - ProtectionDomain[] assignedDomains); -} // interface DomainCombiner diff --git a/libjava/java/security/DummyKeyPairGenerator.java b/libjava/java/security/DummyKeyPairGenerator.java deleted file mode 100644 index da8c362eb71..00000000000 --- a/libjava/java/security/DummyKeyPairGenerator.java +++ /dev/null @@ -1,75 +0,0 @@ -/* DummyKeyPairGenerator.java - Wrapper for KeyPairGeneratorSpi - Copyright (C) 1999, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security; - -import java.security.spec.AlgorithmParameterSpec; - -final class DummyKeyPairGenerator extends KeyPairGenerator -{ - private KeyPairGeneratorSpi kpgSpi = null; - - public DummyKeyPairGenerator(KeyPairGeneratorSpi kpgSpi, String algorithm) - { - super(algorithm); - this.kpgSpi = kpgSpi; - } - - public Object clone() throws CloneNotSupportedException - { - KeyPairGenerator result = new DummyKeyPairGenerator - ((KeyPairGeneratorSpi) kpgSpi.clone(), this.getAlgorithm()); - result.provider = this.getProvider(); - return result; - } - - public void initialize(int keysize, SecureRandom random) - { - kpgSpi.initialize(keysize, random); - } - - public void initialize(AlgorithmParameterSpec params, SecureRandom random) - throws InvalidAlgorithmParameterException - { - kpgSpi.initialize(params, random); - } - - public KeyPair generateKeyPair() - { - return kpgSpi.generateKeyPair(); - } -} diff --git a/libjava/java/security/DummyMessageDigest.java b/libjava/java/security/DummyMessageDigest.java deleted file mode 100644 index 6cecdcf6801..00000000000 --- a/libjava/java/security/DummyMessageDigest.java +++ /dev/null @@ -1,90 +0,0 @@ -/* DummyMessageDigest.java - Wrapper for MessageDigestSpi - Copyright (C) 1999, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security; - -final class DummyMessageDigest extends MessageDigest -{ - private MessageDigestSpi mdSpi = null; - - public DummyMessageDigest(MessageDigestSpi mdSpi, String algorithm) - { - super(algorithm); - this.mdSpi = mdSpi; - } - - public Object clone() throws CloneNotSupportedException - { - MessageDigest result = new DummyMessageDigest - ((MessageDigestSpi) mdSpi.clone(), this.getAlgorithm()); - result.provider = this.getProvider(); - return result; - } - - // java.security.MessageDigestSpi abstract methods implementation --------- - - public byte[] engineDigest() - { - return mdSpi.engineDigest(); - } - - public int engineDigest(byte[] buf, int offset, int len) - throws DigestException - { - return mdSpi.engineDigest(buf, offset, len); - } - - public int engineGetDigestLength() - { - return mdSpi.engineGetDigestLength(); - } - - public void engineReset() - { - mdSpi.engineReset(); - } - - public void engineUpdate(byte input) - { - mdSpi.engineUpdate(input); - } - - public void engineUpdate(byte[] input, int offset, int len) - { - mdSpi.engineUpdate(input, offset, len); - } -} diff --git a/libjava/java/security/DummySignature.java b/libjava/java/security/DummySignature.java deleted file mode 100644 index b74885c9973..00000000000 --- a/libjava/java/security/DummySignature.java +++ /dev/null @@ -1,102 +0,0 @@ -/* DummySignature.java - Signature wrapper for SignatureSpi. - Copyright (C) 1999, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security; - -final class DummySignature extends Signature -{ - private SignatureSpi sigSpi = null; - - public DummySignature(SignatureSpi sigSpi, String algorithm) - { - super(algorithm); - this.sigSpi = sigSpi; - } - - public Object clone() throws CloneNotSupportedException - { - Signature result = new DummySignature - ((SignatureSpi) sigSpi.clone(), this.getAlgorithm()); - result.provider = this.getProvider(); - return result; - } - - protected void engineInitVerify(PublicKey publicKey) - throws InvalidKeyException - { - sigSpi.engineInitVerify(publicKey); - } - - protected void engineInitSign(PrivateKey privateKey) - throws InvalidKeyException - { - sigSpi.engineInitSign(privateKey); - } - - protected void engineUpdate(byte b) throws SignatureException - { - sigSpi.engineUpdate(b); - } - - protected void engineUpdate(byte[]b, int off, int len) - throws SignatureException - { - sigSpi.engineUpdate(b, off, len); - } - - protected byte[] engineSign() throws SignatureException - { - return sigSpi.engineSign(); - } - - protected boolean engineVerify(byte[]sigBytes) throws SignatureException - { - return sigSpi.engineVerify(sigBytes); - } - - protected void engineSetParameter(String param, Object value) - throws InvalidParameterException - { - sigSpi.engineSetParameter(param, value); - } - - protected Object engineGetParameter(String param) - throws InvalidParameterException - { - return sigSpi.engineGetParameter(param); - } -} diff --git a/libjava/java/security/GeneralSecurityException.java b/libjava/java/security/GeneralSecurityException.java deleted file mode 100644 index 72453ee8cbf..00000000000 --- a/libjava/java/security/GeneralSecurityException.java +++ /dev/null @@ -1,75 +0,0 @@ -/* GeneralSecurityException.java -- Common superclass of security exceptions - Copyright (C) 1998, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security; - -/** - * This class is the common superclass of all security exceptions. All - * exceptions in java.security extend this class with the exception (no - * pun intended) of <code>AccessControlException</code> and - * <code>CertificateException</code> (which extend - * <code>SecurityException</code>), <code>ProviderException</code> - * (<code>RuntimeException</code>), and <code>InvalidParamterException</code> - * (<code>IllegalArgumentException</code>). - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @status updated to 1.4 - */ -public class GeneralSecurityException extends Exception -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = 894798122053539237L; - - /** - * Create a new instance with no descriptive error message. - */ - public GeneralSecurityException() - { - } - - /** - * Create a new instance with a descriptive error message. - * - * @param msg the descriptive error message - */ - public GeneralSecurityException(String msg) - { - super(msg); - } -} diff --git a/libjava/java/security/Guard.java b/libjava/java/security/Guard.java deleted file mode 100644 index 4f22360a424..00000000000 --- a/libjava/java/security/Guard.java +++ /dev/null @@ -1,60 +0,0 @@ -/* Guard.java -- Check access to a guarded object - Copyright (C) 1998, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security; - -/** - * This interface specifies a mechanism for querying whether or not - * access is allowed to a guarded object. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @see GuardedObject - * @since 1.1 - * @status updated to 1.4 - */ -public interface Guard -{ - /** - * This method tests whether or not access is allowed to the specified - * guarded object. Access is allowed if this method returns silently. If - * access is denied, an exception is generated. - * - * @param obj the <code>Object</code> to test - * @throws SecurityException if access to the object is denied - */ - void checkGuard(Object obj); -} // interface Guard diff --git a/libjava/java/security/GuardedObject.java b/libjava/java/security/GuardedObject.java deleted file mode 100644 index 5ca08835dc5..00000000000 --- a/libjava/java/security/GuardedObject.java +++ /dev/null @@ -1,121 +0,0 @@ -/* GuardedObject.java -- An object protected by a Guard - Copyright (C) 1998, 2002, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security; - -import java.io.IOException; -import java.io.ObjectOutputStream; -import java.io.Serializable; - -/** - * This class is an object that is guarded by a <code>Guard</code> object. - * The object that is being guarded is retrieved by a call to the only - * method in this class - <code>getObject</code>. That method returns the - * guarded <code>Object</code> after first checking with the - * <code>Guard</code>. If the <code>Guard</code> disallows access, an - * exception will be thrown. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @since 1.1 - * @status updated to 1.4 - */ -public class GuardedObject implements Serializable -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = -5240450096227834308L; - - /** - * This is the Guard that is protecting the object. - * - * @serial the guard - */ - private final Guard guard; - - /** - * This is the object that is being guarded. - * - * @serial the protected object - */ - private final Object object; - - /** - * This method initializes a new instance of <code>GuardedObject</code> - * that protects the specified <code>Object</code> using the specified - * <code>Guard</code>. A null guard means there are no restrictions on - * accessing the object. - * - * @param object the <code>Object</code> to guard - * @param guard the <code>Guard</code> that is protecting the object - */ - public GuardedObject(Object object, Guard guard) - { - this.object = object; - this.guard = guard; - } - - /** - * This method first call the <code>checkGuard</code> method on the - * <code>Guard</code> object protecting the guarded object. If the - * <code>Guard</code> disallows access, an exception is thrown, otherwise - * the <code>Object</code> is returned. - * - * @return The object being guarded - * @throws SecurityException if access is denied - */ - public Object getObject() - { - if (guard != null) - guard.checkGuard(object); - return object; - } - - /** - * Ensures that serialization is legal, by checking the guard. - * - * @param s the stream to write to - * @throws IOException if the underlying stream fails - */ - private void writeObject(ObjectOutputStream s) throws IOException - { - if (guard != null) - guard.checkGuard(object); - s.defaultWriteObject(); - } -} // class GuardedObject diff --git a/libjava/java/security/Identity.java b/libjava/java/security/Identity.java deleted file mode 100644 index 26b01a50a6b..00000000000 --- a/libjava/java/security/Identity.java +++ /dev/null @@ -1,407 +0,0 @@ -/* Identity.java --- Identity Class - Copyright (C) 1999, 2003, Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security; - -import java.io.Serializable; -import java.util.Vector; - -/** - * <p>This class represents identities: real-world objects such as people, - * companies or organizations whose identities can be authenticated using their - * public keys. Identities may also be more abstract (or concrete) constructs, - * such as daemon threads or smart cards.</p> - * - * <p>All Identity objects have a <i>name</i> and a <i>public key</i>. Names - * are immutable. <i>Identities</i> may also be <b>scoped</b>. That is, if an - * <i>Identity</i> is specified to have a particular <i>scope</i>, then the - * <i>name</i> and <i>public key</i> of the <i>Identity</i> are unique within - * that <i>scope</i>.</p> - * - * <p>An <i>Identity</i> also has a <i>set of certificates</i> (all certifying - * its own <i>public key</i>). The <i>Principal</i> names specified in these - * certificates need not be the same, only the key.</p> - * - * <p>An <i>Identity</i> can be subclassed, to include postal and email - * addresses, telephone numbers, images of faces and logos, and so on.</p> - * - * @author Mark Benvenuto - * @see IdentityScope - * @see Signer - * @see Principal - * @deprecated This class is no longer used. Its functionality has been replaced - * by <code>java.security.KeyStore</code>, the <code>java.security.cert</code> - * package, and <code>java.security.Principal</code>. - */ -public abstract class Identity implements Principal, Serializable -{ - private static final long serialVersionUID = 3609922007826600659L; - - private String name; - private IdentityScope scope; - private PublicKey publicKey; - private String info; - private Vector certificates; - - /** Constructor for serialization only. */ - protected Identity() - { - } - - /** - * Constructs an identity with the specified name and scope. - * - * @param name the identity name. - * @param scope the scope of the identity. - * @throws KeyManagementException if there is already an identity with the - * same name in the scope. - */ - public Identity(String name, IdentityScope scope) - throws KeyManagementException - { - this.name = name; - this.scope = scope; - } - - /** - * Constructs an identity with the specified name and no scope. - * - * @param name the identity name. - */ - public Identity(String name) - { - this.name = name; - this.scope = null; - } - - /** - * Returns this identity's name. - * - * @return the name of this identity. - */ - public final String getName() - { - return name; - } - - /** - * Returns this identity's scope. - * - * @return the scope of this identity. - */ - public final IdentityScope getScope() - { - return scope; - } - - /** - * Returns this identity's public key. - * - * @return the public key for this identity. - * @see #setPublicKey(java.security.PublicKey) - */ - public PublicKey getPublicKey() - { - return publicKey; - } - - /** - * <p>Sets this identity's public key. The old key and all of this identity's - * certificates are removed by this operation.</p> - * - * <p>First, if there is a security manager, its <code>checkSecurityAccess() - * </code> method is called with <code>"setIdentityPublicKey"</code> as its - * argument to see if it's ok to set the public key.</p> - * - * @param key the public key for this identity. - * @throws KeyManagementException if another identity in the identity's scope - * has the same public key, or if another exception occurs. - * @throws SecurityException if a security manager exists and its - * <code>checkSecurityAccess()</code> method doesn't allow setting the public - * key. - * @see #getPublicKey() - * @see SecurityManager#checkSecurityAccess(String) - */ - public void setPublicKey(PublicKey key) throws KeyManagementException - { - SecurityManager sm = System.getSecurityManager(); - if (sm != null) - sm.checkSecurityAccess("setIdentityPublicKey"); - - this.publicKey = key; - } - - /** - * <p>Specifies a general information string for this identity.</p> - * - * <p>First, if there is a security manager, its <code>checkSecurityAccess() - * </code> method is called with <code>"setIdentityInfo"</code> as its - * argument to see if it's ok to specify the information string.</p> - * - * @param info the information string. - * @throws SecurityException if a security manager exists and its - * <code>checkSecurityAccess()</code> method doesn't allow setting the - * information string. - * @see #getInfo() - * @see SecurityManager#checkSecurityAccess(String) - */ - public void setInfo(String info) - { - SecurityManager sm = System.getSecurityManager(); - if (sm != null) - sm.checkSecurityAccess("setIdentityInfo"); - - this.info = info; - } - - /** - * Returns general information previously specified for this identity. - * - * @return general information about this identity. - * @see #setInfo(String) - */ - public String getInfo() - { - return info; - } - - /** - * <p>Adds a certificate for this identity. If the identity has a public key, - * the public key in the certificate must be the same, and if the identity - * does not have a public key, the identity's public key is set to be that - * specified in the certificate.</p> - * - * <p>First, if there is a security manager, its <code>checkSecurityAccess() - * </code> method is called with <code>"addIdentityCertificate"</code> as its - * argument to see if it's ok to add a certificate.</p> - * - * @param certificate the certificate to be added. - * @throws KeyManagementException if the certificate is not valid, if the - * public key in the certificate being added conflicts with this identity's - * public key, or if another exception occurs. - * @throws SecurityException if a security manager exists and its - * <code>checkSecurityAccess()</code> method doesn't allow adding a - * certificate. - * @see SecurityManager#checkSecurityAccess(String) - */ - public void addCertificate(Certificate certificate) - throws KeyManagementException - { - SecurityManager sm = System.getSecurityManager(); - if (sm != null) - sm.checkSecurityAccess("addIdentityCertificate"); - - // Check public key of this certificate against the first one in the vector - if (certificates.size() > 0) - { - if (((Certificate) certificates.firstElement()).getPublicKey() != publicKey) - throw new KeyManagementException("Public key does not match"); - } - certificates.addElement(certificate); - } - - /** - * <p>Removes a certificate from this identity.</p> - * - * <p>First, if there is a security manager, its <code>checkSecurityAccess() - * </code> method is called with <code>"removeIdentityCertificate"</code> as - * its argument to see if it's ok to remove a certificate.</p> - * - * @param certificate the certificate to be removed. - * @throws KeyManagementException if the certificate is missing, or if - * another exception occurs. - * @throws SecurityException if a security manager exists and its - * <code>checkSecurityAccess()</code> method doesn't allow removing a - * certificate. - * @see SecurityManager#checkSecurityAccess(String) - */ - public void removeCertificate(Certificate certificate) - throws KeyManagementException - { - SecurityManager sm = System.getSecurityManager(); - if (sm != null) - sm.checkSecurityAccess("removeIdentityCertificate"); - - if (certificates.contains(certificate) == false) - throw new KeyManagementException("Certificate not found"); - - certificates.removeElement(certificate); - } - - /** - * Returns a copy of all the certificates for this identity. - * - * @return a copy of all the certificates for this identity. - */ - public Certificate[] certificates() - { - Certificate[] certs = new Certificate[certificates.size()]; - int max = certificates.size(); - for (int i = 0; i < max; i++) - certs[i] = (Certificate) certificates.elementAt(i); - - return certs; - } - - /** - * Tests for equality between the specified object and this identity. This - * first tests to see if the entities actually refer to the same object, in - * which case it returns <code>true</code>. Next, it checks to see if the - * entities have the same <i>name</i> and the same <i>scope</i>. If they do, - * the method returns <code>true</code>. Otherwise, it calls - * <code>identityEquals()</code>, which subclasses should override. - * - * @param identity the object to test for equality with this identity. - * @return <code>true</code> if the objects are considered equal, <code>false - * </code>otherwise. - * @see #identityEquals(Identity) - */ - public final boolean equals(Object identity) - { - if (identity instanceof Identity) - { - if (identity == this) - return true; - - if ((((Identity) identity).getName() == this.name) && - (((Identity) identity).getScope() == this.scope)) - return true; - - return identityEquals((Identity) identity); - } - return false; - } - - /** - * Tests for equality between the specified <code>identity</code> and this - * <i>identity</i>. This method should be overriden by subclasses to test for - * equality. The default behavior is to return <code>true</code> if the names - * and public keys are equal. - * - * @param identity the identity to test for equality with this identity. - * @return <code>true</code> if the identities are considered equal, - * <code>false</code> otherwise. - * @see #equals(Object) - */ - protected boolean identityEquals(Identity identity) - { - return ((identity.getName() == this.name) && - (identity.getPublicKey() == this.publicKey)); - } - - /** - * <p>Returns a short string describing this identity, telling its name and - * its scope (if any).</p> - * - * <p>First, if there is a security manager, its <code>checkSecurityAccess() - * </code> method is called with <code>"printIdentity"</code> as its argument - * to see if it's ok to return the string.</p> - * - * @return information about this identity, such as its name and the name of - * its scope (if any). - * @throws SecurityException if a security manager exists and its - * <code>checkSecurityAccess()</code> method doesn't allow returning a string - * describing this identity. - * @see SecurityManager#checkSecurityAccess(String) - */ - public String toString() - { - SecurityManager sm = System.getSecurityManager(); - if (sm != null) - sm.checkSecurityAccess("printIdentity"); - - /* TODO: Insert proper format here */ - return (name + ":@" + scope + " Public Key: " + publicKey); - } - - /** - * <p>Returns a string representation of this identity, with optionally more - * details than that provided by the <code>toString()</code> method without - * any arguments.</p> - * - * <p>First, if there is a security manager, its <code>checkSecurityAccess() - * </code> method is called with <code>"printIdentity"</code> as its argument - * to see if it's ok to return the string.</p> - * - * @param detailed whether or not to provide detailed information. - * @return information about this identity. If detailed is <code>true</code>, - * then this method returns more information than that provided by the - * <code>toString()</code> method without any arguments. - * @throws SecurityException if a security manager exists and its - * <code>checkSecurityAccess()</code> method doesn't allow returning a string - * describing this identity. - * @see #toString() - * @see SecurityManager#checkSecurityAccess(String) - */ - public String toString(boolean detailed) - { - SecurityManager sm = System.getSecurityManager(); - if (sm != null) - sm.checkSecurityAccess("printIdentity"); - - if (detailed) - { - /* TODO: Insert proper detailed format here */ - return (name + ":@" + scope + " Public Key: " + publicKey); - } - else - { - /* TODO: Insert proper format here */ - return (name + ":@" + scope + " Public Key: " + publicKey); - } - } - - /** - * Returns a hashcode for this identity. - * - * @return a hashcode for this identity. - */ - public int hashCode() - { - int ret = name.hashCode(); - if (publicKey != null) - ret |= publicKey.hashCode(); - if (scope != null) - ret |= scope.hashCode(); - if (info != null) - ret |= info.hashCode(); - if (certificates != null) - ret |= certificates.hashCode(); - - return ret; - } -} diff --git a/libjava/java/security/IdentityScope.java b/libjava/java/security/IdentityScope.java deleted file mode 100644 index 34dd011e280..00000000000 --- a/libjava/java/security/IdentityScope.java +++ /dev/null @@ -1,226 +0,0 @@ -/* IdentityScope.java --- IdentityScope Class - Copyright (C) 1999, 2003, Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security; - -import java.util.Enumeration; - -/** - * <p>This class represents a scope for identities. It is an Identity itself, - * and therefore has a name and can have a scope. It can also optionally have a - * public key and associated certificates.</p> - * - * <p>An <code>IdentityScope</code> can contain {@link Identity} objects of all - * kinds, including {@link Signer}s. All types of <code>Identity</code> objects - * can be retrieved, added, and removed using the same methods. Note that it is - * possible, and in fact expected, that different types of identity scopes will - * apply different policies for their various operations on the various types of - * Identities.</p> - * - * <p>There is a one-to-one mapping between keys and identities, and there can - * only be one copy of one key per scope. For example, suppose Acme Software, - * Inc is a software publisher known to a user. Suppose it is an <i>Identity</i>, - * that is, it has a public key, and a set of associated certificates. It is - * named in the scope using the name "Acme Software". No other named <i>Identity - * </i> in the scope has the same public key. Of course, none has the same name - * as well.</p> - * - * @author Mark Benvenuto - * @see Identity - * @see Signer - * @see Principal - * @see Key - * @deprecated This class is no longer used. Its functionality has been replaced - * by <code>java.security.KeyStore</code>, the <code>java.security.cert</code> - * package, and <code>java.security.Principal</code>. - */ -public abstract class IdentityScope extends Identity -{ - private static final long serialVersionUID = -2337346281189773310L; - private static IdentityScope systemScope; - - /** - * This constructor is used for serialization only and should not be used by - * subclasses. - */ - protected IdentityScope() - { - super(); - } - - /** - * Constructs a new identity scope with the specified name. - * - * @param name the scope name. - */ - public IdentityScope(String name) - { - super(name); - } - - /** - * Constructs a new identity scope with the specified name and scope. - * - * @param name the scope name. - * @param scope the scope for the new identity scope. - * @throws KeyManagementException if there is already an identity with the - * same name in the scope. - */ - public IdentityScope(String name, IdentityScope scope) - throws KeyManagementException - { - super(name, scope); - } - - /** - * Returns the system's identity scope. - * - * @return the system's identity scope. - * @see #setSystemScope(IdentityScope) - */ - public static IdentityScope getSystemScope() - { - if (systemScope == null) - { - //Load it - //systemScope; - } - return systemScope; - } - - /** - * Sets the system's identity scope. - * - * <p>First, if there is a security manager, its <code>checkSecurityAccess() - * </code> method is called with <code>"setSystemScope"</code> as its argument - * to see if it's ok to set the identity scope.</p> - * - * @param scope the scope to set. - * @throws SecurityException if a security manager exists and its - * <code>checkSecurityAccess()</code> method doesn't allow setting the - * identity scope. - * @see #getSystemScope() - * @see SecurityManager#checkSecurityAccess(String) - */ - protected static void setSystemScope(IdentityScope scope) - { - SecurityManager sm = System.getSecurityManager(); - if (sm != null) - sm.checkSecurityAccess("setSystemScope"); - - systemScope = scope; - } - - /** - * Returns the number of identities within this identity scope. - * - * @return the number of identities within this identity scope. - */ - public abstract int size(); - - /** - * Returns the identity in this scope with the specified name (if any). - * - * @param name the name of the identity to be retrieved. - * @return the identity named name, or <code>null</code> if there are no - * identities named name in this scope. - */ - public abstract Identity getIdentity(String name); - - /** - * Retrieves the identity whose name is the same as that of the specified - * principal. (Note: <code>Identity</code> implements <code>Principal</code>.) - * - * @param principal the principal corresponding to the identity to be - * retrieved. - * @return the identity whose name is the same as that of the principal, or - * <code>null</code> if there are no identities of the same name in this scope. - */ - public Identity getIdentity(Principal principal) - { - return getIdentity(principal.getName()); - } - - /** - * Retrieves the identity with the specified public key. - * - * @param key the public key for the identity to be returned. - * @return the identity with the given key, or <code>null</code> if there are - * no identities in this scope with that key. - */ - public abstract Identity getIdentity(PublicKey key); - - /** - * Adds an identity to this identity scope. - * - * @param identity the identity to be added. - * @throws KeyManagementException if the identity is not valid, a name - * conflict occurs, another identity has the same public key as the identity - * being added, or another exception occurs. - */ - public abstract void addIdentity(Identity identity) - throws KeyManagementException; - - /** - * Removes an identity from this identity scope. - * - * @param identity the identity to be removed. - * @throws KeyManagementException if the identity is missing, or another - * exception occurs. - */ - public abstract void removeIdentity(Identity identity) - throws KeyManagementException; - - /** - * Returns an enumeration of all identities in this identity scope. - * - * @return an enumeration of all identities in this identity scope. - */ - public abstract Enumeration identities(); - - /** - * Returns a string representation of this identity scope, including its name, - * its scope name, and the number of identities in this identity scope. - * - * @return a string representation of this identity scope. - * @see SecurityManager#checkSecurityAccess(String) - */ - public String toString() - { - return (super.getName() + " " + super.getScope().getName() + " " + size()); - } -} diff --git a/libjava/java/security/InvalidAlgorithmParameterException.java b/libjava/java/security/InvalidAlgorithmParameterException.java deleted file mode 100644 index 9b726199521..00000000000 --- a/libjava/java/security/InvalidAlgorithmParameterException.java +++ /dev/null @@ -1,73 +0,0 @@ -/* InvalidAlgorithmParameterException.java -- an invalid parameter to a - security algorithm - Copyright (C) 2000, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security; - -/** - * Thrown for an invalid security algorithm parameter. - * - * @author Warren Levy (warrenl@cygnus.com) - * @since 1.2 - * @status updated to 1.4 - */ -public class InvalidAlgorithmParameterException - extends GeneralSecurityException -{ - /** - * Compatible with JDK 1.2+. - */ - private static final long serialVersionUID = 2864672297499471472L; - - /** - * Construct an exception with no message. - */ - public InvalidAlgorithmParameterException() - { - super(); - } - - /** - * Construct an exception with a message. - * - * @param msg the message - */ - public InvalidAlgorithmParameterException(String msg) - { - super(msg); - } -} diff --git a/libjava/java/security/InvalidKeyException.java b/libjava/java/security/InvalidKeyException.java deleted file mode 100644 index cd5845a6181..00000000000 --- a/libjava/java/security/InvalidKeyException.java +++ /dev/null @@ -1,69 +0,0 @@ -/* InvalidKeyException -- thrown for an invalid key - Copyright (C) 2000, 2002 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security; - -/** - * Thrown for an invalid key. - * - * @author Warren Levy (warrenl@cygnus.com) - * @status updated to 1.4 - */ -public class InvalidKeyException extends KeyException -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = 5698479920593359816L; - - /** - * Construct an exception with no message. - */ - public InvalidKeyException() - { - } - - /** - * Construct an exception with a message. - * - * @param msg the message - */ - public InvalidKeyException(String msg) - { - super(msg); - } -} diff --git a/libjava/java/security/InvalidParameterException.java b/libjava/java/security/InvalidParameterException.java deleted file mode 100644 index c5218a04917..00000000000 --- a/libjava/java/security/InvalidParameterException.java +++ /dev/null @@ -1,70 +0,0 @@ -/* InvalidParameterException.java -- an invalid parameter in the JCA/JCE engine - Copyright (C) 2000, 2002 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security; - -/** - * Thrown when an invalid parameter is passed to a method of the JCA/JCE - * engine classes. - * - * @author Warren Levy (warrenl@cygnus.com) - * @status updated to 1.4 - */ -public class InvalidParameterException extends IllegalArgumentException -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = -857968536935667808L; - - /** - * Construct an exception with no message. - */ - public InvalidParameterException() - { - } - - /** - * Construct an exception with a message. - * - * @param msg the message - */ - public InvalidParameterException(String msg) - { - super(msg); - } -} diff --git a/libjava/java/security/Key.java b/libjava/java/security/Key.java deleted file mode 100644 index 23652b6e7c4..00000000000 --- a/libjava/java/security/Key.java +++ /dev/null @@ -1,94 +0,0 @@ -/* Key.java -- A abstract representation of a digital key - Copyright (C) 1998, 2000, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security; - -import java.io.Serializable; - -/** - * This interfaces models the base characteristics that all keys must - * have. These are: a key algorithm, an encoded form, and a format used - * to encode the key. Specific key types inherit from this interface. - * Note that since this interface extends <code>Serializable</code>, all - * keys may be serialized. Keys are generally obtained through key generators, - * including {@link KeyFactory}. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @see PublicKey - * @see PrivateKey - * @see KeyPair - * @see KeyPairGenerator - * @see KeyFactory - * @see KeySpec - * @see Identity - * @see Signer - * @since 1.1 - * @status updated to 1.4 - */ -public interface Key extends Serializable -{ - /** - * The version identifier used for serialization. - */ - long serialVersionUID = 6603384152749567654L; - - /** - * This method returns the name of the algorithm for this key. This is a - * <code>String</code> such as "RSA". - * - * @return the name of the algorithm in use - */ - String getAlgorithm(); - - /** - * This method returns the name of the encoding format for this key. This - * is the name of the ASN.1 data format used for this key, such as - * "X.509" or "PKCS#8". This method returns <code>null</code> if this key - * does not have an encoding format. - * - * @return the name of the encoding format for this key, or null - */ - String getFormat(); - - /** - * This method returns the encoded form of the key. If this key does not - * support encoding, this method returns <code>null</code>. - * - * @return the encoded form of the key, or null - */ - byte[] getEncoded(); -} // interface Key diff --git a/libjava/java/security/KeyException.java b/libjava/java/security/KeyException.java deleted file mode 100644 index feaf0249a95..00000000000 --- a/libjava/java/security/KeyException.java +++ /dev/null @@ -1,72 +0,0 @@ -/* KeyException.java -- Thrown when there is a problem with a key - Copyright (C) 1998, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security; - -/** - * This exception is thrown when there is a problem with a key. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @see Key - * @status updated to 1.4 - */ -public class KeyException extends GeneralSecurityException -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = -7483676942812432108L; - - /** - * This method initializes a new instance of <code>KeyException</code> - * with no descriptive message. - */ - public KeyException() - { - } - - /** - * This method initializes a new instance of <code>KeyException</code> - * with a descriptive message. - * - * @param msg the descriptive message - */ - public KeyException(String msg) - { - super(msg); - } -} diff --git a/libjava/java/security/KeyFactory.java b/libjava/java/security/KeyFactory.java deleted file mode 100644 index 64ce841fae8..00000000000 --- a/libjava/java/security/KeyFactory.java +++ /dev/null @@ -1,297 +0,0 @@ -/* KeyFactory.java --- Key Factory Class - Copyright (C) 1999, 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security; - -import gnu.java.security.Engine; - -import java.security.spec.InvalidKeySpecException; -import java.security.spec.KeySpec; - -/** - * <p>Key factories are used to convert keys (opaque cryptographic keys of type - * {@link Key}) into key specifications (transparent representations of the - * underlying key material), and vice versa.</p> - * - * <p>Key factories are bi-directional. That is, they allow you to build an - * opaque key object from a given key specification (key material), or to - * retrieve the underlying key material of a key object in a suitable format.</p> - * - * <p>Multiple compatible key specifications may exist for the same key. For - * example, a <i>DSA</i> public key may be specified using {@link - * java.security.spec.DSAPublicKeySpec} or {@link - * java.security.spec.X509EncodedKeySpec}. A key factory can be used to - * translate between compatible key specifications.</p> - * - * <p>The following is an example of how to use a key factory in order to - * instantiate a <i>DSA</i> public key from its encoding. Assume Alice has - * received a digital signature from Bob. Bob also sent her his public key (in - * encoded format) to verify his signature. Alice then performs the following - * actions: - * - * <pre> - * X509EncodedKeySpec bobPubKeySpec = new X509EncodedKeySpec(bobEncodedPubKey); - * KeyFactory keyFactory = KeyFactory.getInstance("DSA"); - * PublicKey bobPubKey = keyFactory.generatePublic(bobPubKeySpec); - * Signature sig = Signature.getInstance("DSA"); - * sig.initVerify(bobPubKey); - * sig.update(data); - * sig.verify(signature); - * </pre> - * - * @since 1.2 - * @see Key - * @see PublicKey - * @see PrivateKey - * @see KeySpec - * @see java.security.spec.DSAPublicKeySpec - * @see java.security.spec.X509EncodedKeySpec - @author Mark Benvenuto - */ -public class KeyFactory -{ - /** The service name for key factories. */ - private static final String KEY_FACTORY = "KeyFactory"; - - private KeyFactorySpi keyFacSpi; - private Provider provider; - private String algorithm; - - /** - * Creates a <code>KeyFactory</code> object. - * - * @param keyFacSpi the delegate. - * @param provider the provider. - * @param algorithm the name of the algorithm to associate with this - * <code>KeyFactory</code>. - */ - protected KeyFactory(KeyFactorySpi keyFacSpi, Provider provider, - String algorithm) - { - this.keyFacSpi = keyFacSpi; - this.provider = provider; - this.algorithm = algorithm; - } - - /** - * Generates a <code>KeyFactory</code> object that implements the specified - * algorithm. If the default provider package provides an implementation of - * the requested algorithm, an instance of <code>KeyFactory</code> containing - * that implementation is returned. If the algorithm is not available in the - * default package, other packages are searched. - * - * @param algorithm the name of the requested key algorithm. See Appendix A - * in the Java Cryptography Architecture API Specification & Reference - * for information about standard algorithm names. - * @return a <code>KeyFactory</code> object for the specified algorithm. - * @throws NoSuchAlgorithmException if the requested algorithm is not - * available in the default provider package or any of the other provider - * packages that were searched. - */ - public static KeyFactory getInstance(String algorithm) - throws NoSuchAlgorithmException - { - Provider[] p = Security.getProviders(); - for (int i = 0; i < p.length; i++) - try - { - return getInstance(algorithm, p[i]); - } - catch (NoSuchAlgorithmException e) - { - // Ignore. - } - - throw new NoSuchAlgorithmException(algorithm); - } - - /** - * Generates a <code>KeyFactory</code> object for the specified algorithm - * from the specified provider. - * - * @param algorithm the name of the requested key algorithm. See Appendix A - * in the Java Cryptography Architecture API Specification & Reference - * for information about standard algorithm names. - * @param provider the name of the provider. - * @return a <code>KeyFactory</code> object for the specified algorithm. - * @throws NoSuchAlgorithmException if the algorithm is not available from - * the specified provider. - * @throws NoSuchProviderException if the provider has not been configured. - * @throws IllegalArgumentException if the provider name is null or empty. - * @see Provider - */ - public static KeyFactory getInstance(String algorithm, String provider) - throws NoSuchAlgorithmException, NoSuchProviderException - { - if (provider == null || provider.length() == 0) - throw new IllegalArgumentException("Illegal provider"); - - Provider p = Security.getProvider(provider); - if (p == null) - throw new NoSuchProviderException(provider); - - return getInstance(algorithm, p); - } - - /** - * Generates a <code>KeyFactory</code> object for the specified algorithm from - * the specified provider. Note: the <code>provider</code> doesn't have to be - * registered. - * - * @param algorithm the name of the requested key algorithm. See Appendix A - * in the Java Cryptography Architecture API Specification & Reference for - * information about standard algorithm names. - * @param provider the provider. - * @return a <code>KeyFactory</code> object for the specified algorithm. - * @throws NoSuchAlgorithmException if the algorithm is not available from - * the specified provider. - * @throws IllegalArgumentException if the <code>provider</code> is - * <code>null</code>. - * @since 1.4 - * @see Provider - */ - public static KeyFactory getInstance(String algorithm, Provider provider) - throws NoSuchAlgorithmException - { - if (provider == null) - throw new IllegalArgumentException("Illegal provider"); - - try - { - return new KeyFactory((KeyFactorySpi) - Engine.getInstance(KEY_FACTORY, algorithm, provider), - provider, algorithm); - } - catch (java.lang.reflect.InvocationTargetException ite) - { - throw new NoSuchAlgorithmException(algorithm); - } - catch (ClassCastException cce) - { - throw new NoSuchAlgorithmException(algorithm); - } - } - - /** - * Returns the provider of this key factory object. - * - * @return the provider of this key factory object. - */ - public final Provider getProvider() - { - return provider; - } - - /** - * Gets the name of the algorithm associated with this <code>KeyFactory</code>. - * - * @return the name of the algorithm associated with this - * <code>KeyFactory</code>. - */ - public final String getAlgorithm() - { - return algorithm; - } - - /** - * Generates a public key object from the provided key specification (key - * material). - * - * @param keySpec the specification (key material) of the public key. - * @return the public key. - * @throws InvalidKeySpecException if the given key specification is - * inappropriate for this key factory to produce a public key. - */ - public final PublicKey generatePublic(KeySpec keySpec) - throws InvalidKeySpecException - { - return keyFacSpi.engineGeneratePublic(keySpec); - } - - /** - * Generates a private key object from the provided key specification (key - * material). - * - * @param keySpec the specification (key material) of the private key. - * @return the private key. - * @throws InvalidKeySpecException if the given key specification is - * inappropriate for this key factory to produce a private key. - */ - public final PrivateKey generatePrivate(KeySpec keySpec) - throws InvalidKeySpecException - { - return keyFacSpi.engineGeneratePrivate(keySpec); - } - - /** - * Returns a specification (key material) of the given key object. - * <code>keySpec</code> identifies the specification class in which the key - * material should be returned. It could, for example, be - * <code>DSAPublicKeySpec.class</code>, to indicate that the key material - * should be returned in an instance of the {@link - * java.security.spec.DSAPublicKeySpec} class. - * - * @param key the key. - * @param keySpec the specification class in which the key material should be - * returned. - * @return the underlying key specification (key material) in an instance of - * the requested specification class. - * @throws InvalidKeySpecException if the requested key specification is - * inappropriate for the given key, or the given key cannot be processed - * (e.g., the given key has an unrecognized algorithm or format). - */ - public final KeySpec getKeySpec(Key key, Class keySpec) - throws InvalidKeySpecException - { - return keyFacSpi.engineGetKeySpec(key, keySpec); - } - - /** - * Translates a key object, whose provider may be unknown or potentially - * untrusted, into a corresponding key object of this key factory. - * - * @param key the key whose provider is unknown or untrusted. - * @return the translated key. - * @throws InvalidKeyException if the given key cannot be processed by this - * key factory. - */ - public final Key translateKey(Key key) throws InvalidKeyException - { - return keyFacSpi.engineTranslateKey(key); - } -} diff --git a/libjava/java/security/KeyFactorySpi.java b/libjava/java/security/KeyFactorySpi.java deleted file mode 100644 index 1894fad08df..00000000000 --- a/libjava/java/security/KeyFactorySpi.java +++ /dev/null @@ -1,133 +0,0 @@ -/* KeyFactorySpi.java --- Key Factory Service Provider Interface - Copyright (C) 1999, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security; - -import java.security.spec.InvalidKeySpecException; -import java.security.spec.KeySpec; - -/** - * KeyFactorySpi is the Service Provider Interface (SPI) for the - * KeyFactory class. This is the interface for providers to - * supply to implement a key factory for an algorithm. - * - * Key factories are used to convert keys (opaque cryptographic - * keys of type Key) into key specifications (transparent - * representations of the underlying key material). - * - * Key factories are bi-directional. They allow a key class - * to be converted into a key specification (key material) and - * back again. - * - * For example DSA public keys can be specified as - * DSAPublicKeySpec or X509EncodedKeySpec. The key factory - * translate these key specifications. - * - * @since JDK 1.2 - * @author Mark Benvenuto - */ -public abstract class KeyFactorySpi -{ - /** - * Constucts a new KeyFactorySpi. - */ - public KeyFactorySpi() - { - } - - /** - * Generates a public key from the provided key specification. - * - * @param keySpec key specification - * - * @return the public key - * - * @throws InvalidKeySpecException invalid key specification for - * this key factory to produce a public key - */ - protected abstract PublicKey engineGeneratePublic(KeySpec keySpec) - throws InvalidKeySpecException; - - - /** - * Generates a private key from the provided key specification. - * - * @param keySpec key specification - * - * @return the private key - * - * @throws InvalidKeySpecException invalid key specification for - * this key factory to produce a private key - */ - protected abstract PrivateKey engineGeneratePrivate(KeySpec keySpec) - throws InvalidKeySpecException; - - /** - * Returns a key specification for the given key. keySpec - * identifies the specification class to return the key - * material in. - * - * @param key the key - * @param keySpec the specification class to return the - * key material in. - * - * @return the key specification in an instance of the requested - * specification class - * - * @throws InvalidKeySpecException the requested key specification - * is inappropriate for this key or the key is - * unrecognized. - */ - protected abstract KeySpec engineGetKeySpec(Key key, Class keySpec) - throws InvalidKeySpecException; - - - /** - * Translates the key from an unknown or untrusted provider - * into a key for this key factory. - * - * @param the key from an unknown or untrusted provider - * - * @return the translated key - * - * @throws InvalidKeySpecException if the key cannot be - * processed by this key factory - */ - protected abstract Key engineTranslateKey(Key key) - throws InvalidKeyException; -} diff --git a/libjava/java/security/KeyManagementException.java b/libjava/java/security/KeyManagementException.java deleted file mode 100644 index 694b4c242b6..00000000000 --- a/libjava/java/security/KeyManagementException.java +++ /dev/null @@ -1,71 +0,0 @@ -/* KeyManagementException.java -- an exception in key management - Copyright (C) 1998, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security; - -/** - * This exception is thrown whenever a problem related to the management of - * security keys is encountered. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @see Key - * @status updated to 1.4 - */ -public class KeyManagementException extends KeyException -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = 947674216157062695L; - - /** - * Create a new instance with no descriptive error message. - */ - public KeyManagementException() - { - } - - /** - * Create a new instance with a descriptive error message. - * - * @param msg the descriptive error message - */ - public KeyManagementException(String msg) - { - super(msg); - } -} diff --git a/libjava/java/security/KeyPair.java b/libjava/java/security/KeyPair.java deleted file mode 100644 index bf1a40a23ab..00000000000 --- a/libjava/java/security/KeyPair.java +++ /dev/null @@ -1,87 +0,0 @@ -/* KeyPair.java --- Key Pair Class - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security; -import java.io.Serializable; - -/** - KeyPair serves as a simple container for public and private keys. - If properly initialized, this class should be treated like the - private key since it contains it and take approriate security - measures. - - @author Mark Benvenuto - */ -public final class KeyPair implements Serializable -{ - private static final long serialVersionUID = -7565189502268009837L; - - private PublicKey publicKey; - private PrivateKey privateKey; - - /** - Initializes the KeyPair with a pubilc and private key. - - @param publicKey Public Key to store - @param privateKey Private Key to store - */ - public KeyPair(PublicKey publicKey, PrivateKey privateKey) - { - this.publicKey = publicKey; - this.privateKey = privateKey; - } - - /** - Returns the public key stored in the KeyPair - - @return The public key - */ - public PublicKey getPublic() - { - return publicKey; - } - - /** - Returns the private key stored in the KeyPair - - @return The private key - */ - public PrivateKey getPrivate() - { - return privateKey; - } -} diff --git a/libjava/java/security/KeyPairGenerator.java b/libjava/java/security/KeyPairGenerator.java deleted file mode 100644 index e6f926e2bf0..00000000000 --- a/libjava/java/security/KeyPairGenerator.java +++ /dev/null @@ -1,401 +0,0 @@ -/* KeyPairGenerator.java --- Key Pair Generator Class - Copyright (C) 1999, 2002, 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security; - -import gnu.java.security.Engine; - -import java.security.spec.AlgorithmParameterSpec; - -/** - * <p>The <code>KeyPairGenerator</code> class is used to generate pairs of - * public and private keys. Key pair generators are constructed using the - * <code>getInstance()</code> factory methods (static methods that return - * instances of a given class).</p> - * - * <p>A Key pair generator for a particular algorithm creates a public/private - * key pair that can be used with this algorithm. It also associates - * algorithm-specific parameters with each of the generated keys.</p> - * - * <p>There are two ways to generate a key pair: in an algorithm-independent - * manner, and in an algorithm-specific manner. The only difference between the - * two is the initialization of the object:</p> - * - * <ul> - * <li><b>Algorithm-Independent Initialization</b><br/> - * All key pair generators share the concepts of a <i>keysize</i> and a - * <i>source of randomness</i>. The <i>keysize</i> is interpreted differently - * for different algorithms (e.g., in the case of the <i>DSA</i> algorithm, - * the <i>keysize</i> corresponds to the length of the modulus). There is an - * <code>initialize()</code> method in this <code>KeyPairGenerator</code> - * class that takes these two universally shared types of arguments. There - * is also one that takes just a <i>keysize</i> argument, and uses the - * {@link SecureRandom} implementation of the highest-priority installed - * provider as the <i>source of randomness</i>. (If none of the installed - * providers supply an implementation of {@link SecureRandom}, a - * system-provided source of randomness is used.) - * - * <p>Since no other parameters are specified when you call the above - * algorithm-independent initialize methods, it is up to the provider what - * to do about the algorithm-specific parameters (if any) to be associated - * with each of the keys.</p> - * - * <p>If the algorithm is the <i>DSA</i> algorithm, and the <i>keysize</i> - * (modulus size) is <code>512</code>, <code>768</code>, or <code>1024</code>, - * then the <b>GNU</b> provider uses a set of precomputed values for the - * <code>p</code>, <code>q</code>, and <code>g</code> parameters. If the - * <i>modulus size</i> is not one of the above values, the <b>GNU</b> - * provider creates a new set of parameters. Other providers might have - * precomputed parameter sets for more than just the three modulus sizes - * mentioned above. Still others might not have a list of precomputed - * parameters at all and instead always create new parameter sets.</p></li> - * <li><b>Algorithm-Specific Initialization</b><br/> - * For situations where a set of algorithm-specific parameters already - * exists (e.g., so-called <i>community parameters</i> in <i>DSA</i>), there - * are two initialize methods that have an {@link AlgorithmParameterSpec} - * argument. One also has a {@link SecureRandom} argument, while the the - * other uses the {@link SecureRandom} implementation of the highest-priority - * installed provider as the source of randomness. (If none of the installed - * providers supply an implementation of {@link SecureRandom}, a - * system-provided source of randomness is used.)</li> - * </ul> - * - * <p>In case the client does not explicitly initialize the - * <code>KeyPairGenerator</code> (via a call to an initialize method), each - * provider must supply (and document) a default initialization. For example, - * the <b>GNU</b> provider uses a default modulus size (keysize) of - * <code>1024</code> bits.</p> - * - * <p>Note that this class is abstract and extends from {@link - * KeyPairGeneratorSpi} for historical reasons. Application developers should - * only take notice of the methods defined in this <code>KeyPairGenerator</code> - * class; all the methods in the superclass are intended for cryptographic - * service providers who wish to supply their own implementations of key pair - * generators.</p> - * - * @see Signature - * @see KeyPair - * @see AlgorithmParameterSpec - * @author Mark Benvenuto - * @author Casey Marshall - */ -public abstract class KeyPairGenerator extends KeyPairGeneratorSpi -{ - /** The service name for key pair generators. */ - private static final String KEY_PAIR_GENERATOR = "KeyPairGenerator"; - - Provider provider; - private String algorithm; - - /** - * Creates a <code>KeyPairGenerator</code> object for the specified - * algorithm. - * - * @param algorithm the standard string name of the algorithm. - * See Appendix A in the Java Cryptography Architecture API - * Specification & Reference for information about standard - * algorithm names. - */ - protected KeyPairGenerator(String algorithm) - { - this.algorithm = algorithm; - this.provider = null; - } - - /** - * Returns the standard name of the algorithm for this key pair generator. - * See Appendix A in the Java Cryptography Architecture API Specification - * & Reference for information about standard algorithm names. - * - * @return the standard string name of the algorithm. - */ - public String getAlgorithm() - { - return algorithm; - } - - /** - * Generates a <code>KeyPairGenerator</code> object that implements the - * specified digest algorithm. If the default provider package provides an - * implementation of the requested digest algorithm, an instance of - * <code>KeyPairGenerator</code> containing that implementation is returned. - * If the algorithm is not available in the default package, other packages - * are searched. - * - * @param algorithm the standard string name of the algorithm. See Appendix A - * in the Java Cryptography Architecture API Specification & Reference for - * information about standard algorithm names. - * @return the new <code>KeyPairGenerator</code> object. - * @throws NoSuchAlgorithmException if the algorithm is not available in the - * environment. - */ - public static KeyPairGenerator getInstance(String algorithm) - throws NoSuchAlgorithmException - { - Provider[] p = Security.getProviders(); - for (int i = 0; i < p.length; i++) - { - try - { - return getInstance(algorithm, p[i]); - } - catch (NoSuchAlgorithmException e) - { - // Ignored. - } - } - - throw new NoSuchAlgorithmException(algorithm); - } - - /** - * Generates a <code>KeyPairGenerator</code> object implementing the - * specified algorithm, as supplied from the specified provider, if - * such an algorithm is available from the provider. - * - * @param algorithm the standard string name of the algorithm. See - * Appendix A in the Java Cryptography Architecture API Specification - * & Reference for information about standard algorithm names. - * @param provider the string name of the provider. - * @return the new <code>KeyPairGenerator</code> object. - * @throws NoSuchAlgorithmException if the algorithm is not available - * from the provider. - * @throws NoSuchProviderException if the provider is not available in the - * environment. - * @throws IllegalArgumentException if the provider name is <code>null</code> - * or empty. - * @see Provider - */ - public static KeyPairGenerator getInstance(String algorithm, String provider) - throws NoSuchAlgorithmException, NoSuchProviderException - { - Provider p = Security.getProvider(provider); - if (p == null) - throw new NoSuchProviderException(provider); - - return getInstance(algorithm, p); - } - - /** - * Generates a <code>KeyPairGenerator</code> object implementing the specified - * algorithm, as supplied from the specified provider, if such an algorithm is - * available from the provider. Note: the provider doesn't have to be - * registered. - * - * @param algorithm the standard string name of the algorithm. See Appendix A - * in the Java Cryptography Architecture API Specification & Reference for - * information about standard algorithm names. - * @param provider the provider. - * @return the new <code>KeyPairGenerator</code> object. - * @throws NoSuchAlgorithmException if the <code>algorithm</code> is not - * available from the <code>provider</code>. - * @throws IllegalArgumentException if the <code>provider</code> is - * <code>null</code>. - * @since 1.4 - * @see Provider - */ - public static KeyPairGenerator getInstance(String algorithm, - Provider provider) - throws NoSuchAlgorithmException - { - if (provider == null) - throw new IllegalArgumentException("Illegal provider"); - - Object o = null; - try - { - o = Engine.getInstance(KEY_PAIR_GENERATOR, algorithm, provider); - } - catch (java.lang.reflect.InvocationTargetException ite) - { - throw new NoSuchAlgorithmException(algorithm); - } - - KeyPairGenerator result = null; - if (o instanceof KeyPairGeneratorSpi) - { - result = new DummyKeyPairGenerator((KeyPairGeneratorSpi) o, algorithm); - } - else if (o instanceof KeyPairGenerator) - { - result = (KeyPairGenerator) o; - result.algorithm = algorithm; - } - result.provider = provider; - return result; - } - - /** - * Returns the provider of this key pair generator object. - * - * @return the provider of this key pair generator object. - */ - public final Provider getProvider() - { - return provider; - } - - /** - * Initializes the key pair generator for a certain keysize using a default - * parameter set and the {@link SecureRandom} implementation of the - * highest-priority installed provider as the source of randomness. (If none - * of the installed providers supply an implementation of {@link SecureRandom}, - * a system-provided source of randomness is used.) - * - * @param keysize the keysize. This is an algorithm-specific metric, such as - * modulus length, specified in number of bits. - * @throws InvalidParameterException if the keysize is not supported by this - * <code>KeyPairGenerator</code> object. - */ - public void initialize(int keysize) - { - initialize(keysize, new SecureRandom()); - } - - /** - * Initializes the key pair generator for a certain keysize with the given - * source of randomness (and a default parameter set). - * - * @param keysize the keysize. This is an algorithm-specific metric, such as - * modulus length, specified in number of bits. - * @param random the source of randomness. - * @throws InvalidParameterException if the <code>keysize</code> is not - * supported by this <code>KeyPairGenerator</code> object. - * @since 1.2 - */ - public void initialize(int keysize, SecureRandom random) - { - initialize(keysize, random); - } - - /** - * <p>Initializes the key pair generator using the specified parameter set and - * the {@link SecureRandom} implementation of the highest-priority installed - * provider as the source of randomness. (If none of the installed providers - * supply an implementation of {@link SecureRandom}, a system-provided source - * of randomness is used.)</p> - * - * <p>This concrete method has been added to this previously-defined abstract - * class. This method calls the - * {@link KeyPairGeneratorSpi#initialize(AlgorithmParameterSpec, SecureRandom)} - * initialize method, passing it <code>params</code> and a source of - * randomness (obtained from the highest-priority installed provider or - * system-provided if none of the installed providers supply one). That - * initialize method always throws an {@link UnsupportedOperationException} - * if it is not overridden by the provider.</p> - * - * @param params the parameter set used to generate the keys. - * @throws InvalidAlgorithmParameterException if the given parameters are - * inappropriate for this key pair generator. - * @since 1.2 - */ - public void initialize(AlgorithmParameterSpec params) - throws InvalidAlgorithmParameterException - { - initialize(params, new SecureRandom()); - } - - /** - * <p>Initializes the key pair generator with the given parameter set and - * source of randomness.</p> - * - * <p>This concrete method has been added to this previously-defined abstract - * class. This method calls the - * {@link KeyPairGeneratorSpi#initialize(AlgorithmParameterSpec, SecureRandom)} - * initialize method, passing it <code>params</code> and <code>random</code>. - * That initialize method always throws an {@link UnsupportedOperationException} - * if it is not overridden by the provider.</p> - * - * @param params the parameter set used to generate the keys. - * @param random the source of randomness. - * @throws InvalidAlgorithmParameterException if the given parameters are - * inappropriate for this key pair generator. - * @since 1.2 - */ - public void initialize(AlgorithmParameterSpec params, SecureRandom random) - throws InvalidAlgorithmParameterException - { - super.initialize(params, random); - } - - /** - * <p>Generates a key pair.</p> - * - * <p>If this <code>KeyPairGenerator</code> has not been initialized - * explicitly, provider-specific defaults will be used for the size and other - * (algorithm-specific) values of the generated keys.</p> - * - * <p>This will generate a new key pair every time it is called.</p> - * - * <p>This method is functionally equivalent to {@link #generateKeyPair()}.</p> - * - * @return the generated key pair. - * @since 1.2 - */ - public final KeyPair genKeyPair() - { - try - { - return getInstance("DSA", "GNU").generateKeyPair(); - } - catch (Exception e) - { - System.err.println("genKeyPair failed: " + e); - e.printStackTrace(); - return null; - } - } - - /** - * <p>Generates a key pair.</p> - * - * <p>If this <code>KeyPairGenerator</code> has not been initialized - * explicitly, provider-specific defaults will be used for the size and other - * (algorithm-specific) values of the generated keys.</p> - * - * <p>This will generate a new key pair every time it is called.</p> - * - * <p>This method is functionally equivalent to {@link #genKeyPair()}.</p> - * - * @return the generated key pair. - */ - public KeyPair generateKeyPair() - { - return genKeyPair(); - } -} diff --git a/libjava/java/security/KeyPairGeneratorSpi.java b/libjava/java/security/KeyPairGeneratorSpi.java deleted file mode 100644 index 689fbec128e..00000000000 --- a/libjava/java/security/KeyPairGeneratorSpi.java +++ /dev/null @@ -1,102 +0,0 @@ -/* KeyPairGeneratorSpi.java --- Key Pair Generator SPI Class - Copyright (C) 1999, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security; -import java.security.spec.AlgorithmParameterSpec; - -/** - KeyPairGeneratorSpi is the interface used to generate key pairs - for security algorithms. - - @author Mark Benvenuto - */ -public abstract class KeyPairGeneratorSpi -{ - /** - Constructs a new KeyPairGeneratorSpi - */ - public KeyPairGeneratorSpi() - { - } - - /** - Initialize the KeyPairGeneratorSpi with the specified - key size and source of randomness - - @param keysize size of the key to generate - @param random A SecureRandom source of randomness - */ - public abstract void initialize(int keysize, SecureRandom random); - - /** - Initialize the KeyPairGeneratorSpi with the specified - AlgorithmParameterSpec and source of randomness - - This is a concrete method. It may be overridden by the provider - and if the AlgorithmParameterSpec class is invalid - throw InvalidAlgorithmParameterException. By default this - method just throws UnsupportedOperationException. - - @param params A AlgorithmParameterSpec to intialize with - @param random A SecureRandom source of randomness - - @throws InvalidAlgorithmParameterException - */ - public void initialize(AlgorithmParameterSpec params, SecureRandom random) - throws InvalidAlgorithmParameterException - { - throw new java.lang.UnsupportedOperationException(); - } - - /** - Generates a KeyPair according the rules for the algorithm. - Unless intialized, algorithm defaults will be used. It - creates a unique key pair each time. - - @return a key pair - */ - public abstract KeyPair generateKeyPair(); - - /** - * We override clone here to make it accessible for use by - * DummyKeyPairGenerator. - */ - protected Object clone() throws CloneNotSupportedException - { - return super.clone(); - } -} diff --git a/libjava/java/security/KeyStore.java b/libjava/java/security/KeyStore.java deleted file mode 100644 index 696448728ff..00000000000 --- a/libjava/java/security/KeyStore.java +++ /dev/null @@ -1,507 +0,0 @@ -/* KeyStore.java --- Key Store Class - Copyright (C) 1999, 2002, 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security; - -import gnu.java.security.Engine; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.security.cert.CertificateException; -import java.util.Date; -import java.util.Enumeration; - -/** - * Keystore represents an in-memory collection of keys and - * certificates. There are two types of entries: - * - * <dl> - * <dt>Key Entry</dt> - * - * <dd><p>This type of keystore entry store sensitive crytographic key - * information in a protected format.Typically this is a secret - * key or a private key with a certificate chain.</p></dd> - * - * <dt>Trusted Ceritificate Entry</dt> - * - * <dd><p>This type of keystore entry contains a single public key - * certificate belonging to annother entity. It is called trusted - * because the keystore owner trusts that the certificates - * belongs to the subject (owner) of the certificate.</p></dd> - * </dl> - * - * <p>Entries in a key store are referred to by their "alias": a simple - * unique string. - * - * <p>The structure and persistentence of the key store is not - * specified. Any method could be used to protect sensitive - * (private or secret) keys. Smart cards or integrated - * cryptographic engines could be used or the keystore could - * be simply stored in a file.</p> - * - * @see java.security.cert.Certificate - * @see Key - */ -public class KeyStore -{ - - // Constants and fields. - // ------------------------------------------------------------------------ - - /** Service name for key stores. */ - private static final String KEY_STORE = "KeyStore"; - - private KeyStoreSpi keyStoreSpi; - private Provider provider; - private String type; - - // Constructors. - // ------------------------------------------------------------------------ - - /** - Creates an instance of KeyStore - - @param keyStoreSpi A KeyStore engine to use - @param provider A provider to use - @param type The type of KeyStore - */ - protected KeyStore(KeyStoreSpi keyStoreSpi, Provider provider, String type) - { - this.keyStoreSpi = keyStoreSpi; - this.provider = provider; - this.type = type; - } - - // Class methods. - // ------------------------------------------------------------------------ - - /** - * Gets an instance of the KeyStore class representing - * the specified keystore. If the type is not - * found then, it throws KeyStoreException. - * - * @param type the type of keystore to choose - * @return a KeyStore repesenting the desired type - * @throws KeyStoreException if the type of keystore is not implemented - * by providers or the implementation cannot be instantiated. - */ - public static KeyStore getInstance(String type) throws KeyStoreException - { - Provider[] p = Security.getProviders(); - - for (int i = 0; i < p.length; i++) - { - try - { - return getInstance(type, p[i]); - } - catch (KeyStoreException e) - { - // Ignore. - } - } - - throw new KeyStoreException(type); - } - - /** - * Gets an instance of the KeyStore class representing - * the specified key store from the specified provider. - * If the type is not found then, it throws KeyStoreException. - * If the provider is not found, then it throws - * NoSuchProviderException. - * - * @param type the type of keystore to choose - * @param provider the provider name - * @return a KeyStore repesenting the desired type - * @throws KeyStoreException if the type of keystore is not - * implemented by the given provider - * @throws NoSuchProviderException if the provider is not found - * @throws IllegalArgumentException if the provider string is - * null or empty - */ - public static KeyStore getInstance(String type, String provider) - throws KeyStoreException, NoSuchProviderException - { - if (provider == null || provider.length() == 0) - throw new IllegalArgumentException("Illegal provider"); - - Provider p = Security.getProvider(provider); - if (p == null) - throw new NoSuchProviderException(provider); - - return getInstance(type, p); - } - - /** - * Gets an instance of the KeyStore class representing - * the specified key store from the specified provider. - * If the type is not found then, it throws KeyStoreException. - * If the provider is not found, then it throws - * NoSuchProviderException. - * - * @param type the type of keystore to choose - * @param provider the keystore provider - * @return a KeyStore repesenting the desired type - * @throws KeyStoreException if the type of keystore is not - * implemented by the given provider - * @throws IllegalArgumentException if the provider object is null - * @since 1.4 - */ - public static KeyStore getInstance(String type, Provider provider) - throws KeyStoreException - { - if (provider == null) - throw new IllegalArgumentException("Illegal provider"); - try - { - return new KeyStore( - (KeyStoreSpi) Engine.getInstance(KEY_STORE, type, provider), - provider, type); - } - catch (NoSuchAlgorithmException nsae) - { - throw new KeyStoreException(type); - } - catch (java.lang.reflect.InvocationTargetException ite) - { - throw new KeyStoreException(type); - } - catch (ClassCastException cce) - { - throw new KeyStoreException(type); - } - } - - /** - * Returns the default KeyStore type. This method looks up the - * type in <JAVA_HOME>/lib/security/java.security with the - * property "keystore.type" or if that fails then "jks" . - */ - public static final String getDefaultType() - { - // Security reads every property in java.security so it - // will return this property if it exists. - String tmp = Security.getProperty("keystore.type"); - - if (tmp == null) - tmp = "jks"; - - return tmp; - } - - // Instance methods. - // ------------------------------------------------------------------------ - - /** - Gets the provider that the class is from. - - @return the provider of this class - */ - public final Provider getProvider() - { - return provider; - } - - /** - Returns the type of the KeyStore supported - - @return A string with the type of KeyStore - */ - public final String getType() - { - return type; - } - - /** - Returns the key associated with given alias using the - supplied password. - - @param alias an alias for the key to get - @param password password to access key with - - @return the requested key, or null otherwise - - @throws NoSuchAlgorithmException if there is no algorithm - for recovering the key - @throws UnrecoverableKeyException key cannot be reocovered - (wrong password). - */ - public final Key getKey(String alias, char[]password) - throws KeyStoreException, NoSuchAlgorithmException, - UnrecoverableKeyException - { - return keyStoreSpi.engineGetKey(alias, password); - } - - /** - Gets a Certificate chain for the specified alias. - - @param alias the alias name - - @return a chain of Certificates ( ordered from the user's - certificate to the Certificate Authority's ) or - null if the alias does not exist or there is no - certificate chain for the alias ( the alias refers - to a trusted certificate entry or there is no entry). - */ - public final java.security.cert. - Certificate[] getCertificateChain(String alias) throws KeyStoreException - { - return keyStoreSpi.engineGetCertificateChain(alias); - } - - /** - Gets a Certificate for the specified alias. - - If there is a trusted certificate entry then that is returned. - it there is a key entry with a certificate chain then the - first certificate is return or else null. - - @param alias the alias name - - @return a Certificate or null if the alias does not exist - or there is no certificate for the alias - */ - public final java.security.cert.Certificate getCertificate(String alias) - throws KeyStoreException - { - return keyStoreSpi.engineGetCertificate(alias); - } - - /** - Gets entry creation date for the specified alias. - - @param alias the alias name - - @returns the entry creation date or null - */ - public final Date getCreationDate(String alias) throws KeyStoreException - { - return keyStoreSpi.engineGetCreationDate(alias); - } - - /** - Assign the key to the alias in the keystore, protecting it - with the given password. It will overwrite an existing - entry and if the key is a PrivateKey, also add the - certificate chain representing the corresponding public key. - - @param alias the alias name - @param key the key to add - @password the password to protect with - @param chain the certificate chain for the corresponding - public key - - @throws KeyStoreException if it fails - */ - public final void setKeyEntry(String alias, Key key, char[]password, - java.security.cert. - Certificate[]chain) throws KeyStoreException - { - keyStoreSpi.engineSetKeyEntry(alias, key, password, chain); - } - - /** - Assign the key to the alias in the keystore. It will overwrite - an existing entry and if the key is a PrivateKey, also - add the certificate chain representing the corresponding - public key. - - @param alias the alias name - @param key the key to add - @param chain the certificate chain for the corresponding - public key - - @throws KeyStoreException if it fails - */ - public final void setKeyEntry(String alias, byte[]key, - java.security.cert. - Certificate[]chain) throws KeyStoreException - { - keyStoreSpi.engineSetKeyEntry(alias, key, chain); - } - - /** - Assign the certificate to the alias in the keystore. It - will overwrite an existing entry. - - @param alias the alias name - @param cert the certificate to add - - @throws KeyStoreException if it fails - */ - public final void setCertificateEntry(String alias, - java.security.cert. - Certificate cert) throws - KeyStoreException - { - keyStoreSpi.engineSetCertificateEntry(alias, cert); - } - - /** - Deletes the entry for the specified entry. - - @param alias the alias name - - @throws KeyStoreException if it fails - */ - public final void deleteEntry(String alias) throws KeyStoreException - { - keyStoreSpi.engineDeleteEntry(alias); - } - - /** - Generates a list of all the aliases in the keystore. - - @return an Enumeration of the aliases - */ - public final Enumeration aliases() throws KeyStoreException - { - return keyStoreSpi.engineAliases(); - } - - /** - Determines if the keystore contains the specified alias. - - @param alias the alias name - - @return true if it contains the alias, false otherwise - */ - public final boolean containsAlias(String alias) throws KeyStoreException - { - return keyStoreSpi.engineContainsAlias(alias); - } - - /** - Returns the number of entries in the keystore. - - @returns the number of keystore entries. - */ - public final int size() throws KeyStoreException - { - return keyStoreSpi.engineSize(); - } - - /** - Determines if the keystore contains a key entry for - the specified alias. - - @param alias the alias name - - @return true if it is a key entry, false otherwise - */ - public final boolean isKeyEntry(String alias) throws KeyStoreException - { - return keyStoreSpi.engineIsKeyEntry(alias); - } - - - /** - Determines if the keystore contains a certificate entry for - the specified alias. - - @param alias the alias name - - @return true if it is a certificate entry, false otherwise - */ - public final boolean isCertificateEntry(String alias) - throws KeyStoreException - { - return keyStoreSpi.engineIsCertificateEntry(alias); - } - - /** - Determines if the keystore contains the specified certificate - entry and returns the alias. - - It checks every entry and for a key entry checks only the - first certificate in the chain. - - @param cert Certificate to look for - - @return alias of first matching certificate, null if it - does not exist. - */ - public final String getCertificateAlias(java.security.cert.Certificate cert) - throws KeyStoreException - { - return keyStoreSpi.engineGetCertificateAlias(cert); - } - - /** - Stores the keystore in the specified output stream and it - uses the specified key it keep it secure. - - @param stream the output stream to save the keystore to - @param password the password to protect the keystore integrity with - - @throws IOException if an I/O error occurs. - @throws NoSuchAlgorithmException the data integrity algorithm - used cannot be found. - @throws CertificateException if any certificates could not be - stored in the output stream. - */ - public final void store(OutputStream stream, char[]password) - throws KeyStoreException, IOException, NoSuchAlgorithmException, - CertificateException - { - keyStoreSpi.engineStore(stream, password); - } - - /** - Loads the keystore from the specified input stream and it - uses the specified password to check for integrity if supplied. - - @param stream the input stream to load the keystore from - @param password the password to check the keystore integrity with - - @throws IOException if an I/O error occurs. - @throws NoSuchAlgorithmException the data integrity algorithm - used cannot be found. - @throws CertificateException if any certificates could not be - stored in the output stream. - */ - public final void load(InputStream stream, char[]password) - throws IOException, NoSuchAlgorithmException, CertificateException - { - keyStoreSpi.engineLoad(stream, password); - } - -} diff --git a/libjava/java/security/KeyStoreException.java b/libjava/java/security/KeyStoreException.java deleted file mode 100644 index 9a0a5354d2c..00000000000 --- a/libjava/java/security/KeyStoreException.java +++ /dev/null @@ -1,70 +0,0 @@ -/* KeyStoreException.java -- Indicates a problem with the key store - Copyright (C) 1998, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security; - -/** - * Indicates a problem with the key store. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @since 1.2 - * @status updated to 1.4 - */ -public class KeyStoreException extends GeneralSecurityException -{ - /** - * Compatible with JDK 1.2+. - */ - private static final long serialVersionUID = -1119353179322377262L; - - /** - * Create a new instance detailed error message. - */ - public KeyStoreException() - { - } - - /** - * Create a new instance with a detailed error message. - * - * @param msg the descriptive error message - */ - public KeyStoreException(String msg) - { - super(msg); - } -} diff --git a/libjava/java/security/KeyStoreSpi.java b/libjava/java/security/KeyStoreSpi.java deleted file mode 100644 index a16008f9960..00000000000 --- a/libjava/java/security/KeyStoreSpi.java +++ /dev/null @@ -1,275 +0,0 @@ -/* KeyStoreSpi.java --- Key Store Service Provider Interface - Copyright (C) 1999, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.security.cert.CertificateException; -import java.util.Date; -import java.util.Enumeration; - -/** - * KeyStoreSpi is the Service Provider Interface (SPI) for the - * KeyStore class. This is the interface for providers to - * supply to implement a keystore for a particular keystore - * type. - * - * @since 1.2 - * @author Mark Benvenuto - */ -public abstract class KeyStoreSpi -{ - /** - * Constructs a new KeyStoreSpi - */ - public KeyStoreSpi() - { - } - - /** - * Returns the key associated with given alias using the - * supplied password. - * - * @param alias an alias for the key to get - * @param password password to access key with - * - * @return the requested key, or null otherwise - * - * @throws NoSuchAlgorithmException if there is no algorithm - * for recovering the key - * @throws UnrecoverableKeyException key cannot be reocovered - * (wrong password). - */ - public abstract Key engineGetKey(String alias, char[]password) - throws NoSuchAlgorithmException, UnrecoverableKeyException; - - /** - * Gets a Certificate chain for the specified alias. - * - * @param alias the alias name - * - * @return a chain of Certificates ( ordered from the user's - * certificate to the Certificate Authority's ) or - * null if the alias does not exist or there is no - * certificate chain for the alias ( the alias refers - * to a trusted certificate entry or there is no entry). - */ - public abstract java.security.cert. - Certificate[] engineGetCertificateChain(String alias); - - - /** - * Gets a Certificate for the specified alias. - * - * If there is a trusted certificate entry then that is returned. - * it there is a key entry with a certificate chain then the - * first certificate is return or else null. - * - * @param alias the alias name - * - * @return a Certificate or null if the alias does not exist - * or there is no certificate for the alias - */ - public abstract java.security.cert. - Certificate engineGetCertificate(String alias); - - /** - * Gets entry creation date for the specified alias. - * - * @param alias the alias name - * - * @returns the entry creation date or null - */ - public abstract Date engineGetCreationDate(String alias); - - /** - * Assign the key to the alias in the keystore, protecting it - * with the given password. It will overwrite an existing - * entry and if the key is a PrivateKey, also add the - * certificate chain representing the corresponding public key. - * - * @param alias the alias name - * @param key the key to add - * @password the password to protect with - * @param chain the certificate chain for the corresponding - * public key - * - * @throws KeyStoreException if it fails - */ - public abstract void engineSetKeyEntry(String alias, Key key, - char[]password, - java.security.cert. - Certificate[]chain) throws - KeyStoreException; - - /** - * Assign the key to the alias in the keystore. It will overwrite - * an existing entry and if the key is a PrivateKey, also - * add the certificate chain representing the corresponding - * public key. - * - * @param alias the alias name - * @param key the key to add - * @param chain the certificate chain for the corresponding - * public key - * - * @throws KeyStoreException if it fails - */ - public abstract void engineSetKeyEntry(String alias, byte[]key, - java.security.cert. - Certificate[]chain) throws - KeyStoreException; - - - /** - * Assign the certificate to the alias in the keystore. It - * will overwrite an existing entry. - * - * @param alias the alias name - * @param cert the certificate to add - * - * @throws KeyStoreException if it fails - */ - public abstract void engineSetCertificateEntry(String alias, - java.security.cert. - Certificate cert) throws - KeyStoreException; - - /** - * Deletes the entry for the specified entry. - * - * @param alias the alias name - * - * @throws KeyStoreException if it fails - */ - public abstract void engineDeleteEntry(String alias) - throws KeyStoreException; - - /** - * Generates a list of all the aliases in the keystore. - * - * @return an Enumeration of the aliases - */ - public abstract Enumeration engineAliases(); - - /** - * Determines if the keystore contains the specified alias. - * - * @param alias the alias name - * - * @return true if it contains the alias, false otherwise - */ - public abstract boolean engineContainsAlias(String alias); - - /** - * Returns the number of entries in the keystore. - * - * @returns the number of keystore entries. - */ - public abstract int engineSize(); - - /** - * Determines if the keystore contains a key entry for - * the specified alias. - * - * @param alias the alias name - * - * @return true if it is a key entry, false otherwise - */ - public abstract boolean engineIsKeyEntry(String alias); - - /** - * Determines if the keystore contains a certificate entry for - * the specified alias. - * - * @param alias the alias name - * - * @return true if it is a certificate entry, false otherwise - */ - public abstract boolean engineIsCertificateEntry(String alias); - - /** - * Determines if the keystore contains the specified certificate - * entry and returns the alias. - * - * It checks every entry and for a key entry checks only the - * first certificate in the chain. - * - * @param cert Certificate to look for - * - * @return alias of first matching certificate, null if it - * does not exist. - */ - public abstract String engineGetCertificateAlias(java.security.cert. - Certificate cert); - - /** - * Stores the keystore in the specified output stream and it - * uses the specified key it keep it secure. - * - * @param stream the output stream to save the keystore to - * @param password the password to protect the keystore integrity with - * - * @throws IOException if an I/O error occurs. - * @throws NoSuchAlgorithmException the data integrity algorithm - * used cannot be found. - * @throws CertificateException if any certificates could not be - * stored in the output stream. - */ - public abstract void engineStore(OutputStream stream, char[]password) - throws IOException, NoSuchAlgorithmException, CertificateException; - - - /** - * Loads the keystore from the specified input stream and it - * uses the specified password to check for integrity if supplied. - * - * @param stream the input stream to load the keystore from - * @param password the password to check the keystore integrity with - * - * @throws IOException if an I/O error occurs. - * @throws NoSuchAlgorithmException the data integrity algorithm - * used cannot be found. - * @throws CertificateException if any certificates could not be - * stored in the output stream. - */ - public abstract void engineLoad(InputStream stream, char[]password) - throws IOException, NoSuchAlgorithmException, CertificateException; -} diff --git a/libjava/java/security/MessageDigest.java b/libjava/java/security/MessageDigest.java deleted file mode 100644 index 8684f2083b1..00000000000 --- a/libjava/java/security/MessageDigest.java +++ /dev/null @@ -1,413 +0,0 @@ -/* MessageDigest.java --- The message digest interface. - Copyright (C) 1999, 2002, 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security; - -import gnu.java.security.Engine; - -/** - * <p>This <code>MessageDigest</code> class provides applications the - * functionality of a message digest algorithm, such as <i>MD5</i> or <i>SHA</i>. - * Message digests are secure one-way hash functions that take arbitrary-sized - * data and output a fixed-length hash value.</p> - * - * <p>A <code>MessageDigest</code> object starts out initialized. The data is - * processed through it using the <code>update()</code> methods. At any point - * <code>reset()</code> can be called to reset the digest. Once all the data to - * be updated has been updated, one of the <code>digest()</code> methods should - * be called to complete the hash computation.</p> - * - * <p>The <code>digest()</code> method can be called <b>once</b> for a given - * number of updates. After <code>digest()</code> has been called, the - * <code>MessageDigest</code> object is <b>reset</b> to its initialized state. - * </p> - * - * <p>Implementations are free to implement the {@link Cloneable} interface. - * Client applications can test cloneability by attempting cloning and catching - * the {@link CloneNotSupportedException}: - * - * <pre> - * MessageDigest md = MessageDigest.getInstance("SHA"); - * try - * { - * md.update(toChapter1); - * MessageDigest tc1 = md.clone(); - * byte[] toChapter1Digest = tc1.digest(); - * md.update(toChapter2); - * // ... - * } - * catch (CloneNotSupportedException x) - * { - * throw new DigestException("couldn't make digest of partial content"); - * } - * </pre> - * - * <p>Note that if a given implementation is not cloneable, it is still possible - * to compute intermediate digests by instantiating several instances, if the - * number of digests is known in advance.</p> - * - * <p>Note that this class is abstract and extends from {@link MessageDigestSpi} - * for historical reasons. Application developers should only take notice of the - * methods defined in this <code>MessageDigest</code> class; all the methods in - * the superclass are intended for cryptographic service providers who wish to - * supply their own implementations of message digest algorithms.</p> - * - * @see MessageDigestSpi - * @see Provider - * @since JDK 1.1 - */ -public abstract class MessageDigest extends MessageDigestSpi -{ - /** The service name for message digests. */ - private static final String MESSAGE_DIGEST = "MessageDigest"; - - private String algorithm; - Provider provider; - private byte[] lastDigest; - - /** - * Creates a message digest with the specified algorithm name. - * - * @param algorithm the standard name of the digest algorithm. - * See Appendix A in the Java Cryptography Architecture API - * Specification & Reference for information about standard - * algorithm names. - */ - protected MessageDigest(String algorithm) - { - this.algorithm = algorithm; - provider = null; - } - - /** - * Generates a <code>MessageDigest</code> object that implements the specified - * digest algorithm. If the default provider package provides an - * implementation of the requested digest algorithm, an instance of - * <code>MessageDigest</code> containing that implementation is returned. If - * the algorithm is not available in the default package, other packages are - * searched. - * - * @param algorithm the name of the algorithm requested. See Appendix A in the - * Java Cryptography Architecture API Specification & Reference for - * information about standard algorithm names. - * @return a Message Digest object implementing the specified algorithm. - * @throws NoSuchAlgorithmException if the algorithm is not available in the - * caller's environment. - */ - public static MessageDigest getInstance(String algorithm) - throws NoSuchAlgorithmException - { - Provider[] p = Security.getProviders(); - for (int i = 0; i < p.length; i++) - { - try - { - return getInstance(algorithm, p[i]); - } - catch (NoSuchAlgorithmException ignored) - { - // Ignore. - } - } - - throw new NoSuchAlgorithmException(algorithm); - } - - /** - * Generates a <code>MessageDigest</code> object implementing the specified - * algorithm, as supplied from the specified provider, if such an algorithm is - * available from the provider. - * - * @param algorithm the name of the algorithm requested. See Appendix A in the - * Java Cryptography Architecture API Specification & Reference for - * information about standard algorithm names. - * @param provider the name of the provider. - * @return a Message Digest object implementing the specified algorithm. - * @throws NoSuchAlgorithmException if the algorithm is not available in the - * package supplied by the requested provider. - * @throws NoSuchProviderException if the provider is not available in the - * environment. - * @throws IllegalArgumentException if the provider name is null or empty. - * @see Provider - */ - public static MessageDigest getInstance(String algorithm, String provider) - throws NoSuchAlgorithmException, NoSuchProviderException - { - if (provider == null || provider.length() == 0) - throw new IllegalArgumentException("Illegal provider"); - - Provider p = Security.getProvider(provider); - if (p == null) - throw new NoSuchProviderException(provider); - - return getInstance(algorithm, p); - } - - /** - * Generates a <code>MessageDigest</code> object implementing the specified - * algorithm, as supplied from the specified provider, if such an algorithm - * is available from the provider. Note: the provider doesn't have to be - * registered. - * - * @param algorithm the name of the algorithm requested. See Appendix A in - * the Java Cryptography Architecture API Specification & Reference for - * information about standard algorithm names. - * @param provider the provider. - * @return a Message Digest object implementing the specified algorithm. - * @throws NoSuchAlgorithmException if the <code>algorithm</code> is not - * available in the package supplied by the requested <code>provider</code>. - * @throws IllegalArgumentException if the <code>provider</code> is - * <code>null</code>. - * @since 1.4 - * @see Provider - */ - public static MessageDigest getInstance(String algorithm, Provider provider) - throws NoSuchAlgorithmException - { - if (provider == null) - throw new IllegalArgumentException("Illegal provider"); - - MessageDigest result = null; - Object o = null; - try - { - o = Engine.getInstance(MESSAGE_DIGEST, algorithm, provider); - } - catch (java.lang.reflect.InvocationTargetException ite) - { - throw new NoSuchAlgorithmException(algorithm); - } - - if (o instanceof MessageDigestSpi) - { - result = new DummyMessageDigest((MessageDigestSpi) o, algorithm); - } - else if (o instanceof MessageDigest) - { - result = (MessageDigest) o; - result.algorithm = algorithm; - } - else - { - throw new NoSuchAlgorithmException(algorithm); - } - result.provider = provider; - return result; - } - - /** - * Returns the provider of this message digest object. - * - * @return the provider of this message digest object. - */ - public final Provider getProvider() - { - return provider; - } - - /** - * Updates the digest using the specified byte. - * - * @param input the byte with which to update the digest. - */ - public void update(byte input) - { - engineUpdate(input); - } - - /** - * Updates the digest using the specified array of bytes, starting at the - * specified offset. - * - * @param input the array of bytes. - * @param offset the offset to start from in the array of bytes. - * @param len the number of bytes to use, starting at offset. - */ - public void update(byte[] input, int offset, int len) - { - engineUpdate(input, offset, len); - } - - /** - * Updates the digest using the specified array of bytes. - * - * @param input the array of bytes. - */ - public void update(byte[] input) - { - engineUpdate(input, 0, input.length); - } - - /** - * Completes the hash computation by performing final operations such as - * padding. The digest is reset after this call is made. - * - * @return the array of bytes for the resulting hash value. - */ - public byte[] digest() - { - return lastDigest = engineDigest(); - } - - /** - * Completes the hash computation by performing final operations such as - * padding. The digest is reset after this call is made. - * - * @param buf An output buffer for the computed digest. - * @param offset The offset into the output buffer to begin storing the digest. - * @param len The number of bytes within buf allotted for the digest. - * @return The number of bytes placed into buf. - * @throws DigestException if an error occurs. - */ - public int digest(byte[] buf, int offset, int len) throws DigestException - { - return engineDigest(buf, offset, len); - } - - /** - * Performs a final update on the digest using the specified array of bytes, - * then completes the digest computation. That is, this method first calls - * <code>update(input)</code>, passing the input array to the <code>update() - * </code> method, then calls <code>digest()</code>. - * - * @param input the input to be updated before the digest is completed. - * @return the array of bytes for the resulting hash value. - */ - public byte[] digest(byte[] input) - { - update(input); - return digest(); - } - - /** - * Returns a string representation of this message digest object. - * - * @return a string representation of the object. - */ - public String toString() - { - return (getClass()).getName() + " Message Digest <" + digestToString() + ">"; - } - - /** - * Compares two digests for equality. Does a simple byte compare. - * - * @param digesta one of the digests to compare. - * @param digestb the other digest to compare. - * @return <code>true</code> if the digests are equal, <code>false</code> - * otherwise. - */ - public static boolean isEqual(byte[] digesta, byte[] digestb) - { - if (digesta.length != digestb.length) - return false; - - for (int i = digesta.length - 1; i >= 0; --i) - if (digesta[i] != digestb[i]) - return false; - - return true; - } - - /** Resets the digest for further use. */ - public void reset() - { - engineReset(); - } - - /** - * Returns a string that identifies the algorithm, independent of - * implementation details. The name should be a standard Java Security name - * (such as <code>"SHA"</code>, <code>"MD5"</code>, and so on). See Appendix - * A in the Java Cryptography Architecture API Specification & Reference - * for information about standard algorithm names. - * - * @return the name of the algorithm. - */ - public final String getAlgorithm() - { - return algorithm; - } - - /** - * Returns the length of the digest in bytes, or <code>0</code> if this - * operation is not supported by the provider and the implementation is not - * cloneable. - * - * @return the digest length in bytes, or <code>0</code> if this operation is - * not supported by the provider and the implementation is not cloneable. - * @since 1.2 - */ - public final int getDigestLength() - { - return engineGetDigestLength(); - } - - /** - * Returns a clone if the implementation is cloneable. - * - * @return a clone if the implementation is cloneable. - * @throws CloneNotSupportedException if this is called on an implementation - * that does not support {@link Cloneable}. - */ - public Object clone() throws CloneNotSupportedException - { - return super.clone(); - } - - private String digestToString() - { - byte[] digest = lastDigest; - - if (digest == null) - return "incomplete"; - - StringBuffer buf = new StringBuffer(); - int len = digest.length; - for (int i = 0; i < len; ++i) - { - byte b = digest[i]; - byte high = (byte) ((b & 0xff) >>> 4); - byte low = (byte) (b & 0xf); - - buf.append(high > 9 ? ('a' - 10) + high : '0' + high); - buf.append(low > 9 ? ('a' - 10) + low : '0' + low); - } - - return buf.toString(); - } -} diff --git a/libjava/java/security/MessageDigestSpi.java b/libjava/java/security/MessageDigestSpi.java deleted file mode 100644 index df3bd3ead02..00000000000 --- a/libjava/java/security/MessageDigestSpi.java +++ /dev/null @@ -1,155 +0,0 @@ -/* MessageDigestSpi.java --- The message digest service provider interface. - Copyright (C) 1999, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security; - -/** - This is the Service Provider Interface (SPI) for MessageDigest - class in java.security. It provides the back end functionality - for the MessageDigest class so that it can compute message - hashes. The default hashes are SHA-1 and MD5. A message hash - takes data of arbitrary length and produces a unique number - representing it. - - Cryptography service providers who want to implement their - own message digest hashes need only to subclass this class. - - The implementation of a Cloneable interface is left to up to - the programmer of a subclass. - - @version 0.0 - - @author Mark Benvenuto (ivymccough@worldnet.att.net) - */ -public abstract class MessageDigestSpi -{ - /** - Default constructor of the MessageDigestSpi class - */ - public MessageDigestSpi() - { - } - - /** - Returns the length of the digest. It may be overridden by the - provider to return the length of the digest. Default is to - return 0. It is concrete for backwards compatibility with JDK1.1 - message digest classes. - - @return Length of Digest in Bytes - - @since 1.2 - */ - protected int engineGetDigestLength() - { - return 0; - } - - /** - Updates the digest with the specified byte. - - @param input the byte to update digest with - */ - protected abstract void engineUpdate(byte input); - - - /** - Updates the digest with the specified bytes starting with the - offset and proceeding for the specified length. - - @param input the byte array to update digest with - @param offset the offset of the byte to start with - @param len the number of the bytes to update with - */ - protected abstract void engineUpdate(byte[]input, int offset, int len); - - /** - Computes the final digest of the stored bytes and returns - them. It performs any necessary padding. The message digest - should reset sensitive data after performing the digest. - - @return An array of bytes containing the digest - */ - protected abstract byte[] engineDigest(); - - /** - Computes the final digest of the stored bytes and returns - them. It performs any necessary padding. The message digest - should reset sensitive data after performing the digest. This - method is left concrete for backwards compatibility with JDK1.1 - message digest classes. - - @param buf An array of bytes to store the digest - @param offset An offset to start storing the digest at - @param len The length of the buffer - @return Returns the length of the buffer - - @since 1.2 - */ - protected int engineDigest(byte[]buf, int offset, int len) - throws DigestException - { - if (engineGetDigestLength() > len) - throw new DigestException("Buffer is too small."); - - byte[] tmp = engineDigest(); - if (tmp.length > len) - throw new DigestException("Buffer is too small"); - - System.arraycopy(tmp, 0, buf, offset, tmp.length); - return tmp.length; - } - - /** - Resets the digest engine. Reinitializes internal variables - and clears sensitive data. - */ - protected abstract void engineReset(); - - /** - Returns a clone of this class. - - If cloning is not supported, then by default the class throws a - CloneNotSupportedException. The MessageDigestSpi provider - implementation has to overload this class in order to be - cloneable. - */ - public Object clone() throws CloneNotSupportedException - { - return super.clone(); - } -} diff --git a/libjava/java/security/NoSuchAlgorithmException.java b/libjava/java/security/NoSuchAlgorithmException.java deleted file mode 100644 index 412d14a16d7..00000000000 --- a/libjava/java/security/NoSuchAlgorithmException.java +++ /dev/null @@ -1,70 +0,0 @@ -/* NoSuchAlgorithmException.java -- an algorithm was not available - Copyright (C) 1998, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security; - -/** - * This exception is thrown when the requested security algorithm is - * not available - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @status updated to 1.4 - */ -public class NoSuchAlgorithmException extends GeneralSecurityException -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = -7443947487218346562L; - - /** - * Create a new instance with no descriptive error message. - */ - public NoSuchAlgorithmException() - { - } - - /** - * Create a new instance with a descriptive error message. - * - * @param msg the descriptive error message - */ - public NoSuchAlgorithmException(String msg) - { - super(msg); - } -} diff --git a/libjava/java/security/NoSuchProviderException.java b/libjava/java/security/NoSuchProviderException.java deleted file mode 100644 index bd26df5ef07..00000000000 --- a/libjava/java/security/NoSuchProviderException.java +++ /dev/null @@ -1,70 +0,0 @@ -/* NoSuchProviderException.java -- thrown when a provider is not found - Copyright (C) 1998, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security; - -/** - * This exception is thrown when the requested security provider is - * not available. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @status updated to 1.4 - */ -public class NoSuchProviderException extends GeneralSecurityException -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = 8488111756688534474L; - - /** - * Create a new instance with no descriptive error message. - */ - public NoSuchProviderException() - { - } - - /** - * Create a new instance with a descriptive error message. - * - * @param msg the descriptive error message - */ - public NoSuchProviderException(String msg) - { - super(msg); - } -} diff --git a/libjava/java/security/Permission.java b/libjava/java/security/Permission.java deleted file mode 100644 index 48f4d52a18c..00000000000 --- a/libjava/java/security/Permission.java +++ /dev/null @@ -1,187 +0,0 @@ -/* Permission.java -- The superclass for all permission objects - Copyright (C) 1998, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security; - -import java.io.Serializable; - -/** - * This class is the abstract superclass of all classes that implement - * the concept of a permission. A permission consists of a permission name - * and optionally a list of actions that relate to the permission. The - * actual meaning of the name of the permission is defined only in the - * context of a subclass. It may name a resource to which access permissions - * are granted (for example, the name of a file) or it might represent - * something else entirely. Similarly, the action list only has meaning - * within the context of a subclass. Some permission names may have no - * actions associated with them. That is, you either have the permission - * or you don't. - * - * <p>The most important method in this class is <code>implies</code>. This - * checks whether if one has this permission, then the specified - * permission is also implied. As a conceptual example, consider the - * permissions "Read All Files" and "Read File foo". The permission - * "Read All Files" implies that the caller has permission to read the - * file foo. - * - * <p><code>Permission</code>'s must be immutable - do not change their - * state after creation. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @see Permissions - * @see PermissionCollection - * @since 1.1 - * @status updated to 1.4 - */ -public abstract class Permission implements Guard, Serializable -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = -5636570222231596674L; - - /** - * This is the name assigned to this permission object. - * - * @serial the name of the permission - */ - private String name; - - /** - * Create an instance with the specified name. - * - * @param name the permission name - */ - public Permission(String name) - { - this.name = name; - } - - /** - * This method implements the <code>Guard</code> interface for this class. - * It calls the <code>checkPermission</code> method in - * <code>SecurityManager</code> with this <code>Permission</code> as its - * argument. This method returns silently if the security check succeeds - * or throws an exception if it fails. - * - * @param obj the <code>Object</code> being guarded - ignored by this class - * @throws SecurityException if the security check fails - * @see GuardedObject - * @see SecurityManager#checkPermission(Permission) - */ - public void checkGuard(Object obj) - { - SecurityManager sm = System.getSecurityManager(); - if (sm != null) - sm.checkPermission(this); - } - - /** - * This method tests whether this <code>Permission</code> implies that the - * specified <code>Permission</code> is also granted. - * - * @param perm the <code>Permission</code> to test against - * @return true if perm is implied by this - */ - public abstract boolean implies(Permission perm); - - /** - * Check to see if this object equals obj. Use <code>implies</code>, rather - * than <code>equals</code>, when making access control decisions. - * - * @param obj the object to compare to - */ - public abstract boolean equals(Object obj); - - /** - * This method returns a hash code for this <code>Permission</code>. It - * must satisfy the contract of <code>Object.hashCode</code>: it must be - * the same for all objects that equals considers to be the same. - * - * @return a hash value - */ - public abstract int hashCode(); - - /** - * Get the name of this <code>Permission</code>. - * - * @return the name - */ - public final String getName() - { - return name; - } - - /** - * This method returns the list of actions for this <code>Permission</code> - * as a <code>String</code>. The string should be in canonical order, for - * example, both <code>new FilePermission(f, "write,read")</code> and - * <code>new FilePermission(f, "read,write")</code> have the action list - * "read,write". - * - * @return the action list for this <code>Permission</code> - */ - public abstract String getActions(); - - /** - * This method returns an empty <code>PermissionCollection</code> object - * that can store permissions of this type, or <code>null</code> if no - * such collection is defined. Subclasses must override this to provide - * an appropriate collection when one is needed to accurately calculate - * <code>implies</code>. - * - * @return a new <code>PermissionCollection</code> - */ - public PermissionCollection newPermissionCollection() - { - return null; - } - - /** - * This method returns a <code>String</code> representation of this - * <code>Permission</code> object. This is in the format: - * <code>'(' + getClass().getName() + ' ' + getName() + ' ' + getActions - * + ')'</code>. - * - * @return this object as a <code>String</code> - */ - public String toString() - { - return '(' + getClass().getName() + ' ' + getName() + ' ' - + getActions() + ')'; - } -} // class Permission diff --git a/libjava/java/security/PermissionCollection.java b/libjava/java/security/PermissionCollection.java deleted file mode 100644 index 4e8ffe57948..00000000000 --- a/libjava/java/security/PermissionCollection.java +++ /dev/null @@ -1,167 +0,0 @@ -/* PermissionCollection.java -- A collection of permission objects - Copyright (C) 1998, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security; - -import java.io.Serializable; -import java.util.Enumeration; - -/** - * This class models a group of Java permissions. It has convenient - * methods for determining whether or not a given permission is implied - * by any of the permissions in this collection. - * - * <p>Some care must be taken in storing permissions. First, a collection of - * the appropriate type must be created. This is done by calling the - * <code>newPermissionCollection</code> method on an object of the - * permission class you wish to add to the collection. If this method - * returns <code>null</code>, any type of <code>PermissionCollection</code> - * can be used to store permissions of that type. However, if a - * <code>PermissionCollection</code> collection object is returned, that - * type must be used. - * - * <p>A <code>PermissionCollection</code> returned by the - * <code>newPermissionCollection</code> method in a subclass of - * <code>Permission</code> is a homogeneous collection. It only will - * hold permissions of one specified type - instances of the class that - * created it. Not all <code>PermissionCollection</code> subclasses - * have to hold permissions of only one type however. For example, - * the <code>Permissions</code> class holds permissions of many types. - * - * <p>Since the <code>newPermissionCollection</code> in <code>Permission</code> - * itself returns <code>null</code>, by default a permission can be stored - * in any type of collection unless it overrides that method to create its - * own collection type. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Eric Blake (ebb9@email.byu.edu) - * @see Permission - * @see Permissions - * @since 1.1 - * @status updated to 1.4 - */ -public abstract class PermissionCollection implements Serializable -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = -6727011328946861783L; - - /** - * Indicates whether or not this collection is read only. - * - * @serial if the collection is read-only - */ - private boolean readOnly; - - /** - * Create a new collection. - */ - public PermissionCollection() - { - } - - /** - * This method adds a new <code>Permission</code> object to the collection. - * - * @param perm the <code>Permission</code> to add - * - * @throws SecurityException if the collection is marked read only - * @throws IllegalArgumentException if perm is of the wrong type - */ - public abstract void add(Permission perm); - - /** - * This method tests whether the specified <code>Permission</code> object is - * implied by this collection of <code>Permission</code> objects. - * - * @param perm the <code>Permission</code> object to test - * @return true if the collection implies perm - */ - public abstract boolean implies(Permission perm); - - /** - * This method returns an <code>Enumeration</code> of all the objects in - * this collection. - * - * @return an <code>Enumeration</code> of this collection's objects - */ - public abstract Enumeration elements(); - - /** - * This method sets this <code>PermissionCollection</code> object to be - * read only. No further permissions can be added to it after calling this - * method. - */ - public void setReadOnly() - { - readOnly = true; - } - - /** - * This method tests whether or not this <code>PermissionCollection</code> - * object is read only. - * - * @return true if this collection is read only - */ - public boolean isReadOnly() - { - return readOnly; - } - - /** - * This method returns a <code>String</code> representation of this - * collection. It is formed by: - * <pre> - * super.toString()" (\n" - * // enumerate all permissions, one per line - * ")\n" - * </pre> - * - * @return a <code>String</code> representing this object - */ - public String toString() - { - StringBuffer sb = new StringBuffer(super.toString()); - - sb.append(" (\n"); - Enumeration e = elements(); - while (e.hasMoreElements()) - sb.append(' ').append(e.nextElement()).append('\n'); - return sb.append(")\n").toString(); - } -} // class PermissionCollection diff --git a/libjava/java/security/Permissions.java b/libjava/java/security/Permissions.java deleted file mode 100644 index e3fd06970ab..00000000000 --- a/libjava/java/security/Permissions.java +++ /dev/null @@ -1,254 +0,0 @@ -/* Permissions.java -- a collection of permission collections - Copyright (C) 1998, 2001, 2002, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security; - -import java.io.Serializable; -import java.util.Enumeration; -import java.util.Hashtable; -import java.util.NoSuchElementException; - -/** - * This class is a heterogeneous collection of permissions. It is - * organized as a collection of <code>PermissionCollection</code>'s stored - * in a hashtable. Each individual <code>PermissionCollection</code> - * contains permissions of a single type. If a specific type of - * <code>Permission</code> does not provide a collection type to use - * via its <code>newPermissionCollection</code> method, then a default - * collection type which stores its permissions in a hash table will be - * used. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.1 - */ -public final class Permissions extends PermissionCollection - implements Serializable -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = 4858622370623524688L; - - /** - * Holds instances of <code>AllPermission</code>. - * - * @serial the permission collection for AllPermission - */ - private PermissionCollection allPermission; - - // Package-private to avoid a trampoline. - /** - * This is the <code>Hashtable</code> that contains our collections. - * - * @serial maps Class to PermissionCollection - */ - final Hashtable perms = new Hashtable(); - - /** - * This method initializes a new instance of <code>Permissions</code>. - */ - public Permissions() - { - } - - /** - * This method adds a new <code>Permission</code> to this collection. It - * will be stored in a <code>PermissionCollection</code> of the appropriate - * type, as determined by calling <code>newPermissionCollection</code> on - * the specified permission (if an appropriate collection does not already - * exist). If this object does not specify a particular type of collection, - * a default collection, which stores in permissions in a hash table, will - * be used. - * - * @param perm the <code>Permission</code> to add - * @throws SecurityException if this collection is marked as read only - */ - public void add(Permission perm) - { - if (isReadOnly()) - throw new SecurityException("PermissionCollection is read only"); - if (perm instanceof AllPermission) - { - if (allPermission == null) - { - allPermission = perm.newPermissionCollection(); - allPermission.add(perm); - perms.put(perm.getClass(), allPermission); - } - } - else - { - PermissionCollection pc - = (PermissionCollection) perms.get(perm.getClass()); - if (pc == null) - { - pc = perm.newPermissionCollection(); - if (pc == null) - pc = new PermissionsHash(); - perms.put(perm.getClass(), pc); - } - pc.add(perm); - } - } - - /** - * This method tests whether or not the specified <code>Permission</code> - * is implied by this <code>PermissionCollection</code>. - * - * @param perm the <code>Permission</code> to test - * @return true if the specified permission is implied by this - */ - public boolean implies(Permission perm) - { - if (allPermission != null) - return true; - PermissionCollection pc - = (PermissionCollection) perms.get(perm.getClass()); - return pc == null ? false : pc.implies(perm); - } - - /** - * This method returns an <code>Enumeration</code> which contains a - * list of all <code>Permission</code> objects contained in this - * collection. - * - * @return an <code>Enumeration</code> of this collection's elements - */ - public Enumeration elements() - { - return new Enumeration() - { - Enumeration main_enum = perms.elements(); - Enumeration sub_enum; - - public boolean hasMoreElements() - { - if (sub_enum == null) - { - if (main_enum == null) - return false; - if (! main_enum.hasMoreElements()) - { - main_enum = null; - return false; - } - PermissionCollection pc = - (PermissionCollection) main_enum.nextElement(); - sub_enum = pc.elements(); - } - if (! sub_enum.hasMoreElements()) - { - sub_enum = null; - return hasMoreElements(); - } - return true; - } - - public Object nextElement() - { - if (! hasMoreElements()) - throw new NoSuchElementException(); - return sub_enum.nextElement(); - } - }; - } - - /** - * Implements the permission collection for all permissions without one of - * their own, and obeys serialization of JDK. - * - * @author Eric Blake (ebb9@email.byu.edu) - */ - private static final class PermissionsHash extends PermissionCollection - { - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = -8491988220802933440L; - - /** - * Hashtable where we store permissions. - * - * @serial the stored permissions, both as key and value - */ - private final Hashtable perms = new Hashtable(); - - /** - * Add a permission. We don't need to check for read-only, as this - * collection is never exposed outside of Permissions, which has already - * done that check. - * - * @param perm the permission to add - */ - public void add(Permission perm) - { - perms.put(perm, perm); - } - - /** - * Returns true if perm is in the collection. - * - * @param perm the permission to check - * @return true if it is implied - */ - // FIXME: Should this method be synchronized? - public boolean implies(Permission perm) - { - Enumeration elements = elements(); - - while (elements.hasMoreElements()) - { - Permission p = (Permission)elements.nextElement(); - if (p.implies(perm)) - return true; - } - return false; - } - - /** - * Return the elements. - * - * @return the elements - */ - public Enumeration elements() - { - return perms.elements(); - } - } // class PermissionsHash -} // class Permissions diff --git a/libjava/java/security/Policy.java b/libjava/java/security/Policy.java deleted file mode 100644 index 03d9bbb4ed6..00000000000 --- a/libjava/java/security/Policy.java +++ /dev/null @@ -1,310 +0,0 @@ -/* Policy.java --- Policy Manager Class - Copyright (C) 1999, 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security; - -import java.util.Collections; -import java.util.Enumeration; -import java.util.LinkedHashMap; -import java.util.Map; - -/** - * <p>This is an abstract class for representing the system security policy for - * a Java application environment (specifying which permissions are available - * for code from various sources). That is, the security policy is represented - * by a <code>Policy</code> subclass providing an implementation of the abstract - * methods in this <code>Policy</code> class.</p> - * - * <p>There is only one <code>Policy</code> object in effect at any given time. - * </p> - * - * <p>The source location for the policy information utilized by the - * <code>Policy</code> object is up to the <code>Policy</code> implementation. - * The policy configuration may be stored, for example, as a flat ASCII file, as - * a serialized binary file of the <code>Policy</code> class, or as a database. - * </p> - * - * <p>The currently-installed <code>Policy</code> object can be obtained by - * calling the <code>getPolicy()</code> method, and it can be changed by a call - * to the <code>setPolicy()</code> method (by code with permission to reset the - * <code>Policy</code>).</p> - * - * <p>The <code>refresh()</code> method causes the policy object to refresh / - * reload its current configuration.</p> - * - * <p>This is implementation-dependent. For example, if the policy object stores - * its policy in configuration files, calling <code>refresh()</code> will cause - * it to re-read the configuration policy files. The refreshed policy may not - * have an effect on classes in a particular {@link ProtectionDomain}. This is - * dependent on the <code>Policy</code> provider's implementation of the - * <code>implies()</code> method and the {@link PermissionCollection} caching - * strategy.</p> - * - * <p>The default <code>Policy</code> implementation can be changed by setting - * the value of the <code>"policy.provider"</code> security property (in the - * Java security properties file) to the fully qualified name of the desired - * <code>Policy</code> implementation class. The Java security properties file - * is located in the file named <code><JAVA_HOME>/lib/security/java.security - * </code>, where <code><JAVA_HOME></code> refers to the directory where the - * SDK was installed.</p> - * - * <p><b>IMPLEMENTATION NOTE:</b> This implementation attempts to read the - * System property named <code>policy.provider</code> to find the concrete - * implementation of the <code>Policy</code>. If/when this fails, it falls back - * to a default implementation, which <b>allows everything</b>. - * - * @author Mark Benvenuto - * @see CodeSource - * @see PermissionCollection - * @see SecureClassLoader - * @since 1.2 - */ -public abstract class Policy -{ - private static Policy currentPolicy; - - /** Map of ProtectionDomains to PermissionCollections for this instance. */ - private Map pd2pc = null; - - /** Constructs a new <code>Policy</code> object. */ - public Policy() - { - } - - /** - * Returns the installed <code>Policy</code> object. This value should not be - * cached, as it may be changed by a call to <code>setPolicy()</code>. This - * method first calls {@link SecurityManager#checkPermission(Permission)} with - * a <code>SecurityPermission("getPolicy")</code> permission to ensure it's ok - * to get the <code>Policy</code> object. - * - * @return the installed <code>Policy</code>. - * @throws SecurityException if a security manager exists and its - * <code>checkPermission()</code> method doesn't allow getting the - * <code>Policy</code> object. - * @see SecurityManager#checkPermission(Permission) - * @see #setPolicy(Policy) - */ - public static Policy getPolicy() - { - SecurityManager sm = System.getSecurityManager(); - if (sm != null) - sm.checkPermission(new SecurityPermission("getPolicy")); - - return getCurrentPolicy(); - } - - /** - * Sets the system-wide <code>Policy</code> object. This method first calls - * {@link SecurityManager#checkPermission(Permission)} with a - * <code>SecurityPermission("setPolicy")</code> permission to ensure it's ok - * to set the <code>Policy</code>. - * - * @param policy the new system <code>Policy</code> object. - * @throws SecurityException if a security manager exists and its - * <code>checkPermission()</code> method doesn't allow setting the - * <code>Policy</code>. - * @see SecurityManager#checkPermission(Permission) - * @see #getPolicy() - */ - public static void setPolicy(Policy policy) - { - SecurityManager sm = System.getSecurityManager(); - if (sm != null) - sm.checkPermission(new SecurityPermission("setPolicy")); - - setup(policy); - currentPolicy = policy; - } - - private static void setup(final Policy policy) - { - if (policy.pd2pc == null) - policy.pd2pc = Collections.synchronizedMap(new LinkedHashMap()); - - ProtectionDomain pd = policy.getClass().getProtectionDomain(); - if (pd.getCodeSource() != null) - { - PermissionCollection pc = null; - if (currentPolicy != null) - pc = currentPolicy.getPermissions(pd); - - if (pc == null) // assume it has all - { - pc = new Permissions(); - pc.add(new AllPermission()); - } - - policy.pd2pc.put(pd, pc); // add the mapping pd -> pc - } - } - - /** - * Ensures/forces loading of the configured policy provider, while bypassing - * the {@link SecurityManager} checks for <code>"getPolicy"</code> security - * permission. Needed by {@link ProtectionDomain}. - */ - static Policy getCurrentPolicy() - { - // FIXME: The class name of the Policy provider should really be sourced - // from the "java.security" configuration file. For now, just hard-code - // a stub implementation. - if (currentPolicy == null) - { - String pp = System.getProperty ("policy.provider"); - if (pp != null) - try - { - currentPolicy = (Policy) Class.forName(pp).newInstance(); - } - catch (Exception e) - { - // Ignored. - } - - if (currentPolicy == null) - currentPolicy = new gnu.java.security.provider.DefaultPolicy(); - } - return currentPolicy; - } - - /** - * Tests if <code>currentPolicy</code> is not <code>null</code>, - * thus allowing clients to not force loading of any policy - * provider; needed by {@link ProtectionDomain}. - */ - static boolean isLoaded() - { - return currentPolicy != null; - } - - /** - * Evaluates the global policy and returns a {@link PermissionCollection} - * object specifying the set of permissions allowed for code from the - * specified code source. - * - * @param codesource the {@link CodeSource} associated with the caller. This - * encapsulates the original location of the code (where the code came from) - * and the public key(s) of its signer. - * @return the set of permissions allowed for code from codesource according - * to the policy. The returned set of permissions must be a new mutable - * instance and it must support heterogeneous {@link Permission} types. - */ - public abstract PermissionCollection getPermissions(CodeSource codesource); - - /** - * Evaluates the global policy and returns a {@link PermissionCollection} - * object specifying the set of permissions allowed given the characteristics - * of the protection domain. - * - * @param domain the {@link ProtectionDomain} associated with the caller. - * @return the set of permissions allowed for the domain according to the - * policy. The returned set of permissions must be a new mutable instance and - * it must support heterogeneous {@link Permission} types. - * @since 1.4 - * @see ProtectionDomain - * @see SecureClassLoader - */ - public PermissionCollection getPermissions(ProtectionDomain domain) - { - if (domain == null) - return new Permissions(); - - if (pd2pc == null) - setup(this); - - PermissionCollection result = (PermissionCollection) pd2pc.get(domain); - if (result != null) - { - Permissions realResult = new Permissions(); - for (Enumeration e = result.elements(); e.hasMoreElements(); ) - realResult.add((Permission) e.nextElement()); - - return realResult; - } - - result = getPermissions(domain.getCodeSource()); - if (result == null) - result = new Permissions(); - - PermissionCollection pc = domain.getPermissions(); - if (pc != null) - for (Enumeration e = pc.elements(); e.hasMoreElements(); ) - result.add((Permission) e.nextElement()); - - return result; - } - - /** - * Evaluates the global policy for the permissions granted to the {@link - * ProtectionDomain} and tests whether the <code>permission</code> is granted. - * - * @param domain the {@link ProtectionDomain} to test. - * @param permission the {@link Permission} object to be tested for - * implication. - * @return <code>true</code> if <code>permission</code> is a proper subset of - * a permission granted to this {@link ProtectionDomain}. - * @since 1.4 - * @see ProtectionDomain - */ - public boolean implies(ProtectionDomain domain, Permission permission) - { - if (pd2pc == null) - setup(this); - - PermissionCollection pc = (PermissionCollection) pd2pc.get(domain); - if (pc != null) - return pc.implies(permission); - - boolean result = false; - pc = getPermissions(domain); - if (pc != null) - { - result = pc.implies(permission); - pd2pc.put(domain, pc); - } - - return result; - } - - /** - * Refreshes/reloads the policy configuration. The behavior of this method - * depends on the implementation. For example, calling refresh on a file-based - * policy will cause the file to be re-read. - */ - public abstract void refresh(); -} diff --git a/libjava/java/security/Principal.java b/libjava/java/security/Principal.java deleted file mode 100644 index 6d9de6ccd8a..00000000000 --- a/libjava/java/security/Principal.java +++ /dev/null @@ -1,85 +0,0 @@ -/* Principal.java -- A security entity - Copyright (C) 1998, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security; - -/** - * This interface models an entity (such as a user or a certificate authority) - * for the purposes of applying the Java security model. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @see X509Certificate - * @since 1.1 - * @status updated to 1.4 - */ -public interface Principal -{ - /** - * This method tests another <code>Principal</code> object for equality - * with this one. - * - * @param obj the Object to test for equality - * @return true if the specified <code>Principal</code> is equal - */ - boolean equals(Object obj); - - /** - * This method returns a <code>String</code> representation of this - * <code>Principal</code>. - * - * @return this <code>Principal</code> represented as a <code>String</code> - */ - String toString(); - - /** - * This method returns a hash code value for this <code>Principal</code>. - * Remember the contract of hashCode - two objects which compare as - * equals() must have the same hashCode(). - * - * @return a hash value - */ - int hashCode(); - - /** - * This method returns a <code>String</code> that names this - * <code>Principal</code>. - * - * @return the name of this <code>Principal</code> - */ - String getName(); -} // interface Principal diff --git a/libjava/java/security/PrivateKey.java b/libjava/java/security/PrivateKey.java deleted file mode 100644 index 70607c13442..00000000000 --- a/libjava/java/security/PrivateKey.java +++ /dev/null @@ -1,62 +0,0 @@ -/* PrivateKey.java -- tagging interface for all private keys - Copyright (C) 1998, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security; - -/** - * This interface specified no methods. In simply provides a common - * super-interface for all algorithm specific private key values. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @see Key - * @see PublicKey - * @see Certificate - * @see Signature#initVerify(PublicKey) - * @see DSAPrivateKey - * @see RSAPrivateKey - * @see RSAPrivateCrtKey - * @since 1.1 - * @status updated to 1.4 - */ -public interface PrivateKey extends Key -{ - /** - * The version identifier used for serialization. - */ - long serialVersionUID = 6034044314589513430L; -} // interface PrivateKey diff --git a/libjava/java/security/PrivilegedAction.java b/libjava/java/security/PrivilegedAction.java deleted file mode 100644 index c3a41346f9c..00000000000 --- a/libjava/java/security/PrivilegedAction.java +++ /dev/null @@ -1,64 +0,0 @@ -/* PrivilegedAction.java -- Perform a privileged action - Copyright (C) 1998, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security; - -/** - * This interface specifes a single <code>run</code> method that - * executes a privileged operation. This method is called by - * <code>AccessController.doPrivileged()</code> after that method - * activiates the required privileges. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @see AccessController - * @see PrivilegedExceptionAction - * @since 1.1 - * @status updated to 1.4 - */ -public interface PrivilegedAction -{ - /** - * This method performs an operation that requires higher privileges to - * perform. It is called when a section of code invokes - * <code>AccessController.doPrivileged()</code>. - * - * @return obj An implementation dependent return value - * @see AccessController#doPrivileged(PrivilegedAction) - * @see AccessController#doPrivileged(PrivilegedAction, AccessControlContext) - */ - Object run(); -} // interface PrivilegedAction diff --git a/libjava/java/security/PrivilegedActionException.java b/libjava/java/security/PrivilegedActionException.java deleted file mode 100644 index 3f08c813065..00000000000 --- a/libjava/java/security/PrivilegedActionException.java +++ /dev/null @@ -1,109 +0,0 @@ -/* PrivilegedActionException.java -- wrap an exception in a privileged action - Copyright (C) 1998, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security; - -/** - * This exception is thrown when an exception is thrown during a - * privileged action being performed with the - * <code>AccessController.doPrivileged()</code> method. It wraps the - * actual exception thrown in the privileged code. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Eric Blake (ebb9@email.byu.edu) - * @see PrivilegedExceptionAction - * @see AccessController#doPrivileged(PrivilegedExceptionAction) - * @see AccessController#doPrivileged(PrivilegedExceptionAction, AccessControlContext) - * @status updated to 1.4 - */ -public class PrivilegedActionException extends Exception -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = 4724086851538908602L; - - /** - * This is the actual exception that occurred. - * - * @serial the wrapped exception - */ - private Exception exception; - - /** - * Create a new instance that wraps the specified <code>Exception</code>. - * - * @param e the <code>Exception</code> to wrap - */ - public PrivilegedActionException(Exception e) - { - super(e); - exception = e; - } - - /** - * Get the underlying <code>Exception</code> that caused this one. This - * is a legacy method, the preferred way is {@link #getCause()}. - * - * @return the cause - */ - public Exception getException() - { - return exception; - } - - /** - * Gets the cause of this exception. - * - * @return the cause - * @since 1.4 - */ - public Throwable getCause() - { - return exception; - } - - /** - * Convert this to a String. - * - * @return the string representation - */ - public String toString() - { - return super.toString(); - } -} diff --git a/libjava/java/security/PrivilegedExceptionAction.java b/libjava/java/security/PrivilegedExceptionAction.java deleted file mode 100644 index d3d0478fd48..00000000000 --- a/libjava/java/security/PrivilegedExceptionAction.java +++ /dev/null @@ -1,65 +0,0 @@ -/* PrivilegedExceptionAction.java -- Perform a privileged operation - Copyright (C) 1998, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security; - -/** - * This interface defines a method that is called by - * <code>AccessController.doPrivileged()</code> in order to perform a - * privileged operation with higher privileges enabled. This interface - * differs from <code>PrivilegedAction</code> in that the <code>run</code> - * method in this interface may throw a checked exception. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @since 1.1 - * @status updated to 1.4 - */ -public interface PrivilegedExceptionAction -{ - /** - * This method performs an operation that requires higher privileges to - * successfully complete. It is called when a section of code invokes - * <code>AccessController.doPrivileged()</code>. - * - * @return obj An implementation defined return value - * @throws Exception An implementation specific exception - * @see AccessController#doPrivileged(PrivilegedExceptionAction) - * @see AccessController#doPrivileged(PrivilegedExceptionAction, - * AccessControlContext) - */ - Object run() throws Exception; -} // interface PrivilegedExceptionAction diff --git a/libjava/java/security/ProtectionDomain.java b/libjava/java/security/ProtectionDomain.java deleted file mode 100644 index a5851b5adf4..00000000000 --- a/libjava/java/security/ProtectionDomain.java +++ /dev/null @@ -1,269 +0,0 @@ -/* ProtectionDomain.java -- A security domain - Copyright (C) 1998, 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security; - -/** - * <p>This <code>ProtectionDomain</code> class encapsulates the characteristics - * of a domain, which encloses a set of classes whose instances are granted a - * set of permissions when being executed on behalf of a given set of - * <i>Principals</i>. - * - * <p>A static set of permissions can be bound to a <code>ProtectionDomain</code> - * when it is constructed; such permissions are granted to the domain regardless - * of the {@link Policy} in force. However, to support dynamic security - * policies, a <code>ProtectionDomain</code> can also be constructed such that - * it is dynamically mapped to a set of permissions by the current {@link - * Policy} whenever a permission is checked.</p> - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @version 0.0 - */ -public class ProtectionDomain -{ - /** This is the <code>CodeSource</code> for this protection domain. */ - private CodeSource code_source; - - /** This is the set of permissions granted to this domain. */ - private PermissionCollection perms; - - /** The {@link ClassLoader} associated with this domain. */ - private ClassLoader classloader; - - /** The array of Principals associated with this domain.. */ - private Principal[] principals; - - /** Post 1.4 the policy may be refreshed! use false for pre 1.4. */ - private boolean staticBinding; - - /** - * Creates a new <code>ProtectionDomain</code> with the given {@link - * CodeSource} and {@link Permissions}. If the permissions object is not - * <code>null</code>, then <code>setReadOnly()</code> will be called on the - * passed in {@link Permissions} object. The only permissions granted to this - * domain are the ones specified; the current {@link Policy} will not be - * consulted. - * - * @param codesource the codesource associated with this domain. - * @param permissions the permissions granted to this domain - */ - public ProtectionDomain(CodeSource codesource, PermissionCollection permissions) - { - this(codesource, permissions, null, null, true); - } - - /** - * <p>Creates a new ProtectionDomain qualified by the given CodeSource, - * Permissions, ClassLoader and array of Principals. If the permissions - * object is not null, then <code>setReadOnly()</code> will be called on the - * passed in Permissions object. The permissions granted to this domain are - * dynamic; they include both the static permissions passed to this - * constructor, and any permissions granted to this domain by the current - * Policy at the time a permission is checked.</p> - * - * <p>This constructor is typically used by {@link ClassLoader}s and {@link - * DomainCombiner}s which delegate to <code>Policy</code> to actively - * associate the permissions granted to this domain. This constructor affords - * the Policy provider the opportunity to augment the supplied - * PermissionCollection to reflect policy changes.</p> - * - * @param codesource the CodeSource associated with this domain. - * @param permissions the permissions granted to this domain. - * @param classloader the ClassLoader associated with this domain. - * @param principals the array of Principals associated with this domain. - * @since 1.4 - * @see Policy#refresh() - * @see Policy#getPermissions(ProtectionDomain) - */ - public ProtectionDomain(CodeSource codesource, - PermissionCollection permissions, - ClassLoader classloader, Principal[] principals) - { - this(codesource, permissions, classloader, principals, false); - } - - private ProtectionDomain(CodeSource codesource, - PermissionCollection permissions, - ClassLoader classloader, Principal[] principals, - boolean staticBinding) - { - super(); - - code_source = codesource; - if (permissions != null) - { - perms = permissions; - perms.setReadOnly(); - } - - this.classloader = classloader; - this.principals = - (principals != null ? (Principal[]) principals.clone() : new Principal[0]); - this.staticBinding = staticBinding; - } - - /** - * Returns the {@link CodeSource} of this domain. - * - * @return the {@link CodeSource} of this domain which may be <code>null</code>. - * @since 1.2 - */ - public final CodeSource getCodeSource() - { - return code_source; - } - - /** - * Returns the {@link ClassLoader} of this domain. - * - * @return the {@link ClassLoader} of this domain which may be - * <code>null</code>. - * @since 1.4 - */ - public final ClassLoader getClassLoader() - { - return this.classloader; - } - - /** - * Returns an array of principals for this domain. - * - * @return returns a non-null array of principals for this domain. Changes to - * this array will have no impact on the <code>ProtectionDomain</code>. - * @since 1.4 - */ - public final Principal[] getPrincipals() - { - return (Principal[]) principals.clone(); - } - - /** - * Returns the static permissions granted to this domain. - * - * @return the static set of permissions for this domain which may be - * <code>null</code>. - * @see Policy#refresh() - * @see Policy#getPermissions(ProtectionDomain) - */ - public final PermissionCollection getPermissions() - { - return perms; - } - - /** - * <p>Check and see if this <code>ProtectionDomain</code> implies the - * permissions expressed in the <code>Permission</code> object.</p> - * - * <p>The set of permissions evaluated is a function of whether the - * <code>ProtectionDomain</code> was constructed with a static set of - * permissions or it was bound to a dynamically mapped set of permissions.</p> - * - * <p>If the <code>ProtectionDomain</code> was constructed to a statically - * bound {@link PermissionCollection} then the permission will only be checked - * against the {@link PermissionCollection} supplied at construction.</p> - * - * <p>However, if the <code>ProtectionDomain</code> was constructed with the - * constructor variant which supports dynamically binding permissions, then - * the permission will be checked against the combination of the - * {@link PermissionCollection} supplied at construction and the current - * {@link Policy} binding. - * - * @param permission the {@link Permission} object to check. - * @return <code>true</code> if <code>permission</code> is implicit to this - * <code>ProtectionDomain</code>. - */ - public boolean implies(Permission permission) - { - if (staticBinding) - return (perms == null ? false : perms.implies(permission)); - // Else dynamically bound. Do we have it? - // NOTE: this will force loading of Policy.currentPolicy - return Policy.getCurrentPolicy().implies(this, permission); - } - - /** - * Convert a <code>ProtectionDomain</code> to a String. - * - * @return a string representation of the object. - */ - public String toString() - { - String linesep = System.getProperty("line.separator"); - StringBuffer sb = new StringBuffer("ProtectionDomain (").append(linesep); - - if (code_source == null) - sb.append("CodeSource:null"); - else - sb.append(code_source); - - sb.append(linesep); - if (classloader == null) - sb.append("ClassLoader:null"); - else - sb.append(classloader); - - sb.append(linesep); - sb.append("Principals:"); - if (principals != null && principals.length > 0) - { - sb.append("["); - Principal pal; - for (int i = 0; i < principals.length; i++) - { - pal = principals[i]; - sb.append("'").append(pal.getName()) - .append("' of type ").append(pal.getClass().getName()); - if (i < principals.length-1) - sb.append(", "); - } - sb.append("]"); - } - else - sb.append("none"); - - sb.append(linesep); - if (!staticBinding) // include all but dont force loading Policy.currentPolicy - if (Policy.isLoaded()) - sb.append(Policy.getCurrentPolicy().getPermissions(this)); - else // fallback on this one's permissions - sb.append(perms); - else - sb.append(perms); - - return sb.append(linesep).append(")").append(linesep).toString(); - } -} diff --git a/libjava/java/security/Provider.java b/libjava/java/security/Provider.java deleted file mode 100644 index 4ffaa55bcb1..00000000000 --- a/libjava/java/security/Provider.java +++ /dev/null @@ -1,202 +0,0 @@ -/* Provider.java -- Security provider information - Copyright (C) 1998, 1999, 2000, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security; - -import java.io.Serializable; -import java.util.Properties; - -/** - * This class represents a Java security architecture service provider. - * The services provided by a such a provider can range from security - * algorithms to key generation. - * <p> - * Providers are installed by name and version number. There is one - * standard provider supplied with the class library. This is the - * "GNU" provider, which can also be accessed by the alias "SUN" for - * compatibility with the JDK. - * - * @version 0.0 - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public abstract class Provider extends Properties implements Serializable -{ - private static final long serialVersionUID = -4298000515446427739L; - - /** - * This is a textual description of the provider - */ - private String info; - - /** - * This is the name of the provider - */ - private String name; - - /** - * This is the version number of the provider - */ - private double version; - - /** - * This method initializes a new instance of <code>Provider</code> to have - * the specified name, version, and description information. - * - * @param name The name to assign to this <code>Provider</code>. - * @param version The version number for this <code>Provider</code>. - * @param info A textual description of this provider. - */ - protected Provider(String name, double version, String info) - { - this.name = name; - this.version = version; - this.info = info; - } - - /** - * This method returns the name assigned to this <code>Provider</code>. - * - * @return The <code>Provider</code>'s name. - */ - public String getName() - { - return (name); - } - - /** - * This method retunrs the version number of this <code>Provider</code>. - * - * @return The <code>Provider</code>'s version number. - */ - public double getVersion() - { - return (version); - } - - /** - * This method returns a textual description of the <code>Provider</code>. - * - * @return A description of the <code>Provider</code>. - */ - public String getInfo() - { - return (info); - } - - /** - * Sets the key property to have the specified value. - * <p> - * <bold>NOT IMPLEMENTED YET</bold>[ - * First, if there is a security manager, its <code>checkSecurityAccess</code> - * method is called with the string "putProviderProperty."+name, where name is - * the provider name, to see if it's ok to set this provider's property - * values. - * If the default implementation of <code>checkSecurityAccess</code> is used - * (that is, that method is not overriden), then this results in a call to the - * security manager's <code>checkPermission</code> method with a - * <code>SecurityPermission("putProviderProperty."+name)</code> - * permission.<br>] - * - * @param key The property key. - * @param value The property value. - * - * @return The previous value of the specified property (<code>key</code>), - * or <code>null</code> if it did not have one. - * @throws SecurityException If a security manager exists and its - * {@link java.lang.SecurityManager.checkSecurityAccess(java.lang.String)} - * method denies access to set property values. - * @since Classpath 0.4+cvs, JDK 1.2 - * @see java.lang.Object.equals(Object) - * @see java.util.Hashtable.get(Object) - */ - public Object put(Object key, Object value) - { - return super.put(toCanonicalKey(key), value); - } - - // overrides same in java.util.Hashtable - public Object get(Object key) - { - return super.get(toCanonicalKey(key)); - } - - /** - * This method removes the specified key entry (and its associated value) - * from the property mapping list. - * - * @param key The key to remove - * - * @return The previous value for this key, or <code>null</code> if no - * previous value. - */ - public Object remove(Object key) - { - return super.remove(toCanonicalKey(key)); - } - - /** - * This method clears the entire property list such that it no longer - * contains the properties used to look up the services provided by - * the <code>Provider</code>. - */ - public void clear() - { - super.clear(); - } - - /** - * This method returns a <code>String</code> representation of this - * object. This will include the <code>Provider</code> name and - * version number. - * - * @return A <code>String</code> representation of this object. - */ - public String toString() - { - return (getClass().getName() + ": name=" + getName() + " version=" + - version); - } - - private Object toCanonicalKey(Object key) - { - if (key.getClass().isAssignableFrom(String.class)) // is it ours? - return ((String) key).toUpperCase(); // use default locale - else - return key; - } -} diff --git a/libjava/java/security/ProviderException.java b/libjava/java/security/ProviderException.java deleted file mode 100644 index 2dafcec3495..00000000000 --- a/libjava/java/security/ProviderException.java +++ /dev/null @@ -1,70 +0,0 @@ -/* ProviderException.java -- Generic security provider runtime exception - Copyright (C) 1998, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security; - -/** - * This exception indicates that a runtime problem was encounterd with - * a security provider. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @status updated to 1.4 - */ -public class ProviderException extends RuntimeException -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = 5256023526693665674L; - - /** - * Create an instance with no descriptive error message. - */ - public ProviderException() - { - } - - /** - * Create an instance with a descriptive error message. - * - * @param msg the descriptive error message - */ - public ProviderException(String msg) - { - super(msg); - } -} diff --git a/libjava/java/security/PublicKey.java b/libjava/java/security/PublicKey.java deleted file mode 100644 index 9bf14584089..00000000000 --- a/libjava/java/security/PublicKey.java +++ /dev/null @@ -1,60 +0,0 @@ -/* PublicKey.java -- tagging interface for all public keys - Copyright (C) 1998, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security; - -/** - * This interface specified no methods. In simply provides a common - * super-interface for all algorithm specific public key values. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @see Key - * @see PrivateKey - * @see Certificate - * @see Signature#initVerify(PublicKey) - * @see DSAPublicKey - * @see RSAPublicKey - * @since 1.1 - * @status updated to 1.4 - */ -public interface PublicKey extends Key -{ - /** - * The version identifier used for serialization. - */ - long serialVersionUID = 7187392471159151072L; -} // interface PublicKey diff --git a/libjava/java/security/SecureClassLoader.java b/libjava/java/security/SecureClassLoader.java deleted file mode 100644 index 9d1fac79749..00000000000 --- a/libjava/java/security/SecureClassLoader.java +++ /dev/null @@ -1,128 +0,0 @@ -/* SecureClassLoader.java --- A Secure Class Loader - Copyright (C) 1999, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security; - -/** - * A Secure Class Loader for loading classes with additional - * support for specifying code source and permissions when - * they are retrieved by the system policy handler. - * - * @since 1.2 - * - * @author Mark Benvenuto - */ -public class SecureClassLoader extends ClassLoader -{ - java.util.WeakHashMap protectionDomainCache = new java.util.WeakHashMap(); - - protected SecureClassLoader(ClassLoader parent) - { - super(parent); - SecurityManager sm = System.getSecurityManager(); - if(sm != null) - sm.checkCreateClassLoader(); - } - - protected SecureClassLoader() - { - SecurityManager sm = System.getSecurityManager(); - if(sm != null) - sm.checkCreateClassLoader(); - } - - /** - * Creates a class using an array of bytes and a - * CodeSource. - * - * @param name the name to give the class. null if unknown. - * @param b the data representing the classfile, in classfile format. - * @param off the offset into the data where the classfile starts. - * @param len the length of the classfile data in the array. - * @param cs the CodeSource for the class or null when unknown. - * - * @return the class that was defined and optional CodeSource. - * - * @exception ClassFormatError if the byte array is not in proper classfile format. - */ - protected final Class defineClass(String name, byte[] b, int off, int len, - CodeSource cs) - { - if (cs != null) - { - ProtectionDomain protectionDomain; - - synchronized (protectionDomainCache) - { - protectionDomain = (ProtectionDomain)protectionDomainCache.get(cs); - } - - if (protectionDomain == null) - { - protectionDomain - = new ProtectionDomain(cs, getPermissions(cs), this, null); - synchronized (protectionDomainCache) - { - ProtectionDomain domain - = (ProtectionDomain)protectionDomainCache.get(cs); - if (domain == null) - protectionDomainCache.put(cs, protectionDomain); - else - protectionDomain = domain; - } - } - return super.defineClass(name, b, off, len, protectionDomain); - } - else - return super.defineClass(name, b, off, len); - } - - /** - * Returns a PermissionCollection for the specified CodeSource. - * The default implementation invokes - * java.security.Policy.getPermissions. - * - * This method is called by defineClass that takes a CodeSource - * arguement to build a proper ProtectionDomain for the class - * being defined. - */ - protected PermissionCollection getPermissions(CodeSource cs) - { - Policy policy = Policy.getCurrentPolicy(); - return policy.getPermissions(cs); - } -} diff --git a/libjava/java/security/SecureRandom.java b/libjava/java/security/SecureRandom.java deleted file mode 100644 index 3ee3a841d26..00000000000 --- a/libjava/java/security/SecureRandom.java +++ /dev/null @@ -1,380 +0,0 @@ -/* SecureRandom.java --- Secure Random class implementation - Copyright (C) 1999, 2001, 2002, 2003, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security; - -import gnu.java.security.Engine; - -import java.util.Enumeration; -import java.util.Random; - -/** - * An interface to a cryptographically secure pseudo-random number - * generator (PRNG). Random (or at least unguessable) numbers are used - * in all areas of security and cryptography, from the generation of - * keys and initialization vectors to the generation of random padding - * bytes. - * - * @author Mark Benvenuto (ivymccough@worldnet.att.net) - * @author Casey Marshall - */ -public class SecureRandom extends Random -{ - - // Constants and fields. - // ------------------------------------------------------------------------ - - /** Service name for PRNGs. */ - private static final String SECURE_RANDOM = "SecureRandom"; - - private static final long serialVersionUID = 4940670005562187L; - - //Serialized Field - long counter = 0; //Serialized - Provider provider = null; - byte[] randomBytes = null; //Always null - int randomBytesUsed = 0; - SecureRandomSpi secureRandomSpi = null; - byte[] state = null; - - // Constructors. - // ------------------------------------------------------------------------ - - /** - Default constructor for SecureRandom. It constructs a - new SecureRandom by instantating the first SecureRandom - algorithm in the default security provier. - - It is not seeded and should be seeded using setSeed or else - on the first call to getnextBytes it will force a seed. - - It is maintained for backwards compatibility and programs - should use {@link #getInstance(java.lang.String)}. - */ - public SecureRandom() - { - Provider[] p = Security.getProviders(); - - //Format of Key: SecureRandom.algname - String key; - - String classname = null; - int i; - Enumeration e; - for (i = 0; i < p.length; i++) - { - e = p[i].propertyNames(); - while (e.hasMoreElements()) - { - key = (String) e.nextElement(); - if (key.startsWith("SECURERANDOM.")) - { - if ((classname = p[i].getProperty(key)) != null) - { - try - { - secureRandomSpi = (SecureRandomSpi) Class. - forName(classname).newInstance(); - provider = p[i]; - return; - } - catch (ThreadDeath death) - { - throw death; - } - catch (Throwable t) - { - // Ignore. - } - } - } - } - } - - // Nothing found. Fall back to SHA1PRNG - secureRandomSpi = new gnu.java.security.provider.SHA1PRNG(); - } - - /** - A constructor for SecureRandom. It constructs a new - SecureRandom by instantating the first SecureRandom algorithm - in the default security provier. - - It is seeded with the passed function and is useful if the user - has access to hardware random device (like a radiation detector). - - It is maintained for backwards compatibility and programs - should use getInstance. - - @param seed Seed bytes for class - */ - public SecureRandom(byte[] seed) - { - this(); - setSeed(seed); - } - - /** - A constructor for SecureRandom. It constructs a new - SecureRandom using the specified SecureRandomSpi from - the specified security provier. - - @param secureRandomSpi A SecureRandomSpi class - @param provider A Provider class - */ - protected SecureRandom(SecureRandomSpi secureRandomSpi, Provider provider) - { - this.secureRandomSpi = secureRandomSpi; - this.provider = provider; - } - - // Class methods. - // ------------------------------------------------------------------------ - - /** - * Returns an instance of a SecureRandom. It creates the class from - * the first provider that implements it. - * - * @param algorithm The algorithm name. - * @return A new SecureRandom implementing the given algorithm. - * @throws NoSuchAlgorithmException If no installed provider implements - * the given algorithm. - */ - public static SecureRandom getInstance(String algorithm) - throws NoSuchAlgorithmException - { - Provider[] p = Security.getProviders(); - - for (int i = 0; i < p.length; i++) - { - try - { - return getInstance(algorithm, p[i]); - } - catch (NoSuchAlgorithmException e) - { - // Ignore. - } - } - - // None found. - throw new NoSuchAlgorithmException(algorithm); - } - - /** - * Returns an instance of a SecureRandom. It creates the class - * for the specified algorithm from the named provider. - * - * @param algorithm The algorithm name. - * @param provider The provider name. - * @return A new SecureRandom implementing the chosen algorithm. - * @throws NoSuchAlgorithmException If the named provider does not implement - * the algorithm, or if the implementation cannot be - * instantiated. - * @throws NoSuchProviderException If no provider named - * <code>provider</code> is currently installed. - * @throws IllegalArgumentException If <code>provider</code> is null - * or is empty. - */ - public static SecureRandom getInstance(String algorithm, String provider) - throws NoSuchAlgorithmException, NoSuchProviderException - { - if (provider == null || provider.length() == 0) - throw new IllegalArgumentException("Illegal provider"); - - Provider p = Security.getProvider(provider); - if (p == null) - throw new NoSuchProviderException(provider); - - return getInstance(algorithm, p); - } - - /** - * Returns an instance of a SecureRandom. It creates the class for - * the specified algorithm from the given provider. - * - * @param algorithm The SecureRandom algorithm to create. - * @param provider The provider to get the instance from. - * @throws NoSuchAlgorithmException If the algorithm cannot be found, or - * if the class cannot be instantiated. - * @throws IllegalArgumentException If <code>provider</code> is null. - */ - public static SecureRandom getInstance(String algorithm, Provider provider) - throws NoSuchAlgorithmException - { - if (provider == null) - throw new IllegalArgumentException("Illegal provider"); - try - { - return new SecureRandom((SecureRandomSpi) - Engine.getInstance(SECURE_RANDOM, algorithm, provider), - provider); - } - catch (java.lang.reflect.InvocationTargetException ite) - { - throw new NoSuchAlgorithmException(algorithm); - } - catch (ClassCastException cce) - { - throw new NoSuchAlgorithmException(algorithm); - } - } - - // Instance methods. - // ------------------------------------------------------------------------ - - /** - Returns the provider being used by the current SecureRandom class. - - @return The provider from which this SecureRandom was attained - */ - public final Provider getProvider() - { - return provider; - } - - /** - Seeds the SecureRandom. The class is re-seeded for each call and - each seed builds on the previous seed so as not to weaken security. - - @param seed seed bytes to seed with - */ - public void setSeed(byte[] seed) - { - secureRandomSpi.engineSetSeed(seed); - } - - /** - Seeds the SecureRandom. The class is re-seeded for each call and - each seed builds on the previous seed so as not to weaken security. - - @param seed 8 seed bytes to seed with - */ - public void setSeed(long seed) - { - // This particular setSeed will be called by Random.Random(), via - // our own constructor, before secureRandomSpi is initialized. In - // this case we can't call a method on secureRandomSpi, and we - // definitely don't want to throw a NullPointerException. - // Therefore we test. - if (secureRandomSpi != null) - { - byte[] tmp = { (byte) (0xff & (seed >> 56)), - (byte) (0xff & (seed >> 48)), - (byte) (0xff & (seed >> 40)), - (byte) (0xff & (seed >> 32)), - (byte) (0xff & (seed >> 24)), - (byte) (0xff & (seed >> 16)), - (byte) (0xff & (seed >> 8)), - (byte) (0xff & seed) - }; - secureRandomSpi.engineSetSeed(tmp); - } - } - - /** - Generates a user specified number of bytes. This function - is the basis for all the random functions. - - @param bytes array to store generated bytes in - */ - public void nextBytes(byte[] bytes) - { - randomBytesUsed += bytes.length; - counter++; - secureRandomSpi.engineNextBytes(bytes); - } - - /** - Generates an integer containing the user specified - number of random bits. It is right justified and padded - with zeros. - - @param numBits number of random bits to get, 0 <= numBits <= 32; - - @return the random bits - */ - protected final int next(int numBits) - { - if (numBits == 0) - return 0; - - byte[] tmp = new byte[numBits / 8 + (1 * (numBits % 8))]; - - secureRandomSpi.engineNextBytes(tmp); - randomBytesUsed += tmp.length; - counter++; - - int ret = 0; - - for (int i = 0; i < tmp.length; i++) - ret |= (tmp[i] & 0xFF) << (8 * i); - - long mask = (1L << numBits) - 1; - return (int) (ret & mask); - } - - /** - Returns the given number of seed bytes. This method is - maintained only for backwards capability. - - @param numBytes number of seed bytes to get - - @return an array containing the seed bytes - */ - public static byte[] getSeed(int numBytes) - { - byte[] tmp = new byte[numBytes]; - - new Random().nextBytes(tmp); - return tmp; - //return secureRandomSpi.engineGenerateSeed( numBytes ); - } - - /** - Returns the specified number of seed bytes. - - @param numBytes number of seed bytes to get - - @return an array containing the seed bytes - */ - public byte[] generateSeed(int numBytes) - { - return secureRandomSpi.engineGenerateSeed(numBytes); - } - -} diff --git a/libjava/java/security/SecureRandomSpi.java b/libjava/java/security/SecureRandomSpi.java deleted file mode 100644 index 7759097a456..00000000000 --- a/libjava/java/security/SecureRandomSpi.java +++ /dev/null @@ -1,85 +0,0 @@ -/* SecureRandomSpi.java --- Secure Random Service Provider Interface - Copyright (C) 1999, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security; -import java.io.Serializable; - -/** - SecureRandomSpi is the Service Provider Interface for SecureRandom - providers. It provides an interface for providers to the - SecureRandom engine to write their own pseudo-random number - generator. - - @since JDK 1.2 - - @author Mark Benvenuto (ivymccough@worldnet.att.net) - */ -public abstract class SecureRandomSpi implements Serializable -{ - private static final long serialVersionUID = -2991854161009191830L; - - /** - Default Constructor for SecureRandomSpi - */ - public SecureRandomSpi() - { - } - - /** - Updates the seed for SecureRandomSpi but does not reset seed. - It does to this so repeated called never decrease randomness. - */ - protected abstract void engineSetSeed(byte[] seed); - - /** - Gets a user specified number of bytes depending on the length - of the array? - - @param bytes array to fill with random bytes - */ - protected abstract void engineNextBytes(byte[] bytes); - - /** - Gets a user specified number of bytes specified by the - parameter. - - @param numBytes number of random bytes to generate - - @return an array full of random bytes - */ - protected abstract byte[] engineGenerateSeed(int numBytes); -} diff --git a/libjava/java/security/Security.java b/libjava/java/security/Security.java deleted file mode 100644 index 54b97923efd..00000000000 --- a/libjava/java/security/Security.java +++ /dev/null @@ -1,740 +0,0 @@ -/* Security.java --- Java base security class implementation - Copyright (C) 1999, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security; - -import gnu.classpath.SystemProperties; - -import gnu.classpath.Configuration; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.util.Collections; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedHashSet; -import java.util.Map; -import java.util.Properties; -import java.util.Set; -import java.util.Vector; - -/** - * This class centralizes all security properties and common security methods. - * One of its primary uses is to manage providers. - * - * @author Mark Benvenuto (ivymccough@worldnet.att.net) - */ -public final class Security -{ - private static final String ALG_ALIAS = "Alg.Alias."; - - private static Vector providers = new Vector(); - private static Properties secprops = new Properties(); - - static - { - String base = SystemProperties.getProperty("gnu.classpath.home.url"); - String vendor = SystemProperties.getProperty("gnu.classpath.vm.shortname"); - - // Try VM specific security file - boolean loaded = loadProviders (base, vendor); - - // Append classpath standard provider if possible - if (!loadProviders (base, "classpath") - && !loaded - && providers.size() == 0) - { - if (Configuration.DEBUG) - { - /* No providers found and both security files failed to - * load properly. Give a warning in case of DEBUG is - * enabled. Could be done with java.util.logging later. - */ - System.err.println - ("WARNING: could not properly read security provider files:"); - System.err.println - (" " + base + "/security/" + vendor - + ".security"); - System.err.println - (" " + base + "/security/" + "classpath" - + ".security"); - System.err.println - (" Falling back to standard GNU security provider"); - } - providers.addElement (new gnu.java.security.provider.Gnu()); - } - } - // This class can't be instantiated. - private Security() - { - } - - /** - * Tries to load the vender specific security providers from the given - * base URL. Returns true if the resource could be read and completely - * parsed successfully, false otherwise. - */ - private static boolean loadProviders(String baseUrl, String vendor) - { - if (baseUrl == null || vendor == null) - return false; - - boolean result = true; - String secfilestr = baseUrl + "/security/" + vendor + ".security"; - try - { - InputStream fin = new URL(secfilestr).openStream(); - secprops.load(fin); - - int i = 1; - String name; - while ((name = secprops.getProperty("security.provider." + i)) != null) - { - Exception exception = null; - try - { - providers.addElement(Class.forName(name).newInstance()); - } - catch (ClassNotFoundException x) - { - exception = x; - } - catch (InstantiationException x) - { - exception = x; - } - catch (IllegalAccessException x) - { - exception = x; - } - - if (exception != null) - { - System.err.println ("WARNING: Error loading security provider " - + name + ": " + exception); - result = false; - } - i++; - } - } - catch (IOException ignored) - { - result = false; - } - - return result; - } - - /** - * Gets a specified property for an algorithm. The algorithm name should be a - * standard name. See Appendix A in the Java Cryptography Architecture API - * Specification & Reference for information about standard algorithm - * names. One possible use is by specialized algorithm parsers, which may map - * classes to algorithms which they understand (much like {@link Key} parsers - * do). - * - * @param algName the algorithm name. - * @param propName the name of the property to get. - * @return the value of the specified property. - * @deprecated This method used to return the value of a proprietary property - * in the master file of the "SUN" Cryptographic Service Provider in order to - * determine how to parse algorithm-specific parameters. Use the new - * provider-based and algorithm-independent {@link AlgorithmParameters} and - * {@link KeyFactory} engine classes (introduced in the Java 2 platform) - * instead. - */ - public static String getAlgorithmProperty(String algName, String propName) - { - if (algName == null || propName == null) - return null; - - String property = String.valueOf(propName) + "." + String.valueOf(algName); - Provider p; - for (Iterator i = providers.iterator(); i.hasNext(); ) - { - p = (Provider) i.next(); - for (Iterator j = p.keySet().iterator(); j.hasNext(); ) - { - String key = (String) j.next(); - if (key.equalsIgnoreCase(property)) - return p.getProperty(key); - } - } - return null; - } - - /** - * <p>Adds a new provider, at a specified position. The position is the - * preference order in which providers are searched for requested algorithms. - * Note that it is not guaranteed that this preference will be respected. The - * position is 1-based, that is, <code>1</code> is most preferred, followed by - * <code>2</code>, and so on.</p> - * - * <p>If the given provider is installed at the requested position, the - * provider that used to be at that position, and all providers with a - * position greater than position, are shifted up one position (towards the - * end of the list of installed providers).</p> - * - * <p>A provider cannot be added if it is already installed.</p> - * - * <p>First, if there is a security manager, its <code>checkSecurityAccess() - * </code> method is called with the string <code>"insertProvider."+provider. - * getName()</code> to see if it's ok to add a new provider. If the default - * implementation of <code>checkSecurityAccess()</code> is used (i.e., that - * method is not overriden), then this will result in a call to the security - * manager's <code>checkPermission()</code> method with a - * <code>SecurityPermission("insertProvider."+provider.getName())</code> - * permission.</p> - * - * @param provider the provider to be added. - * @param position the preference position that the caller would like for - * this provider. - * @return the actual preference position in which the provider was added, or - * <code>-1</code> if the provider was not added because it is already - * installed. - * @throws SecurityException if a security manager exists and its - * {@link SecurityManager#checkSecurityAccess(String)} method denies access - * to add a new provider. - * @see #getProvider(String) - * @see #removeProvider(String) - * @see SecurityPermission - */ - public static int insertProviderAt(Provider provider, int position) - { - SecurityManager sm = System.getSecurityManager(); - if (sm != null) - sm.checkSecurityAccess("insertProvider." + provider.getName()); - - position--; - int max = providers.size (); - for (int i = 0; i < max; i++) - { - if (((Provider) providers.elementAt(i)).getName().equals(provider.getName())) - return -1; - } - - if (position < 0) - position = 0; - if (position > max) - position = max; - - providers.insertElementAt(provider, position); - - return position + 1; - } - - /** - * <p>Adds a provider to the next position available.</p> - * - * <p>First, if there is a security manager, its <code>checkSecurityAccess() - * </code> method is called with the string <code>"insertProvider."+provider. - * getName()</code> to see if it's ok to add a new provider. If the default - * implementation of <code>checkSecurityAccess()</code> is used (i.e., that - * method is not overriden), then this will result in a call to the security - * manager's <code>checkPermission()</code> method with a - * <code>SecurityPermission("insertProvider."+provider.getName())</code> - * permission.</p> - * - * @param provider the provider to be added. - * @return the preference position in which the provider was added, or - * <code>-1</code> if the provider was not added because it is already - * installed. - * @throws SecurityException if a security manager exists and its - * {@link SecurityManager#checkSecurityAccess(String)} method denies access - * to add a new provider. - * @see #getProvider(String) - * @see #removeProvider(String) - * @see SecurityPermission - */ - public static int addProvider(Provider provider) - { - return insertProviderAt (provider, providers.size () + 1); - } - - /** - * <p>Removes the provider with the specified name.</p> - * - * <p>When the specified provider is removed, all providers located at a - * position greater than where the specified provider was are shifted down - * one position (towards the head of the list of installed providers).</p> - * - * <p>This method returns silently if the provider is not installed.</p> - * - * <p>First, if there is a security manager, its <code>checkSecurityAccess() - * </code> method is called with the string <code>"removeProvider."+name</code> - * to see if it's ok to remove the provider. If the default implementation of - * <code>checkSecurityAccess()</code> is used (i.e., that method is not - * overriden), then this will result in a call to the security manager's - * <code>checkPermission()</code> method with a <code>SecurityPermission( - * "removeProvider."+name)</code> permission.</p> - * - * @param name the name of the provider to remove. - * @throws SecurityException if a security manager exists and its - * {@link SecurityManager#checkSecurityAccess(String)} method denies access - * to remove the provider. - * @see #getProvider(String) - * @see #addProvider(Provider) - */ - public static void removeProvider(String name) - { - SecurityManager sm = System.getSecurityManager(); - if (sm != null) - sm.checkSecurityAccess("removeProvider." + name); - - int max = providers.size (); - for (int i = 0; i < max; i++) - { - if (((Provider) providers.elementAt(i)).getName().equals(name)) - { - providers.remove(i); - break; - } - } - } - - /** - * Returns an array containing all the installed providers. The order of the - * providers in the array is their preference order. - * - * @return an array of all the installed providers. - */ - public static Provider[] getProviders() - { - Provider[] array = new Provider[providers.size ()]; - providers.copyInto (array); - return array; - } - - /** - * Returns the provider installed with the specified name, if any. Returns - * <code>null</code> if no provider with the specified name is installed. - * - * @param name the name of the provider to get. - * @return the provider of the specified name. - * @see #removeProvider(String) - * @see #addProvider(Provider) - */ - public static Provider getProvider(String name) - { - Provider p; - int max = providers.size (); - for (int i = 0; i < max; i++) - { - p = (Provider) providers.elementAt(i); - if (p.getName().equals(name)) - return p; - } - return null; - } - - /** - * <p>Gets a security property value.</p> - * - * <p>First, if there is a security manager, its <code>checkPermission()</code> - * method is called with a <code>SecurityPermission("getProperty."+key)</code> - * permission to see if it's ok to retrieve the specified security property - * value.</p> - * - * @param key the key of the property being retrieved. - * @return the value of the security property corresponding to key. - * @throws SecurityException if a security manager exists and its - * {@link SecurityManager#checkPermission(Permission)} method denies access - * to retrieve the specified security property value. - * @see #setProperty(String, String) - * @see SecurityPermission - */ - public static String getProperty(String key) - { - SecurityManager sm = System.getSecurityManager(); - if (sm != null) - sm.checkSecurityAccess("getProperty." + key); - - return secprops.getProperty(key); - } - - /** - * <p>Sets a security property value.</p> - * - * <p>First, if there is a security manager, its <code>checkPermission()</code> - * method is called with a <code>SecurityPermission("setProperty."+key)</code> - * permission to see if it's ok to set the specified security property value. - * </p> - * - * @param key the name of the property to be set. - * @param datnum the value of the property to be set. - * @throws SecurityException if a security manager exists and its - * {@link SecurityManager#checkPermission(Permission)} method denies access - * to set the specified security property value. - * @see #getProperty(String) - * @see SecurityPermission - */ - public static void setProperty(String key, String datnum) - { - SecurityManager sm = System.getSecurityManager(); - if (sm != null) - sm.checkSecurityAccess("setProperty." + key); - - secprops.put(key, datnum); - } - - /** - * Returns a Set of Strings containing the names of all available algorithms - * or types for the specified Java cryptographic service (e.g., Signature, - * MessageDigest, Cipher, Mac, KeyStore). Returns an empty Set if there is no - * provider that supports the specified service. For a complete list of Java - * cryptographic services, please see the Java Cryptography Architecture API - * Specification & Reference. Note: the returned set is immutable. - * - * @param serviceName the name of the Java cryptographic service (e.g., - * Signature, MessageDigest, Cipher, Mac, KeyStore). Note: this parameter is - * case-insensitive. - * @return a Set of Strings containing the names of all available algorithms - * or types for the specified Java cryptographic service or an empty set if - * no provider supports the specified service. - * @since 1.4 - */ - public static Set getAlgorithms(String serviceName) - { - HashSet result = new HashSet(); - if (serviceName == null || serviceName.length() == 0) - return result; - - serviceName = serviceName.trim(); - if (serviceName.length() == 0) - return result; - - serviceName = serviceName.toUpperCase()+"."; - Provider[] providers = getProviders(); - int ndx; - for (int i = 0; i < providers.length; i++) - for (Enumeration e = providers[i].propertyNames(); e.hasMoreElements(); ) - { - String service = ((String) e.nextElement()).trim(); - if (service.toUpperCase().startsWith(serviceName)) - { - service = service.substring(serviceName.length()).trim(); - ndx = service.indexOf(' '); // get rid of attributes - if (ndx != -1) - service = service.substring(0, ndx); - result.add(service); - } - } - return Collections.unmodifiableSet(result); - } - - /** - * <p>Returns an array containing all installed providers that satisfy the - * specified selection criterion, or <code>null</code> if no such providers - * have been installed. The returned providers are ordered according to their - * preference order.</p> - * - * <p>A cryptographic service is always associated with a particular - * algorithm or type. For example, a digital signature service is always - * associated with a particular algorithm (e.g., <i>DSA</i>), and a - * CertificateFactory service is always associated with a particular - * certificate type (e.g., <i>X.509</i>).</p> - * - * <p>The selection criterion must be specified in one of the following two - * formats:</p> - * - * <ul> - * <li><p><crypto_service>.<algorithm_or_type></p> - * <p>The cryptographic service name must not contain any dots.</p> - * <p>A provider satisfies the specified selection criterion iff the - * provider implements the specified algorithm or type for the specified - * cryptographic service.</p> - * <p>For example, "CertificateFactory.X.509" would be satisfied by any - * provider that supplied a CertificateFactory implementation for X.509 - * certificates.</p></li> - * - * <li><p><crypto_service>.<algorithm_or_type> <attribute_name>:<attribute_value></p> - * <p>The cryptographic service name must not contain any dots. There must - * be one or more space charaters between the the <algorithm_or_type> - * and the <attribute_name>.</p> - * <p>A provider satisfies this selection criterion iff the provider - * implements the specified algorithm or type for the specified - * cryptographic service and its implementation meets the constraint - * expressed by the specified attribute name/value pair.</p> - * <p>For example, "Signature.SHA1withDSA KeySize:1024" would be satisfied - * by any provider that implemented the SHA1withDSA signature algorithm - * with a keysize of 1024 (or larger).</p></li> - * </ul> - * - * <p>See Appendix A in the Java Cryptogaphy Architecture API Specification - * & Reference for information about standard cryptographic service names, - * standard algorithm names and standard attribute names.</p> - * - * @param filter the criterion for selecting providers. The filter is case- - * insensitive. - * @return all the installed providers that satisfy the selection criterion, - * or null if no such providers have been installed. - * @throws InvalidParameterException if the filter is not in the required - * format. - * @see #getProviders(Map) - */ - public static Provider[] getProviders(String filter) - { - if (providers == null || providers.isEmpty()) - return null; - - if (filter == null || filter.length() == 0) - return getProviders(); - - HashMap map = new HashMap(1); - int i = filter.indexOf(':'); - if (i == -1) // <service>.<algorithm> - map.put(filter, ""); - else // <service>.<algorithm> <attribute>:<value> - map.put(filter.substring(0, i), filter.substring(i+1)); - - return getProviders(map); - } - - /** - * <p>Returns an array containing all installed providers that satisfy the - * specified selection criteria, or <code>null</code> if no such providers - * have been installed. The returned providers are ordered according to their - * preference order.</p> - * - * <p>The selection criteria are represented by a map. Each map entry - * represents a selection criterion. A provider is selected iff it satisfies - * all selection criteria. The key for any entry in such a map must be in one - * of the following two formats:</p> - * - * <ul> - * <li><p><crypto_service>.<algorithm_or_type></p> - * <p>The cryptographic service name must not contain any dots.</p> - * <p>The value associated with the key must be an empty string.</p> - * <p>A provider satisfies this selection criterion iff the provider - * implements the specified algorithm or type for the specified - * cryptographic service.</p></li> - * - * <li><p><crypto_service>.<algorithm_or_type> <attribute_name></p> - * <p>The cryptographic service name must not contain any dots. There must - * be one or more space charaters between the <algorithm_or_type> and - * the <attribute_name>.</p> - * <p>The value associated with the key must be a non-empty string. A - * provider satisfies this selection criterion iff the provider implements - * the specified algorithm or type for the specified cryptographic service - * and its implementation meets the constraint expressed by the specified - * attribute name/value pair.</p></li> - * </ul> - * - * <p>See Appendix A in the Java Cryptogaphy Architecture API Specification - * & Reference for information about standard cryptographic service names, - * standard algorithm names and standard attribute names.</p> - * - * @param filter the criteria for selecting providers. The filter is case- - * insensitive. - * @return all the installed providers that satisfy the selection criteria, - * or <code>null</code> if no such providers have been installed. - * @throws InvalidParameterException if the filter is not in the required - * format. - * @see #getProviders(String) - */ - public static Provider[] getProviders(Map filter) - { - if (providers == null || providers.isEmpty()) - return null; - - if (filter == null) - return getProviders(); - - Set querries = filter.keySet(); - if (querries == null || querries.isEmpty()) - return getProviders(); - - LinkedHashSet result = new LinkedHashSet(providers); // assume all - int dot, ws; - String querry, service, algorithm, attribute, value; - LinkedHashSet serviceProviders = new LinkedHashSet(); // preserve insertion order - for (Iterator i = querries.iterator(); i.hasNext(); ) - { - querry = (String) i.next(); - if (querry == null) // all providers - continue; - - querry = querry.trim(); - if (querry.length() == 0) // all providers - continue; - - dot = querry.indexOf('.'); - if (dot == -1) // syntax error - throw new InvalidParameterException( - "missing dot in '" + String.valueOf(querry)+"'"); - - value = (String) filter.get(querry); - // deconstruct querry into [service, algorithm, attribute] - if (value == null || value.trim().length() == 0) // <service>.<algorithm> - { - value = null; - attribute = null; - service = querry.substring(0, dot).trim(); - algorithm = querry.substring(dot+1).trim(); - } - else // <service>.<algorithm> <attribute> - { - ws = querry.indexOf(' '); - if (ws == -1) - throw new InvalidParameterException( - "value (" + String.valueOf(value) + - ") is not empty, but querry (" + String.valueOf(querry) + - ") is missing at least one space character"); - value = value.trim(); - attribute = querry.substring(ws+1).trim(); - // was the dot in the attribute? - if (attribute.indexOf('.') != -1) - throw new InvalidParameterException( - "attribute_name (" + String.valueOf(attribute) + - ") in querry (" + String.valueOf(querry) + ") contains a dot"); - - querry = querry.substring(0, ws).trim(); - service = querry.substring(0, dot).trim(); - algorithm = querry.substring(dot+1).trim(); - } - - // service and algorithm must not be empty - if (service.length() == 0) - throw new InvalidParameterException( - "<crypto_service> in querry (" + String.valueOf(querry) + - ") is empty"); - - if (algorithm.length() == 0) - throw new InvalidParameterException( - "<algorithm_or_type> in querry (" + String.valueOf(querry) + - ") is empty"); - - selectProviders(service, algorithm, attribute, value, result, serviceProviders); - result.retainAll(serviceProviders); // eval next retaining found providers - if (result.isEmpty()) // no point continuing - break; - } - - if (result.isEmpty()) - return null; - - return (Provider[]) result.toArray(new Provider[0]); - } - - private static void selectProviders(String svc, String algo, String attr, - String val, LinkedHashSet providerSet, - LinkedHashSet result) - { - result.clear(); // ensure we start with an empty result set - for (Iterator i = providerSet.iterator(); i.hasNext(); ) - { - Provider p = (Provider) i.next(); - if (provides(p, svc, algo, attr, val)) - result.add(p); - } - } - - private static boolean provides(Provider p, String svc, String algo, - String attr, String val) - { - Iterator it; - String serviceDotAlgorithm = null; - String key = null; - String realVal; - boolean found = false; - // if <svc>.<algo> <attr> is in the set then so is <svc>.<algo> - // but it may be stored under an alias <algo>. resolve - outer: for (int r = 0; r < 3; r++) // guard against circularity - { - serviceDotAlgorithm = (svc+"."+String.valueOf(algo)).trim(); - for (it = p.keySet().iterator(); it.hasNext(); ) - { - key = (String) it.next(); - if (key.equalsIgnoreCase(serviceDotAlgorithm)) // eureka - { - found = true; - break outer; - } - // it may be there but as an alias - if (key.equalsIgnoreCase(ALG_ALIAS + serviceDotAlgorithm)) - { - algo = p.getProperty(key); - continue outer; - } - // else continue inner - } - } - - if (!found) - return false; - - // found a candidate for the querry. do we have an attr to match? - if (val == null) // <service>.<algorithm> querry - return true; - - // <service>.<algorithm> <attribute>; find the key entry that match - String realAttr; - int limit = serviceDotAlgorithm.length() + 1; - for (it = p.keySet().iterator(); it.hasNext(); ) - { - key = (String) it.next(); - if (key.length() <= limit) - continue; - - if (key.substring(0, limit).equalsIgnoreCase(serviceDotAlgorithm+" ")) - { - realAttr = key.substring(limit).trim(); - if (! realAttr.equalsIgnoreCase(attr)) - continue; - - // eveything matches so far. do the value - realVal = p.getProperty(key); - if (realVal == null) - return false; - - realVal = realVal.trim(); - // is it a string value? - if (val.equalsIgnoreCase(realVal)) - return true; - - // assume value is a number. cehck for greater-than-or-equal - return (new Integer(val).intValue() >= new Integer(realVal).intValue()); - } - } - - return false; - } -} diff --git a/libjava/java/security/SecurityPermission.java b/libjava/java/security/SecurityPermission.java deleted file mode 100644 index 6aba18f346e..00000000000 --- a/libjava/java/security/SecurityPermission.java +++ /dev/null @@ -1,178 +0,0 @@ -/* SecurityPermission.java -- Class for named security permissions - Copyright (C) 1998, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security; - -/** - * This class provides a mechanism for specified named permissions - * related to the Java security framework. These permissions have no - * associated actions list. They are either granted or not granted. - * - * <p>The list of valid permission names is:<br> - * <table border=1> - * <tr><th>Permission Name</th><th>Permission Allows</th><th>Risks</th</tr> - * <tr> - * <td><code>createAccessControlContext</code></td> - * <td>Allows creation of an AccessControlContext</td> - * <td>The new control context can have a rogue DomainCombiner, leading - * to a privacy leak</td></tr> - * <tr> - * <td><code>getDomainCombiner</code></td> - * <td>Get a DomainCombiner from an AccessControlContext</td> - * <td>Access to a DomainCombiner can lead to a privacy leak</td></tr> - * <tr> - * <td><code>getPolicy</code></td> - * <td>Allows retrieval of the system security policy</td> - * <td>Malicious code can use information from the policy to better plan - * an attack</td></tr> - * <tr> - * <td><code>setPolicy</code></td> - * <td>Allows the security policy to be changed</td> - * <td>Malicious code can give itself any permission it wants</td></tr> - * <tr> - * <td><code>getProperty.</code><em>key</em></td> - * <td>Retrieve the property specified by the key</td> - * <td>Malicious code can use information from the property to better plan - * an attack</td></tr> - * <tr> - * <td><code>setProperty.</code><em>key</em></td> - * <td>Allows changing of the value of all properties implied by key</td> - * <td>Malicious code can insert rogue classes to steal keys or recreate - * the security policy with whatever permissions it desires</td></tr> - * <tr> - * <td><code>insertProvider.</code><em>key</em></td> - * <td>Allows the named provider to be added</td> - * <td>Malicious code can insert rogue providers that steal data</td></tr> - * <tr> - * <td><code>removeProvider.</code><em>key</em></td> - * <td>Allows the named provider to be removed</td> - * <td>A missing provider can cripple code that relies on it</td></tr> - * <tr> - * <td><code>setSystemScope</code></td> - * <td>Allows the system identity scope to be set</td> - * <td>Malicious code can add certificates not available in the original - * identity scope, to gain more permissions</td></tr> - * <tr> - * <td><code>setIdentityPublicKey</code></td> - * <td>Allows the public key of an Identity to be set</td> - * <td>Malicious code can install its own key to gain permissions not - * allowed by the original identity scope</td></tr> - * <tr> - * <td><code>SetIdentityInfo</code></td> - * <td>Allows the description of an Identity to be set</td> - * <td>Malicious code can spoof users into trusting a fake identity</td></tr> - * <tr> - * <td><code>addIdentityCertificate</code></td> - * <td>Allows a certificate to be set for the public key of an identity</td> - * <td>The public key can become trusted to a wider audience than originally - * intended</td></tr> - * <tr> - * <td><code>removeIdentityCertificate</code></td> - * <td>Allows removal of a certificate from an identity's public key</td> - * <td>The public key can become less trusted than it should be</td></tr> - * <tr> - * <td><code>printIdentity</code></td> - * <td>View the name of the identity and scope, and whether they are - * trusted</td> - * <td>The scope may include a filename, which provides an entry point for - * further security breaches</td></tr> - * <tr> - * <td><code>clearProviderProperties.</code><em>key</em></td> - * <td>Allows the properties of the named provider to be cleared</td> - * <td>This can disable parts of the program which depend on finding the - * provider</td></tr> - * <tr> - * <td><code>putProviderProperty.</code><em>key</em></td> - * <td>Allows the properties of the named provider to be changed</td> - * <td>Malicious code can replace the implementation of a provider</td></tr> - * <tr> - * <td><code>removeProviderProperty.</code><em>key</em></td> - * <td>Allows the properties of the named provider to be deleted</td> - * <td>This can disable parts of the program which depend on finding the - * provider</td></tr> - * <tr> - * <td><code>getSignerPrivateKey</code></td> - * <td>Allows the retrieval of the private key for a signer</td> - * <td>Anyone that can access the private key can claim to be the - * Signer</td></tr> - * <tr> - * <td><code>setSignerKeyPair</code></td> - * <td>Allows the public and private key of a Signer to be changed</td> - * <td>The replacement might be a weaker encryption, or the attacker - * can use knowledge of the replaced key to decrypt an entire - * communication session</td></tr> - * </table> - * - * <p>There is some degree of security risk in granting any of these - * permissions. Some of them can completely compromise system security. - * Please exercise extreme caution in granting these permissions. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @see Permission - * @see SecurityManager - * @since 1.1 - * @status updated to 1.4 - */ -public final class SecurityPermission extends BasicPermission -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = 5236109936224050470L; - - /** - * Create a new instance with the specified name. - * - * @param name the name to assign to this permission - */ - public SecurityPermission(String name) - { - super(name); - } - - /** - * Create a new instance with the specified name. As SecurityPermission - * carries no actions, the second parameter is ignored. - * - * @param name the name to assign to this permission - * @param actions ignored - */ - public SecurityPermission(String name, String actions) - { - super(name); - } -} // class SecurityPermission diff --git a/libjava/java/security/Signature.java b/libjava/java/security/Signature.java deleted file mode 100644 index 852c959220f..00000000000 --- a/libjava/java/security/Signature.java +++ /dev/null @@ -1,636 +0,0 @@ -/* Signature.java --- Signature Class - Copyright (C) 1999, 2002, 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security; - -import gnu.java.security.Engine; - -import java.security.cert.Certificate; -import java.security.cert.X509Certificate; -import java.security.spec.AlgorithmParameterSpec; - -/** - * <p>This <code>Signature</code> class is used to provide applications the - * functionality of a digital signature algorithm. Digital signatures are used - * for authentication and integrity assurance of digital data.</p> - * - * <p>The signature algorithm can be, among others, the NIST standard <i>DSS</i>, - * using <i>DSA</i> and <i>SHA-1</i>. The <i>DSA</i> algorithm using the - * <i>SHA-1</i> message digest algorithm can be specified as <code>SHA1withDSA - * </code>. In the case of <i>RSA</i>, there are multiple choices for the - * message digest algorithm, so the signing algorithm could be specified as, for - * example, <code>MD2withRSA</code>, <code>MD5withRSA</code>, or - * <code>SHA1withRSA</code>. The algorithm name must be specified, as there is - * no default.</p> - * - * <p>Like other algorithm-based classes in Java Security, <code>Signature</code> - * provides implementation-independent algorithms, whereby a caller (application - * code) requests a particular signature algorithm and is handed back a properly - * initialized <code>Signature</code> object. It is also possible, if desired, - * to request a particular algorithm from a particular provider. See the - * <code>getInstance()</code> methods.</p> - * - * <p>Thus, there are two ways to request a <code>Signature</code> algorithm - * object: by specifying either just an algorithm name, or both an algorithm - * name and a package provider.</p> - * - * <p>If just an algorithm name is specified, the system will determine if there - * is an implementation of the algorithm requested available in the environment, - * and if there is more than one, if there is a preferred one.</p> - * - * <p>If both an algorithm name and a package provider are specified, the system - * will determine if there is an implementation of the algorithm in the package - * requested, and throw an exception if there is not.</p> - * - * <p>A <code>Signature</code> object can be used to generate and verify digital - * signatures.</p> - * - * <p>There are three phases to the use of a <code>Signature</code> object for - * either signing data or verifying a signature:</p> - * - * <ol> - * <li>Initialization, with either - * <ul> - * <li>a public key, which initializes the signature for verification - * (see <code>initVerify()</code>), or</li> - * <li>a private key (and optionally a Secure Random Number Generator), - * which initializes the signature for signing (see - * {@link #initSign(PrivateKey)} and {@link #initSign(PrivateKey, SecureRandom)} - * ).</li> - * </ul></li> - * <li>Updating<br/> - * Depending on the type of initialization, this will update the bytes to - * be signed or verified. See the update methods.<br/></li> - * <li>Signing or Verifying a signature on all updated bytes. See the - * <code>sign()</code> methods and the <code>verify()</code> method.</li> - * </ol> - * - * <p>Note that this class is abstract and extends from {@link SignatureSpi} for - * historical reasons. Application developers should only take notice of the - * methods defined in this <code>Signature</code> class; all the methods in the - * superclass are intended for cryptographic service providers who wish to - * supply their own implementations of digital signature algorithms. - * - * @author Mark Benvenuto (ivymccough@worldnet.att.net) - */ -public abstract class Signature extends SignatureSpi -{ - /** Service name for signatures. */ - private static final String SIGNATURE = "Signature"; - - /** - * Possible <code>state</code> value, signifying that this signature object - * has not yet been initialized. - */ - protected static final int UNINITIALIZED = 0; - - // Constructor. - // ------------------------------------------------------------------------ - - /** - * Possible <code>state</code> value, signifying that this signature object - * has been initialized for signing. - */ - protected static final int SIGN = 2; - - /** - * Possible <code>state</code> value, signifying that this signature object - * has been initialized for verification. - */ - protected static final int VERIFY = 3; - - /** Current state of this signature object. */ - protected int state = UNINITIALIZED; - - private String algorithm; - Provider provider; - - /** - * Creates a <code>Signature</code> object for the specified algorithm. - * - * @param algorithm the standard string name of the algorithm. See Appendix A - * in the Java Cryptography Architecture API Specification & Reference for - * information about standard algorithm names. - */ - protected Signature(String algorithm) - { - this.algorithm = algorithm; - state = UNINITIALIZED; - } - - /** - * Generates a <code>Signature</code> object that implements the specified - * digest algorithm. If the default provider package provides an - * implementation of the requested digest algorithm, an instance of - * <code>Signature</code> containing that implementation is returned. If the - * algorithm is not available in the default package, other packages are - * searched. - * - * @param algorithm the standard name of the algorithm requested. See Appendix - * A in the Java Cryptography Architecture API Specification & Reference - * for information about standard algorithm names. - * @return the new Signature object. - * @throws NoSuchAlgorithmException if the algorithm is not available in the - * environment. - */ - public static Signature getInstance(String algorithm) - throws NoSuchAlgorithmException - { - Provider[] p = Security.getProviders(); - for (int i = 0; i < p.length; i++) - { - try - { - return getInstance(algorithm, p[i]); - } - catch (NoSuchAlgorithmException e) - { - // Ignored. - } - } - - throw new NoSuchAlgorithmException(algorithm); - } - - /** - * Generates a <code>Signature</code> object implementing the specified - * algorithm, as supplied from the specified provider, if such an algorithm - * is available from the provider. - * - * @param algorithm the name of the algorithm requested. See Appendix A in - * the Java Cryptography Architecture API Specification & Reference for - * information about standard algorithm names. - * @param provider the name of the provider. - * @return the new <code>Signature</code> object. - * @throws NoSuchAlgorithmException if the algorithm is not available in the - * package supplied by the requested provider. - * @throws NoSuchProviderException if the provider is not available in the - * environment. - * @throws IllegalArgumentException if the provider name is <code>null</code> - * or empty. - * @see Provider - */ - public static Signature getInstance(String algorithm, String provider) - throws NoSuchAlgorithmException, NoSuchProviderException - { - if (provider == null || provider.length() == 0) - throw new IllegalArgumentException("Illegal provider"); - - Provider p = Security.getProvider(provider); - if (p == null) - throw new NoSuchProviderException(provider); - - return getInstance(algorithm, p); - } - - /** - * Generates a <code>Signature</code> object implementing the specified - * algorithm, as supplied from the specified provider, if such an algorithm - * is available from the provider. Note: the provider doesn't have to be - * registered. - * - * @param algorithm the name of the algorithm requested. See Appendix A in - * the Java Cryptography Architecture API Specification & Reference for - * information about standard algorithm names. - * @param provider the provider. - * @return the new <code>Signature</code> object. - * @throws NoSuchAlgorithmException if the <code>algorithm</code> is not - * available in the package supplied by the requested <code>provider</code>. - * @throws IllegalArgumentException if the <code>provider</code> is - * <code>null</code>. - * @since 1.4 - * @see Provider - */ - public static Signature getInstance(String algorithm, Provider provider) - throws NoSuchAlgorithmException - { - if (provider == null) - throw new IllegalArgumentException("Illegal provider"); - - Signature result = null; - Object o = null; - try - { - o = Engine.getInstance(SIGNATURE, algorithm, provider); - } - catch (java.lang.reflect.InvocationTargetException ite) - { - throw new NoSuchAlgorithmException(algorithm); - } - - if (o instanceof SignatureSpi) - { - result = new DummySignature((SignatureSpi) o, algorithm); - } - else if (o instanceof Signature) - { - result = (Signature) o; - result.algorithm = algorithm; - } - else - { - throw new NoSuchAlgorithmException(algorithm); - } - result.provider = provider; - return result; - } - - /** - * Returns the provider of this signature object. - * - * @return the provider of this signature object. - */ - public final Provider getProvider() - { - return provider; - } - - /** - * Initializes this object for verification. If this method is called again - * with a different argument, it negates the effect of this call. - * - * @param publicKey the public key of the identity whose signature is going - * to be verified. - * @throws InvalidKeyException if the key is invalid. - */ - public final void initVerify(PublicKey publicKey) throws InvalidKeyException - { - state = VERIFY; - engineInitVerify(publicKey); - } - - /** - * <p>Initializes this object for verification, using the public key from the - * given certificate.</p> - * - * <p>If the certificate is of type <i>X.509</i> and has a <i>key usage</i> - * extension field marked as <i>critical</i>, and the value of the <i>key - * usage</i> extension field implies that the public key in the certificate - * and its corresponding private key are not supposed to be used for digital - * signatures, an {@link InvalidKeyException} is thrown.</p> - * - * @param certificate the certificate of the identity whose signature is - * going to be verified. - * @throws InvalidKeyException if the public key in the certificate is not - * encoded properly or does not include required parameter information or - * cannot be used for digital signature purposes. - */ - public final void initVerify(Certificate certificate) - throws InvalidKeyException - { - state = VERIFY; - if (certificate.getType().equals("X509")) - { - X509Certificate cert = (X509Certificate) certificate; - boolean[]array = cert.getKeyUsage(); - if (array != null && array[0] == false) - throw new InvalidKeyException( - "KeyUsage of this Certificate indicates it cannot be used for digital signing"); - } - this.initVerify(certificate.getPublicKey()); - } - - /** - * Initialize this object for signing. If this method is called again with a - * different argument, it negates the effect of this call. - * - * @param privateKey the private key of the identity whose signature is going - * to be generated. - * @throws InvalidKeyException if the key is invalid. - */ - public final void initSign(PrivateKey privateKey) throws InvalidKeyException - { - state = SIGN; - engineInitSign(privateKey); - } - - /** - * Initialize this object for signing. If this method is called again with a - * different argument, it negates the effect of this call. - * - * @param privateKey the private key of the identity whose signature is going - * to be generated. - * @param random the source of randomness for this signature. - * @throws InvalidKeyException if the key is invalid. - */ - public final void initSign(PrivateKey privateKey, SecureRandom random) - throws InvalidKeyException - { - state = SIGN; - engineInitSign(privateKey, random); - } - - /** - * <p>Returns the signature bytes of all the data updated. The format of the - * signature depends on the underlying signature scheme.</p> - * - * <p>A call to this method resets this signature object to the state it was - * in when previously initialized for signing via a call to - * <code>initSign(PrivateKey)</code>. That is, the object is reset and - * available to generate another signature from the same signer, if desired, - * via new calls to <code>update()</code> and <code>sign()</code>.</p> - * - * @return the signature bytes of the signing operation's result. - * @throws SignatureException if this signature object is not initialized - * properly. - */ - public final byte[] sign() throws SignatureException - { - if (state == SIGN) - return engineSign(); - else - throw new SignatureException(); - } - - /** - * <p>Finishes the signature operation and stores the resulting signature - * bytes in the provided buffer <code>outbuf</code>, starting at <code>offset - * </code>. The format of the signature depends on the underlying signature - * scheme.</p> - * - * <p>This signature object is reset to its initial state (the state it was - * in after a call to one of the <code>initSign()</code> methods) and can be - * reused to generate further signatures with the same private key.</p> - * - * @param outbuf buffer for the signature result. - * @param offset offset into outbuf where the signature is stored. - * @param len number of bytes within outbuf allotted for the signature. - * @return the number of bytes placed into outbuf. - * @throws SignatureException if an error occurs or len is less than the - * actual signature length. - * @since 1.2 - */ - public final int sign(byte[] outbuf, int offset, int len) - throws SignatureException - { - if (state == SIGN) - return engineSign(outbuf, offset, len); - else - throw new SignatureException(); - } - - /** - * <p>Verifies the passed-in signature.</p> - * - * <p>A call to this method resets this signature object to the state it was - * in when previously initialized for verification via a call to - * <code>initVerify(PublicKey)</code>. That is, the object is reset and - * available to verify another signature from the identity whose public key - * was specified in the call to <code>initVerify()</code>.</p> - * - * @param signature the signature bytes to be verified. - * @return <code>true</code> if the signature was verified, <code>false</code> - * if not. - * @throws SignatureException if this signature object is not initialized - * properly, or the passed-in signature is improperly encoded or of the wrong - * type, etc. - */ - public final boolean verify(byte[]signature) throws SignatureException - { - if (state == VERIFY) - return engineVerify(signature); - else - throw new SignatureException(); - } - - /** - * <p>Verifies the passed-in <code>signature</code> in the specified array of - * bytes, starting at the specified <code>offset</code>.</p> - * - * <p>A call to this method resets this signature object to the state it was - * in when previously initialized for verification via a call to - * <code>initVerify(PublicKey)</code>. That is, the object is reset and - * available to verify another signature from the identity whose public key - * was specified in the call to <code>initVerify()</code>.</p> - * - * @param signature the signature bytes to be verified. - * @param offset the offset to start from in the array of bytes. - * @param length the number of bytes to use, starting at offset. - * @return <code>true</code> if the signature was verified, <code>false</code> - * if not. - * @throws SignatureException if this signature object is not initialized - * properly, or the passed-in <code>signature</code> is improperly encoded or - * of the wrong type, etc. - * @throws IllegalArgumentException if the <code>signature</code> byte array - * is <code>null</code>, or the <code>offset</code> or <code>length</code> is - * less than <code>0</code>, or the sum of the <code>offset</code> and - * <code>length</code> is greater than the length of the <code>signature</code> - * byte array. - */ - public final boolean verify(byte[] signature, int offset, int length) - throws SignatureException - { - if (state != VERIFY) - throw new SignatureException("illegal state"); - - if (signature == null) - throw new IllegalArgumentException("signature is null"); - if (offset < 0) - throw new IllegalArgumentException("offset is less than 0"); - if (length < 0) - throw new IllegalArgumentException("length is less than 0"); - if (offset + length < signature.length) - throw new IllegalArgumentException("range is out of bounds"); - - return engineVerify(signature, offset, length); - } - - /** - * Updates the data to be signed or verified by a byte. - * - * @param b the byte to use for the update. - * @throws SignatureException if this signature object is not initialized - * properly. - */ - public final void update(byte b) throws SignatureException - { - if (state != UNINITIALIZED) - engineUpdate(b); - else - throw new SignatureException(); - } - - /** - * Updates the data to be signed or verified, using the specified array of - * bytes. - * - * @param data the byte array to use for the update. - * @throws SignatureException if this signature object is not initialized - * properly. - */ - public final void update(byte[]data) throws SignatureException - { - if (state != UNINITIALIZED) - engineUpdate(data, 0, data.length); - else - throw new SignatureException(); - } - - /** - * Updates the data to be signed or verified, using the specified array of - * bytes, starting at the specified offset. - * - * @param data the array of bytes. - * @param off the offset to start from in the array of bytes. - * @param len the number of bytes to use, starting at offset. - * @throws SignatureException if this signature object is not initialized - * properly. - */ - public final void update(byte[]data, int off, int len) - throws SignatureException - { - if (state != UNINITIALIZED) - engineUpdate(data, off, len); - else - throw new SignatureException(); - } - - /** - * Returns the name of the algorithm for this signature object. - * - * @return the name of the algorithm for this signature object. - */ - public final String getAlgorithm() - { - return algorithm; - } - - /** - * Returns a string representation of this signature object, providing - * information that includes the state of the object and the name of the - * algorithm used. - * - * @return a string representation of this signature object. - */ - public String toString() - { - return (algorithm + " Signature"); - } - - /** - * Sets the specified algorithm parameter to the specified value. This method - * supplies a general-purpose mechanism through which it is possible to set - * the various parameters of this object. A parameter may be any settable - * parameter for the algorithm, such as a parameter size, or a source of - * random bits for signature generation (if appropriate), or an indication of - * whether or not to perform a specific but optional computation. A uniform - * algorithm-specific naming scheme for each parameter is desirable but left - * unspecified at this time. - * - * @param param the string identifier of the parameter. - * @param value the parameter value. - * @throws InvalidParameterException if param is an invalid parameter for this - * signature algorithm engine, the parameter is already set and cannot be set - * again, a security exception occurs, and so on. - * @see #getParameter(String) - * @deprecated Use setParameter(AlgorithmParameterSpec). - */ - public final void setParameter(String param, Object value) - throws InvalidParameterException - { - engineSetParameter(param, value); - } - - /** - * Initializes this signature engine with the specified parameter set. - * - * @param params the parameters. - * @throws InvalidAlgorithmParameterException if the given parameters are - * inappropriate for this signature engine. - * @see #getParameters() - */ - public final void setParameter(AlgorithmParameterSpec params) - throws InvalidAlgorithmParameterException - { - engineSetParameter(params); - } - - /** - * <p>Returns the parameters used with this signature object.</p> - * - * <p>The returned parameters may be the same that were used to initialize - * this signature, or may contain a combination of default and randomly - * generated parameter values used by the underlying signature implementation - * if this signature requires algorithm parameters but was not initialized - * with any. - * - * @return the parameters used with this signature, or <code>null</code> if - * this signature does not use any parameters. - * @see #setParameter(AlgorithmParameterSpec) - */ - public final AlgorithmParameters getParameters() - { - return engineGetParameters(); - } - - /** - * Gets the value of the specified algorithm parameter. This method supplies - * a general-purpose mechanism through which it is possible to get the various - * parameters of this object. A parameter may be any settable parameter for - * the algorithm, such as a parameter size, or a source of random bits for - * signature generation (if appropriate), or an indication of whether or not - * to perform a specific but optional computation. A uniform - * algorithm-specific naming scheme for each parameter is desirable but left - * unspecified at this time. - * - * @param param the string name of the parameter. - * @return the object that represents the parameter value, or null if there - * is none. - * @throws InvalidParameterException if param is an invalid parameter for this - * engine, or another exception occurs while trying to get this parameter. - * @see #setParameter(String, Object) - * @deprecated - */ - public final Object getParameter(String param) - throws InvalidParameterException - { - return engineGetParameter(param); - } - - /** - * Returns a clone if the implementation is cloneable. - * - * @return a clone if the implementation is cloneable. - * @throws CloneNotSupportedException if this is called on an implementation - * that does not support {@link Cloneable}. - */ - public Object clone() throws CloneNotSupportedException - { - return super.clone(); - } -} diff --git a/libjava/java/security/SignatureException.java b/libjava/java/security/SignatureException.java deleted file mode 100644 index e294c16c3f6..00000000000 --- a/libjava/java/security/SignatureException.java +++ /dev/null @@ -1,70 +0,0 @@ -/* SignatureException.java -- Generic error in signature - Copyright (C) 1998, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security; - -/** - * This exception is thrown when a problem is encountered with a - * digital signature. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @status updated to 1.4 - */ -public class SignatureException extends GeneralSecurityException -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = 7509989324975124438L; - - /** - * Create an instance with no descriptive error message. - */ - public SignatureException() - { - } - - /** - * Create an instance with a descriptive error message. - * - * @param msg the message - */ - public SignatureException(String msg) - { - super(msg); - } -} diff --git a/libjava/java/security/SignatureSpi.java b/libjava/java/security/SignatureSpi.java deleted file mode 100644 index 471a73d17cd..00000000000 --- a/libjava/java/security/SignatureSpi.java +++ /dev/null @@ -1,302 +0,0 @@ -/* SignatureSpi.java --- Signature Service Provider Interface - Copyright (C) 1999, 2003, Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security; - -import java.security.spec.AlgorithmParameterSpec; - -/** - * <p>This class defines the <i>Service Provider Interface (SPI)</i> for the - * {@link Signature} class, which is used to provide the functionality of a - * digital signature algorithm. Digital signatures are used for authentication - * and integrity assurance of digital data.</p> - * - * <p>All the abstract methods in this class must be implemented by each - * cryptographic service provider who wishes to supply the implementation of a - * particular signature algorithm. - * - * @author Mark Benvenuto (ivymccough@worldnet.att.net) - * @since 1.2 - * @see Signature - */ -public abstract class SignatureSpi -{ - /** Application-specified source of randomness. */ - protected SecureRandom appRandom; - - public SignatureSpi() - { - appRandom = null; - } - - /** - * Initializes this signature object with the specified public key for - * verification operations. - * - * @param publicKey the public key of the identity whose signature is going - * to be verified. - * @throws InvalidKeyException if the key is improperly encoded, parameters - * are missing, and so on. - */ - protected abstract void engineInitVerify(PublicKey publicKey) - throws InvalidKeyException; - - /** - * Initializes this signature object with the specified private key for - * signing operations. - * - * @param privateKey the private key of the identity whose signature will be - * generated. - * @throws InvalidKeyException if the key is improperly encoded, parameters - * are missing, and so on. - */ - protected abstract void engineInitSign(PrivateKey privateKey) - throws InvalidKeyException; - - /** - * <p>Initializes this signature object with the specified private key and - * source of randomness for signing operations.</p> - * - * <p>This concrete method has been added to this previously-defined abstract - * class. (For backwards compatibility, it cannot be abstract.)</p> - * - * @param privateKey the private key of the identity whose signature will be - * generated. - * @param random the source of randomness. - * @throws InvalidKeyException if the key is improperly encoded, parameters - * are missing, and so on. - * @since 1.2 - */ - protected void engineInitSign(PrivateKey privateKey, SecureRandom random) - throws InvalidKeyException - { - appRandom = random; - engineInitSign(privateKey); - } - - /** - * Updates the data to be signed or verified using the specified byte. - * - * @param b the byte to use for the update. - * @throws SignatureException if the engine is not initialized properly. - */ - protected abstract void engineUpdate(byte b) throws SignatureException; - - /** - * Updates the data to be signed or verified, using the specified array of - * bytes, starting at the specified offset. - * - * @param b the array of bytes. - * @param off the offset to start from in the array of bytes. - * @param len the number of bytes to use, starting at offset. - * @throws SignatureException if the engine is not initialized properly. - */ - protected abstract void engineUpdate(byte[] b, int off, int len) - throws SignatureException; - - /** - * Returns the signature bytes of all the data updated so far. The format of - * the signature depends on the underlying signature scheme. - * - * @return the signature bytes of the signing operation's result. - * @throws SignatureException if the engine is not initialized properly. - */ - protected abstract byte[] engineSign() throws SignatureException; - - /** - * <p>Finishes this signature operation and stores the resulting signature - * bytes in the provided buffer <code>outbuf</code>, starting at <code>offset - * </code>. The format of the signature depends on the underlying signature - * scheme.</p> - * - * <p>The signature implementation is reset to its initial state (the state it - * was in after a call to one of the <code>engineInitSign()</code> methods) - * and can be reused to generate further signatures with the same private key. - * This method should be abstract, but we leave it concrete for binary - * compatibility. Knowledgeable providers should override this method.</p> - * - * @param outbuf buffer for the signature result. - * @param offset offset into outbuf where the signature is stored. - * @param len number of bytes within outbuf allotted for the signature. Both - * this default implementation and the <b>GNU</b> provider do not return - * partial digests. If the value of this parameter is less than the actual - * signature length, this method will throw a {@link SignatureException}. This - * parameter is ignored if its value is greater than or equal to the actual - * signature length. - * @return the number of bytes placed into <code>outbuf</code>. - * @throws SignatureException if an error occurs or len is less than the - * actual signature length. - * @since 1.2 - */ - protected int engineSign(byte[] outbuf, int offset, int len) - throws SignatureException - { - byte[] tmp = engineSign(); - if (tmp.length > len) - throw new SignatureException("Invalid Length"); - - System.arraycopy(outbuf, offset, tmp, 0, tmp.length); - return tmp.length; - } - - /** - * Verifies the passed-in signature. - * - * @param sigBytes the signature bytes to be verified. - * @return <code>true</code> if the signature was verified, <code>false</code> - * if not. - * @throws SignatureException if the engine is not initialized properly, or - * the passed-in signature is improperly encoded or of the wrong type, etc. - */ - protected abstract boolean engineVerify(byte[] sigBytes) - throws SignatureException; - - /** - * <p>Verifies the passed-in <code>signature</code> in the specified array of - * bytes, starting at the specified <code>offset</code>.</p> - * - * <p>Note: Subclasses should overwrite the default implementation.</p> - * - * @param sigBytes the signature bytes to be verified. - * @param offset the offset to start from in the array of bytes. - * @param length the number of bytes to use, starting at offset. - * @return <code>true</code> if the signature was verified, <code>false</code> - * if not. - * @throws SignatureException if the engine is not initialized properly, or - * the passed-in <code>signature</code> is improperly encoded or of the wrong - * type, etc. - */ - protected boolean engineVerify(byte[] sigBytes, int offset, int length) - throws SignatureException - { - byte[] tmp = new byte[length]; - System.arraycopy(sigBytes, offset, tmp, 0, length); - return engineVerify(tmp); - } - - /** - * Sets the specified algorithm parameter to the specified value. This method - * supplies a general-purpose mechanism through which it is possible to set - * the various parameters of this object. A parameter may be any settable - * parameter for the algorithm, such as a parameter size, or a source of - * random bits for signature generation (if appropriate), or an indication of - * whether or not to perform a specific but optional computation. A uniform - * algorithm-specific naming scheme for each parameter is desirable but left - * unspecified at this time. - * - * @param param the string identifier of the parameter. - * @param value the parameter value. - * @throws InvalidParameterException if <code>param</code> is an invalid - * parameter for this signature algorithm engine, the parameter is already set - * and cannot be set again, a security exception occurs, and so on. - * @deprecated Replaced by engineSetParameter(AlgorithmParameterSpec). - */ - protected abstract void engineSetParameter(String param, Object value) - throws InvalidParameterException; - - /** - * This method is overridden by providers to initialize this signature engine - * with the specified parameter set. - * - * @param params the parameters. - * @throws UnsupportedOperationException if this method is not overridden by - * a provider. - * @throws InvalidAlgorithmParameterException if this method is overridden by - * a provider and the the given parameters are inappropriate for this - * signature engine. - */ - protected void engineSetParameter(AlgorithmParameterSpec params) - throws InvalidAlgorithmParameterException - { - throw new UnsupportedOperationException(); - } - - /** - * <p>This method is overridden by providers to return the parameters used - * with this signature engine, or <code>null</code> if this signature engine - * does not use any parameters.</p> - * - * <p>The returned parameters may be the same that were used to initialize - * this signature engine, or may contain a combination of default and randomly - * generated parameter values used by the underlying signature implementation - * if this signature engine requires algorithm parameters but was not - * initialized with any.</p> - * - * @return the parameters used with this signature engine, or <code>null</code> - * if this signature engine does not use any parameters. - * @throws UnsupportedOperationException if this method is not overridden by - * a provider. - */ - protected AlgorithmParameters engineGetParameters() - { - throw new UnsupportedOperationException(); - } - - /** - * Gets the value of the specified algorithm parameter. This method supplies - * a general-purpose mechanism through which it is possible to get the various - * parameters of this object. A parameter may be any settable parameter for - * the algorithm, such as a parameter size, or a source of random bits for - * signature generation (if appropriate), or an indication of whether or not - * to perform a specific but optional computation. A uniform algorithm-specific - * naming scheme for each parameter is desirable but left unspecified at this - * time. - * - * @param param the string name of the parameter. - * @return the object that represents the parameter value, or <code>null</code> - * if there is none. - * @throws InvalidParameterException if <code>param</code> is an invalid - * parameter for this engine, or another exception occurs while trying to get - * this parameter. - * @deprecated - */ - protected abstract Object engineGetParameter(String param) - throws InvalidParameterException; - - /** - * Returns a clone if the implementation is cloneable. - * - * @return a clone if the implementation is cloneable. - * @throws CloneNotSupportedException if this is called on an implementation - * that does not support {@link Cloneable}. - * @see Cloneable - */ - public Object clone() throws CloneNotSupportedException - { - return super.clone(); - } -} diff --git a/libjava/java/security/SignedObject.java b/libjava/java/security/SignedObject.java deleted file mode 100644 index d565b2ea3b4..00000000000 --- a/libjava/java/security/SignedObject.java +++ /dev/null @@ -1,240 +0,0 @@ -/* SignedObject.java --- Signed Object Class - Copyright (C) 1999, 2003, Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; - -/** - * <p><code>SignedObject</code> is a class for the purpose of creating authentic - * runtime objects whose integrity cannot be compromised without being detected. - * </p> - * - * <p>More specifically, a <code>SignedObject</code> contains another - * {@link Serializable} object, the (to-be-)signed object and its signature.</p> - * - * <p>The signed object is a <i>"deep copy"</i> (in serialized form) of an - * original object. Once the copy is made, further manipulation of the original - * object has no side effect on the copy.</p> - * - * <p>The underlying signing algorithm is designated by the {@link Signature} - * object passed to the constructor and the <code>verify()</code> method. A - * typical usage for signing is the following:</p> - * - * <pre> - * Signature signingEngine = Signature.getInstance(algorithm, provider); - * SignedObject so = new SignedObject(myobject, signingKey, signingEngine); - * </pre> - * - * <p>A typical usage for verification is the following (having received - * <code>SignedObject</code> so):</p> - * - * <pre> - * Signature verificationEngine = Signature.getInstance(algorithm, provider); - * if (so.verify(publickey, verificationEngine)) - * try - * { - * Object myobj = so.getObject(); - * } - * catch (ClassNotFoundException ignored) {}; - * </pre> - * - * <p>Several points are worth noting. First, there is no need to initialize the - * signing or verification engine, as it will be re-initialized inside the - * constructor and the <code>verify()</code> method. Secondly, for verification - * to succeed, the specified public key must be the public key corresponding to - * the private key used to generate the <code>SignedObject</code>.</p> - * - * <p>More importantly, for flexibility reasons, the <code>constructor</code> - * and <code>verify()</code> method allow for customized signature engines, - * which can implement signature algorithms that are not installed formally as - * part of a crypto provider. However, it is crucial that the programmer writing - * the verifier code be aware what {@link Signature} engine is being used, as - * its own implementation of the <code>verify()</code> method is invoked to - * verify a signature. In other words, a malicious {@link Signature} may choose - * to always return <code>true</code> on verification in an attempt to bypass a - * security check.</p> - * - * <p>The signature algorithm can be, among others, the NIST standard <i>DSS</i>, - * using <i>DSA</i> and <i>SHA-1</i>. The algorithm is specified using the same - * convention as that for signatures. The <i>DSA</i> algorithm using the - * <i>SHA-1</i> message digest algorithm can be specified, for example, as - * <code>"SHA/DSA"</code> or <code>"SHA-1/DSA"</code> (they are equivalent). In - * the case of <i>RSA</i>, there are multiple choices for the message digest - * algorithm, so the signing algorithm could be specified as, for example, - * <code>"MD2/RSA"</code>, <code>"MD5/RSA"</code> or <code>"SHA-1/RSA"</code>. - * The algorithm name must be specified, as there is no default.</p> - * - * <p>The name of the Cryptography Package Provider is designated also by the - * {@link Signature} parameter to the <code>constructor</code> and the <code> - * verify()</code> method. If the provider is not specified, the default - * provider is used. Each installation can be configured to use a particular - * provider as default.</p> - * - * <p>Potential applications of <code>SignedObject</code> include:</p> - * - * <ul> - * <li>It can be used internally to any Java runtime as an unforgeable - * authorization token -- one that can be passed around without the fear that - * the token can be maliciously modified without being detected.</li> - * <li>It can be used to sign and serialize data/object for storage outside the - * Java runtime (e.g., storing critical access control data on disk).</li> - * <li>Nested <i>SignedObjects</i> can be used to construct a logical sequence - * of signatures, resembling a chain of authorization and delegation.</li> - * </ul> - * - * @author Mark Benvenuto (ivymccough@worldnet.att.net) - * @since 1.2 - * @see Signature - */ -public final class SignedObject implements Serializable -{ - private static final long serialVersionUID = 720502720485447167L; - - /** @serial */ - private byte[] content; - /** @serial */ - private byte[] signature; - /** @serial */ - private String thealgorithm; - - /** - * Constructs a <code>SignedObject</code> from any {@link Serializable} - * object. The given object is signed with the given signing key, using the - * designated signature engine. - * - * @param object the object to be signed. - * @param signingKey the private key for signing. - * @param signingEngine the signature signing engine. - * @throws IOException if an error occurs during serialization. - * @throws InvalidKeyException if the key is invalid. - * @throws SignatureException if signing fails. - */ - public SignedObject(Serializable object, PrivateKey signingKey, - Signature signingEngine) - throws IOException, InvalidKeyException, SignatureException - { - thealgorithm = signingEngine.getAlgorithm(); - - ByteArrayOutputStream ostream = new ByteArrayOutputStream(); - ObjectOutputStream p = new ObjectOutputStream(ostream); - p.writeObject(object); - p.flush(); - p.close(); - - content = ostream.toByteArray(); - - signingEngine.initSign(signingKey); - signingEngine.update(content); - signature = signingEngine.sign(); - } - - /** - * Retrieves the encapsulated object. The encapsulated object is de-serialized - * before it is returned. - * - * @return the encapsulated object. - * @throws IOException if an error occurs during de-serialization. - * @throws ClassNotFoundException if an error occurs during de-serialization. - */ - public Object getObject() throws IOException, ClassNotFoundException - { - ByteArrayInputStream bais = new ByteArrayInputStream(content); - ObjectInput oi = new ObjectInputStream(bais); - Object obj = oi.readObject(); - oi.close(); - bais.close(); - - return obj; - } - - /** - * Retrieves the signature on the signed object, in the form of a byte array. - * - * @return a copy of the signature. - */ - public byte[] getSignature() - { - return (byte[]) signature.clone(); - - } - - /** - * Retrieves the name of the signature algorithm. - * - * @return the signature algorithm name. - */ - public String getAlgorithm() - { - return thealgorithm; - } - - /** - * Verifies that the signature in this <code>SignedObject</code> is the valid - * signature for the object stored inside, with the given verification key, - * using the designated verification engine. - * - * @param verificationKey the public key for verification. - * @param verificationEngine the signature verification engine. - * @return <code>true</code> if the signature is valid, <code>false</code> - * otherwise. - * @throws SignatureException if signature verification failed. - * @throws InvalidKeyException if the verification key is invalid. - */ - public boolean verify(PublicKey verificationKey, Signature verificationEngine) - throws InvalidKeyException, SignatureException - { - verificationEngine.initVerify(verificationKey); - verificationEngine.update(content); - return verificationEngine.verify(signature); - } - - /** Called to restore the state of the SignedObject from a stream. */ - private void readObject(ObjectInputStream s) - throws IOException, ClassNotFoundException - { - s.defaultReadObject(); - content = (byte[]) content.clone(); - signature = (byte[]) signature.clone(); - } -} diff --git a/libjava/java/security/Signer.java b/libjava/java/security/Signer.java deleted file mode 100644 index ae1463db84c..00000000000 --- a/libjava/java/security/Signer.java +++ /dev/null @@ -1,164 +0,0 @@ -/* Signer.java --- Signer Class - Copyright (C) 1999, 2003, Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security; - -/** - * <p>This class is used to represent an {@link Identity} that can also - * digitally sign data.</p> - * - * <p>The management of a signer's private keys is an important and sensitive - * issue that should be handled by subclasses as appropriate to their intended - * use.</p> - * - * @author Mark Benvenuto (ivymccough@worldnet.att.net) - * @deprecated This class is no longer used. Its functionality has been replaced - * by <code>java.security.KeyStore</code>, the <code>java.security.cert</code> - * package, and <code>java.security.Principal</code>. - */ -public abstract class Signer extends Identity -{ - private static final long serialVersionUID = -1763464102261361480L; - private PrivateKey privateKey = null; - - /** - * Creates a <code>Signer</code>. This constructor should only be used for - * serialization. - */ - protected Signer() - { - } - - /** - * Creates a <code>Signer</code> with the specified identity name. - * - * @param name the identity name. - */ - public Signer(String name) - { - super(name); - } - - /** - * Creates a <code>Signer</code> with the specified identity name and scope. - * - * @param name the identity name. - * @param scope the scope of the identity. - * @throws KeyManagementException if there is already an identity with the - * same name in the scope. - */ - public Signer(String name, IdentityScope scope) throws KeyManagementException - { - super(name, scope); - } - - /** - * <p>Returns this signer's private key.</p> - * - * <p>First, if there is a security manager, its <code>checkSecurityAccess() - * </code> method is called with <code>"getSignerPrivateKey"</code> as its - * argument to see if it's ok to return the private key.</p> - * - * @return this signer's private key, or <code>null</code> if the private key - * has not yet been set. - * @throws SecurityException if a security manager exists and its - * <code>checkSecurityAccess()</code> method doesn't allow returning the - * private key. - * @see SecurityManager#checkSecurityAccess(String) - */ - public PrivateKey getPrivateKey() - { - SecurityManager sm = System.getSecurityManager(); - if (sm != null) - sm.checkSecurityAccess("getSignerPrivateKey"); - - return privateKey; - } - - /** - * <p>Sets the key pair (public key and private key) for this signer.</p> - * - * <p>First, if there is a security manager, its <code>checkSecurityAccess() - * </code> method is called with <code>"setSignerKeyPair"</code> as its - * argument to see if it's ok to set the key pair.</p> - * - * @param pair an initialized key pair. - * @throws InvalidParameterException if the key pair is not properly - * initialized. - * @throws KeyException if the key pair cannot be set for any other reason. - * @throws SecurityException if a security manager exists and its - * <code>checkSecurityAccess()</code> method doesn't allow setting the key - * pair. - * @see SecurityManager#checkSecurityAccess(String) - */ - public final void setKeyPair(KeyPair pair) - throws InvalidParameterException, KeyException - { - SecurityManager sm = System.getSecurityManager(); - if (sm != null) - sm.checkSecurityAccess("setSignerKeyPair"); - - try - { - if (pair.getPublic() != null) - setPublicKey(pair.getPublic()); - else - throw new InvalidParameterException(); - - } - catch (KeyManagementException kme) - { - throw new KeyException(); - } - - if (pair.getPrivate() != null) - privateKey = pair.getPrivate(); - else - throw new InvalidParameterException(); - } - - /** - * Returns a string of information about the signer. - * - * @return a string of information about the signer. - * @see SecurityManager#checkSecurityAccess(String) - */ - public String toString() - { - return (getName() + ": " + privateKey); - } -} diff --git a/libjava/java/security/UnrecoverableKeyException.java b/libjava/java/security/UnrecoverableKeyException.java deleted file mode 100644 index 6759c3c7b91..00000000000 --- a/libjava/java/security/UnrecoverableKeyException.java +++ /dev/null @@ -1,71 +0,0 @@ -/* UnrecoverableKeyException.java -- Cannot recover a key from the key store - Copyright (C) 1998, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security; - -/** - * This exception is thrown when a key cannot be recovered from the key - * store. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @since 1.2 - * @status updated to 1.4 - */ -public class UnrecoverableKeyException extends GeneralSecurityException -{ - /** - * Compatible with JDK 1.2+. - */ - private static final long serialVersionUID = 7275063078190151277L; - - /** - * Create an instance with no descriptive error message. - */ - public UnrecoverableKeyException() - { - } - - /** - * Create an instance with a descriptive error message. - * - * @param msg the descriptive error message - */ - public UnrecoverableKeyException(String msg) - { - super(msg); - } -} diff --git a/libjava/java/security/UnresolvedPermission.java b/libjava/java/security/UnresolvedPermission.java deleted file mode 100644 index d3f671a9c06..00000000000 --- a/libjava/java/security/UnresolvedPermission.java +++ /dev/null @@ -1,304 +0,0 @@ -/* UnresolvedPermission.java -- Placeholder for unresolved permissions - Copyright (C) 1998, 2001, 2002, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security; - -// All uses of Certificate in this file refer to the one in the listed -// package, not this one. -import java.security.cert.Certificate; -import java.util.Arrays; -import java.util.Enumeration; -import java.util.Hashtable; -import java.util.NoSuchElementException; -import java.util.Vector; - -/** - * This class is used to hold instances of all permissions that cannot - * be resolved to available permission classes when the security - * <code>Policy</code> object is instantiated. This may happen when the - * necessary security class has not yet been downloaded from the network. - * - * <p>Instances of this class are re-resolved when - * <code>AccessController</code> check is done. At that time, a scan is - * made of all existing <code>UnresolvedPermission</code> objects and they - * are converted to objects of the appropriate permission type if the class - * for that type is then available. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @see Permission - * @see Permissions - * @see PermissionCollection - * @see Policy - * @since 1.1 - * @status updated to 1.4 - */ -public final class UnresolvedPermission extends Permission -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = -4821973115467008846L; - - /** - * The list of actions associated with this permission object. - * - * @serial the permission actions - */ - private final String actions; - - /** - * The list of <code>Certificates</code> associated with this object. - */ - private final transient Certificate[] certs; - - /** - * The name of the class this object should be resolved to. - * - * @serial the fully-qualified classname of the resolved type - */ - // Package visible for use by UnresolvedPermissionCollection. - final String type; - - /** - * The name of the permission. - * - * @serial the permission name - */ - private final String name; - - /** - * Create a new instance with all the information necessary to resolve it - * to an instance of the proper class at a future time. - * - * @param type the fully-qualified name of the class of this permission - * @param name the name of this permission - * @param actions the action list for this permission - * @param certs the list of certificates that sign this permission - */ - public UnresolvedPermission(String type, String name, String actions, - Certificate[] certs) - { - super(name); - this.name = name; - this.type = type; - this.actions = actions; - this.certs = certs; - } - - /** - * This method returns <code>false</code> always to indicate that this - * permission does not imply the specified permission. An - * <code>UnresolvedPermission</code> never grants any permissions. - * - * @param perm the <code>Permission</code> object to test - * @return false; until a permission is resolved, it implies nothing - */ - public boolean implies(Permission perm) - { - return false; - } - - /** - * This method tests this permission for equality against the specified - * <code>Object</code>. This will be true if and only if the following - * conditions are met:<ul> - * <li>The specified <code>Object</code> is an UnresolvedPermission</li> - * <li>The specified permission has the same type (i.e., desired class name) - * as this permission.</li> - * <li>The specified permission has the same name as this one.</li> - * <li>The specified permissoin has the same action list as this one.</li> - * <li>The specified permission has the same certificate list as this - * one.</li> - * </ul> - * - * @param obj the <code>Object</code> to test for equality - * @return true if the specified object is equal to this one - */ - public boolean equals(Object obj) - { - if (! (obj instanceof UnresolvedPermission)) - return (false); - UnresolvedPermission up = (UnresolvedPermission) obj; - return up.name.equals(name) && up.actions.equals(actions) - && up.type.equals(type) && Arrays.equals(up.certs, certs); - } - - /** - * Returns a hash code value for this object. Following the lead of - * Permission, this returns the hashcode of the permission name. - * - * @return A hash value - */ - public int hashCode() - { - return name.hashCode(); - } - - /** - * This method returns the list of actions associated with this - * permission. - * - * @return the action list - */ - public String getActions() - { - return actions; - } - - /** - * This method returns a <code>String</code> representation of this - * class. The format is: '(unresolved "ClassName "name" "actions")' - * - * @return <code>String</code> representation of this object - */ - public String toString() - { - return "(unresolved " + type + ' ' + name + ' ' + actions + ')'; - } - - /** - * This class returns a <code>PermissionCollection</code> object that can - * be used to store instances of <code>UnresolvedPermission</code>. - * - * @return a new <code>PermissionCollection</code> - */ - public PermissionCollection newPermissionCollection() - { - return new UnresolvedPermissionCollection(); - } -} // class UnresolvedPermission - -/** - * Implements the permission collection for unresolved permissions, and - * obeys serialization of JDK. - * - * @author Eric Blake (ebb9@email.byu.edu) - */ -class UnresolvedPermissionCollection extends PermissionCollection -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = -7176153071733132400L; - - // Package-private to avoid a trampoline. - /** - * Hashtable where we store permissions. - * - * @serial map of typename to a Vector of permissions (you'd think Sun - * would document this better!) - */ - final Hashtable permissions = new Hashtable(); - - /** - * Add a permission. - * - * @param perm the permission to add - * @throws IllegalArgumentException if perm is not an UnresolvedPermission - * @throws SecurityException if the collection is read-only - */ - public void add(Permission perm) - { - if (isReadOnly()) - throw new SecurityException(); - if (! (perm instanceof UnresolvedPermission)) - throw new IllegalArgumentException(); - UnresolvedPermission up = (UnresolvedPermission) perm; - Vector v = (Vector) permissions.get(up.type); - if (v == null) - { - v = new Vector(); - permissions.put(up.type, v); - } - v.add(up); - } - - /** - * Returns true if perm is implied by the collection. - * - * @param perm the permission to check - * @return false; unresolved permissions imply nothing - */ - public boolean implies(Permission perm) - { - return false; - } - - /** - * Return the elements. - * - * @return the elements - */ - public Enumeration elements() - { - return new Enumeration() - { - Enumeration main_enum = permissions.elements(); - Enumeration sub_enum; - - public boolean hasMoreElements() - { - if (sub_enum == null) - { - if (main_enum == null) - return false; - if (! main_enum.hasMoreElements()) - { - main_enum = null; - return false; - } - Vector v = (Vector) main_enum.nextElement(); - sub_enum = v.elements(); - } - if (! sub_enum.hasMoreElements()) - { - sub_enum = null; - return hasMoreElements(); - } - return true; - } - - public Object nextElement() - { - if (! hasMoreElements()) - throw new NoSuchElementException(); - return sub_enum.nextElement(); - } - }; - } -} // class UnresolvedPermissionCollection diff --git a/libjava/java/security/acl/Acl.java b/libjava/java/security/acl/Acl.java deleted file mode 100644 index ff139afd6c0..00000000000 --- a/libjava/java/security/acl/Acl.java +++ /dev/null @@ -1,153 +0,0 @@ -/* Acl.java -- An access control list - Copyright (C) 1998 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security.acl; - -import java.security.Principal; -import java.util.Enumeration; - -/** - * A Java access control list (ACL) is a group of individual ACL entries. - * These entries consist of a <code>Principal</code> and a list of - * permissions this <code>Principal</code> is either granted or denied. - * A given <code>Principal</code> can have at most one positive ACL entry - * (i.e., one that grants permissions) and one negative ACL entry (i.e., one - * that denies permissions). If a given permission is both granted and - * denied, the ACL treats it as if it were never granted or denied. If - * both a <code>Principal</code> and a <code>Group</code> to which the - * <code>Principal</code> belongs have an ACL entry, the permissions for - * the individual <code>Principal</code> take precedence over the - * permissions of the <code>Group</code> if there is a conflict. - * <p> - * Additionally, the ACL interface extends the <code>Owner</code> interface - * and so an ACL has owners. Actions which modify the ACL are restricted - * to owners. - * - * @version 0.0 - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public interface Acl extends Owner -{ - - /** - * This method returns the name of this ACL. - * - * @return The name of this ACL - */ - String getName(); - - /** - * This method sets the name of the ACL - * - * @param caller The <code>Principal</code> requesting the action. - * @param name The new name for this ACL. - * - * @exception NotOwnerException If the caller is not an owner of this ACL. - */ - void setName(Principal caller, String name) - throws NotOwnerException; - - /** - * This method adds the specified entry to the ACL - * - * @param caller The <code>Principal</code> requesting the addition - * @param entry The ACL entry to add - * - * @return <code>true</code> if the entry was added, <code>false</code> - * if there is already an entry of the same type for the - * <code>Principal</code>. - * - * @exception NotOwnerException If the caller is not an owner of this ACL. - */ - boolean addEntry(Principal caller, AclEntry entry) - throws NotOwnerException; - - /** - * This method delets the specified entry from the ACL - * - * @param caller The <code>Principal</code> requesting the deletion. - * @param entry The ACL entry to delete - * - * @return <code>true</code> if the entry was deleted, or <code>false</code> - * if this entry was not part of the ACL to begin with - * - * @exception NotOwnerException If the caller is not an owner of this ACL. - */ - boolean removeEntry(Principal caller, AclEntry entry) - throws NotOwnerException; - - /** - * This method returns a list of all the entries in the ACL as an - * <code>Enumeration</code>. - * - * @return An enumeration of the ACL entries - */ - Enumeration entries(); - - /** - * This method tests whether or not the specified <code>Principal</code> - * has the specified <code>Permission</code> - * - * @param user The <code>Principal</code> to test - * @param perm The <code>Permission</code> to test for - * - * @return <code>true</code> if the user has been granted the permission, - * <code>false</code> otherwise - */ - boolean checkPermission(Principal user, Permission perm); - - /** - * This method returns a list of <code>Permission</code>'s that are granted - * to a particular <code>Principal</code>. This includes any permissions - * that are granted to <code>Group</code>'s to which the <code>Principal</code> - * belongs unless they are overridden by a negative ACL. This permission - * list is returned as an <code>Enumeration</code>. - * - * @param user The <code>Principal</code> to retrieve permissions for. - * - * @return A list of permissions for the <code>Principal</code>. - */ - Enumeration getPermissions(Principal user); - - /** - * This method returns the ACL as a <code>String</code> - * - * @return A <code>String</code> representation of this ACL - */ - String toString(); -} diff --git a/libjava/java/security/acl/AclEntry.java b/libjava/java/security/acl/AclEntry.java deleted file mode 100644 index 7b1bcf54db9..00000000000 --- a/libjava/java/security/acl/AclEntry.java +++ /dev/null @@ -1,143 +0,0 @@ -/* AclEntry.java -- An entry in an ACL list. - Copyright (C) 1998 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security.acl; - -import java.security.Principal; -import java.util.Enumeration; - -/** - * This interface models an entry in an access control list (ACL). Java - * ACL's consist of a list of entries, where each consists of a - * <code>Principal</code> and a list of <code>Permission</code>'s which - * have been granted to that <code>Principal</code>. An ACL can also - * be <em>negative</em>, which indicates that the list of - * <code>Permission</code>'s is a list of permissions that are <em>not</em> - * granted to the <code>Principal</code>. A <code>Principal</code> can - * have at most one regular (or positive) ACL entry and one negative - * ACL entry. - * - * @version 0.0 - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public interface AclEntry extends Cloneable -{ - /** - * This method returns the <code>Principal</code> associated with this - * ACL entry. - * - * @return The <code>Principal</code> for this ACL entry - */ - Principal getPrincipal(); - - /** - * This method sets ths <code>Principal</code> associated with this - * ACL entry. This operation will only succeed if there is not already - * a <code>Principal</code> assigned. - * - * @param user The <code>Principal</code> for this ACL entry - * - * @return <code>true</code> if the <code>Principal</code> was successfully set or <code>false</code> if this entry already has a <code>Principal</code>. - */ - boolean setPrincipal(Principal user); - - /** - * This method sets this ACL entry to be a <em>negative</em> entry, indicating - * that it contains a list of permissions that are <em>not</em> granted - * to the entry's <code>Principal</code>. Note that there is no way to - * undo this operation. - */ - void setNegativePermissions(); - - /** - * This method tests whether or not this ACL entry is a negative entry or not. - * - * @return <code>true</code> if this ACL entry is negative, <code>false</code> otherwise - */ - boolean isNegative(); - - /** - * This method adds the specified permission to this ACL entry. - * - * @param perm The <code>Permission</code> to add - * - * @return <code>true</code> if the permission was added or <code>false</code> if it was already set for this entry - */ - boolean addPermission(Permission permission); - - /** - * This method deletes the specified permission to this ACL entry. - * - * @param perm The <code>Permission</code> to delete from this ACL entry. - * - * @return <code>true</code> if the permission was successfully deleted or <code>false</code> if the permission was not part of this ACL to begin with - */ - boolean removePermission(Permission perm); - - /** - * This method tests whether or not the specified permission is associated - * with this ACL entry. - * - * @param perm The <code>Permission</code> to test - * - * @return <code>true</code> if this permission is associated with this entry or <code>false</code> otherwise - */ - boolean checkPermission(Permission permission); - - /** - * This method returns a list of all <code>Permission</code> objects - * associated with this ACL entry as an <code>Enumeration</code>. - * - * @return A list of permissions for this ACL entry - */ - Enumeration permissions(); - - /** - * This method returns this object as a <code>String</code>. - * - * @return A <code>String</code> representation of this object - */ - String toString(); - - /** - * This method returns a clone of this ACL entry - * - * @return A clone of this ACL entry - */ - Object clone(); -} diff --git a/libjava/java/security/acl/AclNotFoundException.java b/libjava/java/security/acl/AclNotFoundException.java deleted file mode 100644 index 9a16d9c50b0..00000000000 --- a/libjava/java/security/acl/AclNotFoundException.java +++ /dev/null @@ -1,60 +0,0 @@ -/* AclNotFoundException.java -- thrown when an ACL is not found - Copyright (C) 1998, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security.acl; - -/** - * This exception is thrown when a requested access control list (ACL) is - * not found. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @status updated to 1.4 - */ -public class AclNotFoundException extends Exception -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = 5684295034092681791L; - - /** - * Initializes a new instance of this class with no descriptive message - */ - public AclNotFoundException() - { - } -} diff --git a/libjava/java/security/acl/Group.java b/libjava/java/security/acl/Group.java deleted file mode 100644 index 3ffdf15a4ce..00000000000 --- a/libjava/java/security/acl/Group.java +++ /dev/null @@ -1,90 +0,0 @@ -/* Group.java -- Represents a group of Principals - Copyright (C) 1998, 2001 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security.acl; - -import java.security.Principal; -import java.util.Enumeration; - -/** - * This interface represents a group of <code>Principals</code>. Note that - * since this interface extends <code>Principal</code>, a <code>Group</code> - * can be used where ever a <code>Principal</code> is requested. This - * includes arguments to the methods in this interface. - * - * @version 0.0 - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public interface Group extends Principal -{ - /** - * This method adds a new <code>Principal</code> to this group. - * - * @param user The new <code>Principal</code> to add - * - * @return <code>true</code> if the user was successfully added or <code>false</code> if the user is already a member - */ - boolean addMember(Principal user); - - /** - * This method deletes a member from the group. - * - * @param user The <code>Principal</code> to delete - * - * @return <code>true</code> if the user was successfully deleted or <code>false</code> if the user is not a member of the group - */ - boolean removeMember(Principal user); - - /** - * This method tests whether or not a given <code>Principal</code> is a - * member of this group. - * - * @param user The <code>Principal</code> to test for membership - * - * @return <code>true</code> if the user is member, <code>false</code> otherwise - */ - boolean isMember(Principal member); - - /** - * This method returns a list of all members of the group as an - * <code>Enumeration</code>. - * - * @return The list of all members of the group - */ - Enumeration members(); -} diff --git a/libjava/java/security/acl/LastOwnerException.java b/libjava/java/security/acl/LastOwnerException.java deleted file mode 100644 index 95272445997..00000000000 --- a/libjava/java/security/acl/LastOwnerException.java +++ /dev/null @@ -1,62 +0,0 @@ -/* LastOwnerException.java -- User attempted to delete last ACL owner - Copyright (C) 1998, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security.acl; - -/** - * This exception is thrown when an attempt is made to delete the last owner - * of an access control list (ACL) - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @see Owner#deleteOwner(java.security.Principal, java.security.Principal) - * @status updated to 1.4 - */ -public class LastOwnerException extends Exception -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = -5141997548211140359L; - - /** - * Initialize a new instance of <code>LastOwnerException</code> that does - * not have a log message. - */ - public LastOwnerException() - { - } -} diff --git a/libjava/java/security/acl/NotOwnerException.java b/libjava/java/security/acl/NotOwnerException.java deleted file mode 100644 index bea94763e4b..00000000000 --- a/libjava/java/security/acl/NotOwnerException.java +++ /dev/null @@ -1,62 +0,0 @@ -/* NotOwnerException.java -- Attempt to modify an unowned ACL - Copyright (C) 1998, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security.acl; - -/** - * This exception is thrown whenever an operation is attempted that requires - * the caller to be the owner of the access control list (ACL) when the caller - * is in fact not the owner of the ACL. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @status updated to 1.4 - */ -public class NotOwnerException extends Exception -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = -5555597911163362399L; - - /** - * Initializes a new instance of <code>NotOwnerException</code> that does - * not have a descriptive message. - */ - public NotOwnerException() - { - } -} diff --git a/libjava/java/security/acl/Owner.java b/libjava/java/security/acl/Owner.java deleted file mode 100644 index df1605b2e4f..00000000000 --- a/libjava/java/security/acl/Owner.java +++ /dev/null @@ -1,95 +0,0 @@ -/* Owner.java -- ACL owner - Copyright (C) 1998 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security.acl; - -import java.security.Principal; - -/** - * This interface provides a mechanism for maintaining a list of owners - * of an access control list (ACL). Since a <code>Principal</code> must - * be an owner in order to modify the owner list, a mechanism must be - * provided to specify the initial owner of the ACL. The proper way to do - * this is for the implementing class to specify the initial owner in - * the contructor for that class. - * - * @version 0.0 - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public interface Owner -{ - /** - * This method adds an owner to the access control list (ACL). Only a - * <code>Principal</code> who is already an owner can perform this operation. - * - * @param caller The <code>Principal</code> who is requesting that an owner be added - * @param owner The <code>Principal</code> to add as a new owner - * - * @param <code>true</code> if the new owner was successfully added or <code>false</code> if the specified new owner is already an owner - * - * @exception NotOwnerException If the caller is not already an owner of this ACL - */ - boolean addOwner(Principal caller, Principal owner) - throws NotOwnerException; - - /** - * This method delets an owner from the access control list (ACL). Only a - * <code>Principal</code> who is an owner can perform this operation. An - * owner can delete itself from the list. If there is only one - * owner remaining on this list, any attempt to delete it will throw an - * exception. - * - * @param caller The <code>Principal</code> who is requesting that an owner be deleted - * @param owner The <code>Principal</code> to delete as an owner - * - * @param <code>true</code> if the new owner was successfully deleted or <code>false</code> if the specified owner is not currently an owner - * - * @exception NotOwnerException If the caller is not already an owner of this ACL - * @exception LastOwnerException If completing the operation would delete the last ACL owner - */ - boolean deleteOwner(Principal caller, Principal owner) - throws NotOwnerException, LastOwnerException; - - /** - * This method tests whether or not a given <code>Principal</code> is an - * owner of this access control list (ACL). - * - * @return <code>true</code> if the <code>Principal</code> is an owner, <code>false</code> otherwise - */ - boolean isOwner(Principal owner); -} diff --git a/libjava/java/security/acl/Permission.java b/libjava/java/security/acl/Permission.java deleted file mode 100644 index e5ba2913890..00000000000 --- a/libjava/java/security/acl/Permission.java +++ /dev/null @@ -1,67 +0,0 @@ -/* Permission.java -- Information about an ACL permission - Copyright (C) 1998 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security.acl; - -/** - * This interface provides information about a permission that can be - * granted. Note that this is <em>not</em> the same as the class - * <code>java.security.Permission</code>. - * - * @version 0.0 - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public interface Permission -{ - /** - * This method tests whether or not a specified <code>Permission</code> - * (passed as an <code>Object</code>) is the same as this permission. - * - * @param perm The permission to check for equality - * - * @return <code>true</code> if the specified permission is the same as this one, <code>false</code> otherwise - */ - boolean equals (Object perm); - - /** - * This method returns this <code>Permission</code> as a <code>String</code>. - * - * @return A <code>String</code> representing this permission. - */ - String toString(); -} diff --git a/libjava/java/security/cert/CRL.java b/libjava/java/security/cert/CRL.java deleted file mode 100644 index e763663f52c..00000000000 --- a/libjava/java/security/cert/CRL.java +++ /dev/null @@ -1,98 +0,0 @@ -/* CRL.java --- Certificate Revocation List - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security.cert; - -/** - Certificate Revocation List class for managing CRLs that - have different formats but the same general use. They - all serve as lists of revoked certificates and can - be queried for a given certificate. - - Specialized CRLs extend this class. - - @author Mark Benvenuto - - @since JDK 1.2 -*/ -public abstract class CRL -{ - - private String type; - - /** - Creates a new CRL for the specified type. An example - is "X.509". - - @param type the standard name for the CRL type. - */ - protected CRL(String type) - { - this.type = type; - } - - /** - Returns the CRL type. - - @return a string representing the CRL type - */ - public final String getType() - { - return type; - } - - /** - Returns a string representing the CRL. - - @return a string representing the CRL. - */ - public abstract String toString(); - - /** - Determines whether or not the specified Certificate - is revoked. - - @param cert A certificate to check if it is revoked - - @return true if the certificate is revoked, - false otherwise. - */ - public abstract boolean isRevoked(Certificate cert); - - -} diff --git a/libjava/java/security/cert/CRLException.java b/libjava/java/security/cert/CRLException.java deleted file mode 100644 index f3addfe9594..00000000000 --- a/libjava/java/security/cert/CRLException.java +++ /dev/null @@ -1,73 +0,0 @@ -/* CRLException.java -- Certificate Revocation List Exception - Copyright (C) 1999, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security.cert; - -import java.security.GeneralSecurityException; - -/** - * Exception for a Certificate Revocation List. - * - * @author Mark Benvenuto - * @since 1.2 - * @status updated to 1.4 -*/ -public class CRLException extends GeneralSecurityException -{ - /** - * Compatible with JDK 1.2+. - */ - private static final long serialVersionUID = -6694728944094197147L; - - /** - * Constructs an CRLExceptionwithout a message string. - */ - public CRLException() - { - } - - /** - * Constructs an CRLException with a message string. - * - * @param msg a message to display with exception - */ - public CRLException(String msg) - { - super(msg); - } -} diff --git a/libjava/java/security/cert/CRLSelector.java b/libjava/java/security/cert/CRLSelector.java deleted file mode 100644 index 1fa5a207dfc..00000000000 --- a/libjava/java/security/cert/CRLSelector.java +++ /dev/null @@ -1,69 +0,0 @@ -/* CRLSelector.java -- matches CRLs against criteria. - Copyright (C) 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security.cert; - -/** - * A generic interface to classes that match certificate revocation - * lists (CRLs) to some given criteria. Implementations of this - * interface are useful for finding {@link CRL} objects in a {@link - * CertStore}. - * - * @see CertStore - * @see CertSelector - * @see X509CRLSelector - */ -public interface CRLSelector extends Cloneable -{ - - /** - * Returns a clone of this instance. - * - * @return The clone. - */ - Object clone(); - - /** - * Match a given certificate revocation list to this selector's - * criteria, returning true if it matches, false otherwise. - * - * @param crl The certificate revocation list to test. - * @return The boolean result of this test. - */ - boolean match(CRL crl); -} diff --git a/libjava/java/security/cert/CertPath.java b/libjava/java/security/cert/CertPath.java deleted file mode 100644 index e818763aab4..00000000000 --- a/libjava/java/security/cert/CertPath.java +++ /dev/null @@ -1,252 +0,0 @@ -/* CertPath.java -- a sequence of certificates - Copyright (C) 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security.cert; - -import java.io.ByteArrayInputStream; -import java.io.NotSerializableException; -import java.io.ObjectStreamException; -import java.io.Serializable; -import java.util.Iterator; -import java.util.List; - -/** - * This class represents an immutable sequence, or path, of security - * certificates. The path type must match the type of each certificate in the - * path, or in other words, for all instances of cert in a certpath object, - * <code>cert.getType().equals(certpath.getType())</code> will return true. - * - * <p>Since this class is immutable, it is thread-safe. During serialization, - * the path is consolidated into a {@link CertPathRep}, which preserves the - * data regardless of the underlying implementation of the path. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.4 - * @status updated to 1.4 - */ -public abstract class CertPath implements Serializable -{ - /** - * The serialized representation of a path. - * - * @author Eric Blake (ebb9@email.byu.edu) - */ - protected static class CertPathRep implements Serializable - { - /** - * Compatible with JDK 1.4+. - */ - private static final long serialVersionUID = 3015633072427920915L; - - /** - * The certificate type. - * - * @serial the type of the certificate path - */ - private final String type; - - /** - * The encoded form of the path. - * - * @serial the encoded form - */ - private final byte[] data; - - /** - * Create the new serial representation. - * - * @param type the path type - * @param data the encoded path data - */ - protected CertPathRep(String type, byte[] data) - { - this.type = type; - this.data = data; - } - - /** - * Decode the data into an actual {@link CertPath} upon deserialization. - * - * @return the replacement object - * @throws ObjectStreamException if replacement fails - */ - protected Object readResolve() throws ObjectStreamException - { - try - { - return CertificateFactory.getInstance(type) - .generateCertPath(new ByteArrayInputStream(data)); - } - catch (CertificateException e) - { - throw (ObjectStreamException) - new NotSerializableException("java.security.cert.CertPath: " - + type).initCause(e); - } - } - } // class CertPathRep - - /** - * Compatible with JDK 1.4+. - */ - private static final long serialVersionUID = 6068470306649138683L; - - /** - * The path type. - * - * @serial the type of all certificates in this path - */ - private final String type; - - /** - * Create a certificate path with the given type. Most code should use - * {@link CertificateFactory} to create CertPaths. - * - * @param type the type of the path - */ - protected CertPath(String type) - { - this.type = type; - } - - /** - * Get the (non-null) type of all certificates in the path. - * - * @return the path certificate type - */ - public String getType() - { - return type; - } - - /** - * Get an immutable iterator over the path encodings (all String names), - * starting with the default encoding. The iterator will throw an - * <code>UnsupportedOperationException</code> if an attempt is made to - * remove items from the list. - * - * @return the iterator of supported encodings in the path - */ - public abstract Iterator getEncodings(); - - /** - * Compares this path to another for semantic equality. To be equal, both - * must be instances of CertPath, with the same type, and identical - * certificate lists. Overriding classes must not change this behavior. - * - * @param o the object to compare to - * @return true if the two are equal - */ - public boolean equals(Object o) - { - if (! (o instanceof CertPath)) - return false; - CertPath cp = (CertPath) o; - return type.equals(cp.type) - && getCertificates().equals(cp.getCertificates()); - } - - /** - * Returns the hashcode of this certificate path. This is defined as:<br> - * <code>31 * getType().hashCode() + getCertificates().hashCode()</code>. - * - * @return the hashcode - */ - public int hashCode() - { - return 31 * type.hashCode() + getCertificates().hashCode(); - } - - public String toString() - { - List l = getCertificates(); - int size = l.size(); - int i = 0; - StringBuffer result = new StringBuffer(type); - result.append(" Cert Path: length = ").append(size).append(".\n[\n"); - while (--size >= 0) - result.append(l.get(i++)).append('\n'); - return result.append("\n]").toString(); - } - - /** - * Returns the encoded form of this path, via the default encoding. - * - * @return the encoded form - * @throws CertificateEncodingException if encoding fails - */ - public abstract byte[] getEncoded() throws CertificateEncodingException; - - /** - * Returns the encoded form of this path, via the specified encoding. - * - * @param encoding the encoding to use - * @return the encoded form - * @throws CertificateEncodingException if encoding fails or does not exist - */ - public abstract byte[] getEncoded(String encoding) - throws CertificateEncodingException; - - /** - * Returns the immutable, thread-safe list of certificates in this path. - * - * @return the list of certificates, non-null but possibly empty - */ - public abstract List getCertificates(); - - /** - * Serializes the path in its encoded form, to ensure reserialization with - * the appropriate factory object without worrying about list implementation. - * The result will always be an instance of {@link CertPathRep}. - * - * @return the replacement object - * @throws ObjectStreamException if the replacement creation fails - */ - protected Object writeReplace() throws ObjectStreamException - { - try - { - return new CertPathRep(type, getEncoded()); - } - catch (CertificateEncodingException e) - { - throw (ObjectStreamException) - new NotSerializableException("java.security.cert.CertPath: " - + type).initCause(e); - } - } -} // class CertPath diff --git a/libjava/java/security/cert/CertPathBuilder.java b/libjava/java/security/cert/CertPathBuilder.java deleted file mode 100644 index f6965205f53..00000000000 --- a/libjava/java/security/cert/CertPathBuilder.java +++ /dev/null @@ -1,238 +0,0 @@ -/* CertPathBuilder.java -- bulids CertPath objects from Certificates. - Copyright (C) 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security.cert; - -import gnu.java.security.Engine; - -import java.security.InvalidAlgorithmParameterException; -import java.security.NoSuchAlgorithmException; -import java.security.NoSuchProviderException; -import java.security.Provider; -import java.security.Security; - -/** - * This class builds certificate paths (also called certificate chains), - * which can be used to establish trust for a particular certificate by - * building a path from a trusted certificate (a trust anchor) to the - * untrusted certificate. - * - * @see CertPath - */ -public class CertPathBuilder -{ - - // Constants and fields. - // ------------------------------------------------------------------------ - - /** Service name for CertPathBuilder. */ - private static final String CERT_PATH_BUILDER = "CertPathBuilder"; - - /** The underlying implementation. */ - private CertPathBuilderSpi cpbSpi; - - /** The provider of this implementation. */ - private Provider provider; - - /** The name of this implementation. */ - private String algorithm; - - // Constructor. - // ------------------------------------------------------------------------ - - /** - * Creates a new CertPathBuilder. - * - * @param cpbSpi The underlying implementation. - * @param provider The provider of the implementation. - * @param algorithm This implementation's name. - */ - protected CertPathBuilder(CertPathBuilderSpi cpbSpi, Provider provider, - String algorithm) - { - this.cpbSpi = cpbSpi; - this.provider = provider; - this.algorithm = algorithm; - } - - // Class methods. - // ------------------------------------------------------------------------ - - /** - * Get the default cert path builder type. - * - * <p>This value can be set at run-time by the security property - * <code>"certpathbuilder.type"</code>. If this property is not set, - * then the value returned is <code>"PKIX"</code>. - * - * @return The default CertPathBuilder algorithm. - */ - public static final String getDefaultType() - { - String type = Security.getProperty("certpathbuilder.type"); - if (type == null) - type = "PKIX"; - return type; - } - - /** - * Get an instance of a named CertPathBuilder, from the first provider - * that implements it. - * - * @param algorithm The name of the CertPathBuilder to create. - * @return The new instance. - * @throws NoSuchAlgorithmException If no installed provider - * implements the named algorithm. - */ - public static CertPathBuilder getInstance(String algorithm) - throws NoSuchAlgorithmException - { - Provider[] p = Security.getProviders(); - - for (int i = 0; i < p.length; i++) - { - try - { - return getInstance(algorithm, p[i]); - } - catch (NoSuchAlgorithmException e) - { - // Ignored. - } - } - - throw new NoSuchAlgorithmException(algorithm); - } - - /** - * Get an instance of a named CertPathBuilder from the named - * provider. - * - * @param algorithm The name of the CertPathBuilder to create. - * @param provider The name of the provider from which to get the - * implementation. - * @return The new instance. - * @throws NoSuchAlgorithmException If no installed provider - * implements the named algorithm. - * @throws NoSuchProviderException If the named provider does not - * exist. - */ - public static CertPathBuilder getInstance(String algorithm, String provider) - throws NoSuchAlgorithmException, NoSuchProviderException - { - Provider p = Security.getProvider(provider); - if (p == null) - throw new NoSuchProviderException(provider); - return getInstance(algorithm, p); - } - - /** - * Get an instance of a named CertPathBuilder from the specified - * provider. - * - * @param algorithm The name of the CertPathBuilder to create. - * @param provider The provider from which to get the implementation. - * @return The new instance. - * @throws NoSuchAlgorithmException If no installed provider - * implements the named algorithm. - * @throws IllegalArgumentException If <i>provider</i> in - * <tt>null</tt>. - */ - public static CertPathBuilder getInstance(String algorithm, Provider provider) - throws NoSuchAlgorithmException - { - if (provider == null) - throw new IllegalArgumentException("null provider"); - try - { - return new CertPathBuilder((CertPathBuilderSpi) - Engine.getInstance(CERT_PATH_BUILDER, algorithm, provider), - provider, algorithm); - } - catch (java.lang.reflect.InvocationTargetException ite) - { - throw new NoSuchAlgorithmException(algorithm); - } - catch (ClassCastException cce) - { - throw new NoSuchAlgorithmException(algorithm); - } - } - - // Instance methods. - // ------------------------------------------------------------------------ - - /** - * Return the name of this CertPathBuilder algorithm. - * - * @return The algorithm name. - */ - public final String getAlgorithm() - { - return algorithm; - } - - /** - * Return the provider of this instance's implementation. - * - * @return The provider. - */ - public final Provider getProvider() - { - return provider; - } - - /** - * Builds a certificate path. The {@link CertPathParameters} parameter - * passed to this method is implementation-specific, but in general - * should contain some number of certificates and some number of - * trusted certificates (or "trust anchors"). - * - * @param params The parameters. - * @retrun The certificate path result. - * @throws CertPathBuilderException If the certificate path cannot be - * built. - * @throws InvalidAlgorithmParameterException If the implementation - * rejects the specified parameters. - */ - public final CertPathBuilderResult build(CertPathParameters params) - throws CertPathBuilderException, InvalidAlgorithmParameterException - { - return cpbSpi.engineBuild(params); - } -} diff --git a/libjava/java/security/cert/CertPathBuilderException.java b/libjava/java/security/cert/CertPathBuilderException.java deleted file mode 100644 index 98515101025..00000000000 --- a/libjava/java/security/cert/CertPathBuilderException.java +++ /dev/null @@ -1,159 +0,0 @@ -/* CertPathBuilderException.java -- wraps an exception during certificate - path building - Copyright (C) 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security.cert; - -import java.io.PrintStream; -import java.io.PrintWriter; -import java.security.GeneralSecurityException; - -/** - * Indicates a problem while using a <code>CertPathBuilder</code>, wrapping - * the lower exception. This class is not thread-safe. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @see CertPathBuilder - * @since 1.4 - * @status updated to 1.4 -*/ -public class CertPathBuilderException extends GeneralSecurityException -{ - /** - * Compatible with JDK 1.4+. - */ - private static final long serialVersionUID = 5316471420178794402L; - - /** - * Create an exception without a message. The cause may be initialized. - */ - public CertPathBuilderException() - { - } - - /** - * Create an exception with a message. The cause may be initialized. - * - * @param msg a message to display with exception - */ - public CertPathBuilderException(String msg) - { - super(msg); - } - - /** - * Create an exception with a cause. The message will be - * <code>cause == null ? null : cause.toString()</code>. - * - * @param cause the cause - */ - public CertPathBuilderException(Throwable cause) - { - this(cause == null ? null : cause.toString(), cause); - } - - /** - * Create an exception with a cause and a message. - * - * @param msg the message - * @param cause the cause - */ - public CertPathBuilderException(String msg, Throwable cause) - { - super(msg); - initCause(cause); - } - - /** - * Get the detail message. - * - * @return the detail message - */ - public String getMessage() - { - return super.getMessage(); - } - - /** - * Get the cause, null if unknown. - * - * @return the cause - */ - public Throwable getCause() - { - return super.getCause(); - } - - /** - * Convert this to a string, including its cause. - * - * @return the string conversion - */ - public String toString() - { - return super.toString(); - } - - /** - * Print the stack trace to <code>System.err</code>. - */ - public void printStackTrace() - { - super.printStackTrace(); - } - - /** - * Print the stack trace to a stream. - * - * @param stream the stream - */ - public void printStackTrace(PrintStream stream) - { - super.printStackTrace(stream); - } - - /** - * Print the stack trace to a stream. - * - * @param stream the stream - */ - public void printStackTrace(PrintWriter stream) - { - super.printStackTrace(stream); - } -} diff --git a/libjava/java/security/cert/CertPathBuilderResult.java b/libjava/java/security/cert/CertPathBuilderResult.java deleted file mode 100644 index 737ba9431b3..00000000000 --- a/libjava/java/security/cert/CertPathBuilderResult.java +++ /dev/null @@ -1,63 +0,0 @@ -/* CertPathBuilderResult -- results from building cert paths. - Copyright (C) 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security.cert; - -/** - * A standard interface for the result of building a certificate path. - * All implementations of this class must provide a way to get the - * certificate path, but may also define additional methods for - * returning other result data generated by the certificate path - * builder. - */ -public interface CertPathBuilderResult extends Cloneable { - - /** - * Creates a copy of this builder result. - * - * @return The copy. - */ - Object clone(); - - /** - * Get the certificate path that was built. - * - * @retrn The certificate path. - */ - CertPath getCertPath(); -} diff --git a/libjava/java/security/cert/CertPathBuilderSpi.java b/libjava/java/security/cert/CertPathBuilderSpi.java deleted file mode 100644 index afc7fc07366..00000000000 --- a/libjava/java/security/cert/CertPathBuilderSpi.java +++ /dev/null @@ -1,74 +0,0 @@ -/* CertPathBuilderSpi -- CertPathBuilder service provider interface. - Copyright (C) 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security.cert; - -/** - * The {@link CertPathBuilder} <i>Service Provider Interface</i> - * (<b>SPI</b>). - * - * @see CertPathBuilder - */ -public abstract class CertPathBuilderSpi { - - // Constructors. - // ------------------------------------------------------------------------ - - /** - * Creates a new CertPathBuilderSpi. - */ - public CertPathBuilderSpi() { - super(); - } - - // Abstract methods. - // ------------------------------------------------------------------------ - - /** - * Creates a certificate path from the specified parameters. - * - * @param params The parameters to use. - * @return The certificate path result. - * @throws CertPathBuilderException If the certificate path cannot be - * built. - * @throws java.security.InvalidAlgorithmParameterException If the - * implementation rejects the specified parameters. - */ - public abstract CertPathBuilderResult engineBuild(CertPathParameters params) - throws CertPathBuilderException, - java.security.InvalidAlgorithmParameterException; -} diff --git a/libjava/java/security/cert/CertPathParameters.java b/libjava/java/security/cert/CertPathParameters.java deleted file mode 100644 index 62a5cb6a69e..00000000000 --- a/libjava/java/security/cert/CertPathParameters.java +++ /dev/null @@ -1,58 +0,0 @@ -/* CertPathParameters.java -- parameters for CertPathBuilder. - Copyright (C) 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security.cert; - -/** - * Parameters for generating and validating certificate paths. This - * class does not define any methods (except a required cloneable - * interface) and is provided only to provide type safety for - * implementations. Concrete implementations implement this interface - * in accord with thier own needs. - * - * @see CertPathBuilder - * @see CertPathValidator - */ -public interface CertPathParameters extends Cloneable { - - /** - * Makes a copy of this CertPathParameters instance. - * - * @return The copy. - */ - Object clone(); -} diff --git a/libjava/java/security/cert/CertPathValidator.java b/libjava/java/security/cert/CertPathValidator.java deleted file mode 100644 index 5fed19e9a78..00000000000 --- a/libjava/java/security/cert/CertPathValidator.java +++ /dev/null @@ -1,249 +0,0 @@ -/* CertPathValidator -- validates certificate paths. - Copyright (C) 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security.cert; - -import gnu.java.security.Engine; - -import java.security.AccessController; -import java.security.InvalidAlgorithmParameterException; -import java.security.NoSuchAlgorithmException; -import java.security.NoSuchProviderException; -import java.security.PrivilegedAction; -import java.security.Provider; -import java.security.Security; - -/** - * Generic interface to classes that validate certificate paths. - * - * <p>Using this class is similar to all the provider-based security - * classes; the method of interest, {@link - * #validate(java.security.cert.CertPath,java.security.cert.CertPathParameters)}, - * which takes provider-specific implementations of {@link - * CertPathParameters}, and return provider-specific implementations of - * {@link CertPathValidatorResult}. - * - * @since JDK 1.4 - * @see CertPath - */ -public class CertPathValidator { - - // Constants and fields. - // ------------------------------------------------------------------------ - - /** Service name for CertPathValidator. */ - private static final String CERT_PATH_VALIDATOR = "CertPathValidator"; - - /** The underlying implementation. */ - private final CertPathValidatorSpi validatorSpi; - - /** The provider of this implementation. */ - private final Provider provider; - - /** The algorithm's name. */ - private final String algorithm; - - // Constructor. - // ------------------------------------------------------------------------ - - /** - * Creates a new CertPathValidator. - * - * @param validatorSpi The underlying implementation. - * @param provider The provider of the implementation. - * @param algorithm The algorithm name. - */ - protected CertPathValidator(CertPathValidatorSpi validatorSpi, - Provider provider, String algorithm) - { - this.validatorSpi = validatorSpi; - this.provider = provider; - this.algorithm = algorithm; - } - - // Class methods. - // ------------------------------------------------------------------------ - - /** - * Returns the default validator type. - * - * <p>This value may be set at run-time via the security property - * "certpathvalidator.type", or the value "PKIX" if this property is - * not set. - * - * @return The default validator type. - */ - public static synchronized String getDefaultType() { - String type = (String) AccessController.doPrivileged( - new PrivilegedAction() - { - public Object run() - { - return Security.getProperty("certpathvalidator.type"); - } - } - ); - if (type == null) - type = "PKIX"; - return type; - } - - /** - * Get an instance of the given validator from the first provider that - * implements it. - * - * @param algorithm The name of the algorithm to get. - * @return The new instance. - * @throws NoSuchAlgorithmException If no installed provider - * implements the requested algorithm. - */ - public static CertPathValidator getInstance(String algorithm) - throws NoSuchAlgorithmException - { - Provider[] p = Security.getProviders(); - for (int i = 0; i < p.length; i++) - { - try - { - return getInstance(algorithm, p[i]); - } - catch (NoSuchAlgorithmException e) - { - // Ignored. - } - } - throw new NoSuchAlgorithmException(algorithm); - } - - /** - * Get an instance of the given validator from the named provider. - * - * @param algorithm The name of the algorithm to get. - * @param provider The name of the provider from which to get the - * implementation. - * @return The new instance. - * @throws NoSuchAlgorithmException If the named provider does not - * implement the algorithm. - * @throws NoSuchProviderException If no provider named - * <i>provider</i> is installed. - */ - public static CertPathValidator getInstance(String algorithm, - String provider) - throws NoSuchAlgorithmException, NoSuchProviderException - { - Provider p = Security.getProvider(provider); - if (p == null) - throw new NoSuchProviderException(provider); - - return getInstance(algorithm, p); - } - - /** - * Get an instance of the given validator from the given provider. - * - * @param algorithm The name of the algorithm to get. - * @param provider The provider from which to get the implementation. - * @return The new instance. - * @throws NoSuchAlgorithmException If the provider does not implement - * the algorithm. - * @throws IllegalArgumentException If <i>provider</i> is null. - */ - public static CertPathValidator getInstance(String algorithm, - Provider provider) - throws NoSuchAlgorithmException - { - if (provider == null) - throw new IllegalArgumentException("null provider"); - - try - { - return new CertPathValidator((CertPathValidatorSpi) - Engine.getInstance(CERT_PATH_VALIDATOR, algorithm, provider), - provider, algorithm); - } - catch (java.lang.reflect.InvocationTargetException ite) - { - throw new NoSuchAlgorithmException(algorithm); - } - catch (ClassCastException cce) - { - throw new NoSuchAlgorithmException(algorithm); - } - } - - // Instance methods. - // ------------------------------------------------------------------------ - - /** - * Return the name of this validator. - * - * @return This validator's name. - */ - public final String getAlgorithm() - { - return algorithm; - } - - /** - * Return the provider of this implementation. - * - * @return The provider. - */ - public final Provider getProvider() - { - return provider; - } - - /** - * Attempt to validate a certificate path. - * - * @param certPath The path to validate. - * @param params The algorithm-specific parameters. - * @return The result of this validation attempt. - * @throws CertPathValidatorException If the certificate path cannot - * be validated. - * @throws InvalidAlgorithmParameterException If this implementation - * rejects the specified parameters. - */ - public final CertPathValidatorResult validate(CertPath certPath, - CertPathParameters params) - throws CertPathValidatorException, InvalidAlgorithmParameterException - { - return validatorSpi.engineValidate(certPath, params); - } -} diff --git a/libjava/java/security/cert/CertPathValidatorException.java b/libjava/java/security/cert/CertPathValidatorException.java deleted file mode 100644 index f3195be296f..00000000000 --- a/libjava/java/security/cert/CertPathValidatorException.java +++ /dev/null @@ -1,226 +0,0 @@ -/* CertPathValidatorException.java -- wraps an exception during validation - of a CertPath - Copyright (C) 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security.cert; - -import java.io.PrintStream; -import java.io.PrintWriter; -import java.security.GeneralSecurityException; - -/** - * Indicates a problem while validating a certification path. In addition, - * it can store the path an index in that path that caused the problem. This - * class is not thread-safe. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @see CertPathValidator - * @since 1.4 - * @status updated to 1.4 -*/ -public class CertPathValidatorException extends GeneralSecurityException -{ - /** - * Compatible with JDK 1.4+. - */ - private static final long serialVersionUID = -3083180014971893139L; - - /** - * The index of the certificate path that failed, or -1. - * - * @serial the failed index - */ - private final int index; - - /** - * The <code>CertPath</code> that failed. - * - * @serial the object being validated at time of failure - */ - private final CertPath certPath; - - /** - * Create an exception without a message. The cause may be initialized. The - * index is set to -1 and the failed CertPath object to null. - */ - public CertPathValidatorException() - { - this((String) null); - } - - /** - * Create an exception with a message. The cause may be initialized. The - * index is set to -1 and the failed CertPath object to null. - * - * @param msg a message to display with exception - */ - public CertPathValidatorException(String msg) - { - super(msg); - index = -1; - certPath = null; - } - - /** - * Create an exception with a cause. The message will be - * <code>cause == null ? null : cause.toString()</code>. The index is set - * to -1 and the failed CertPath object to null. - * - * @param cause the cause - */ - public CertPathValidatorException(Throwable cause) - { - this(cause == null ? null : cause.toString(), cause, null, -1); - } - - /** - * Create an exception with a cause and a message. The index is set to -1 - * and the failed CertPath object to null. - * - * @param msg the message - * @param cause the cause - */ - public CertPathValidatorException(String msg, Throwable cause) - { - this(msg, cause, null, -1); - } - - /** - * Create an exception with a cause, message, failed object, and index of - * failure in that CertPath. - * - * @param msg the message - * @param cause the cause - * @param certPath the path that was being validated, or null - * @param index the index of the path, or -1 - * @throws IndexOutOfBoundsException if index is < -1 or - * > certPath.getCertificates().size() - * @throws IllegalArgumentException if certPath is null but index != -1 - */ - public CertPathValidatorException(String msg, Throwable cause, - CertPath certPath, int index) - { - super(msg); - initCause(cause); - if (index < -1 || (certPath != null - && index >= certPath.getCertificates().size())) - throw new IndexOutOfBoundsException(); - if ((certPath == null) != (index == -1)) - throw new IllegalArgumentException(); - this.certPath = certPath; - this.index = index; - } - - /** - * Get the detail message. - * - * @return the detail message - */ - public String getMessage() - { - return super.getMessage(); - } - - /** - * Get the certificate path that had the failure, or null. - * - * @return the culprit path - */ - public CertPath getCertPath() - { - return certPath; - } - - /** - * Get the index that failed, or -1. - * - * @return the colprit index - */ - public int getIndex() - { - return index; - } - - /** - * Get the cause, null if unknown. - * - * @return the cause - */ - public Throwable getCause() - { - return super.getCause(); - } - - /** - * Convert this to a string, including its cause. - * - * @return the string conversion - */ - public String toString() - { - return super.toString(); - } - - /** - * Print the stack trace to <code>System.err</code>. - */ - public void printStackTrace() - { - super.printStackTrace(); - } - - /** - * Print the stack trace to a stream. - * - * @param stream the stream - */ - public void printStackTrace(PrintStream stream) - { - super.printStackTrace(stream); - } - - /** - * Print the stack trace to a stream. - * - * @param stream the stream - */ - public void printStackTrace(PrintWriter stream) - { - super.printStackTrace(stream); - } -} diff --git a/libjava/java/security/cert/CertPathValidatorResult.java b/libjava/java/security/cert/CertPathValidatorResult.java deleted file mode 100644 index 71aaf89bc18..00000000000 --- a/libjava/java/security/cert/CertPathValidatorResult.java +++ /dev/null @@ -1,63 +0,0 @@ -/* CertPathValidatorResult -- result of validating certificate paths - Copyright (C) 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security.cert; - -/** - * Interface to the result of calling {@link - * CertPathValidator#validate(java.security.cert.CertPath,java.security.cert.CertPathParameters)}. - * - * <p>This interface defines no methods other than the required - * {@link java.lang.Cloneable} interface, and is intended to group and - * provide type safety for validator results. Providers that implement - * a certificate path validator must also provide an implementation of - * this interface, possibly defining additional methods. - * - * @since JDK 1.4 - * @see CertPathValidator - */ -public interface CertPathValidatorResult extends Cloneable -{ - - /** - * Returns a copy of this validator result. - * - * @return The copy. - */ - Object clone(); -} diff --git a/libjava/java/security/cert/CertPathValidatorSpi.java b/libjava/java/security/cert/CertPathValidatorSpi.java deleted file mode 100644 index 8d18b49dac4..00000000000 --- a/libjava/java/security/cert/CertPathValidatorSpi.java +++ /dev/null @@ -1,79 +0,0 @@ -/* CertPathValidatorSpi -- cert path validator service provider interface - Copyright (C) 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security.cert; - -/** - * The <i>service provider interface</i> (<b>SPI</b>) for the {@link - * CertPathValidator} class. Providers implementing certificate path - * validators must subclass this class and implement its abstract - * methods. - */ -public abstract class CertPathValidatorSpi -{ - - // Constructor. - // ------------------------------------------------------------------------ - - /** - * Default constructor. - */ - public CertPathValidatorSpi() - { - super(); - } - - // Abstract methods. - // ------------------------------------------------------------------------ - - /** - * Attempt to validate a certificate path. - * - * @param certPath The path to validate. - * @param params The algorithm-specific parameters. - * @return The result of this validation attempt. - * @throws CertPathValidatorException If the certificate path cannot - * be validated. - * @throws InvalidAlgorithmParameterException If this implementation - * rejects the specified parameters. - */ - public abstract CertPathValidatorResult - engineValidate(CertPath certPath, CertPathParameters params) - throws CertPathValidatorException, - java.security.InvalidAlgorithmParameterException; -} diff --git a/libjava/java/security/cert/CertSelector.java b/libjava/java/security/cert/CertSelector.java deleted file mode 100644 index aea614ad95e..00000000000 --- a/libjava/java/security/cert/CertSelector.java +++ /dev/null @@ -1,58 +0,0 @@ -/* CertSelector.java -- certificate selector interface. - Copyright (C) 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security.cert; - -public interface CertSelector extends Cloneable -{ - - /** - * Returns a copy of this CertSelector. - * - * @return The copy. - */ - Object clone(); - - /** - * Match a certificate according to this selector's criteria. - * - * @param cert The certificate to match. - * @return true if the certificate matches thin criteria. - */ - boolean match(Certificate cert); -} diff --git a/libjava/java/security/cert/CertStore.java b/libjava/java/security/cert/CertStore.java deleted file mode 100644 index 864da868f19..00000000000 --- a/libjava/java/security/cert/CertStore.java +++ /dev/null @@ -1,294 +0,0 @@ -/* CertStore -- stores and retrieves certificates. - Copyright (C) 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security.cert; - -import gnu.java.security.Engine; - -import java.security.InvalidAlgorithmParameterException; -import java.security.NoSuchAlgorithmException; -import java.security.NoSuchProviderException; -import java.security.PrivilegedAction; -import java.security.Provider; -import java.security.Security; -import java.util.Collection; - -/** - * A CertStore is a read-only repository for certificates and - * certificate revocation lists. - * - * @since JDK 1.4 - */ -public class CertStore -{ - - // Constants and fields. - // ------------------------------------------------------------------------ - - /** Service name for CertStore. */ - private static final String CERT_STORE = "CertStore"; - - /** The underlying implementation. */ - private CertStoreSpi storeSpi; - - /** This implementation's provider. */ - private Provider provider; - - /** The name of this key store type. */ - private String type; - - /** The parameters used to initialize this instance, if any. */ - private CertStoreParameters params; - - // Constructor. - // ------------------------------------------------------------------------ - - /** - * Create a new CertStore. - * - * @param storeSpi The underlying implementation. - * @param provider The provider of this implementation. - * @param type The type of CertStore this class represents. - * @param params The parameters used to initialize this instance, if any. - */ - protected CertStore(CertStoreSpi storeSpi, Provider provider, String type, - CertStoreParameters params) - { - this.storeSpi = storeSpi; - this.provider = provider; - this.type = type; - this.params = params; - } - -// Class methods. - // ------------------------------------------------------------------------ - - /** - * Returns the default certificate store type. - * - * <p>This value can be set at run-time via the security property - * "certstore.type"; if not specified than the default type will be - * "LDAP". - * - * @return The default CertStore type. - */ - public static final synchronized String getDefaultType() - { - String type = null; - type = (String) java.security.AccessController.doPrivileged( - new PrivilegedAction() { - public Object run() { - return Security.getProperty("certstore.type"); - } - } - ); - if (type == null) - type = "LDAP"; - return type; - } - - /** - * Get an instance of the given certificate store from the first - * installed provider. - * - * @param type The type of CertStore to create. - * @param params The parameters to initialize this cert store with. - * @return The new instance. - * @throws InvalidAlgorithmParameterException If the instance rejects - * the specified parameters. - * @throws NoSuchAlgorithmException If no installed provider - * implements the specified CertStore. - * @throws IllegalArgumentException If <i>provider</i> is null. - */ - public static CertStore getInstance(String type, CertStoreParameters params) - throws InvalidAlgorithmParameterException, NoSuchAlgorithmException - { - Provider[] p = Security.getProviders(); - for (int i = 0; i < p.length; i++) - { - try - { - return getInstance(type, params, p[i]); - } - catch (NoSuchAlgorithmException e) - { - // Ignored. - } - } - - throw new NoSuchAlgorithmException(type); - } - - /** - * Get an instance of the given certificate store from the named - * provider. - * - * @param type The type of CertStore to create. - * @param params The parameters to initialize this cert store with. - * @param provider The name of the provider from which to get the - * implementation. - * @return The new instance. - * @throws InvalidAlgorithmParameterException If the instance rejects - * the specified parameters. - * @throws NoSuchAlgorithmException If the specified provider does not - * implement the specified CertStore. - * @throws NoSuchProviderException If no provider named - * <i>provider</i> is installed. - * @throws IllegalArgumentException If <i>provider</i> is null. - */ - public static CertStore getInstance(String type, CertStoreParameters params, - String provider) - throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, - NoSuchProviderException - { - Provider p = Security.getProvider(provider); - if (p == null) - throw new NoSuchProviderException(provider); - return getInstance(type, params, p); - } - - /** - * Get an instance of the given certificate store from the given - * provider. - * - * @param type The type of CertStore to create. - * @param params The parameters to initialize this cert store with. - * @param provider The provider from which to get the implementation. - * @return The new instance. - * @throws InvalidAlgorithmParameterException If the instance rejects - * the specified parameters. - * @throws NoSuchAlgorithmException If the specified provider does not - * implement the specified CertStore. - * @throws IllegalArgumentException If <i>provider</i> is null. - */ - public static CertStore getInstance(String type, CertStoreParameters params, - Provider provider) - throws InvalidAlgorithmParameterException, NoSuchAlgorithmException - { - if (provider == null) - throw new IllegalArgumentException("null provider"); - - try - { - return new CertStore((CertStoreSpi) Engine.getInstance(CERT_STORE, - type, provider, new Object[] { params }), provider, type, params); - } - catch (ClassCastException cce) - { - throw new NoSuchAlgorithmException(type); - } - catch (java.lang.reflect.InvocationTargetException ite) - { - Throwable cause = ite.getCause(); - if (cause instanceof InvalidAlgorithmParameterException) - throw (InvalidAlgorithmParameterException) cause; - else - throw new NoSuchAlgorithmException(type); - } - } - -// Instance methods. - // ------------------------------------------------------------------------ - - /** - * Return the type of certificate store this instance represents. - * - * @return The CertStore type. - */ - public final String getType() - { - return type; - } - - /** - * Return the provider of this implementation. - * - * @return The provider. - */ - public final Provider getProvider() - { - return provider; - } - - /** - * Get the parameters this instance was created with, if any. The - * parameters will be cloned before they are returned. - * - * @return The parameters, or null. - */ - public final CertStoreParameters getCertStoreParameters() - { - return params != null ? (CertStoreParameters) params.clone() : null; - } - - /** - * Get a collection of certificates from this CertStore, optionally - * filtered by the specified CertSelector. The Collection returned may - * be empty, but will never be null. - * - * <p>Implementations may not allow a null argument, even if no - * filtering is desired. - * - * @param selector The certificate selector. - * @return The collection of certificates. - * @throws CertStoreException If the certificates cannot be retrieved. - */ - public final Collection getCertificates(CertSelector selector) - throws CertStoreException - { - return storeSpi.engineGetCertificates(selector); - } - - /** - * Get a collection of certificate revocation lists from this CertStore, - * optionally filtered by the specified CRLSelector. The Collection - * returned may be empty, but will never be null. - * - * <p>Implementations may not allow a null argument, even if no - * filtering is desired. - * - * @param selector The certificate selector. - * @return The collection of certificate revocation lists. - * @throws CertStoreException If the CRLs cannot be retrieved. - */ - public final Collection getCRLs(CRLSelector selector) - throws CertStoreException - { - return storeSpi.engineGetCRLs(selector); - } -} diff --git a/libjava/java/security/cert/CertStoreException.java b/libjava/java/security/cert/CertStoreException.java deleted file mode 100644 index a4d8b7a46e1..00000000000 --- a/libjava/java/security/cert/CertStoreException.java +++ /dev/null @@ -1,159 +0,0 @@ -/* CertStoreException.java -- wraps an exception during certificate storage - Copyright (C) 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security.cert; - -import java.io.PrintStream; -import java.io.PrintWriter; -import java.security.GeneralSecurityException; - -/** - * Indicates a problem while retrieving certificates and CRLs from - * <code>CertStore</code>, wrapping the lower exception. This class is not - * thread-safe. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @see CertStore - * @since 1.4 - * @status updated to 1.4 -*/ -public class CertStoreException extends GeneralSecurityException -{ - /** - * Compatible with JDK 1.4+. - */ - private static final long serialVersionUID = 2395296107471573245L; - - /** - * Create an exception without a message. The cause may be initialized. - */ - public CertStoreException() - { - } - - /** - * Create an exception with a message. The cause may be initialized. - * - * @param msg a message to display with exception - */ - public CertStoreException(String msg) - { - super(msg); - } - - /** - * Create an exception with a cause. The message will be - * <code>cause == null ? null : cause.toString()</code>. - * - * @param cause the cause - */ - public CertStoreException(Throwable cause) - { - this(cause == null ? null : cause.toString(), cause); - } - - /** - * Create an exception with a cause and a message. - * - * @param msg the message - * @param cause the cause - */ - public CertStoreException(String msg, Throwable cause) - { - super(msg); - initCause(cause); - } - - /** - * Get the detail message. - * - * @return the detail message - */ - public String getMessage() - { - return super.getMessage(); - } - - /** - * Get the cause, null if unknown. - * - * @return the cause - */ - public Throwable getCause() - { - return super.getCause(); - } - - /** - * Convert this to a string, including its cause. - * - * @return the string conversion - */ - public String toString() - { - return super.toString(); - } - - /** - * Print the stack trace to <code>System.err</code>. - */ - public void printStackTrace() - { - super.printStackTrace(); - } - - /** - * Print the stack trace to a stream. - * - * @param stream the stream - */ - public void printStackTrace(PrintStream stream) - { - super.printStackTrace(stream); - } - - /** - * Print the stack trace to a stream. - * - * @param stream the stream - */ - public void printStackTrace(PrintWriter stream) - { - super.printStackTrace(stream); - } -} diff --git a/libjava/java/security/cert/CertStoreParameters.java b/libjava/java/security/cert/CertStoreParameters.java deleted file mode 100644 index aab22f01fda..00000000000 --- a/libjava/java/security/cert/CertStoreParameters.java +++ /dev/null @@ -1,60 +0,0 @@ -/* CertStoreParameters -- interface to CertStore parameters. - Copyright (C) 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security.cert; - -/** - * Parameters used when creating instances of {@link CertStore}. This - * class does not define any methods (except a required cloneable - * interface) and is provided only to provide type safety for - * implementations. Concrete implementations implement this interface - * in accord with thier own needs. - * - * @see LDAPCertStoreParameters - * @see CollectionCertStoreParameters - */ -public interface CertStoreParameters extends Cloneable -{ - - /** - * Create a copy of these parameters. - * - * @return The copy. - */ - Object clone(); -} diff --git a/libjava/java/security/cert/CertStoreSpi.java b/libjava/java/security/cert/CertStoreSpi.java deleted file mode 100644 index eca0e866ca1..00000000000 --- a/libjava/java/security/cert/CertStoreSpi.java +++ /dev/null @@ -1,102 +0,0 @@ -/* CertStoreSpi -- certificate store service provider interface. - Copyright (C) 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security.cert; - -import java.util.Collection; - -/** - * The <i>service provider interface</i> (<b>SPI</b>) for the {@link - * CertStore} class. - * - * <p>Providers wishing to implement a CertStore must subclass this - * class, implementing all the abstract methods. Providers may also - * implement the {@link CertStoreParameters} interface, if they require - * parameters. - * - * @since JDK 1.4 - * @see CertStore - * @see CollectionCertStoreParameters - * @see LDAPCertStoreParameters - */ -public abstract class CertStoreSpi -{ - - // Constructors. - // ------------------------------------------------------------------------ - - /** - * Creates a new CertStoreSpi. - * - * @param params The parameters to initialize this instance with, or - * null if no parameters are required. - * @throws InvalidAlgorithmParameterException If the specified - * parameters are inappropriate for this class. - */ - public CertStoreSpi(CertStoreParameters params) - throws java.security.InvalidAlgorithmParameterException - { - super(); - } - - // Abstract methods. - // ------------------------------------------------------------------------ - - /** - * Get the certificates from this store, filtering them through the - * specified CertSelector. - * - * @param selector The CertSelector to filter certificates. - * @return A (non-null) collection of certificates. - * @throws CertStoreException If the certificates cannot be retrieved. - */ - public abstract Collection engineGetCertificates(CertSelector selector) - throws CertStoreException; - - /** - * Get the certificate revocation list from this store, filtering them - * through the specified CRLSelector. - * - * @param selector The CRLSelector to filter certificate revocation - * lists. - * @return A (non-null) collection of certificate revocation list. - * @throws CertStoreException If the CRLs cannot be retrieved. - */ - public abstract Collection engineGetCRLs(CRLSelector selector) - throws CertStoreException; -} diff --git a/libjava/java/security/cert/Certificate.java b/libjava/java/security/cert/Certificate.java deleted file mode 100644 index f8456f97ae5..00000000000 --- a/libjava/java/security/cert/Certificate.java +++ /dev/null @@ -1,306 +0,0 @@ -/* Certificate.java --- Certificate class - Copyright (C) 1999, 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security.cert; - -import java.io.ByteArrayInputStream; -import java.io.InvalidObjectException; -import java.io.ObjectStreamException; -import java.io.Serializable; -import java.security.InvalidKeyException; -import java.security.NoSuchAlgorithmException; -import java.security.NoSuchProviderException; -import java.security.PublicKey; -import java.security.SignatureException; - -/** - * The Certificate class is an abstract class used to manage - * identity certificates. An identity certificate is a - * combination of a principal and a public key which is - * certified by another principal. This is the puprose of - * Certificate Authorities (CA). - * - * <p>This class is used to manage different types of certificates - * but have important common puposes. Different types of - * certificates like X.509 and OpenPGP share general certificate - * functions (like encoding and verifying) and information like - * public keys. - * - * <p>X.509, OpenPGP, and SDSI can be implemented by subclassing this - * class even though they differ in storage methods and information - * stored. - * - * @see CertificateFactory - * @see X509Certificate - * @since JDK 1.2 - * @author Mark Benvenuto - * @author Casey Marshall - */ -public abstract class Certificate implements Serializable -{ - private static final long serialVersionUID = -6751606818319535583L; - - private String type; - - /** - Constructs a new certificate of the specified type. An example - is "X.509". - - @param type a valid standard name for a certificate. - */ - protected Certificate(String type) - { - this.type = type; - } - - /** - Returns the Certificate type. - - @return a string representing the Certificate type - */ - public final String getType() - { - return type; - } - - /** - Compares this Certificate to other. It checks if the - object if instanceOf Certificate and then checks if - the encoded form matches. - - @param other An Object to test for equality - - @return true if equal, false otherwise - */ - public boolean equals(Object other) - { - if( other instanceof Certificate ) { - try { - Certificate x = (Certificate) other; - if( getEncoded().length != x.getEncoded().length ) - return false; - - byte[] b1 = getEncoded(); - byte[] b2 = x.getEncoded(); - - for( int i = 0; i < b1.length; i++ ) - if( b1[i] != b2[i] ) - return false; - - } catch( CertificateEncodingException cee ) { - return false; - } - return true; - } - return false; - } - - /** - Returns a hash code for this Certificate in its encoded - form. - - @return A hash code of this class - */ - public int hashCode() - { - return super.hashCode(); - } - - /** - Gets the DER ASN.1 encoded format for this Certificate. - It assumes each certificate has only one encoding format. - Ex: X.509 is encoded as ASN.1 DER - - @return byte array containg encoded form - - @throws CertificateEncodingException if an error occurs - */ - public abstract byte[] getEncoded() throws CertificateEncodingException; - - /** - Verifies that this Certificate was properly signed with the - PublicKey that corresponds to its private key. - - @param key PublicKey to verify with - - @throws CertificateException encoding error - @throws NoSuchAlgorithmException unsupported algorithm - @throws InvalidKeyException incorrect key - @throws NoSuchProviderException no provider - @throws SignatureException signature error - */ - public abstract void verify(PublicKey key) - throws CertificateException, - NoSuchAlgorithmException, - InvalidKeyException, - NoSuchProviderException, - SignatureException; - - /** - Verifies that this Certificate was properly signed with the - PublicKey that corresponds to its private key and uses - the signature engine provided by the provider. - - @param key PublicKey to verify with - @param sigProvider Provider to use for signature algorithm - - @throws CertificateException encoding error - @throws NoSuchAlgorithmException unsupported algorithm - @throws InvalidKeyException incorrect key - @throws NoSuchProviderException incorrect provider - @throws SignatureException signature error - */ - public abstract void verify(PublicKey key, - String sigProvider) - throws CertificateException, - NoSuchAlgorithmException, - InvalidKeyException, - NoSuchProviderException, - SignatureException; - - /** - Returns a string representing the Certificate. - - @return a string representing the Certificate. - */ - public abstract String toString(); - - - /** - Returns the public key stored in the Certificate. - - @return The public key - */ - public abstract PublicKey getPublicKey(); - - // Protected methods. - // ------------------------------------------------------------------------ - - /** - * Returns a replacement for this certificate to be serialized. This - * method returns the equivalent to the following for this class: - * - * <blockquote> - * <pre>new CertificateRep(getType(), getEncoded());</pre> - * </blockquote> - * - * <p>This thusly replaces the certificate with its name and its - * encoded form, which can be deserialized later with the {@link - * CertificateFactory} implementation for this certificate's type. - * - * @return The replacement object to be serialized. - * @throws ObjectStreamException If the replacement could not be - * created. - */ - protected Object writeReplace() throws ObjectStreamException - { - try - { - return new CertificateRep(getType(), getEncoded()); - } - catch (CertificateEncodingException cee) - { - throw new InvalidObjectException(cee.toString()); - } - } - - // Inner class. - // ------------------------------------------------------------------------ - - /** - Certificate.CertificateRep is an inner class used to provide an alternate - storage mechanism for serialized Certificates. - */ - protected static class CertificateRep implements java.io.Serializable - { - - /** From JDK1.4. */ - private static final long serialVersionUID = -8563758940495660020L; - - /** The certificate type, e.g. "X.509". */ - private String type; - - /** The encoded certificate data. */ - private byte[] data; - - /** - * Create an alternative representation of this certificate. The - * <code>(type, data)</code> pair is typically the certificate's - * type as returned by {@link Certificate#getType()} (i.e. the - * canonical name of the certificate type) and the encoded form as - * returned by {@link Certificate#getEncoded()}. - * - * <p>For example, X.509 certificates would create an instance of - * this class with the parameters "X.509" and the ASN.1 - * representation of the certificate, encoded as DER bytes. - * - * @param type The certificate type. - * @param data The encoded certificate data. - */ - protected CertificateRep(String type, byte[] data) - { - this.type = type; - this.data = data; - } - - /** - * Deserialize this certificate replacement into the appropriate - * certificate object. That is, this method attempts to create a - * {@link CertificateFactory} for this certificate's type, then - * attempts to parse the encoded data with that factory, returning - * the resulting certificate. - * - * @return The deserialized certificate. - * @throws ObjectStreamException If there is no appropriate - * certificate factory for the given type, or if the encoded form - * cannot be parsed. - */ - protected Object readResolve() throws ObjectStreamException - { - try - { - CertificateFactory fact = CertificateFactory.getInstance(type); - return fact.generateCertificate(new ByteArrayInputStream(data)); - } - catch (Exception e) - { - throw new InvalidObjectException(e.toString()); - } - } - } -} diff --git a/libjava/java/security/cert/CertificateEncodingException.java b/libjava/java/security/cert/CertificateEncodingException.java deleted file mode 100644 index 0bb0c26d358..00000000000 --- a/libjava/java/security/cert/CertificateEncodingException.java +++ /dev/null @@ -1,71 +0,0 @@ -/* CertificateEncodingException.java -- Certificate Encoding Exception - Copyright (C) 1999, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security.cert; - -/** - * Exception for a Certificate Encoding. - * - * @author Mark Benvenuto - * @since 1.2 - * @status updated to 1.4 - */ -public class CertificateEncodingException extends CertificateException -{ - /** - * Compatible with JDK 1.2+. - */ - private static final long serialVersionUID = 6219492851589449162L; - - /** - * Constructs an exception without a message string. - */ - public CertificateEncodingException() - { - } - - /** - * Constructs an exception with a message string. - * - * @param msg A message to display with exception - */ - public CertificateEncodingException(String msg) - { - super(msg); - } -} diff --git a/libjava/java/security/cert/CertificateException.java b/libjava/java/security/cert/CertificateException.java deleted file mode 100644 index 3e075ddaf35..00000000000 --- a/libjava/java/security/cert/CertificateException.java +++ /dev/null @@ -1,74 +0,0 @@ -/* CertificateException.java -- Certificate Exception - Copyright (C) 1999, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security.cert; - -import java.security.GeneralSecurityException; - -/** - * Exception for a Certificate. - * - * @author Mark Benvenuto - * @see Certificate - * @since 1.2 - * @status updated to 1.4 - */ -public class CertificateException extends GeneralSecurityException -{ - /** - * Compatible with JDK 1.2+. - */ - private static final long serialVersionUID = 3192535253797119798L; - - /** - * Constructs an exception without a message string. - */ - public CertificateException() - { - } - - /** - * Constructs an exception with a message string. - * - * @param msg a message to display with exception - */ - public CertificateException(String msg) - { - super(msg); - } -} diff --git a/libjava/java/security/cert/CertificateExpiredException.java b/libjava/java/security/cert/CertificateExpiredException.java deleted file mode 100644 index 5b37142b5ec..00000000000 --- a/libjava/java/security/cert/CertificateExpiredException.java +++ /dev/null @@ -1,71 +0,0 @@ -/* CertificateExpiredException.java --- Certificate Expired Exception - Copyright (C) 1999, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security.cert; - -/** - * Exception for a Certificate Expiring. - * - * @author Mark Benvenuto - * @since 1.2 - * @status updated to 1.4 - */ -public class CertificateExpiredException extends CertificateException -{ - /** - * Compatible with JDK 1.2+. - */ - private static final long serialVersionUID = 9071001339691533771L; - - /** - * Constructs an exception without a message string. - */ - public CertificateExpiredException() - { - } - - /** - * Constructs an exception with a message string. - * - * @param msg a message to display with exception - */ - public CertificateExpiredException(String msg) - { - super(msg); - } -} diff --git a/libjava/java/security/cert/CertificateFactory.java b/libjava/java/security/cert/CertificateFactory.java deleted file mode 100644 index aedeff53573..00000000000 --- a/libjava/java/security/cert/CertificateFactory.java +++ /dev/null @@ -1,358 +0,0 @@ -/* CertificateFactory.java -- Certificate Factory Class - Copyright (C) 1999, 2002, 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security.cert; - -import gnu.java.security.Engine; - -import java.io.InputStream; -import java.security.NoSuchAlgorithmException; -import java.security.NoSuchProviderException; -import java.security.Provider; -import java.security.Security; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; - -/** - * This class implements the CertificateFactory class interface used to - * generate certificates, certificate revocation lists (CRLs), and certificate - * paths objects from their encoded forms. - * - * @author Mark Benvenuto - * @author Casey Marshall - * @since JDK 1.2 - * @status Fully compatible with JDK 1.4. - */ -public class CertificateFactory -{ - - /** The service name for certificate factories. */ - private static final String CERTIFICATE_FACTORY = "CertificateFactory"; - - private CertificateFactorySpi certFacSpi; - private Provider provider; - private String type; - - /** - * Creates an instance of CertificateFactory. - * - * @param certFacSpi The underlying CertificateFactory engine. - * @param provider The provider of this implementation. - * @param type The type of Certificate this factory creates. - */ - protected CertificateFactory(CertificateFactorySpi certFacSpi, - Provider provider, String type) - { - this.certFacSpi = certFacSpi; - this.provider = provider; - this.type = type; - } - -// Class methods. - // ------------------------------------------------------------------------ - - /** - * Gets an instance of the CertificateFactory class representing - * the specified certificate factory. If the type is not - * found then, it throws CertificateException. - * - * @param type The type of certificate factory to create. - * @return a CertificateFactory repesenting the desired type - * @throws CertificateException If the type of certificate is not - * implemented by any installed provider. - */ - public static final CertificateFactory getInstance(String type) - throws CertificateException - { - Provider[] p = Security.getProviders(); - - for (int i = 0; i < p.length; i++) - { - try - { - return getInstance(type, p[i]); - } - catch (CertificateException e) - { - // Ignored. - } - } - - throw new CertificateException(type); - } - - /** - * Gets an instance of the CertificateFactory class representing - * the specified certificate factory from the specified provider. - * If the type is not found then, it throws {@link CertificateException}. - * If the provider is not found, then it throws - * {@link java.security.NoSuchProviderException}. - * - * @param type The type of certificate factory to create. - * @param provider The name of the provider from which to get the - * implementation. - * @return A CertificateFactory for the desired type. - * @throws CertificateException If the type of certificate is not - * implemented by the named provider. - * @throws NoSuchProviderException If the named provider is not installed. - */ - public static final CertificateFactory getInstance(String type, - String provider) - throws CertificateException, NoSuchProviderException - { - Provider p = Security.getProvider(provider); - if( p == null) - throw new NoSuchProviderException(provider); - - return getInstance(type, p); - } - - /** - * Get a certificate factory for the given certificate type from the - * given provider. - * - * @param type The type of certificate factory to create. - * @param provider The provider from which to get the implementation. - * @return A CertificateFactory for the desired type. - * @throws CertificateException If the type of certificate is not - * implemented by the provider. - * @throws IllegalArgumentException If the provider is null. - */ - public static final CertificateFactory getInstance(String type, - Provider provider) - throws CertificateException - { - if (provider == null) - throw new IllegalArgumentException("null provider"); - - try - { - return new CertificateFactory((CertificateFactorySpi) - Engine.getInstance(CERTIFICATE_FACTORY, type, provider), - provider, type); - } - catch (ClassCastException cce) - { - throw new CertificateException(type); - } - catch (java.lang.reflect.InvocationTargetException ite) - { - throw new CertificateException(type); - } - catch (NoSuchAlgorithmException nsae) - { - throw new CertificateException(nsae.getMessage()); - } - } - -// Instance methods. - // ------------------------------------------------------------------------ - - /** - * Gets the provider of this implementation. - * - * @return The provider of this implementation. - */ - public final Provider getProvider() - { - return provider; - } - - /** - * Returns the type of the certificate this factory creates. - * - * @return A string with the type of certificate - */ - public final String getType() - { - return type; - } - - /** - * Generates a Certificate from the encoded data read - * from an InputStream. - * - * <p>The input stream must contain only one certificate. - * - * <p>If there exists a specialized certificate class for the - * certificate format handled by the certificate factory - * then the return Ceritificate should be a typecast of it. - * Ex: A X.509 CertificateFactory should return X509Certificate. - * - * <p>For X.509 certificates, the certificate in inStream must be - * DER encoded and supplied in binary or printable (Base64) - * encoding. If the certificate is in Base64 encoding, it must be - * bounded by -----BEGINCERTIFICATE-----, and - * -----END CERTIFICATE-----. - * - * @param inStream An input stream containing the certificate data. - * @return A certificate initialized from the decoded InputStream data. - * @throws CertificateException If an error occurs decoding the - * certificate. - */ - public final Certificate generateCertificate(InputStream inStream) - throws CertificateException - { - return certFacSpi.engineGenerateCertificate(inStream); - } - - /** - * Returns a collection of certificates that were read from the - * input stream. It may be empty, have only one, or have - * multiple certificates. - * - * For a X.509 certificate factory, the stream may contain a - * single DER encoded certificate or a PKCS#7 certificate - * chain. This is a PKCS#7 <I>SignedData</I> object with the - * most significant field being <I>certificates</I>. If no - * CRLs are present, then an empty collection is returned. - * - * @param inStream An input stream containing the certificate data. - * @return A collection of certificates initialized from the decoded - * InputStream data. - * @throws CertificateException If an error occurs decoding the - * certificates. - */ - public final Collection generateCertificates(InputStream inStream) - throws CertificateException - { - return certFacSpi.engineGenerateCertificates(inStream); - } - - /** - * Generates a CRL based on the encoded data read - * from the InputStream. - * - * <p>The input stream must contain only one CRL. - * - * <p>If there exists a specialized CRL class for the - * CRL format handled by the certificate factory - * then the return CRL should be a typecast of it. - * Ex: A X.509 CertificateFactory should return X509CRL. - * - * @param inStream An input stream containing the CRL data. - * @return A CRL initialized from the decoded InputStream data. - * @throws CRLException If an error occurs decoding the CRL. - */ - public final CRL generateCRL(InputStream inStream) - throws CRLException - { - return certFacSpi.engineGenerateCRL(inStream); - } - - /** - * <p>Generates CRLs based on the encoded data read - * from the InputStream. - * - * <p>For a X.509 certificate factory, the stream may contain a - * single DER encoded CRL or a PKCS#7 CRL set. This is a - * PKCS#7 <I>SignedData</I> object with the most significant - * field being <I>crls</I>. If no CRLs are present, then an - * empty collection is returned. - * - * @param inStream an input stream containing the CRLs. - * @return a collection of CRLs initialized from the decoded - * InputStream data. - * @throws CRLException If an error occurs decoding the CRLs. - */ - public final Collection generateCRLs(InputStream inStream) - throws CRLException - { - return certFacSpi.engineGenerateCRLs( inStream ); - } - - /** - * Generate a {@link CertPath} and initialize it with data parsed from - * the input stream. The default encoding of this factory is used. - * - * @param inStream The InputStream containing the CertPath data. - * @return A CertPath initialized from the input stream data. - * @throws CertificateException If an error occurs decoding the - * CertPath. - */ - public final CertPath generateCertPath(InputStream inStream) - throws CertificateException - { - return certFacSpi.engineGenerateCertPath(inStream); - } - - /** - * Generate a {@link CertPath} and initialize it with data parsed from - * the input stream, using the specified encoding. - * - * @param inStream The InputStream containing the CertPath data. - * @param encoding The encoding of the InputStream data. - * @return A CertPath initialized from the input stream data. - * @throws CertificateException If an error occurs decoding the - * CertPath. - */ - public final CertPath generateCertPath(InputStream inStream, String encoding) - throws CertificateException - { - return certFacSpi.engineGenerateCertPath(inStream, encoding); - } - - /** - * Generate a {@link CertPath} and initialize it with the certificates - * in the {@link java.util.List} argument. - * - * @param certificates The list of certificates with which to create - * the CertPath. - * @return A CertPath initialized from the certificates. - * @throws CertificateException If an error occurs generating the - * CertPath. - */ - public final CertPath generateCertPath(List certificates) - throws CertificateException - { - return certFacSpi.engineGenerateCertPath(certificates); - } - - /** - * Returns an Iterator of CertPath encodings supported by this - * factory, with the default encoding first. The returned Iterator - * cannot be modified. - * - * @return The Iterator of supported encodings. - */ - public final Iterator getCertPathEncodings() - { - return certFacSpi.engineGetCertPathEncodings(); - } -} // class CertificateFactory diff --git a/libjava/java/security/cert/CertificateFactorySpi.java b/libjava/java/security/cert/CertificateFactorySpi.java deleted file mode 100644 index beea9646a67..00000000000 --- a/libjava/java/security/cert/CertificateFactorySpi.java +++ /dev/null @@ -1,225 +0,0 @@ -/* CertificateFactorySpi.java --- Certificate Factory Class - Copyright (C) 1999,2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security.cert; - -import java.io.InputStream; - -import java.util.Collection; -import java.util.Iterator; -import java.util.List; - -/** - CertificateFactorySpi is the abstract class Service Provider - Interface (SPI) for the CertificateFactory class. A provider - must implement all the abstract methods if they wish to - supply a certificate factory for a particular certificate - type. Ex: X.509 - - Certificate factories are used to generate certificates and - certificate revocation lists (CRL) from their encoding. - - @since JDK 1.2 - - @author Mark Benvenuto - */ -public abstract class CertificateFactorySpi -{ - - // Constructor. - // ------------------------------------------------------------------------ - - /** - * Constructs a new CertificateFactorySpi - */ - public CertificateFactorySpi() - {} - - // Abstract methods. - // ------------------------------------------------------------------------ - - /** - Generates a Certificate based on the encoded data read - from the InputStream. - - The input stream must contain only one certificate. - - If there exists a specialized certificate class for the - certificate format handled by the certificate factory - then the return Ceritificate should be a typecast of it. - Ex: A X.509 CertificateFactory should return X509Certificate. - - For X.509 certificates, the certificate in inStream must be - DER encoded and supplied in binary or printable (Base64) - encoding. If the certificate is in Base64 encoding, it must be - bounded by -----BEGIN CERTIFICATE-----, and - -----END CERTIFICATE-----. - - @param inStream an input stream containing the certificate data - - @return a certificate initialized with InputStream data. - - @throws CertificateException Certificate parsing error - */ - public abstract Certificate engineGenerateCertificate(InputStream inStream) - throws CertificateException; - - /** - Returns a collection of certificates that were read from the - input stream. It may be empty, have only one, or have - multiple certificates. - - For a X.509 certificate factory, the stream may contain a - single DER encoded certificate or a PKCS#7 certificate - chain. This is a PKCS#7 <I>SignedData</I> object with the - most significant field being <I>certificates</I>. If no - CRLs are present, then an empty collection is returned. - - @param inStream an input stream containing the certificates - - @return a collection of certificates initialized with - the InputStream data. - - @throws CertificateException Certificate parsing error - */ - public abstract Collection engineGenerateCertificates(InputStream inStream) - throws CertificateException; - - /** - Generates a CRL based on the encoded data read - from the InputStream. - - The input stream must contain only one CRL. - - If there exists a specialized CRL class for the - CRL format handled by the certificate factory - then the return CRL should be a typecast of it. - Ex: A X.509 CertificateFactory should return X509CRL. - - @param inStream an input stream containing the CRL data - - @return a CRL initialized with InputStream data. - - @throws CRLException CRL parsing error - */ - public abstract CRL engineGenerateCRL(InputStream inStream) - throws CRLException; - - /** - Generates CRLs based on the encoded data read - from the InputStream. - - For a X.509 certificate factory, the stream may contain a - single DER encoded CRL or a PKCS#7 CRL set. This is a - PKCS#7 <I>SignedData</I> object with the most significant - field being <I>crls</I>. If no CRLs are present, then an - empty collection is returned. - - @param inStream an input stream containing the CRLs - - @return a collection of CRLs initialized with - the InputStream data. - - @throws CRLException CRL parsing error - */ - public abstract Collection engineGenerateCRLs(InputStream inStream) - throws CRLException; - - // 1.4 instance methods. - // ------------------------------------------------------------------------ - - /** - * Generate a {@link CertPath} and initialize it with data parsed from - * the input stream. The default encoding of this factory is used. - * - * @param inStream The InputStream containing the CertPath data. - * @return A CertPath initialized from the input stream data. - * @throws CertificateException If an error occurs decoding the - * CertPath. - */ - public CertPath engineGenerateCertPath(InputStream inStream) - throws CertificateException - { - throw new UnsupportedOperationException("not implemented"); - } - - /** - * Generate a {@link CertPath} and initialize it with data parsed from - * the input stream, using the specified encoding. - * - * @param inStream The InputStream containing the CertPath data. - * @param encoding The encoding of the InputStream data. - * @return A CertPath initialized from the input stream data. - * @throws CertificateException If an error occurs decoding the - * CertPath. - */ - public CertPath engineGenerateCertPath(InputStream inStream, String encoding) - throws CertificateException - { - throw new UnsupportedOperationException("not implemented"); - } - - /** - * Generate a {@link CertPath} and initialize it with the certificates - * in the {@link java.util.List} argument. - * - * @param certificates The list of certificates with which to create - * the CertPath. - * @return A CertPath initialized from the certificates. - * @throws CertificateException If an error occurs generating the - * CertPath. - */ - public CertPath engineGenerateCertPath(List certificates) - throws CertificateException - { - throw new UnsupportedOperationException("not implemented"); - } - - /** - * Returns an Iterator of CertPath encodings supported by this - * factory, with the default encoding first. The returned Iterator - * cannot be modified. - * - * @return The Iterator of supported encodings. - */ - public Iterator engineGetCertPathEncodings() - { - throw new UnsupportedOperationException("not implemented"); - } -} - diff --git a/libjava/java/security/cert/CertificateNotYetValidException.java b/libjava/java/security/cert/CertificateNotYetValidException.java deleted file mode 100644 index dfb4b483785..00000000000 --- a/libjava/java/security/cert/CertificateNotYetValidException.java +++ /dev/null @@ -1,71 +0,0 @@ -/* CertificateNotYetValidException.java -- Certificate Not Yet Valid Exception - Copyright (C) 1999, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security.cert; - -/** - * Exception for a Certificate that is not yet valid. - * - * @author Mark Benvenuto - * @since 1.2 - * @status updated to 1.4 -*/ -public class CertificateNotYetValidException extends CertificateException -{ - /** - * Compatible with JDK 1.2+. - */ - private static final long serialVersionUID = 4355919900041064702L; - - /** - * Constructs an exception without a message string. - */ - public CertificateNotYetValidException() - { - } - - /** - * Constructs an exception with a message string. - * - * @param msg A message to display with exception - */ - public CertificateNotYetValidException(String msg) - { - super(msg); - } -} diff --git a/libjava/java/security/cert/CertificateParsingException.java b/libjava/java/security/cert/CertificateParsingException.java deleted file mode 100644 index 61faa44386e..00000000000 --- a/libjava/java/security/cert/CertificateParsingException.java +++ /dev/null @@ -1,71 +0,0 @@ -/* CertificateParsingException.java -- Certificate Parsing Exception - Copyright (C) 1999, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security.cert; - -/** - * Exception for parsing a DER-encoded Certificate. - * - * @author Mark Benvenuto - * @since 1.2 - * @status updated to 1.4 -*/ -public class CertificateParsingException extends CertificateException -{ - /** - * Compatible with JDK 1.2+. - */ - private static final long serialVersionUID = -7989222416793322029L; - - /** - * Constructs an exception without a message string. - */ - public CertificateParsingException() - { - } - - /** - * Constructs an exception with a message string. - * - * @param msg a message to display with exception - */ - public CertificateParsingException(String msg) - { - super(msg); - } -} diff --git a/libjava/java/security/cert/CollectionCertStoreParameters.java b/libjava/java/security/cert/CollectionCertStoreParameters.java deleted file mode 100644 index bac1e3b3e4f..00000000000 --- a/libjava/java/security/cert/CollectionCertStoreParameters.java +++ /dev/null @@ -1,121 +0,0 @@ -/* CollectionCertStoreParameters -- collection-based cert store parameters - Copyright (C) 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security.cert; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; - -/** - * An implementation of {@link CertStoreParameters} with a simple, - * in-memory {@link Collection} of certificates and certificate - * revocation list. - * - * <p>Note that this class is not thread-safe, and its underlying - * collection may be changed at any time. - * - * @see CertStore - */ -public class CollectionCertStoreParameters implements CertStoreParameters -{ - - // Constants and fields. - // ------------------------------------------------------------------------ - - /** The underlying collection. */ - private final Collection collection; - - // Constructors. - // ------------------------------------------------------------------------ - - /** - * Creates a new CollectionCertStoreParameters with an empty, - * immutable collection. - */ - public CollectionCertStoreParameters() - { - this(Collections.EMPTY_LIST); - } - - /** - * Create a new CollectionCertStoreParameters with the specified - * collection. The argument is not copied, and subsequent changes to - * the collection will change this class's collection. - * - * @param collection The collection. - * @throws NullPointerException If <i>collection</i> is null. - */ - public CollectionCertStoreParameters(Collection collection) - { - if (collection == null) - throw new NullPointerException(); - this.collection = collection; - } - - // Instance methods. - // ------------------------------------------------------------------------ - - public Object clone() - { - return new CollectionCertStoreParameters(new ArrayList(collection)); - } - - /** - * Return the underlying collection. The collection is not copied - * before being returned, so callers may update the collection that is - * returned. - * - * @return The collection. - */ - public Collection getCollection() - { - return collection; - } - - /** - * Return a string representation of these parameters. - * - * @return The string representation of these parameters. - */ - public String toString() - { - return "CollectionCertStoreParameters: [ collection: " - + collection + " ]"; - } -} diff --git a/libjava/java/security/cert/LDAPCertStoreParameters.java b/libjava/java/security/cert/LDAPCertStoreParameters.java deleted file mode 100644 index 4414e65a092..00000000000 --- a/libjava/java/security/cert/LDAPCertStoreParameters.java +++ /dev/null @@ -1,140 +0,0 @@ -/* LDAPCertStoreParameters.java -- LDAP CertStore parameters. - Copyright (C) 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security.cert; - -/** - * Parameters for CertStores that are retrieved via the <i>lightweight - * directory access protocol</i> (<b>LDAP</b>). - * - * @see CertStore - */ -public class LDAPCertStoreParameters implements CertStoreParameters -{ - - // Constants and fields. - // ------------------------------------------------------------------------ - - /** The default LDAP port. */ - private static final int LDAP_PORT = 389; - - /** The server name. */ - private final String serverName; - - /** The LDAP port. */ - private final int port; - - // Constructors. - // ------------------------------------------------------------------------ - - /** - * Create a new LDAPCertStoreParameters object, with a servername of - * "localhost" and a port of 389. - */ - public LDAPCertStoreParameters() - { - this("localhost", LDAP_PORT); - } - - /** - * Create a new LDAPCertStoreParameters object, with a specified - * server name and a port of 389. - * - * @param serverName The LDAP server name. - * @throws NullPointerException If <i>serverName</i> is null. - */ - public LDAPCertStoreParameters(String serverName) - { - this(serverName, LDAP_PORT); - } - - /** - * Create a new LDAPCertStoreParameters object, with a specified - * server name and port. - * - * @param serverName The LDAP server name. - * @param port The LDAP port. - * @throws NullPointerException If <i>serverName</i> is null. - */ - public LDAPCertStoreParameters(String serverName, int port) - { - if (serverName == null) - throw new NullPointerException(); - this.serverName = serverName; - this.port = port; - } - - // Instance methods. - // ------------------------------------------------------------------------ - - public Object clone() - { - return new LDAPCertStoreParameters(serverName, port); - } - - /** - * Return the server name. - * - * @return The server name. - */ - public String getServerName() - { - return serverName; - } - - /** - * Return the port. - * - * @return the port. - */ - public int getPort() - { - return port; - } - - /** - * Return a string representation of these parameters. - * - * @return The string representation of these parameters. - */ - public String toString() - { - return "LDAPCertStoreParameters: [ serverName: " + serverName - + "; port: " + port + " ]"; - } -} diff --git a/libjava/java/security/cert/PKIXBuilderParameters.java b/libjava/java/security/cert/PKIXBuilderParameters.java deleted file mode 100644 index 38b3df5e78a..00000000000 --- a/libjava/java/security/cert/PKIXBuilderParameters.java +++ /dev/null @@ -1,145 +0,0 @@ -/* PKIXBuilderParameters.java -- parameters for PKIX cert path builders - Copyright (C) 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security.cert; - -import java.security.InvalidAlgorithmParameterException; -import java.security.KeyStore; -import java.security.KeyStoreException; - -import java.util.Set; - -/** - * Parameters for building certificate paths using the PKIX algorithm. - * - * @see CertPathBuilder - */ -public class PKIXBuilderParameters extends PKIXParameters -{ - - // Fields. - // ------------------------------------------------------------------------ - - /** The maximum path length. */ - private int maxPathLength; - - // Constructors. - // ------------------------------------------------------------------------ - - /** - * Create a new PKIXBuilderParameters object, populating the trusted - * certificates set with all X.509 certificates found in the given key - * store. All certificates found in the key store are assumed to be - * trusted by this constructor. - * - * @param keystore The key store. - * @param targetConstraints The target certificate constraints. - * @throws KeyStoreException If the certificates cannot be retrieved - * from the key store. - * @throws InvalidAlgorithmParameterException If there are no - * certificates in the key store. - * @throws NullPointerException If <i>keystore</i> is null. - */ - public PKIXBuilderParameters(KeyStore keystore, - CertSelector targetConstraints) - throws KeyStoreException, InvalidAlgorithmParameterException - { - super(keystore); - setTargetCertConstraints(targetConstraints); - maxPathLength = 5; - } - - /** - * Create a new PKIXBuilderParameters object, populating the trusted - * certificates set with the elements of the given set, each of which - * must be a {@link TrustAnchor}. - * - * @param trustAnchors The set of trust anchors. - * @param targetConstraints The target certificate constraints. - * @throws InvalidAlgorithmParameterException If there are no - * certificates in the set. - * @throws NullPointerException If <i>trustAnchors</i> is null. - * @throws ClassCastException If every element in <i>trustAnchors</i> - * is not a {@link TrustAnchor}. - */ - public PKIXBuilderParameters(Set trustAnchors, CertSelector targetConstraints) - throws InvalidAlgorithmParameterException - { - super(trustAnchors); - setTargetCertConstraints(targetConstraints); - maxPathLength = 5; - } - - // Instance methods. - // ------------------------------------------------------------------------ - - /** - * Returns the maximum length of certificate paths to build. - * - * <p>If this value is 0 it is taken to mean that the certificate path - * should contain only one certificate. A value of -1 means that the - * certificate path length is unconstrained. The default value is 5. - * - * @return The maximum path length. - */ - public int getMaxPathLength() - { - return maxPathLength; - } - - /** - * Sets the maximum length of certificate paths to build. - * - * @param maxPathLength The new path length. - * @throws IllegalArgumentException If <i>maxPathLength</i> is less - * than -1. - */ - public void setMaxPathLength(int maxPathLength) - { - if (maxPathLength < -1) - throw new IllegalArgumentException(); - this.maxPathLength = maxPathLength; - } - - public String toString() - { - StringBuffer buf = new StringBuffer(super.toString()); - buf.insert(buf.length() - 2, "; Max Path Length=" + maxPathLength); - return buf.toString(); - } -} diff --git a/libjava/java/security/cert/PKIXCertPathBuilderResult.java b/libjava/java/security/cert/PKIXCertPathBuilderResult.java deleted file mode 100644 index 5091dd41298..00000000000 --- a/libjava/java/security/cert/PKIXCertPathBuilderResult.java +++ /dev/null @@ -1,102 +0,0 @@ -/* PKIXCertPathBuilderResult.java -- PKIX cert path bulider result - Copyright (C) 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security.cert; - -/** - * The result of calling the {@link - * CertPathBuilder#build(java.security.cert.CertPathParameters)} method - * of PKIX {@link CertPathBuilder}s. - * - * @see CertPathBuilder - * @see CertPathBuilderResult - */ -public class PKIXCertPathBuilderResult extends PKIXCertPathValidatorResult - implements CertPathBuilderResult -{ - - // Fields. - // ------------------------------------------------------------------------ - - /** The certificate path. */ - private CertPath certPath; - - // Constructor. - // ------------------------------------------------------------------------ - - /** - * Creates a new PKIXCertPathBuilderResult. - * - * @param certPath The certificate path. - * @param trustAnchor The trust anchor. - * @param policyTree The root node of the policy tree. - * @param subjectPublicKey The public key. - * @throws NullPointerException If <i>certPath</i>, <i>trustAnchor</i> or - * <i>subjectPublicKey</i> is null. - */ - public PKIXCertPathBuilderResult(CertPath certPath, - TrustAnchor trustAnchor, - PolicyNode policyTree, - java.security.PublicKey subjectPublicKey) - { - super(trustAnchor, policyTree, subjectPublicKey); - if (certPath == null) - throw new NullPointerException(); - this.certPath = certPath; - } - - // Instance methods. - // ------------------------------------------------------------------------ - - /** - * Returns the certificate path that was built. - * - * @return The certificate path that was built. - */ - public CertPath getCertPath() - { - return certPath; - } - - public String toString() - { - StringBuffer buf = new StringBuffer(super.toString()); - buf.insert(buf.length() - 2, "; CertPath=" + certPath); - return buf.toString(); - } -} diff --git a/libjava/java/security/cert/PKIXCertPathChecker.java b/libjava/java/security/cert/PKIXCertPathChecker.java deleted file mode 100644 index 7a33576e1bb..00000000000 --- a/libjava/java/security/cert/PKIXCertPathChecker.java +++ /dev/null @@ -1,133 +0,0 @@ -/* PKIXCertPathChecker.java -- checks X.509 certificate paths. - Copyright (C) 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security.cert; - -import java.util.Collection; -import java.util.Set; - -/** - * A validator for X.509 certificates when approving certificate chains. - * - * <p>Concrete subclasses can be passed to the {@link - * PKIXParameters#setCertPathCheckers(java.util.List)} and {@link - * PKIXParameters#addCertPathChecker(java.security.cert.PKIXCertPathChecker} - * methods, which are then used to set up PKIX certificate chain - * builders or validators. These classes then call the {@link - * #check(java.security.cert.Certificate,java.util.Collection)} method - * of this class, performing whatever checks on the certificate, - * throwing an exception if any check fails. - * - * <p>Subclasses of this must be able to perform their checks in the - * backward direction -- from the most-trusted certificate to the target - * -- and may optionally support forward checking -- from the target to - * the most-trusted certificate. - * - * @see PKIXParameters - */ -public abstract class PKIXCertPathChecker implements Cloneable -{ - - // Constructor. - // ------------------------------------------------------------------------ - - /** Default constructor. */ - protected PKIXCertPathChecker() - { - super(); - } - - // Cloneable interface. - // ------------------------------------------------------------------------ - - public Object clone() - { - try - { - return super.clone(); - } - catch (CloneNotSupportedException cnse) - { - throw new InternalError(cnse.getMessage()); - } - } - - // Abstract methods. - // ------------------------------------------------------------------------ - - /** - * Initialize this PKIXCertPathChecker. If subclasses support forward - * checking, a value of true can be passed to this method, and - * certificates can be validated from the target certificate to the - * most-trusted certifcate. - * - * @param forward The direction of this PKIXCertPathChecker. - * @throws CertPathValidatorException If <i>forward</i> is true and - * this class does not support forward checking. - */ - public abstract void init(boolean forward) throws CertPathValidatorException; - - /** - * Returns whether or not this class supports forward checking. - * - * @return Whether or not this class supports forward checking. - */ - public abstract boolean isForwardCheckingSupported(); - - /** - * Returns an immutable set of X.509 extension object identifiers (OIDs) - * supported by this PKIXCertPathChecker. - * - * @return An immutable set of Strings of the supported X.509 OIDs, or - * null if no extensions are supported. - */ - public abstract Set getSupportedExtensions(); - - /** - * Checks a certificate, removing any critical extensions that are - * resolved in this check. - * - * @param cert The certificate to check. - * @param unresolvedCritExts The (mutable) collection of as-of-yet - * unresolved critical extensions, as OID strings. - * @throws CertPathValidatorException If this certificate fails this - * check. - */ - public abstract void check(Certificate cert, Collection unresolvedCritExts) - throws CertPathValidatorException; -} diff --git a/libjava/java/security/cert/PKIXCertPathValidatorResult.java b/libjava/java/security/cert/PKIXCertPathValidatorResult.java deleted file mode 100644 index 5a1660c3bc9..00000000000 --- a/libjava/java/security/cert/PKIXCertPathValidatorResult.java +++ /dev/null @@ -1,142 +0,0 @@ -/* PKIXCertPathValidatorResult.java -- PKIX cert path builder result - Copyright (C) 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security.cert; - -import java.security.PublicKey; - -/** - * Results returned by the {@link - * CertPathValidator#validate(java.security.cert.CertPath,java.security.cert.CertPathParameters)} - * method for PKIX {@link CertPathValidator}s. - * - * @see CertPathValidator - */ -public class PKIXCertPathValidatorResult implements CertPathValidatorResult -{ - - // Fields. - // ------------------------------------------------------------------------ - - /** The trust anchor. */ - private final TrustAnchor trustAnchor; - - /** The root node of the policy tree. */ - private final PolicyNode policyTree; - - /** The subject's public key. */ - private final PublicKey subjectPublicKey; - - // Constructor. - // ------------------------------------------------------------------------ - - /** - * Creates a new PKIXCertPathValidatorResult. - * - * @param trustAnchor The trust anchor. - * @param policyTree The root node of the policy tree. - * @param subjectPublicKey The public key. - * @throws NullPointerException If either <i>trustAnchor</i> or - * <i>subjectPublicKey</i> is null. - */ - public PKIXCertPathValidatorResult(TrustAnchor trustAnchor, - PolicyNode policyTree, - PublicKey subjectPublicKey) - { - if (trustAnchor == null || subjectPublicKey == null) - throw new NullPointerException(); - this.trustAnchor = trustAnchor; - this.policyTree = policyTree; - this.subjectPublicKey = subjectPublicKey; - } - - // Instance methods. - // ------------------------------------------------------------------------ - - /** - * Returns the trust anchor. - * - * @return The trust anchor. - */ - public TrustAnchor getTrustAnchor() - { - return trustAnchor; - } - - /** - * Returns the root node of the policy tree. - * - * @return The root node of the policy tree. - */ - public PolicyNode getPolicyTree() - { - return policyTree; - } - - /** - * Returns the subject public key. - * - * @return The subject public key. - */ - public PublicKey getPublicKey() - { - return subjectPublicKey; - } - - /** - * Returns a copy of this object. - * - * @return The copy. - */ - public Object clone() - { - return new PKIXCertPathValidatorResult(trustAnchor, policyTree, - subjectPublicKey); - } - - /** - * Returns a printable string representation of this result. - * - * @return A printable string representation of this result. - */ - public String toString() - { - return "[ Trust Anchor=" + trustAnchor + "; Policy Tree=" - + policyTree + "; Subject Public Key=" + subjectPublicKey + " ]"; - } -} diff --git a/libjava/java/security/cert/PKIXParameters.java b/libjava/java/security/cert/PKIXParameters.java deleted file mode 100644 index 4a987115a29..00000000000 --- a/libjava/java/security/cert/PKIXParameters.java +++ /dev/null @@ -1,546 +0,0 @@ -/* PKIXParameters.java -- parameters for the PKIX cert path algorithm - Copyright (C) 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security.cert; - -import java.security.InvalidAlgorithmParameterException; -import java.security.KeyStore; -import java.security.KeyStoreException; - -import java.util.Collections; -import java.util.Date; -import java.util.Enumeration; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; - -/** - * Parameters for verifying certificate paths using the PKIX - * (Public-Key Infrastructure (X.509)) algorithm. - * - * @see CertPathBulider - */ -public class PKIXParameters implements CertPathParameters -{ - - // Fields. - // ------------------------------------------------------------------------ - - /** The trusted certificates. */ - private final Set trustAnchors; - - /** The set of initial policy identifiers. */ - private final Set initPolicies; - - /** The list of certificate stores. */ - private final List certStores; - - /** The list of path checkers. */ - private final List pathCheckers; - - /** The revocation enabled flag. */ - private boolean revocationEnabled; - - /** The explicit policy required flag. */ - private boolean exPolicyRequired; - - /** The policy mapping inhibited flag. */ - private boolean policyMappingInhibited; - - /** The any policy inhibited flag. */ - private boolean anyPolicyInhibited; - - /** The policy qualifiers rejected flag. */ - private boolean policyQualRejected; - - /** The target validation date. */ - private Date date; - - /** The signature algorithm provider. */ - private String sigProvider; - - /** The target constraints. */ - private CertSelector targetConstraints; - - // Constructors. - // ------------------------------------------------------------------------ - - /** - * Create a new PKIXParameters object, populating the trusted - * certificates set with all certificates found in the given key - * store. All certificates found in the key store are assumed to be - * trusted by this constructor. - * - * @param keystore The key store. - * @throws KeyStoreException If the certificates cannot be retrieved - * from the key store. - * @throws InvalidAlgorithmParameterException If there are no - * certificates in the key store. - * @throws NullPointerException If <i>keystore</i> is null. - */ - public PKIXParameters(KeyStore keystore) - throws KeyStoreException, InvalidAlgorithmParameterException - { - this(); - for (Enumeration e = keystore.aliases(); e.hasMoreElements(); ) - { - String alias = (String) e.nextElement(); - if (!keystore.isCertificateEntry(alias)) - continue; - Certificate cert = keystore.getCertificate(alias); - if (cert instanceof X509Certificate) - trustAnchors.add(new TrustAnchor((X509Certificate) cert, null)); - } - if (trustAnchors.isEmpty()) - throw new InvalidAlgorithmParameterException("no certs in the key store"); - } - - /** - * Create a new PKIXParameters object, populating the trusted - * certificates set with the elements of the given set, each of which - * must be a {@link TrustAnchor}. - * - * @param trustAnchors The set of trust anchors. - * @throws InvalidAlgorithmParameterException If there are no - * certificates in the set. - * @throws NullPointerException If <i>trustAnchors</i> is null. - * @throws ClassCastException If every element in <i>trustAnchors</i> - * is not a {@link TrustAnchor}. - */ - public PKIXParameters(Set trustAnchors) - throws InvalidAlgorithmParameterException - { - this(); - setTrustAnchors(trustAnchors); - } - - /** - * Default constructor. - */ - private PKIXParameters() - { - trustAnchors = new HashSet(); - initPolicies = new HashSet(); - certStores = new LinkedList(); - pathCheckers = new LinkedList(); - revocationEnabled = true; - exPolicyRequired = false; - policyMappingInhibited = false; - anyPolicyInhibited = false; - policyQualRejected = true; - } - - /** - * Copying constructor for cloning. - * - * @param that The instance being cloned. - */ - private PKIXParameters(PKIXParameters that) - { - this(); - this.trustAnchors.addAll(that.trustAnchors); - this.initPolicies.addAll(that.initPolicies); - this.certStores.addAll(that.certStores); - this.pathCheckers.addAll(that.pathCheckers); - this.revocationEnabled = that.revocationEnabled; - this.exPolicyRequired = that.exPolicyRequired; - this.policyMappingInhibited = that.policyMappingInhibited; - this.anyPolicyInhibited = that.anyPolicyInhibited; - this.policyQualRejected = that.policyQualRejected; - this.date = that.date; - this.sigProvider = that.sigProvider; - this.targetConstraints = that.targetConstraints != null - ? (CertSelector) that.targetConstraints.clone() : null; - } - - // Instance methods. - // ------------------------------------------------------------------------ - - /** - * Returns an immutable set of trust anchors. The set returned will - * never be null and will never be empty. - * - * @return A (never null, never empty) immutable set of trust anchors. - */ - public Set getTrustAnchors() - { - return Collections.unmodifiableSet(trustAnchors); - } - - /** - * Sets the trust anchors of this class, replacing the current trust - * anchors with those in the given set. The supplied set is copied to - * prevent modification. - * - * @param trustAnchors The new set of trust anchors. - * @throws InvalidAlgorithmParameterException If there are no - * certificates in the set. - * @throws NullPointerException If <i>trustAnchors</i> is null. - * @throws ClassCastException If every element in <i>trustAnchors</i> - * is not a {@link TrustAnchor}. - */ - public void setTrustAnchors(Set trustAnchors) - throws InvalidAlgorithmParameterException - { - if (trustAnchors.isEmpty()) - throw new InvalidAlgorithmParameterException("no trust anchors"); - this.trustAnchors.clear(); - for (Iterator i = trustAnchors.iterator(); i.hasNext(); ) - { - this.trustAnchors.add((TrustAnchor) i.next()); - } - } - - /** - * Returns the set of initial policy identifiers (as OID strings). If - * any policy is accepted, this method returns the empty set. - * - * @return An immutable set of initial policy OID strings, or the - * empty set if any policy is acceptable. - */ - public Set getInitialPolicies() - { - return Collections.unmodifiableSet(initPolicies); - } - - /** - * Sets the initial policy identifiers (as OID strings). If the - * argument is null or the empty set, then any policy identifier will - * be accepted. - * - * @param initPolicies The new set of policy strings, or null. - * @throws ClassCastException If any element in <i>initPolicies</i> is - * not a string. - */ - public void setInitialPolicies(Set initPolicies) - { - this.initPolicies.clear(); - if (initPolicies == null) - return; - for (Iterator i = initPolicies.iterator(); i.hasNext(); ) - { - this.initPolicies.add((String) i.next()); - } - } - - /** - * Add a {@link CertStore} to the list of cert stores. - * - * @param store The CertStore to add. - */ - public void addCertStore(CertStore store) - { - if (store != null) - certStores.add(store); - } - - /** - * Returns an immutable list of cert stores. This method never returns - * null. - * - * @return The list of cert stores. - */ - public List getCertStores() - { - return Collections.unmodifiableList(certStores); - } - - /** - * Set the cert stores. If the argument is null the list of cert - * stores will be empty. - * - * @param certStores The cert stores. - */ - public void setCertStores(List certStores) - { - this.certStores.clear(); - if (certStores == null) - return; - for (Iterator i = certStores.iterator(); i.hasNext(); ) - { - this.certStores.add((CertStore) i.next()); - } - } - - /** - * Returns the value of the <i>revocation enabled</i> flag. The default - * value for this flag is <code>true</code>. - * - * @return The <i>revocation enabled</i> flag. - */ - public boolean isRevocationEnabled() - { - return revocationEnabled; - } - - /** - * Sets the value of the <i>revocation enabled</i> flag. - * - * @param value The new value. - */ - public void setRevocationEnabled(boolean value) - { - revocationEnabled = value; - } - - /** - * Returns the value of the <i>explicit policy required</i> flag. The - * default value of this flag is <code>false</code>. - * - * @return The <i>explicit policy required</i> flag. - */ - public boolean isExplicitPolicyRequired() - { - return exPolicyRequired; - } - - /** - * Sets the value of the <i>explicit policy required</i> flag. - * - * @param value The new value. - */ - public void setExplicitPolicyRequired(boolean value) - { - exPolicyRequired = value; - } - - /** - * Returns the value of the <i>policy mapping inhibited</i> flag. The - * default value of this flag is <code>false</code>. - * - * @return The <i>policy mapping inhibited</i> flag. - */ - public boolean isPolicyMappingInhibited() - { - return policyMappingInhibited; - } - - /** - * Sets the value of the <i>policy mapping inhibited</i> flag. - * - * @param value The new value. - */ - public void setPolicyMappingInhibited(boolean value) - { - policyMappingInhibited = value; - } - - /** - * Returns the value of the <i>any policy inhibited</i> flag. The - * default value of this flag is <code>false</code>. - * - * @return The <i>any policy inhibited</i> flag. - */ - public boolean isAnyPolicyInhibited() - { - return anyPolicyInhibited; - } - - /** - * Sets the value of the <i>any policy inhibited</i> flag. - * - * @param value The new value. - */ - public void setAnyPolicyInhibited(boolean value) - { - anyPolicyInhibited = value; - } - - /** - * Returns the value of the <i>policy qualifiers enabled</i> flag. The - * default value of this flag is <code>true</code>. - * - * @return The <i>policy qualifiers enabled</i> flag. - */ - public boolean getPolicyQualifiersRejected() - { - return policyQualRejected; - } - - /** - * Sets the value of the <i>policy qualifiers enabled</i> flag. - * - * @param value The new value. - */ - public void setPolicyQualifiersRejected(boolean value) - { - policyQualRejected = value; - } - - /** - * Returns the date for which the certificate path should be - * validated, or null if the current time should be used. The date - * object is copied to prevent subsequent modification. - * - * @return The date, or null if not set. - */ - public Date getDate() - { - return date != null ? (Date) date.clone() : null; - } - - /** - * Sets the date for which the certificate path should be validated, - * or null if the current time should be used. - * - * @param date The new date, or null. - */ - public void setDate(Date date) - { - if (date != null) - this.date = (Date) date.clone(); - else - this.date = null; - } - - /** - * Add a certificate path checker. - * - * @param checker The certificate path checker to add. - */ - public void addCertPathChecker(PKIXCertPathChecker checker) - { - if (checker != null) - pathCheckers.add(checker); - } - - /** - * Returns an immutable list of all certificate path checkers. - * - * @return An immutable list of all certificate path checkers. - */ - public List getCertPathCheckers() - { - return Collections.unmodifiableList(pathCheckers); - } - - /** - * Sets the certificate path checkers. If the argument is null, the - * list of checkers will merely be cleared. - * - * @param pathCheckers The new list of certificate path checkers. - * @throws ClassCastException If any element of <i>pathCheckers</i> is - * not a {@link PKIXCertPathChecker}. - */ - public void setCertPathCheckers(List pathCheckers) - { - this.pathCheckers.clear(); - if (pathCheckers == null) - return; - for (Iterator i = pathCheckers.iterator(); i.hasNext(); ) - { - this.pathCheckers.add((PKIXCertPathChecker) i.next()); - } - } - - /** - * Returns the signature algorithm provider, or null if not set. - * - * @return The signature algorithm provider, or null if not set. - */ - public String getSigProvider() - { - return sigProvider; - } - - /** - * Sets the signature algorithm provider, or null if there is no - * preferred provider. - * - * @param sigProvider The signature provider name. - */ - public void setSigProvider(String sigProvider) - { - this.sigProvider = sigProvider; - } - - /** - * Returns the constraints placed on the target certificate, or null - * if there are none. The target constraints are copied to prevent - * subsequent modification. - * - * @return The target constraints, or null. - */ - public CertSelector getTargetCertConstraints() - { - return targetConstraints != null - ? (CertSelector) targetConstraints.clone() : null; - } - - /** - * Sets the constraints placed on the target certificate. - * - * @param targetConstraints The target constraints. - */ - public void setTargetCertConstraints(CertSelector targetConstraints) - { - this.targetConstraints = targetConstraints != null - ? (CertSelector) targetConstraints.clone() : null; - } - - /** - * Returns a copy of these parameters. - * - * @return The copy. - */ - public Object clone() - { - return new PKIXParameters(this); - } - - /** - * Returns a printable representation of these parameters. - * - * @return A printable representation of these parameters. - */ - public String toString() { - return "[ Trust Anchors: " + trustAnchors + "; Initial Policy OIDs=" - + (initPolicies != null ? initPolicies.toString() : "any") - + "; Validity Date=" + date + "; Signature Provider=" - + sigProvider + "; Default Revocation Enabled=" + revocationEnabled - + "; Explicit Policy Required=" + exPolicyRequired - + "; Policy Mapping Inhibited=" + policyMappingInhibited - + "; Any Policy Inhibited=" + anyPolicyInhibited - + "; Policy Qualifiers Rejected=" + policyQualRejected - + "; Target Cert Contstraints=" + targetConstraints - + "; Certification Path Checkers=" + pathCheckers - + "; CertStores=" + certStores + " ]"; - } -} diff --git a/libjava/java/security/cert/PolicyNode.java b/libjava/java/security/cert/PolicyNode.java deleted file mode 100644 index 58d411cd3ad..00000000000 --- a/libjava/java/security/cert/PolicyNode.java +++ /dev/null @@ -1,102 +0,0 @@ -/* PolicyNode.java -- a single node in a policy tree - Copyright (C) 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security.cert; - -public interface PolicyNode -{ - - /** - * Get the iterator of the child nodes of this node. The returned - * iterator is (naturally) unmodifiable. - * - * @return An iterator over the child nodes. - */ - java.util.Iterator getChildren(); - - /** - * Get the depth of this node within the tree, starting at 0 for the - * root node. - * - * @return The depth of this node. - */ - int getDepth(); - - /** - * Returns a set of policies (string OIDs) that will satisfy this - * node's policy. The root node should always return the singleton set - * with the element "any-policy". - * - * @return The set of expected policies. - */ - java.util.Set getExpectedPolicies(); - - /** - * Returns the parent node of this node, or null if this is the root - * node. - * - * @return The parent node, or null. - */ - PolicyNode getParent(); - - /** - * Returns a set of {@link PolicyQualifierInfo} objects that qualify - * the valid policy of this node. The root node should always return - * the empty set. - * - * @return The set of {@link PolicyQualifierInfo} objects. - */ - java.util.Set getPolicyQualifiers(); - - /** - * Get the policy OID this node represents. The root node should return - * the special value "any-policy". - * - * @return The policy of this node. - */ - String getValidPolicy(); - - /** - * Return the criticality flag of this policy node. Nodes who return - * true for this method should be considered critical. The root node - * is never critical. - * - * @return The criticality flag. - */ - boolean isCritical(); -} diff --git a/libjava/java/security/cert/PolicyQualifierInfo.java b/libjava/java/security/cert/PolicyQualifierInfo.java deleted file mode 100644 index 7dcf2315632..00000000000 --- a/libjava/java/security/cert/PolicyQualifierInfo.java +++ /dev/null @@ -1,168 +0,0 @@ -/* PolicyQualifierInfo.java -- policy qualifier info object. - Copyright (C) 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security.cert; - -import gnu.java.io.ASN1ParsingException; -import gnu.java.security.OID; -import gnu.java.security.der.DERReader; -import gnu.java.security.der.DERValue; - -import java.io.ByteArrayInputStream; -import java.io.IOException; - -/** - * The PolicyQualifierInfo X.509 certificate extension. - * PolicyQualifierInfo objects are represented by the ASN.1 structure: - * - * <pre> - * PolicyQualifierInfo ::= SEQUENCE { - * policyQualifierId PolicyQualifierId, - * qualifier ANY DEFINED BY policyQualifierId - * } - * - * PolicyQualifierId ::= OBJECT IDENTIFIER - * </pre> - * - * @since JDK 1.4 - */ -public final class PolicyQualifierInfo -{ - - // Fields. - // ------------------------------------------------------------------------ - - /** The <code>policyQualifierId</code> field. */ - private OID oid; - - /** The DER encoded form of this object. */ - private byte[] encoded; - - /** The DER encoded form of the <code>qualifier</code> field. */ - private DERValue qualifier; - - // Constructor. - // ------------------------------------------------------------------------ - - /** - * Create a new PolicyQualifierInfo object from the DER encoded form - * passed in the byte array. The argument is copied. - * - * <p>The ASN.1 form of PolicyQualifierInfo is: -<pre> -PolicyQualifierInfo ::= SEQUENCE { - policyQualifierId PolicyQualifierId, - qualifier ANY DEFINED BY policyQualifierId -} - -PolicyQualifierId ::= OBJECT IDENTIFIER -</pre> - * - * @param encoded The DER encoded form. - * @throws IOException If the structure cannot be parsed from the - * encoded bytes. - */ - public PolicyQualifierInfo(byte[] encoded) throws IOException - { - if (encoded == null) - throw new IOException("null bytes"); - this.encoded = (byte[]) encoded.clone(); - DERReader in = new DERReader(new ByteArrayInputStream(this.encoded)); - DERValue qualInfo = in.read(); - if (!qualInfo.isConstructed()) - throw new ASN1ParsingException("malformed PolicyQualifierInfo"); - DERValue val = in.read(); - if (!(val.getValue() instanceof OID)) - throw new ASN1ParsingException("value read not an OBJECT IDENTIFIER"); - oid = (OID) val.getValue(); - if (val.getEncodedLength() < val.getLength()) - qualifier = in.read(); - } - - // Instance methods. - // ------------------------------------------------------------------------ - - /** - * Returns the <code>policyQualifierId</code> field of this structure, - * as a dotted-decimal representation of the object identifier. - * - * @return This structure's OID field. - */ - public String getPolicyQualifierId() - { - return oid.toString(); - } - - /** - * Returns the DER encoded form of this object; the contents of the - * returned byte array are equivalent to those that were passed to the - * constructor. The byte array is cloned every time this method is - * called. - * - * @return The encoded form. - */ - public byte[] getEncoded() - { - return (byte[]) encoded.clone(); - } - - /** - * Get the <code>qualifier</code> field of this object, as a DER - * encoded byte array. The byte array returned is cloned every time - * this method is called. - * - * @return The encoded qualifier. - */ - public byte[] getPolicyQualifier() - { - if (qualifier == null) - return new byte[0]; - return qualifier.getEncoded(); - } - - /** - * Returns a printable string representation of this object. - * - * @return The string representation. - */ - public String toString() - { - return "PolicyQualifierInfo { policyQualifierId ::= " + oid - + ", qualifier ::= " + qualifier + " }"; - } -} diff --git a/libjava/java/security/cert/TrustAnchor.java b/libjava/java/security/cert/TrustAnchor.java deleted file mode 100644 index 2110ed5181d..00000000000 --- a/libjava/java/security/cert/TrustAnchor.java +++ /dev/null @@ -1,185 +0,0 @@ -/* TrustAnchor.java -- an ultimately-trusted certificate. - Copyright (C) 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security.cert; - -import gnu.java.security.x509.X500DistinguishedName; - -import java.security.PublicKey; - -/** - * An ultimately-trusted certificate to serve as the root of a - * certificate chain. - * - * @author Casey Marshall (rsdio@metastatic.org) - */ -public class TrustAnchor -{ - - // Fields. - // ------------------------------------------------------------------------ - - /** The certificate authority's distinguished name. */ - private final X500DistinguishedName caName; - - /** The certficate authority's public key. */ - private final PublicKey caKey; - - /** The certficate authority's certificate. */ - private final X509Certificate trustedCert; - - /** The encoded name constraints bytes. */ - private final byte[] nameConstraints; - - // Constnuctors. - // ------------------------------------------------------------------------ - - /** - * Create a new trust anchor from a certificate and (optional) name - * constraints. - * - * <p>If the <i>nameConstraints</i> argument in non-null, it will be - * copied to prevent modification. - * - * @param trustedCert The trusted certificate. - * @param nameConstraints The encoded nameConstraints. - */ - public TrustAnchor(X509Certificate trustedCert, byte[] nameConstraints) - { - if (trustedCert == null) - throw new NullPointerException(); - this.trustedCert = trustedCert; - caName = null; - caKey = null; - if (nameConstraints != null) - this.nameConstraints = (byte[]) nameConstraints.clone(); - else - this.nameConstraints = null; - } - - /** - * Create a new trust anchor from a certificate authority's - * distinguished name, public key, and (optional) name constraints. - * - * <p>If the <i>nameConstraints</i> argument in non-null, it will be - * copied to prevent modification. - * - * @params caName The CA's distinguished name. - * @params caKey The CA's public key. - * @params nameConstraints The encoded nameConstraints. - */ - public TrustAnchor(String caName, PublicKey caKey, byte[] nameConstraints) - { - if (caName == null || caKey == null) - throw new NullPointerException(); - if (caName.length() == 0) - throw new IllegalArgumentException(); - trustedCert = null; - this.caName = new X500DistinguishedName(caName); - this.caKey = caKey; - if (nameConstraints != null) - this.nameConstraints = (byte[]) nameConstraints.clone(); - else - this.nameConstraints = null; - } - - // Instance methods. - // ------------------------------------------------------------------------ - - /** - * Return the trusted certificate, or null if none was specified. - * - * @return The trusted certificate. - */ - public final X509Certificate getTrustedCert() - { - return trustedCert; - } - - /** - * Return the certificate authority's distinguished name, or null if - * none was specified. - * - * @return The CA's distinguished name. - */ - public final String getCAName() - { - if (caName != null) - return caName.toString(); - return null; - } - - /** - * Return the certificate authority's public key, or null if none was - * specified. - * - * @return The CA's public key. - */ - public final PublicKey getCAPublicKey() - { - return caKey; - } - - /** - * Return the encoded name constraints, or null if none was specified. - * - * <p>The name constraints byte array is copied when this method is - * called to prevent modification. - * - * @return The encoded name constraints. - */ - public final byte[] getNameConstraints() - { - if (nameConstraints == null) - return null; - return (byte[]) nameConstraints.clone(); - } - - /** - * Return a printable representation of this trust anchor. - * - * @return The printable representation. - */ - public String toString() - { - if (trustedCert == null) - return "[ Trusted CA Public Key=" + caKey + ", Trusted CA Issuer Name=" - + caName.toString() + " ]"; - return "[ Trusted CA Certificate=" + trustedCert + " ]"; - } -} diff --git a/libjava/java/security/cert/X509CRL.java b/libjava/java/security/cert/X509CRL.java deleted file mode 100644 index 5657b3eb3f5..00000000000 --- a/libjava/java/security/cert/X509CRL.java +++ /dev/null @@ -1,397 +0,0 @@ -/* X509CRL.java --- X.509 Certificate Revocation List - Copyright (C) 1999, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security.cert; - -import java.math.BigInteger; -import java.security.InvalidKeyException; -import java.security.NoSuchAlgorithmException; -import java.security.NoSuchProviderException; -import java.security.Principal; -import java.security.PublicKey; -import java.security.SignatureException; -import java.util.Date; -import java.util.Set; - -import javax.security.auth.x500.X500Principal; - -/** - The X509CRL class is the abstract class used to manage - X.509 Certificate Revocation Lists. The CRL is a list of - time stamped entries which indicate which lists have been - revoked. The list is signed by a Certificate Authority (CA) - and made publically available in a repository. - - Each revoked certificate in the CRL is identified by its - certificate serial number. When a piece of code uses a - certificate, the certificates validity is checked by - validating its signature and determing that it is not - only a recently acquired CRL. The recently aquired CRL - is depends on the local policy in affect. The CA issues - a new CRL periodically and entries are removed as the - certificate expiration date is reached - - - A description of the X.509 v2 CRL follows below from rfc2459. - - "The X.509 v2 CRL syntax is as follows. For signature calculation, - the data that is to be signed is ASN.1 DER encoded. ASN.1 DER - encoding is a tag, length, value encoding system for each element. - - CertificateList ::= SEQUENCE { - tbsCertList TBSCertList, - signatureAlgorithm AlgorithmIdentifier, - signatureValue BIT STRING } - - TBSCertList ::= SEQUENCE { - version Version OPTIONAL, - -- if present, shall be v2 - signature AlgorithmIdentifier, - issuer Name, - thisUpdate Time, - nextUpdate Time OPTIONAL, - revokedCertificates SEQUENCE OF SEQUENCE { - userCertificate CertificateSerialNumber, - revocationDate Time, - crlEntryExtensions Extensions OPTIONAL - -- if present, shall be v2 - } OPTIONAL, - crlExtensions [0] EXPLICIT Extensions OPTIONAL - -- if present, shall be v2 - }" - - @author Mark Benvenuto - - @since JDK 1.2 -*/ -public abstract class X509CRL extends CRL implements X509Extension -{ - - /** - Constructs a new X509CRL. - */ - protected X509CRL() - { - super("X.509"); - } - - /** - Compares this X509CRL to other. It checks if the - object if instanceOf X509CRL and then checks if - the encoded form matches. - - @param other An Object to test for equality - - @return true if equal, false otherwise - */ - public boolean equals(Object other) - { - if( other instanceof X509CRL ) { - try { - X509CRL x = (X509CRL) other; - if( getEncoded().length != x.getEncoded().length ) - return false; - - byte[] b1 = getEncoded(); - byte[] b2 = x.getEncoded(); - - for( int i = 0; i < b1.length; i++ ) - if( b1[i] != b2[i] ) - return false; - - } catch( CRLException crle ) { - return false; - } - return true; - } - return false; - } - - /** - Returns a hash code for this X509CRL in its encoded - form. - - @return A hash code of this class - */ - public int hashCode() - { - return super.hashCode(); - } - - /** - Gets the DER ASN.1 encoded format for this X.509 CRL. - - @return byte array containg encoded form - - @throws CRLException if an error occurs - */ - public abstract byte[] getEncoded() throws CRLException; - - /** - Verifies that this CRL was properly signed with the - PublicKey that corresponds to its private key. - - @param key PublicKey to verify with - - @throws CRLException encoding error - @throws NoSuchAlgorithmException unsupported algorithm - @throws InvalidKeyException incorrect key - @throws NoSuchProviderException no provider - @throws SignatureException signature error - */ - public abstract void verify(PublicKey key) - throws CRLException, - NoSuchAlgorithmException, - InvalidKeyException, - NoSuchProviderException, - SignatureException; - - /** - Verifies that this CRL was properly signed with the - PublicKey that corresponds to its private key and uses - the signature engine provided by the provider. - - @param key PublicKey to verify with - @param sigProvider Provider to use for signature algorithm - - @throws CRLException encoding error - @throws NoSuchAlgorithmException unsupported algorithm - @throws InvalidKeyException incorrect key - @throws NoSuchProviderException incorrect provider - @throws SignatureException signature error - */ - public abstract void verify(PublicKey key, - String sigProvider) - throws CRLException, - NoSuchAlgorithmException, - InvalidKeyException, - NoSuchProviderException, - SignatureException; - - /** - Gets the version of this CRL. - - The ASN.1 encoding is: - - version Version OPTIONAL, - -- if present, shall be v2 - - Version ::= INTEGER { v1(0), v2(1), v3(2) } - - Consult rfc2459 for more information. - - @return the version number, Ex: 1 or 2 - */ - public abstract int getVersion(); - - /** - Returns the issuer (issuer distinguished name) of the CRL. - The issuer is the entity who signed and issued the - Certificate Revocation List. - - The ASN.1 DER encoding is: - - issuer Name, - - Name ::= CHOICE { - RDNSequence } - - RDNSequence ::= SEQUENCE OF RelativeDistinguishedName - - RelativeDistinguishedName ::= - SET OF AttributeTypeAndValue - - AttributeTypeAndValue ::= SEQUENCE { - type AttributeType, - value AttributeValue } - - AttributeType ::= OBJECT IDENTIFIER - - AttributeValue ::= ANY DEFINED BY AttributeType - - DirectoryString ::= CHOICE { - teletexString TeletexString (SIZE (1..MAX)), - printableString PrintableString (SIZE (1..MAX)), - universalString UniversalString (SIZE (1..MAX)), - utf8String UTF8String (SIZE (1.. MAX)), - bmpString BMPString (SIZE (1..MAX)) } - - Consult rfc2459 for more information. - - @return the issuer in the Principal class - */ - public abstract Principal getIssuerDN(); - - /** - Returns the thisUpdate date of the CRL. - - The ASN.1 DER encoding is: - - thisUpdate Time, - - Time ::= CHOICE { - utcTime UTCTime, - generalTime GeneralizedTime } - - Consult rfc2459 for more information. - - @return the thisUpdate date - */ - public abstract Date getThisUpdate(); - - /* - Gets the nextUpdate field - - The ASN.1 DER encoding is: - - nextUpdate Time OPTIONAL, - - Time ::= CHOICE { - utcTime UTCTime, - generalTime GeneralizedTime } - - Consult rfc2459 for more information. - - @return the nextUpdate date - */ - public abstract Date getNextUpdate(); - - /** - Gets the requeste dX509Entry for the specified - certificate serial number. - - @return a X509CRLEntry representing the X.509 CRL entry - */ - public abstract X509CRLEntry getRevokedCertificate(BigInteger serialNumber); - - /** - Returns a Set of revoked certificates. - - @return a set of revoked certificates. - */ - public abstract Set getRevokedCertificates(); - - /** - Returns the DER ASN.1 encoded tbsCertList which is - the basic information of the list and associated certificates - in the encoded state. See top for more information. - - The ASN.1 DER encoding is: - - tbsCertList TBSCertList, - - Consult rfc2459 for more information. - - @return byte array representing tbsCertList - */ - public abstract byte[] getTBSCertList() throws CRLException; - - - /** - Returns the signature for the CRL. - - The ASN.1 DER encoding is: - - signatureValue BIT STRING - - Consult rfc2459 for more information. - */ - public abstract byte[] getSignature(); - - /** - Returns the signature algorithm used to sign the CRL. - An examples is "SHA-1/DSA". - - The ASN.1 DER encoding is: - - signatureAlgorithm AlgorithmIdentifier, - - AlgorithmIdentifier ::= SEQUENCE { - algorithm OBJECT IDENTIFIER, - parameters ANY DEFINED BY algorithm OPTIONAL } - - Consult rfc2459 for more information. - - The algorithm name is determined from the OID. - - @return a string with the signature algorithm name - */ - public abstract String getSigAlgName(); - - /** - Returns the OID for the signature algorithm used. - Example "1.2.840.10040.4.3" is return for SHA-1 with DSA.\ - - The ASN.1 DER encoding for the example is: - - id-dsa-with-sha1 ID ::= { - iso(1) member-body(2) us(840) x9-57 (10040) - x9cm(4) 3 } - - Consult rfc2459 for more information. - - @return a string containing the OID. - */ - public abstract String getSigAlgOID(); - - /** - Returns the AlgorithmParameters in the encoded form - for the signature algorithm used. - - If access to the parameters is need, create an - instance of AlgorithmParameters. - - @return byte array containing algorithm parameters, null - if no parameters are present in CRL - */ - public abstract byte[] getSigAlgParams(); - - // 1.4 instance methods. - // ------------------------------------------------------------------------ - - /** - * Returns the X.500 distinguished name of this CRL's issuer. - * - * @return The issuer's X.500 distinguished name. - * @since JDK 1.4 - */ - public X500Principal getIssuerX500Principal() - { - throw new UnsupportedOperationException(); - } -} diff --git a/libjava/java/security/cert/X509CRLEntry.java b/libjava/java/security/cert/X509CRLEntry.java deleted file mode 100644 index 4c9cada4747..00000000000 --- a/libjava/java/security/cert/X509CRLEntry.java +++ /dev/null @@ -1,169 +0,0 @@ -/* X509CRLEntry.java --- X.509 Certificate Revocation List Entry - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security.cert; - -import java.math.BigInteger; -import java.util.Date; - -/** - Abstract class for entries in the CRL (Certificate Revocation - List). The ASN.1 definition for <I>revokedCertificates</I> is - - revokedCertificates SEQUENCE OF SEQUENCE { - userCertificate CertificateSerialNumber, - revocationDate Time, - crlEntryExtensions Extensions OPTIONAL - -- if present, shall be v2 - } OPTIONAL, - - CertificateSerialNumber ::= INTEGER - - Time ::= CHOICE { - utcTime UTCTime, - generalTime GeneralizedTime } - - Extensions ::= SEQUENCE SIZE (1..MAX) OF Extension - - Extension ::= SEQUENCE { - extnID OBJECT IDENTIFIER, - critical BOOLEAN DEFAULT FALSE, - extnValue OCTET STRING } - - For more information consult rfc2459. - - @author Mark Benvenuto - - @since JDK 1.2 -*/ -public abstract class X509CRLEntry implements X509Extension -{ - - /** - Creates a new X509CRLEntry - */ - public X509CRLEntry() - {} - - /** - Compares this X509CRLEntry to other. It checks if the - object if instanceOf X509CRLEntry and then checks if - the encoded form( the inner SEQUENCE) matches. - - @param other An Object to test for equality - - @return true if equal, false otherwise - */ - public boolean equals(Object other) - { - if( other instanceof X509CRLEntry ) { - try { - X509CRLEntry xe = (X509CRLEntry) other; - if( getEncoded().length != xe.getEncoded().length ) - return false; - - byte[] b1 = getEncoded(); - byte[] b2 = xe.getEncoded(); - - for( int i = 0; i < b1.length; i++ ) - if( b1[i] != b2[i] ) - return false; - - } catch( CRLException crle ) { - return false; - } - return true; - } - return false; - } - - /** - Returns a hash code for this X509CRLEntry in its encoded - form. - - @return A hash code of this class - */ - public int hashCode() - { - return super.hashCode(); - } - - /** - Gets the DER ASN.1 encoded format for this CRL Entry, - the inner SEQUENCE. - - @return byte array containg encoded form - - @throws CRLException if an error occurs - */ - public abstract byte[] getEncoded() throws CRLException; - - /** - Gets the serial number for <I>userCertificate</I> in - this X509CRLEntry. - - @return the serial number for this X509CRLEntry. - */ - public abstract BigInteger getSerialNumber(); - - - /** - Gets the revocation date in <I>revocationDate</I> for - this X509CRLEntry. - - @return the revocation date for this X509CRLEntry. - */ - public abstract Date getRevocationDate(); - - - /** - Checks if this X509CRLEntry has extensions. - - @return true if it has extensions, false otherwise - */ - public abstract boolean hasExtensions(); - - - /** - Returns a string that represents this X509CRLEntry. - - @return a string representing this X509CRLEntry. - */ - public abstract String toString(); - -} diff --git a/libjava/java/security/cert/X509CRLSelector.java b/libjava/java/security/cert/X509CRLSelector.java deleted file mode 100644 index 3c79fba9cb8..00000000000 --- a/libjava/java/security/cert/X509CRLSelector.java +++ /dev/null @@ -1,440 +0,0 @@ -/* X509CRLSelector.java -- selects X.509 CRLs by criteria. - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security.cert; - -import gnu.classpath.SystemProperties; -import gnu.java.security.der.DERReader; -import gnu.java.security.der.DERValue; - -import java.io.IOException; -import java.io.InputStream; -import java.math.BigInteger; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Date; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; - -import javax.security.auth.x500.X500Principal; - -/** - * A class for matching X.509 certificate revocation lists by criteria. - * - * <p>Use of this class requires extensive knowledge of the Internet - * Engineering Task Force's Public Key Infrastructure (X.509). The primary - * document describing this standard is <a - * href="http://www.ietf.org/rfc/rfc3280.txt">RFC 3280: Internet X.509 - * Public Key Infrastructure Certificate and Certificate Revocation List - * (CRL) Profile</a>. - * - * <p>Note that this class is not thread-safe. If multiple threads will - * use or modify this class then they need to synchronize on the object. - * - * @author Casey Marshall (csm@gnu.org) - */ -public class X509CRLSelector implements CRLSelector, Cloneable -{ - - // Fields. - // ------------------------------------------------------------------------- - - private static final String CRL_NUMBER_ID = "2.5.29.20"; - - private List issuerNames; - private BigInteger maxCrlNumber; - private BigInteger minCrlNumber; - private Date date; - private X509Certificate cert; - - // Constructor. - // ------------------------------------------------------------------------- - - /** - * Creates a new CRL selector with no criteria enabled; i.e., every CRL - * will be matched. - */ - public X509CRLSelector() - { - } - - // Instance methods. - // ------------------------------------------------------------------------- - - /** - * Add an issuer name to the set of issuer names criteria, as the DER - * encoded form. - * - * @param name The name to add, as DER bytes. - * @throws IOException If the argument is not a valid DER-encoding. - */ - public void addIssuerName(byte[] name) throws IOException - { - X500Principal p = null; - try - { - p = new X500Principal(name); - } - catch (IllegalArgumentException iae) - { - IOException ioe = new IOException("malformed name"); - ioe.initCause(iae); - throw ioe; - } - if (issuerNames == null) - issuerNames = new LinkedList(); - issuerNames.add(p); - } - - /** - * Add an issuer name to the set of issuer names criteria, as a - * String representation. - * - * @param name The name to add. - * @throws IOException If the argument is not a valid name. - */ - public void addIssuerName(String name) throws IOException - { - X500Principal p = null; - try - { - p = new X500Principal(name); - } - catch (IllegalArgumentException iae) - { - IOException ioe = new IOException("malformed name: " + name); - ioe.initCause(iae); - throw ioe; - } - if (issuerNames == null) - issuerNames = new LinkedList(); - issuerNames.add(p); - } - - /** - * Sets the issuer names criterion. Pass <code>null</code> to clear this - * value. CRLs matched by this selector must have an issuer name in this - * set. - * - * @param names The issuer names. - * @throws IOException If any of the elements in the collection is not - * a valid name. - */ - public void setIssuerNames(Collection names) throws IOException - { - if (names == null) - { - issuerNames = null; - return; - } - List l = new ArrayList(names.size()); - for (Iterator it = names.iterator(); it.hasNext(); ) - { - Object o = it.next(); - if (o instanceof X500Principal) - l.add(o); - else if (o instanceof String) - { - try - { - l.add(new X500Principal((String) o)); - } - catch (IllegalArgumentException iae) - { - IOException ioe = new IOException("malformed name: " + o); - ioe.initCause(iae); - throw ioe; - } - } - else if (o instanceof byte[]) - { - try - { - l.add(new X500Principal((byte[]) o)); - } - catch (IllegalArgumentException iae) - { - IOException ioe = new IOException("malformed name"); - ioe.initCause(iae); - throw ioe; - } - } - else if (o instanceof InputStream) - { - try - { - l.add(new X500Principal((InputStream) o)); - } - catch (IllegalArgumentException iae) - { - IOException ioe = new IOException("malformed name"); - ioe.initCause(iae); - throw ioe; - } - } - else - throw new IOException("not a valid name: " + - (o != null ? o.getClass().getName() : "null")); - - } - issuerNames = l; - } - - /** - * Returns the set of issuer names that are matched by this selector, - * or <code>null</code> if this criteria is not set. The returned - * collection is not modifiable. - * - * @return The set of issuer names. - */ - public Collection getIssuerNames() - { - if (issuerNames != null) - return Collections.unmodifiableList(issuerNames); - else - return null; - } - - /** - * Returns the maximum value of the CRLNumber extension present in - * CRLs matched by this selector, or <code>null</code> if this - * criteria is not set. - * - * @return The maximum CRL number. - */ - public BigInteger getMaxCRL() - { - return maxCrlNumber; - } - - /** - * Returns the minimum value of the CRLNumber extension present in - * CRLs matched by this selector, or <code>null</code> if this - * criteria is not set. - * - * @return The minimum CRL number. - */ - public BigInteger getMinCRL() - { - return minCrlNumber; - } - - /** - * Sets the maximum value of the CRLNumber extension present in CRLs - * matched by this selector. Specify <code>null</code> to clear this - * criterion. - * - * @param maxCrlNumber The maximum CRL number. - */ - public void setMaxCRLNumber(BigInteger maxCrlNumber) - { - this.maxCrlNumber = maxCrlNumber; - } - - /** - * Sets the minimum value of the CRLNumber extension present in CRLs - * matched by this selector. Specify <code>null</code> to clear this - * criterion. - * - * @param minCrlNumber The minimum CRL number. - */ - public void setMinCRLNumber(BigInteger minCrlNumber) - { - this.minCrlNumber = minCrlNumber; - } - - /** - * Returns the date when this CRL must be valid; that is, the date - * must be after the thisUpdate date, but before the nextUpdate date. - * Returns <code>null</code> if this criterion is not set. - * - * @return The date. - */ - public Date getDateAndTime() - { - return date != null ? (Date) date.clone() : null; - } - - /** - * Sets the date at which this CRL must be valid. Specify - * <code>null</code> to clear this criterion. - * - * @param date The date. - */ - public void setDateAndTime(Date date) - { - this.date = date != null ? (Date) date.clone() : null; - } - - /** - * Returns the certificate being checked, or <code>null</code> if this - * value is not set. - * - * @return The certificate. - */ - public X509Certificate getCertificateChecking() - { - return cert; - } - - /** - * Sets the certificate being checked. This is not a criterion, but - * info used by certificate store implementations to aid in searching. - * - * @param cert The certificate. - */ - public void setCertificateChecking(X509Certificate cert) - { - this.cert = cert; - } - - /** - * Returns a string representation of this selector. The string will - * only describe the enabled criteria, so if none are enabled this will - * return a string that contains little else besides the class name. - * - * @return The string. - */ - public String toString() - { - StringBuffer str = new StringBuffer(X509CRLSelector.class.getName()); - String nl = SystemProperties.getProperty("line.separator"); - String eol = ";" + nl; - - str.append(" {").append(nl); - if (issuerNames != null) - str.append(" issuer names = ").append(issuerNames).append(eol); - if (maxCrlNumber != null) - str.append(" max CRL = ").append(maxCrlNumber).append(eol); - if (minCrlNumber != null) - str.append(" min CRL = ").append(minCrlNumber).append(eol); - if (date != null) - str.append(" date = ").append(date).append(eol); - if (cert != null) - str.append(" certificate = ").append(cert).append(eol); - str.append("}").append(nl); - return str.toString(); - } - - /** - * Checks a CRL against the criteria of this selector, returning - * <code>true</code> if the given CRL matches all the criteria. - * - * @param _crl The CRL being checked. - * @return True if the CRL matches, false otherwise. - */ - public boolean match(CRL _crl) - { - if (!(_crl instanceof X509CRL)) - return false; - X509CRL crl = (X509CRL) _crl; - if (issuerNames != null) - { - if (!issuerNames.contains(crl.getIssuerX500Principal())) - return false; - } - BigInteger crlNumber = null; - if (maxCrlNumber != null) - { - byte[] b = crl.getExtensionValue(CRL_NUMBER_ID); - if (b == null) - return false; - try - { - DERValue val = DERReader.read(b); - if (!(val.getValue() instanceof BigInteger)) - return false; - crlNumber = (BigInteger) val.getValue(); - } - catch (IOException ioe) - { - return false; - } - if (maxCrlNumber.compareTo(crlNumber) < 0) - return false; - } - if (minCrlNumber != null) - { - if (crlNumber == null) - { - byte[] b = crl.getExtensionValue(CRL_NUMBER_ID); - if (b == null) - return false; - try - { - DERValue val = DERReader.read(b); - if (!(val.getValue() instanceof BigInteger)) - return false; - crlNumber = (BigInteger) val.getValue(); - } - catch (IOException ioe) - { - return false; - } - } - if (minCrlNumber.compareTo(crlNumber) > 0) - return false; - } - if (date != null) - { - if (date.compareTo(crl.getThisUpdate()) < 0 || - date.compareTo(crl.getNextUpdate()) > 0) - return false; - } - return true; - } - - /** - * Returns a copy of this object. - * - * @return The copy. - */ - public Object clone() - { - try - { - return super.clone(); - } - catch (CloneNotSupportedException shouldNotHappen) - { - throw new Error(shouldNotHappen); - } - } -} diff --git a/libjava/java/security/cert/X509CertSelector.java b/libjava/java/security/cert/X509CertSelector.java deleted file mode 100644 index 4149a37643d..00000000000 --- a/libjava/java/security/cert/X509CertSelector.java +++ /dev/null @@ -1,1106 +0,0 @@ -/* X509CertSelector.java -- selects X.509 certificates by criteria. - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security.cert; - -import gnu.classpath.SystemProperties; -import gnu.java.security.OID; - -import java.io.IOException; -import java.math.BigInteger; -import java.security.KeyFactory; -import java.security.PublicKey; -import java.security.spec.X509EncodedKeySpec; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Date; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; - -import javax.security.auth.x500.X500Principal; - -/** - * A concrete implementation of {@link CertSelector} for X.509 certificates, - * which allows a number of criteria to be set when accepting certificates, - * from validity dates, to issuer and subject distinguished names, to some - * of the various X.509 extensions. - * - * <p>Use of this class requires extensive knowledge of the Internet - * Engineering Task Force's Public Key Infrastructure (X.509). The primary - * document describing this standard is <a - * href="http://www.ietf.org/rfc/rfc3280.txt">RFC 3280: Internet X.509 - * Public Key Infrastructure Certificate and Certificate Revocation List - * (CRL) Profile</a>. - * - * <p>Note that this class is not thread-safe. If multiple threads will - * use or modify this class then they need to synchronize on the object. - * - * @author Casey Marshall (csm@gnu.org) - */ -public class X509CertSelector implements CertSelector, Cloneable -{ - - // Constants and fields. - // ------------------------------------------------------------------------- - - private static final String AUTH_KEY_ID = "2.5.29.35"; - private static final String SUBJECT_KEY_ID = "2.5.29.14"; - private static final String NAME_CONSTRAINTS_ID = "2.5.29.30"; - - private int basicConstraints; - private X509Certificate cert; - private BigInteger serialNo; - private X500Principal issuer; - private X500Principal subject; - private byte[] subjectKeyId; - private byte[] authKeyId; - private boolean[] keyUsage; - private Date certValid; - private OID sigId; - private PublicKey subjectKey; - private X509EncodedKeySpec subjectKeySpec; - private Set keyPurposeSet; - private List altNames; - private boolean matchAllNames; - private byte[] nameConstraints; - private Set policy; - - // Constructors. - // ------------------------------------------------------------------------ - - /** - * Creates a new X.509 certificate selector. The new selector will be - * empty, and will accept any certificate (provided that it is an - * {@link X509Certificate}). - */ - public X509CertSelector() - { - basicConstraints = -1; - } - - // Instance methods. - // ------------------------------------------------------------------------ - - /** - * Returns the certificate criterion, or <code>null</code> if this value - * was not set. - * - * @return The certificate. - */ - public X509Certificate getCertificate() - { - return cert; - } - - /** - * Sets the certificate criterion. If set, only certificates that are - * equal to the certificate passed here will be accepted. - * - * @param cert The certificate. - */ - public void setCertificate(X509Certificate cert) - { - this.cert = cert; - } - - /** - * Returns the serial number criterion, or <code>null</code> if this - * value was not set. - * - * @return The serial number. - */ - public BigInteger getSerialNumber() - { - return serialNo; - } - - /** - * Sets the serial number of the desired certificate. Only certificates that - * contain this serial number are accepted. - * - * @param serialNo The serial number. - */ - public void setSerialNumber(BigInteger serialNo) - { - this.serialNo = serialNo; - } - - /** - * Returns the issuer criterion as a string, or <code>null</code> if this - * value was not set. - * - * @return The issuer. - */ - public String getIssuerAsString() - { - if (issuer != null) - return issuer.getName(); - else - return null; - } - - /** - * Returns the issuer criterion as a sequence of DER bytes, or - * <code>null</code> if this value was not set. - * - * @return The issuer. - */ - public byte[] getIssuerAsBytes() throws IOException - { - if (issuer != null) - return issuer.getEncoded(); - else - return null; - } - - /** - * Sets the issuer, specified as a string representation of the issuer's - * distinguished name. Only certificates issued by this issuer will - * be accepted. - * - * @param name The string representation of the issuer's distinguished name. - * @throws IOException If the given name is incorrectly formatted. - */ - public void setIssuer(String name) throws IOException - { - if (name != null) - { - try - { - issuer = new X500Principal(name); - } - catch (IllegalArgumentException iae) - { - throw new IOException(iae.getMessage()); - } - } - else - issuer = null; - } - - /** - * Sets the issuer, specified as the DER encoding of the issuer's - * distinguished name. Only certificates issued by this issuer will - * be accepted. - * - * @param name The DER encoding of the issuer's distinguished name. - * @throws IOException If the given name is incorrectly formatted. - */ - public void setIssuer(byte[] name) throws IOException - { - if (name != null) - { - try - { - issuer = new X500Principal(name); - } - catch (IllegalArgumentException iae) - { - throw new IOException(iae.getMessage()); - } - } - else - issuer = null; - } - - /** - * Returns the subject criterion as a string, of <code>null</code> if - * this value was not set. - * - * @return The subject. - */ - public String getSubjectAsString() - { - if (subject != null) - return subject.getName(); - else - return null; - } - - /** - * Returns the subject criterion as a sequence of DER bytes, or - * <code>null</code> if this value is not set. - * - * @return The subject. - */ - public byte[] getSubjectAsBytes() throws IOException - { - if (subject != null) - return subject.getEncoded(); - else - return null; - } - - /** - * Sets the subject, specified as a string representation of the - * subject's distinguished name. Only certificates with the given - * subject will be accepted. - * - * @param name The string representation of the subject's distinguished name. - * @throws IOException If the given name is incorrectly formatted. - */ - public void setSubject(String name) throws IOException - { - if (name != null) - { - try - { - subject = new X500Principal(name); - } - catch (IllegalArgumentException iae) - { - throw new IOException(iae.getMessage()); - } - } - else - subject = null; - } - - /** - * Sets the subject, specified as the DER encoding of the subject's - * distinguished name. Only certificates with the given subject will - * be accepted. - * - * @param name The DER encoding of the subject's distinguished name. - * @throws IOException If the given name is incorrectly formatted. - */ - public void setSubject(byte[] name) throws IOException - { - if (name != null) - { - try - { - subject = new X500Principal(name); - } - catch (IllegalArgumentException iae) - { - throw new IOException(iae.getMessage()); - } - } - else - subject = null; - } - - /** - * Returns the subject key identifier criterion, or <code>null</code> if - * this value was not set. Note that the byte array is cloned to prevent - * modification. - * - * @return The subject key identifier. - */ - public byte[] getSubjectKeyIdentifier() - { - if (subjectKeyId != null) - return (byte[]) subjectKeyId.clone(); - else - return null; - } - - /** - * Sets the subject key identifier criterion, or <code>null</code> to clear - * this criterion. Note that the byte array is cloned to prevent modification. - * - * @param subjectKeyId The subject key identifier. - */ - public void setSubjectKeyIdentifier(byte[] subjectKeyId) - { - this.subjectKeyId = subjectKeyId != null ? (byte[]) subjectKeyId.clone() : - null; - } - - /** - * Returns the authority key identifier criterion, or <code>null</code> if - * this value was not set. Note that the byte array is cloned to prevent - * modification. - * - * @return The authority key identifier. - */ - public byte[] getAuthorityKeyIdentifier() - { - if (authKeyId != null) - return (byte[]) authKeyId.clone(); - else - return null; - } - - /** - * Sets the authority key identifier criterion, or <code>null</code> to clear - * this criterion. Note that the byte array is cloned to prevent modification. - * - * @param subjectKeyId The subject key identifier. - */ - public void setAuthorityKeyIdentifier(byte[] authKeyId) - { - this.authKeyId = authKeyId != null ? (byte[]) authKeyId.clone() : null; - } - - /** - * Returns the date at which certificates must be valid, or <code>null</code> - * if this criterion was not set. - * - * @return The target certificate valitity date. - */ - public Date getCertificateValid() - { - if (certValid != null) - return (Date) certValid.clone(); - else - return null; - } - - /** - * Sets the date at which certificates must be valid. Specify - * <code>null</code> to clear this criterion. - * - * @param certValid The certificate validity date. - */ - public void setCertificateValid(Date certValid) - { - this.certValid = certValid != null ? (Date) certValid.clone() : null; - } - - /** - * This method, and its related X.509 certificate extension — the - * private key usage period — is not supported under the Internet - * PKI for X.509 certificates (PKIX), described in RFC 3280. As such, this - * method is not supported either. - * - * <p>Do not use this method. It is not deprecated, as it is not deprecated - * in the Java standard, but it is basically a no-operation and simply - * returns <code>null</code>. - * - * @return Null. - */ - public Date getPrivateKeyValid() - { - return null; - } - - /** - * This method, and its related X.509 certificate extension — the - * private key usage period — is not supported under the Internet - * PKI for X.509 certificates (PKIX), described in RFC 3280. As such, this - * method is not supported either. - * - * <p>Do not use this method. It is not deprecated, as it is not deprecated - * in the Java standard, but it is basically a no-operation. - * - * @param UNUSED Is silently ignored. - */ - public void setPrivateKeyValid(Date UNUSED) - { - } - - /** - * Returns the public key algorithm ID that matching certificates must have, - * or <code>null</code> if this criterion was not set. - * - * @return The public key algorithm ID. - */ - public String getSubjectPublicKeyAlgID() - { - return String.valueOf(sigId); - } - - /** - * Sets the public key algorithm ID that matching certificates must have. - * Specify <code>null</code> to clear this criterion. - * - * @param sigId The public key ID. - * @throws IOException If the specified ID is not a valid object identifier. - */ - public void setSubjectPublicKeyAlgID(String sigId) throws IOException - { - if (sigId != null) - { - try - { - OID oid = new OID(sigId); - int[] comp = oid.getIDs(); - if (!checkOid(comp)) - throw new IOException("malformed OID: " + sigId); - this.sigId = oid; - } - catch (IllegalArgumentException iae) - { - IOException ioe = new IOException("malformed OID: " + sigId); - ioe.initCause(iae); - throw ioe; - } - } - else - this.sigId = null; - } - - /** - * Returns the subject public key criterion, or <code>null</code> if this - * value is not set. - * - * @return The subject public key. - */ - public PublicKey getSubjectPublicKey() - { - return subjectKey; - } - - /** - * Sets the subject public key criterion as an opaque representation. - * Specify <code>null</code> to clear this criterion. - * - * @param key The public key. - */ - public void setSubjectPublicKey(PublicKey key) - { - this.subjectKey = key; - if (key == null) - { - subjectKeySpec = null; - return; - } - try - { - KeyFactory enc = KeyFactory.getInstance("X.509"); - subjectKeySpec = (X509EncodedKeySpec) - enc.getKeySpec(key, X509EncodedKeySpec.class); - } - catch (Exception x) - { - subjectKey = null; - subjectKeySpec = null; - } - } - - /** - * Sets the subject public key criterion as a DER-encoded key. Specify - * <code>null</code> to clear this value. - * - * @param key The DER-encoded key bytes. - * @throws IOException If the argument is not a valid DER-encoded key. - */ - public void setSubjectPublicKey(byte[] key) throws IOException - { - if (key == null) - { - subjectKey = null; - subjectKeySpec = null; - return; - } - try - { - subjectKeySpec = new X509EncodedKeySpec(key); - KeyFactory enc = KeyFactory.getInstance("X.509"); - subjectKey = enc.generatePublic(subjectKeySpec); - } - catch (Exception x) - { - subjectKey = null; - subjectKeySpec = null; - IOException ioe = new IOException(x.getMessage()); - ioe.initCause(x); - throw ioe; - } - } - - /** - * Returns the public key usage criterion, or <code>null</code> if this - * value is not set. Note that the array is cloned to prevent modification. - * - * @return The public key usage. - */ - public boolean[] getKeyUsage() - { - if (keyUsage != null) - return (boolean[]) keyUsage.clone(); - else - return null; - } - - /** - * Sets the public key usage criterion. Specify <code>null</code> to clear - * this value. - * - * @param keyUsage The public key usage. - */ - public void setKeyUsage(boolean[] keyUsage) - { - this.keyUsage = keyUsage != null ? (boolean[]) keyUsage.clone() : null; - } - - /** - * Returns the set of extended key purpose IDs, as an unmodifiable set - * of OID strings. Returns <code>null</code> if this criterion is not - * set. - * - * @return The set of key purpose OIDs (strings). - */ - public Set getExtendedKeyUsage() - { - if (keyPurposeSet != null) - return Collections.unmodifiableSet(keyPurposeSet); - else - return null; - } - - /** - * Sets the extended key usage criterion, as a set of OID strings. Specify - * <code>null</code> to clear this value. - * - * @param keyPurposeSet The set of key purpose OIDs. - * @throws IOException If any element of the set is not a valid OID string. - */ - public void setExtendedKeyUsage(Set keyPurposeSet) throws IOException - { - if (keyPurposeSet == null) - { - this.keyPurposeSet = null; - return; - } - Set s = new HashSet(); - for (Iterator it = keyPurposeSet.iterator(); it.hasNext(); ) - { - Object o = it.next(); - if (!(o instanceof String)) - throw new IOException("not a string: " + o); - try - { - OID oid = new OID((String) o); - int[] comp = oid.getIDs(); - if (!checkOid(comp)) - throw new IOException("malformed OID: " + o); - } - catch (IllegalArgumentException iae) - { - IOException ioe = new IOException("malformed OID: " + o); - ioe.initCause(iae); - throw ioe; - } - } - this.keyPurposeSet = s; - } - - /** - * Returns whether or not all specified alternative names must match. - * If false, a certificate is considered a match if <em>one</em> of the - * specified alternative names matches. - * - * @return true if all names must match. - */ - public boolean getMatchAllSubjectAltNames() - { - return matchAllNames; - } - - /** - * Sets whether or not all subject alternative names must be matched. - * If false, then a certificate will be considered a match if one - * alternative name matches. - * - * @param matchAllNames Whether or not all alternative names must be - * matched. - */ - public void setMatchAllSubjectAltNames(boolean matchAllNames) - { - this.matchAllNames = matchAllNames; - } - - /** - * Sets the subject alternative names critertion. Each element of the - * argument must be a {@link java.util.List} that contains exactly two - * elements: the first an {@link Integer}, representing the type of - * name, and the second either a {@link String} or a byte array, - * representing the name itself. - * - * @param altNames The alternative names. - * @throws IOException If any element of the argument is invalid. - */ - public void setSubjectAlternativeNames(Collection altNames) - throws IOException - { - if (altNames == null) - { - this.altNames = null; - return; - } - List l = new ArrayList(altNames.size()); - for (Iterator it = altNames.iterator(); it.hasNext(); ) - { - Object o = it.next(); - if (!(o instanceof List) || ((List) o).size() != 2 || - !(((List) o).get(0) instanceof Integer) || - !(((List) o).get(1) instanceof String) || - !(((List) o).get(1) instanceof byte[])) - throw new IOException("illegal alternative name: " + o); - Integer i = (Integer) ((List) o).get(0); - if (i.intValue() < 0 || i.intValue() > 8) - throw new IOException("illegal alternative name: " + o + - ", bad id: " + i); - l.add(new ArrayList((List) o)); - } - this.altNames = l; - } - - /** - * Add a name to the subject alternative names criterion. - * - * @param id The type of name this is. Must be in the range [0,8]. - * @param name The name. - * @throws IOException If the id is out of range, or if the name - * is null. - */ - public void addSubjectAlternativeName(int id, String name) - throws IOException - { - if (id < 0 || id > 8 || name == null) - throw new IOException("illegal alternative name"); - if (altNames == null) - altNames = new LinkedList(); - ArrayList l = new ArrayList(2); - l.add(new Integer(id)); - l.add(name); - altNames.add(l); - } - - /** - * Add a name, as DER-encoded bytes, to the subject alternative names - * criterion. - * - * @param id The type of name this is. - */ - public void addSubjectAlternativeName(int id, byte[] name) - throws IOException - { - if (id < 0 || id > 8 || name == null) - throw new IOException("illegal alternative name"); - if (altNames == null) - altNames = new LinkedList(); - ArrayList l = new ArrayList(2); - l.add(new Integer(id)); - l.add(name); - altNames.add(l); - } - - /** - * Returns the name constraints criterion, or <code>null</code> if this - * value is not set. Note that the byte array is cloned to prevent - * modification. - * - * @return The name constraints. - */ - public byte[] getNameConstraints() - { - if (nameConstraints != null) - return (byte[]) nameConstraints.clone(); - else - return null; - } - - /** - * Sets the name constraints criterion; specify <code>null</code> to - * clear this criterion. Note that if non-null, the argument will be - * cloned to prevent modification. - * - * @param nameConstraints The new name constraints. - * @throws IOException If the argument is not a valid DER-encoded - * name constraints. - */ - public void setNameConstraints(byte[] nameConstraints) - throws IOException - { - // FIXME check if the argument is valid. - this.nameConstraints = nameConstraints != null - ? (byte[]) nameConstraints.clone() : null; - } - - /** - * Returns the basic constraints criterion, or -1 if this value is not set. - * - * @return The basic constraints. - */ - public int getBasicConstraints() - { - return basicConstraints; - } - - /** - * Sets the basic constraints criterion. Specify -1 to clear this parameter. - * - * @param basicConstraints The new basic constraints value. - */ - public void setBasicConstraints(int basicConstraints) - { - if (basicConstraints < -1) - basicConstraints = -1; - this.basicConstraints = basicConstraints; - } - - // The last two criteria not yet implemented are certificate policies - // and path-to-names. Both of these are somewhat advanced extensions - // (you could probably count the applications that actually use them - // on one hand), and they both have no support in the X509Certificate - // class. - // - // Not having support in X509Certificate is not always a problem; for - // example, we can compare DER-encoded values as byte arrays for some - // extensions. We can't, however, compare them if they are specified - // in a set (as policies are). We need to parse the actual value in the - // certificate, and check it against the specified set. - - // FIXME -// public void setPolicy(Set policy) throws IOException -// { -// if (policy != null) -// { -// for (Iterator it = policy.iterator(); it.hasNext(); ) -// try -// { -// OID oid = new OID((String) it.next()); -// int[] i = oid.getIDs(); -// if (!checkOid(i)) -// throw new IOException("invalid OID"); -// } -// catch (Exception x) -// { -// throw new IOException("invalid OID"); -// } -// } -// this.policy = policy != null ? new HashSet(policy) : null; -// } - - // FIXME -// public void setPathToNames(Collection names) throws IOException -// { -// if (names == null) -// { -// this.names = null; -// return; -// } -// for (Iterator it = names.iterator(); it.hasNext(); ) -// { -// try -// { -// List l = (List) it.next(); -// if (l.get(1) instanceof String) -// addPathToName(((Integer)l.get(0)).intValue(), (String)l.get(1)); -// else -// addPathToName(((Integer)l.get(0)).intValue(), (byte[])l.get(1)); -// } -// catch (Exception x) -// { -// this.names = null; -// throw new IOException("invalid names"); -// } -// } -// } - - // FIXME -// public void addPathToName(int id, String name) throws IOException -// { -// } - - // FIXME -// public void addPathToName(int id, byte[] name) throws IOException -// { -// } - - // FIXME -// public Collection getSubjectAlternativeNames() -// { -// return null; -// } - - // FIXME -// public Set getPolicy() -// { -// return null; -// } - - // FIXME -// public Collection getPathToNames() -// { -// return null; -// } - - /** - * Match a certificate. This method will check the given certificate - * against all the enabled criteria of this selector, and will return - * <code>true</code> if the given certificate matches. - * - * @param certificate The certificate to check. - * @return true if the certificate matches all criteria. - */ - public boolean match(Certificate certificate) - { - if (!(certificate instanceof X509Certificate)) - return false; - X509Certificate cert = (X509Certificate) certificate; - if (this.cert != null) - { - try - { - byte[] e1 = this.cert.getEncoded(); - byte[] e2 = cert.getEncoded(); - if (!Arrays.equals(e1, e2)) - return false; - } - catch (CertificateEncodingException cee) - { - return false; - } - } - if (serialNo != null) - { - if (!serialNo.equals(cert.getSerialNumber())) - return false; - } - if (certValid != null) - { - try - { - cert.checkValidity(certValid); - } - catch (CertificateException ce) - { - return false; - } - } - if (issuer != null) - { - if (!issuer.equals(cert.getIssuerX500Principal())) - return false; - } - if (subject != null) - { - if (!subject.equals(cert.getSubjectX500Principal())) - return false; - } - if (sigId != null) - { - if (!sigId.equals(cert.getSigAlgOID())) - return false; - } - if (subjectKeyId != null) - { - byte[] b = cert.getExtensionValue(SUBJECT_KEY_ID); - if (!Arrays.equals(b, subjectKeyId)) - return false; - } - if (authKeyId != null) - { - byte[] b = cert.getExtensionValue(AUTH_KEY_ID); - if (!Arrays.equals(b, authKeyId)) - return false; - } - if (keyUsage != null) - { - boolean[] b = cert.getKeyUsage(); - if (!Arrays.equals(b, keyUsage)) - return false; - } - if (basicConstraints >= 0) - { - if (cert.getBasicConstraints() != basicConstraints) - return false; - } - if (keyPurposeSet != null) - { - List kp = null; - try - { - kp = cert.getExtendedKeyUsage(); - } - catch (CertificateParsingException cpe) - { - return false; - } - if (kp == null) - return false; - for (Iterator it = keyPurposeSet.iterator(); it.hasNext(); ) - { - if (!kp.contains(it.next())) - return false; - } - } - if (altNames != null) - { - Collection an = null; - try - { - an = cert.getSubjectAlternativeNames(); - } - catch (CertificateParsingException cpe) - { - return false; - } - if (an == null) - return false; - int match = 0; - for (Iterator it = altNames.iterator(); it.hasNext(); ) - { - List l = (List) it.next(); - Integer id = (Integer) l.get(0); - String s = null; - byte[] b = null; - if (l.get(1) instanceof String) - s = (String) l.get(1); - else if (l.get(1) instanceof byte[]) - b = (byte[]) l.get(1); - else - return false; - for (Iterator it2 = an.iterator(); it2.hasNext(); ) - { - Object o = it2.next(); - if (!(o instanceof List)) - continue; - List l2 = (List) o; - if (l2.size() != 2) - continue; - if (!id.equals(l2.get(0))) - continue; - if (s != null && (l2.get(1) instanceof String) && - s.equals(l2.get(1))) - match++; - else if (b != null && (l2.get(1) instanceof byte[]) && - Arrays.equals(b, (byte[]) l2.get(1))) - match++; - } - if (match == 0 || (matchAllNames && match != altNames.size())) - return false; - } - } - if (nameConstraints != null) - { - byte[] nc = cert.getExtensionValue(NAME_CONSTRAINTS_ID); - if (!Arrays.equals(nameConstraints, nc)) - return false; - } - - // FIXME check policies. - // FIXME check path-to-names. - - return true; - } - - public String toString() - { - StringBuffer str = new StringBuffer(X509CertSelector.class.getName()); - String nl = SystemProperties.getProperty("line.separator"); - String eol = ";" + nl; - str.append(" {").append(nl); - if (cert != null) - str.append(" certificate = ").append(cert).append(eol); - if (basicConstraints >= 0) - str.append(" basic constraints = ").append(basicConstraints).append(eol); - if (serialNo != null) - str.append(" serial number = ").append(serialNo).append(eol); - if (certValid != null) - str.append(" valid date = ").append(certValid).append(eol); - if (issuer != null) - str.append(" issuer = ").append(issuer).append(eol); - if (subject != null) - str.append(" subject = ").append(subject).append(eol); - if (sigId != null) - str.append(" signature OID = ").append(sigId).append(eol); - if (subjectKey != null) - str.append(" subject public key = ").append(subjectKey).append(eol); - if (subjectKeyId != null) - { - str.append(" subject key ID = "); - for (int i = 0; i < subjectKeyId.length; i++) - { - str.append(Character.forDigit((subjectKeyId[i] & 0xF0) >>> 8, 16)); - str.append(Character.forDigit((subjectKeyId[i] & 0x0F), 16)); - if (i < subjectKeyId.length - 1) - str.append(':'); - } - str.append(eol); - } - if (authKeyId != null) - { - str.append(" authority key ID = "); - for (int i = 0; i < authKeyId.length; i++) - { - str.append(Character.forDigit((authKeyId[i] & 0xF0) >>> 8, 16)); - str.append(Character.forDigit((authKeyId[i] & 0x0F), 16)); - if (i < authKeyId.length - 1) - str.append(':'); - } - str.append(eol); - } - if (keyUsage != null) - { - str.append(" key usage = "); - for (int i = 0; i < keyUsage.length; i++) - str.append(keyUsage[i] ? '1' : '0'); - str.append(eol); - } - if (keyPurposeSet != null) - str.append(" key purpose = ").append(keyPurposeSet).append(eol); - if (altNames != null) - str.append(" alternative names = ").append(altNames).append(eol); - if (nameConstraints != null) - str.append(" name constraints = <blob of data>").append(eol); - str.append("}").append(nl); - return str.toString(); - } - - public Object clone() - { - try - { - return super.clone(); - } - catch (CloneNotSupportedException shouldNotHappen) - { - throw new Error(shouldNotHappen); - } - } - - // Own methods. - // ------------------------------------------------------------------------- - - private static boolean checkOid(int[] oid) - { - return (oid != null && oid.length > 2 && - (oid[0] >= 0 && oid[0] <= 2) && (oid[1] >= 0 && oid[1] <= 39)); - } -} diff --git a/libjava/java/security/cert/X509Certificate.java b/libjava/java/security/cert/X509Certificate.java deleted file mode 100644 index 0f13357fd1d..00000000000 --- a/libjava/java/security/cert/X509Certificate.java +++ /dev/null @@ -1,586 +0,0 @@ -/* X509Certificate.java --- X.509 Certificate class - Copyright (C) 1999,2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security.cert; - -import java.math.BigInteger; -import java.security.Principal; -import java.util.Date; - -/** - * X509Certificate is the abstract class for X.509 certificates. - * This provides a stanard class interface for accessing all - * the attributes of X.509 certificates. - * - * <p>In June 1996, the basic X.509 v3 format was finished by - * ISO/IEC and ANSI X.9. The ASN.1 DER format is below: - * - * <blockquote><pre> - * Certificate ::= SEQUENCE { - * tbsCertificate TBSCertificate, - * signatureAlgorithm AlgorithmIdentifier, - * signatureValue BIT STRING } - * </pre></blockquote> - * - * <p>These certificates are widely used in various Internet - * protocols to support authentication. It is used in - * Privacy Enhanced Mail (PEM), Transport Layer Security (TLS), - * Secure Sockets Layer (SSL), code signing for trusted software - * distribution, and Secure Electronic Transactions (SET). - * - * <p>The certificates are managed and vouched for by - * <I>Certificate Authorities</I> (CAs). CAs are companies or - * groups that create certificates by placing the data in the - * X.509 certificate format and signing it with their private - * key. CAs serve as trusted third parties by certifying that - * the person or group specified in the certificate is who - * they say they are. - * - * <p>The ASN.1 defintion for <I>tbsCertificate</I> is - * - * <blockquote><pre> - * TBSCertificate ::= SEQUENCE { - * version [0] EXPLICIT Version DEFAULT v1, - * serialNumber CertificateSerialNumber, - * signature AlgorithmIdentifier, - * issuer Name, - * validity Validity, - * subject Name, - * subjectPublicKeyInfo SubjectPublicKeyInfo, - * issuerUniqueID [1] IMPLICIT UniqueIdentifier OPTIONAL, - * -- If present, version shall be v2 or v3 - * subjectUniqueID [2] IMPLICIT UniqueIdentifier OPTIONAL, - * -- If present, version shall be v2 or v3 - * extensions [3] EXPLICIT Extensions OPTIONAL - * -- If present, version shall be v3 - * } - * - * Version ::= INTEGER { v1(0), v2(1), v3(2) } - * - * CertificateSerialNumber ::= INTEGER - * - * Validity ::= SEQUENCE { - * notBefore Time, - * notAfter Time } - * - * Time ::= CHOICE { - * utcTime UTCTime, - * generalTime GeneralizedTime } - * - * UniqueIdentifier ::= BIT STRING - * - * SubjectPublicKeyInfo ::= SEQUENCE { - * algorithm AlgorithmIdentifier, - * subjectPublicKey BIT STRING } - * - * Extensions ::= SEQUENCE SIZE (1..MAX) OF Extension - * - * Extension ::= SEQUENCE { - * extnID OBJECT IDENTIFIER, - * critical BOOLEAN DEFAULT FALSE, - * extnValue OCTET STRING } - * </pre></blockquote> - * - * Certificates are created with the CertificateFactory. - * - * <p>References: - * - * <ol> - * <li>Olivier Dubuisson, Philippe Fouquart (Translator) <i>ASN.1 - - * Communication between heterogeneous systems</i>, (C) September 2000, - * Morgan Kaufmann Publishers, ISBN 0-12-6333361-0. Available on-line at - * <a - * href="http://www.oss.com/asn1/dubuisson.html">http://www.oss.com/asn1/dubuisson.html</a></li> - * <li>R. Housley et al, <i><a href="http://www.ietf.org/rfc/rfc3280.txt">RFC - * 3280: Internet X.509 Public Key Infrastructure Certificate and CRL - * Profile</a></i>.</li> - * </ol> - * - * @since JDK 1.2 - * @author Mark Benvenuto - * @author Casey Marshall (rsdio@metastatic.org) - */ -public abstract class X509Certificate extends Certificate implements X509Extension -{ - private static final long serialVersionUID = -2491127588187038216L; - - /** - * Constructs a new certificate of the specified type. - */ - protected X509Certificate() - { - super( "X.509" ); - } - - /** - Checks the validity of the X.509 certificate. It is valid - if the current date and time are within the period specified - by the certificate. - - The ASN.1 DER encoding is: - - validity Validity, - - Validity ::= SEQUENCE { - notBefore Time, - notAfter Time } - - Time ::= CHOICE { - utcTime UTCTime, - generalTime GeneralizedTime } - - Consult rfc2459 for more information. - - @throws CertificateExpiredException if the certificate expired - @throws CertificateNotYetValidException if the certificate is - not yet valid - */ - public abstract void checkValidity() - throws CertificateExpiredException, - CertificateNotYetValidException; - - /** - Checks the validity of the X.509 certificate for the - specified time and date. It is valid if the specified - date and time are within the period specified by - the certificate. - - @throws CertificateExpiredException if the certificate expired - based on the date - @throws CertificateNotYetValidException if the certificate is - not yet valid based on the date - */ - public abstract void checkValidity(Date date) - throws CertificateExpiredException, - CertificateNotYetValidException; - - /** - Returns the version of this certificate. - - The ASN.1 DER encoding is: - - version [0] EXPLICIT Version DEFAULT v1, - - Version ::= INTEGER { v1(0), v2(1), v3(2) } - - Consult rfc2459 for more information. - - @return version number of certificate - */ - public abstract int getVersion(); - - /** - Gets the serial number for serial Number in - this Certifcate. It must be a unique number - unique other serial numbers from the granting CA. - - The ASN.1 DER encoding is: - - serialNumber CertificateSerialNumber, - - CertificateSerialNumber ::= INTEGER - - Consult rfc2459 for more information. - - @return the serial number for this X509CRLEntry. - */ - public abstract BigInteger getSerialNumber(); - - /** - Returns the issuer (issuer distinguished name) of the - Certificate. The issuer is the entity who signed - and issued the Certificate. - - The ASN.1 DER encoding is: - - issuer Name, - - Name ::= CHOICE { - RDNSequence } - - RDNSequence ::= SEQUENCE OF RelativeDistinguishedName - - RelativeDistinguishedName ::= - SET OF AttributeTypeAndValue - - AttributeTypeAndValue ::= SEQUENCE { - type AttributeType, - value AttributeValue } - - AttributeType ::= OBJECT IDENTIFIER - - AttributeValue ::= ANY DEFINED BY AttributeType - - DirectoryString ::= CHOICE { - teletexString TeletexString (SIZE (1..MAX)), - printableString PrintableString (SIZE (1..MAX)), - universalString UniversalString (SIZE (1..MAX)), - utf8String UTF8String (SIZE (1.. MAX)), - bmpString BMPString (SIZE (1..MAX)) } - - Consult rfc2459 for more information. - - @return the issuer in the Principal class - */ - public abstract Principal getIssuerDN(); - - /** - Returns the subject (subject distinguished name) of the - Certificate. The subject is the entity who the Certificate - identifies. - - The ASN.1 DER encoding is: - - subject Name, - - Consult rfc2459 for more information. - - @return the issuer in the Principal class - */ - public abstract Principal getSubjectDN(); - - /** - Returns the date that this certificate is not to be used - before, <I>notBefore</I>. - - The ASN.1 DER encoding is: - - validity Validity, - - Validity ::= SEQUENCE { - notBefore Time, - notAfter Time } - - Time ::= CHOICE { - utcTime UTCTime, - generalTime GeneralizedTime } - - Consult rfc2459 for more information. - - @return the date <I>notBefore</I> - */ - public abstract Date getNotBefore(); - - /** - Returns the date that this certificate is not to be used - after, <I>notAfter</I>. - - @return the date <I>notAfter</I> - */ - public abstract Date getNotAfter(); - - - /** - Returns the <I>tbsCertificate</I> from the certificate. - - @return the DER encoded tbsCertificate - - @throws CertificateEncodingException if encoding error occurred - */ - public abstract byte[] getTBSCertificate() throws CertificateEncodingException; - - /** - Returns the signature in its raw DER encoded format. - - The ASN.1 DER encoding is: - - signatureValue BIT STRING - - Consult rfc2459 for more information. - - @return byte array representing signature - */ - public abstract byte[] getSignature(); - - /** - Returns the signature algorithm used to sign the CRL. - An examples is "SHA-1/DSA". - - The ASN.1 DER encoding is: - - signatureAlgorithm AlgorithmIdentifier, - - AlgorithmIdentifier ::= SEQUENCE { - algorithm OBJECT IDENTIFIER, - parameters ANY DEFINED BY algorithm OPTIONAL } - - Consult rfc2459 for more information. - - The algorithm name is determined from the OID. - - @return a string with the signature algorithm name - */ - public abstract String getSigAlgName(); - - - /** - Returns the OID for the signature algorithm used. - Example "1.2.840.10040.4.3" is return for SHA-1 with DSA.\ - - The ASN.1 DER encoding for the example is: - - id-dsa-with-sha1 ID ::= { - iso(1) member-body(2) us(840) x9-57 (10040) - x9cm(4) 3 } - - Consult rfc2459 for more information. - - @return a string containing the OID. - */ - public abstract String getSigAlgOID(); - - - /** - Returns the AlgorithmParameters in the encoded form - for the signature algorithm used. - - If access to the parameters is need, create an - instance of AlgorithmParameters. - - @return byte array containing algorithm parameters, null - if no parameters are present in certificate - */ - public abstract byte[] getSigAlgParams(); - - - /** - Returns the issuer unique ID for this certificate. - - The ASN.1 DER encoding is: - - issuerUniqueID [1] IMPLICIT UniqueIdentifier OPTIONAL, - -- If present, version shall be v2 or v3 - - UniqueIdentifier ::= BIT STRING - - Consult rfc2459 for more information. - - @return bit representation of <I>issuerUniqueID</I> - */ - public abstract boolean[] getIssuerUniqueID(); - - /** - Returns the subject unique ID for this certificate. - - The ASN.1 DER encoding is: - - subjectUniqueID [2] IMPLICIT UniqueIdentifier OPTIONAL, - -- If present, version shall be v2 or v3 - - UniqueIdentifier ::= BIT STRING - - Consult rfc2459 for more information. - - @return bit representation of <I>subjectUniqueID</I> - */ - public abstract boolean[] getSubjectUniqueID(); - - /** - Returns a boolean array representing the <I>KeyUsage</I> - extension for the certificate. The KeyUsage (OID = 2.5.29.15) - defines the purpose of the key in the certificate. - - The ASN.1 DER encoding is: - - id-ce-keyUsage OBJECT IDENTIFIER ::= { id-ce 15 } - - KeyUsage ::= BIT STRING { - digitalSignature (0), - nonRepudiation (1), - keyEncipherment (2), - dataEncipherment (3), - keyAgreement (4), - keyCertSign (5), - cRLSign (6), - encipherOnly (7), - decipherOnly (8) } - - Consult rfc2459 for more information. - - @return bit representation of <I>KeyUsage</I> - */ - public abstract boolean[] getKeyUsage(); - - /** - Returns the certificate constraints path length from the - critical BasicConstraints extension, (OID = 2.5.29.19). - - The basic constraints extensions is used to determine if - the subject of the certificate is a Certificate Authority (CA) - and how deep the certification path may exist. The - <I>pathLenConstraint</I> only takes affect if <I>cA</I> - is set to true. "A value of zero indicates that only an - end-entity certificate may follow in the path." (rfc2459) - - The ASN.1 DER encoding is: - - id-ce-basicConstraints OBJECT IDENTIFIER ::= { id-ce 19 } - - BasicConstraints ::= SEQUENCE { - cA BOOLEAN DEFAULT FALSE, - pathLenConstraint INTEGER (0..MAX) OPTIONAL } - - Consult rfc2459 for more information. - - @return the length of the path constraint if BasicConstraints - is present and cA is TRUE. Otherwise returns -1. - */ - public abstract int getBasicConstraints(); - - // 1.4 instance methods. - // ------------------------------------------------------------------------ - - /** - * Returns the <code>ExtendedKeyUsage</code> extension of this - * certificate, or null if there is no extension present. The returned - * value is a {@link java.util.List} strings representing the object - * identifiers of the extended key usages. This extension has the OID - * 2.5.29.37. - * - * <p>The ASN.1 definition for this extension is: - * - * <blockquote><pre> - * ExtendedKeyUsage ::= SEQUENCE SIZE (1..MAX) OF KeyPurposeId - * - * KeyPurposeId ::= OBJECT IDENTIFIER - * </pre></blockquote> - * - * @return The list of extension OIDs, or null if there are none - * present in this certificate. - * @throws CertificateParsingException If this extension cannot be - * parsed from its encoded form. - */ - public java.util.List getExtendedKeyUsage() - throws CertificateParsingException - { - throw new UnsupportedOperationException(); - } - - /** - * Returns the alternative names for this certificate's subject (the - * owner), or null if there are none. - * - * <p>This is an X.509 extension with OID 2.5.29.17 and is defined by - * the ASN.1 construction: - * - * <blockquote><pre> - * SubjectAltNames ::= GeneralNames - * - * GeneralNames ::= SEQUENCE SIZE (1..MAX) OF GeneralName - * - * GeneralName ::= CHOICE { - * otherName [0] OtherName, - * rfc822Name [1] IA5String, - * dNSName [2] IA5String, - * x400Address [3] ORAddress, - * directoryName [4] Name, - * ediPartyName [5] EDIPartyName, - * uniformResourceIdentifier [6] IA5String, - * iPAddress [7] OCTET STRING, - * registeredID [8] OBJECT IDENTIFIER - * } - * </pre></blockquote> - * - * <p>The returned collection contains one or more two-element Lists, - * with the first object being an Integer representing the choice - * above (with value 0 through 8) and the second being an (a) String - * if the <code>GeneralName</code> is a rfc822Name, dNSName, - * uniformResourceIdentifier, iPAddress, or registeredID, or (b) a - * byte array of the DER encoded form for any others. - * - * @return The collection of alternative names, or null if there are - * none. - * @throws CertificateParsingException If the encoded extension cannot - * be parsed. - * @since JDK 1.4 - */ - public java.util.Collection getSubjectAlternativeNames() - throws CertificateParsingException - { - throw new UnsupportedOperationException(); - } - - /** - * Returns the alternative names for this certificate's issuer, or - * null if there are none. - * - * <p>This is an X.509 extension with OID 2.5.29.18, and is defined by - * the ASN.1 construction: - * - * <blockquote><pre> - * IssuerAltNames ::= GeneralNames - * </pre></blockquote> - * - * <p>The <code>GeneralNames</code> construct and the form of the - * returned collection are the same as with {@link - * #getSubjectAlternativeNames()}. - * - * @return The collection of alternative names, or null if there are - * none. - * @throws CertificateParsingException If the encoded extension cannot - * be parsed. - * @since JDK 1.4 - */ - public java.util.Collection getIssuerAlternativeNames() - throws CertificateParsingException - { - throw new UnsupportedOperationException(); - } - - /** - * Returns the X.500 distinguished name of this certificate's subject. - * - * @return The subject's X.500 distinguished name. - * @since JDK 1.4 - */ - public javax.security.auth.x500.X500Principal getSubjectX500Principal() - { - throw new UnsupportedOperationException(); - } - - /** - * Returns the X.500 distinguished name of this certificate's issuer. - * - * @return The issuer's X.500 distinguished name. - * @since JDK 1.4 - */ - public javax.security.auth.x500.X500Principal getIssuerX500Principal() - { - throw new UnsupportedOperationException(); - } -} diff --git a/libjava/java/security/cert/X509Extension.java b/libjava/java/security/cert/X509Extension.java deleted file mode 100644 index d2cb80a9f57..00000000000 --- a/libjava/java/security/cert/X509Extension.java +++ /dev/null @@ -1,113 +0,0 @@ -/* X509Extension.java --- X.509 Extension - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security.cert; -import java.util.Set; - -/** - Public interface for the X.509 Extension. - - This is used for X.509 v3 Certificates and CRL v2 (Certificate - Revocation Lists) for managing attributes assoicated with - Certificates, for managing the hierarchy of certificates, - and for managing the distribution of CRL. This extension - format is used to define private extensions. - - Each extensions for a certificate or CRL must be marked - either critical or non-critical. If the certificate/CRL - system encounters a critical extension not recognized then - it must reject the certificate. A non-critical extension - may be just ignored if not recognized. - - - The ASN.1 definition for this class is: - - Extensions ::= SEQUENCE SIZE (1..MAX) OF Extension - - Extension ::= SEQUENCE { - extnId OBJECT IDENTIFIER, - critical BOOLEAN DEFAULT FALSE, - extnValue OCTET STRING - -- contains a DER encoding of a value - -- of the type registered for use with - -- the extnId object identifier value - } - - @author Mark Benvenuto - - @since JDK 1.2 -*/ -public interface X509Extension -{ - - /** - Returns true if the certificate contains a critical extension - that is not supported. - - @return true if has unsupported extension, false otherwise - */ - boolean hasUnsupportedCriticalExtension(); - - /** - Returns a set of the CRITICAL extension OIDs from the - certificate/CRL that the object implementing this interface - manages. - - @return A Set containing the OIDs. If there are no CRITICAL - extensions or extensions at all this returns null. - */ - Set getCriticalExtensionOIDs(); - - /** - Returns a set of the NON-CRITICAL extension OIDs from the - certificate/CRL that the object implementing this interface - manages. - - @return A Set containing the OIDs. If there are no NON-CRITICAL - extensions or extensions at all this returns null. - */ - Set getNonCriticalExtensionOIDs(); - - /** - Returns the DER encoded OCTET string for the specified - extension value identified by a OID. The OID is a string - of number separated by periods. Ex: 12.23.45.67 - */ - byte[] getExtensionValue(String oid); - -} diff --git a/libjava/java/security/interfaces/DSAKey.java b/libjava/java/security/interfaces/DSAKey.java deleted file mode 100644 index c6e819eb0e5..00000000000 --- a/libjava/java/security/interfaces/DSAKey.java +++ /dev/null @@ -1,56 +0,0 @@ -/* DSAKey.java -- Interface for Digital Signature Algorithm key - Copyright (C) 1998 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security.interfaces; - -/** - * This interface is implemented by a class to return the parameters - * of a Digital Signature Algorithm (DSA) public or private key. - * - * @version 0.0 - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public interface DSAKey -{ - /** - * This method returns non-secret parameters of the DSA key - * - * @return The DSA parameters - */ - DSAParams getParams(); -} diff --git a/libjava/java/security/interfaces/DSAKeyPairGenerator.java b/libjava/java/security/interfaces/DSAKeyPairGenerator.java deleted file mode 100644 index e657c54b4e6..00000000000 --- a/libjava/java/security/interfaces/DSAKeyPairGenerator.java +++ /dev/null @@ -1,85 +0,0 @@ -/* DSAKeyPairGenerator.java -- Initialize a DSA key generator - Copyright (C) 1998, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security.interfaces; - -import java.security.InvalidParameterException; -import java.security.SecureRandom; - -/** - * This interface contains methods for intializing a Digital Signature - * Algorithm key generation engine. The initialize methods may be called - * any number of times. If no explicity initialization call is made, then - * the engine defaults to generating 1024-bit keys using pre-calculated - * base, prime, and subprime values. - * - * @version 0.0 - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public interface DSAKeyPairGenerator -{ - /** - * Initializes the key generator with the specified DSA parameters and - * random bit source - * - * @param params The DSA parameters to use - * @param random The random bit source to use - * - * @exception InvalidParameterException If the parameters passed are not valid - */ - void initialize (DSAParams params, SecureRandom random) - throws InvalidParameterException; - - /** - * Initializes the key generator to a give modulus. If the <code>genParams</code> - * value is <code>true</code> then new base, prime, and subprime values - * will be generated for the given modulus. If not, the pre-calculated - * values will be used. If no pre-calculated values exist for the specified - * modulus, an exception will be thrown. It is guaranteed that there will - * always be pre-calculated values for all modulus values between 512 and - * 1024 bits inclusives. - * - * @param modlen The modulus length - * @param genParams <code>true</code> to generate new DSA parameters, <code>false</code> otherwise - * @param random The random bit source to use - * - * @exception InvalidParameterException If a parameter is invalid - */ - void initialize (int modlen, boolean genParams, SecureRandom random) - throws InvalidParameterException; -} diff --git a/libjava/java/security/interfaces/DSAParams.java b/libjava/java/security/interfaces/DSAParams.java deleted file mode 100644 index 42baeeb9570..00000000000 --- a/libjava/java/security/interfaces/DSAParams.java +++ /dev/null @@ -1,72 +0,0 @@ -/* DSAParams.java -- Digital Signature Algorithm parameter access - Copyright (C) 1998 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security.interfaces; - -import java.math.BigInteger; - -/** - * This interface allows the Digital Signature Algorithm (DSA) parameters - * to be queried. - * - * @version 0.0 - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public interface DSAParams -{ - /** - * Returns the base, or 'g' value - * - * @return The DSA base value - */ - BigInteger getG(); - - /** - * Returns the prime, or 'p' value - * - * @return The DSA prime value - */ - BigInteger getP(); - - /** - * Returns the subprime, or 'q' value - * - * @return The DSA subprime value - */ - BigInteger getQ(); -} diff --git a/libjava/java/security/interfaces/DSAPrivateKey.java b/libjava/java/security/interfaces/DSAPrivateKey.java deleted file mode 100644 index d79b34b9043..00000000000 --- a/libjava/java/security/interfaces/DSAPrivateKey.java +++ /dev/null @@ -1,61 +0,0 @@ -/* DSAPublicKey.java -- A Digital Signature Algorithm private key - Copyright (C) 1998, 2000, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security.interfaces; - -import java.math.BigInteger; -import java.security.PrivateKey; - -/** - * This interface models a Digital Signature Algorithm (DSA) private key - * - * @version 0.0 - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public interface DSAPrivateKey extends DSAKey, PrivateKey -{ - /** - * The version identifier used for serialization. - */ - long serialVersionUID = 7776497482533790279L; - - /** - * This method returns the value of the DSA private key - */ - BigInteger getX(); -} diff --git a/libjava/java/security/interfaces/DSAPublicKey.java b/libjava/java/security/interfaces/DSAPublicKey.java deleted file mode 100644 index d73e189f607..00000000000 --- a/libjava/java/security/interfaces/DSAPublicKey.java +++ /dev/null @@ -1,61 +0,0 @@ -/* DSAPublicKey.java -- A Digital Signature Algorithm public key - Copyright (C) 1998, 2000, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security.interfaces; - -import java.math.BigInteger; -import java.security.PublicKey; - -/** - * This interface models a Digital Signature Algorithm (DSA) public key - * - * @version 0.0 - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public interface DSAPublicKey extends DSAKey, PublicKey -{ - /** - * The version identifier used for serialization. - */ - long serialVersionUID = 1234526332779022332L; - - /** - * This method returns the value of the DSA public key - */ - BigInteger getY(); -} diff --git a/libjava/java/security/interfaces/RSAKey.java b/libjava/java/security/interfaces/RSAKey.java deleted file mode 100644 index 485fa81e05a..00000000000 --- a/libjava/java/security/interfaces/RSAKey.java +++ /dev/null @@ -1,57 +0,0 @@ -/* RSAKey.java --- A generic RSA Key interface - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security.interfaces; - -import java.math.BigInteger; - -/** - A generic RSA Key interface for public and private keys - - @since JDK 1.3 - - @author Mark Benvenuto - */ -public interface RSAKey -{ - /** - Generates a modulus. - - @returns a modulus - */ - BigInteger getModulus(); -} diff --git a/libjava/java/security/interfaces/RSAMultiPrimePrivateCrtKey.java b/libjava/java/security/interfaces/RSAMultiPrimePrivateCrtKey.java deleted file mode 100644 index d80b962d012..00000000000 --- a/libjava/java/security/interfaces/RSAMultiPrimePrivateCrtKey.java +++ /dev/null @@ -1,111 +0,0 @@ -/* RSAMultiPrimePrivateCrtKey.java -- - Copyright (C) 2003, Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security.interfaces; - -import java.math.BigInteger; -import java.security.spec.RSAOtherPrimeInfo; - -/** - * The interface to an RSA multi-prime private key, as defined in the PKCS#1 - * v2.1, using the <i>Chinese Remainder Theorem</i> (CRT) information values. - * - * @since 1.4 - * @see java.security.spec.RSAPrivateKeySpec - * @see java.security.spec.RSAMultiPrimePrivateCrtKeySpec - * @see RSAPrivateKey - * @see RSAPrivateCrtKey - */ -public interface RSAMultiPrimePrivateCrtKey extends RSAPrivateKey -{ - // Constants - // -------------------------------------------------------------------------- - long serialVersionUID = 618058533534628008L; - - // Methods - // -------------------------------------------------------------------------- - - /** - * Returns the public exponent. - * - * @return the public exponent. - */ - BigInteger getPublicExponent(); - - /** - * Returns the primeP. - * - * @return the primeP. - */ - BigInteger getPrimeP(); - - /** - * Returns the primeQ. - * - * @return the primeQ. - */ - BigInteger getPrimeQ(); - - /** - * Returns the primeExponentP. - * - * @return the primeExponentP. - */ - BigInteger getPrimeExponentP(); - - /** - * Returns the primeExponentQ. - * - * @return the primeExponentQ. - */ - BigInteger getPrimeExponentQ(); - - /** - * Returns the crtCoefficient. - * - * @return the crtCoefficient. - */ - BigInteger getCrtCoefficient(); - - /** - * Returns the otherPrimeInfo or <code>null</code> if there are only two - * prime factors (p and q). - * - * @return the otherPrimeInfo. - */ - RSAOtherPrimeInfo[] getOtherPrimeInfo(); -} diff --git a/libjava/java/security/interfaces/RSAPrivateCrtKey.java b/libjava/java/security/interfaces/RSAPrivateCrtKey.java deleted file mode 100644 index 96a1496cf92..00000000000 --- a/libjava/java/security/interfaces/RSAPrivateCrtKey.java +++ /dev/null @@ -1,95 +0,0 @@ -/* RSAPrivateCrtKey.java -- An RSA private key in CRT format - Copyright (C) 1998 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security.interfaces; - -import java.math.BigInteger; - -/** - * This interface provides access to information about an RSA private - * key in Chinese Remainder Theorem (CRT) format. - * - * @version 0.0 - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public interface RSAPrivateCrtKey extends RSAPrivateKey -{ - long serialVersionUID = -5682214253527700368L; - - /** - * Returns the public exponent for this key - * - * @return The public exponent for this key - */ - BigInteger getPublicExponent(); - - /** - * Returns the primeP value - * - * @return The primeP value - */ - BigInteger getPrimeP(); - - /** - * Returns the primeQ value - * - * @return The primeQ value - */ - BigInteger getPrimeQ(); - - /** - * Returns the primeExponentP - * - * @return The primeExponentP - */ - BigInteger getPrimeExponentP(); - - /** - * Returns the primeExponentQ - * - * @return The primeExponentQ - */ - BigInteger getPrimeExponentQ(); - - /** - * Returns the CRT coefficient - * - * @return The CRT coefficient - */ - BigInteger getCrtCoefficient(); -} diff --git a/libjava/java/security/interfaces/RSAPrivateKey.java b/libjava/java/security/interfaces/RSAPrivateKey.java deleted file mode 100644 index 514987625a5..00000000000 --- a/libjava/java/security/interfaces/RSAPrivateKey.java +++ /dev/null @@ -1,60 +0,0 @@ -/* RSAPrivateKey.java -- An RSA private key - Copyright (C) 1998, 1999, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security.interfaces; - -import java.math.BigInteger; -import java.security.PrivateKey; - -/** - * This interface provides access to information about an RSA private key. - * - * @version 0.1 - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public interface RSAPrivateKey extends PrivateKey, RSAKey -{ - long serialVersionUID = 5187144804936595022L; - - /** - * Returns the private exponent value for this key - * - * @return The private exponent value for this key - */ - BigInteger getPrivateExponent(); -} diff --git a/libjava/java/security/interfaces/RSAPublicKey.java b/libjava/java/security/interfaces/RSAPublicKey.java deleted file mode 100644 index 5fb569d1dec..00000000000 --- a/libjava/java/security/interfaces/RSAPublicKey.java +++ /dev/null @@ -1,60 +0,0 @@ -/* RSAPublicKey.java -- An RSA public key - Copyright (C) 1998, 1999, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security.interfaces; - -import java.math.BigInteger; -import java.security.PublicKey; - -/** - * This interface provides access to information about an RSA public key. - * - * @version 0.1 - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public interface RSAPublicKey extends PublicKey, RSAKey -{ - long serialVersionUID = -8727434096241101194L; - - /** - * Returns the public exponent value for this key - * - * @return The public exponent value for this key - */ - BigInteger getPublicExponent(); -} diff --git a/libjava/java/security/spec/AlgorithmParameterSpec.java b/libjava/java/security/spec/AlgorithmParameterSpec.java deleted file mode 100644 index 25506f55cfe..00000000000 --- a/libjava/java/security/spec/AlgorithmParameterSpec.java +++ /dev/null @@ -1,52 +0,0 @@ -/* AlgorithmParameterSpec.java --- Algorithm Parameter Spec Interface - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security.spec; - -/** - A transparent interface for Algorithm Parameter Specifications. - It contains no member functions. It is used to group - algorithm parameter classes. - - @since JDK 1.2 - - @author Mark Benvenuto -*/ -public interface AlgorithmParameterSpec -{ -} diff --git a/libjava/java/security/spec/DSAParameterSpec.java b/libjava/java/security/spec/DSAParameterSpec.java deleted file mode 100644 index 31270537c4c..00000000000 --- a/libjava/java/security/spec/DSAParameterSpec.java +++ /dev/null @@ -1,101 +0,0 @@ -/* DSAParameterSpec.java --- DSA Parameter Specificaton class - Copyright (C) 1999, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security.spec; - -import java.math.BigInteger; -import java.security.interfaces.DSAParams; - -/** - * DSA Parameter class Specification. Used to maintain the DSA - * Parameters. - * - * @since 1.2 - * - * @author Mark Benvenuto -*/ -public class DSAParameterSpec implements AlgorithmParameterSpec, DSAParams -{ - private BigInteger p = null; - private BigInteger q = null; - private BigInteger g = null; - - /** - * Constructs a new DSAParameterSpec with the specified p, q, and g. - * - * @param p the prime - * @param q the sub-prime - * @param g the base - */ - public DSAParameterSpec(BigInteger p, BigInteger q, BigInteger g) - { - this.p = p; - this.q = q; - this.g = g; - } - - /** - * Returns p for the DSA algorithm. - * - * @return Returns the requested BigInteger - */ - public BigInteger getP() - { - return this.p; - } - - /** - * Returns p for the DSA algorithm. - * - * @return Returns the requested BigInteger - */ - public BigInteger getQ() - { - return this.q; - } - - /** - * Returns g for the DSA algorithm. - * - * @return Returns the requested BigInteger - */ - public BigInteger getG() - { - return this.g; - } -} diff --git a/libjava/java/security/spec/DSAPrivateKeySpec.java b/libjava/java/security/spec/DSAPrivateKeySpec.java deleted file mode 100644 index 7415fa11a45..00000000000 --- a/libjava/java/security/spec/DSAPrivateKeySpec.java +++ /dev/null @@ -1,113 +0,0 @@ -/* DSAPrivateKeySpec.java --- DSA Private Key Specificaton class - Copyright (C) 1999, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security.spec; -import java.math.BigInteger; - -/** - DSA Private Key class Specification. Used to maintain the DSA - Private Keys. - - @since JDK 1.2 - - @author Mark Benvenuto -*/ -public class DSAPrivateKeySpec implements KeySpec -{ - private BigInteger x = null; - private BigInteger p = null; - private BigInteger q = null; - private BigInteger g = null; - - /** - Constructs a new DSAPrivateKeySpec with the specified x, p, q, and g. - - @param x the private key - @param p the prime - @param q the sub-prime - @param g the base - */ - public DSAPrivateKeySpec(BigInteger x, BigInteger p, BigInteger q, BigInteger g) - { - this.x = x; - this.p = p; - this.q = q; - this.g = g; - } - - /** - Returns private key x for the DSA algorithm. - - @return Returns the requested BigInteger - */ - public BigInteger getX() - { - return this.x; - } - - /** - Returns p for the DSA algorithm. - - @return Returns the requested BigInteger - */ - public BigInteger getP() - { - return this.p; - } - - /** - Returns p for the DSA algorithm. - - @return Returns the requested BigInteger - */ - public BigInteger getQ() - { - return this.q; - } - - /** - Returns g for the DSA algorithm. - - @return Returns the requested BigInteger - */ - public BigInteger getG() - { - return this.g; - } - -} diff --git a/libjava/java/security/spec/DSAPublicKeySpec.java b/libjava/java/security/spec/DSAPublicKeySpec.java deleted file mode 100644 index ac1310c1caa..00000000000 --- a/libjava/java/security/spec/DSAPublicKeySpec.java +++ /dev/null @@ -1,113 +0,0 @@ -/* DSAPublicKeySpec.java --- DSA Public Key Specificaton class - Copyright (C) 1999, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security.spec; -import java.math.BigInteger; - -/** - DSA Public Key class Specification. Used to maintain the DSA - Public Keys. - - @since JDK 1.2 - - @author Mark Benvenuto -*/ -public class DSAPublicKeySpec implements KeySpec -{ - private BigInteger y = null; - private BigInteger p = null; - private BigInteger q = null; - private BigInteger g = null; - - /** - Constructs a new DSAPublicKeySpec with the specified y, p, q, and g. - - @param y the public key - @param p the prime - @param q the sub-prime - @param g the base - */ - public DSAPublicKeySpec(BigInteger y, BigInteger p, BigInteger q, BigInteger g) - { - this.y = y; - this.p = p; - this.q = q; - this.g = g; - } - - /** - Returns public key y for the DSA algorithm. - - @return Returns the requested BigInteger - */ - public BigInteger getY() - { - return this.y; - } - - /** - Returns p for the DSA algorithm. - - @return Returns the requested BigInteger - */ - public BigInteger getP() - { - return this.p; - } - - /** - Returns p for the DSA algorithm. - - @return Returns the requested BigInteger - */ - public BigInteger getQ() - { - return this.q; - } - - /** - Returns g for the DSA algorithm. - - @return Returns the requested BigInteger - */ - public BigInteger getG() - { - return this.g; - } - -} diff --git a/libjava/java/security/spec/EncodedKeySpec.java b/libjava/java/security/spec/EncodedKeySpec.java deleted file mode 100644 index c5baf55fd7a..00000000000 --- a/libjava/java/security/spec/EncodedKeySpec.java +++ /dev/null @@ -1,85 +0,0 @@ -/* EncodedKeySpec.java --- Encoded Key Specificaton class - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security.spec; - -/** - Encoded Key Specification class which is used to store - byte encoded keys. - - @since JDK 1.2 - - @author Mark Benvenuto -*/ -public abstract class EncodedKeySpec implements KeySpec -{ - - private byte[] encodedKey; - - /** - Constructs a new EncodedKeySpec with the specified encoded key. - - @param encodedKey A key to store - */ - public EncodedKeySpec(byte[] encodedKey) - { - this.encodedKey = encodedKey; - } - - /** - Gets the encoded key in byte format. - - @returns the encoded key - */ - public byte[] getEncoded() - { - return this.encodedKey; - } - - /** - Returns the name of the key format used. - - This name is the format such as "PKCS#8" or "X.509" which - if it matches a Key class name of the same type can be - transformed using the apporiate KeyFactory. - - @return a string representing the name - */ - public abstract String getFormat(); - -} diff --git a/libjava/java/security/spec/InvalidKeySpecException.java b/libjava/java/security/spec/InvalidKeySpecException.java deleted file mode 100644 index c2ec6b03b5a..00000000000 --- a/libjava/java/security/spec/InvalidKeySpecException.java +++ /dev/null @@ -1,74 +0,0 @@ -/* InvalidKeySpecException.java -- invalid KeySpec Exception - Copyright (C) 1999, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security.spec; - -import java.security.GeneralSecurityException; - -/** - * Exception for an invalid key specification. - * - * @author Mark Benvenuto - * @see KeySpec - * @since 1.2 - * @status updated to 1.4 - */ -public class InvalidKeySpecException extends GeneralSecurityException -{ - /** - * Compatible with JDK 1.2+. - */ - private static final long serialVersionUID = 3546139293998810778L; - - /** - * Constructs an InvalidKeySpecException without a message string. - */ - public InvalidKeySpecException() - { - } - - /** - * Constructs an InvalidKeySpecException with a message string. - * - * @param msg a message to display with exception - */ - public InvalidKeySpecException(String msg) - { - super(msg); - } -} diff --git a/libjava/java/security/spec/InvalidParameterSpecException.java b/libjava/java/security/spec/InvalidParameterSpecException.java deleted file mode 100644 index 481e11e306b..00000000000 --- a/libjava/java/security/spec/InvalidParameterSpecException.java +++ /dev/null @@ -1,76 +0,0 @@ -/* InvalidParameterSpecException.java --- invalid ParameterSpec Exception - Copyright (C) 1999, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security.spec; - -import java.security.GeneralSecurityException; - -/** - * Exception for an invalid algorithm specification. - * - * @author Mark Benvenuto - * @see AlogorithmParameters - * @see AlogorithmParameterSpec - * @see DSAParameterSpec - * @since 1.2 - * @status updated to 1.4 -*/ -public class InvalidParameterSpecException extends GeneralSecurityException -{ - /** - * Compatible with JDK 1.2+. - */ - private static final long serialVersionUID = -970468769593399342L; - - /** - * Constructs an InvalidParameterSpecException without a message string. - */ - public InvalidParameterSpecException() - { - } - - /** - * Constructs an InvalidParameterSpecException with a message string. - * - * @param msg a message to display with exception - */ - public InvalidParameterSpecException(String msg) - { - super(msg); - } -} diff --git a/libjava/java/security/spec/KeySpec.java b/libjava/java/security/spec/KeySpec.java deleted file mode 100644 index 93f1a6db277..00000000000 --- a/libjava/java/security/spec/KeySpec.java +++ /dev/null @@ -1,52 +0,0 @@ -/* KeySpec.java --- Key Specification interface - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security.spec; - -/** - A transparent interface for Key Specifications. - It contains no member functions. It is used to group - key classes. - - @since JDK 1.2 - - @author Mark Benvenuto -*/ -public interface KeySpec -{ -} diff --git a/libjava/java/security/spec/PKCS8EncodedKeySpec.java b/libjava/java/security/spec/PKCS8EncodedKeySpec.java deleted file mode 100644 index 4a4f1eccea7..00000000000 --- a/libjava/java/security/spec/PKCS8EncodedKeySpec.java +++ /dev/null @@ -1,81 +0,0 @@ -/* PKCS8EncodedKeySpec.java --- PKCS8 Encoded Key Specificaton class - Copyright (C) 1999, 2001 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security.spec; - -/** - PKCS8 Encoded Key Specification class which is used to store - "PKCS#8" byte encoded keys. - - @since JDK 1.2 - - @author Mark Benvenuto -*/ -public class PKCS8EncodedKeySpec extends EncodedKeySpec -{ - /** - Constructs a new PKCS8EncodedKeySpec with the specified encoded key. - - @param encodedKey A key to store, assumed to be "PKCS#8" - */ - public PKCS8EncodedKeySpec(byte[] encodedKey) - { - super( encodedKey ); - } - - /** - Gets the encoded key in byte format. - - @returns the encoded key -*/ - public byte[] getEncoded() - { - return super.getEncoded(); - } - - /** - Returns the name of the key format used which is "PKCS#8" - - @return a string representing the name -*/ - public final String getFormat() - { - return "PKCS#8"; - } - -} diff --git a/libjava/java/security/spec/PSSParameterSpec.java b/libjava/java/security/spec/PSSParameterSpec.java deleted file mode 100644 index 7a14a24fbe4..00000000000 --- a/libjava/java/security/spec/PSSParameterSpec.java +++ /dev/null @@ -1,90 +0,0 @@ -/* PSSParameterSpec.java -- - Copyright (C) 2003, Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security.spec; - -/** - * This class specifies a parameter spec for RSA PSS encoding scheme, as - * defined in the PKCS#1 v2.1. - * - * @since 1.4 - * @see AlgorithmParameterSpec - * @see java.security.Signature - */ -public class PSSParameterSpec implements AlgorithmParameterSpec -{ - // Constants and fields - // -------------------------------------------------------------------------- - - private int saltLen; - - // Constructor(s) - // -------------------------------------------------------------------------- - - /** - * Creates a new <code>PSSParameterSpec</code> given the salt length as - * defined in PKCS#1. - * - * @param saltLen the length of salt in bits to be used in PKCS#1 PSS encoding. - * @throws IllegalArgumentException if <code>saltLen</code> is less than - * <code>0</code>. - */ - public PSSParameterSpec(int saltLen) - { - super(); - - if (saltLen < 0) - throw new IllegalArgumentException(); - this.saltLen = saltLen; - } - - // Class methods - // -------------------------------------------------------------------------- - - // Instance methods - // -------------------------------------------------------------------------- - - /** - * Returns the salt length in bits. - * - * @return the salt length. - */ - public int getSaltLength() - { - return this.saltLen; - } -} diff --git a/libjava/java/security/spec/RSAKeyGenParameterSpec.java b/libjava/java/security/spec/RSAKeyGenParameterSpec.java deleted file mode 100644 index 0df8dec783e..00000000000 --- a/libjava/java/security/spec/RSAKeyGenParameterSpec.java +++ /dev/null @@ -1,97 +0,0 @@ -/* RSAKeyGenParameterSpec.java --- RSA Key Generator Parameter Spec Class - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security.spec; -import java.math.BigInteger; - -/** - This class generates a set of RSA Key parameters used in the generation - of RSA keys. - - @since JDK 1.3 - - @author Mark Benvenuto -*/ -public class RSAKeyGenParameterSpec implements AlgorithmParameterSpec -{ - private int keysize; - private BigInteger publicExponent; - - /** - Public Exponent F0 = 3 - */ - public static final BigInteger F0 = new BigInteger("3"); - - /** - Public Exponent F4 = 3 - */ - public static final BigInteger F4 = new BigInteger("65537"); - - /** - Create a new RSAKeyGenParameterSpec to store the RSA key's keysize - and public exponent - - @param keysize Modulus size of key in bits - @param publicExponent - the exponent - */ - public RSAKeyGenParameterSpec(int keysize, BigInteger publicExponent) - { - this.keysize = keysize; - this.publicExponent = publicExponent; - } - - /** - Return the size of the key. - - @return the size of the key. - */ - public int getKeysize() - { - return keysize; - } - - /** - Return the public exponent. - - @return the public exponent. - */ - public BigInteger getPublicExponent() - { - return publicExponent; - } -} diff --git a/libjava/java/security/spec/RSAMultiPrimePrivateCrtKeySpec.java b/libjava/java/security/spec/RSAMultiPrimePrivateCrtKeySpec.java deleted file mode 100644 index 519a0291373..00000000000 --- a/libjava/java/security/spec/RSAMultiPrimePrivateCrtKeySpec.java +++ /dev/null @@ -1,217 +0,0 @@ -/* PSSParameterSpec.java -- - Copyright (C) 2003, Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security.spec; - -import java.math.BigInteger; - -/** - * This class specifies an RSA multi-prime private key, as defined in the - * PKCS#1 v2.1, using the <i>Chinese Remainder Theorem</i> (CRT) information - * values for efficiency. - * - * @since 1.4 - * @see java.security.Key - * @see java.security.KeyFactory - * @see KeySpec - * @see PKCS8EncodedKeySpec - * @see RSAPrivateKeySpec - * @see RSAPublicKeySpec - * @see RSAOtherPrimeInfo - */ -public class RSAMultiPrimePrivateCrtKeySpec extends RSAPrivateKeySpec -{ - // Constants and fields - // -------------------------------------------------------------------------- - - private BigInteger publicExponent; - private BigInteger primeP; - private BigInteger primeQ; - private BigInteger primeExponentP; - private BigInteger primeExponentQ; - private BigInteger crtCoefficient; - private RSAOtherPrimeInfo[] otherPrimeInfo; - - // Constructor(s) - // -------------------------------------------------------------------------- - - /** - * <p>Creates a new <code>RSAMultiPrimePrivateCrtKeySpec</code> given the - * modulus, publicExponent, privateExponent, primeP, primeQ, primeExponentP, - * primeExponentQ, crtCoefficient, and otherPrimeInfo as defined in PKCS#1 - * v2.1.</p> - * - * <p>Note that <code>otherPrimeInfo</code> is cloned when constructing this - * object.</p> - * - * @param modulus the modulus n. - * @param publicExponent the public exponent e. - * @param privateExponent the private exponent d. - * @param primeP the prime factor p of n. - * @param primeQ the prime factor q of n. - * @param primeExponentP this is d mod (p-1). - * @param primeExponentQ this is d mod (q-1). - * @param crtCoefficient the Chinese Remainder Theorem coefficient q-1 mod p. - * @param otherPrimeInfo triplets of the rest of primes, <code>null</code> - * can be specified if there are only two prime factors (p and q). - * @throws NullPointerException if any of the parameters, i.e. modulus, - * publicExponent, privateExponent, primeP, primeQ, primeExponentP, - * primeExponentQ, crtCoefficient, is <code>null</code>. - * @throws IllegalArgumentException if an empty, i.e. 0-length, - * otherPrimeInfo is specified. - */ - public RSAMultiPrimePrivateCrtKeySpec(BigInteger modulus, - BigInteger publicExponent, - BigInteger privateExponent, - BigInteger primeP, - BigInteger primeQ, - BigInteger primeExponentP, - BigInteger primeExponentQ, - BigInteger crtCoefficient, - RSAOtherPrimeInfo[] otherPrimeInfo) - { - super(modulus, privateExponent); - - if (modulus == null) - throw new NullPointerException("modulus"); - if (publicExponent == null) - throw new NullPointerException("publicExponent"); - if (privateExponent == null) - throw new NullPointerException("privateExponent"); - if (primeP == null) - throw new NullPointerException("primeP"); - if (primeQ == null) - throw new NullPointerException("primeQ"); - if (primeExponentP == null) - throw new NullPointerException("primeExponentP"); - if (primeExponentQ == null) - throw new NullPointerException("primeExponentQ"); - if (crtCoefficient == null) - throw new NullPointerException("crtCoefficient"); - if (otherPrimeInfo != null) - if (otherPrimeInfo.length == 0) - throw new IllegalArgumentException(); - else - this.otherPrimeInfo = (RSAOtherPrimeInfo[]) otherPrimeInfo.clone(); - - this.publicExponent = publicExponent; - this.primeP = primeP; - this.primeQ = primeQ; - this.primeExponentP = primeExponentP; - this.primeExponentQ = primeExponentQ; - this.crtCoefficient = crtCoefficient; - } - - // Class methods - // -------------------------------------------------------------------------- - - // Instance methods - // -------------------------------------------------------------------------- - - /** - * Returns the public exponent. - * - * @return the public exponent. - */ - public BigInteger getPublicExponent() - { - return this.publicExponent; - } - - /** - * Returns the primeP. - * - * @return the primeP. - */ - public BigInteger getPrimeP() - { - return this.primeP; - } - - /** - * Returns the primeQ. - * - * @return the primeQ. - */ - public BigInteger getPrimeQ() - { - return this.primeQ; - } - - /** - * Returns the primeExponentP. - * - * @return the primeExponentP. - */ - public BigInteger getPrimeExponentP() - { - return this.primeExponentP; - } - - /** - * Returns the primeExponentQ. - * - * @return the primeExponentQ. - */ - public BigInteger getPrimeExponentQ() - { - return this.primeExponentQ; - } - - /** - * Returns the crtCoefficient. - * - * @return the crtCoefficient. - */ - public BigInteger getCrtCoefficient() - { - return this.crtCoefficient; - } - - /** - * Returns a copy of the otherPrimeInfo or <code>null</code> if there are - * only two prime factors (p and q). - * - * @return the otherPrimeInfo. - */ - public RSAOtherPrimeInfo[] getOtherPrimeInfo() - { - return this.otherPrimeInfo == null - ? null - : (RSAOtherPrimeInfo[]) this.otherPrimeInfo.clone(); - } -} diff --git a/libjava/java/security/spec/RSAOtherPrimeInfo.java b/libjava/java/security/spec/RSAOtherPrimeInfo.java deleted file mode 100644 index 654bcb574d8..00000000000 --- a/libjava/java/security/spec/RSAOtherPrimeInfo.java +++ /dev/null @@ -1,133 +0,0 @@ -/* RSAOtherPrimeInfo.java -- - Copyright (C) 2003, Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.security.spec; - -import java.math.BigInteger; - -/** - * This class represents the triplet (prime, exponent, and coefficient) inside - * RSA's OtherPrimeInfo structure, as defined in the PKCS#1 v2.1. The ASN.1 - * syntax of RSA's OtherPrimeInfo is as follows: - * - * <pre> - * OtherPrimeInfo ::= SEQUENCE { - * prime INTEGER, - * exponent INTEGER, - * coefficient INTEGER - * } - * </pre> - * - * @since 1.4 - * @see RSAPrivateCrtKeySpec - * @see java.security.interfaces.RSAMultiPrimePrivateCrtKey - */ -public class RSAOtherPrimeInfo -{ - // Constants and fields - // -------------------------------------------------------------------------- - - private BigInteger prime; - private BigInteger primeExponent; - private BigInteger crtCoefficient; - - // Constructor(s) - // -------------------------------------------------------------------------- - - /** - * Creates a new <code>RSAOtherPrimeInfo</code> given the prime, - * primeExponent, and crtCoefficient as defined in PKCS#1. - * - * @param prime the prime factor of n. - * @param primeExponent the exponent. - * @param crtCoefficient the Chinese Remainder Theorem coefficient. - * @throws NullPointerException if any of the parameters, i.e. prime, - * primeExponent, crtCoefficient, is <code>null</code>. - */ - public RSAOtherPrimeInfo(BigInteger prime, BigInteger primeExponent, - BigInteger crtCoefficient) - { - super(); - - if (prime == null) - throw new NullPointerException("prime"); - if (primeExponent == null) - throw new NullPointerException("primeExponent"); - if (crtCoefficient == null) - throw new NullPointerException("crtCoefficient"); - - this.prime = prime; - this.primeExponent = primeExponent; - this.crtCoefficient = crtCoefficient; - } - - // Class methods - // -------------------------------------------------------------------------- - - // Instance methods - // -------------------------------------------------------------------------- - - /** - * Returns the prime. - * - * @return the prime. - */ - public final BigInteger getPrime() - { - return this.prime; - } - - /** - * Returns the prime's exponent. - * - * @return the primeExponent. - */ - public final BigInteger getExponent() - { - return this.primeExponent; - } - - /** - * Returns the prime's crtCoefficient. - * - * @return the crtCoefficient. - */ - public final BigInteger getCrtCoefficient() - { - return this.crtCoefficient; - } -} diff --git a/libjava/java/security/spec/RSAPrivateCrtKeySpec.java b/libjava/java/security/spec/RSAPrivateCrtKeySpec.java deleted file mode 100644 index a904c305d65..00000000000 --- a/libjava/java/security/spec/RSAPrivateCrtKeySpec.java +++ /dev/null @@ -1,151 +0,0 @@ -/* RSAPrivateCrtKeySpec.java --- RSA Private Certificate Key Specificaton class - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security.spec; -import java.math.BigInteger; - -/** - RSA Private Certificate Key class Specification. Used to - maintain the RSA Private Certificate Keys with the - <I>Chinese Remainder Theorem</I>(CRT) as specified by PKCS#1. - - @since JDK 1.2 - - @author Mark Benvenuto -*/ -public class RSAPrivateCrtKeySpec extends RSAPrivateKeySpec -{ - private BigInteger publicExponent; - private BigInteger primeP; - private BigInteger primeQ; - private BigInteger primeExponentP; - private BigInteger primeExponentQ; - private BigInteger crtCoefficient; - - /** - Constructs a new RSAPrivateKeySpec with the specified - variables. - - @param modulus the RSA modulus - @param publicExponent the public key exponent - @param privateExponent the private key exponent - @param primeP the prime P - @param primeQ the prime Q - @param primeExponentP the prime exponent P - @param primeExponentQ the prime exponent P - @param crtCoefficient the CRT coefficient - */ - public RSAPrivateCrtKeySpec(BigInteger modulus, - BigInteger publicExponent, - BigInteger privateExponent, - BigInteger primeP, - BigInteger primeQ, - BigInteger primeExponentP, - BigInteger primeExponentQ, - BigInteger crtCoefficient) - { - super( modulus, privateExponent); - this.publicExponent = publicExponent; - this.primeP = primeP; - this.primeQ = primeQ; - this.primeExponentP = primeExponentP; - this.primeExponentQ = primeExponentQ; - this.crtCoefficient = crtCoefficient; - } - - /** - Gets the RSA public exponent. - - @return the RSA public exponent - */ - public BigInteger getPublicExponent() - { - return this.publicExponent; - } - - /** - Gets the RSA prime P. - - @return the RSA prime P - */ - public BigInteger getPrimeP() - { - return this.primeP; - } - - /** - Gets the RSA prime Q. - - @return the RSA prime Q - */ - public BigInteger getPrimeQ() - { - return this.primeQ; - } - - /** - Gets the RSA prime exponent P. - - @return the RSA prime exponent P - */ - public BigInteger getPrimeExponentP() - { - return this.primeExponentP; - } - - /** - Gets the RSA prime exponent P. - - @return the RSA prime exponent Q - */ - public BigInteger getPrimeExponentQ() - { - return this.primeExponentQ; - } - - /** - Gets the RSA CRT coefficient. - - @return the RSA CRT coefficient - */ - public BigInteger getCrtCoefficient() - { - return this.crtCoefficient; - } - -} diff --git a/libjava/java/security/spec/RSAPrivateKeySpec.java b/libjava/java/security/spec/RSAPrivateKeySpec.java deleted file mode 100644 index d29f261cfb3..00000000000 --- a/libjava/java/security/spec/RSAPrivateKeySpec.java +++ /dev/null @@ -1,88 +0,0 @@ -/* RSAPrivateKeySpec.java --- RSA Private Key Specificaton class - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security.spec; -import java.math.BigInteger; - -/** - RSA Private Key class Specification. Used to maintain the RSA - Private Keys. - - @since JDK 1.2 - - @author Mark Benvenuto -*/ -public class RSAPrivateKeySpec implements KeySpec -{ - private BigInteger modulus; - private BigInteger privateExponent; - - /** - Constructs a new RSAPrivateKeySpec with the specified - modulus and privateExponent. - - @param modulus the RSA modulus - @param privateExponent the private key exponent - */ - public RSAPrivateKeySpec(BigInteger modulus, BigInteger privateExponent) - { - this.modulus = modulus; - this.privateExponent = privateExponent; - } - - /** - Gets the RSA modulus. - - @return the RSA modulus - */ - public BigInteger getModulus() - { - return this.modulus; - } - - /** - Gets the RSA private exponent. - - @return the RSA private exponent - */ - public BigInteger getPrivateExponent() - { - return this.privateExponent; - } - -} diff --git a/libjava/java/security/spec/RSAPublicKeySpec.java b/libjava/java/security/spec/RSAPublicKeySpec.java deleted file mode 100644 index 21283aa643b..00000000000 --- a/libjava/java/security/spec/RSAPublicKeySpec.java +++ /dev/null @@ -1,88 +0,0 @@ -/* RSAPublicKeySpec.java --- RSA Public Key Specificaton class - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security.spec; -import java.math.BigInteger; - -/** - RSA Public Key class Specification. Used to maintain the RSA - Public Keys. - - @since JDK 1.2 - - @author Mark Benvenuto -*/ -public class RSAPublicKeySpec implements KeySpec -{ - private BigInteger modulus; - private BigInteger publicExponent; - - /** - Constructs a new RSAPublicKeySpec with the specified - modulus and publicExponent. - - @param modulus the RSA modulus - @param publicExponent the public key exponent - */ - public RSAPublicKeySpec(BigInteger modulus, BigInteger publicExponent) - { - this.modulus = modulus; - this.publicExponent = publicExponent; - } - - /** - Gets the RSA modulus. - - @return the RSA modulus - */ - public BigInteger getModulus() - { - return this.modulus; - } - - /** - Gets the RSA public exponent. - - @return the RSA public exponent - */ - public BigInteger getPublicExponent() - { - return this.publicExponent; - } - -} diff --git a/libjava/java/security/spec/X509EncodedKeySpec.java b/libjava/java/security/spec/X509EncodedKeySpec.java deleted file mode 100644 index de35960296d..00000000000 --- a/libjava/java/security/spec/X509EncodedKeySpec.java +++ /dev/null @@ -1,82 +0,0 @@ -/* X509EncodedKeySpec.java --- X.509 Encoded Key Specificaton class - Copyright (C) 1999, 2001 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.security.spec; - -/** - X.509 Encoded Key Specification class which is used to store - "X.509" byte encoded keys. - - @since JDK 1.2 - - @author Mark Benvenuto -*/ -public class X509EncodedKeySpec extends EncodedKeySpec -{ - - /** - Constructs a new X509EncodedKeySpec with the specified encoded key. - - @param encodedKey A key to store, assumed to be "X.509" - */ - public X509EncodedKeySpec(byte[] encodedKey) - { - super( encodedKey ); - } - - /** - Gets the encoded key in byte format. - - @returns the encoded key - */ - public byte[] getEncoded() - { - return super.getEncoded(); - } - - /** - Returns the name of the key format used which is "X.509" - - @return a string representing the name - */ - public final String getFormat() - { - return "X.509"; - } - -} diff --git a/libjava/java/sql/Array.java b/libjava/java/sql/Array.java deleted file mode 100644 index 51628757885..00000000000 --- a/libjava/java/sql/Array.java +++ /dev/null @@ -1,185 +0,0 @@ -/* Array.java -- Interface for accessing SQL array object - Copyright (C) 1999, 2000, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.sql; - -import java.util.Map; - -/** - * This interface provides methods for accessing SQL array types. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public interface Array -{ - /** - * Returns the name of the SQL type of the elements in this - * array. This name is database specific. - * - * @param The name of the SQL type of the elements in this array. - * @exception SQLException If an error occurs. - */ - String getBaseTypeName() throws SQLException; - - /** - * Returns the JDBC type identifier of the elements in this - * array. This will be one of the values defined in the - * <code>Types</code> class. - * - * @return The JDBC type of the elements in this array. - * @exception SQLException If an error occurs. - * @see Types - */ - int getBaseType() throws SQLException; - - /** - * Returns the contents of this array. This object returned - * will be an array of Java objects of the appropriate types. - * - * @return The contents of the array as an array of Java objects. - * @exception SQLException If an error occurs. - */ - Object getArray() throws SQLException; - - /** - * Returns the contents of this array. The specified - * <code>Map</code> will be used to override selected mappings - * between SQL types and Java classes. - * - * @param map A mapping of SQL types to Java classes. - * @return The contents of the array as an array of Java objects. - * @exception SQLException If an error occurs. - */ - Object getArray(Map map) throws SQLException; - - /** - * Returns a portion of this array starting at <code>index</code> - * into the array and continuing for <code>count</code> - * elements. Fewer than the requested number of elements will be - * returned if the array does not contain the requested number of elements. - * The object returned will be an array of Java objects of - * the appropriate types. - * - * @param offset The offset into this array to start returning elements from. - * @param count The requested number of elements to return. - * @return The requested portion of the array. - * @exception SQLException If an error occurs. - */ - Object getArray(long index, int count) throws SQLException; - - /** - * This method returns a portion of this array starting at <code>index</code> - * into the array and continuing for <code>count</code> - * elements. Fewer than the requested number of elements will be - * returned if the array does not contain the requested number of elements. - * The object returned will be an array of Java objects. The specified - * <code>Map</code> will be used for overriding selected SQL type to - * Java class mappings. - * - * @param offset The offset into this array to start returning elements from. - * @param count The requested number of elements to return. - * @param map A mapping of SQL types to Java classes. - * @return The requested portion of the array. - * @exception SQLException If an error occurs. - */ - Object getArray(long index, int count, Map map) throws SQLException; - - /** - * Returns the elements in the array as a <code>ResultSet</code>. - * Each row of the result set will have two columns. The first will be - * the index into the array of that row's contents. The second will be - * the actual value of that array element. - * - * @return The elements of this array as a <code>ResultSet</code>. - * @exception SQLException If an error occurs. - * @see ResultSet - */ - ResultSet getResultSet() throws SQLException; - - /** - * This method returns the elements in the array as a <code>ResultSet</code>. - * Each row of the result set will have two columns. The first will be - * the index into the array of that row's contents. The second will be - * the actual value of that array element. The specified <code>Map</code> - * will be used to override selected default mappings of SQL types to - * Java classes. - * - * @param map A mapping of SQL types to Java classes. - * @return The elements of this array as a <code>ResultSet</code>. - * @exception SQLException If an error occurs. - * @see ResultSet - */ - ResultSet getResultSet(Map map) throws SQLException; - - /** - * This method returns a portion of the array as a <code>ResultSet</code>. - * The returned portion will start at <code>index</code> into the - * array and up to <code>count</code> elements will be returned. - * <p> - * Each row of the result set will have two columns. The first will be - * the index into the array of that row's contents. The second will be - * the actual value of that array element. - * - * @param offset The index into the array to start returning elements from. - * @param length The requested number of elements to return. - * @return The requested elements of this array as a <code>ResultSet</code>. - * @exception SQLException If an error occurs. - * @see ResultSet - */ - ResultSet getResultSet(long index, int count) throws SQLException; - - /** - * This method returns a portion of the array as a <code>ResultSet</code>. - * The returned portion will start at <code>index</code> into the - * array and up to <code>count</code> elements will be returned. - * - * <p> Each row of the result set will have two columns. The first will be - * the index into the array of that row's contents. The second will be - * the actual value of that array element. The specified <code>Map</code> - * will be used to override selected default mappings of SQL types to - * Java classes.</p> - * - * @param offset The index into the array to start returning elements from. - * @param length The requested number of elements to return. - * @param map A mapping of SQL types to Java classes. - * @return The requested elements of this array as a <code>ResultSet</code>. - * @exception SQLException If an error occurs. - * @see ResultSet - */ - ResultSet getResultSet(long index, int count, Map map) - throws SQLException; -} diff --git a/libjava/java/sql/BatchUpdateException.java b/libjava/java/sql/BatchUpdateException.java deleted file mode 100644 index c2e186548db..00000000000 --- a/libjava/java/sql/BatchUpdateException.java +++ /dev/null @@ -1,141 +0,0 @@ -/* BatchUpdateException.java -- Exception for batch oriented SQL errors - Copyright (C) 1999, 2000, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.sql; - -/** - * This class extends <code>SQLException</code> to count the successful - * updates in each statement in a batch that was successfully updated prior - * to the error. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public class BatchUpdateException extends SQLException -{ - static final long serialVersionUID = 5977529877145521757L; - - /** - * This is the array of update counts for the commands which completed - * successfully prior to the error. - */ - private int[] updateCounts; - - /** - * This method initializes a new instance of <code>BatchUpdateException</code> - * with the specified descriptive error message, SQL state, and update count - * information. The vendor specific error code will be initialized to 0. - * - * @param message The descriptive error message. - * @param SQLState The SQL state information for this error. - * @param vendorCode - * @param updateCounts The update count information for this error. - */ - public BatchUpdateException(String message, String SQLState, int vendorCode, - int[] updateCounts) - { - super(message, SQLState, vendorCode); - this.updateCounts = updateCounts; - } - - /** - * This method initializes a new instance of <code>BatchUpdateException</code> - * with the specified descriptive error message, SQL state, and update count - * information. The vendor specific error code will be initialized to 0. - * - * @param message The descriptive error message. - * @param SQLState The SQL state information for this error. - * @param updateCounts The update count information for this error. - */ - public BatchUpdateException(String message, String SQLState, - int[] updateCounts) - { - super(message, SQLState); - this.updateCounts = updateCounts; - } - - /** - * This method initializes a new instance of <code>BatchUpdateException</code> - * with the specified descriptive error message and update count information. - * The SQL state will be initialized to <code>null</code> and the vendor - * specific error code will be initialized to 0. - * - * @param message The descriptive error message. - * @param updateCounts The update count information for this error. - */ - public BatchUpdateException(String message, int[] updateCounts) - { - super(message); - this.updateCounts = updateCounts; - } - - /** - * Initializes a new instance of <code>BatchUpdateException</code> - * with the specified update count information and no descriptive error - * message. This SQL state will be initialized to <code>null</code> and - * the vendor specific error code will be initialized to 0. - * - * @param updateCounts The update count array. - */ - public BatchUpdateException(int[] updateCounts) - { - this.updateCounts = updateCounts; - } - - /** - * Initializes a new instance of <code>BatchUpdateException</code> - * with no descriptive error message. The SQL state and update count will - * be initialized to <code>null</code> and the vendor specific error code will - * initialized to 0. - */ - public BatchUpdateException() - { - super(); - } - - /** - * This method returns the update count information for this error. If - * not <code>null</code> this is an array of <code>int</code>'s that are - * the update accounts for each command that was successfully executed. - * The array elements are in the order that the commands were executed. - * - * @return The update count information, which may be <code>null</code>. - */ - public int[] getUpdateCounts() - { - return updateCounts; - } -} diff --git a/libjava/java/sql/Blob.java b/libjava/java/sql/Blob.java deleted file mode 100644 index 616839d01be..00000000000 --- a/libjava/java/sql/Blob.java +++ /dev/null @@ -1,131 +0,0 @@ -/* Blob.java -- Access a SQL Binary Large OBject. - Copyright (C) 1999, 2000, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.sql; - -import java.io.InputStream; -import java.io.OutputStream; - -/** - * This interface specified methods for accessing a SQL BLOB (Binary - * Large OBject) type. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @since 1.2 - */ -public interface Blob -{ - /** - * This method returns the number of bytes in the BLOB. - * - * @return The number of bytes in the BLOB. - * @exception SQLException If an error occurs. - */ - long length() throws SQLException; - - /** - * This method returns up to the requested bytes of this BLOB as a - * <code>byte</code> array. - * - * @param pos The index into the BLOB to start returning bytes from. - * @param length The requested number of bytes to return. - * @return The requested bytes from the BLOB. - * @exception SQLException If an error occurs. - */ - byte[] getBytes(long pos, int length) throws SQLException; - - /** - * This method returns a stream that will read the bytes of the BLOB. - * - * @return A stream that will read the bytes of the BLOB. - * @exception SQLException If an error occurs. - */ - InputStream getBinaryStream() throws SQLException; - - /** - * This method returns the index into the BLOB at which the first instance - * of the specified bytes occur. The searching starts at the specified - * index into the BLOB. - * - * @param pattern The byte pattern to search for. - * @param offset The index into the BLOB to starting searching for the pattern. - * @return The offset at which the pattern is first found, or -1 if the - * pattern is not found. - * @exception SQLException If an error occurs. - */ - long position(byte[] pattern, long start) throws SQLException; - - /** - * This method returns the index into the BLOB at which the first instance - * of the specified pattern occurs. The searching starts at the specified - * index into this BLOB. The bytes in the specified <code>Blob</code> are - * used as the search pattern. - * - * @param pattern The <code>Blob</code> containing the byte pattern to - * search for. - * @param offset The index into the BLOB to starting searching for the pattern. - * @return The offset at which the pattern is first found, or -1 if the - * pattern is not found. - * @exception SQLException If an error occurs. - */ - long position(Blob pattern, long start) throws SQLException; - - /** - * @exception SQLException If an error occurs. - * @since 1.4 - */ - int setBytes(long pos, byte[] bytes) throws SQLException; - - /** - * @exception SQLException If an error occurs. - * @since 1.4 - */ - int setBytes(long pos, byte[] bytes, int offset, int len) - throws SQLException; - - /** - * @exception SQLException If an error occurs. - * @since 1.4 - */ - OutputStream setBinaryStream(long pos) throws SQLException; - - /** - * @exception SQLException If an error occurs. - * @since 1.4 - */ - void truncate(long len) throws SQLException; -} diff --git a/libjava/java/sql/CallableStatement.java b/libjava/java/sql/CallableStatement.java deleted file mode 100644 index 452294144a0..00000000000 --- a/libjava/java/sql/CallableStatement.java +++ /dev/null @@ -1,651 +0,0 @@ -/* CallableStatement.java -- A statement for calling stored procedures. - Copyright (C) 1999, 2000, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.sql; - -import java.io.InputStream; -import java.io.Reader; -import java.math.BigDecimal; -import java.net.URL; -import java.util.Calendar; -import java.util.Map; - -/** - * This interface provides a mechanism for calling stored procedures. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public interface CallableStatement extends PreparedStatement -{ - /** - * This method registers the specified parameter as an output parameter - * of the specified SQL type. - * - * @param index The index of the parameter to register as output. - * @param type The SQL type value from <code>Types</code>. - * @exception SQLException If an error occurs. - */ - void registerOutParameter(int parameterIndex, int sqlType) - throws SQLException; - - /** - * This method registers the specified parameter as an output parameter - * of the specified SQL type and scale. - * - * @param index The index of the parameter to register as output. - * @param type The SQL type value from <code>Types</code>. - * @param scale The scale of the value that will be returned. - * @exception SQLException If an error occurs. - */ - void registerOutParameter(int parameterIndex, int sqlType, int scale) - throws SQLException; - - /** - * This method tests whether the value of the last parameter that was fetched - * was actually a SQL NULL value. - * - * @return <code>true</code> if the last parameter fetched was a NULL, - * <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean wasNull() throws SQLException; - - /** - * This method returns the value of the specified parameter as a Java - * <code>String</code>. - * - * @param index The index of the parameter to return. - * @return The parameter value as a <code>String</code>. - * @exception SQLException If an error occurs. - */ - String getString(int parameterIndex) throws SQLException; - - /** - * This method returns the value of the specified parameter as a Java - * <code>boolean</code>. - * - * @param index The index of the parameter to return. - * @return The parameter value as a <code>boolean</code>. - * @exception SQLException If an error occurs. - */ - boolean getBoolean(int parameterIndex) throws SQLException; - - /** - * This method returns the value of the specified parameter as a Java - * <code>byte</code>. - * - * @param index The index of the parameter to return. - * @return The parameter value as a <code>byte</code>. - * @exception SQLException If an error occurs. - */ - byte getByte(int parameterIndex) throws SQLException; - - /** - * This method returns the value of the specified parameter as a Java - * <code>short</code>. - * - * @param index The index of the parameter to return. - * @return The parameter value as a <code>short</code>. - * @exception SQLException If an error occurs. - */ - short getShort(int parameterIndex) throws SQLException; - - /** - * This method returns the value of the specified parameter as a Java - * <code>int</code>. - * - * @param index The index of the parameter to return. - * @return The parameter value as a <code>int</code>. - * @exception SQLException If an error occurs. - */ - int getInt(int parameterIndex) throws SQLException; - - /** - * This method returns the value of the specified parameter as a Java - * <code>long</code>. - * - * @param index The index of the parameter to return. - * @return The parameter value as a <code>long</code>. - * @exception SQLException If an error occurs. - */ - long getLong(int parameterIndex) throws SQLException; - - /** - * This method returns the value of the specified parameter as a Java - * <code>float</code>. - * - * @param index The index of the parameter to return. - * @return The parameter value as a <code>float</code>. - * @exception SQLException If an error occurs. - */ - float getFloat(int parameterIndex) throws SQLException; - - /** - * This method returns the value of the specified parameter as a Java - * <code>double</code>. - * - * @param index The index of the parameter to return. - * @return The parameter value as a <code>double</code>. - * @exception SQLException If an error occurs. - */ - double getDouble(int parameterIndex) throws SQLException; - - /** - * This method returns the value of the specified parameter as a Java - * <code>BigDecimal</code>. - * - * @param parameterIndex The index of the parameter to return. - * @param scale The number of digits to the right of the decimal to return. - * @return The parameter value as a <code>BigDecimal</code>. - * @exception SQLException If an error occurs. - * @deprecated Use getBigDecimal(int parameterIndex) - * or getBigDecimal(String parameterName) instead. - */ - BigDecimal getBigDecimal(int parameterIndex, int scale) - throws SQLException; - - /** - * This method returns the value of the specified parameter as a Java - * byte array. - * - * @param parameterIndex The index of the parameter to return. - * @return The parameter value as a byte array - * @exception SQLException If an error occurs. - */ - byte[] getBytes(int parameterIndex) throws SQLException; - - /** - * This method returns the value of the specified parameter as a Java - * <code>java.sql.Date</code>. - * - * @param index The index of the parameter to return. - * @return The parameter value as a <code>java.sql.Date</code>. - * @exception SQLException If an error occurs. - */ - Date getDate(int parameterIndex) throws SQLException; - - /** - * This method returns the value of the specified parameter as a Java - * <code>java.sql.Time</code>. - * - * @param index The index of the parameter to return. - * @return The parameter value as a <code>java.sql.Time</code>. - * @exception SQLException If an error occurs. - */ - Time getTime(int parameterIndex) throws SQLException; - - /** - * This method returns the value of the specified parameter as a Java - * <code>java.sql.Timestamp</code>. - * - * @param index The index of the parameter to return. - * @return The parameter value as a <code>java.sql.Timestamp</code>. - * @exception SQLException If an error occurs. - */ - Timestamp getTimestamp(int parameterIndex) throws SQLException; - - /** - * This method returns the value of the specified parameter as a Java - * <code>Object</code>. - * - * @param parameterIndex The index of the parameter to return. - * @return The parameter value as an <code>Object</code>. - * @exception SQLException If an error occurs. - * @since 1.2 - */ - Object getObject(int parameterIndex) throws SQLException; - - /** - * This method returns the value of the specified parameter as a Java - * <code>BigDecimal</code>. - * - * @param parameterIndex The index of the parameter to return. - * @return The parameter value as a <code>BigDecimal</code>. - * @exception SQLException If an error occurs. - * @since 1.2 - */ - BigDecimal getBigDecimal(int parameterIndex) throws SQLException; - - /** - * This method returns the value of the specified parameter as a Java - * <code>Object</code>. - * - * @param index The index of the parameter to return. - * @param map The mapping to use for conversion from SQL to Java types. - * @return The parameter value as an <code>Object</code>. - * @exception SQLException If an error occurs. - * @since 1.2 - */ - Object getObject(int index, Map map) throws SQLException; - - /** - * This method returns the value of the specified parameter as a Java - * <code>Ref</code>. - * - * @param index The index of the parameter to return. - * @return The parameter value as a <code>Ref</code>. - * @exception SQLException If an error occurs. - * @since 1.2 - */ - Ref getRef(int index) throws SQLException; - - /** - * This method returns the value of the specified parameter as a Java - * <code>Blob</code>. - * - * @param index The index of the parameter to return. - * @return The parameter value as a <code>Blob</code>. - * @exception SQLException If an error occurs. - * @since 1.2 - */ - Blob getBlob(int index) throws SQLException; - - /** - * This method returns the value of the specified parameter as a Java - * <code>Clob</code>. - * - * @param index The index of the parameter to return. - * @return The parameter value as a <code>Clob</code>. - * @exception SQLException If an error occurs. - * @since 1.2 - */ - Clob getClob(int index) throws SQLException; - - /** - * This method returns the value of the specified parameter as a Java - * <code>Array</code>. - * - * @param parameterIndex The index of the parameter to return. - * @return The parameter value as a <code>Array</code>. - * @exception SQLException If an error occurs. - * @since 1.2 - */ - Array getArray(int index) throws SQLException; - - /** - * This method returns the value of the specified parameter as a Java - * <code>java.sql.Date</code>. - * - * @param parameterIndex The index of the parameter to return. - * @param cal The <code>Calendar</code> to use for timezone and locale. - * @return The parameter value as a <code>java.sql.Date</code>. - * @exception SQLException If an error occurs. - * @since 1.2 - */ - Date getDate(int parameterIndex, Calendar cal) throws SQLException; - - /** - * This method returns the value of the specified parameter as a Java - * <code>java.sql.Time</code>. - * - * @param parameterIndex The index of the parameter to return. - * @param cal The <code>Calendar</code> to use for timezone and locale. - * @return The parameter value as a <code>java.sql.Time</code>. - * @exception SQLException If an error occurs. - * @since 1.2 - */ - Time getTime(int parameterIndex, Calendar cal) throws SQLException; - - /** - * This method returns the value of the specified parameter as a Java - * <code>java.sql.Timestamp</code>. - * - * @param index The index of the parameter to return. - * @return The parameter value as a <code>java.sql.Timestamp</code>. - * @exception SQLException If an error occurs. - * @since 1.2 - */ - Timestamp getTimestamp(int parameterIndex, Calendar cal) - throws SQLException; - - /** - * This method registers the specified parameter as an output parameter - * of the specified SQL type. - * - * @param index The index of the parameter to register as output. - * @param type The SQL type value from <code>Types</code>. - * @param name The user defined data type name. - * @exception SQLException If an error occurs. - * @since 1.2 - */ - void registerOutParameter(int paramIndex, int sqlType, - String typeName) - throws SQLException; - - /** - * This method registers the specified parameter as an output parameter - * of the specified SQL type. - * - * @param parameterName The name of the parameter to register as output. - * @param sqlType The SQL type value from <code>Types</code>. - * @exception SQLException If an error occurs. - * @since 1.4 - */ - void registerOutParameter(String parameterName, int sqlType) - throws SQLException; - - /** - * This method registers the specified parameter as an output parameter - * of the specified SQL type. This version of registerOutParameter is used - * for NUMERIC or DECIMAL types. - * - * @param parameterName The name of the parameter to register as output. - * @param sqlType The SQL type value from <code>Types</code>. - * @param scale Number of digits to the right of the decimal point. - * @exception SQLException If an error occurs. - * @since 1.4 - */ - void registerOutParameter(String parameterName, int sqlType, - int scale) - throws SQLException; - - - /** - * This method registers the specified parameter as an output parameter - * of the specified SQL type. This version of registerOutParameter is used - * for user-named or REF types. If the type of the output parameter does - * not have such a type, the typeName argument is ignored. - * - * @param parameterName The name of the parameter to register as output. - * @param sqlType The SQL type value from <code>Types</code>. - * @param typeName The SQL structured type name. - * @exception SQLException If an error occurs. - * @since 1.4 - */ - void registerOutParameter(String parameterName, int sqlType, - String typeName) - throws SQLException; - - /** - * @since 1.4 - */ - URL getURL(int parameterIndex) throws SQLException; - - /** - * @since 1.4 - */ - void setURL(String parameterName, URL val) throws SQLException; - - /** - * @since 1.4 - */ - void setNull(String parameterName, int sqlType) throws SQLException; - - /** - * @since 1.4 - */ - void setBoolean(String parameterName, boolean x) throws SQLException; - - /** - * @since 1.4 - */ - void setByte(String parameterName, byte x) throws SQLException; - - /** - * @since 1.4 - */ - void setShort(String parameterName, short x) throws SQLException; - - /** - * @since 1.4 - */ - void setInt(String parameterName, int x) throws SQLException; - - /** - * @since 1.4 - */ - void setLong(String parameterName, long x) throws SQLException; - - /** - * @since 1.4 - */ - void setFloat(String parameterName, float x) throws SQLException; - - /** - * @since 1.4 - */ - void setDouble(String parameterName, double x) throws SQLException; - - /** - * @since 1.4 - */ - void setBigDecimal(String parameterName, BigDecimal x) - throws SQLException; - - /** - * @since 1.4 - */ - void setString(String parameterName, String x) throws SQLException; - - /** - * @since 1.4 - */ - void setBytes(String parameterName, byte[] x) throws SQLException; - - /** - * @since 1.4 - */ - void setDate(String parameterName, Date x) throws SQLException; - - /** - * @since 1.4 - */ - void setTime(String parameterName, Time x) throws SQLException; - - /** - * @since 1.4 - */ - void setTimestamp(String parameterName, Timestamp x) - throws SQLException; - - /** - * @since 1.4 - */ - void setAsciiStream(String parameterName, InputStream x, int length) - throws SQLException; - - /** - * @since 1.4 - */ - void setBinaryStream(String parameterName, InputStream x, int length) - throws SQLException; - - /** - * @since 1.4 - */ - void setObject(String parameterName, Object x, int targetSqlType, - int scale) - throws SQLException; - - /** - * @since 1.4 - */ - void setObject(String parameterName, Object x, int targetSqlType) - throws SQLException; - - /** - * @since 1.4 - */ - void setObject(String parameterName, Object x) throws SQLException; - - /** - * @since 1.4 - */ - void setCharacterStream(String parameterName, Reader reader, - int length) - throws SQLException; - - /** - * @since 1.4 - */ - void setDate(String parameterName, Date x, Calendar cal) - throws SQLException; - - /** - * @since 1.4 - */ - void setTime(String parameterName, Time x, Calendar cal) - throws SQLException; - - /** - * @since 1.4 - */ - void setTimestamp(String parameterName, Timestamp x, Calendar cal) - throws SQLException; - - /** - * @since 1.4 - */ - void setNull(String parameterName, int sqlType, String typeName) - throws SQLException; - - /** - * @since 1.4 - */ - String getString(String parameterName) throws SQLException; - - /** - * @since 1.4 - */ - boolean getBoolean(String parameterName) throws SQLException; - - /** - * @since 1.4 - */ - byte getByte(String parameterName) throws SQLException; - - /** - * @since 1.4 - */ - short getShort(String parameterName) throws SQLException; - - /** - * @since 1.4 - */ - int getInt(String parameterName) throws SQLException; - - /** - * @since 1.4 - */ - long getLong(String parameterName) throws SQLException; - - /** - * @since 1.4 - */ - float getFloat(String parameterName) throws SQLException; - - /** - * @since 1.4 - */ - double getDouble(String parameterName) throws SQLException; - - /** - * @since 1.4 - */ - byte[] getBytes(String parameterName) throws SQLException; - - /** - * @since 1.4 - */ - Date getDate(String parameterName) throws SQLException; - - /** - * @since 1.4 - */ - Time getTime(String parameterName) throws SQLException; - - /** - * @since 1.4 - */ - Timestamp getTimestamp(String parameterName) throws SQLException; - - /** - * @since 1.4 - */ - Object getObject(String parameterName) throws SQLException; - - /** - * @since 1.4 - */ - BigDecimal getBigDecimal(String parameterName) throws SQLException; - - /** - * @since 1.4 - */ - Object getObject(String parameterName, Map map) throws SQLException; - - /** - * @since 1.4 - */ - Ref getRef(String parameterName) throws SQLException; - - /** - * @since 1.4 - */ - Blob getBlob(String parameterName) throws SQLException; - - /** - * @since 1.4 - */ - Clob getClob(String parameterName) throws SQLException; - - /** - * @since 1.4 - */ - Array getArray(String parameterName) throws SQLException; - - /** - * @since 1.4 - */ - Date getDate(String parameterName, Calendar cal) throws SQLException; - - /** - * @since 1.4 - */ - Time getTime(String parameterName, Calendar cal) throws SQLException; - - /** - * @since 1.4 - */ - Timestamp getTimestamp(String parameterName, Calendar cal) - throws SQLException; - - /** - * @since 1.4 - */ - URL getURL(String parameterName) throws SQLException; -} diff --git a/libjava/java/sql/Clob.java b/libjava/java/sql/Clob.java deleted file mode 100644 index 8789da5967a..00000000000 --- a/libjava/java/sql/Clob.java +++ /dev/null @@ -1,152 +0,0 @@ -/* Clob.java -- Access Character Large OBjects - Copyright (C) 1999, 2000, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.sql; - -import java.io.InputStream; -import java.io.OutputStream; -import java.io.Reader; -import java.io.Writer; - -/** - * This interface contains methods for accessing a SQL CLOB (Character - * Large OBject) type. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public interface Clob -{ - /** - * This method returns the number of characters in the CLOB. - * - * @return The number of characters in the CLOB. - * @exception SQLException If an error occurs. - * @since 1.2 - */ - long length() throws SQLException; - - /** - * This method returns the specified portion of the CLOB as a - * <code>String</code>. - * - * @param offset The index into the CLOB (index values start at 1) to - * start returning characters from. - * @param length The requested number of characters to return. - * @return The requested CLOB section, as a <code>String</code>. - * @exception SQLException If an error occurs. - * @since 1.2 - */ - String getSubString(long pos, int length) throws SQLException; - - /** - * This method returns a character stream that reads the contents of the - * CLOB. - * - * @return A character stream to read the CLOB's contents. - * @exception SQLException If an error occurs. - * @since 1.2 - */ - Reader getCharacterStream() throws SQLException; - - /** - * This method returns a byte stream that reads the contents of the - * CLOB as a series of ASCII bytes. - * - * @return A stream to read the CLOB's contents. - * @exception SQLException If an error occurs. - * @since 1.2 - */ - InputStream getAsciiStream() throws SQLException; - - /** - * This method returns the index into the CLOB of the first occurrence of - * the specified character pattern (supplied by the caller as a - * <code>String</code>). The search begins at the specified index. - * - * @param searchstr The character pattern to search for, passed as a - * <code>String</code>. - * @param start. The index into the CLOB to start search (indexes start - * at 1). - * @return The index at which the pattern was found (indexes start at 1), - * or -1 if the pattern was not found. - * @exception SQLException If an error occurs. - * @since 1.2 - */ - long position(String searchstr, long start) throws SQLException; - - /** - * This method returns the index into the CLOB of the first occurrence of - * the specified character pattern (supplied by the caller as a - * <code>Clob</code>). The search begins at the specified index. - * - * @param searchstr The character pattern to search for, passed as a - * <code>Clob</code>. - * @param start. The index into the CLOB to start search (indexes start - * at 1). - * @return The index at which the pattern was found (indexes start at 1), - * or -1 if the pattern was not found. - * @exception SQLException If an error occurs. - * @since 1.2 - */ - long position(Clob searchstr, long start) throws SQLException; - - /** - * @since 1.4 - */ - int setString(long pos, String str) throws SQLException; - - /** - * @since 1.4 - */ - int setString(long pos, String str, int offset, int len) - throws SQLException; - - /** - * @since 1.4 - */ - OutputStream setAsciiStream(long pos) throws SQLException; - - /** - * @since 1.4 - */ - Writer setCharacterStream(long pos) throws SQLException; - - /** - * @since 1.4 - */ - void truncate(long len) throws SQLException; -} diff --git a/libjava/java/sql/Connection.java b/libjava/java/sql/Connection.java deleted file mode 100644 index 48ec12dd09f..00000000000 --- a/libjava/java/sql/Connection.java +++ /dev/null @@ -1,420 +0,0 @@ -/* Connection.java -- Manage a database connection. - Copyright (C) 1999, 2000, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.sql; - -import java.util.Map; - -/** - * This interface provides methods for managing a connection to a database. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public interface Connection -{ - /** - * This transaction isolation level indicates that transactions are not - * supported. - */ - int TRANSACTION_NONE = 0; - - /** - * This transaction isolation level indicates that one transaction can - * read modifications by other transactions before the other transactions - * have committed their changes. This could result in invalid reads. - */ - int TRANSACTION_READ_UNCOMMITTED = 1; - - /** - * This transaction isolation leve indicates that only committed data from - * other transactions will be read. If a transaction reads a row, then - * another transaction commits a change to that row, the first transaction - * would retrieve the changed row on subsequent reads of the same row. - */ - int TRANSACTION_READ_COMMITTED = 2; - - /** - * This transaction isolation level indicates that only committed data from - * other transactions will be read. It also ensures that data read from - * a row will not be different on a subsequent read even if another - * transaction commits a change. - */ - int TRANSACTION_REPEATABLE_READ = 4; - - /** - * This transaction isolation level indicates that only committed data from - * other transactions will be read. It also ensures that data read from - * a row will not be different on a subsequent read even if another - * transaction commits a change. Additionally, rows modified by other - * transactions will not affect the result set returned during subsequent - * executions of the same WHERE clause in this transaction. - */ - int TRANSACTION_SERIALIZABLE = 8; - - /** - * This method creates a new SQL statement. The default result set type - * and concurrency will be used. - * - * @return A new <code>Statement</code> object. - * @exception SQLException If an error occurs. - * @see Statement - */ - Statement createStatement() throws SQLException; - - /** - * This method creates a new <code>PreparedStatement</code> for the specified - * SQL string. This method is designed for use with parameterized - * statements. The default result set type and concurrency will be used. - * - * @param The SQL statement to use in creating this - * <code>PreparedStatement</code>. - * @return A new <code>PreparedStatement</code>. - * @exception SQLException If an error occurs. - * @see PreparedStatement - */ - PreparedStatement prepareStatement(String sql) throws SQLException; - - /** - * This method creates a new <code>CallableStatement</code> for the - * specified SQL string. Thie method is designed to be used with - * stored procedures. The default result set type and concurrency - * will be used. - * - * @param The SQL statement to use in creating this - * <code>CallableStatement</code>. - * @return A new <code>CallableStatement</code>. - * @exception SQLException If an error occurs. - * @see CallableStatement - */ - CallableStatement prepareCall(String sql) throws SQLException; - - /** - * This method converts the specified generic SQL statement into the - * native grammer of the database this object is connected to. - * - * @param The JDBC generic SQL statement. - * @return The native SQL statement. - * @exception SQLException If an error occurs. - */ - String nativeSQL(String sql) throws SQLException; - - /** - * This method turns auto commit mode on or off. In auto commit mode, - * every SQL statement is committed its own transaction. Otherwise a - * transaction must be explicitly committed or rolled back. - * - * @param autoCommit <code>true</code> to enable auto commit mode, - * <code>false</code> to disable it. - * @exception SQLException If an error occurs. - * @see commit - * @see rollback - */ - void setAutoCommit(boolean autoCommit) throws SQLException; - - /** - * This method tests whether or not auto commit mode is currently enabled. - * In auto commit mode, every SQL statement is committed its own transaction. - * Otherwise a transaction must be explicitly committed or rolled back. - * - * @return <code>true</code> if auto commit mode is enabled, - * <code>false</code> otherwise. - * - * @exception SQLException If an error occurs. - * - * @see commit - * @see rollback - */ - boolean getAutoCommit() throws SQLException; - - /** - * This method commits any SQL statements executed on this connection since - * the last commit or rollback. - * - * @exception SQLException If an error occurs. - */ - void commit() throws SQLException; - - /** - * This method rolls back any SQL statements executed on this connection - * since the last commit or rollback. - * - * @exception SQLException If an error occurs. - */ - void rollback() throws SQLException; - - /** - * This method immediately closes this database connection. - * - * @exception SQLException If an error occurs. - */ - void close() throws SQLException; - - /** - * This method tests whether or not this connection has been closed. - * - * @return <code>true</code> if the connection is closed, <code>false</code> - * otherwise. - * @exception SQLException If an error occurs. - */ - boolean isClosed() throws SQLException; - - /** - * This method returns the meta data for this database connection. - * - * @return The meta data for this database. - * @exception SQLException If an error occurs. - * @see DatabaseMetaData - */ - DatabaseMetaData getMetaData() throws SQLException; - - /** - * This method turns read only mode on or off. It may not be called while - * a transaction is in progress. - * - * @param readOnly <code>true</code> if this connection is read only, - * <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - void setReadOnly(boolean readOnly) throws SQLException; - - /** - * This method tests whether or not this connection is in read only mode. - * - * @return <code>true</code> if the connection is read only <code>false</code> - * otherwise. - * @exception SQLException If an error occurs. - */ - boolean isReadOnly() throws SQLException; - - /** - * This method sets the name of the catalog in use by this connection. - * Note that this method does nothing if catalogs are not supported by - * this database. - * - * @param catalog The name of the catalog to use for this connection. - * @exception SQLException If an error occurs. - */ - void setCatalog(String catalog) throws SQLException; - - /** - * This method returns the name of the catalog in use by this connection, - * if any. - * - * @return The name of the catalog, or <code>null</code> if one does not - * exist or catalogs are not supported by this database. - * @exception SQLException If an error occurs. - */ - String getCatalog() throws SQLException; - - /** - * This method sets the current transaction isolation mode. This must - * be one of the constants defined in this interface. - * - * @param level The transaction isolation level. - * @exception SQLException If an error occurs. - */ - void setTransactionIsolation(int level) throws SQLException; - - /** - * This method returns the current transaction isolation mode. This will - * be one of the constants defined in this interface. - * - * @return The transaction isolation level. - * @exception SQLException If an error occurs. - */ - int getTransactionIsolation() throws SQLException; - - /** - * This method returns the first warning that occurred on this connection, - * if any. If there were any subsequence warnings, they will be chained - * to the first one. - * - * @return The first <code>SQLWarning</code> that occurred, or - * <code>null</code> if there have been no warnings. - * @exception SQLException If an error occurs. - */ - SQLWarning getWarnings() throws SQLException; - - /** - * This method clears all warnings that have occurred on this connection. - * - * @exception SQLException If an error occurs. - */ - void clearWarnings() throws SQLException; - - /** - * This method creates a new SQL statement with the specified type and - * concurrency. Valid values for these parameters are specified in the - * <code>ResultSet</code> class. - * - * @param resultSetType The type of result set to use for this statement. - * @param resultSetConcurrency. The type of concurrency to be used in - * the result set for this statement. - * @return A new <code>Statement</code> object. - * @exception SQLException If an error occurs. - * @see Statement - * @see ResultSet - */ - Statement createStatement(int resultSetType, int resultSetConcurrency) - throws SQLException; - - /** - * This method creates a new <code>PreparedStatement</code> for the specified - * SQL string. This method is designed for use with parameterized - * statements. The specified result set type and concurrency will be used. - * Valid values for these parameters are specified in the - * <code>ResultSet</code> class. - * - * @param The SQL statement to use in creating this - * <code>PreparedStatement</code>. - * @param resultSetType The type of result set to use for this statement. - * @param resultSetConcurrency. The type of concurrency to be used in - * the result set for this statement. - * @return A new <code>PreparedStatement</code>. - * @exception SQLException If an error occurs. - * @see PreparedStatement - * @see ResultSet - */ - PreparedStatement prepareStatement(String sql, int resultSetType, - int resultSetConcurrency) throws SQLException; - - /** - * This method creates a new <code>CallableStatement</code> for the - * specified SQL string. Thie method is designed to be used with - * stored procedures. The specified result set type and concurrency - * will be used. Valid values for these parameters are specified in the - * <code>ResultSet</code> class. - * - * @param The SQL statement to use in creating this - * <code>PreparedStatement</code>. - * @param resultSetType The type of result set to use for this statement. - * @param resultSetConcurrency. The type of concurrency to be used in - * the result set for this statement. - * @return A new <code>CallableStatement</code>. - * @exception SQLException If an error occurs. - * @see CallableStatement - * @see ResultSet - */ - CallableStatement prepareCall(String sql, int resultSetType, int - resultSetConcurrency) throws SQLException; - - /** - * This method returns the mapping of SQL types to Java classes - * currently in use by this connection. This mapping will have no - * entries unless they have been manually added. - * - * @return The SQL type to Java class mapping. - * @exception SQLException If an error occurs. - */ - Map getTypeMap() throws SQLException; - - /** - * This method sets the mapping table for SQL types to Java classes. - * Any entries in this map override the defaults. - * - * @param map The new SQL mapping table. - * @exception SQLException If an error occurs. - */ - void setTypeMap(Map map) throws SQLException; - - /** - * @since 1.4 - */ - void setHoldability(int holdability) throws SQLException; - - /** - * @since 1.4 - */ - int getHoldability() throws SQLException; - - /** - * @since 1.4 - */ - Savepoint setSavepoint() throws SQLException; - - /** - * @since 1.4 - */ - Savepoint setSavepoint(String name) throws SQLException; - - /** - * @since 1.4 - */ - void rollback(Savepoint savepoint) throws SQLException; - - /** - * @since 1.4 - */ - void releaseSavepoint(Savepoint savepoint) throws SQLException; - - /** - * @since 1.4 - */ - Statement createStatement(int resultSetType, int - resultSetConcurrency, int resultSetHoldability) throws SQLException; - - /** - * @since 1.4 - */ - PreparedStatement prepareStatement(String sql, int resultSetType, int - resultSetConcurrency, int resultSetHoldability) throws SQLException; - - /** - * @since 1.4 - */ - CallableStatement prepareCall(String sql, int resultSetType, int - resultSetConcurrency, int resultSetHoldability) throws SQLException; - - /** - * @since 1.4 - */ - PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) - throws SQLException; - - /** - * @since 1.4 - */ - PreparedStatement prepareStatement(String sql, int[] columnIndexes) - throws SQLException; - - /** - * @since 1.4 - */ - PreparedStatement prepareStatement(String sql, String[] columnNames) - throws SQLException; -} diff --git a/libjava/java/sql/DataTruncation.java b/libjava/java/sql/DataTruncation.java deleted file mode 100644 index ec522c0251c..00000000000 --- a/libjava/java/sql/DataTruncation.java +++ /dev/null @@ -1,157 +0,0 @@ -/* DataTruncation.java -- Warning when data has been truncated. - Copyright (C) 1999, 2000, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.sql; - -/** - * This exception is thrown when a piece of data is unexpectedly - * truncated in JDBC. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public class DataTruncation extends SQLWarning -{ - static final long serialVersionUID = 6464298989504059473L; - - /** - * The original size of the data. - */ - private int dataSize; - - /** - * The index of the parameter or column whose value was truncated. - */ - private int index; - - /** - * Indicates whether or not a parameter value was truncated. - */ - private boolean parameter; - - /** - * Indicates whether or not a data column value was truncated. - */ - private boolean read; - - /** - * This is the size of the data after truncation. - */ - private int transferSize; - - /** - * This method initializes a new instance of <code>DataTruncation</code> - * with the specified values. The descriptive error message for this - * exception will be "Data truncation", the SQL state will be "01004" - * and the vendor specific error code will be set to 0. - * - * @param index The index of the parameter or column that was truncated. - * @param parameter <code>true</code> if a parameter was truncated, - * <code>false</code> otherwise. - * @param read <code>true</code> if a data column was truncated, - * <code>false</code> otherwise. - * @param dataSize The original size of the data. - * @param transferSize The size of the data after truncation. - */ - public DataTruncation(int index, boolean parameter, boolean read, int - dataSize, int transferSize) - { - super("Data truncation", "01004"); - - this.index = index; - this.parameter = parameter; - this.read = read; - this.dataSize = dataSize; - this.transferSize = transferSize; - } - - /** - * This method returns the index of the column or parameter that was - * truncated. - * - * @return The index of the column or parameter that was truncated. - */ - public int getIndex() - { - return index; - } - - /** - * This method determines whether or not it was a parameter that was - * truncated. - * - * @return <code>true</code> if a parameter was truncated, <code>false</code> - * otherwise. - */ - public boolean getParameter() - { - return parameter; - } - - /** - * This method determines whether or not it was a column that was - * truncated. - * - * @return <code>true</code> if a column was truncated, <code>false</code> - * otherwise. - */ - public boolean getRead() - { - return read; - } - - /** - * This method returns the original size of the parameter or column that - * was truncated. - * - * @return The original size of the parameter or column that was truncated. - */ - public int getDataSize() - { - return dataSize; - } - - /** - * This method returns the size of the parameter or column after it was - * truncated. - * - * @return The size of the parameter or column after it was truncated. - */ - public int getTransferSize() - { - return transferSize; - } -} diff --git a/libjava/java/sql/DatabaseMetaData.java b/libjava/java/sql/DatabaseMetaData.java deleted file mode 100644 index d34c4e2f927..00000000000 --- a/libjava/java/sql/DatabaseMetaData.java +++ /dev/null @@ -1,2214 +0,0 @@ -/* DatabaseMetaData.java -- Information about the database itself. - Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.sql; - -public interface DatabaseMetaData -{ - /** - * It is unknown whether or not the procedure returns a result. - */ - int procedureResultUnknown = 0; - - /** - * The procedure does not return a result. - */ - int procedureNoResult = 1; - - /** - * The procedure returns a result. - */ - int procedureReturnsResult = 2; - - /** - * The column type is unknown. - */ - int procedureColumnUnknown = 0; - - /** - * The column type is input. - */ - int procedureColumnIn = 1; - - /** - * The column type is input/output. - */ - int procedureColumnInOut = 2; - - /** - * The column type is output - */ - int procedureColumnOut = 4; - - /** - * The column is used for return values. - */ - int procedureColumnReturn = 5; - - /** - * The column is used for storing results - */ - int procedureColumnResult = 3; - - /** - * NULL values are not allowed. - */ - int procedureNoNulls = 0; - - /** - * NULL values are allowed. - */ - int procedureNullable = 1; - - /** - * It is unknown whether or not NULL values are allowed. - */ - int procedureNullableUnknown = 2; - - /** - * The column does not allow NULL - */ - int columnNoNulls = 0; - - /** - * The column does allow NULL - */ - int columnNullable = 1; - - /** - * It is unknown whether or not the column allows NULL - */ - int columnNullableUnknown = 2; - - /** - * The best row's scope is only guaranteed to be valid so long as the - * row is actually being used. - */ - int bestRowTemporary = 0; - - /** - * The best row identifier is valid to the end of the transaction. - */ - int bestRowTransaction = 1; - - /** - * The best row identifier is valid to the end of the session. - */ - int bestRowSession = 2; - - /** - * The best row may or may not be a pseudo-column. - */ - int bestRowUnknown = 0; - - /** - * The best row identifier is not a pseudo-column. - */ - int bestRowNotPseudo = 1; - - /** - * The best row identifier is a pseudo-column. - */ - int bestRowPseudo = 2; - - /** - * It is unknown whether or not the version column is a pseudo-column. - */ - int versionColumnUnknown = 0; - - /** - * The version column is not a pseudo-column - */ - int versionColumnNotPseudo = 1; - - /** - * The version column is a pseudo-column - */ - int versionColumnPseudo = 2; - - /** - * Foreign key changes are cascaded in updates or deletes. - */ - int importedKeyCascade = 0; - - /** - * Column may not be updated or deleted in use as a foreign key. - */ - int importedKeyRestrict = 1; - - /** - * When primary key is updated or deleted, the foreign key is set to NULL. - */ - int importedKeySetNull = 2; - - /** - * If the primary key is a foreign key, it cannot be udpated or deleted. - */ - int importedKeyNoAction = 3; - - /** - * If the primary key is updated or deleted, the foreign key is set to - * a default value. - */ - int importedKeySetDefault = 4; - - /** - * Wish I knew what this meant. - */ - int importedKeyInitiallyDeferred = 5; - - /** - * Wish I knew what this meant. - */ - int importedKeyInitiallyImmediate = 6; - - /** - * Wish I knew what this meant. - */ - int importedKeyNotDeferrable = 7; - - /** - * A NULL value is not allowed for this data type. - */ - int typeNoNulls = 0; - - /** - * A NULL value is allowed for this data type. - */ - int typeNullable = 1; - - /** - * It is unknown whether or not NULL values are allowed for this data type. - */ - int typeNullableUnknown = 2; - - /** - * Where clauses are not supported for this type. - */ - int typePredNone = 0; - - /** - * Only "WHERE..LIKE" style WHERE clauses are allowed on this data type. - */ - int typePredChar = 1; - - /** - * All WHERE clauses except "WHERE..LIKE" style are allowed on this data type. - */ - int typePredBasic = 2; - - /** - * Any type of WHERE clause is allowed for this data type. - */ - int typeSearchable = 3; - - /** - * This column contains table statistics. - */ - short tableIndexStatistic = 0; - - /** - * This table index is clustered. - */ - short tableIndexClustered = 1; - - /** - * This table index is hashed. - */ - short tableIndexHashed = 2; - - /** - * This table index is of another type. - */ - short tableIndexOther = 3; - - short attributeNoNulls = 0; - - short attributeNullable = 1; - - short attributeNullableUnknown = 2; - - int sqlStateXOpen = 1; - - int sqlStateSQL99 = 2; - - /** - * This method tests whether or not all the procedures returned by - * the <code>getProcedures</code> method can be called by this user. - * - * @return <code>true</code> if all the procedures can be called, - * <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean allProceduresAreCallable() throws SQLException; - - /** - * This method tests whether or not all the table returned by the - * <code>getTables</code> method can be selected by this user. - * - * @return <code>true</code> if all the procedures can be called, - * <code>false</code> otherwise. - * - * @exception SQLException If an error occurs. - */ - boolean allTablesAreSelectable() throws SQLException; - - /** - * This method returns the URL for this database. - * - * @return The URL string for this database, or <code>null</code> if it - * is not known. - * @exception SQLException If an error occurs. - */ - String getURL() throws SQLException; - - /** - * This method returns the database username for this connection. - * - * @return The database username. - * @exception SQLException If an error occurs. - */ - String getUserName() throws SQLException; - - /** - * This method tests whether or not the database is in read only mode. - * - * @return <code>true</code> if the database is in read only mode, - * <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean isReadOnly() throws SQLException; - - /** - * This method tests whether or not NULL's sort as high values. - * - * @return <code>true</code> if NULL's sort as high values, <code>false</code> - * otherwise. - * @exception SQLException If an error occurs. - */ - boolean nullsAreSortedHigh() throws SQLException; - - /** - * This method tests whether or not NULL's sort as low values. - * - * @return <code>true</code> if NULL's sort as low values, <code>false</code> - * otherwise. - * @exception SQLException If an error occurs. - */ - boolean nullsAreSortedLow() throws SQLException; - - /** - * This method tests whether or not NULL's sort as high values. - * - * @return <code>true</code> if NULL's sort as high values, <code>false</code> - * otherwise. - * @exception SQLException If an error occurs. - */ - boolean nullsAreSortedAtStart() throws SQLException; - - /** - * This method test whether or not NULL's are sorted to the end - * of the list regardless of ascending or descending sort order. - * - * @return <code>true</code> if NULL's always sort to the end, - * <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean nullsAreSortedAtEnd() throws SQLException; - - /** - * This method returns the name of the database product. - * - * @return The database product. - * @exception SQLException If an error occurs. - */ - String getDatabaseProductName() throws SQLException; - - /** - * This method returns the version of the database product. - * - * @return The version of the database product. - * @exception SQLException If an error occurs. - */ - String getDatabaseProductVersion() throws SQLException; - - /** - * This method returns the name of the JDBC driver. - * - * @return The name of the JDBC driver. - * @exception SQLException If an error occurs. - */ - String getDriverName() throws SQLException; - - /** - * This method returns the version of the JDBC driver. - * - * @return The version of the JDBC driver. - * @exception SQLException If an error occurs. - */ - String getDriverVersion() throws SQLException; - - /** - * This method returns the major version number of the JDBC driver. - * - * @return The major version number of the JDBC driver. - */ - int getDriverMajorVersion(); - - /** - * This method returns the minor version number of the JDBC driver. - * - * @return The minor version number of the JDBC driver. - */ - int getDriverMinorVersion(); - - /** - * This method tests whether or not the database uses local files to - * store tables. - * - * @return <code>true</code> if the database uses local files, - * <code>false</code> otherwise. - * - * @exception SQLException If an error occurs. - */ - boolean usesLocalFiles() throws SQLException; - - /** - * This method tests whether or not the database uses a separate file for - * each table. - * - * @return <code>true</code> if the database uses a separate file for each - * table <code>false</code> otherwise. - * - * @exception SQLException If an error occurs. - */ - boolean usesLocalFilePerTable() throws SQLException; - - /** - * This method tests whether or not the database supports identifiers - * with mixed case. - * - * @return <code>true</code> if the database supports mixed case identifiers, - * <code>false</code> otherwise. - * - * @exception SQLException If an error occurs. - */ - boolean supportsMixedCaseIdentifiers() throws SQLException; - - /** - * This method tests whether or not the database treats mixed case - * identifiers as all upper case. - * - * @return <code>true</code> if the database treats all identifiers as - * upper case, <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean storesUpperCaseIdentifiers() throws SQLException; - - /** - * This method tests whether or not the database treats mixed case - * identifiers as all lower case. - * - * @return <code>true</code> if the database treats all identifiers as - * lower case, <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean storesLowerCaseIdentifiers() throws SQLException; - - /** - * This method tests whether or not the database stores mixed case - * identifers even if it treats them as case insensitive. - * - * @return <code>true</code> if the database stores mixed case identifiers, - * <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean storesMixedCaseIdentifiers() throws SQLException; - - /** - * This method tests whether or not the database supports quoted identifiers - * with mixed case. - * - * @return <code>true</code> if the database supports mixed case quoted - * identifiers, <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean supportsMixedCaseQuotedIdentifiers() throws SQLException; - - /** - * This method tests whether or not the database treats mixed case - * quoted identifiers as all upper case. - * - * @return <code>true</code> if the database treats all quoted identifiers - * as upper case, <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean storesUpperCaseQuotedIdentifiers() throws SQLException; - - /** - * This method tests whether or not the database treats mixed case - * quoted identifiers as all lower case. - * - * @return <code>true</code> if the database treats all quoted identifiers - * as lower case, <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean storesLowerCaseQuotedIdentifiers() throws SQLException; - - /** - * This method tests whether or not the database stores mixed case - * quoted identifers even if it treats them as case insensitive. - * - * @return <code>true</code> if the database stores mixed case quoted - * identifiers, <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean storesMixedCaseQuotedIdentifiers() throws SQLException; - - /** - * This metohd returns the quote string for SQL identifiers. - * - * @return The quote string for SQL identifers, or a space if quoting - * is not supported. - * @exception SQLException If an error occurs. - */ - String getIdentifierQuoteString() throws SQLException; - - /** - * This method returns a comma separated list of all the SQL keywords in - * the database that are not in SQL92. - * - * @return The list of SQL keywords not in SQL92. - * @exception SQLException If an error occurs. - */ - String getSQLKeywords() throws SQLException; - - /** - * This method returns a comma separated list of math functions. - * - * @return The list of math functions. - * @exception SQLException If an error occurs. - */ - String getNumericFunctions() throws SQLException; - - /** - * This method returns a comma separated list of string functions. - * - * @return The list of string functions. - * @exception SQLException If an error occurs. - */ - String getStringFunctions() throws SQLException; - - /** - * This method returns a comma separated list of of system functions. - * - * @return A comma separated list of system functions. - * @exception SQLException If an error occurs. - */ - String getSystemFunctions() throws SQLException; - - /** - * This method returns comma separated list of time/date functions. - * - * @return The list of time/date functions. - * @exception SQLException If an error occurs. - */ - String getTimeDateFunctions() throws SQLException; - - /** - * This method returns the string used to escape wildcards in search strings. - * - * @return The string used to escape wildcards in search strings. - * @exception SQLException If an error occurs. - */ - String getSearchStringEscape() throws SQLException; - - /** - * This methods returns non-standard characters that can appear in - * unquoted identifiers. - * - * @return Non-standard characters that can appear in unquoted identifiers. - * @exception SQLException If an error occurs. - */ - String getExtraNameCharacters() throws SQLException; - - /** - * This method tests whether or not the database supports - * "ALTER TABLE ADD COLUMN" - * - * @return <code>true</code> if column add supported, <code>false</code> - * otherwise. - * @exception SQLException If an error occurs. - */ - boolean supportsAlterTableWithAddColumn() throws SQLException; - - /** - * This method tests whether or not the database supports - * "ALTER TABLE DROP COLUMN" - * - * @return <code>true</code> if column drop supported, <code>false</code> - * otherwise. - * @exception SQLException If an error occurs. - */ - boolean supportsAlterTableWithDropColumn() throws SQLException; - - /** - * This method tests whether or not column aliasing is supported. - * - * @return <code>true</code> if column aliasing is supported, - * <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean supportsColumnAliasing() throws SQLException; - - /** - * This method tests whether the concatenation of a NULL and non-NULL - * value results in a NULL. This will always be true in fully JDBC compliant - * drivers. - * - * @return <code>true</code> if concatenating NULL and a non-NULL value - * returns a NULL, <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean nullPlusNonNullIsNull() throws SQLException; - - /** - * Tests whether or not CONVERT is supported. - * - * @return <code>true</code> if CONVERT is supported, <code>false</code> - * otherwise. - * @exception SQLException If an error occurs. - */ - boolean supportsConvert() throws SQLException; - - /** - * This method tests whether or not CONVERT can be performed between the - * specified types. The types are contants from <code>Types</code>. - * - * @param fromType The SQL type to convert from. - * @param toType The SQL type to convert to. - * @return <code>true</code> if the conversion can be performed, - * <code>false</code> otherwise. - * @see Types - */ - boolean supportsConvert(int fromType, int toType) throws - SQLException; - - /** - * This method tests whether or not table correlation names are - * supported. This will be always be <code>true</code> in a fully JDBC - * compliant driver. - * - * @return <code>true</code> if table correlation names are supported, - * <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean supportsTableCorrelationNames() throws SQLException; - - /** - * This method tests whether correlation names must be different from the - * name of the table. - * - * @return <code>true</code> if the correlation name must be different from - * the table name, <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean supportsDifferentTableCorrelationNames() throws SQLException; - - /** - * This method tests whether or not expressions are allowed in an - * ORDER BY lists. - * - * @return <code>true</code> if expressions are allowed in ORDER BY - * lists, <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean supportsExpressionsInOrderBy() throws SQLException; - - /** - * This method tests whether or ORDER BY on a non-selected column is - * allowed. - * - * @return <code>true</code> if a non-selected column can be used in an - * ORDER BY, <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean supportsOrderByUnrelated() throws SQLException; - - /** - * This method tests whether or not GROUP BY is supported. - * - * @return <code>true</code> if GROUP BY is supported, <code>false</code> - * otherwise. - * @exception SQLException If an error occurs. - */ - boolean supportsGroupBy() throws SQLException; - - /** - * This method tests whether GROUP BY on a non-selected column is - * allowed. - * - * @return <code>true</code> if a non-selected column can be used in a - * GROUP BY, <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean supportsGroupByUnrelated() throws SQLException; - - /** - * This method tests whether or not a GROUP BY can add columns not in the - * select if it includes all the columns in the select. - * - * @return <code>true</code> if GROUP BY an add columns provided it includes - * all columns in the select, <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean supportsGroupByBeyondSelect() throws SQLException; - - /** - * This method tests whether or not the escape character is supported in - * LIKE expressions. A fully JDBC compliant driver will always return - * <code>true</code>. - * - * @return <code>true</code> if escapes are supported in LIKE expressions, - * <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean supportsLikeEscapeClause() throws SQLException; - - /** - * This method tests whether multiple result sets for a single statement are - * supported. - * - * @return <code>true</code> if multiple result sets are supported for a - * single statement, <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean supportsMultipleResultSets() throws SQLException; - - /** - * This method test whether or not multiple transactions may be open - * at once, as long as they are on different connections. - * - * @return <code>true</code> if multiple transactions on different - * connections are supported, <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean supportsMultipleTransactions() throws SQLException; - - /** - * This method tests whether or not columns can be defined as NOT NULL. A - * fully JDBC compliant driver always returns <code>true</code>. - * - * @return <code>true</code> if NOT NULL columns are supported, - * <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean supportsNonNullableColumns() throws SQLException; - - /** - * This method tests whether or not the minimum grammer for ODBC is supported. - * A fully JDBC compliant driver will always return <code>true</code>. - * - * @return <code>true</code> if the ODBC minimum grammar is supported, - * <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean supportsMinimumSQLGrammar() throws SQLException; - - /** - * This method tests whether or not the core grammer for ODBC is supported. - * - * @return <code>true</code> if the ODBC core grammar is supported, - * <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean supportsCoreSQLGrammar() throws SQLException; - - /** - * This method tests whether or not the extended grammer for ODBC is supported. - * - * @return <code>true</code> if the ODBC extended grammar is supported, - * <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean supportsExtendedSQLGrammar() throws SQLException; - - /** - * This method tests whether or not the ANSI92 entry level SQL - * grammar is supported. A fully JDBC compliant drivers must return - * <code>true</code>. - * - * @return <code>true</code> if the ANSI92 entry level SQL grammar is - * supported, <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean supportsANSI92EntryLevelSQL() throws SQLException; - - /** - * This method tests whether or not the ANSI92 intermediate SQL - * grammar is supported. - * - * @return <code>true</code> if the ANSI92 intermediate SQL grammar is - * supported, <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean supportsANSI92IntermediateSQL() throws SQLException; - - /** - * This method tests whether or not the ANSI92 full SQL - * grammar is supported. - * - * @return <code>true</code> if the ANSI92 full SQL grammar is - * supported, <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean supportsANSI92FullSQL() throws SQLException; - - /** - * This method tests whether or not the SQL integrity enhancement - * facility is supported. - * - * @return <code>true</code> if the integrity enhancement facility is - * supported, <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean supportsIntegrityEnhancementFacility() throws SQLException; - - /** - * This method tests whether or not the database supports outer joins. - * - * @return <code>true</code> if outer joins are supported, <code>false</code> - * otherwise. - * @exception SQLException If an error occurs. - */ - boolean supportsOuterJoins() throws SQLException; - - /** - * This method tests whether or not the database supports full outer joins. - * - * @return <code>true</code> if full outer joins are supported, - * <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean supportsFullOuterJoins() throws SQLException; - - /** - * This method tests whether or not the database supports limited outer joins. - * - * @return <code>true</code> if limited outer joins are supported, - * <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean supportsLimitedOuterJoins() throws SQLException; - - /** - * This method returns the vendor's term for "schema". - * - * @return The vendor's term for schema. - * @exception SQLException if an error occurs. - */ - String getSchemaTerm() throws SQLException; - - /** - * This method returns the vendor's term for "procedure". - * - * @return The vendor's term for procedure. - * @exception SQLException if an error occurs. - */ - String getProcedureTerm() throws SQLException; - - /** - * This method returns the vendor's term for "catalog". - * - * @return The vendor's term for catalog. - * @exception SQLException if an error occurs. - */ - String getCatalogTerm() throws SQLException; - - /** - * This method tests whether a catalog name appears at the beginning of - * a fully qualified table name. - * - * @return <code>true</code> if the catalog name appears at the beginning, - * <code>false</code> if it appears at the end. - * @exception SQLException If an error occurs. - */ - boolean isCatalogAtStart() throws SQLException; - - /** - * This method returns the separator between the catalog name and the - * table name. - * - * @return The separator between the catalog name and the table name. - * @exception SQLException If an error occurs. - */ - String getCatalogSeparator() throws SQLException; - - /** - * This method tests whether a catalog name can appear in a data - * manipulation statement. - * - * @return <code>true</code> if a catalog name can appear in a data - * manipulation statement, <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean supportsSchemasInDataManipulation() throws SQLException; - - /** - * This method tests whether a catalog name can appear in a procedure - * call - * - * @return <code>true</code> if a catalog name can appear in a procedure - * call, <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean supportsSchemasInProcedureCalls() throws SQLException; - - /** - * This method tests whether a catalog name can appear in a table definition. - * - * @return <code>true</code> if a catalog name can appear in a table - * definition, <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean supportsSchemasInTableDefinitions() throws SQLException; - - /** - * This method tests whether a catalog name can appear in an index definition. - * - * @return <code>true</code> if a catalog name can appear in an index - * definition, <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean supportsSchemasInIndexDefinitions() throws SQLException; - - /** - * This method tests whether a catalog name can appear in privilege definitions. - * - * @return <code>true</code> if a catalog name can appear in privilege - * definition, <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean supportsSchemasInPrivilegeDefinitions() throws SQLException; - - /** - * This method tests whether a catalog name can appear in a data - * manipulation statement. - * - * @return <code>true</code> if a catalog name can appear in a data - * manipulation statement, <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean supportsCatalogsInDataManipulation() throws SQLException; - - /** - * This method tests whether a catalog name can appear in a procedure - * call - * - * @return <code>true</code> if a catalog name can appear in a procedure - * call, <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean supportsCatalogsInProcedureCalls() throws SQLException; - - /** - * This method tests whether a catalog name can appear in a table definition. - * - * @return <code>true</code> if a catalog name can appear in a table - * definition, <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean supportsCatalogsInTableDefinitions() throws SQLException; - - /** - * This method tests whether a catalog name can appear in an index definition. - * - * @return <code>true</code> if a catalog name can appear in an index - * definition, <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean supportsCatalogsInIndexDefinitions() throws SQLException; - - /** - * This method tests whether a catalog name can appear in privilege definitions. - * - * @return <code>true</code> if a catalog name can appear in privilege - * definition, <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean supportsCatalogsInPrivilegeDefinitions() throws SQLException; - - /** - * This method tests whether or not that database supports positioned - * deletes. - * - * @return <code>true</code> if positioned deletes are supported, - * <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean supportsPositionedDelete() throws SQLException; - - /** - * This method tests whether or not that database supports positioned - * updates. - * - * @return <code>true</code> if positioned updates are supported, - * <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean supportsPositionedUpdate() throws SQLException; - - /** - * This method tests whether or not SELECT FOR UPDATE is supported by the - * database. - * - * @return <code>true</code> if SELECT FOR UPDATE is supported - * <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean supportsSelectForUpdate() throws SQLException; - - /** - * This method tests whether or not stored procedures are supported on - * this database. - * - * @return <code>true</code> if stored procedures are supported, - * <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean supportsStoredProcedures() throws SQLException; - - /** - * This method tests whether or not subqueries are allowed in comparisons. - * A fully JDBC compliant driver will always return <code>true</code>. - * - * @return <code>true</code> if subqueries are allowed in comparisons, - * <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean supportsSubqueriesInComparisons() throws SQLException; - - /** - * This method tests whether or not subqueries are allowed in exists - * expressions. A fully JDBC compliant driver will always return - * <code>true</code>. - * - * @return <code>true</code> if subqueries are allowed in exists - * expressions, <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean supportsSubqueriesInExists() throws SQLException; - - /** - * This method tests whether subqueries are allowed in IN statements. - * A fully JDBC compliant driver will always return <code>true</code>. - * - * @return <code>true</code> if the driver supports subqueries in IN - * statements, <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean supportsSubqueriesInIns() throws SQLException; - - /** - * This method tests whether or not subqueries are allowed in quantified - * expressions. A fully JDBC compliant driver will always return - * <code>true</code>. - * - * @return <code>true</code> if subqueries are allowed in quantified - * expressions, <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean supportsSubqueriesInQuantifieds() throws SQLException; - - /** - * This method test whether or not correlated subqueries are allowed. A - * fully JDBC compliant driver will always return <code>true</code>. - * - * @return <code>true</code> if correlated subqueries are allowed, - * <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean supportsCorrelatedSubqueries() throws SQLException; - - /** - * This method tests whether or not the UNION statement is supported. - * - * @return <code>true</code> if UNION is supported, <code>false</code> - * otherwise. - * @exception SQLException If an error occurs. - */ - boolean supportsUnion() throws SQLException; - - /** - * This method tests whether or not the UNION ALL statement is supported. - * - * @return <code>true</code> if UNION ALL is supported, <code>false</code> - * otherwise. - * @exception SQLException If an error occurs. - */ - boolean supportsUnionAll() throws SQLException; - - /** - * This method tests whether or not the database supports cursors - * remaining open across commits. - * - * @return <code>true</code> if cursors can remain open across commits, - * <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean supportsOpenCursorsAcrossCommit() throws SQLException; - - /** - * This method tests whether or not the database supports cursors - * remaining open across rollbacks. - * - * @return <code>true</code> if cursors can remain open across rollbacks, - * <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean supportsOpenCursorsAcrossRollback() throws SQLException; - - /** - * This method tests whether or not the database supports statements - * remaining open across commits. - * - * @return <code>true</code> if statements can remain open across commits, - * <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean supportsOpenStatementsAcrossCommit() throws SQLException; - - /** - * This method tests whether or not the database supports statements - * remaining open across rollbacks. - * - * @return <code>true</code> if statements can remain open across rollbacks, - * <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean supportsOpenStatementsAcrossRollback() throws SQLException; - - /** - * This method returns the number of hex characters allowed in an inline - * binary literal. - * - * @return The number of hex characters allowed in a binary literal, 0 meaning - * either an unknown or unlimited number. - * @exception SQLException If an error occurs. - */ - int getMaxBinaryLiteralLength() throws SQLException; - - /** - * This method returns the maximum length of a character literal. - * - * @return The maximum length of a character literal. - * @exception SQLException If an error occurs. - */ - int getMaxCharLiteralLength() throws SQLException; - - /** - * This method returns the maximum length of a column name. - * - * @return The maximum length of a column name. - * @exception SQLException If an error occurs. - */ - int getMaxColumnNameLength() throws SQLException; - - /** - * This method returns the maximum number of columns in a GROUP BY statement. - * - * @return The maximum number of columns in a GROUP BY statement. - * @exception SQLException If an error occurs. - */ - int getMaxColumnsInGroupBy() throws SQLException; - - /** - * This method returns the maximum number of columns in an index. - * - * @return The maximum number of columns in an index. - * @exception SQLException If an error occurs. - */ - int getMaxColumnsInIndex() throws SQLException; - - /** - * This method returns the maximum number of columns in an ORDER BY statement. - * - * @return The maximum number of columns in an ORDER BY statement. - * @exception SQLException If an error occurs. - */ - int getMaxColumnsInOrderBy() throws SQLException; - - /** - * This method returns the maximum number of columns in a SELECT statement. - * - * @return The maximum number of columns in a SELECT statement. - * @exception SQLException If an error occurs. - */ - int getMaxColumnsInSelect() throws SQLException; - - /** - * This method returns the maximum number of columns in a table. - * - * @return The maximum number of columns in a table. - * @exception SQLException If an error occurs. - */ - int getMaxColumnsInTable() throws SQLException; - - /** - * This method returns the maximum number of connections this client - * can have to the database. - * - * @return The maximum number of database connections. - * @SQLException If an error occurs. - */ - int getMaxConnections() throws SQLException; - - /** - * This method returns the maximum length of a cursor name. - * - * @return The maximum length of a cursor name. - * @exception SQLException If an error occurs. - */ - int getMaxCursorNameLength() throws SQLException; - - /** - * This method returns the maximum length of an index. - * - * @return The maximum length of an index. - * @exception SQLException If an error occurs. - */ - int getMaxIndexLength() throws SQLException; - - /** - * This method returns the maximum length of a schema name. - * - * @return The maximum length of a schema name. - * @exception SQLException If an error occurs. - */ - int getMaxSchemaNameLength() throws SQLException; - - /** - * This method returns the maximum length of a procedure name. - * - * @return The maximum length of a procedure name. - * @exception SQLException If an error occurs. - */ - int getMaxProcedureNameLength() throws SQLException; - - /** - * This method returns the maximum length of a catalog name. - * - * @return The maximum length of a catalog name. - * @exception SQLException If an error occurs. - */ - int getMaxCatalogNameLength() throws SQLException; - - /** - * This method returns the maximum size of a row in bytes. - * - * @return The maximum size of a row. - * @exception SQLException If an error occurs. - */ - int getMaxRowSize() throws SQLException; - - /** - * This method tests whether or not the maximum row size includes BLOB's - * - * @return <code>true</code> if the maximum row size includes BLOB's, - * <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean doesMaxRowSizeIncludeBlobs() throws SQLException; - - /** - * This method includes the maximum length of a SQL statement. - * - * @return The maximum length of a SQL statement. - * @exception SQLException If an error occurs. - */ - int getMaxStatementLength() throws SQLException; - - /** - * This method returns the maximum number of statements that can be - * active at any time. - * - * @return The maximum number of statements that can be active at any time. - * @exception SQLException If an error occurs. - */ - int getMaxStatements() throws SQLException; - - /** - * This method returns the maximum length of a table name. - * - * @return The maximum length of a table name. - * @exception SQLException If an error occurs. - */ - int getMaxTableNameLength() throws SQLException; - - /** - * This method returns the maximum number of tables that may be referenced - * in a SELECT statement. - * - * @return The maximum number of tables allowed in a SELECT statement. - * @exception SQLException If an error occurs. - */ - int getMaxTablesInSelect() throws SQLException; - - /** - * This method returns the maximum length of a user name. - * - * @return The maximum length of a user name. - * @exception SQLException If an error occurs. - */ - int getMaxUserNameLength() throws SQLException; - - /** - * This method returns the default transaction isolation level of the - * database. - * - * @return The default transaction isolation level of the database. - * @exception SQLException If an error occurs. - * @see Connection - */ - int getDefaultTransactionIsolation() throws SQLException; - - /** - * This method tests whether or not the database supports transactions. - * - * @return <code>true</code> if the database supports transactions, - * <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean supportsTransactions() throws SQLException; - - /** - * This method tests whether or not the database supports the specified - * transaction isolation level. - * - * @param level The transaction isolation level. - * - * @return <code>true</code> if the specified transaction isolation level - * is supported, <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean supportsTransactionIsolationLevel(int level) throws - SQLException; - - /** - * This method tests whether or not DDL and DML statements allowed within - * the same transaction. - * - * @return <code>true</code> if DDL and DML statements are allowed in the - * same transaction, <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean supportsDataDefinitionAndDataManipulationTransactions() - throws SQLException; - - /** - * This method tests whether or not only DML statement are allowed - * inside a transaction. - * - * @return <code>true</code> if only DML statements are allowed in - * transactions, <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean supportsDataManipulationTransactionsOnly() throws - SQLException; - - /** - * This method tests whether or not a DDL statement will cause the - * current transaction to be automatically committed. - * - * @return <code>true</code> if DDL causes an immediate transaction commit, - * <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean dataDefinitionCausesTransactionCommit() throws SQLException; - - /** - * This method tests whether or not DDL statements are ignored in - * transactions. - * - * @return <code>true</code> if DDL statements are ignored in transactions, - * <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean dataDefinitionIgnoredInTransactions() throws SQLException; - - /** - * This method returns a list of all the stored procedures matching the - * specified pattern in the given schema and catalog. This is returned - * a <code>ResultSet</code> with the following columns: - * <p> - * <ol> - * <li>PROCEDURE_CAT - The catalog the procedure is in, which may be - * <code>null</code>.</li> - * <li>PROCEDURE_SCHEM - The schema the procedures is in, which may be - * <code>null</code>.</li> - * <li>PROCEDURE_NAME - The name of the procedure.</li> - * <li>Unused</li> - * <li>Unused</li> - * <li>Unused</li> - * <li>REMARKS - A description of the procedure</li> - * <li>PROCEDURE_TYPE - Indicates the return type of the procedure, which - * is one of the contstants defined in this class - * (<code>procedureResultUnknown</code>, <code>procedureNoResult</code>, or - * <code>procedureReturnsResult</code>).</li> - * </ol> - * - * @param catalog The name of the catalog to return stored procedured from, - * or "" to return procedures from all catalogs. - * @param schemaPattern A schema pattern for the schemas to return stored - * procedures from, or "" to return procedures from all schemas. - * @param namePattern The pattern of procedures names to return. - * @returns A <code>ResultSet</code> with all the requested procedures. - * @exception SQLException If an error occurs. - */ - ResultSet getProcedures(String catalog, String schemaPattern, String - procedureNamePattern) throws SQLException; - - /** - * This method returns a list of the parameter and result columns for - * the requested stored procedures. This is returned in the form of a - * <code>ResultSet</code> with the following columns: - * <p> - * <ol> - * <li>PROCEDURE_CAT - The catalog the procedure is in, which may be - * <code>null</code>.</li> - * <li>PROCEDURE_SCHEM - The schema the procedures is in, which may be - * <code>null</code>.</li> - * <li>PROCEDURE_NAME - The name of the procedure.</li> - * <li>COLUMN_NAME - The name of the column</li> - * <li>COLUMN_TYPE - The type of the column, which will be one of the - * contants defined in this class (<code>procedureColumnUnknown</code>, - * <code>procedureColumnIn</code>, <code>procedureColumnInOut</code>, - * <code>procedureColumnOut</code>, <code>procedureColumnReturn</code>, - * or <code>procedureColumnResult</code>).</li> - * <li>DATA_TYPE - The SQL type of the column. This is one of the constants - * defined in <code>Types</code>.</li> - * <li>TYPE_NAME - The string name of the data type for this column.</li> - * <li>PRECISION - The precision of the column.</li> - * <li>LENGTH - The length of the column in bytes</li> - * <li>SCALE - The scale of the column.</li> - * <li>RADIX - The radix of the column.</li> - * <li>NULLABLE - Whether or not the column is NULLABLE. This is one of - * the constants defined in this class (<code>procedureNoNulls</code>, - * <code>procedureNullable</code>, or <code>procedureNullableUnknown</code>)</li> - * <li>REMARKS - A description of the column.</li> - * </ol> - * - * @param catalog The name of the catalog to return stored procedured from, - * or "" to return procedures from all catalogs. - * @param schemaPattern A schema pattern for the schemas to return stored - * procedures from, or "" to return procedures from all schemas. - * @param namePattern The pattern of procedures names to return. - * @param columnPattern The pattern of column names to return. - * @returns A <code>ResultSet</code> with all the requested procedures. - * @exception SQLException If an error occurs. - */ - ResultSet getProcedureColumns(String catalog, String schemaPattern, - String procedureNamePattern, String columnNamePattern) throws - SQLException; - - /** - * This method returns a list of the requested table as a - * <code>ResultSet</code> with the following columns: - * - * <ol> - * <li>TABLE_CAT - The catalog the table is in, which may be <code>null</code>.</li> - * <li>TABLE_SCHEM - The schema the table is in, which may be <code>null</code>.</li> - * <li>TABLE_NAME - The name of the table.</li> - * <li>TABLE_TYPE - A string describing the table type. This will be one - * of the values returned by the <code>getTableTypes()</code> method.</li> - * <li>REMARKS - Comments about the table.</li> - * </ol> - * - * @param catalog The name of the catalog to return tables from, - * or "" to return tables from all catalogs. - * @param schemaPattern A schema pattern for the schemas to return tables - * from, or "" to return tables from all schemas. - * @param namePattern The pattern of table names to return. - * @param types The list of table types to include; null returns all types. - * @returns A <code>ResultSet</code> with all the requested tables. - * @exception SQLException If an error occurs. - */ - ResultSet getTables(String catalog, String schemaPattern, String - tableNamePattern, String[] types) throws SQLException; - - /** - * This method returns the list of database schemas as a - * <code>ResultSet</code>, with one column - TABLE_SCHEM - that is the - * name of the schema. - * - * @return A <code>ResultSet</code> with all the requested schemas. - * @exception SQLException If an error occurs. - */ - ResultSet getSchemas() throws SQLException; - - /** - * This method returns the list of database catalogs as a - * <code>ResultSet</code> with one column - TABLE_CAT - that is the - * name of the catalog. - * - * @return A <code>ResultSet</code> with all the requested catalogs. - * @exception SQLException If an error occurs. - */ - ResultSet getCatalogs() throws SQLException; - - /** - * This method returns the list of database table types as a - * <code>ResultSet</code> with one column - TABLE_TYPE - that is the - * name of the table type. - * - * @return A <code>ResultSet</code> with all the requested table types. - * @exception SQLException If an error occurs. - */ - ResultSet getTableTypes() throws SQLException; - - /** - * This method returns a list of the tables columns for - * the requested tables. This is returned in the form of a - * <code>ResultSet</code> with the following columns: - * <p> - * <ol> - * <li>TABLE_CAT - The catalog the table is in, which may be - * <code>null</code>.</li> - * <li>TABLE_SCHEM - The schema the tables is in, which may be - * <code>null</code>.</li> - * <li>TABLE_NAME - The name of the table.</li> - * <li>COLUMN_NAME - The name of the column</li> - * <li>DATA_TYPE - The SQL type of the column. This is one of the constants - * defined in <code>Types</code>.</li> - * <li>TYPE_NAME - The string name of the data type for this column.</li> - * <li>COLUMN_SIZE - The size of the column.</li> - * <li>Unused</li> - * <li>NUM_PREC_RADIX - The radix of the column.</li> - * <li>NULLABLE - Whether or not the column is NULLABLE. This is one of - * the constants defined in this class (<code>tableNoNulls</code>, - * <code>tableNullable</code>, or <code>tableNullableUnknown</code>)</li> - * <li>REMARKS - A description of the column.</li> - * <li>COLUMN_DEF - The default value for the column, may be <code>null</code>.</li> - * <li>SQL_DATA_TYPE - Unused</li> - * <li>SQL_DATETIME_SUB - Unused</li> - * <li>CHAR_OCTET_LENGTH - For character columns, the maximum number of bytes - * in the column.</li> - * <li>ORDINAL_POSITION - The index of the column in the table.</li> - * <li>IS_NULLABLE - "NO" means no, "YES" means maybe, and an empty string - * means unknown.</li> - * </ol> - * - * @param catalog The name of the catalog to return table from, - * or "" to return tables from all catalogs. - * @param schemaPattern A schema pattern for the schemas to return - * tables from, or "" to return tables from all schemas. - * @param namePattern The pattern of tables names to return. - * @param columnPattern The pattern of column names to return. - * @returns A <code>ResultSet</code> with all the requested tables. - * @exception SQLException If an error occurs. - */ - ResultSet getColumns(String catalog, String schemaPattern, String - tableNamePattern, String columnNamePattern) throws SQLException; - - /** - * This method returns the access rights that have been granted to the - * requested columns. This information is returned as a <code>ResultSet</code> - * with the following columns: - * - * <ol> - * <li>TABLE_CAT - The catalog the table is in, which may be - * <code>null</code>.</li> - * <li>TABLE_SCHEM - The schema the tables is in, which may be - * <code>null</code>.</li> - * <li>TABLE_NAME - The name of the table.</li> - * <li>COLUMN_NAME - The name of the column.</li> - * <li>GRANTOR - The entity that granted the access.</li> - * <li>GRANTEE - The entity granted the access.</li> - * <li>PRIVILEGE - The name of the privilege granted.</li> - * <li>IS_GRANTABLE - "YES" if the grantee can grant the privilege to - * others, "NO" if not, and <code>null</code> if unknown.</li> - * </ol> - * - * @param catalog The catalog to retrieve information from, or the empty string - * to return entities not associated with a catalog, or <code>null</code> - * to return information from all catalogs. - * @param schema The schema to retrieve information from, or the empty string - * to return entities not associated with a schema. - * @param table The table name to return information for. - * @param columnPattern A pattern of column names to return information for. - * @return A <code>ResultSet</code> with all the requested privileges. - * @exception SQLException If an error occurs. - */ - ResultSet getColumnPrivileges(String catalog, String schema, String - table, String columnNamePattern) throws SQLException; - - /** - * This method returns the access rights that have been granted to the - * requested tables. This information is returned as a <code>ResultSet</code> - * with the following columns: - * - * <ol> - * <li>TABLE_CAT - The catalog the table is in, which may be - * <code>null</code>.</li> - * <li>TABLE_SCHEM - The schema the tables is in, which may be - * <code>null</code>.</li> - * <li>TABLE_NAME - The name of the table.</li> - * <li>GRANTOR - The entity that granted the access.</li> - * <li>GRANTEE - The entity granted the access.</li> - * <li>PRIVILEGE - The name of the privilege granted.</li> - * <li>IS_GRANTABLE - "YES" if the grantee can grant the privilege to - * others, "NO" if not, and <code>null</code> if unknown.</li> - * </ol> - * - * @param catalog The catalog to retrieve information from, or the empty string - * to return entities not associated with a catalog, or <code>null</code> - * to return information from all catalogs. - * @param schema The schema to retrieve information from, or the empty string - * to return entities not associated with a schema. - * @param tablePattern The table name pattern of tables to return - * information for. - * @return A <code>ResultSet</code> with all the requested privileges. - * @exception SQLException If an error occurs. - */ - ResultSet getTablePrivileges(String catalog, String schemaPattern, - String tableNamePattern) throws SQLException; - - /** - * This method returns the best set of columns for uniquely identifying - * a row. It returns this information as a <code>ResultSet</code> with - * the following columns: - * - * <ol> - * <li>SCOPE - The scope of the results returned. This is one of the - * constants defined in this class (<code>bestRowTemporary</code>, - * <code>bestRowTransaction</code>, or <code>bestRowSession</code>).</li> - * <li>COLUMN_NAME - The name of the column.</li> - * <li>DATA_TYPE - The SQL type of the column. This is one of the constants - * defined in <code>Types</code>.</li> - * <li>TYPE_NAME - The string name of the data type for this column.</li> - * <li>COLUMN_SIZE - The precision of the columns</li> - * <li>BUFFER_LENGTH - Unused</li> - * <li>DECIMAL_DIGITS - The scale of the column.</li> - * <li>PSEUDO_COLUMN - Whether or not the best row identifier is a - * pseudo_column. This is one of the constants defined in this class - * (<code>bestRowUnknown</code>, <code>bestRowNotPseudo</code>, or - * <code>bestRowPseudo</code>).</li> - * </ol> - * - * @param catalog The catalog to retrieve information from, or the empty string - * to return entities not associated with a catalog, or <code>null</code> - * to return information from all catalogs. - * @param schema The schema to retrieve information from, or the empty string - * to return entities not associated with a schema. - * @param table The table name to return information for. - * @param columnPattern A pattern of column names to return information for. - * @param scope One of the best row id scope constants from this class. - * @param nullable <code>true</code> to include columns that are nullable, - * <code>false</code> otherwise. - * @return A <code>ResultSet</code> with the best row identifier. - * @exception SQLException If an error occurs. - */ - ResultSet getBestRowIdentifier(String catalog, String schema, - String table, int scope, boolean nullable) throws SQLException; - - /** - * This method returns the set of columns that are automatically updated - * when the row is update. It returns this information as a - * <code>ResultSet</code> with the following columns: - * - * <ol> - * <li>SCOPE - Unused</li> - * <li>COLUMN_NAME - The name of the column.</li> - * <li>DATA_TYPE - The SQL type of the column. This is one of the constants - * defined in <code>Types</code>.</li> - * <li>TYPE_NAME - The string name of the data type for this column.</li> - * <li>COLUMN_SIZE - The precision of the columns</li> - * <li>BUFFER_LENGTH - Unused</li> - * <li>DECIMAL_DIGITS - The scale of the column.</li> - * <li>PSEUDO_COLUMN - Whether or not the best row identifier is a - * pseudo_column. This is one of the constants defined in this class - * (<code>versionRowUnknown</code>, <code>versionRowNotPseudo</code>, or - * <code>versionRowPseudo</code>).</li> - * </ol> - * - * @param catalog The catalog to retrieve information from, or the empty string - * to return entities not associated with a catalog, or <code>null</code> - * to return information from all catalogs. - * @param schema The schema to retrieve information from, or the empty string - * to return entities not associated with a schema. - * @param table The table name to return information for. - * @param columnPattern A pattern of column names to return information for. - * @return A <code>ResultSet</code> with the version columns. - * @exception SQLException If an error occurs. - */ - ResultSet getVersionColumns(String catalog, String schema, - String table) throws SQLException; - - /** - * This method returns a list of a table's primary key columns. These - * are returned as a <code>ResultSet</code> with the following columns. - * - * <ol> - * <li>TABLE_CAT - The catalog of the table, which may be <code>null</code>.</li> - * <li>TABLE_SCHEM - The schema of the table, which may be <code>null</code>.</li> - * <li>TABLE_NAME - The name of the table.</li> - * <li>COLUMN_NAME - The name of the column.</li> - * <li>KEY_SEQ - The sequence number of the column within the primary key.</li> - * <li>PK_NAME - The name of the primary key, which may be <code>null</code>.</li> - * </ol> - * - * @param catalog The catalog to retrieve information from, or the empty string - * to return entities not associated with a catalog, or <code>null</code> - * to return information from all catalogs. - * @param schema The schema to retrieve information from, or the empty string - * to return entities not associated with a schema. - * @param table The table name to return information for. - * @param columnPattern A pattern of column names to return information for. - * @return A <code>ResultSet</code> with the primary key columns. - * @exception SQLException If an error occurs. - */ - ResultSet getPrimaryKeys(String catalog, String schema, String table) - throws SQLException; - - /** - * This method returns a list of the table's foreign keys. These are - * returned as a <code>ResultSet</code> with the following columns: - * - * <ol> - * <li>PKTABLE_CAT - The catalog of the table the key was imported from.</li> - * <li>PKTABLE_SCHEM - The schema of the table the key was imported from.</li> - * <li>PKTABLE_NAME - The name of the table the key was imported from.</li> - * <li>PKCOLUMN_NAME - The name of the column that was imported.</li> - * <li>FKTABLE_CAT - The foreign key catalog name.</li> - * <li>FKTABLE_SCHEM - The foreign key schema name.</li> - * <li>FKTABLE_NAME - The foreign key table name.</li> - * <li>FKCOLUMN_NAME - The foreign key column name.</li> - * <li>KEY_SEQ - The sequence number of the column within the foreign key.</li> - * <li>UPDATE_RULE - How the foreign key behaves when the primary key is - * updated. This is one of the constants defined in this class - * (<code>importedNoAction</code>, <code>importedKeyCascade</code>, - * <code>importedKeySetNull</code>, <code>importedKeySetDefault</code>, or - * <code>importedKeyRestrict</code>).</li> - * <li>DELETE_RULE - How the foreign key behaves when the primary key is - * deleted. This is one of the constants defined in this class - * (<code>importedNoAction</code>, <code>importedKeyCascade</code>, - * <code>importedKeySetNull</code>, or <code>importedKeySetDefault</code>)</li> - * <li>FK_NAME - The name of the foreign key.</li> - * <li>PK_NAME - The name of the primary key.</li> - * <li>DEFERRABILITY - The deferrability value. This is one of the - * constants defined in this table (<code>importedKeyInitiallyDeferred</code>, - * <code>importedKeyInitiallyImmediate</code>, or - * <code>importedKeyNotDeferrable</code>).</li> - * </ol> - * - * @param catalog The catalog to retrieve information from, or the empty string - * to return entities not associated with a catalog, or <code>null</code> - * to return information from all catalogs. - * @param schema The schema to retrieve information from, or the empty string - * to return entities not associated with a schema. - * @param table The table name to return information for. - * - * @return A <code>ResultSet</code> with the foreign key columns. - * - * @exception SQLException If an error occurs. - */ - ResultSet getImportedKeys(String catalog, String schema, - String table) throws SQLException; - - /** - * This method returns a list of the table's which use this table's - * primary key as a foreign key. The information is - * returned as a <code>ResultSet</code> with the following columns: - * - * <ol> - * <li>PKTABLE_CAT - The catalog of the table the key was imported from.</li> - * <li>PKTABLE_SCHEM - The schema of the table the key was imported from.</li> - * <li>PKTABLE_NAME - The name of the table the key was imported from.</li> - * <li>PKCOLUMN_NAME - The name of the column that was imported.</li> - * <li>FKTABLE_CAT - The foreign key catalog name.</li> - * <li>FKTABLE_SCHEM - The foreign key schema name.</li> - * <li>FKTABLE_NAME - The foreign key table name.</li> - * <li>FKCOLUMN_NAME - The foreign key column name.</li> - * <li>KEY_SEQ - The sequence number of the column within the foreign key.</li> - * <li>UPDATE_RULE - How the foreign key behaves when the primary key is - * updated. This is one of the constants defined in this class - * (<code>importedNoAction</code>, <code>importedKeyCascade</code>, - * <code>importedKeySetNull</code>, <code>importedKeySetDefault</code>, or - * <code>importedKeyRestrict</code>).</li> - * <li>DELETE_RULE - How the foreign key behaves when the primary key is - * deleted. This is one of the constants defined in this class - * (<code>importedNoAction</code>, <code>importedKeyCascade</code>, - * <code>importedKeySetNull</code>, or <code>importedKeySetDefault</code>)</li> - * <li>FK_NAME - The name of the foreign key.</li> - * <li>PK_NAME - The name of the primary key.</li> - * <li>DEFERRABILITY - The deferrability value. This is one of the - * constants defined in this table (<code>importedKeyInitiallyDeferred</code>, - * <code>importedKeyInitiallyImmediate</code>, or - * <code>importedKeyNotDeferrable</code>).</li> - * </ol> - * - * @param catalog The catalog to retrieve information from, or the empty string - * to return entities not associated with a catalog, or <code>null</code> - * to return information from all catalogs. - * @param schema The schema to retrieve information from, or the empty string - * to return entities not associated with a schema. - * @param table The table name to return information for. - * @return A <code>ResultSet</code> with the requested information - * @exception SQLException If an error occurs. - */ - ResultSet getExportedKeys(String catalog, String schema, - String table) throws SQLException; - - /** - * This method returns a description of how one table imports another - * table's primary key as a foreign key. The information is - * returned as a <code>ResultSet</code> with the following columns: - * - * <ol> - * <li>PKTABLE_CAT - The catalog of the table the key was imported from.</li> - * <li>PKTABLE_SCHEM - The schema of the table the key was imported from.</li> - * <li>PKTABLE_NAME - The name of the table the key was imported from.</li> - * <li>PKCOLUMN_NAME - The name of the column that was imported.</li> - * <li>FKTABLE_CAT - The foreign key catalog name.</li> - * <li>FKTABLE_SCHEM - The foreign key schema name.</li> - * <li>FKTABLE_NAME - The foreign key table name.</li> - * <li>FKCOLUMN_NAME - The foreign key column name.</li> - * <li>KEY_SEQ - The sequence number of the column within the foreign key.</li> - * <li>UPDATE_RULE - How the foreign key behaves when the primary key is - * updated. This is one of the constants defined in this class - * (<code>importedNoAction</code>, <code>importedKeyCascade</code>, - * <code>importedKeySetNull</code>, <code>importedKeySetDefault</code>, or - * <code>importedKeyRestrict</code>).</li> - * <li>DELETE_RULE - How the foreign key behaves when the primary key is - * deleted. This is one of the constants defined in this class - * (<code>importedNoAction</code>, <code>importedKeyCascade</code>, - * <code>importedKeySetNull</code>, or <code>importedKeySetDefault</code>)</li> - * <li>FK_NAME - The name of the foreign key.</li> - * <li>PK_NAME - The name of the primary key.</li> - * <li>DEFERRABILITY - The deferrability value. This is one of the - * constants defined in this table (<code>importedKeyInitiallyDeferred</code>, - * <code>importedKeyInitiallyImmediate</code>, or - * <code>importedKeyNotDeferrable</code>).</li> - * </ol> - * - * @param primCatalog The catalog to retrieve information from, or the empty string - * to return entities not associated with a catalog, or <code>null</code> - * to return information from all catalogs, on the exporting side. - * @param primSchema The schema to retrieve information from, or the empty string - * to return entities not associated with a schema, on the exporting side. - * @param primTable The table name to return information for, on the exporting - * side. - * @param forCatalog The catalog to retrieve information from, or the empty string - * to return entities not associated with a catalog, or <code>null</code> - * to return information from all catalogs, on the importing side. - * @param forSchema The schema to retrieve information from, or the empty string - * to return entities not associated with a schema on the importing side. - * @param forTable The table name to return information for on the importing - * side. - * @return A <code>ResultSet</code> with the requested information - * @exception SQLException If an error occurs. - */ - ResultSet getCrossReference(String primaryCatalog, String - primarySchema, String primaryTable, String foreignCatalog, String - foreignSchema, String foreignTable) throws SQLException; - - /** - * This method returns a list of the SQL types supported by this - * database. The information is returned as a <code>ResultSet</code> - * with the following columns: - * - * <ol> - * <li>TYPE_NAME - The name of the data type.</li> - * <li>DATA_TYPE - A data type constant from <code>Types</code> for this - * type.</li> - * <li>PRECISION - The maximum precision of this type.</li> - * <li>LITERAL_PREFIX - Prefix value used to quote a literal, which may be - * <code>null</code>.</li> - * <li>LITERAL_SUFFIX - Suffix value used to quote a literal, which may be - * <code>null</code>.</li> - * <li>CREATE_PARAMS - The parameters used to create the type, which may be - * <code>null</code>.</li> - * <li>NULLABLE - Whether or not this type supports NULL values. This will - * be one of the constants defined in this interface - * (<code>typeNoNulls</code>, <code>typeNullable</code>, or - * <code>typeNullableUnknown</code>).</li> - * <li>CASE_SENSITIVE - Whether or not the value is case sensitive.</li> - * <li>SEARCHABLE - Whether or not "LIKE" expressions are supported in - * WHERE clauses for this type. This will be one of the constants defined - * in this interface (<code>typePredNone</code>, <code>typePredChar</code>, - * <code>typePredBasic</code>, or <code>typeSearchable</code>).</li> - * <li>UNSIGNED_ATTRIBUTE - Is the value of this type unsigned.</li> - * <li>FIXED_PREC_SCALE - Whether or not this type can be used for money.</li> - * <li>AUTO_INCREMENT - Whether or not this type supports auto-incrementing.</li> - * <li>LOCAL_TYPE_NAME - A localized name for this data type.</li> - * <li>MINIMUM_SCALE - The minimum scale supported by this type.</li> - * <li>MAXIMUM_SCALE - The maximum scale supported by this type.</li> - * <li>SQL_DATA_TYPE - Unused.</li> - * <li>SQL_DATETIME_SUB - Unused.</li> - * <li>NUM_PREC_RADIX - The radix of this data type.</li> - * </ol> - * - * @return A <code>ResultSet</code> with the list of available data types. - * @exception SQLException If an error occurs. - */ - ResultSet getTypeInfo() throws SQLException; - - /** - * This method returns information about a tables indices and statistics. - * It is returned as a <code>ResultSet</code> with the following columns: - * - * <ol> - * <li>TABLE_CAT - The catalog of the table, which may be <code>null</code>.</li> - * <li>TABLE_SCHEM - The schema of the table, which may be <code>null</code>.</li> - * <li>TABLE_NAME - The name of the table.</li> - * <li>NON_UNIQUE - Are index values non-unique?</li> - * <li>INDEX_QUALIFIER The index catalog, which may be <code>null</code></li> - * <li>INDEX_NAME - The name of the index.</li> - * <li>TYPE - The type of index, which will be one of the constants defined - * in this interface (<code>tableIndexStatistic</code>, - * <code>tableIndexClustered</code>, <code>tableIndexHashed</code>, or - * <code>tableIndexOther</code>).</li> - * <li>ORDINAL_POSITION - The sequence number of this column in the index. - * This will be 0 when the index type is <code>tableIndexStatistic</code>.</li> - * <li>COLUMN_NAME - The name of this column in the index.</li> - * <li>ASC_OR_DESC - "A" for an ascending sort sequence, "D" for a - * descending sort sequence or <code>null</code> if a sort sequence is not - * supported.</li> - * <li>CARDINALITY - The number of unique rows in the index, or the number - * of rows in the table if the index type is <code>tableIndexStatistic</code>.</li> - * <li>PAGES - The number of pages used for the index, or the number of pages - * in the table if the index type is <code>tableIndexStatistic</code>.</li> - * <li>FILTER_CONDITION - The filter condition for this index, which may be - * <code>null</code>.</li> - * </ol> - * - * @param catalog The catalog to retrieve information from, or the empty string - * to return entities not associated with a catalog, or - * <code>null</code> to return information from all catalogs. - * @param schema The schema to retrieve information from, or the empty string - * to return entities not associated with a schema. - * @param table The table name to return information for. - * @param unique <code>true</code> to return only unique indexes, - * <code>false</code> otherwise. - * @param approx <code>true</code> if data values can be approximations, - * <code>false</code> otherwise. - * @return A <code>ResultSet</code> with the requested index information - * @exception SQLException If an error occurs. - */ - ResultSet getIndexInfo(String catalog, String schema, String table, - boolean unique, boolean approximate) throws SQLException; - - /** - * This method tests whether or not the datbase supports the specified - * result type. - * - * @param type The desired result type, which is one of the constants - * defined in <code>ResultSet</code>. - * - * @return <code>true</code> if the result set type is supported, - * <code>false</code> otherwise. - * - * @exception SQLException If an error occurs. - * - * @see ResultSet - */ - boolean supportsResultSetType(int type) throws SQLException; - - /** - * This method tests whether the specified result set type and result set - * concurrency type are supported by the database. - * - * @param type The desired result type, which is one of the constants - * defined in <code>ResultSet</code>. - * @param concur The desired concurrency type, which is one of the constants - * defined in <code>ResultSet</code>. - * @return <code>true</code> if the result set type is supported, - * <code>false</code> otherwise. - * @exception SQLException If an error occurs. - * @see ResultSet - */ - boolean supportsResultSetConcurrency(int type, int concurrency) - throws SQLException; - - /** - * This method tests whether or not the specified result set type sees its - * own updates. - * - * @param type The desired result type, which is one of the constants - * defined in <code>ResultSet</code>. - * @return <code>true</code> if the result set type sees its own updates, - * <code>false</code> otherwise. - * @exception SQLException If an error occurs. - * @see ResultSet - */ - boolean ownUpdatesAreVisible(int type) throws SQLException; - - /** - * This method tests whether or not the specified result set type sees its - * own deletes. - * - * @param type The desired result type, which is one of the constants - * defined in <code>ResultSet</code>. - * @return <code>true</code> if the result set type sees its own deletes, - * <code>false</code> otherwise. - * @exception SQLException If an error occurs. - * @see ResultSet - */ - boolean ownDeletesAreVisible(int type) throws SQLException; - - /** - * This method tests whether or not the specified result set type sees its - * own inserts. - * - * @param type The desired result type, which is one of the constants - * defined in <code>ResultSet</code>. - * @return <code>true</code> if the result set type sees its own inserts, - * <code>false</code> otherwise. - * @exception SQLException If an error occurs. - * @see ResultSet - */ - boolean ownInsertsAreVisible(int type) throws SQLException; - - /** - * This method tests whether or not the specified result set type sees - * updates committed by others. - * - * @param type The desired result type, which is one of the constants - * defined in <code>ResultSet</code>. - * @return <code>true</code> if the result set type sees other updates, - * <code>false</code> otherwise. - * @exception SQLException If an error occurs. - * @see ResultSet - */ - boolean othersUpdatesAreVisible(int type) throws SQLException; - - /** - * This method tests whether or not the specified result set type sees - * deletes committed by others. - * - * @param type The desired result type, which is one of the constants - * defined in <code>ResultSet</code>. - * @return <code>true</code> if the result set type sees other deletes, - * <code>false</code> otherwise. - * @exception SQLException If an error occurs. - * @see ResultSet - */ - boolean othersDeletesAreVisible(int type) throws SQLException; - - /** - * This method tests whether or not the specified result set type sees - * inserts committed by others. - * - * @param type The desired result type, which is one of the constants - * defined in <code>ResultSet</code>. - * @return <code>true</code> if the result set type sees other inserts, - * <code>false</code> otherwise. - * @exception SQLException If an error occurs. - * @see ResultSet - */ - boolean othersInsertsAreVisible(int type) throws SQLException; - - /** - * This method tests whether or not the specified result set type can detect - * a visible update by calling the <code>rowUpdated</code> method. - * - * @param type The desired result type, which is one of the constants - * defined in <code>ResultSet</code>. - * @return <code>true</code> if the result set type can detect visible updates - * using <code>rowUpdated</code>, <code>false</code> otherwise. - * @exception SQLException If an error occurs. - * @see ResultSet - */ - boolean updatesAreDetected(int type) throws SQLException; - - /** - * This method tests whether or not the specified result set type can detect - * a visible delete by calling the <code>rowUpdated</code> method. - * - * @param type The desired result type, which is one of the constants - * defined in <code>ResultSet</code>. - * @return <code>true</code> if the result set type can detect visible deletes - * using <code>rowUpdated</code>, <code>false</code> otherwise. - * @exception SQLException If an error occurs. - * @see ResultSet - */ - boolean deletesAreDetected(int type) throws SQLException; - - /** - * This method tests whether or not the specified result set type can detect - * a visible insert by calling the <code>rowUpdated</code> method. - * - * @param type The desired result type, which is one of the constants - * defined in <code>ResultSet</code>. - * @return <code>true</code> if the result set type can detect visible inserts - * using <code>rowUpdated</code>, <code>false</code> otherwise. - * @exception SQLException If an error occurs. - * @see ResultSet - */ - boolean insertsAreDetected(int type) throws SQLException; - - /** - * This method tests whether or not the database supports batch updates. - * - * @return <code>true</code> if batch updates are supported, - * <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean supportsBatchUpdates() throws SQLException; - - /** - * This method returns the list of user defined data types in use. These - * are returned as a <code>ResultSet</code> with the following columns: - * - * <ol> - * <li>TYPE_CAT - The catalog name, which may be <code>null</code>.</li> - * <li>TYPE_SCEHM - The schema name, which may be <code>null</code>.</li> - * <li>TYPE_NAME - The user defined data type name.</li> - * <li>CLASS_NAME - The Java class name this type maps to.</li> - * <li>DATA_TYPE - A type identifier from <code>Types</code> for this type. - * This will be one of <code>JAVA_OBJECT</code>, <code>STRUCT</code>, or - * <code>DISTINCT</code>.</li> - * <li>REMARKS - Comments about this data type.</li> - * </ol> - * - * @param catalog The catalog to retrieve information from, or the empty string - * to return entities not associated with a catalog, or <code>null</code> - * to return information from all catalogs. - * @param schema The schema to retrieve information from, or the empty string - * to return entities not associated with a schema. - * @param typePattern The type name pattern to match. - * @param types The type identifier patterns (from <code>Types</code>) to - * match. - * @return A <code>ResultSet</code> with the requested type information - * @exception SQLException If an error occurs. - */ - ResultSet getUDTs(String catalog, String schemaPattern, String - typeNamePattern, int[] types) throws SQLException; - - /** - * This method returns the <code>Connection</code> object that was used - * to generate the metadata in this object. - * - * @return The connection for this object. - * @exception SQLException If an error occurs. - */ - Connection getConnection() throws SQLException; - - /** - * @since 1.4 - */ - boolean supportsSavepoints() throws SQLException; - - /** - * @since 1.4 - */ - boolean supportsNamedParameters() throws SQLException; - - /** - * @since 1.4 - */ - boolean supportsMultipleOpenResults() throws SQLException; - - /** - * @since 1.4 - */ - boolean supportsGetGeneratedKeys() throws SQLException; - - /** - * @since 1.4 - */ - ResultSet getSuperTypes(String catalog, String schemaPattern, - String typeNamePattern) throws SQLException; - - /** - * @since 1.4 - */ - ResultSet getSuperTables(String catalog, String schemaPattern, - String tableNamePattern) throws SQLException; - - /** - * @since 1.4 - */ - ResultSet getAttributes(String catalog, String schemaPattern, String - typeNamePattern, String attributeNamePattern) throws SQLException; - - /** - * @since 1.4 - */ - boolean supportsResultSetHoldability(int holdability) - throws SQLException; - - /** - * @since 1.4 - */ - int getResultSetHoldability() throws SQLException; - - /** - * @since 1.4 - */ - int getDatabaseMajorVersion() throws SQLException; - - /** - * @since 1.4 - */ - int getDatabaseMinorVersion() throws SQLException; - - /** - * @since 1.4 - */ - int getJDBCMajorVersion() throws SQLException; - - /** - * @since 1.4 - */ - int getJDBCMinorVersion() throws SQLException; - - /** - * @since 1.4 - */ - int getSQLStateType() throws SQLException; - - /** - * @since 1.4 - */ - boolean locatorsUpdateCopy() throws SQLException; - - /** - * @since 1.4 - */ - boolean supportsStatementPooling() throws SQLException; -} diff --git a/libjava/java/sql/Date.java b/libjava/java/sql/Date.java deleted file mode 100644 index 48a274f331e..00000000000 --- a/libjava/java/sql/Date.java +++ /dev/null @@ -1,188 +0,0 @@ -/* Date.java -- Wrapper around java.util.Date - Copyright (C) 1999, 2000, 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.sql; - -import java.text.ParseException; -import java.text.SimpleDateFormat; - -/** - * This class is a wrapper around java.util.Date to allow the JDBC - * driver to identify the value as a SQL Date. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public class Date extends java.util.Date -{ - static final long serialVersionUID = 1511598038487230103L; - - /** - * Used for parsing and formatting this date. - */ - private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); - - /** - * This method initializes a new instance of this class with the - * specified year, month, and day. - * - * @param year The year of this date minue 1900. - * @param month The month of this date (0-11). - * @param day The day of this date (1-31). - * - * @deprecated - */ - public Date(int year, int month, int day) - { - super(year, month, day); - } - - /** - * This method initializes a new instance of this class with the - * specified time value representing the number of seconds since - * Jan 1, 1970 at 12:00 midnight GMT. - * - * @param time The time value to intialize this date to. - */ - public Date(long date) - { - super(date); - } - - /** - * This method always throws an IllegalArgumentException. - * - * @throws IllegalArgumentException when it's called. - * @deprecated - */ - public int getHours() throws IllegalArgumentException - { - throw new IllegalArgumentException(); - } - - /** - * This method always throws an IllegalArgumentException. - * - * @throws IllegalArgumentException when it's called. - * @deprecated - */ - public int getMinutes() throws IllegalArgumentException - { - throw new IllegalArgumentException(); - } - - /** - * This method always throws an IllegalArgumentException. - * - * @throws IllegalArgumentException when it's called. - * @deprecated - */ - public int getSeconds() throws IllegalArgumentException - { - throw new IllegalArgumentException(); - } - - /** - * This method always throws an IllegalArgumentException. - * - * @throws IllegalArgumentException when it's called. - * @deprecated - */ - public void setHours(int newValue) throws IllegalArgumentException - { - throw new IllegalArgumentException(); - } - - /** - * This method always throws an IllegalArgumentException. - * - * @throws IllegalArgumentException when it's called. - * @deprecated - */ - public void setMinutes(int newValue) throws IllegalArgumentException - { - throw new IllegalArgumentException(); - } - - /** - * This method always throws an IllegalArgumentException. - * - * @throws IllegalArgumentException when it's called. - * @deprecated - */ - public void setSeconds(int newValue) throws IllegalArgumentException - { - throw new IllegalArgumentException(); - } - - /** - * This method returns a new instance of this class by parsing a - * date in JDBC format into a Java date. - * - * @param str The string to parse. - * @return The resulting <code>java.sql.Date</code> value. - * - * @deprecated - */ - public static Date valueOf (String str) - { - try - { - java.util.Date d = (java.util.Date) sdf.parseObject(str); - - if (d == null) - throw new IllegalArgumentException(str); - else - return new Date(d.getTime()); - } - catch (ParseException e) - { - throw new IllegalArgumentException(str); - } - } - - /** - * This method returns this date in JDBC format. - * - * @return This date as a string. - * - * @deprecated - */ - public String toString() - { - return sdf.format(this); - } -} diff --git a/libjava/java/sql/Driver.java b/libjava/java/sql/Driver.java deleted file mode 100644 index 10f83ef2f8b..00000000000 --- a/libjava/java/sql/Driver.java +++ /dev/null @@ -1,123 +0,0 @@ -/* Driver.java -- A JDBC driver - Copyright (C) 1999, 2000 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.sql; - -import java.util.Properties; - -/** - * This interface specifies a mechanism for accessing a JDBC database - * driver. When the class implementing this method is loaded, it should - * register an instance of itself with the <code>DriverManager</code> in - * a static initializer. - * <p> - * Because the <code>DriverManager</code> might attempt to use several - * drivers to find one that can connect to the requested database, - * this driver should not cause large numbers of classes and code to - * be loaded. If another driver is the one that ends up performing the - * request, any loading done by this driver would be wasted. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public interface Driver -{ - /** - * This method connects to the specified database using the connection - * properties supplied. If the driver does not understand the database - * URL, it should return <code>null</code> instead of throwing an - * exception since the <code>DriverManager</code> will probe a driver - * in this manner. - * - * @param url The URL string for this connection. - * @param properties The list of database connection properties. - * @return A <code>Connection</code> object for the newly established - * connection, or <code>null</code> if the URL is not understood. - * @exception SQLException If an error occurs. - */ - Connection connect(String url, Properties info) throws SQLException; - - /** - * This method tests whether or not the driver believes it can connect to - * the specified database. The driver should only test whether it - * understands and accepts the URL. It should not necessarily attempt to - * probe the database for a connection. - * - * @param The database URL string. - * @return <code>true</code> if the drivers can connect to the database, - * <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean acceptsURL(String url) throws SQLException; - - /** - * This method returns an array of possible properties that could be - * used to connect to the specified database. - * - * @param url The URL string of the database to connect to. - * @param properties The list of properties the caller is planning to use - * to connect to the database. - * @return A list of possible additional properties for a connection to this - * database. This list may be empty. - * @exception SQLException If an error occurs. - */ - DriverPropertyInfo[] getPropertyInfo(String url, Properties properties) - throws SQLException; - - /** - * This method returns the major version number of the driver. - * - * @return The major version number of the driver. - */ - int getMajorVersion(); - - /** - * This method returns the minor version number of the driver. - * - * @return The minor version number of the driver. - */ - int getMinorVersion(); - - /** - * This method tests whether or not the driver is JDBC compliant. This - * method should only return <code>true</code> if the driver has been - * certified as JDBC compliant. - * - * @return <code>true</code> if the driver has been certified JDBC compliant, - * <code>false</code> otherwise. - */ - boolean jdbcCompliant(); -} diff --git a/libjava/java/sql/DriverManager.java b/libjava/java/sql/DriverManager.java deleted file mode 100644 index 9e252abcc60..00000000000 --- a/libjava/java/sql/DriverManager.java +++ /dev/null @@ -1,346 +0,0 @@ -/* DriverManager.java -- Manage JDBC drivers - Copyright (C) 1999, 2000, 2001, 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.sql; - -import java.io.PrintStream; -import java.io.PrintWriter; -import java.util.Enumeration; -import java.util.Properties; -import java.util.StringTokenizer; -import java.util.Vector; - -/** - * This class manages the JDBC drivers in the system. It maintains a - * registry of drivers and locates the appropriate driver to handle a - * JDBC database URL. - * <p> - * On startup, <code>DriverManager</code> loads all the managers specified - * by the system property <code>jdbc.drivers</code>. The value of this - * property should be a colon separated list of fully qualified driver - * class names. Additional drivers can be loaded at any time by - * simply loading the driver class with <code>class.forName(String)</code>. - * The driver should automatically register itself in a static - * initializer. - * <p> - * The methods in this class are all <code>static</code>. This class - * cannot be instantiated. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public class DriverManager -{ - /** - * This is the log stream for JDBC drivers. - */ - private static PrintStream log_stream; - - /** - * This is the log writer for JDBC drivers. - */ - private static PrintWriter log_writer; - - /** - * This is the login timeout used by JDBC drivers. - */ - private static int login_timeout; - - /** - * This is the list of JDBC drivers that are loaded. - */ - private static Vector drivers; - // Hmm, seems like we might want to do a Hashtable and lookup by something, - // but what would it be? - - // Load all drivers on startup - static - { - drivers = new Vector(); - - String driver_string = System.getProperty("jdbc.drivers"); - if (driver_string != null) - { - StringTokenizer st = new StringTokenizer(driver_string); - while (st.hasMoreTokens()) - { - String driver_classname = st.nextToken(); - - try - { - Class.forName(driver_classname); // The driver registers itself - } - catch (Exception e) - { - // Ignore not founds - } - } - } - - } - - /** Can't be instantiated. */ - private DriverManager() - { - } - - /** - * This method returns the log writer being used by all JDBC drivers. - * This method should be used in place of the deprecated - * <code>getLogStream</code> method. - * - * @return The log writer in use by JDBC drivers. - */ - public static PrintWriter getLogWriter() - { - return log_writer; - } - - /** - * This method sets the log writer being used by JDBC drivers. This is a - * system-wide parameter that affects all drivers. Note that since there - * is no way to retrieve a <code>PrintStream</code> from a - * <code>PrintWriter</code>, this method cannot set the log stream in - * use by JDBC. Thus any older drivers may not see this setting. - * - * @param out The new log writer for JDBC. - */ - public static void setLogWriter(PrintWriter out) - { - DriverManager.log_writer = out; - } - -/** - * This method attempts to return a connection to the specified - * JDBC URL string using the specified connection properties. - * - * @param url The JDBC URL string to connect to. - * @param properties The connection properties. - * - * @return A <code>Connection</code> to that URL. - * - * @exception SQLException If an error occurs. - */ - public static Connection getConnection(String url, Properties properties) - throws SQLException - { - Driver d = getDriver(url); - if (d == null) - throw new SQLException("Driver not found for URL: " + url); - - return d.connect(url, properties); - } - - - /** - * This method attempts to return a connection to the specified - * JDBC URL string using the specified username and password. - * - * @param url The JDBC URL string to connect to. - * @param user The username to connect with. - * @param password The password to connect with. - * @return A <code>Connection</code> to that URL. - * @exception SQLException If an error occurs. - */ - public static Connection getConnection(String url, String user, - String password) throws SQLException - { - Properties p = new Properties(); - - if (user != null) - p.setProperty("user", user); - if (password != null) - p.setProperty("password", password); - - return getConnection(url, p); - } - - /** - * This method attempts to return a connection to the specified - * JDBC URL string. - * - * @param url The JDBC URL string to connect to. - * - * @return A <code>Connection</code> to that URL. - * - * @exception SQLException If an error occurs. - */ - public static Connection getConnection(String url) throws SQLException - { - return getConnection(url, new Properties()); - } - - /** - * This method returns a driver that can connect to the specified - * JDBC URL string. This will be selected from among drivers loaded - * at initialization time and those drivers manually loaded by the - * same class loader as the caller. - * - * @param url The JDBC URL string to find a driver for. - * - * @return A <code>Driver</code> that can connect to the specified - * URL. - * - * @exception SQLException If an error occurs, or no suitable driver can be found. - */ - public static Driver getDriver(String url) throws SQLException - { - // FIXME: Limit driver search to the appropriate subset of loaded drivers. - Enumeration e = drivers.elements(); - while(e.hasMoreElements()) - { - Driver d = (Driver)e.nextElement(); - if (d.acceptsURL(url)) - return d; - } - - throw new SQLException("No driver found for " + url); - } - - /** - * This method registers a new driver with the manager. This is normally - * called by the driver itself in a static initializer. - * - * @param driver The new <code>Driver</code> to add. - * - * @exception SQLException If an error occurs. - */ - public static void registerDriver(Driver driver) throws SQLException - { - if (! drivers.contains(driver)) - drivers.addElement(driver); - } - -/** - * This method de-registers a driver from the manager. - * - * @param driver The <code>Driver</code> to unregister. - * - * @exception SQLException If an error occurs. - */ - public static void deregisterDriver(Driver driver) throws SQLException - { - if (drivers.contains(driver)) - drivers.removeElement(driver); - } - - /** - * This method returns a list of all the currently registered JDBC drivers - * that were loaded by the current <code>ClassLoader</code>. - * - * @return An <code>Enumeration</code> of all currently loaded JDBC drivers. - */ - public static Enumeration getDrivers() - { - Vector v = new Vector(); - Enumeration e = drivers.elements(); - - // Is this right? - ClassLoader cl = Thread.currentThread().getContextClassLoader(); - - while(e.hasMoreElements()) - { - Object obj = e.nextElement(); - - ClassLoader loader = obj.getClass().getClassLoader(); - - if (loader == null) - loader = ClassLoader.getSystemClassLoader(); - if (! loader.equals(cl)) - continue; - - v.addElement(obj); - } - - return v.elements(); - } - - /** - * This method set the login timeout used by JDBC drivers. This is a - * system-wide parameter that applies to all drivers. - * - * @param login_timeout The new login timeout value. - */ - public static void setLoginTimeout(int seconds) - { - DriverManager.login_timeout = login_timeout; - } - - /** - * This method returns the login timeout in use by JDBC drivers systemwide. - * - * @return The login timeout. - */ - public static int getLoginTimeout() - { - return login_timeout; - } - - /** - * This method sets the log stream in use by JDBC. - * - * @param log_stream The log stream in use by JDBC. - * - * @deprecated Use <code>setLogWriter</code> instead. - */ - public static void setLogStream(PrintStream out) - { - DriverManager.log_stream = log_stream; - } - - /** - * This method returns the log stream in use by JDBC. - * - * @return The log stream in use by JDBC. - * - * @deprecated Use <code>getLogWriter()</code> instead. - */ - public static PrintStream getLogStream() - { - return log_stream; - } - - /** - * This method prints the specified line to the log stream. - * - * @param str The string to write to the log stream. - */ - public static void println(String message) - { - if (log_stream != null) // Watch for user not using logging - log_stream.println(message); - } -} diff --git a/libjava/java/sql/DriverPropertyInfo.java b/libjava/java/sql/DriverPropertyInfo.java deleted file mode 100644 index 34e40fa0c3e..00000000000 --- a/libjava/java/sql/DriverPropertyInfo.java +++ /dev/null @@ -1,88 +0,0 @@ -/* DriverPropertyInfo.java -- Property information about drivers. - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.sql; - -/** - * This class holds a driver property that can be used for querying or - * setting driver configuration parameters. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public class DriverPropertyInfo -{ - /** - * The name of the property. - */ - public String name; - - /** - * A description of the property, possibly <code>null</code>. - */ - public String description; - - /** - * A flag indicating whether or not a value for this property is required - * in order to connect to the database. - */ - public boolean required; - - /** - * This is the value of the property. - */ - public String value; - - /** - * If values are restricted to certain choices, this is the list of valid - * ones. Otherwise it is <code>null</code>. - */ - public String[] choices; - - /** - * This method initializes a new instance of <code>DriverPropertyInfo</code> - * with the specified name and value. All other fields are defaulted. - * - * @param name The name of the property. - * @param value The value to assign to the property. - */ - public DriverPropertyInfo(String name, String value) - { - this.name = name; - this.value = value; - } -} diff --git a/libjava/java/sql/ParameterMetaData.java b/libjava/java/sql/ParameterMetaData.java deleted file mode 100644 index b3a75fd2058..00000000000 --- a/libjava/java/sql/ParameterMetaData.java +++ /dev/null @@ -1,103 +0,0 @@ -/* ParameterMetaData.java - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.sql; - -/** - * @since 1.4 - */ -public interface ParameterMetaData -{ - int parameterNoNulls = 0; - - int parameterNullable = 1; - - int parameterNullableUnknown = 2; - - int parameterModeUnknown = 0; - - int parameterModeIn = 1; - - int parameterModeInOut = 2; - - int parameterModeOut = 4; - - /** - * @since 1.4 - */ - int getParameterCount() throws SQLException; - - /** - * @since 1.4 - */ - int isNullable(int param) throws SQLException; - - /** - * @since 1.4 - */ - boolean isSigned(int param) throws SQLException; - - /** - * @since 1.4 - */ - int getPrecision(int param) throws SQLException; - - /** - * @since 1.4 - */ - int getScale(int param) throws SQLException; - - /** - * @since 1.4 - */ - int getParameterType(int param) throws SQLException; - - /** - * @since 1.4 - */ - String getParameterTypeName(int param) throws SQLException; - - /** - * @since 1.4 - */ - String getParameterClassName(int param) throws SQLException; - - /** - * @since 1.4 - */ - int getParameterMode(int param) throws SQLException; -} diff --git a/libjava/java/sql/PreparedStatement.java b/libjava/java/sql/PreparedStatement.java deleted file mode 100644 index 3aedbc59300..00000000000 --- a/libjava/java/sql/PreparedStatement.java +++ /dev/null @@ -1,438 +0,0 @@ -/* PreparedStatement.java -- Interface for pre-compiled statements. - Copyright (C) 1999, 2000 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.sql; - -import java.io.InputStream; -import java.io.Reader; -import java.math.BigDecimal; -import java.net.URL; -import java.util.Calendar; - -/** - * This interface provides a mechanism for executing pre-compiled - * statements. This provides greater efficiency when calling the same - * statement multiple times. Parameters are allowed in a statement, - * providings for maximum reusability. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public interface PreparedStatement extends Statement -{ - /** - * This method executes a prepared SQL query and returns its ResultSet. - * - * @return The ResultSet of the SQL statement. - * @exception SQLException If an error occurs. - */ - ResultSet executeQuery() throws SQLException; - - /** - * This method executes an SQL INSERT, UPDATE or DELETE statement. SQL - * statements that return nothing such as SQL DDL statements can be executed. - * - * @return The result is either the row count for INSERT, UPDATE or DELETE - * statements; or 0 for SQL statements that return nothing. - * @exception SQLException If an error occurs. - */ - int executeUpdate() throws SQLException; - - /** - * This method populates the specified parameter with a SQL NULL value - * for the specified type. - * - * @param index The index of the parameter to set. - * @param type The SQL type identifier of the parameter from <code>Types</code> - * - * @exception SQLException If an error occurs. - */ - void setNull(int parameterIndex, int sqlType) throws SQLException; - - /** - * This method sets the specified parameter from the given Java - * <code>boolean</code> value. - * - * @param index The index of the parameter value to set. - * @param value The value of the parameter. - * @exception SQLException If an error occurs. - */ - void setBoolean(int parameterIndex, boolean x) throws SQLException; - - /** - * This method sets the specified parameter from the given Java - * <code>byte</code> value. - * - * @param index The index of the parameter value to set. - * @param value The value of the parameter. - * @exception SQLException If an error occurs. - */ - void setByte(int parameterIndex, byte x) throws SQLException; - - /** - * This method sets the specified parameter from the given Java - * <code>short</code> value. - * - * @param index The index of the parameter value to set. - * @param value The value of the parameter. - * @exception SQLException If an error occurs. - */ - void setShort(int parameterIndex, short x) throws SQLException; - - /** - * This method sets the specified parameter from the given Java - * <code>int</code> value. - * - * @param index The index of the parameter value to set. - * @param value The value of the parameter. - * @exception SQLException If an error occurs. - */ - void setInt(int parameterIndex, int x) throws SQLException; - - /** - * This method sets the specified parameter from the given Java - * <code>long</code> value. - * - * @param index The index of the parameter value to set. - * @param value The value of the parameter. - * @exception SQLException If an error occurs. - */ - void setLong(int parameterIndex, long x) throws SQLException; - - /** - * This method sets the specified parameter from the given Java - * <code>float</code> value. - * - * @param index The index of the parameter value to set. - * @param value The value of the parameter. - * @exception SQLException If an error occurs. - */ - void setFloat(int parameterIndex, float x) throws SQLException; - - /** - * This method sets the specified parameter from the given Java - * <code>double</code> value. - * - * @param index The index of the parameter value to set. - * @param value The value of the parameter. - * @exception SQLException If an error occurs. - */ - void setDouble(int parameterIndex, double x) throws SQLException; - - /** - * This method sets the specified parameter from the given Java - * <code>java.math.BigDecimal</code> value. - * - * @param index The index of the parameter value to set. - * @param value The value of the parameter. - * @exception SQLException If an error occurs. - */ - void setBigDecimal(int parameterIndex, BigDecimal x) throws - SQLException; - - /** - * This method sets the specified parameter from the given Java - * <code>String</code> value. - * - * @param index The index of the parameter value to set. - * @param value The value of the parameter. - * @exception SQLException If an error occurs. - */ - void setString(int parameterIndex, String x) throws SQLException; - - /** - * This method sets the specified parameter from the given Java - * <code>byte</code> array value. - * - * @param index The index of the parameter value to set. - * @param value The value of the parameter. - * @exception SQLException If an error occurs. - */ - void setBytes(int parameterIndex, byte[] x) throws SQLException; - - /** - * This method sets the specified parameter from the given Java - * <code>java.sql.Date</code> value. - * - * @param index The index of the parameter value to set. - * @param value The value of the parameter. - * @exception SQLException If an error occurs. - */ - void setDate(int parameterIndex, Date x) throws SQLException; - - /** - * This method sets the specified parameter from the given Java - * <code>java.sql.Time</code> value. - * - * @param index The index of the parameter value to set. - * @param value The value of the parameter. - * @exception SQLException If an error occurs. - */ - void setTime(int parameterIndex, Time x) throws SQLException; - - /** - * This method sets the specified parameter from the given Java - * <code>java.sql.Timestamp</code> value. - * - * @param index The index of the parameter value to set. - * @param value The value of the parameter. - * @exception SQLException If an error occurs. - */ - void setTimestamp(int parameterIndex, Timestamp x) - throws SQLException; - - /** - * This method sets the specified parameter from the given Java - * ASCII <code>InputStream</code> value. - * - * @param index The index of the parameter value to set. - * @param value The value of the parameter. - * @param length The number of bytes in the stream. - * @exception SQLException If an error occurs. - */ - void setAsciiStream(int parameterIndex, InputStream x, int length) - throws SQLException; - - /** - * This method sets the specified parameter from the given Java - * Unicode UTF-8 <code>InputStream</code> value. - * - * @param index The index of the parameter value to set. - * @param value The value of the parameter. - * @param length The number of bytes in the stream. - * @exception SQLException If an error occurs. - * @deprecated - */ - void setUnicodeStream(int parameterIndex, InputStream x, int length) - throws SQLException; - - /** - * This method sets the specified parameter from the given Java - * binary <code>InputStream</code> value. - * - * @param index The index of the parameter value to set. - * @param value The value of the parameter. - * @param length The number of bytes in the stream. - * @exception SQLException If an error occurs. - */ - void setBinaryStream(int parameterIndex, InputStream x, int length) - throws SQLException; - - /** - * This method clears all of the input parameter that have been - * set on this statement. - * - * @exception SQLException If an error occurs. - */ - void clearParameters() throws SQLException; - - /** - * This method sets the specified parameter from the given Java - * <code>Object</code> value. The specified SQL object type will be used. - * - * @param index The index of the parameter value to set. - * @param value The value of the parameter. - * @param type The SQL type to use for the parameter, from <code>Types</code> - * @param scale The scale of the value, for numeric values only. - * @exception SQLException If an error occurs. - * @see Types - */ - void setObject(int parameterIndex, Object x, int targetSqlType, - int scale) throws SQLException; - - /** - * This method sets the specified parameter from the given Java - * <code>Object</code> value. The specified SQL object type will be used. - * - * @param index The index of the parameter value to set. - * @param value The value of the parameter. - * @param type The SQL type to use for the parameter, from <code>Types</code> - * @exception SQLException If an error occurs. - * @see Types - */ - void setObject(int parameterIndex, Object x, int targetSqlType) - throws SQLException; - - /** - * This method sets the specified parameter from the given Java - * <code>Object</code> value. The default object type to SQL type mapping - * will be used. - * - * @param index The index of the parameter value to set. - * @param value The value of the parameter. - * @exception SQLException If an error occurs. - */ - void setObject(int parameterIndex, Object x) throws SQLException; - - /** - * This method executes a prepared SQL query. - * Some prepared statements return multiple results; the execute method - * handles these complex statements as well as the simpler form of - * statements handled by executeQuery and executeUpdate. - * - * @return The result of the SQL statement. - * @exception SQLException If an error occurs. - */ - boolean execute() throws SQLException; - - /** - * This method adds a set of parameters to the batch for JDBC 2.0. - * @exception SQLException If an error occurs. - */ - void addBatch() throws SQLException; - - /** - * This method sets the specified parameter from the given Java - * character <code>Reader</code> value. - * - * @param index The index of the parameter value to set. - * @param value The value of the parameter. - * @param length The number of bytes in the stream. - * @exception SQLException If an error occurs. - */ - void setCharacterStream(int parameterIndex, Reader reader, - int length) throws SQLException; - - /** - * This method sets the specified parameter from the given Java - * <code>Ref</code> value. The default object type to SQL type mapping - * will be used. - * - * @param index The index of the parameter value to set. - * @param value The value of the parameter. - * @exception SQLException If an error occurs. - */ - void setRef(int i, Ref x) throws SQLException; - - /** - * This method sets the specified parameter from the given Java - * <code>Blob</code> value. The default object type to SQL type mapping - * will be used. - * - * @param index The index of the parameter value to set. - * @param value The value of the parameter. - * @exception SQLException If an error occurs. - */ - void setBlob(int i, Blob x) throws SQLException; - - /** - * This method sets the specified parameter from the given Java - * <code>Clob</code> value. The default object type to SQL type mapping - * will be used. - * - * @param index The index of the parameter value to set. - * @param value The value of the parameter. - * @exception SQLException If an error occurs. - */ - void setClob(int i, Clob x) throws SQLException; - - /** - * This method sets the specified parameter from the given Java - * <code>Array</code> value. The default object type to SQL type mapping - * will be used. - * - * @param index The index of the parameter value to set. - * @param value The value of the parameter. - * @exception SQLException If an error occurs. - */ - void setArray(int i, Array x) throws SQLException; - - /** - * This method returns meta data for the result set from this statement. - * - * @return Meta data for the result set from this statement. - * @exception SQLException If an error occurs. - */ - ResultSetMetaData getMetaData() throws SQLException; - - /** - * This method sets the specified parameter from the given Java - * <code>java.sql.Date</code> value. - * - * @param index The index of the parameter value to set. - * @param value The value of the parameter. - * @param calendar The <code>Calendar</code> to use for timezone and locale. - * @exception SQLException If an error occurs. - */ - void setDate(int parameterIndex, Date x, Calendar cal) - throws SQLException; - - /** - * This method sets the specified parameter from the given Java - * <code>java.sql.Time</code> value. - * - * @param index The index of the parameter value to set. - * @param value The value of the parameter. - * @param calendar The <code>Calendar</code> to use for timezone and locale. - * @exception SQLException If an error occurs. - */ - void setTime(int parameterIndex, Time x, Calendar cal) - throws SQLException; - - /** - * This method sets the specified parameter from the given Java - * <code>java.sql.Timestamp</code> value. - * - * @param index The index of the parameter value to set. - * @param value The value of the parameter. - * @param calendar The <code>Calendar</code> to use for timezone and locale. - * @exception SQLException If an error occurs. - */ - void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) - throws SQLException; - - /** - * This method populates the specified parameter with a SQL NULL value - * for the specified type. - * - * @param index The index of the parameter to set. - * @param type The SQL type identifier of the parameter from <code>Types</code> - * @param name The name of the data type, for user defined types. - * @exception SQLException If an error occurs. - */ - void setNull(int paramIndex, int sqlType, String typeName) - throws SQLException; - - /** - * @since 1.4 - */ - void setURL(int parameterIndex, URL x) throws SQLException; - - /** - * @since 1.4 - */ - ParameterMetaData getParameterMetaData() throws SQLException; -} diff --git a/libjava/java/sql/Ref.java b/libjava/java/sql/Ref.java deleted file mode 100644 index 4ebd5e64898..00000000000 --- a/libjava/java/sql/Ref.java +++ /dev/null @@ -1,75 +0,0 @@ -/* Ref.java -- Reference to a SQL structured type. - Copyright (C) 1999, 2000 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.sql; - -import java.util.Map; - -/** - * This interface provides a mechanism for obtaining information about - * a SQL structured type - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @since 1.2 - */ -public interface Ref -{ - /** - * This method returns the fully qualified name of the SQL structured - * type of the referenced item. - * - * @return The fully qualified name of the SQL structured type. - * @exception SQLException If an error occurs. - * @since 1.2 - */ - String getBaseTypeName() throws SQLException; - - /** - * @since 1.4 - */ - Object getObject(Map map) throws SQLException; - - /** - * @since 1.4 - */ - Object getObject() throws SQLException; - - /** - * @since 1.4 - */ - void setObject(Object value) throws SQLException; -} diff --git a/libjava/java/sql/ResultSet.java b/libjava/java/sql/ResultSet.java deleted file mode 100644 index 97f2897d423..00000000000 --- a/libjava/java/sql/ResultSet.java +++ /dev/null @@ -1,1530 +0,0 @@ -/* ResultSet.java -- A SQL statement result set. - Copyright (C) 1999, 2000, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.sql; - -import java.io.InputStream; -import java.io.Reader; -import java.math.BigDecimal; -import java.net.URL; -import java.util.Calendar; -import java.util.Map; - -/** - * This interface provides access to the data set returned by a SQL - * statement. An instance of this interface is returned by the various - * execution methods in the <code>Statement</code>. - * - * <p> This class models a cursor, which can be stepped through one row at a - * time. Methods are provided for accessing columns by column name or by - * index.</p> - * - * <p> Note that a result set is invalidated if the statement that returned - * it is closed.</p> - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public interface ResultSet -{ - /** - * The rows will be processed in order from first to last. - */ - int FETCH_FORWARD = 1000; - - /** - * The rows will be processed in order from last to first. - */ - int FETCH_REVERSE = 1001; - - /** - * The rows will be processed in an unknown order - */ - int FETCH_UNKNOWN = 1002; - - /** - * This type of result set may only step forward through the rows returned. - */ - int TYPE_FORWARD_ONLY = 1003; - - /** - * This type of result set is scrollable and is not sensitive to changes - * made by other statements. - */ - int TYPE_SCROLL_INSENSITIVE = 1004; - - /** - * This type of result set is scrollable and is also sensitive to changes - * made by other statements. - */ - int TYPE_SCROLL_SENSITIVE = 1005; - - /** - * The concurrency mode of for the result set may not be modified. - */ - int CONCUR_READ_ONLY = 1007; - - /** - * The concurrency mode of for the result set may be modified. - */ - int CONCUR_UPDATABLE = 1008; - - int HOLD_CURSORS_OVER_COMMIT = 1; - - int CLOSE_CURSORS_AT_COMMIT = 2; - - /** - * This method advances to the next row in the result set. Any streams - * open on the current row are closed automatically. - * - * @return <code>true</code> if the next row exists, <code>false</code> - * otherwise. - * @exception SQLException If an error occurs. - */ - boolean next() throws SQLException; - - /** - * This method closes the result set and frees any associated resources. - * - * @exception SQLException If an error occurs. - */ - void close() throws SQLException; - - /** - * This method tests whether the value of the last column that was fetched - * was actually a SQL NULL value. - * - * @return <code>true</code> if the last column fetched was a NULL, - * <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean wasNull() throws SQLException; - - /** - * This method returns the value of the specified column as a Java - * <code>String</code>. - * - * @param index The index of the column to return. - * @return The column value as a <code>String</code>. - * @exception SQLException If an error occurs. - */ - String getString(int columnIndex) throws SQLException; - - /** - * This method returns the value of the specified column as a Java - * <code>boolean</code>. - * - * @param index The index of the column to return. - * @return The column value as a <code>boolean</code>. - * @exception SQLException If an error occurs. - */ - boolean getBoolean(int columnIndex) throws SQLException; - - /** - * This method returns the value of the specified column as a Java - * <code>byte</code>. - * - * @param index The index of the column to return. - * @return The column value as a <code>byte</code>. - * @exception SQLException If an error occurs. - */ - byte getByte(int columnIndex) throws SQLException; - - /** - * This method returns the value of the specified column as a Java - * <code>short</code>. - * - * @param index The index of the column to return. - * @return The column value as a <code>short</code>. - * @exception SQLException If an error occurs. - */ - short getShort(int columnIndex) throws SQLException; - - /** - * This method returns the value of the specified column as a Java - * <code>int</code>. - * - * @param index The index of the column to return. - * @return The column value as a <code>int</code>. - * @exception SQLException If an error occurs. - */ - int getInt(int columnIndex) throws SQLException; - - /** - * This method returns the value of the specified column as a Java - * <code>long</code>. - * - * @param index The index of the column to return. - * @return The column value as a <code>long</code>. - * @exception SQLException If an error occurs. - */ - long getLong(int columnIndex) throws SQLException; - - /** - * This method returns the value of the specified column as a Java - * <code>float</code>. - * - * @param index The index of the column to return. - * @return The column value as a <code>float</code>. - * @exception SQLException If an error occurs. - */ - float getFloat(int columnIndex) throws SQLException; - - /** - * This method returns the value of the specified column as a Java - * <code>double</code>. - * - * @param index The index of the column to return. - * @return The column value as a <code>double</code>. - * @exception SQLException If an error occurs. - */ - double getDouble(int columnIndex) throws SQLException; - - /** - * This method returns the value of the specified column as a Java - * <code>BigDecimal</code>. - * - * @param index The index of the column to return. - * @param scale The number of digits to the right of the decimal to return. - * @return The column value as a <code>BigDecimal</code>. - * @exception SQLException If an error occurs. - * @deprecated - */ - BigDecimal getBigDecimal(int columnIndex, int scale) - throws SQLException; - - /** - * This method returns the value of the specified column as a Java - * byte array. - * - * @param index The index of the column to return. - * @return The column value as a byte array - * @exception SQLException If an error occurs. - */ - byte[] getBytes(int columnIndex) throws SQLException; - - /** - * This method returns the value of the specified column as a Java - * <code>java.sql.Date</code>. - * - * @param index The index of the column to return. - * @return The column value as a <code>java.sql.Date</code>. - * @exception SQLException If an error occurs. - */ - Date getDate(int columnIndex) throws SQLException; - - /** - * This method returns the value of the specified column as a Java - * <code>java.sql.Time</code>. - * - * @param index The index of the column to return. - * @return The column value as a <code>java.sql.Time</code>. - * @exception SQLException If an error occurs. - */ - Time getTime(int columnIndex) throws SQLException; - - /** - * This method returns the value of the specified column as a Java - * <code>java.sql.Timestamp</code>. - * - * @param index The index of the column to return. - * @return The column value as a <code>java.sql.Timestamp</code>. - * @exception SQLException If an error occurs. - */ - Timestamp getTimestamp(int columnIndex) throws SQLException; - - /** - * This method returns the value of the specified column as an ASCII - * stream. Note that all the data from this stream must be read before - * fetching the value of any other column. Please also be aware that - * calling <code>next()</code> or <code>close()</code> on this result set - * will close this stream as well. - * - * @param index The index of the column to return. - * @return The column value as an ASCII <code>InputStream</code>. - * @exception SQLException If an error occurs. - */ - InputStream getAsciiStream(int columnIndex) throws SQLException; - - /** - * This method returns the value of the specified column as a Unicode UTF-8 - * stream. Note that all the data from this stream must be read before - * fetching the value of any other column. Please also be aware that - * calling <code>next()</code> or <code>close()</code> on this result set - * will close this stream as well. - * - * @param index The index of the column to return. - * @return The column value as a Unicode UTF-8 <code>InputStream</code>. - * @exception SQLException If an error occurs. - * @deprecated Use getCharacterStream instead. - */ - InputStream getUnicodeStream(int columnIndex) throws SQLException; - - /** - * This method returns the value of the specified column as a raw byte - * stream. Note that all the data from this stream must be read before - * fetching the value of any other column. Please also be aware that - * calling <code>next()</code> or <code>close()</code> on this result set - * will close this stream as well. - * - * @param index The index of the column to return. - * @return The column value as a raw byte <code>InputStream</code>. - * @exception SQLException If an error occurs. - */ - InputStream getBinaryStream(int columnIndex) throws SQLException; - - /** - * This method returns the value of the specified column as a Java - * <code>String</code>. - * - * @param column The name of the column to return. - * @return The column value as a <code>String</code>. - * @exception SQLException If an error occurs. - */ - String getString(String columnName) throws SQLException; - - /** - * This method returns the value of the specified column as a Java - * <code>boolean</code>. - * - * @param column The name of the column to return. - * @return The column value as a <code>boolean</code>. - * @exception SQLException If an error occurs. - */ - boolean getBoolean(String columnName) throws SQLException; - - /** - * This method returns the value of the specified column as a Java - * <code>byte</code>. - * - * @param column The name of the column to return. - * @return The column value as a <code>byte</code>. - * @exception SQLException If an error occurs. - */ - byte getByte(String columnName) throws SQLException; - - /** - * This method returns the value of the specified column as a Java - * <code>short</code>. - * - * @param column The name of the column to return. - * @return The column value as a <code>short</code>. - * @exception SQLException If an error occurs. - */ - short getShort(String columnName) throws SQLException; - - /** - * This method returns the value of the specified column as a Java - * <code>int</code>. - * - * @param column The name of the column to return. - * @return The column value as a <code>int</code>. - * @exception SQLException If an error occurs. - */ - int getInt(String columnName) throws SQLException; - - /** - * This method returns the value of the specified column as a Java - * <code>long</code>. - * - * @param column The name of the column to return. - * @return The column value as a <code>long</code>. - * @exception SQLException If an error occurs. - */ - long getLong(String columnName) throws SQLException; - - /** - * This method returns the value of the specified column as a Java - * <code>float</code>. - * - * @param column The name of the column to return. - * @return The column value as a <code>float</code>. - * @exception SQLException If an error occurs. - */ - float getFloat(String columnName) throws SQLException; - - /** - * This method returns the value of the specified column as a Java - * <code>double</code>. - * - * @param column The name of the column to return. - * @return The column value as a <code>double</code>. - * @exception SQLException If an error occurs. - */ - double getDouble(String columnName) throws SQLException; - - /** - * This method returns the value of the specified column as a Java - * <code>BigDecimal</code>. - * - * @param index The index of the column to return. - * @return The column value as a <code>BigDecimal</code>. - * @exception SQLException If an error occurs. - * @deprecated - */ - BigDecimal getBigDecimal(String columnName, int scale) - throws SQLException; - - /** - * This method returns the value of the specified column as a Java - * byte array. - * - * @param column The name of the column to return. - * @return The column value as a byte array - * @exception SQLException If an error occurs. - */ - byte[] getBytes(String columnName) throws SQLException; - - /** - * This method returns the value of the specified column as a Java - * <code>java.sql.Date</code>. - * - * @param column The name of the column to return. - * @return The column value as a <code>java.sql.Date</code>. - * @exception SQLException If an error occurs. - */ - Date getDate(String columnName) throws SQLException; - - /** - * This method returns the value of the specified column as a Java - * <code>java.sql.Time</code>. - * - * @param column The name of the column to return. - * @return The column value as a <code>java.sql.Time</code>. - * @exception SQLException If an error occurs. - */ - Time getTime(String columnName) throws SQLException; - - /** - * This method returns the value of the specified column as a Java - * <code>java.sql.Timestamp</code>. - * - * @param column The name of the column to return. - * @return The column value as a <code>java.sql.Timestamp</code>. - * @exception SQLException If an error occurs. - */ - Timestamp getTimestamp(String columnName) throws SQLException; - - /** - * This method returns the value of the specified column as an ASCII - * stream. Note that all the data from this stream must be read before - * fetching the value of any other column. Please also be aware that - * calling <code>next()</code> or <code>close()</code> on this result set - * will close this stream as well. - * - * @param column The name of the column to return. - * @return The column value as an ASCII <code>InputStream</code>. - * @exception SQLException If an error occurs. - */ - InputStream getAsciiStream(String columnName) throws SQLException; - - /** - * This method returns the value of the specified column as a Unicode UTF-8 - * stream. Note that all the data from this stream must be read before - * fetching the value of any other column. Please also be aware that - * calling <code>next()</code> or <code>close()</code> on this result set - * will close this stream as well. - * - * @param column The name of the column to return. - * @return The column value as a Unicode UTF-8 <code>InputStream</code>. - * @exception SQLException If an error occurs. - * @deprecated Use getCharacterStream instead. - */ - InputStream getUnicodeStream(String columnName) throws SQLException; - - /** - * This method returns the value of the specified column as a raw byte - * stream. Note that all the data from this stream must be read before - * fetching the value of any other column. Please also be aware that - * calling <code>next()</code> or <code>close()</code> on this result set - * will close this stream as well. - * - * @param column The name of the column to return. - * @return The column value as a raw byte <code>InputStream</code>. - * @exception SQLException If an error occurs. - */ - InputStream getBinaryStream(String columnName) throws SQLException; - - /** - * This method returns the first SQL warning associated with this result - * set. Any additional warnings will be chained to this one. - * - * @return The first SQLWarning for this result set, or <code>null</code> if - * there are no warnings. - * @exception SQLException If an error occurs. - */ - SQLWarning getWarnings() throws SQLException; - - /** - * This method clears all warnings associated with this result set. - * - * @exception SQLException If an error occurs. - */ - void clearWarnings() throws SQLException; - - /** - * This method returns the name of the database cursor used by this - * result set. - * - * @return The name of the database cursor used by this result set. - * @exception SQLException If an error occurs. - */ - String getCursorName() throws SQLException; - - /** - * This method returns data about the columns returned as part of the - * result set as a <code>ResultSetMetaData</code> instance. - * - * @return The <code>ResultSetMetaData</code> instance for this result set. - * @exception SQLException If an error occurs. - */ - ResultSetMetaData getMetaData() throws SQLException; - - /** - * This method returns the value of the specified column as a Java - * <code>Object</code>. - * - * @param index The index of the column to return. - * @return The column value as an <code>Object</code>. - * @exception SQLException If an error occurs. - */ - Object getObject(int columnIndex) throws SQLException; - - /** - * This method returns the value of the specified column as a Java - * <code>Object</code>. - * - * @param column The name of the column to return. - * @return The column value as an <code>Object</code>. - * @exception SQLException If an error occurs. - */ - Object getObject(String columnName) throws SQLException; - - /** - * This method returns the column index of the specified named column. - * - * @param column The name of the column. - * @return The index of the column. - * @exception SQLException If an error occurs. - */ - int findColumn(String columnName) throws SQLException; - - /** - * This method returns the value of the specified column as a character - * stream. Note that all the data from this stream must be read before - * fetching the value of any other column. Please also be aware that - * calling <code>next()</code> or <code>close()</code> on this result set - * will close this stream as well. - * - * @param index The index of the column to return. - * @return The column value as an character <code>Reader</code>. - * @exception SQLException If an error occurs. - */ - Reader getCharacterStream(int columnIndex) throws SQLException; - - /** - * This method returns the value of the specified column as a character - * stream. Note that all the data from this stream must be read before - * fetching the value of any other column. Please also be aware that - * calling <code>next()</code> or <code>close()</code> on this result set - * will close this stream as well. - * - * @param column The name of the column to return. - * @return The column value as an character <code>Reader</code>. - * @exception SQLException If an error occurs. - */ - Reader getCharacterStream(String columnName) throws SQLException; - - /** - * This method returns the value of the specified column as a Java - * <code>BigDecimal</code>. - * - * @param index The index of the column to return. - * @return The column value as a <code>BigDecimal</code>. - * @exception SQLException If an error occurs. - */ - BigDecimal getBigDecimal(int columnIndex) throws SQLException; - - /** - * This method returns the value of the specified column as a Java - * <code>BigDecimal</code>. - * - * @param column The name of the column to return. - * @return The column value as a <code>BigDecimal</code>. - * @exception SQLException If an error occurs. - */ - BigDecimal getBigDecimal(String columnName) throws SQLException; - - /** - * This method tests whether or not the cursor is before the first row - * in the result set. - * - * @return <code>true</code> if the cursor is positioned before the first - * row, <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean isBeforeFirst() throws SQLException; - - /** - * This method tests whether or not the cursor is after the last row - * in the result set. - * - * @return <code>true</code> if the cursor is positioned after the last - * row, <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean isAfterLast() throws SQLException; - - /** - * This method tests whether or not the cursor is positioned on the first - * row in the result set. - * - * @return <code>true</code> if the cursor is positioned on the first - * row, <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean isFirst() throws SQLException; - - /** - * This method tests whether or not the cursor is on the last row - * in the result set. - * - * @return <code>true</code> if the cursor is positioned on the last - * row, <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean isLast() throws SQLException; - - /** - * This method repositions the cursor to before the first row in the - * result set. - * - * @exception SQLException If an error occurs. - */ - void beforeFirst() throws SQLException; - - /** - * This method repositions the cursor to after the last row in the result - * set. - * - * @exception SQLException If an error occurs. - */ - void afterLast() throws SQLException; - - /** - * This method repositions the cursor on the first row in the - * result set. - * - * @return <code>true</code> if the cursor is on a valid row; - * <code>false</code> if there are no rows in the result set. - * @exception SQLException If an error occurs. - */ - boolean first() throws SQLException; - - /** - * This method repositions the cursor on the last row in the result - * set. - * - * @return <code>true</code> if the cursor is on a valid row; - * <code>false</code> if there are no rows in the result set. - * @exception SQLException If an error occurs. - */ - boolean last() throws SQLException; - - /** - * This method returns the current row number in the cursor. Numbering - * begins at index 1. - * - * @return The current row number, or 0 if there is not current row. - * @exception SQLException If an error occurs. - */ - int getRow() throws SQLException; - - /** - * This method positions the result set to the specified absolute row. - * Positive numbers are row offsets from the beginning of the result - * set (numbering starts from row 1) and negative numbers are row offsets - * from the end of the result set (numbering starts from -1). - * - * @param row The row to position the result set to. - * - * @return <code>true</code> if the current position was changed, - * <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean absolute(int row) throws SQLException; - - /** - * This method moves the result set position relative to the current row. - * The offset can be positive or negative. - * - * @param row The relative row position to move to. - * @return <code>true</code> if the current position was changed, - * <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean relative(int rows) throws SQLException; - - /** - * This method moves the current position to the previous row in the - * result set. - * - * @return <code>true</code> if the previous row exists, <code>false</code> - * otherwise. - * @exception SQLException If an error occurs. - */ - boolean previous() throws SQLException; - - /** - * This method provides a hint to the driver about which direction the - * result set will be processed in. - * - * @param direction The direction in which rows will be processed. (Values?) - * @exception SQLException If an error occurs. - */ - void setFetchDirection(int direction) throws SQLException; - - /** - * This method returns the current fetch direction for this result set. - * - * @return The fetch direction for this result set. - * @exception SQLException If an error occurs. - */ - int getFetchDirection() throws SQLException; - - /** - * This method provides a hint to the driver about how many rows at a - * time it should fetch from the database. - * - * @param rows The number of rows the driver should fetch per call. - * @exception SQLException If an error occurs. - */ - void setFetchSize(int rows) throws SQLException; - - /** - * This method returns the current number of rows that will be fetched - * from the database at a time. - * - * @return The current fetch size for this result set. - * @exception SQLException If an error occurs. - */ - int getFetchSize() throws SQLException; - - /** - * This method returns the result set type of this result set. This will - * be one of the TYPE_* constants defined in this interface. - * - * @return The result set type. - * @exception SQLException If an error occurs. - */ - int getType() throws SQLException; - - /** - * This method returns the concurrency type of this result set. This will - * be one of the CONCUR_* constants defined in this interface. - * - * @return The result set concurrency type. - * @exception SQLException If an error occurs. - */ - int getConcurrency() throws SQLException; - - /** - * This method tests whether or not the current row in the result set - * has been updated. Updates must be visible in order of this method to - * detect the update. - * - * @return <code>true</code> if the row has been updated, <code>false</code> - * otherwise. - * @exception SQLException If an error occurs. - */ - boolean rowUpdated() throws SQLException; - - /** - * This method tests whether or not the current row in the result set - * has been inserted. Inserts must be visible in order of this method to - * detect the insert. - * - * @return <code>true</code> if the row has been inserted, <code>false</code> - * otherwise. - * @exception SQLException If an error occurs. - */ - boolean rowInserted() throws SQLException; - - /** - * This method tests whether or not the current row in the result set - * has been deleted. Deletes must be visible in order of this method to - * detect the deletion. - * - * @return <code>true</code> if the row has been deleted, <code>false</code> - * otherwise. - * @exception SQLException If an error occurs. - */ - boolean rowDeleted() throws SQLException; - - /** - * This method updates the specified column to have a NULL value. This - * does not update the actual database. <code>updateRow</code> must be - * called in order to do that. - * - * @return index The index of the column to update. - * @exception SQLException If an error occurs. - */ - void updateNull(int columnIndex) throws SQLException; - - /** - * This method updates the specified column to have a boolean value. This - * does not update the actual database. <code>updateRow</code> must be - * called in order to do that. - * - * @param index The index of the column to update. - * @param value The new value of the column. - * @exception SQLException If an error occurs. - */ - void updateBoolean(int columnIndex, boolean x) throws SQLException; - - /** - * This method updates the specified column to have a byte value. This - * does not update the actual database. <code>updateRow</code> must be - * called in order to do that. - * - * @param index The index of the column to update. - * @param value The new value of the column. - * @exception SQLException If an error occurs. - */ - void updateByte(int columnIndex, byte x) throws SQLException; - - /** - * This method updates the specified column to have a short value. This - * does not update the actual database. <code>updateRow</code> must be - * called in order to do that. - * - * @param index The index of the column to update. - * @param value The new value of the column. - * @exception SQLException If an error occurs. - */ - void updateShort(int columnIndex, short x) throws SQLException; - - /** - * This method updates the specified column to have an int value. This - * does not update the actual database. <code>updateRow</code> must be - * called in order to do that. - * - * @param index The index of the column to update. - * @param value The new value of the column. - * @exception SQLException If an error occurs. - */ - void updateInt(int columnIndex, int x) throws SQLException; - - /** - * This method updates the specified column to have a long value. This - * does not update the actual database. <code>updateRow</code> must be - * called in order to do that. - * - * @param index The index of the column to update. - * @param value The new value of the column. - * @exception SQLException If an error occurs. - */ - void updateLong(int columnIndex, long x) throws SQLException; - - /** - * This method updates the specified column to have a float value. This - * does not update the actual database. <code>updateRow</code> must be - * called in order to do that. - * - * @param index The index of the column to update. - * @param value The new value of the column. - * @exception SQLException If an error occurs. - */ - void updateFloat(int columnIndex, float x) throws SQLException; - - /** - * This method updates the specified column to have a double value. This - * does not update the actual database. <code>updateRow</code> must be - * called in order to do that. - * - * @param index The index of the column to update. - * @param value The new value of the column. - * @exception SQLException If an error occurs. - */ - void updateDouble(int columnIndex, double x) throws SQLException; - - /** - * This method updates the specified column to have a BigDecimal value. This - * does not update the actual database. <code>updateRow</code> must be - * called in order to do that. - * - * @param index The index of the column to update. - * @param value The new value of the column. - * @exception SQLException If an error occurs. - */ - void updateBigDecimal(int columnIndex, BigDecimal x) - throws SQLException; - - /** - * This method updates the specified column to have a String value. This - * does not update the actual database. <code>updateRow</code> must be - * called in order to do that. - * - * @param index The index of the column to update. - * @param value The new value of the column. - * @exception SQLException If an error occurs. - */ - void updateString(int columnIndex, String x) throws SQLException; - - /** - * This method updates the specified column to have a byte array value. This - * does not update the actual database. <code>updateRow</code> must be - * called in order to do that. - * - * @param index The index of the column to update. - * @param value The new value of the column. - * @exception SQLException If an error occurs. - */ - void updateBytes(int columnIndex, byte[] x) throws SQLException; - - /** - * This method updates the specified column to have a java.sql.Date value. This - * does not update the actual database. <code>updateRow</code> must be - * called in order to do that. - * - * @param index The index of the column to update. - * @param value The new value of the column. - * @exception SQLException If an error occurs. - */ - void updateDate(int columnIndex, Date x) throws SQLException; - - /** - * This method updates the specified column to have a java.sql.Time value. This - * does not update the actual database. <code>updateRow</code> must be - * called in order to do that. - * - * @param index The index of the column to update. - * @param value The new value of the column. - * @exception SQLException If an error occurs. - */ - void updateTime(int columnIndex, Time x) throws SQLException; - - /** - * This method updates the specified column to have a java.sql.Timestamp value. - * This does not update the actual database. <code>updateRow</code> must be - * called in order to do that. - * - * @param index The index of the column to update. - * @param value The new value of the column. - * @exception SQLException If an error occurs. - */ - void updateTimestamp(int columnIndex, Timestamp x) - throws SQLException; - - /** - * This method updates the specified column from an ASCII text stream. - * This does not update the actual database. <code>updateRow</code> must be - * called in order to do that. - * - * @param index The index of the column to update. - * @param value The new value of the column. - * @param length The length of the stream. - * @exception SQLException If an error occurs. - */ - void updateAsciiStream(int columnIndex, InputStream x, int length) - throws SQLException; - - /** - * This method updates the specified column from a binary stream. - * This does not update the actual database. <code>updateRow</code> must be - * called in order to do that. - * - * @param index The index of the column to update. - * @param value The new value of the column. - * @param length The length of the stream. - * @exception SQLException If an error occurs. - */ - void updateBinaryStream(int columnIndex, InputStream x, int length) - throws SQLException; - - /** - * This method updates the specified column from a character stream. - * This does not update the actual database. <code>updateRow</code> must be - * called in order to do that. - * - * @param index The index of the column to update. - * @param value The new value of the column. - * @param length The length of the stream. - * @exception SQLException If an error occurs. - */ - void updateCharacterStream(int columnIndex, Reader x, int length) - throws SQLException; - - /** - * This method updates the specified column to have an Object value. - * This does not update the actual database. <code>updateRow</code> must be - * called in order to do that. - * - * @param index The index of the column to update. - * @param value The new value of the column. - * - * @exception SQLException If an error occurs. - */ - void updateObject(int columnIndex, Object x, int scale) - throws SQLException; - - /** - * This method updates the specified column to have an Object value. - * This does not update the actual database. <code>updateRow</code> must be - * called in order to do that. - * - * @param index The index of the column to update. - * @param value The new value of the column. - * @param scale The scale of the object in question, which is used only - * for numeric type objects. - * @exception SQLException If an error occurs. - */ - void updateObject(int columnIndex, Object x) throws SQLException; - - /** - * This method updates the specified column to have a NULL value. This - * does not update the actual database. <code>updateRow</code> must be - * called in order to do that. - * - * @return name The name of the column to update. - * @exception SQLException If an error occurs. - */ - void updateNull(String columnName) throws SQLException; - - /** - * This method updates the specified column to have a boolean value. This - * does not update the actual database. <code>updateRow</code> must be - * called in order to do that. - * - * @param name The name of the column to update. - * @param value The new value of the column. - * @exception SQLException If an error occurs. - */ - void updateBoolean(String columnName, boolean x) throws SQLException; - - /** - * This method updates the specified column to have a byte value. This - * does not update the actual database. <code>updateRow</code> must be - * called in order to do that. - * - * @param name The name of the column to update. - * @param value The new value of the column. - * @exception SQLException If an error occurs. - */ - void updateByte(String columnName, byte x) throws SQLException; - - /** - * This method updates the specified column to have a short value. This - * does not update the actual database. <code>updateRow</code> must be - * called in order to do that. - * - * @param name The name of the column to update. - * @param value The new value of the column. - * @exception SQLException If an error occurs. - */ - void updateShort(String columnName, short x) throws SQLException; - - /** - * This method updates the specified column to have an int value. This - * does not update the actual database. <code>updateRow</code> must be - * called in order to do that. - * - * @param name The name of the column to update. - * @param value The new value of the column. - * @exception SQLException If an error occurs. - */ - void updateInt(String columnName, int x) throws SQLException; - - /** - * This method updates the specified column to have a long value. This - * does not update the actual database. <code>updateRow</code> must be - * called in order to do that. - * - * @param name The name of the column to update. - * @param value The new value of the column. - * @exception SQLException If an error occurs. - */ - void updateLong(String columnName, long x) throws SQLException; - - /** - * This method updates the specified column to have a float value. This - * does not update the actual database. <code>updateRow</code> must be - * called in order to do that. - * - * @param name The name of the column to update. - * @param value The new value of the column. - * @exception SQLException If an error occurs. - */ - void updateFloat(String columnName, float x) throws SQLException; - - /** - * This method updates the specified column to have a double value. This - * does not update the actual database. <code>updateRow</code> must be - * called in order to do that. - * - * @param name The name of the column to update. - * @param value The new value of the column. - * @exception SQLException If an error occurs. - */ - void updateDouble(String columnName, double x) throws SQLException; - - /** - * This method updates the specified column to have a BigDecimal value. This - * does not update the actual database. <code>updateRow</code> must be - * called in order to do that. - * - * @param name The name of the column to update. - * @param value The new value of the column. - * @exception SQLException If an error occurs. - */ - void updateBigDecimal(String columnName, BigDecimal x) - throws SQLException; - - /** - * This method updates the specified column to have a String value. This - * does not update the actual database. <code>updateRow</code> must be - * called in order to do that. - * - * @param name The name of the column to update. - * @param value The new value of the column. - * @exception SQLException If an error occurs. - */ - void updateString(String columnName, String x) throws SQLException; - - /** - * This method updates the specified column to have a byte array value. This - * does not update the actual database. <code>updateRow</code> must be - * called in order to do that. - * - * @param name The name of the column to update. - * @param value The new value of the column. - * @exception SQLException If an error occurs. - */ - void updateBytes(String columnName, byte[] x) throws SQLException; - - /** - * This method updates the specified column to have a java.sql.Date value. This - * does not update the actual database. <code>updateRow</code> must be - * called in order to do that. - * - * @param name The name of the column to update. - * @param value The new value of the column. - * @exception SQLException If an error occurs. - */ - void updateDate(String columnName, Date x) throws SQLException; - - /** - * This method updates the specified column to have a java.sql.Time value. This - * does not update the actual database. <code>updateRow</code> must be - * called in order to do that. - * - * @param name The name of the column to update. - * @param value The new value of the column. - * @exception SQLException If an error occurs. - */ - void updateTime(String columnName, Time x) throws SQLException; - - /** - * This method updates the specified column to have a java.sql.Timestamp value. - * This does not update the actual database. <code>updateRow</code> must be - * called in order to do that. - * - * @param name The name of the column to update. - * @param value The new value of the column. - * @exception SQLException If an error occurs. - */ - void updateTimestamp(String columnName, Timestamp x) - throws SQLException; - - /** - * This method updates the specified column from an ASCII text stream. - * This does not update the actual database. <code>updateRow</code> must be - * called in order to do that. - * - * @param name The name of the column to update. - * @param value The new value of the column. - * @param length The length of the stream. - * @exception SQLException If an error occurs. - */ - void updateAsciiStream(String columnName, InputStream x, int length) - throws SQLException; - - /** - * This method updates the specified column from a binary stream. - * This does not update the actual database. <code>updateRow</code> must be - * called in order to do that. - * - * @param name The name of the column to update. - * @param value The new value of the column. - * @param length The length of the stream. - * @exception SQLException If an error occurs. - */ - void updateBinaryStream(String columnName, InputStream x, int length) - throws SQLException; - - /** - * This method updates the specified column from a character stream. - * This does not update the actual database. <code>updateRow</code> must be - * called in order to do that. - * - * @param name The name of the column to update. - * @param value The new value of the column. - * @param length The length of the stream. - * - * @exception SQLException If an error occurs. - */ - void updateCharacterStream(String columnName, Reader reader, - int length) throws SQLException; - - /** - * This method updates the specified column to have an Object value. - * This does not update the actual database. <code>updateRow</code> must be - * called in order to do that. - * - * @param name The name of the column to update. - * @param value The new value of the column. - * @exception SQLException If an error occurs. - */ - void updateObject(String columnName, Object x, int scale) - throws SQLException; - - /** - * This method updates the specified column to have an Object value. - * This does not update the actual database. <code>updateRow</code> must be - * called in order to do that. - * - * @param name The name of the column to update. - * @param value The new value of the column. - * @param scale The scale of the object in question, which is used only - * for numeric type objects. - * @exception SQLException If an error occurs. - */ - void updateObject(String columnName, Object x) throws SQLException; - - /** - * This method inserts the current row into the database. The result set - * must be positioned on the insert row in order to call this method - * successfully. - * - * @exception SQLException If an error occurs. - */ - void insertRow() throws SQLException; - - /** - * This method updates the current row in the database. - * - * @exception SQLException If an error occurs. - */ - void updateRow() throws SQLException; - - /** - * This method deletes the current row in the database. - * - * @exception SQLException If an error occurs. - */ - void deleteRow() throws SQLException; - - /** - * This method refreshes the contents of the current row from the database. - * - * @exception SQLException If an error occurs. - */ - void refreshRow() throws SQLException; - - /** - * This method cancels any changes that have been made to a row. If - * the <code>rowUpdate</code> method has been called, then the changes - * cannot be undone. - * - * @exception SQLException If an error occurs. - */ - void cancelRowUpdates() throws SQLException; - - /** - * This method positions the result set to the "insert row", which allows - * a new row to be inserted into the database from the result set. - * - * @exception SQLException If an error occurs. - */ - void moveToInsertRow() throws SQLException; - - /** - * This method moves the result set position from the insert row back to - * the current row that was selected prior to moving to the insert row. - * - * @exception SQLException If an error occurs. - */ - void moveToCurrentRow() throws SQLException; - - /** - * This method returns a the <code>Statement</code> that was used to - * produce this result set. - * - * @return The <code>Statement</code> used to produce this result set. - * - * @exception SQLException If an error occurs. - */ - Statement getStatement() throws SQLException; - - /** - * This method returns the value of the specified column as a Java - * <code>Object</code> using the specified SQL type to Java type map. - * - * @param index The index of the column to return. - * @param map The SQL type to Java type map to use. - * @return The value of the column as an <code>Object</code>. - * @exception SQLException If an error occurs. - */ - Object getObject(int i, Map map) throws SQLException; - - /** - * This method returns a <code>Ref</code> for the specified column which - * represents the structured type for the column. - * - * @param index The index of the column to return. - * @return A <code>Ref</code> object for the column - * @exception SQLException If an error occurs. - */ - Ref getRef(int i) throws SQLException; - - /** - * This method returns the specified column value as a BLOB. - * - * @param index The index of the column value to return. - * @return The value of the column as a BLOB. - * @exception SQLException If an error occurs. - */ - Blob getBlob(int i) throws SQLException; - - /** - * This method returns the specified column value as a CLOB. - * - * @param index The index of the column value to return. - * @return The value of the column as a CLOB. - * @exception SQLException If an error occurs. - */ - Clob getClob(int i) throws SQLException; - - /** - * This method returns the specified column value as an <code>Array</code>. - * - * @param index The index of the column value to return. - * @return The value of the column as an <code>Array</code>. - * @exception SQLException If an error occurs. - */ - Array getArray(int i) throws SQLException; - - /** - * This method returns the value of the specified column as a Java - * <code>Object</code> using the specified SQL type to Java type map. - * - * @param name The name of the column to return. - * @param map The SQL type to Java type map to use. - * @return The value of the column as an <code>Object</code>. - * @exception SQLException If an error occurs. - */ - Object getObject(String colName, Map map) throws SQLException; - - /** - * This method returns a <code>Ref</code> for the specified column which - * represents the structured type for the column. - * - * @param index The index of the column to return. - * @return A <code>Ref</code> object for the column - * @exception SQLException If an error occurs. - */ - Ref getRef(String colName) throws SQLException; - - /** - * This method returns the specified column value as a BLOB. - * - * @param name The name of the column value to return. - * @return The value of the column as a BLOB. - * @exception SQLException If an error occurs. - */ - Blob getBlob(String colName) throws SQLException; - - /** - * This method returns the specified column value as a CLOB. - * - * @param name The name of the column value to return. - * @return The value of the column as a CLOB. - * @exception SQLException If an error occurs. - */ - Clob getClob(String colName) throws SQLException; - - /** - * This method returns the specified column value as an <code>Array</code>. - * - * @param name The name of the column value to return. - * @return The value of the column as an <code>Array</code>. - * @exception SQLException If an error occurs. - */ - Array getArray(String colName) throws SQLException; - - /** - * This method returns the specified column value as a - * <code>java.sql.Date</code>. The specified <code>Calendar</code> is used - * to generate a value for the date if the database does not support - * timezones. - * - * @param index The index of the column value to return. - * @param cal The <code>Calendar</code> to use for calculating timezones. - * @return The value of the column as a <code>java.sql.Date</code>. - * @exception SQLException If an error occurs. - */ - Date getDate(int columnIndex, Calendar cal) throws SQLException; - - /** - * This method returns the specified column value as a - * <code>java.sql.Date</code>. The specified <code>Calendar</code> is used - * to generate a value for the date if the database does not support - * timezones. - * - * @param name The name of the column value to return. - * @param cal The <code>Calendar</code> to use for calculating timezones. - * @return The value of the column as a <code>java.sql.Date</code>. - * @exception SQLException If an error occurs. - */ - Date getDate(String columnName, Calendar cal) throws SQLException; - - /** - * This method returns the specified column value as a - * <code>java.sql.Time</code>. The specified <code>Calendar</code> is used - * to generate a value for the time if the database does not support - * timezones. - * - * @param index The index of the column value to return. - * @param cal The <code>Calendar</code> to use for calculating timezones. - * @return The value of the column as a <code>java.sql.Time</code>. - * @exception SQLException If an error occurs. - */ - Time getTime(int columnIndex, Calendar cal) throws SQLException; - - /** - * This method returns the specified column value as a - * <code>java.sql.Time</code>. The specified <code>Calendar</code> is used - * to generate a value for the time if the database does not support - * timezones. - * - * @param name The name of the column value to return. - * @param cal The <code>Calendar</code> to use for calculating timezones. - * @return The value of the column as a <code>java.sql.Time</code>. - * @exception SQLException If an error occurs. - */ - Time getTime(String columnName, Calendar cal) throws SQLException; - - /** - * This method returns the specified column value as a - * <code>java.sql.Timestamp</code>. The specified <code>Calendar</code> is used - * to generate a value for the timestamp if the database does not support - * timezones. - * - * @param index The index of the column value to return. - * @param cal The <code>Calendar</code> to use for calculating timezones. - * @return The value of the column as a <code>java.sql.Timestamp</code>. - * @exception SQLException If an error occurs. - */ - Timestamp getTimestamp(int columnIndex, Calendar cal) - throws SQLException; - - /** - * This method returns the specified column value as a - * <code>java.sql.Timestamp</code>. The specified <code>Calendar</code> is used - * to generate a value for the timestamp if the database does not support - * timezones. - * - * @param name The name of the column value to return. - * @param cal The <code>Calendar</code> to use for calculating timezones. - * - * @return The value of the column as a <code>java.sql.Timestamp</code>. - * - * @exception SQLException If an error occurs. - */ - Timestamp getTimestamp(String columnName, Calendar cal) - throws SQLException; - - /** - * @since 1.4 - */ - URL getURL(int columnIndex) throws SQLException; - - /** - * @since 1.4 - */ - URL getURL(String columnName) throws SQLException; - - /** - * @since 1.4 - */ - void updateRef(int columnIndex, Ref x) throws SQLException; - - /** - * @since 1.4 - */ - void updateRef(String columnName, Ref x) throws SQLException; - - /** - * @since 1.4 - */ - void updateBlob(int columnIndex, Blob x) throws SQLException; - - /** - * @since 1.4 - */ - void updateBlob(String columnName, Blob x) throws SQLException; - - /** - * @since 1.4 - */ - void updateClob(int columnIndex, Clob x) throws SQLException; - - /** - * @since 1.4 - */ - void updateClob(String columnName, Clob x) throws SQLException; - - /** - * @since 1.4 - */ - void updateArray(int columnIndex, Array x) throws SQLException; - - /** - * @since 1.4 - */ - void updateArray(String columnName, Array x) throws SQLException; -} diff --git a/libjava/java/sql/ResultSetMetaData.java b/libjava/java/sql/ResultSetMetaData.java deleted file mode 100644 index 0086677ee60..00000000000 --- a/libjava/java/sql/ResultSetMetaData.java +++ /dev/null @@ -1,281 +0,0 @@ -/* ResultSetMetaData.java -- Returns information about the ResultSet - Copyright (C) 1999, 2000, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.sql; - -/** - * This interface provides a mechanism for obtaining information about - * the columns that are present in a <code>ResultSet</code>. - * <p> - * Note that in this class column indexes start at 1, not 0. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public interface ResultSetMetaData -{ - /** - * The column does not allow NULL's. - */ - int columnNoNulls = 0; - - /** - * The column allows NULL's. - */ - int columnNullable = 1; - - /** - * It is unknown whether or not the column allows NULL's. - */ - int columnNullableUnknown = 2; - - /** - * This method returns the number of columns in the result set. - * - * @return The number of columns in the result set. - * @exception SQLException If an error occurs. - */ - int getColumnCount() throws SQLException; - - /** - * This method test whether or not the column is an auto-increment column. - * Auto-increment columns are read-only. - * - * @param index The index of the column to test. - * @return <code>true</code> if the column is auto-increment, <code>false</code> - * otherwise. - * @exception SQLException If an error occurs. - */ - boolean isAutoIncrement(int column) throws SQLException; - - /** - * This method tests whether or not a column is case sensitive in its values. - * - * @param index The index of the column to test. - * @return <code>true</code> if the column value is case sensitive, - * <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean isCaseSensitive(int column) throws SQLException; - - /** - * This method tests whether not the specified column can be used in - * a WHERE clause. - * - * @param index The index of the column to test. - * @return <code>true</code> if the column may be used in a WHERE clause, - * <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean isSearchable(int column) throws SQLException; - - /** - * This method tests whether or not the column stores a monetary value. - * - * @param index The index of the column to test. - * @return <code>true</code> if the column contains a monetary value, - * <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean isCurrency(int column) throws SQLException; - - /** - * This method returns a value indicating whether or not the specified - * column may contain a NULL value. - * - * @param index The index of the column to test. - * @return A constant indicating whether or not the column can contain NULL, - * which will be one of <code>columnNoNulls</code>, - * <code>columnNullable</code>, or <code>columnNullableUnknown</code>. - * @exception SQLException If an error occurs. - */ - int isNullable(int column) throws SQLException; - - /** - * This method tests whether or not the value of the specified column - * is signed or unsigned. - * - * @param index The index of the column to test. - * @return <code>true</code> if the column value is signed, <code>false</code> - * otherwise. - * @exception SQLException If an error occurs. - */ - boolean isSigned(int column) throws SQLException; - - /** - * This method returns the maximum number of characters that can be used - * to display a value in this column. - * - * @param index The index of the column to check. - * @return The maximum number of characters that can be used to display a - * value for this column. - * @exception SQLException If an error occurs. - */ - int getColumnDisplaySize(int column) throws SQLException; - - /** - * This method returns a string that should be used as a caption for this - * column for user display purposes. - * - * @param index The index of the column to check. - * @return A display string for the column. - * @exception SQLException If an error occurs. - */ - String getColumnLabel(int column) throws SQLException; - - /** - * This method returns the name of the specified column. - * - * @param index The index of the column to return the name of. - * @return The name of the column. - * @exception SQLException If an error occurs. - */ - String getColumnName(int column) throws SQLException; - - /** - * This method returns the name of the schema that contains the specified - * column. - * - * @param index The index of the column to check the schema name for. - * @return The name of the schema that contains the column. - * @exception SQLException If an error occurs. - */ - String getSchemaName(int column) throws SQLException; - - /** - * This method returns the precision of the specified column, which is the - * number of decimal digits it contains. - * - * @param index The index of the column to check the precision on. - * @return The precision of the specified column. - * @exception SQLException If an error occurs. - */ - int getPrecision(int column) throws SQLException; - - /** - * This method returns the scale of the specified column, which is the - * number of digits to the right of the decimal point. - * - * @param index The index column to check the scale of. - * @return The scale of the column. - * @exception SQLException If an error occurs. - */ - int getScale(int column) throws SQLException; - - /** - * This method returns the name of the table containing the specified - * column. - * - * @param index The index of the column to check the table name for. - * @return The name of the table containing the column. - * @exception SQLException If an error occurs. - */ - String getTableName(int column) throws SQLException; - - /** - * This method returns the name of the catalog containing the specified - * column. - * - * @param index The index of the column to check the catalog name for. - * @return The name of the catalog containing the column. - * @exception SQLException If an error occurs. - */ - String getCatalogName(int column) throws SQLException; - - /** - * This method returns the SQL type of the specified column. This will - * be one of the constants from <code>Types</code>. - * - * @param index The index of the column to check the SQL type of. - * @return The SQL type for this column. - * @exception SQLException If an error occurs. - * @see Types - */ - int getColumnType(int column) throws SQLException; - - /** - * This method returns the name of the SQL type for this column. - * - * @param index The index of the column to check the SQL type name for. - * @return The name of the SQL type for this column. - * @exception SQLException If an error occurs. - */ - String getColumnTypeName(int column) throws SQLException; - - /** - * This method tests whether or not the specified column is read only. - * - * @param index The index of the column to check. - * @return <code>true</code> if the column is read only, <code>false</code> - * otherwise. - * @exception SQLException If an error occurs. - */ - boolean isReadOnly(int column) throws SQLException; - - /** - * This method tests whether or not the column may be writable. This - * does not guarantee that a write will be successful. - * - * @param index The index of the column to check for writability. - * @return <code>true</code> if the column may be writable, - * <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean isWritable(int column) throws SQLException; - - /** - * This method tests whether or not the column is writable. This - * does guarantee that a write will be successful. - * - * @param index The index of the column to check for writability. - * @return <code>true</code> if the column is writable, - * <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean isDefinitelyWritable(int column) throws SQLException; - - /** - * This method returns the name of the Java class which will be used to - * create objects representing the data in this column. - * - * @param index The index of the column to check. - * @return The name of the Java class that will be used for values in - * this column. - * @exception SQLException If an error occurs. - */ - String getColumnClassName(int column) throws SQLException; -} diff --git a/libjava/java/sql/SQLData.java b/libjava/java/sql/SQLData.java deleted file mode 100644 index 2ba1fb18d05..00000000000 --- a/libjava/java/sql/SQLData.java +++ /dev/null @@ -1,72 +0,0 @@ -/* SQLData.java -- Custom mapping for a user defined datatype - Copyright (C) 1999, 2000 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.sql; - -/** - * This interface is used for mapping SQL data to user defined datatypes. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public interface SQLData -{ - /** - * This method returns the user defined datatype name for this object. - * - * @return The user defined data type name for this object. - * @exception SQLException If an error occurs. - */ - String getSQLTypeName() throws SQLException; - - /** - * This method populates the data in the object from the specified stream. - * - * @param stream The stream to read the data from. - * @param name The data type name of the data on the stream. - * @exception SQLException If an error occurs. - */ - void readSQL(SQLInput stream, String typeName) throws SQLException; - - /** - * This method writes the data in this object to the specified stream. - * - * @param stream The stream to write the data to. - * @exception SQLException If an error occurs. - */ - void writeSQL(SQLOutput stream) throws SQLException; -} diff --git a/libjava/java/sql/SQLException.java b/libjava/java/sql/SQLException.java deleted file mode 100644 index 8c502f2df7c..00000000000 --- a/libjava/java/sql/SQLException.java +++ /dev/null @@ -1,167 +0,0 @@ -/* SQLException.java -- General SQL exception - Copyright (C) 1999, 2000 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.sql; - -/** - * This exception is thrown when a database error occurs. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public class SQLException extends Exception -{ - static final long serialVersionUID = 2135244094396331484L; - - /** - * This is the next exception in the chain - */ - private SQLException next; - - /** - * This is the state of the SQL statement at the time of the error. - */ - private String SQLState; - - /** - * The vendor error code for this error - */ - private int vendorCode; - - /** - * This method initializes a nwe instance of <code>SQLException</code> - * with the specified descriptive error message, SQL state string, and - * vendor code. - * - * @param message A string describing the nature of the error. - * @param SQLState A string containing the SQL state of the error. - * @param vendorCode The vendor error code associated with this error. - */ - public SQLException(String message, String SQLState, int vendorCode) - { - super(message); - this.SQLState = SQLState; - this.vendorCode = vendorCode; - } - - /** - * This method initializes a new instance of <code>SQLException</code> - * with the specified descriptive error message and SQL state string. - * The vendor error code of this instance will be 0. - * - * @param message A string describing the nature of the error. - * @param SQLState A string containing the SQL state of the error. - */ - public SQLException(String message, String SQLState) - { - this(message, SQLState, 0); - } - - /** - * This method initializes a new instance of <code>SQLException</code> - * with the specified descriptive error message. The SQL state of this - * instance will be <code>null</code> and the vendor error code will be 0. - * - * @param message A string describing the nature of the error. - */ - public SQLException(String message) - { - this(message, null, 0); - } - - /** - * This method initializes a new instance of <code>SQLException</code> - * that does not have a descriptive messages and SQL state, and which - * has a vendor error code of 0. - */ - public SQLException() - { - this(null, null, 0); - } - - /** - * This method returns the SQLState information associated with this - * error. The value returned is a <code>String</code> which is formatted - * using the XOPEN SQL state conventions. - * - * @return The SQL state, which may be <code>null</code>. - */ - public String getSQLState() - { - return SQLState; - } - - /** - * This method returns the vendor specific error code associated with - * this error. - * - * @return The vendor specific error code associated with this error. - */ - public int getErrorCode() - { - return vendorCode; - } - - /** - * This method returns the exception that is chained to this object. - * - * @return The exception chained to this object, which may be - * <code>null</code>. - */ - public SQLException getNextException() - { - return next; - } - - /** - * This method adds a new exception to the end of the chain of exceptions - * that are chained to this object. - * - * @param e The exception to add to the end of the chain. - */ - public void setNextException(SQLException e) - { - if (e == null) - return; - - SQLException list_entry = this; - while (list_entry.getNextException() != null) - list_entry = list_entry.getNextException(); - - list_entry.next = e; - } -} diff --git a/libjava/java/sql/SQLInput.java b/libjava/java/sql/SQLInput.java deleted file mode 100644 index 730627d9a9e..00000000000 --- a/libjava/java/sql/SQLInput.java +++ /dev/null @@ -1,259 +0,0 @@ -/* SQLInput.java -- Read SQL values from a stream - Copyright (C) 1999, 2000, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.sql; - -import java.io.InputStream; -import java.io.Reader; -import java.math.BigDecimal; -import java.net.URL; - -/** - * This interface provides methods for reading values from a stream - * that is connected to a SQL structured or distinct type. It is used - * for custom mapping of user defined data types. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public interface SQLInput -{ - /** - * This method reads the next item from the stream a Java - * <code>String</code>. - * - * @return The value read from the stream as a <code>String</code>. - * @exception SQLException If an error occurs. - */ - String readString() throws SQLException; - - /** - * This method reads the next item from the stream a Java - * <code>boolean</code>. - * - * @return The value read from the stream as a <code>boolean</code>. - * @exception SQLException If an error occurs. - */ - boolean readBoolean() throws SQLException; - - /** - * This method reads the next item from the stream a Java - * <code>byte</code>. - * - * @return The value read from the stream as a <code>byte</code>. - * @exception SQLException If an error occurs. - */ - byte readByte() throws SQLException; - - /** - * This method reads the next item from the stream a Java - * <code>short</code>. - * - * @return The value read from the stream as a <code>short</code>. - * @exception SQLException If an error occurs. - */ - short readShort() throws SQLException; - - /** - * This method reads the next item from the stream a Java - * <code>int</code>. - * - * @return The value read from the stream as an <code>int</code>. - * @exception SQLException If an error occurs. - */ - int readInt() throws SQLException; - - /** - * This method reads the next item from the stream a Java - * <code>long</code>. - * - * @return The value read from the stream as a <code>long</code>. - * @exception SQLException If an error occurs. - */ - long readLong() throws SQLException; - - /** - * This method reads the next item from the stream a Java - * <code>float</code>. - * - * @return The value read from the stream as a <code>float</code>. - * @exception SQLException If an error occurs. - */ - float readFloat() throws SQLException; - - /** - * This method reads the next item from the stream a Java - * <code>double</code>. - * - * @return The value read from the stream as a <code>double</code>. - * @exception SQLException If an error occurs. - */ - double readDouble() throws SQLException; - - /** - * This method reads the next item from the stream a Java - * <code>BigDecimal</code>. - * - * @return The value read from the stream as a <code>BigDecimal</code>. - * @exception SQLException If an error occurs. - */ - BigDecimal readBigDecimal() throws SQLException; - - /** - * This method reads the next item from the stream a Java - * byte array - * - * @return The value read from the stream as a byte array. - * @exception SQLException If an error occurs. - */ - byte[] readBytes() throws SQLException; - - /** - * This method reads the next item from the stream a Java - * <code>java.sql.Date</code>. - * - * @return The value read from the stream as a <code>java.sql.Date</code>. - * @exception SQLException If an error occurs. - */ - Date readDate() throws SQLException; - - /** - * This method reads the next item from the stream a Java - * <code>java.sql.Time</code>. - * - * @return The value read from the stream as a <code>java.sql.Time</code>. - * @exception SQLException If an error occurs. - */ - Time readTime() throws SQLException; - - /** - * This method reads the next item from the stream a Java - * <code>java.sql.Timestamp</code>. - * - * @return The value read from the stream as a <code>java.sql.Timestamp</code>. - * @exception SQLException If an error occurs. - */ - Timestamp readTimestamp() throws SQLException; - - /** - * This method reads the next item from the stream a character - * <code>Reader</code>. - * - * @return The value read from the stream as a <code>Reader</code>. - * @exception SQLException If an error occurs. - */ - Reader readCharacterStream() throws SQLException; - - /** - * This method reads the next item from the stream a ASCII text - * <code>InputStream</code>. - * - * @return The value read from the stream as an <code>InputStream</code>. - * @exception SQLException If an error occurs. - */ - InputStream readAsciiStream() throws SQLException; - - /** - * This method reads the next item from the stream a binary - * <code>InputStream</code>. - * - * @return The value read from the stream as an <code>InputStream</code>. - * @exception SQLException If an error occurs. - */ - InputStream readBinaryStream() throws SQLException; - - /** - * This method reads the next item from the stream a Java - * <code>Object</code>. - * - * @return The value read from the stream as an <code>Object</code>. - * @exception SQLException If an error occurs. - */ - Object readObject() throws SQLException; - - /** - * This method reads the next item from the stream a Java SQL - * <code>Ref</code>. - * - * @return The value read from the stream as an <code>Ref</code>. - * @exception SQLException If an error occurs. - */ - Ref readRef() throws SQLException; - - /** - * This method reads the next item from the stream a Java SQL - * <code>Blob</code>. - * - * @return The value read from the stream as a <code>Blob</code>. - * @exception SQLException If an error occurs. - */ - Blob readBlob() throws SQLException; - - /** - * This method reads the next item from the stream a Java SQL - * <code>Clob</code>. - * - * @return The value read from the stream as a <code>Clob</code>. - * @exception SQLException If an error occurs. - */ - Clob readClob() throws SQLException; - - /** - * This method reads the next item from the stream a Java SQL - * <code>Array</code>. - * - * @return The value read from the stream as an <code>Array</code>. - * @exception SQLException If an error occurs. - */ - Array readArray() throws SQLException; - - /** - * This method tests whether or not the last value read was a SQL - * NULL value. - * - * @return <code>true</code> if the last value read was a NULL, - * <code>false</code> otherwise. - * @exception SQLException If an error occurs. - */ - boolean wasNull() throws SQLException; - - /** - * @since 1.4 - */ - URL readURL() throws SQLException; -} - diff --git a/libjava/java/sql/SQLOutput.java b/libjava/java/sql/SQLOutput.java deleted file mode 100644 index 8e6c88f8cf6..00000000000 --- a/libjava/java/sql/SQLOutput.java +++ /dev/null @@ -1,257 +0,0 @@ -/* SQLOutput.java -- Write SQL values to a stream - Copyright (C) 1999, 2000, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.sql; - -import java.io.InputStream; -import java.io.Reader; -import java.math.BigDecimal; -import java.net.URL; - -/** - * This interface provides methods for writing Java types to a SQL stream. - * It is used for implemented custom type mappings for user defined data - * types. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public interface SQLOutput -{ - /** - * This method writes the specified Java <code>String</code> - * to the SQL stream. - * - * @param value The value to write to the stream. - * @exception SQLException If an error occurs. - */ - void writeString(String x) throws SQLException; - - /** - * This method writes the specified Java <code>boolean</code> - * to the SQL stream. - * - * @param value The value to write to the stream. - * @exception SQLException If an error occurs. - */ - void writeBoolean(boolean x) throws SQLException; - - /** - * This method writes the specified Java <code>byte</code> - * to the SQL stream. - * - * @param value The value to write to the stream. - * @exception SQLException If an error occurs. - */ - void writeByte(byte x) throws SQLException; - - /** - * This method writes the specified Java <code>short</code> - * to the SQL stream. - * - * @param value The value to write to the stream. - * @exception SQLException If an error occurs. - */ - void writeShort(short x) throws SQLException; - - /** - * This method writes the specified Java <code>int</code> - * to the SQL stream. - * - * @param value The value to write to the stream. - * @exception SQLException If an error occurs. - */ - void writeInt(int x) throws SQLException; - - /** - * This method writes the specified Java <code>long</code> - * to the SQL stream. - * - * @param value The value to write to the stream. - * @exception SQLException If an error occurs. - */ - void writeLong(long x) throws SQLException; - - /** - * This method writes the specified Java <code>float</code> - * to the SQL stream. - * - * @param value The value to write to the stream. - * @exception SQLException If an error occurs. - */ - void writeFloat(float x) throws SQLException; - - /** - * This method writes the specified Java <code>double</code> - * to the SQL stream. - * - * @param value The value to write to the stream. - * @exception SQLException If an error occurs. - */ - void writeDouble(double x) throws SQLException; - - /** - * This method writes the specified Java <code>BigDecimal</code> - * to the SQL stream. - * - * @param value The value to write to the stream. - * @exception SQLException If an error occurs. - */ - void writeBigDecimal(BigDecimal x) throws SQLException; - - /** - * This method writes the specified Java <code>byte</code> array - * to the SQL stream. - * - * @param value The value to write to the stream. - * @exception SQLException If an error occurs. - */ - void writeBytes(byte[] x) throws SQLException; - - /** - * This method writes the specified Java <code>java.sql.Date</code> - * to the SQL stream. - * - * @param value The value to write to the stream. - * @exception SQLException If an error occurs. - */ - void writeDate(Date x) throws SQLException; - - /** - * This method writes the specified Java <code>java.sql.Time</code> - * to the SQL stream. - * - * @param value The value to write to the stream. - * @exception SQLException If an error occurs. - */ - void writeTime(Time x) throws SQLException; - - /** - * This method writes the specified Java <code>java.sql.Timestamp</code> - * to the SQL stream. - * - * @param value The value to write to the stream. - * @exception SQLException If an error occurs. - */ - void writeTimestamp(Timestamp x) throws SQLException; - - /** - * This method writes the specified Java character stream - * to the SQL stream. - * - * @param value The value to write to the stream. - * @exception SQLException If an error occurs. - */ - void writeCharacterStream(Reader x) throws SQLException; - - /** - * This method writes the specified ASCII text stream - * to the SQL stream. - * - * @param value The value to write to the stream. - * @exception SQLException If an error occurs. - */ - void writeAsciiStream(InputStream x) throws SQLException; - - /** - * This method writes the specified uninterpreted binary byte stream - * to the SQL stream. - * - * @param value The value to write to the stream. - * @exception SQLException If an error occurs. - */ - void writeBinaryStream(InputStream x) throws SQLException; - - /** - * This method writes the specified Java <code>SQLData</code> object - * to the SQL stream. - * - * @param value The value to write to the stream. - * @exception SQLException If an error occurs. - */ - void writeObject(SQLData x) throws SQLException; - - /** - * This method writes the specified Java SQL <code>Ref</code> object - * to the SQL stream. - * - * @param value The value to write to the stream. - * @exception SQLException If an error occurs. - */ - void writeRef(Ref x) throws SQLException; - - /** - * This method writes the specified Java SQL <code>Blob</code> object - * to the SQL stream. - * - * @param value The value to write to the stream. - * @exception SQLException If an error occurs. - */ - void writeBlob(Blob x) throws SQLException; - - /** - * This method writes the specified Java SQL <code>Clob</code> object - * to the SQL stream. - * - * @param value The value to write to the stream. - * @exception SQLException If an error occurs. - */ - void writeClob(Clob x) throws SQLException; - - /** - * This method writes the specified Java SQL <code>Struct</code> object - * to the SQL stream. - * - * @param value The value to write to the stream. - * @exception SQLException If an error occurs. - */ - void writeStruct(Struct x) throws SQLException; - - /** - * This method writes the specified Java SQL <code>Array</code> object - * to the SQL stream. - * - * @param value The value to write to the stream. - * @exception SQLException If an error occurs. - */ - void writeArray(Array x) throws SQLException; - - /** - * @since 1.4 - */ - void writeURL(URL x) throws SQLException; -} diff --git a/libjava/java/sql/SQLPermission.java b/libjava/java/sql/SQLPermission.java deleted file mode 100644 index 101fa0161b4..00000000000 --- a/libjava/java/sql/SQLPermission.java +++ /dev/null @@ -1,57 +0,0 @@ -/* SQLPermission.java - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.sql; - -import java.security.BasicPermission; - -/** - * @since 1.3 - */ -public final class SQLPermission extends BasicPermission -{ - public SQLPermission(String name) - { - super(name); - } - - public SQLPermission(String name, String actions) - { - super(name, actions); - } -} diff --git a/libjava/java/sql/SQLWarning.java b/libjava/java/sql/SQLWarning.java deleted file mode 100644 index 841d137e13a..00000000000 --- a/libjava/java/sql/SQLWarning.java +++ /dev/null @@ -1,120 +0,0 @@ -/* SQLWarning.java -- Database access warnings. - Copyright (C) 1999, 2000, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.sql; - -/** - * This exception is thrown when a database warning occurs. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public class SQLWarning extends SQLException -{ - static final long serialVersionUID = 3917336774604784856L; - - /** - * This method initializes a nwe instance of <code>SQLWarning</code> - * with the specified descriptive error message, SQL state string, and - * vendor code. - * - * @param message A string describing the nature of the error. - * @param SQLState A string containing the SQL state of the error. - * @param vendorCode The vendor error code associated with this error. - */ - public SQLWarning(String reason, String SQLState, int vendorCode) - { - super(reason, SQLState, vendorCode); - } - - /** - * This method initializes a new instance of <code>SQLWarning</code> - * with the specified descriptive error message and SQL state string. - * The vendor error code of this instance will be 0. - * - * @param message A string describing the nature of the error. - * @param SQLState A string containing the SQL state of the error. - */ - public SQLWarning(String message, String SQLState) - { - super(message, SQLState); - } - - /** - * This method initializes a new instance of <code>SQLWarning</code> - * with the specified descriptive error message. The SQL state of this - * instance will be <code>null</code> and the vendor error code will be 0. - * - * @param message A string describing the nature of the error. - */ - public SQLWarning(String message) - { - super(message); - } - - /** - * This method initializes a new instance of <code>SQLWarning</code> - * that does not have a descriptive messages and SQL state, and which - * has a vendor error code of 0. - */ - public SQLWarning() - { - super(); - } - - /** - * This method returns the exception that is chained to this object. - * - * @return The exception chained to this object, which may be - * <code>null</code>. - */ - public SQLWarning getNextWarning() - { - return (SQLWarning) super.getNextException(); - } - - /** - * This method adds a new exception to the end of the chain of exceptions - * that are chained to this object. - * - * @param w The exception to add to the end of the chain. - */ - public void setNextWarning(SQLWarning w) - { - super.setNextException(w); - } -} diff --git a/libjava/java/sql/Savepoint.java b/libjava/java/sql/Savepoint.java deleted file mode 100644 index a4d89ae6e50..00000000000 --- a/libjava/java/sql/Savepoint.java +++ /dev/null @@ -1,55 +0,0 @@ -/* SavePoint.java -- Returns information about the ResultSet - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.sql; - -/** - * @since 1.4 - */ -public interface Savepoint -{ - /** - * @since 1.4 - */ - int getSavepointId() throws SQLException; - - /** - * @since 1.4 - */ - String getSavepointName() throws SQLException; -} diff --git a/libjava/java/sql/Statement.java b/libjava/java/sql/Statement.java deleted file mode 100644 index 42e8e8e8816..00000000000 --- a/libjava/java/sql/Statement.java +++ /dev/null @@ -1,366 +0,0 @@ -/* Statement.java -- Interface for executing SQL statements. - Copyright (C) 1999, 2000, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.sql; - -/** - * This interface provides a mechanism for executing SQL statements. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public interface Statement -{ - int CLOSE_CURRENT_RESULT = 1; - int KEEP_CURRENT_RESULT = 2; - int CLOSE_ALL_RESULTS = 3; - int SUCCESS_NO_INFO = -2; - int EXECUTE_FAILED = -3; - int RETURN_GENERATED_KEYS = 1; - int NO_GENERATED_KEYS = 2; - - /** - * This method executes the specified SQL SELECT statement and returns a - * (possibly empty) <code>ResultSet</code> with the results of the query. - * - * @param sql The SQL statement to execute. - * @return The result set of the SQL statement. - * @exception SQLException If an error occurs. - */ - ResultSet executeQuery(String sql) throws SQLException; - - /** - * This method executes the specified SQL INSERT, UPDATE, or DELETE statement - * and returns the number of rows affected, which may be 0. - * - * @param sql The SQL statement to execute. - * @return The number of rows affected by the SQL statement. - * @exception SQLException If an error occurs. - */ - int executeUpdate(String sql) throws SQLException; - - /** - * This method closes the statement and frees any associated resources. - * - * @exception SQLException If an error occurs. - */ - void close() throws SQLException; - - /** - * This method returns the maximum length of any column value in bytes. - * - * @return The maximum length of any column value in bytes. - * @exception SQLException If an error occurs. - */ - int getMaxFieldSize() throws SQLException; - - /** - * This method sets the limit for the maximum length of any column in bytes. - * - * @param maxsize The new maximum length of any column in bytes. - * @exception SQLException If an error occurs. - */ - void setMaxFieldSize(int max) throws SQLException; - - /** - * This method returns the maximum possible number of rows in a result set. - * - * @return The maximum possible number of rows in a result set. - * @exception SQLException If an error occurs. - */ - int getMaxRows() throws SQLException; - - /** - * This method sets the maximum number of rows that can be present in a - * result set. - * - * @param maxrows The maximum possible number of rows in a result set. - * @exception SQLException If an error occurs. - */ - void setMaxRows(int max) throws SQLException; - - /** - * This method sets the local escape processing mode on or off. The - * default value is on. - * - * @param escape <code>true</code> to enable local escape processing, - * <code>false</code> to disable it. - * @exception SQLException If an error occurs. - */ - void setEscapeProcessing(boolean enable) throws SQLException; - - /** - * The method returns the number of seconds a statement may be in process - * before timing out. A value of 0 means there is no timeout. - * - * @return The SQL statement timeout in seconds. - * @exception SQLException If an error occurs. - */ - int getQueryTimeout() throws SQLException; - - /** - * This method sets the number of seconds a statement may be in process - * before timing out. A value of 0 means there is no timeout. - * - * @param timeout The new SQL statement timeout value. - * @exception SQLException If an error occurs. - */ - void setQueryTimeout(int seconds) throws SQLException; - - /** - * This method cancels an outstanding statement, if the database supports - * that operation. - * - * @exception SQLException If an error occurs. - */ - void cancel() throws SQLException; - - /** - * This method returns the first SQL warning attached to this statement. - * Subsequent warnings will be chained to this one. - * - * @return The first SQL warning for this statement. - * @exception SQLException If an error occurs. - */ - SQLWarning getWarnings() throws SQLException; - - /** - * This method clears any SQL warnings that have been attached to this - * statement. - * - * @exception SQLException If an error occurs. - */ - void clearWarnings() throws SQLException; - - /** - * This method sets the cursor name that will be used by the result set. - * - * @param name The cursor name to use for this statement. - * @exception SQLException If an error occurs. - */ - void setCursorName(String name) throws SQLException; - - /** - * This method executes an arbitrary SQL statement of any time. The - * methods <code>getResultSet</code>, <code>getMoreResults</code> and - * <code>getUpdateCount</code> retrieve the results. - * - * @return <code>true</code> if a result set was returned, <code>false</code> - * if an update count was returned. - * @exception SQLException If an error occurs. - */ - boolean execute(String sql) throws SQLException; - - /** - * This method returns the result set of the SQL statement that was - * executed. This should be called only once per result set returned. - * - * @return The result set of the query, or <code>null</code> if there was - * no result set (for example, if the statement was an UPDATE). - * @exception SQLException If an error occurs. - * @see execute - */ - ResultSet getResultSet() throws SQLException; - - /** - * This method returns the update count of the SQL statement that was - * executed. This should be called only once per executed SQL statement. - * - * @return The update count of the query, or -1 if there was no update - * count (for example, if the statement was a SELECT). - * @exception SQLException If an error occurs. - * @see execute - */ - int getUpdateCount() throws SQLException; - - /** - * This method advances the result set pointer to the next result set, - * which can then be retrieved using <code>getResultSet</code> - * - * @return <code>true</code> if there is another result set, - * <code>false</code> otherwise (for example, the next result is an - * update count). - * @exception SQLException If an error occurs. - * @see execute - */ - boolean getMoreResults() throws SQLException; - - /** - * This method informs the driver which direction the result set will - * be accessed in. - * - * @param direction The direction the result set will be accessed in (?????) - * @exception SQLException If an error occurs. - */ - void setFetchDirection(int direction) throws SQLException; - - /** - * This method returns the current direction that the driver thinks the - * result set will be accessed int. - * - * @return The direction the result set will be accessed in (????) - * @exception SQLException If an error occurs. - */ - int getFetchDirection() throws SQLException; - - /** - * This method informs the driver how many rows it should fetch from the - * database at a time. - * - * @param numrows The number of rows the driver should fetch at a time - * to populate the result set. - * @exception SQLException If an error occurs. - */ - void setFetchSize(int rows) throws SQLException; - - /** - * This method returns the number of rows the driver believes should be - * fetched from the database at a time. - * - * @return The number of rows that will be fetched from the database at a time. - * @exception SQLException If an error occurs. - */ - int getFetchSize() throws SQLException; - - /** - * This method returns the concurrency type of the result set for this - * statement. This will be one of the concurrency types defined in - * <code>ResultSet</code>. - * - * @return The concurrency type of the result set for this statement. - * @exception SQLException If an error occurs. - * @see ResultSet - */ - int getResultSetConcurrency() throws SQLException; - - /** - * This method returns the result set type for this statement. This will - * be one of the result set types defined in <code>ResultSet</code>. - * - * @return The result set type for this statement. - * @exception SQLException If an error occurs. - * @see ResultSet - */ - int getResultSetType() throws SQLException; - - /** - * This method adds a SQL statement to a SQL batch. A driver is not - * required to implement this method. - * - * @param sql The sql statement to add to the batch. - * @exception SQLException If an error occurs. - */ - void addBatch(String sql) throws SQLException; - - /** - * This method clears out any SQL statements that have been populated in - * the current batch. A driver is not required to implement this method. - * - * @exception SQLException If an error occurs. - */ - void clearBatch() throws SQLException; - - /** - * This method executes the SQL batch and returns an array of update - * counts - one for each SQL statement in the batch - ordered in the same - * order the statements were added to the batch. A driver is not required - * to implement this method. - * - * @return An array of update counts for this batch. - * @exception SQLException If an error occurs. - */ - int[] executeBatch() throws SQLException; - - /** - * This method returns the <code>Connection</code> instance that was - * used to create this object. - * - * @return The connection used to create this object. - * @exception SQLException If an error occurs. - */ - Connection getConnection() throws SQLException; - - /** - * @since 1.4 - */ - boolean getMoreResults(int current) throws SQLException; - - /** - * @since 1.4 - */ - ResultSet getGeneratedKeys() throws SQLException; - - /** - * @since 1.4 - */ - int executeUpdate(String sql, int autoGeneratedKeys) - throws SQLException; - - /** - * @since 1.4 - */ - int executeUpdate(String sql, int[] columnIndexes) - throws SQLException; - - /** - * @since 1.4 - */ - int executeUpdate(String sql, String[] columnNames) - throws SQLException; - - /** - * @since 1.4 - */ - boolean execute(String sql, int autoGeneratedKeys) - throws SQLException; - - /** - * @since 1.4 - */ - boolean execute(String sql, int[] columnIndexes) throws SQLException; - - /** - * @since 1.4 - */ - boolean execute(String sql, String[] columnNames) - throws SQLException; - - /** - * @since 1.4 - */ - int getResultSetHoldability() throws SQLException; -} diff --git a/libjava/java/sql/Struct.java b/libjava/java/sql/Struct.java deleted file mode 100644 index 5cbc88e133a..00000000000 --- a/libjava/java/sql/Struct.java +++ /dev/null @@ -1,77 +0,0 @@ -/* Struct.java -- Mapping for a SQL structured type. - Copyright (C) 1999, 2000, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.sql; - -import java.util.Map; - -/** - * This interface implements the standard type mapping for a SQL - * structured type. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public interface Struct -{ - /** - * This method returns the name of the SQL structured type for this - * object. - * - * @return The SQL structured type name. - * @exception SQLException If an error occurs. - */ - String getSQLTypeName() throws SQLException; - - /** - * This method returns the attributes of this SQL structured type. - * - * @return The attributes of this structure type. - * @exception SQLException If an error occurs. - */ - Object[] getAttributes() throws SQLException; - - /** - * This method returns the attributes of this SQL structured type. - * The specified map of type mappings overrides the default mappings. - * - * @param map The map of SQL type mappings. - * @return The attributes of this structure type. - * @exception SQLException If a error occurs. - */ - Object[] getAttributes(Map map) throws SQLException; -} diff --git a/libjava/java/sql/Time.java b/libjava/java/sql/Time.java deleted file mode 100644 index eb6ef2d651e..00000000000 --- a/libjava/java/sql/Time.java +++ /dev/null @@ -1,205 +0,0 @@ -/* Time.java -- Wrapper around java.util.Date - Copyright (C) 1999, 2000, 2002, 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.sql; - -import java.text.ParseException; -import java.text.SimpleDateFormat; - -/** - * This class is a wrapper around java.util.Date to allow the JDBC - * driver to identify the value as a SQL Time. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public class Time extends java.util.Date -{ - static final long serialVersionUID = 8397324403548013681L; - - /** - * Used for parsing and formatting this date. - */ - private static SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss"); - - /** - * This method always throws an IllegalArgumentException. - * - * @throws IllegalArgumentException when it's called. - * @deprecated - */ - public int getDate() throws IllegalArgumentException - { - throw new IllegalArgumentException(); - } - - /** - * This method always throws an IllegalArgumentException. - * - * @throws IllegalArgumentException when it's called. - * @deprecated - */ - public int getDay() throws IllegalArgumentException - { - throw new IllegalArgumentException(); - } - - /** - * This method always throws an IllegalArgumentException. - * - * @throws IllegalArgumentException when it's called. - * @deprecated - */ - public int getMonth() throws IllegalArgumentException - { - throw new IllegalArgumentException(); - } - - /** - * This method always throws an IllegalArgumentException. - * - * @throws IllegalArgumentException when it's called. - * @deprecated - */ - public int getYear() throws IllegalArgumentException - { - throw new IllegalArgumentException(); - } - - /** - * This method always throws an IllegalArgumentException. - * - * @throws IllegalArgumentException when it's called. - * @deprecated - */ - public void setDate(int newValue) throws IllegalArgumentException - { - throw new IllegalArgumentException(); - } - - /** - * This method always throws an IllegalArgumentException. - * - * @throws IllegalArgumentException when it's called. - * @deprecated - */ - public void setMonth(int newValue) throws IllegalArgumentException - { - throw new IllegalArgumentException(); - } - - /** - * This method always throws an IllegalArgumentException. - * - * @throws IllegalArgumentException when it's called. - * @deprecated - */ - public void setYear(int newValue) throws IllegalArgumentException - { - throw new IllegalArgumentException(); - } - - /** - * This method returns a new instance of this class by parsing a - * date in JDBC format into a Java date. - * - * @param str The string to parse. - * @return The resulting <code>java.sql.Time</code> value. - * - * @deprecated - */ - public static Time valueOf (String str) - { - try - { - java.util.Date d = (java.util.Date) sdf.parseObject(str); - - if (d == null) - throw new IllegalArgumentException(str); - else - return new Time(d.getTime()); - } - catch (ParseException e) - { - throw new IllegalArgumentException(str); - } - } - - /** - * This method initializes a new instance of this class with the - * specified year, month, and day. - * - * @param hour The hour for this Time (0-23) - * @param minute The minute for this time (0-59) - * @param second The second for this time (0-59) - * @deprecated - */ - public Time(int hour, int minute, int second) - { - super(System.currentTimeMillis()); - - setHours(hour); - setMinutes(minute); - setSeconds(second); - } - - /** - * This method initializes a new instance of this class with the - * specified time value representing the number of seconds since - * Jan 1, 1970 at 12:00 midnight GMT. - * - * @param time The time value to intialize this <code>Time</code> to. - */ - public Time(long date) - { - super(date); - } - - /** - * This method returns this date in JDBC format. - * - * @return This date as a string. - * - * @deprecated - */ - public String toString () - { - return sdf.format (this); - } - -} - diff --git a/libjava/java/sql/Timestamp.java b/libjava/java/sql/Timestamp.java deleted file mode 100644 index f3459b22f3e..00000000000 --- a/libjava/java/sql/Timestamp.java +++ /dev/null @@ -1,315 +0,0 @@ -/* Time.java -- Wrapper around java.util.Date - Copyright (C) 1999, 2000, 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.sql; - -import java.text.DecimalFormat; -import java.text.ParseException; -import java.text.SimpleDateFormat; - -/** - * This class is a wrapper around java.util.Date to allow the JDBC - * driver to identify the value as a SQL Timestamp. Note that this - * class also adds an additional field for nano-seconds, and so - * is not completely identical to <code>java.util.Date</code> as - * the <code>java.sql.Date</code> and <code>java.sql.Time</code> - * classes are. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public class Timestamp extends java.util.Date -{ - static final long serialVersionUID = 2745179027874758501L; - - /** - * Used for parsing and formatting this date. - */ - private static SimpleDateFormat dateFormat = - new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - private static DecimalFormat decimalFormat = new DecimalFormat("000000000"); - private static StringBuffer sbuf = new StringBuffer(29); - - /** - * The nanosecond value for this object - */ - private int nanos; - - /** - * This method returns a new instance of this class by parsing a - * date in JDBC format into a Java date. - * - * @param str The string to parse. - * @return The resulting <code>java.sql.Timestamp</code> value. - */ - public static Timestamp valueOf(String str) - { - int nanos = 0; - int dot = str.indexOf('.'); - if (dot != -1) - { - if (str.lastIndexOf('.') != dot) - throw new IllegalArgumentException(str); - - int len = str.length() - dot - 1; - if (len < 1 || len > 9) - throw new IllegalArgumentException(str); - - nanos = Integer.parseInt(str.substring(dot + 1)); - for (int i = len; i < 9; i++) - nanos *= 10; - - str = str.substring(0, dot); - - } - - try - { - java.util.Date d; - synchronized (dateFormat) - { - d = (java.util.Date) dateFormat.parseObject(str); - } - - if (d == null) - throw new IllegalArgumentException(str); - - Timestamp ts = new Timestamp(d.getTime() + nanos / 1000000); - ts.nanos = nanos; - return ts; - } - catch (ParseException e) - { - throw new IllegalArgumentException(str); - } - } - - /** - * This method initializes a new instance of this class with the - * specified year, month, and day. - * - * @param year The year for this Timestamp (year - 1900) - * @param month The month for this Timestamp (0-11) - * @param day The day for this Timestamp (1-31) - * @param hour The hour for this Timestamp (0-23) - * @param minute The minute for this Timestamp (0-59) - * @param second The second for this Timestamp (0-59) - * @param nanos The nanosecond value for this Timestamp (0 to 999,999,9999) - * @deprecated - */ - public Timestamp(int year, int month, int day, int hour, int minute, - int second, int nanos) - { - super(year, month, day, hour, minute, second); - this.nanos = nanos; - } - - /** - * This method initializes a new instance of this class with the - * specified time value representing the number of milliseconds since - * Jan 1, 1970 at 12:00 midnight GMT. - * - * @param time The time value to intialize this <code>Time</code> to. - */ - public Timestamp(long date) - { - super(date - (date % 1000)); - nanos = (int) (date % 1000) * 1000000; - } - - /** - * Return the value of this Timestamp as the number of milliseconds - * since Jan 1, 1970 at 12:00 midnight GMT. - */ - public long getTime() - { - return super.getTime() + (nanos / 1000000); - } - - /** - * This method returns this date in JDBC format. - * - * @return This date as a string. - */ - public String toString() - { - synchronized (dateFormat) - { - sbuf.setLength(0); - dateFormat.format(this, sbuf, null); - sbuf.append('.'); - decimalFormat.format(nanos, sbuf, null); - int end = sbuf.length() - 1; - while (end > 20 && sbuf.charAt(end) == '0') - end--; - return sbuf.substring(0, end + 1); - } - } - - /** - * This method returns the nanosecond value for this object. - * @return The nanosecond value for this object. - */ - public int getNanos() - { - return nanos; - } - - /** - * This method sets the nanosecond value for this object. - * - * @param nanos The nanosecond value for this object. - */ - public void setNanos(int nanos) - { - this.nanos = nanos; - } - - /** - * This methods tests whether this object is earlier than the specified - * object. - * - * @param ts The other <code>Timestamp</code> to test against. - * @return <code>true</code> if this object is earlier than the other object, - * <code>false</code> otherwise. - */ - public boolean before(Timestamp ts) - { - long time1 = getTime(); - long time2 = ts.getTime(); - if (time1 < time2 || (time1 == time2 && getNanos() < ts.getNanos())) - return true; - return false; - } - - /** - * This methods tests whether this object is later than the specified - * object. - * - * @param ts The other <code>Timestamp</code> to test against. - * - * @return <code>true</code> if this object is later than the other object, - * <code>false</code> otherwise. - */ - public boolean after(Timestamp ts) - { - long time1 = getTime(); - long time2 = ts.getTime(); - if (time1 > time2 || (time1 == time2 && getNanos() > ts.getNanos())) - return true; - return false; - } - - /** - * This method these the specified <code>Object</code> for equality - * against this object. This will be true if an only if the specified - * object is an instance of <code>Timestamp</code> and has the same - * time value fields. - * - * @param obj The object to test against for equality. - * - * @return <code>true</code> if the specified object is equal to this - * object, <code>false</code> otherwise. - */ - public boolean equals(Object obj) - { - if (!(obj instanceof Timestamp)) - return false; - - return equals((Timestamp) obj); - } - - /** - * This method tests the specified timestamp for equality against this - * object. This will be true if and only if the specified object is - * not <code>null</code> and contains all the same time value fields - * as this object. - * - * @param ts The <code>Timestamp</code> to test against for equality. - * - * @return <code>true</code> if the specified object is equal to this - * object, <code>false</code> otherwise. - */ - public boolean equals(Timestamp ts) - { - if (ts == null) - return false; - - if (ts.getTime() != getTime()) - return false; - - if (ts.getNanos() != getNanos()) - return false; - - return true; - } - - /** - * Compare two Timestamp - * @param when the other Timestamp. - * @return 0, if the date represented - * by obj is exactly the same as the time represented by this - * object, a negative if this Timestamp is before the other Timestamp, and - * a positive value otherwise. - * @since 1.2 - */ - public int compareTo(Timestamp ts) - { - int s = super.compareTo((java.util.Date) ts); - if (s != 0) - return s; - // If Date components were equal, then we check the nanoseconds. - return nanos - ts.nanos; - } - - /** - * Compares this Timestamp to another. This behaves like - * <code>compareTo(Timestamp)</code>, but it may throw a - * <code>ClassCastException</code> - * @param obj the other Timestamp. - * @return 0, if the Timestamp represented - * by obj is exactly the same as the time represented by this - * object, a negative if this Timestamp is before the other Timestamp, and - * a positive value otherwise. - * @exception ClassCastException if obj is not of type Timestamp. - * @since 1.2 - */ - public int compareTo(Object obj) - { - return compareTo((Timestamp) obj); - } -} diff --git a/libjava/java/sql/Types.java b/libjava/java/sql/Types.java deleted file mode 100644 index 7dd41411ada..00000000000 --- a/libjava/java/sql/Types.java +++ /dev/null @@ -1,85 +0,0 @@ -/* Types.java -- SQL type constants - Copyright (C) 1999, 2001 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.sql; - -/** - * This class contains constants that are used to identify SQL data types. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public class Types -{ - // These should be self explanatory. People need a SQL book, not - // Javadoc comments for these. - public static final int BIT = -7; - public static final int TINYINT = -6; - public static final int SMALLINT = 5; - public static final int INTEGER = 4; - public static final int BIGINT = -5; - public static final int FLOAT = 6; - public static final int REAL = 7; - public static final int DOUBLE = 8; - public static final int NUMERIC = 2; - public static final int DECIMAL = 3; - public static final int CHAR = 1; - public static final int VARCHAR = 12; - public static final int LONGVARCHAR = -1; - public static final int DATE = 91; - public static final int TIME = 92; - public static final int TIMESTAMP = 93; - public static final int BINARY = -2; - public static final int VARBINARY = -3; - public static final int LONGVARBINARY = -4; - public static final int NULL = 0; - public static final int OTHER = 1111; - public static final int JAVA_OBJECT = 2000; - public static final int DISTINCT = 2001; - public static final int STRUCT = 2002; - public static final int ARRAY = 2003; - public static final int BLOB = 2004; - public static final int CLOB = 2005; - public static final int REF = 2006; - public static final int DATALINK = 70; - public static final int BOOLEAN = 16; - - // This class can't be instantiated. - private Types() - { - } -} diff --git a/libjava/java/text/Annotation.java b/libjava/java/text/Annotation.java deleted file mode 100644 index cecb44aaf0e..00000000000 --- a/libjava/java/text/Annotation.java +++ /dev/null @@ -1,113 +0,0 @@ -/* Annotation.java -- Wrapper for a text attribute object - Copyright (C) 1998, 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.text; - -/** - * This class is used as a wrapper for a text attribute object. Annotation - * objects are associated with a specific range of text. Changing either - * the text range or the underlying text invalidates the object. - * - * @version 0.0 - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public class Annotation -{ - -/* - * Instance Variables - */ - -/** - * This is the attribute object being wrappered - */ -private Object attrib; - -/*************************************************************************/ - -/** - * Constructors - */ - -/** - * This method initializes a new instance of <code>Annotation</code> to - * wrapper the specified text attribute object. - * - * @param attrib The text attribute <code>Object</code> to wrapper. - */ -public -Annotation(Object attrib) -{ - this.attrib = attrib; -} - -/*************************************************************************/ - -/* - * Instance Variables - */ - -/** - * This method returns the text attribute object this <code>Annotation</code> - * instance is wrappering. - * - * @return The text attribute object for this <code>Annotation</code>. - */ -public Object -getValue() -{ - return(attrib); -} - -/*************************************************************************/ - -/** - * This method returns a <code>String</code> representation of this - * object. - * - * @return This object as a <code>String</code>. - */ -public String -toString() -{ - return(getClass().getName() + "[value=" + attrib.toString() + "]"); -} - -} // class Annotation - diff --git a/libjava/java/text/AttributedCharacterIterator.java b/libjava/java/text/AttributedCharacterIterator.java deleted file mode 100644 index e5686ba346d..00000000000 --- a/libjava/java/text/AttributedCharacterIterator.java +++ /dev/null @@ -1,268 +0,0 @@ -/* AttributedCharacterIterator.java -- Iterate over attributes - Copyright (C) 1998, 1999, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.text; - -import java.io.InvalidObjectException; -import java.io.Serializable; -import java.util.Map; -import java.util.Set; - -/** - * This interface extends the <code>CharacterIterator</code> interface - * in order to support iteration over character attributes as well as - * over the characters themselves. - * <p> - * In addition to attributes of specific characters, this interface - * supports the concept of the "attribute run", which is an attribute - * that is defined for a particular value across an entire range of - * characters or which is undefined over a range of characters. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public interface AttributedCharacterIterator extends CharacterIterator -{ - /** - * This class defines attribute keys that are used as text attributes. - */ - public static class Attribute implements Serializable - { - private static final long serialVersionUID = -9142742483513960612L; - - /** - * This is the attribute for the language of the text. The value of - * attributes of this key type are instances of <code>Locale</code>. - */ - public static final Attribute LANGUAGE = new Attribute ("LANGUAGE"); - - /** - * This is the attribute for the reading form of text. This is used - * for storing pronunciation along with the written text for languages - * which need it. The value of attributes of this key type are - * instances of <code>Annotation</code> which wrappers a <code>String</code>. - */ - public static final Attribute READING = new Attribute ("READING"); - - /** - * This is the attribute for input method segments. The value of attributes - * of this key type are instances of <code>Annotation</code> which wrapper - * a <code>String</code>. - */ - public static final Attribute INPUT_METHOD_SEGMENT = - new Attribute ("INPUT_METHOD_SEGMENT"); - - /** - * This is the name of the attribute key - * @serial - */ - private String name; - - /** - * This method initializes a new instance of this class with the specified - * name. - * - * @param name The name of this attribute key. - */ - protected Attribute (String name) - { - this.name = name; - } - - /** - * This method returns the name of this attribute. - * - * @return The attribute name - */ - protected String getName() - { - return name; - } - - /** - * This method resolves an instance of <code>AttributedCharacterIterator.Attribute</code> - * that is being deserialized to one of the three pre-defined attribute - * constants. It does this by comparing the names of the attributes. The - * constant that the deserialized object resolves to is returned. - * - * @return The resolved contant value - * - * @exception InvalidObjectException If the object being deserialized cannot be resolved. - */ - protected Object readResolve() throws InvalidObjectException - { - if (this.equals (READING)) - return READING; - - if (this.equals (LANGUAGE)) - return LANGUAGE; - - if (this.equals (INPUT_METHOD_SEGMENT)) - return INPUT_METHOD_SEGMENT; - - throw new InvalidObjectException ("Can't resolve Attribute: " + getName()); - } - - /** - * This method tests this object for equality against the specified object. - * The two objects will be considered equal if and only if: - * <ul> - * <li>The specified object is not <code>null</code>. - * <li>The specified object is an instance of <code>AttributedCharacterIterator.Attribute</code>. - * <li>The specified object has the same attribute name as this object. - * </ul> - * - * @param The <code>Object</code> to test for equality against this object. - * - * @return <code>true</code> if the specified object is equal to this one, <code>false</code> otherwise. - */ - public final boolean equals (Object obj) - { - if (obj == this) - return true; - else - return false; - } - - /** - * This method returns a hash value for this object. - * - * @return A hash value for this object. - */ - public final int hashCode() - { - return super.hashCode(); - } - - /** - * This method returns a <code>String</code> representation of this object. - * - * @return A <code>String</code> representation of this object. - */ - public String toString() - { - return getClass().getName() + "(" + getName() + ")"; - } - - } // Inner class Attribute - - /** - * This method returns a list of all keys that are defined for the - * text range. This can be an empty list if no attributes are defined. - * - * @return A list of keys - */ - Set getAllAttributeKeys(); - - /** - * This method returns a <code>Map</code> of the attributed defined for - * the current character. - * - * @return A <code>Map</code> of the attributes for the current character. - */ - Map getAttributes(); - - /** - * This method returns the value of the specified attribute for the - * current character. If the attribute is not defined for the current - * character, <code>null</code> is returned. - * - * @param attrib The attribute to retrieve the value of. - * - * @return The value of the specified attribute - */ - Object getAttribute (AttributedCharacterIterator.Attribute attrib); - - /** - * This method returns the index of the first character in the run that - * contains all attributes defined for the current character. - * - * @return The start index of the run - */ - int getRunStart(); - - /** - * This method returns the index of the first character in the run that - * contains all attributes in the specified <code>Set</code> defined for - * the current character. - * - * @param attribs The <code>Set</code> of attributes. - * - * @return The start index of the run. - */ - int getRunStart (Set attribs); - - /** - * This method returns the index of the first character in the run that - * contains the specified attribute defined for the current character. - * - * @param attrib The attribute. - * - * @return The start index of the run. - */ - int getRunStart (AttributedCharacterIterator.Attribute attrib); - - /** - * This method returns the index of the character after the end of the run - * that contains all attributed defined for the current character. - * - * @return The end index of the run. - */ - int getRunLimit(); - - /** - * This method returns the index of the character after the end of the run - * that contains all attributes in the specified <code>Set</code> defined - * for the current character. - * - * @param attribs The <code>Set</code> of attributes. - * - * @return The end index of the run. - */ - int getRunLimit (Set attribs); - - /** - * This methods returns the index of the character after the end of the run - * that contains the specified attribute defined for the current character. - * - * @param attrib The attribute. - * - * @return The end index of the run. - */ - int getRunLimit (AttributedCharacterIterator.Attribute attrib); - -} // interface AttributedCharacterIterator diff --git a/libjava/java/text/AttributedString.java b/libjava/java/text/AttributedString.java deleted file mode 100644 index b9ced8f5ac2..00000000000 --- a/libjava/java/text/AttributedString.java +++ /dev/null @@ -1,425 +0,0 @@ -/* AttributedString.java -- Models text with attributes - Copyright (C) 1998, 1999, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.text; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Hashtable; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - -/** - * This class models a <code>String</code> with attributes over various - * subranges of the string. It allows applications to access this - * information via the <code>AttributedCharcterIterator</code> interface. - * - * @version 0.0 - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public class AttributedString -{ - -/*************************************************************************/ - -/* - * Inner Classes - */ - -/** - * This class contains the attributes and ranges of text over which - * that attributes apply. - */ -final class AttributeRange -{ - -/* - * Instance Variables - */ - -/** - * A Map of the attributes - */ -Map attribs; - -/** - * The beginning index of the attributes - */ -int begin_index; - -/** - * The ending index of the attributes - */ -int end_index; - -/*************************************************************************/ - -/* - * Constructors - */ - -AttributeRange(Map attribs, int begin_index, int end_index) -{ - this.attribs = attribs; - this.begin_index = begin_index; - this.end_index = end_index; -} - -} // Inner class AttributeRange - -/*************************************************************************/ - -/* - * Instance Variables - */ - -/** - * This object holds the string we are representing. - */ -private StringCharacterIterator sci; - -/** - * This is the attribute information - */ -private AttributeRange[] attribs; - -/*************************************************************************/ - -/* - * Constructors - */ - -/** - * This method initializes a new instance of <code>AttributedString</code> - * that represents the specified <code>String</code> with no attributes. - * - * @param str The <code>String</code> to be attributed. - */ -public -AttributedString(String str) -{ - sci = new StringCharacterIterator(str); - attribs = new AttributeRange[0]; -} - -/*************************************************************************/ - -/** - * This method initializes a new instance of <code>AttributedString</code> - * that represents that specified <code>String</code> with the specified - * attributes over the entire length of the <code>String</code>. - * - * @param str The <code>String</code> to be attributed. - * @param attributes The attribute list. - */ -public -AttributedString(String str, Map attributes) -{ - this(str); - - attribs = new AttributeRange[1]; - attribs[0] = new AttributeRange(attributes, 0, str.length()); -} - -/*************************************************************************/ - -/** - * This method initializes a new instance of <code>AttributedString</code> - * that will use the text and attribute information from the specified - * <code>AttributedCharacterIterator</code>. - * - * @param aci The <code>AttributedCharacterIterator</code> containing the text and attribute information. - */ -public -AttributedString(AttributedCharacterIterator aci) -{ - this(aci, aci.getBeginIndex(), aci.getEndIndex(), null); -} - -/*************************************************************************/ - -/** - * This method initializes a new instance of <code>AttributedString</code> - * that will use the text and attribute information from the specified - * subrange of the specified <code>AttributedCharacterIterator</code>. - * - * @param aci The <code>AttributedCharacterIterator</code> containing the text and attribute information. - * @param begin_index The beginning index of the text subrange. - * @param end_index The ending index of the text subrange. - */ -public -AttributedString(AttributedCharacterIterator aci, int begin_index, - int end_index) -{ - this(aci, begin_index, end_index, null); -} - -/*************************************************************************/ - -/** - * This method initializes a new instance of <code>AttributedString</code> - * that will use the text and attribute information from the specified - * subrange of the specified <code>AttributedCharacterIterator</code>. - * Only attributes from the source iterator that are present in the - * specified array of attributes will be included in the attribute list - * for this object. - * - * @param aci The <code>AttributedCharacterIterator</code> containing the text and attribute information. - * @param begin_index The beginning index of the text subrange. - * @param end_index The ending index of the text subrange. - * @param attributes A list of attributes to include from the iterator, or <code>null</code> to include all attributes. - */ -public -AttributedString(AttributedCharacterIterator aci, int begin_index, - int end_index, AttributedCharacterIterator.Attribute[] attributes) -{ - // Validate some arguments - if ((begin_index < 0) || (end_index < begin_index)) - throw new IllegalArgumentException("Bad index values"); - - StringBuffer sb = new StringBuffer(""); - - // Get the valid attribute list - Set all_attribs = aci.getAllAttributeKeys(); - if (attributes != null) - all_attribs.retainAll(Arrays.asList(attributes)); - - // Loop through and extract the attributes - char c = aci.setIndex(begin_index); - - ArrayList accum = new ArrayList(); - do - { - sb.append(c); - - Iterator iter = all_attribs.iterator(); - while(iter.hasNext()) - { - Object obj = iter.next(); - - // What should we do if this is not true? - if (!(obj instanceof AttributedCharacterIterator.Attribute)) - continue; - - AttributedCharacterIterator.Attribute attrib = - (AttributedCharacterIterator.Attribute)obj; - - // Make sure the attribute is defined. - int rl = aci.getRunLimit(attrib); - if (rl == -1) - continue; - if (rl > end_index) - rl = end_index; - rl -= begin_index; - - // Check to see if we already processed this one - int rs = aci.getRunStart(attrib); - if ((rs < aci.getIndex()) && (aci.getIndex() != begin_index)) - continue; - - // If the attribute run starts before the beginning index, we - // need to junk it if it is an Annotation. - Object attrib_obj = aci.getAttribute(attrib); - if (rs < begin_index) - { - if (attrib_obj instanceof Annotation) - continue; - - rs = begin_index; - } - else - { - rs -= begin_index; - } - - // Create a map object. Yes this will only contain one attribute - Map new_map = new Hashtable(); - new_map.put(attrib, attrib_obj); - - // Add it to the attribute list. - accum.add(new AttributeRange(new_map, rs, rl)); - } - - c = aci.next(); - } - while(c != CharacterIterator.DONE); - - attribs = new AttributeRange[accum.size()]; - attribs = (AttributeRange[]) accum.toArray(attribs); - - sci = new StringCharacterIterator(sb.toString()); -} - -/*************************************************************************/ - -/* - * Instance Methods - */ - -/** - * This method adds a new attribute that will cover the entire string. - * - * @param attrib The attribute to add. - * @param value The value of the attribute. - */ -public void -addAttribute(AttributedCharacterIterator.Attribute attrib, Object value) -{ - addAttribute(attrib, value, 0, sci.getEndIndex()); -} - -/*************************************************************************/ - -/** - * This method adds a new attribute that will cover the specified subrange - * of the string. - * - * @param attrib The attribute to add. - * @param value The value of the attribute, which may be null. - * @param begin_index The beginning index of the subrange. - * @param end_index The ending index of the subrange. - * - * @exception IllegalArgumentException If attribute is <code>null</code> or the subrange is not valid. - */ -public void -addAttribute(AttributedCharacterIterator.Attribute attrib, Object value, - int begin_index, int end_index) -{ - if (attrib == null) - throw new IllegalArgumentException("null attribute"); - - HashMap hm = new HashMap(); - hm.put(attrib, value); - - addAttributes(hm, begin_index, end_index); -} - -/*************************************************************************/ - -/** - * This method adds all of the attributes in the specified list to the - * specified subrange of the string. - * - * @param attributes The list of attributes. - * @param begin_index The beginning index. - * @param end_index The ending index - * - * @param IllegalArgumentException If the list is <code>null</code> or the subrange is not valid. - */ -public void -addAttributes(Map attributes, int begin_index, int end_index) -{ - if (attributes == null) - throw new IllegalArgumentException("null attribute"); - - if ((begin_index < 0) || (end_index > sci.getEndIndex()) || - (end_index < begin_index)) - throw new IllegalArgumentException("bad range"); - - AttributeRange[] new_list = new AttributeRange[attribs.length + 1]; - System.arraycopy(attribs, 0, new_list, 0, attribs.length); - attribs = new_list; - attribs[attribs.length - 1] = new AttributeRange(attributes, begin_index, - end_index); -} - -/*************************************************************************/ - -/** - * This method returns an <code>AttributedCharacterIterator</code> that - * will iterate over the entire string. - * - * @return An <code>AttributedCharacterIterator</code> for the entire string. - */ -public AttributedCharacterIterator -getIterator() -{ - return(new AttributedStringIterator(sci, attribs, 0, sci.getEndIndex(), null)); -} - -/*************************************************************************/ - -/** - * This method returns an <code>AttributedCharacterIterator</code> that - * will iterate over the entire string. This iterator will return information - * about the list of attributes in the specified array. Attributes not in - * the array may or may not be returned by the iterator. If the specified - * array is <code>null</code>, all attributes will be returned. - * - * @param attributes A list of attributes to include in the returned iterator. - * - * @return An <code>AttributedCharacterIterator</code> for this string. - */ -public AttributedCharacterIterator -getIterator(AttributedCharacterIterator.Attribute[] attributes) -{ - return(getIterator(attributes, 0, sci.getEndIndex())); -} - -/*************************************************************************/ - -/** - * This method returns an <code>AttributedCharacterIterator</code> that - * will iterate over the specified subrange. This iterator will return information - * about the list of attributes in the specified array. Attributes not in - * the array may or may not be returned by the iterator. If the specified - * array is <code>null</code>, all attributes will be returned. - * - * @param attributes A list of attributes to include in the returned iterator. - * @param begin_index The beginning index of the subrange. - * @param end_index The ending index of the subrange. - * - * @return An <code>AttributedCharacterIterator</code> for this string. - */ -public AttributedCharacterIterator -getIterator(AttributedCharacterIterator.Attribute[] attributes, - int begin_index, int end_index) -{ - if ((begin_index < 0) || (end_index > sci.getEndIndex()) || - (end_index < begin_index)) - throw new IllegalArgumentException("bad range"); - - return(new AttributedStringIterator(sci, attribs, begin_index, end_index, - attributes)); -} - -} // class AttributedString - diff --git a/libjava/java/text/AttributedStringIterator.java b/libjava/java/text/AttributedStringIterator.java deleted file mode 100644 index 6a35598b497..00000000000 --- a/libjava/java/text/AttributedStringIterator.java +++ /dev/null @@ -1,348 +0,0 @@ -/* AttributedStringIterator.java -- Class to iterate over AttributedString - Copyright (C) 1998, 1999, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.text; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - -/** - * This class implements the AttributedCharacterIterator interface. It - * is used by AttributedString.getIterator(). - * - * @version 0.0 - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -class AttributedStringIterator implements AttributedCharacterIterator -{ - -/*************************************************************************/ - -/** - * Instance Variables - */ - -/** - * The character iterator containing the text - */ -private CharacterIterator ci; - -/** - * The list of attributes and ranges - */ -private AttributedString.AttributeRange[] attribs; - -/** - * The list of attributes that the user is interested in. We may, - * at our option, not return any other attributes. - */ -private AttributedCharacterIterator.Attribute[] restricts; - -/*************************************************************************/ - -/* - * Constructors - */ - -AttributedStringIterator(StringCharacterIterator sci, - AttributedString.AttributeRange[] attribs, - int begin_index, int end_index, - AttributedCharacterIterator.Attribute[] restricts) -{ - this.ci = new StringCharacterIterator(sci, begin_index, end_index); - this.attribs = attribs; - this.restricts = restricts; -} - -/*************************************************************************/ - -/* - * Instance Methods - */ - -// First we have a bunch of stupid redirects. If StringCharacterIterator -// weren't final, I just would have extended that for this class. Alas, no. - -public Object -clone() -{ - return(ci.clone()); -} - -public char -current() -{ - return(ci.current()); -} - -public char -next() -{ - return(ci.next()); -} - -public char -previous() -{ - return(ci.previous()); -} - -public char -first() -{ - return(ci.first()); -} - -public char -last() -{ - return(ci.last()); -} - -public int -getIndex() -{ - return(ci.getIndex()); -} - -public char -setIndex(int index) -{ - return(ci.setIndex(index)); -} - -public int -getBeginIndex() -{ - return(ci.getBeginIndex()); -} - -public int -getEndIndex() -{ - return(ci.getEndIndex()); -} - -/* - * Here is where the AttributedCharacterIterator methods start. - */ - -/*************************************************************************/ - -/** - * Returns a list of all the attribute keys that are defined anywhere - * on this string. - */ -public Set -getAllAttributeKeys() -{ - HashSet s = new HashSet(); - if (attribs == null) - return(s); - - for (int i = 0; i < attribs.length; i++) - { - if (attribs[i].begin_index > getEndIndex() - || attribs[i].end_index <= getBeginIndex()) - continue; - - Set key_set = attribs[i].attribs.keySet(); - Iterator iter = key_set.iterator(); - while (iter.hasNext()) - { - s.add(iter.next()); - } - } - - return(s); -} - -/*************************************************************************/ - -/** - * Various methods that determine how far the run extends for various - * attribute combinations. - */ - -public int -getRunLimit() -{ - return(getRunLimit(getAttributes().keySet())); -} - -public int -getRunLimit(AttributedCharacterIterator.Attribute attrib) -{ - HashSet s = new HashSet(); - s.add(attrib); - - return(getRunLimit(s)); -} - -public synchronized int -getRunLimit(Set attribute_set) -{ - boolean hit = false; - int runLimit = ci.getEndIndex (); - int pos = ci.getIndex (); - - for (int i = 0; i < attribs.length; ++i) - { - if (pos >= attribs[i].begin_index && - pos <= attribs[i].end_index) - { - Iterator iter = attribute_set.iterator(); - while(iter.hasNext()) - if (attribs[i].attribs.containsKey(iter.next())) - { - hit = true; - runLimit = Math.min(runLimit, attribs[i].end_index); - } - } - } - if (hit) - return runLimit; - else - return -1; -} - -/*************************************************************************/ - -/** - * Various methods that determine where the run begins for various - * attribute combinations. - */ - -public int -getRunStart() -{ - return(getRunStart(getAttributes().keySet())); -} - -public int -getRunStart(AttributedCharacterIterator.Attribute attrib) -{ - HashSet s = new HashSet(); - s.add(attrib); - - return(getRunStart(s)); -} - -public int -getRunStart(Set attribute_set) -{ - boolean hit = false; - int runBegin = 0; - int pos = ci.getIndex (); - - for (int i = 0; i < attribs.length; ++i) - { - if (pos >= attribs[i].begin_index && - pos <= attribs[i].end_index) - { - Iterator iter = attribute_set.iterator(); - while(iter.hasNext()) - if (attribs[i].attribs.containsKey(iter.next())) - { - hit = true; - runBegin = Math.max(runBegin, attribs[i].begin_index); - } - } - } - if (hit) - return runBegin; - else - return -1; -} - -/*************************************************************************/ - -public Object -getAttribute(AttributedCharacterIterator.Attribute attrib) -{ - if (attribs == null) - return(null); - - for (int i = 0; i < attribs.length; i++) - { - Set key_set = attribs[i].attribs.keySet(); - Iterator iter = key_set.iterator(); - while (iter.hasNext()) - { - Object obj = iter.next(); - - // Check for attribute match and range match - if (obj.equals(attrib)) - if ((ci.getIndex() >= attribs[i].begin_index) && - (ci.getIndex() < attribs[i].end_index)) - return(attribs[i].attribs.get(obj)); - } - } - - return(null); -} - -/*************************************************************************/ - -/** - * Return a list of all the attributes and values defined for this - * character - */ -public Map -getAttributes() -{ - HashMap m = new HashMap(); - if (attribs == null) - return(m); - - for (int i = 0; i < attribs.length; i++) - { - if ((ci.getIndex() >= attribs[i].begin_index) && - (ci.getIndex() < attribs[i].end_index)) - m.putAll(attribs[i].attribs); - } - - return(m); -} - -} // class AttributedStringIterator - diff --git a/libjava/java/text/BreakIterator.java b/libjava/java/text/BreakIterator.java deleted file mode 100644 index d021dceba73..00000000000 --- a/libjava/java/text/BreakIterator.java +++ /dev/null @@ -1,374 +0,0 @@ -/* BreakIterator.java -- Breaks text into elements - Copyright (C) 1998, 1999, 2001, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.text; - -import java.util.Locale; -import java.util.MissingResourceException; -import java.util.ResourceBundle; - -/** - * This class iterates over text elements such as words, lines, sentences, - * and characters. It can only iterate over one of these text elements at - * a time. An instance of this class configured for the desired iteration - * type is created by calling one of the static factory methods, not - * by directly calling a constructor. - * - * The standard iterators created by the factory methods in this - * class will be valid upon creation. That is, their methods will - * not cause exceptions if called before you call setText(). - * - * @author Tom Tromey (tromey@cygnus.com) - * @author Aaron M. Renn (arenn@urbanophile.com) - * @date March 19, 1999 - */ -/* Written using "Java Class Libraries", 2nd edition, plus online - * API docs for JDK 1.2 beta from http://www.javasoft.com. - * Status: Believed complete and correct to 1.1. - */ -public abstract class BreakIterator implements Cloneable -{ - /** - * This value is returned by the <code>next()</code> and - * <code>previous</code> in order to indicate that the end of the - * text has been reached. - */ - // The value was discovered by writing a test program. - public static final int DONE = -1; - - /** - * This method initializes a new instance of <code>BreakIterator</code>. - * This protected constructor is available to subclasses as a default - * no-arg superclass constructor. - */ - protected BreakIterator () - { - } - - /** - * Create a clone of this object. - */ - public Object clone () - { - try - { - return super.clone(); - } - catch (CloneNotSupportedException e) - { - return null; - } - } - - /** - * This method returns the index of the current text element boundary. - * - * @return The current text boundary. - */ - public abstract int current (); - - /** - * This method returns the first text element boundary in the text being - * iterated over. - * - * @return The first text boundary. - */ - public abstract int first (); - - /** - * This methdod returns the offset of the text element boundary following - * the specified offset. - * - * @param offset The text index from which to find the next text boundary. - * - * @param The next text boundary following the specified index. - */ - public abstract int following (int pos); - - /** - * This method returns a list of locales for which instances of - * <code>BreakIterator</code> are available. - * - * @return A list of available locales - */ - public static synchronized Locale[] getAvailableLocales () - { - Locale[] l = new Locale[1]; - l[0] = Locale.US; - return l; - } - - private static BreakIterator getInstance (String type, Locale loc) - { - String className; - try - { - ResourceBundle res - = ResourceBundle.getBundle("gnu.java.locale.LocaleInformation", - loc, ClassLoader.getSystemClassLoader()); - className = res.getString(type); - } - catch (MissingResourceException x) - { - return null; - } - try - { - Class k = Class.forName(className); - return (BreakIterator) k.newInstance(); - } - catch (ClassNotFoundException x1) - { - return null; - } - catch (InstantiationException x2) - { - return null; - } - catch (IllegalAccessException x3) - { - return null; - } - } - - /** - * This method returns an instance of <code>BreakIterator</code> that will - * iterate over characters as defined in the default locale. - * - * @return A <code>BreakIterator</code> instance for the default locale. - */ - public static BreakIterator getCharacterInstance () - { - return getCharacterInstance (Locale.getDefault()); - } - - /** - * This method returns an instance of <code>BreakIterator</code> that will - * iterate over characters as defined in the specified locale. If the - * desired locale is not available, the default locale is used. - * - * @param locale The desired locale. - * - * @return A <code>BreakIterator</code> instance for the default locale. - */ - public static BreakIterator getCharacterInstance (Locale loc) - { - BreakIterator r = getInstance ("CharacterIterator", loc); - if (r == null) - r = new gnu.java.text.CharacterBreakIterator (); - return r; - } - - /** - * This method returns an instance of <code>BreakIterator</code> that will - * iterate over line breaks as defined in the default locale. - * - * @return A <code>BreakIterator</code> instance for the default locale. - */ - public static BreakIterator getLineInstance () - { - return getLineInstance (Locale.getDefault()); - } - - /** - * This method returns an instance of <code>BreakIterator</code> that will - * iterate over line breaks as defined in the specified locale. If the - * desired locale is not available, the default locale is used. - * - * @param locale The desired locale. - * - * @return A <code>BreakIterator</code> instance for the default locale. - */ - public static BreakIterator getLineInstance (Locale loc) - { - BreakIterator r = getInstance ("LineIterator", loc); - if (r == null) - r = new gnu.java.text.LineBreakIterator (); - return r; - } - - /** - * This method returns an instance of <code>BreakIterator</code> that will - * iterate over sentences as defined in the default locale. - * - * @return A <code>BreakIterator</code> instance for the default locale. - */ - public static BreakIterator getSentenceInstance () - { - return getSentenceInstance (Locale.getDefault()); - } - - /** - * This method returns an instance of <code>BreakIterator</code> that will - * iterate over sentences as defined in the specified locale. If the - * desired locale is not available, the default locale is used. - * - * @param locale The desired locale. - * - * @return A <code>BreakIterator</code> instance for the default locale. - */ - public static BreakIterator getSentenceInstance (Locale loc) - { - BreakIterator r = getInstance ("SentenceIterator", loc); - if (r == null) - r = new gnu.java.text.SentenceBreakIterator (); - return r; - } - - /** - * This method returns the text this object is iterating over as a - * <code>CharacterIterator</code>. - * - * @param The text being iterated over. - */ - public abstract CharacterIterator getText (); - - /** - * This method returns an instance of <code>BreakIterator</code> that will - * iterate over words as defined in the default locale. - * - * @return A <code>BreakIterator</code> instance for the default locale. - */ - public static BreakIterator getWordInstance () - { - return getWordInstance (Locale.getDefault()); - } - - /** - * This method returns an instance of <code>BreakIterator</code> that will - * iterate over words as defined in the specified locale. If the - * desired locale is not available, the default locale is used. - * - * @param locale The desired locale. - * - * @return A <code>BreakIterator</code> instance for the default locale. - */ - public static BreakIterator getWordInstance (Locale loc) - { - BreakIterator r = getInstance ("WordIterator", loc); - if (r == null) - r = new gnu.java.text.WordBreakIterator (); - return r; - } - - /** - * This method tests whether or not the specified position is a text - * element boundary. - * - * @param offset The text position to test. - * - * @return <code>true</code> if the position is a boundary, - * <code>false</code> otherwise. - */ - public boolean isBoundary (int pos) - { - if (pos == 0) - return true; - return following (pos - 1) == pos; - } - - /** - * This method returns the last text element boundary in the text being - * iterated over. - * - * @return The last text boundary. - */ - public abstract int last (); - - /** - * This method returns the text element boundary following the current - * text position. - * - * @return The next text boundary. - */ - public abstract int next (); - - /** - * This method returns the n'th text element boundary following the current - * text position. - * - * @param n The number of text element boundaries to skip. - * - * @return The next text boundary. - */ - public abstract int next (int n); - - /** - * This methdod returns the offset of the text element boundary preceding - * the specified offset. - * - * @param offset The text index from which to find the preceding - * text boundary. - * - * @returns The next text boundary preceding the specified index. - */ - public int preceding (int pos) - { - if (following (pos) == DONE) - last (); - while (previous () >= pos) - ; - return current (); - } - - /** - * This method returns the text element boundary preceding the current - * text position. - * - * @return The previous text boundary. - */ - public abstract int previous (); - - /** - * This method sets the text string to iterate over. - * - * @param str The <code>String</code> to iterate over. - */ - public void setText (String newText) - { - setText (new StringCharacterIterator (newText)); - } - - /** - * This method sets the text to iterate over from the specified - * <code>CharacterIterator</code>. - * - * @param ci The desired <code>CharacterIterator</code>. - */ - public abstract void setText (CharacterIterator newText); -} diff --git a/libjava/java/text/CharacterIterator.java b/libjava/java/text/CharacterIterator.java deleted file mode 100644 index 6b3f951d1fb..00000000000 --- a/libjava/java/text/CharacterIterator.java +++ /dev/null @@ -1,144 +0,0 @@ -/* CharacterIterator.java -- Iterate over a character range - Copyright (C) 1998, 2001 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.text; - -/** - * This interface defines a mechanism for iterating over a range of - * characters. For a given range of text, a beginning and ending index, - * as well as a current index are defined. These values can be queried - * by the methods in this interface. Additionally, various methods allow - * the index to be set. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public interface CharacterIterator extends Cloneable -{ - /** - * This is a special constant value that is returned when the beginning or - * end of the character range has been reached. - */ - char DONE = '\uFFFF'; - - /** - * This method returns the character at the current index position - * - * @return The character at the current index position. - */ - char current(); - - /** - * This method increments the current index and then returns the character - * at the new index value. If the index is already at <code>getEndIndex() - 1</code>, - * it will not be incremented. - * - * @return The character at the position of the incremented index value, - * or <code>DONE</code> if the index has reached getEndIndex() - 1 - */ - char next(); - - /** - * This method decrements the current index and then returns the character - * at the new index value. If the index value is already at the beginning - * index, it will not be decremented. - * - * @return The character at the position of the decremented index value, - * or <code>DONE</code> if index was already equal to the beginning index value. - */ - char previous(); - - /** - * This method sets the index value to the beginning of the range and returns - * the character there. - * - * @return The character at the beginning of the range, or <code>DONE</code> if the range is empty. - */ - char first(); - - /** - * This method sets the index value to <code>getEndIndex() - 1</code> and - * returns the character there. If the range is empty, then the index value - * will be set equal to the beginning index. - * - * @return The character at the end of the range, or <code>DONE</code> if the range is empty. - */ - char last(); - - /** - * This method returns the current value of the index. - * - * @return The current index value - */ - int getIndex(); - - /** - * This method sets the value of the index to the specified value, then - * returns the character at that position. - * - * @param index The new index value. - * - * @return The character at the new index value or <code>DONE</code> if the index value is equal to <code>getEndIndex</code>. - */ - char setIndex (int index) throws IllegalArgumentException; - - /** - * This method returns the character position of the first character in the - * range. - * - * @return The index of the first character in the range. - */ - int getBeginIndex(); - - /** - * This method returns the character position of the end of the text range. - * This will actually be the index of the first character following the - * end of the range. In the event the text range is empty, this will be - * equal to the first character in the range. - * - * @return The index of the end of the range. - */ - int getEndIndex(); - - /** - * This method creates a copy of this <code>CharacterIterator</code>. - * - * @return A copy of this <code>CharacterIterator</code>. - */ - Object clone(); - -} // interface CharacterIterator diff --git a/libjava/java/text/ChoiceFormat.java b/libjava/java/text/ChoiceFormat.java deleted file mode 100644 index 23c8a8c3af0..00000000000 --- a/libjava/java/text/ChoiceFormat.java +++ /dev/null @@ -1,503 +0,0 @@ -/* ChoiceFormat.java -- Format over a range of numbers - Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004, 2005 - Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.text; - -import java.util.Vector; - -/** - * This class allows a format to be specified based on a range of numbers. - * To use this class, first specify two lists of formats and range terminators. - * These lists must be arrays of equal length. The format of index - * <code>i</code> will be selected for value <code>X</code> if - * <code>terminator[i] <= X < limit[i + 1]</code>. If the value X is not - * included in any range, then either the first or last format will be - * used depending on whether the value X falls outside the range. - * <p> - * This sounds complicated, but that is because I did a poor job of - * explaining it. Consider the following example: - * <p> - * -<pre>terminators = { 1, ChoiceFormat.nextDouble(1) } -formats = { "file", "files" }</pre> - * - * <p> - * In this case if the actual number tested is one or less, then the word - * "file" is used as the format value. If the number tested is greater than - * one, then "files" is used. This allows plurals to be handled - * gracefully. Note the use of the method <code>nextDouble</code>. This - * method selects the next highest double number than its argument. This - * effectively makes any double greater than 1.0 cause the "files" string - * to be selected. (Note that all terminator values are specified as - * doubles. - * <p> - * Note that in order for this class to work properly, the range terminator - * array must be sorted in ascending order and the format string array - * must be the same length as the terminator array. - * - * @author Tom Tromey (tromey@cygnus.com) - * @author Aaron M. Renn (arenn@urbanophile.com) - * @date March 9, 1999 - */ -/* Written using "Java Class Libraries", 2nd edition, plus online - * API docs for JDK 1.2 from http://www.javasoft.com. - * Status: Believed complete and correct to 1.1. - */ -public class ChoiceFormat extends NumberFormat -{ - /** - * This method sets new range terminators and format strings for this - * object based on the specified pattern. This pattern is of the form - * "term#string|term#string...". For example "1#Sunday|2#Monday|#Tuesday". - * - * @param pattern The pattern of terminators and format strings. - * - * @exception IllegalArgumentException If the pattern is not valid - */ - public void applyPattern (String newPattern) - { - // Note: we assume the same kind of quoting rules apply here. - // This isn't explicitly documented. But for instance we accept - // '#' as a literal hash in a format string. - int index = 0, max = newPattern.length(); - Vector stringVec = new Vector (); - Vector limitVec = new Vector (); - StringBuffer buf = new StringBuffer (); - - while (true) - { - // Find end of double. - int dstart = index; - while (index < max) - { - char c = newPattern.charAt(index); - if (c == '#' || c == '\u2064' || c == '<') - break; - ++index; - } - - if (index == max) - throw new IllegalArgumentException ("unexpected end of text"); - Double d = new Double (newPattern.substring(dstart, index)); - - if (newPattern.charAt(index) == '<') - d = new Double (nextDouble (d.doubleValue())); - - limitVec.addElement(d); - - // Scan text. - ++index; - buf.setLength(0); - while (index < max) - { - char c = newPattern.charAt(index); - if (c == '\'' && index < max + 1 - && newPattern.charAt(index + 1) == '\'') - { - buf.append(c); - ++index; - } - else if (c == '\'' && index < max + 2) - { - buf.append(newPattern.charAt(index + 1)); - index += 2; - } - else if (c == '|') - break; - else - buf.append(c); - ++index; - } - - stringVec.addElement(buf.toString()); - if (index == max) - break; - ++index; - } - - choiceFormats = new String[stringVec.size()]; - stringVec.copyInto(choiceFormats); - - choiceLimits = new double[limitVec.size()]; - for (int i = 0; i < choiceLimits.length; ++i) - { - Double d = (Double) limitVec.elementAt(i); - choiceLimits[i] = d.doubleValue(); - } - } - - /** - * This method initializes a new instance of <code>ChoiceFormat</code> that - * generates its range terminator and format string arrays from the - * specified pattern. This pattern is of the form - * "term#string|term#string...". For example "1#Sunday|2#Monday|#Tuesday". - * This is the same pattern type used by the <code>applyPattern</code> - * method. - * - * @param pattern The pattern of terminators and format strings. - * - * @exception IllegalArgumentException If the pattern is not valid - */ - public ChoiceFormat (String newPattern) - { - super (); - applyPattern (newPattern); - } - - /** - * This method initializes a new instance of <code>ChoiceFormat</code> that - * will use the specified range terminators and format strings. - * - * @param choiceLimits The array of range terminators - * @param choiceFormats The array of format strings - */ - public ChoiceFormat (double[] choiceLimits, String[] choiceFormats) - { - super (); - setChoices (choiceLimits, choiceFormats); - } - - /** - * This method tests this object for equality with the specified - * object. This will be true if and only if: - * <ul> - * <li>The specified object is not <code>null</code>.</li> - * <li>The specified object is an instance of <code>ChoiceFormat</code>.</li> - * <li>The termination ranges and format strings are identical to - * this object's. </li> - * </ul> - * - * @param obj The object to test for equality against. - * - * @return <code>true</code> if the specified object is equal to - * this one, <code>false</code> otherwise. - */ - public boolean equals (Object obj) - { - if (! (obj instanceof ChoiceFormat)) - return false; - ChoiceFormat cf = (ChoiceFormat) obj; - if (choiceLimits.length != cf.choiceLimits.length) - return false; - for (int i = choiceLimits.length - 1; i >= 0; --i) - { - if (choiceLimits[i] != cf.choiceLimits[i] - || !choiceFormats[i].equals(cf.choiceFormats[i])) - return false; - } - return true; - } - - /** - * This method appends the appropriate format string to the specified - * <code>StringBuffer</code> based on the supplied <code>long</code> - * argument. - * - * @param number The number used for determine (based on the range - * terminators) which format string to append. - * @param sb The <code>StringBuffer</code> to append the format string to. - * @param status Unused. - * - * @return The <code>StringBuffer</code> with the format string appended. - */ - public StringBuffer format (long num, StringBuffer appendBuf, - FieldPosition pos) - { - return format ((double) num, appendBuf, pos); - } - - /** - * This method appends the appropriate format string to the specified - * <code>StringBuffer</code> based on the supplied <code>double</code> - * argument. - * - * @param number The number used for determine (based on the range - * terminators) which format string to append. - * @param sb The <code>StringBuffer</code> to append the format string to. - * @param status Unused. - * - * @return The <code>StringBuffer</code> with the format string appended. - */ - public StringBuffer format (double num, StringBuffer appendBuf, - FieldPosition pos) - { - if (choiceLimits.length == 0) - return appendBuf; - - int index = 0; - if (! Double.isNaN(num) && num >= choiceLimits[0]) - { - for (; index < choiceLimits.length - 1; ++index) - { - if (choiceLimits[index] <= num && num < choiceLimits[index + 1]) - break; - } - } - - return appendBuf.append(choiceFormats[index]); - } - - /** - * This method returns the list of format strings in use. - * - * @return The list of format objects. - */ - public Object[] getFormats () - { - return (Object[]) choiceFormats.clone(); - } - - /** - * This method returns the list of range terminators in use. - * - * @return The list of range terminators. - */ - public double[] getLimits () - { - return (double[]) choiceLimits.clone(); - } - - /** - * This method returns a hash value for this object - * - * @return A hash value for this object. - */ - public int hashCode () - { - int hash = 0; - for (int i = 0; i < choiceLimits.length; ++i) - { - long v = Double.doubleToLongBits(choiceLimits[i]); - hash ^= (v ^ (v >>> 32)); - hash ^= choiceFormats[i].hashCode(); - } - return hash; - } - - /** - * This method returns the lowest possible double greater than the - * specified double. If the specified double value is equal to - * <code>Double.NaN</code> then that is the value returned. - * - * @param d The specified double - * - * @return The lowest double value greater than the specified double. - */ - public static final double nextDouble (double d) - { - return nextDouble (d, true); - } - - /** - * This method returns a double that is either the next highest double - * or next lowest double compared to the specified double depending on the - * value of the passed boolean parameter. If the boolean parameter is - * <code>true</code>, then the lowest possible double greater than the - * specified double will be returned. Otherwise the highest possible - * double less than the specified double will be returned. - * - * @param d The specified double - * @param positive <code>true</code> to return the next highest - * double, <code>false</code> otherwise. - * - * @return The next highest or lowest double value. - */ - public static double nextDouble (double d, boolean next) - { - if (Double.isInfinite(d) || Double.isNaN(d)) - return d; - - long bits = Double.doubleToLongBits(d); - - long mantMask = (1L << mantissaBits) - 1; - long mantissa = bits & mantMask; - - long expMask = (1L << exponentBits) - 1; - long exponent = (bits >>> mantissaBits) & expMask; - - if (next ^ (bits < 0)) // Increment magnitude - { - if (mantissa == (1L << mantissaBits) - 1) - { - mantissa = 0L; - exponent++; - - // Check for absolute overflow. - if (exponent >= (1L << mantissaBits)) - return (bits > 0) ? Double.POSITIVE_INFINITY - : Double.NEGATIVE_INFINITY; - } - else - mantissa++; - } - else // Decrement magnitude - { - if (exponent == 0L && mantissa == 0L) - { - // The only case where there is a change of sign - return next ? Double.MIN_VALUE : -Double.MIN_VALUE; - } - else - { - if (mantissa == 0L) - { - mantissa = (1L << mantissaBits) - 1; - exponent--; - } - else - mantissa--; - } - } - - long result = bits < 0 ? 1 : 0; - result = (result << exponentBits) | exponent; - result = (result << mantissaBits) | mantissa; - return Double.longBitsToDouble(result); - } - - /** - * I'm not sure what this method is really supposed to do, as it is - * not documented. - */ - public Number parse (String sourceStr, ParsePosition pos) - { - int index = pos.getIndex(); - for (int i = 0; i < choiceLimits.length; ++i) - { - if (sourceStr.startsWith(choiceFormats[i], index)) - { - pos.setIndex(index + choiceFormats[i].length()); - return new Double (choiceLimits[i]); - } - } - pos.setErrorIndex(index); - return new Double (Double.NaN); - } - - /** - * This method returns the highest possible double less than the - * specified double. If the specified double value is equal to - * <code>Double.NaN</code> then that is the value returned. - * - * @param d The specified double - * - * @return The highest double value less than the specified double. - */ - public static final double previousDouble (double d) - { - return nextDouble (d, false); - } - - /** - * This method sets new range terminators and format strings for this - * object. - * - * @param choiceLimits The new range terminators - * @param choiceFormats The new choice formats - */ - public void setChoices (double[] choiceLimits, String[] choiceFormats) - { - if (choiceLimits == null || choiceFormats == null) - throw new NullPointerException (); - if (choiceLimits.length != choiceFormats.length) - throw new IllegalArgumentException (); - this.choiceFormats = (String[]) choiceFormats.clone(); - this.choiceLimits = (double[]) choiceLimits.clone(); - } - - private void quoteString (StringBuffer dest, String text) - { - int max = text.length(); - for (int i = 0; i < max; ++i) - { - char c = text.charAt(i); - if (c == '\'') - { - dest.append(c); - dest.append(c); - } - else if (c == '#' || c == '|' || c == '\u2064' || c == '<') - { - dest.append('\''); - dest.append(c); - dest.append('\''); - } - else - dest.append(c); - } - } - - /** - * This method returns the range terminator list and format string list - * as a <code>String</code> suitable for using with the - * <code>applyPattern</code> method. - * - * @return A pattern string for this object - */ - public String toPattern () - { - StringBuffer result = new StringBuffer (); - for (int i = 0; i < choiceLimits.length; ++i) - { - result.append(choiceLimits[i]); - result.append('#'); - quoteString (result, choiceFormats[i]); - } - return result.toString(); - } - - /** - * This is the list of format strings. Note that this variable is - * specified by the serialization spec of this class. - */ - private String[] choiceFormats; - - /** - * This is the list of range terminator values. Note that this variable is - * specified by the serialization spec of this class. - */ - private double[] choiceLimits; - - // Number of mantissa bits in double. - private static final int mantissaBits = 52; - // Number of exponent bits in a double. - private static final int exponentBits = 11; - - private static final long serialVersionUID = 1795184449645032964L; -} diff --git a/libjava/java/text/CollationElementIterator.java b/libjava/java/text/CollationElementIterator.java deleted file mode 100644 index 60b148ef7c1..00000000000 --- a/libjava/java/text/CollationElementIterator.java +++ /dev/null @@ -1,467 +0,0 @@ -/* CollationElementIterator.java -- Walks through collation elements - Copyright (C) 1998, 1999, 2001, 2002, 2003, 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.text; - -import java.util.ArrayList; - -/* Written using "Java Class Libraries", 2nd edition, plus online - * API docs for JDK 1.2 from http://www.javasoft.com. - * Status: Believed complete and correct to JDK 1.1. - */ - -/** - * This class walks through the character collation elements of a - * <code>String</code> as defined by the collation rules in an instance of - * <code>RuleBasedCollator</code>. There is no public constructor for - * this class. An instance is created by calling the - * <code>getCollationElementIterator</code> method on - * <code>RuleBasedCollator</code>. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Tom Tromey (tromey@cygnus.com) - * @author Guilhem Lavaux (guilhem.lavaux@free.fr) - */ -public final class CollationElementIterator -{ - /** - * This is a constant value that is returned to indicate that the end of - * the string was encountered. - */ - public static final int NULLORDER = -1; - - /** - * This is the RuleBasedCollator this object was created from. - */ - RuleBasedCollator collator; - - /** - * This is the String that is being iterated over. - */ - String text; - - /** - * This is the index into the collation decomposition where we are currently scanning. - */ - int index; - - /** - * This is the index into the String where we are currently scanning. - */ - int textIndex; - - /** - * Array containing the collation decomposition of the - * text given to the constructor. - */ - private RuleBasedCollator.CollationElement[] text_decomposition; - - /** - * Array containing the index of the specified block. - */ - private int[] text_indexes; - - /** - * This method initializes a new instance of <code>CollationElementIterator</code> - * to iterate over the specified <code>String</code> using the rules in the - * specified <code>RuleBasedCollator</code>. - * - * @param collator The <code>RuleBasedCollation</code> used for calculating collation values - * @param text The <code>String</code> to iterate over. - */ - CollationElementIterator(RuleBasedCollator collator, String text) - { - this.collator = collator; - - setText (text); - } - - RuleBasedCollator.CollationElement nextBlock() - { - if (index >= text_decomposition.length) - return null; - - RuleBasedCollator.CollationElement e = text_decomposition[index]; - - textIndex = text_indexes[index+1]; - - index++; - - return e; - } - - RuleBasedCollator.CollationElement previousBlock() - { - if (index == 0) - return null; - - index--; - RuleBasedCollator.CollationElement e = text_decomposition[index]; - - textIndex = text_indexes[index+1]; - - return e; - } - - /** - * This method returns the collation ordering value of the next character sequence - * in the string (it may be an extended character following collation rules). - * This method will return <code>NULLORDER</code> if the - * end of the string was reached. - * - * @return The collation ordering value. - */ - public int next() - { - RuleBasedCollator.CollationElement e = nextBlock(); - - if (e == null) - return NULLORDER; - - return e.getValue(); - } - - /** - * This method returns the collation ordering value of the previous character - * in the string. This method will return <code>NULLORDER</code> if the - * beginning of the string was reached. - * - * @return The collation ordering value. - */ - public int previous() - { - RuleBasedCollator.CollationElement e = previousBlock(); - - if (e == null) - return NULLORDER; - - return e.getValue(); - } - - /** - * This method returns the primary order value for the given collation - * value. - * - * @param value The collation value returned from <code>next()</code> or <code>previous()</code>. - * - * @return The primary order value of the specified collation value. This is the high 16 bits. - */ - public static int primaryOrder(int order) - { - // From the JDK 1.2 spec. - return order >>> 16; - } - - /** - * This method resets the internal position pointer to read from the - * beginning of the <code>String</code> again. - */ - public void reset() - { - index = 0; - textIndex = 0; - } - - /** - * This method returns the secondary order value for the given collation - * value. - * - * @param value The collation value returned from <code>next()</code> or <code>previous()</code>. - * - * @return The secondary order value of the specified collation value. This is the bits 8-15. - */ - public static short secondaryOrder(int order) - { - // From the JDK 1.2 spec. - return (short) ((order >>> 8) & 255); - } - - /** - * This method returns the tertiary order value for the given collation - * value. - * - * @param value The collation value returned from <code>next()</code> or <code>previous()</code>. - * - * @return The tertiary order value of the specified collation value. This is the low eight bits. - */ - public static short tertiaryOrder(int order) - { - // From the JDK 1.2 spec. - return (short) (order & 255); - } - - /** - * This method sets the <code>String</code> that it is iterating over - * to the specified <code>String</code>. - * - * @param text The new <code>String</code> to iterate over. - * - * @since 1.2 - */ - public void setText(String text) - { - int idx = 0; - int idx_idx = 0; - int alreadyExpanded = 0; - int idxToMove = 0; - - this.text = text; - this.index = 0; - - String work_text = text.intern(); - - ArrayList a_element = new ArrayList(); - ArrayList a_idx = new ArrayList(); - - // Build element collection ordered as they come in "text". - while (idx < work_text.length()) - { - String key, key_old; - - Object object = null; - int p = 1; - - // IMPROVE: use a TreeMap with a prefix-ordering rule. - key_old = key = null; - do - { - if (object != null) - key_old = key; - key = work_text.substring (idx, idx+p); - object = collator.prefix_tree.get (key); - if (object != null && idx < alreadyExpanded) - { - RuleBasedCollator.CollationElement prefix = (RuleBasedCollator.CollationElement)object; - if (prefix.expansion != null && - prefix.expansion.startsWith(work_text.substring(0, idx))) - { - object = null; - key = key_old; - } - } - p++; - } - while (idx+p <= work_text.length()); - - if (object == null) - key = key_old; - - RuleBasedCollator.CollationElement prefix = - (RuleBasedCollator.CollationElement) collator.prefix_tree.get (key); - - /* - * First case: There is no such sequence in the database. - * We will have to build one from the context. - */ - if (prefix == null) - { - /* - * We are dealing with sequences in an expansion. They - * are treated as accented characters (tertiary order). - */ - if (alreadyExpanded > 0) - { - RuleBasedCollator.CollationElement e = - collator.getDefaultAccentedElement (work_text.charAt (idx)); - - a_element.add (e); - a_idx.add (new Integer(idx_idx)); - idx++; - alreadyExpanded--; - if (alreadyExpanded == 0) - { - /* There is not any characters left in the expansion set. - * We can increase the pointer in the source string. - */ - idx_idx += idxToMove; - idxToMove = 0; - } - else - idx_idx++; - } - else - { - /* This is a normal character. */ - RuleBasedCollator.CollationElement e = - collator.getDefaultElement (work_text.charAt (idx)); - Integer i_ref = new Integer(idx_idx); - - /* Don't forget to mark it as a special sequence so the - * string can be ordered. - */ - a_element.add (RuleBasedCollator.SPECIAL_UNKNOWN_SEQ); - a_idx.add (i_ref); - a_element.add (e); - a_idx.add (i_ref); - idx_idx++; - idx++; - } - continue; - } - - /* - * Second case: Here we have found a matching sequence. - * Here we have an expansion string prepend it to the "work text" and - * add the corresponding sorting element. We must also mark - */ - if (prefix.expansion != null) - { - work_text = prefix.expansion - + work_text.substring (idx+prefix.key.length()); - idx = 0; - a_element.add (prefix); - a_idx.add (new Integer(idx_idx)); - if (alreadyExpanded == 0) - idxToMove = prefix.key.length(); - alreadyExpanded += prefix.expansion.length()-prefix.key.length(); - } - else - { - /* Third case: the simplest. We have got the prefix and it - * has not to be expanded. - */ - a_element.add (prefix); - a_idx.add (new Integer(idx_idx)); - idx += prefix.key.length(); - /* If the sequence is in an expansion, we must decrease the - * counter. - */ - if (alreadyExpanded > 0) - { - alreadyExpanded -= prefix.key.length(); - if (alreadyExpanded == 0) - { - idx_idx += idxToMove; - idxToMove = 0; - } - } - else - idx_idx += prefix.key.length(); - } - } - - text_decomposition = (RuleBasedCollator.CollationElement[]) - a_element.toArray(new RuleBasedCollator.CollationElement[a_element.size()]); - text_indexes = new int[a_idx.size()+1]; - for (int i = 0; i < a_idx.size(); i++) - { - text_indexes[i] = ((Integer)a_idx.get(i)).intValue(); - } - text_indexes[a_idx.size()] = text.length(); - } - - /** - * This method sets the <code>String</code> that it is iterating over - * to the <code>String</code> represented by the specified - * <code>CharacterIterator</code>. - * - * @param source The <code>CharacterIterator</code> containing the new - * <code>String</code> to iterate over. - */ - public void setText(CharacterIterator source) - { - StringBuffer expand = new StringBuffer(); - - // For now assume we read from the beginning of the string. - for (char c = source.first(); - c != CharacterIterator.DONE; - c = source.next()) - expand.append(c); - - setText(expand.toString()); - } - - /** - * This method returns the current offset into the <code>String</code> - * that is being iterated over. - * - * @return The iteration index position. - * - * @since 1.2 - */ - public int getOffset() - { - return textIndex; - } - - /** - * This method sets the iteration index position into the current - * <code>String</code> to the specified value. This value must not - * be negative and must not be greater than the last index position - * in the <code>String</code>. - * - * @param offset The new iteration index position. - * - * @exception IllegalArgumentException If the new offset is not valid. - */ - public void setOffset(int offset) - { - if (offset < 0) - throw new IllegalArgumentException("Negative offset: " + offset); - - if (offset > (text.length() - 1)) - throw new IllegalArgumentException("Offset too large: " + offset); - - for (index = 0; index < text_decomposition.length; index++) - { - if (offset <= text_indexes[index]) - break; - } - /* - * As text_indexes[0] == 0, we should not have to take care whether index is - * greater than 0. It is always. - */ - if (text_indexes[index] == offset) - textIndex = offset; - else - textIndex = text_indexes[index-1]; - } - - /** - * This method returns the maximum length of any expansion sequence that - * ends with the specified collation order value. (Whatever that means). - * - * @param value The collation order value - * - * @param The maximum length of an expansion sequence. - */ - public int getMaxExpansion(int value) - { - return 1; - } -} diff --git a/libjava/java/text/CollationKey.java b/libjava/java/text/CollationKey.java deleted file mode 100644 index f7e3a2476de..00000000000 --- a/libjava/java/text/CollationKey.java +++ /dev/null @@ -1,199 +0,0 @@ -/* CollationKey.java -- Precomputed collation value - Copyright (C) 1998, 1999, 2000, 2003, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.text; - -/* Written using "Java Class Libraries", 2nd edition, plus online - * API docs for JDK 1.2 from http://www.javasoft.com. - * Status: Believed complete and correct. - */ - -/** - * This class represents a pre-computed series of bits representing a - * <code>String</code> for under a particular <code>Collator</code>. This - * value may be compared bitwise against another <code>CollationKey</code> - * representing a different <code>String</code> under the same - * <code>Collator</code> in a manner than is usually more efficient than - * using the raw <code>Collator</code> compare methods. There is overhead - * associated with calculating this value, so it is generally not - * advisable to compute <code>CollationKey</code>'s unless multiple - * comparisons against a <code>String</code> will be done. (For example, - * in a sort routine). - * <p> - * This class cannot be instantiated directly. Instead, a - * <code>CollationKey</code> is created by calling the - * <code>getCollationKey</code> method on an instance of <code>Collator</code>. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Tom Tromey (tromey@cygnus.com) - * @date March 25, 1999 - */ -public final class CollationKey implements Comparable -{ - /** - * This is the <code>Collator</code> this object was created from. - */ - private Collator collator; - - /** - * This is the <code>String</code> this object represents. - */ - private String originalText; - - /** - * This is the bit value for this key. - */ - private byte[] key; - - CollationKey (Collator collator, String originalText, byte[] key) - { - this.collator = collator; - this.originalText = originalText; - this.key = key; - } - - /** - * This method compares the specified object to this one. An integer is - * returned which indicates whether the specified object is less than, - * greater than, or equal to this object. - * - * @param ck The <code>CollationKey</code> to compare against this one. - * - * @return A negative integer if this object is less than the specified object, 0 if it is equal or a positive integer if it is greater than the specified object. - */ - public int compareTo (CollationKey ck) - { - int max = Math.min (key.length, ck.key.length); - - for (int i = 0; i < max; ++i) - { - if (key[i] != ck.key[i]) - return key[i] - ck.key[i]; - } - - return key.length - ck.key.length; - } - - /** - * This method compares the specified object to this one. The specified - * object must be an instance of <code>CollationKey</code> or an exception - * will be thrown. An integer is returned which indicates whether the - * specified object is less than, greater than, or equal to this object. - * - * @param obj The <code>Object</code> to compare against this one. - * - * @return A negative integer if this object is less than the specified object, 0 if it is equal or a positive integer if it is greater than the specified object. - */ - public int compareTo (Object obj) - { - return compareTo ((CollationKey) obj); - } - - /** - * This method tests the specified <code>Object</code> for equality with - * this object. This will be true if and only if: - * <p> - * <ul> - * <li>The specified object must not be <code>null</code></li> - * <li>The specified object is an instance of <code>CollationKey</code>.</li> - * <li>The specified object was created from the same <code>Collator</code> - * as this object.</li> - * <li>The specified object has the same source string and bit key as - * this object.</li> - * </ul> - * - * @param obj The <code>Object</code> to test for equality. - * - * @return <code>true</code> if the specified object is equal to this one, <code>false</code> otherwise. - */ - public boolean equals (Object obj) - { - if (! (obj instanceof CollationKey)) - return false; - - CollationKey ck = (CollationKey) obj; - - if (ck.collator != collator) - return false; - - if (!ck.getSourceString ().equals (getSourceString ())) - return false; - - if (!ck.toByteArray ().equals (toByteArray ())) - return false; - - return true; - } - - /** - * This method returns the <code>String</code> that this object was created - * from. - * - * @return The source <code>String</code> for this object. - */ - public String getSourceString() - { - return originalText; - } - - /** - * This method returns a hash value for this object. The hash value - * returned will be the hash code of the bit key so that identical bit - * keys will return the same value. - * - * @return A hash value for this object. - */ - public int hashCode() - { - // We just follow BitSet instead of thinking up something new. - long h = originalText.hashCode(); - for (int i = key.length - 1; i >= 0; --i) - h ^= key[i] * (i + 1); - return (int) ((h >> 32) ^ h); - } - - /** - * This method returns the collation bit sequence as a byte array. - * - * @param A byte array containing the collation bit sequence. - */ - public byte[] toByteArray() - { - return key; - } -} diff --git a/libjava/java/text/DecimalFormat.java b/libjava/java/text/DecimalFormat.java deleted file mode 100644 index 4a2e1b4d002..00000000000 --- a/libjava/java/text/DecimalFormat.java +++ /dev/null @@ -1,1265 +0,0 @@ -/* DecimalFormat.java -- Formats and parses numbers - Copyright (C) 1999, 2000, 2001, 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.text; - -import gnu.java.text.AttributedFormatBuffer; -import gnu.java.text.FormatBuffer; -import gnu.java.text.FormatCharacterIterator; -import gnu.java.text.StringFormatBuffer; - -import java.io.IOException; -import java.io.ObjectInputStream; -import java.util.Currency; -import java.util.HashMap; -import java.util.Locale; - -/** - * @author Tom Tromey (tromey@cygnus.com) - * @author Andrew John Hughes (gnu_andrew@member.fsf.org) - * @date March 4, 1999 - */ -/* Written using "Java Class Libraries", 2nd edition, plus online - * API docs for JDK 1.2 from http://www.javasoft.com. - * Status: Believed complete and correct to 1.2. - * Note however that the docs are very unclear about how format parsing - * should work. No doubt there are problems here. - */ -public class DecimalFormat extends NumberFormat -{ - // This is a helper for applyPatternWithSymbols. It reads a prefix - // or a suffix. It can cause some side-effects. - private int scanFix (String pattern, int index, FormatBuffer buf, - String patChars, DecimalFormatSymbols syms, - boolean is_suffix) - { - int len = pattern.length(); - boolean quoteStarted = false; - buf.clear(); - - boolean multiplierSet = false; - while (index < len) - { - char c = pattern.charAt(index); - - if (quoteStarted) - { - if (c == '\'') - quoteStarted = false; - else - buf.append(c); - index++; - continue; - } - - if (c == '\'' && index + 1 < len - && pattern.charAt(index + 1) == '\'') - { - buf.append(c); - index++; - } - else if (c == '\'') - { - quoteStarted = true; - } - else if (c == '\u00a4') - { - if (index + 1 < len && pattern.charAt(index + 1) == '\u00a4') - { - buf.append(syms.getInternationalCurrencySymbol(), NumberFormat.Field.CURRENCY); - index++; - } - else - buf.append(syms.getCurrencySymbol(), NumberFormat.Field.CURRENCY); - } - else if (c == syms.getPercent()) - { - if (multiplierSet) - throw new IllegalArgumentException ("multiplier already set " + - "- index: " + index); - multiplierSet = true; - multiplier = 100; - buf.append(c, NumberFormat.Field.PERCENT); - } - else if (c == syms.getPerMill()) - { - if (multiplierSet) - throw new IllegalArgumentException ("multiplier already set " + - "- index: " + index); - multiplierSet = true; - multiplier = 1000; - buf.append(c, NumberFormat.Field.PERMILLE); - } - else if (patChars.indexOf(c) != -1) - { - // This is a pattern character. - break; - } - else - buf.append(c); - index++; - } - - if (quoteStarted) - throw new IllegalArgumentException ("pattern is lacking a closing quote"); - - return index; - } - - // A helper which reads a number format. - private int scanFormat (String pattern, int index, String patChars, - DecimalFormatSymbols syms, boolean is_positive) - { - int max = pattern.length(); - - int countSinceGroup = 0; - int zeroCount = 0; - boolean saw_group = false; - - // - // Scan integer part. - // - while (index < max) - { - char c = pattern.charAt(index); - - if (c == syms.getDigit()) - { - if (zeroCount > 0) - throw new IllegalArgumentException ("digit mark following " + - "zero - index: " + index); - ++countSinceGroup; - } - else if (c == syms.getZeroDigit()) - { - ++zeroCount; - ++countSinceGroup; - } - else if (c == syms.getGroupingSeparator()) - { - countSinceGroup = 0; - saw_group = true; - } - else - break; - - ++index; - } - - // We can only side-effect when parsing the positive format. - if (is_positive) - { - groupingUsed = saw_group; - groupingSize = (byte) countSinceGroup; - minimumIntegerDigits = zeroCount; - } - - // Early termination. - if (index == max || pattern.charAt(index) == syms.getGroupingSeparator()) - { - if (is_positive) - decimalSeparatorAlwaysShown = false; - return index; - } - - if (pattern.charAt(index) == syms.getDecimalSeparator()) - { - ++index; - - // - // Scan fractional part. - // - int hashCount = 0; - zeroCount = 0; - while (index < max) - { - char c = pattern.charAt(index); - if (c == syms.getZeroDigit()) - { - if (hashCount > 0) - throw new IllegalArgumentException ("zero mark " + - "following digit - index: " + index); - ++zeroCount; - } - else if (c == syms.getDigit()) - { - ++hashCount; - } - else if (c != syms.getExponential() - && c != syms.getPatternSeparator() - && c != syms.getPercent() - && c != syms.getPerMill() - && patChars.indexOf(c) != -1) - throw new IllegalArgumentException ("unexpected special " + - "character - index: " + index); - else - break; - - ++index; - } - - if (is_positive) - { - maximumFractionDigits = hashCount + zeroCount; - minimumFractionDigits = zeroCount; - } - - if (index == max) - return index; - } - - if (pattern.charAt(index) == syms.getExponential()) - { - // - // Scan exponential format. - // - zeroCount = 0; - ++index; - while (index < max) - { - char c = pattern.charAt(index); - if (c == syms.getZeroDigit()) - ++zeroCount; - else if (c == syms.getDigit()) - { - if (zeroCount > 0) - throw new - IllegalArgumentException ("digit mark following zero " + - "in exponent - index: " + - index); - } - else if (patChars.indexOf(c) != -1) - throw new IllegalArgumentException ("unexpected special " + - "character - index: " + - index); - else - break; - - ++index; - } - - if (is_positive) - { - useExponentialNotation = true; - minExponentDigits = (byte) zeroCount; - } - - maximumIntegerDigits = groupingSize; - groupingSize = 0; - if (maximumIntegerDigits > minimumIntegerDigits && maximumIntegerDigits > 0) - { - minimumIntegerDigits = 1; - exponentRound = maximumIntegerDigits; - } - else - exponentRound = 1; - } - - return index; - } - - // This helper function creates a string consisting of all the - // characters which can appear in a pattern and must be quoted. - private String patternChars (DecimalFormatSymbols syms) - { - StringBuffer buf = new StringBuffer (); - buf.append(syms.getDecimalSeparator()); - buf.append(syms.getDigit()); - buf.append(syms.getExponential()); - buf.append(syms.getGroupingSeparator()); - // Adding this one causes pattern application to fail. - // Of course, omitting is causes toPattern to fail. - // ... but we already have bugs there. FIXME. - // buf.append(syms.getMinusSign()); - buf.append(syms.getPatternSeparator()); - buf.append(syms.getPercent()); - buf.append(syms.getPerMill()); - buf.append(syms.getZeroDigit()); - buf.append('\u00a4'); - return buf.toString(); - } - - private void applyPatternWithSymbols(String pattern, DecimalFormatSymbols syms) - { - // Initialize to the state the parser expects. - negativePrefix = ""; - negativeSuffix = ""; - positivePrefix = ""; - positiveSuffix = ""; - decimalSeparatorAlwaysShown = false; - groupingSize = 0; - minExponentDigits = 0; - multiplier = 1; - useExponentialNotation = false; - groupingUsed = false; - maximumFractionDigits = 0; - maximumIntegerDigits = MAXIMUM_INTEGER_DIGITS; - minimumFractionDigits = 0; - minimumIntegerDigits = 1; - - AttributedFormatBuffer buf = new AttributedFormatBuffer (); - String patChars = patternChars (syms); - - int max = pattern.length(); - int index = scanFix (pattern, 0, buf, patChars, syms, false); - buf.sync(); - positivePrefix = buf.getBuffer().toString(); - positivePrefixRanges = buf.getRanges(); - positivePrefixAttrs = buf.getAttributes(); - - index = scanFormat (pattern, index, patChars, syms, true); - - index = scanFix (pattern, index, buf, patChars, syms, true); - buf.sync(); - positiveSuffix = buf.getBuffer().toString(); - positiveSuffixRanges = buf.getRanges(); - positiveSuffixAttrs = buf.getAttributes(); - - if (index == pattern.length()) - { - // No negative info. - negativePrefix = null; - negativeSuffix = null; - } - else - { - if (pattern.charAt(index) != syms.getPatternSeparator()) - throw new IllegalArgumentException ("separator character " + - "expected - index: " + index); - - index = scanFix (pattern, index + 1, buf, patChars, syms, false); - buf.sync(); - negativePrefix = buf.getBuffer().toString(); - negativePrefixRanges = buf.getRanges(); - negativePrefixAttrs = buf.getAttributes(); - - // We parse the negative format for errors but we don't let - // it side-effect this object. - index = scanFormat (pattern, index, patChars, syms, false); - - index = scanFix (pattern, index, buf, patChars, syms, true); - buf.sync(); - negativeSuffix = buf.getBuffer().toString(); - negativeSuffixRanges = buf.getRanges(); - negativeSuffixAttrs = buf.getAttributes(); - - if (index != pattern.length()) - throw new IllegalArgumentException ("end of pattern expected " + - "- index: " + index); - } - } - - public void applyLocalizedPattern (String pattern) - { - // JCL p. 638 claims this throws a ParseException but p. 629 - // contradicts this. Empirical tests with patterns of "0,###.0" - // and "#.#.#" corroborate the p. 629 statement that an - // IllegalArgumentException is thrown. - applyPatternWithSymbols (pattern, symbols); - } - - public void applyPattern (String pattern) - { - // JCL p. 638 claims this throws a ParseException but p. 629 - // contradicts this. Empirical tests with patterns of "0,###.0" - // and "#.#.#" corroborate the p. 629 statement that an - // IllegalArgumentException is thrown. - applyPatternWithSymbols (pattern, nonLocalizedSymbols); - } - - public Object clone () - { - DecimalFormat c = (DecimalFormat) super.clone (); - c.symbols = (DecimalFormatSymbols) symbols.clone (); - return c; - } - - public DecimalFormat () - { - this ("#,##0.###"); - } - - public DecimalFormat (String pattern) - { - this (pattern, new DecimalFormatSymbols ()); - } - - public DecimalFormat (String pattern, DecimalFormatSymbols symbols) - { - this.symbols = symbols; - applyPattern (pattern); - } - - private boolean equals(String s1, String s2) - { - if (s1 == null || s2 == null) - return s1 == s2; - return s1.equals(s2); - } - - public boolean equals (Object obj) - { - if (! (obj instanceof DecimalFormat)) - return false; - DecimalFormat dup = (DecimalFormat) obj; - return (decimalSeparatorAlwaysShown == dup.decimalSeparatorAlwaysShown - && groupingSize == dup.groupingSize - && minExponentDigits == dup.minExponentDigits - && multiplier == dup.multiplier - && equals(negativePrefix, dup.negativePrefix) - && equals(negativeSuffix, dup.negativeSuffix) - && equals(positivePrefix, dup.positivePrefix) - && equals(positiveSuffix, dup.positiveSuffix) - && symbols.equals(dup.symbols) - && useExponentialNotation == dup.useExponentialNotation); - } - - private void formatInternal (double number, FormatBuffer dest, - FieldPosition fieldPos) - { - // A very special case. - if (Double.isNaN(number)) - { - dest.append(symbols.getNaN()); - if (fieldPos != null && - (fieldPos.getField() == INTEGER_FIELD || - fieldPos.getFieldAttribute() == NumberFormat.Field.INTEGER)) - { - int index = dest.length(); - fieldPos.setBeginIndex(index - symbols.getNaN().length()); - fieldPos.setEndIndex(index); - } - return; - } - - boolean is_neg = number < 0; - if (is_neg) - { - if (negativePrefix != null) - dest.append(negativePrefix, negativePrefixRanges, negativePrefixAttrs); - else - { - dest.append(symbols.getMinusSign(), NumberFormat.Field.SIGN); - dest.append(positivePrefix, positivePrefixRanges, positivePrefixAttrs); - } - number = - number; - } - else - dest.append(positivePrefix, positivePrefixRanges, positivePrefixAttrs); - - int integerBeginIndex = dest.length(); - int integerEndIndex = 0; - int zeroStart = symbols.getZeroDigit() - '0'; - - if (Double.isInfinite (number)) - { - dest.append(symbols.getInfinity()); - integerEndIndex = dest.length(); - } - else - { - number *= multiplier; - - // Compute exponent. - long exponent = 0; - double baseNumber; - if (useExponentialNotation) - { - exponent = (long) Math.floor (Math.log(number) / Math.log(10)); - exponent = exponent - (exponent % exponentRound); - if (minimumIntegerDigits > 0) - exponent -= minimumIntegerDigits - 1; - baseNumber = (number / Math.pow(10.0, exponent)); - } - else - baseNumber = number; - - // Round to the correct number of digits. - baseNumber += 5 * Math.pow(10.0, - maximumFractionDigits - 1); - - int index = dest.length(); - //double intPart = Math.floor(baseNumber); - String intPart = Long.toString((long)Math.floor(baseNumber)); - int count, groupPosition = intPart.length(); - - dest.setDefaultAttribute(NumberFormat.Field.INTEGER); - - for (count = 0; count < minimumIntegerDigits-intPart.length(); count++) - dest.append(symbols.getZeroDigit()); - - for (count = 0; - count < maximumIntegerDigits && count < intPart.length(); - count++) - { - int dig = intPart.charAt(count); - - // Append group separator if required. - if (groupingUsed && count > 0 && groupingSize != 0 && groupPosition % groupingSize == 0) - { - dest.append(symbols.getGroupingSeparator(), NumberFormat.Field.GROUPING_SEPARATOR); - dest.setDefaultAttribute(NumberFormat.Field.INTEGER); - } - dest.append((char) (zeroStart + dig)); - - groupPosition--; - } - dest.setDefaultAttribute(null); - - integerEndIndex = dest.length(); - - int decimal_index = integerEndIndex; - int consecutive_zeros = 0; - int total_digits = 0; - - int localMaximumFractionDigits = maximumFractionDigits; - - if (useExponentialNotation) - localMaximumFractionDigits += minimumIntegerDigits - count; - - // Strip integer part from NUMBER. - double fracPart = baseNumber - Math.floor(baseNumber); - - if ( ((fracPart != 0 || minimumFractionDigits > 0) && localMaximumFractionDigits > 0) - || decimalSeparatorAlwaysShown) - { - dest.append (symbols.getDecimalSeparator(), NumberFormat.Field.DECIMAL_SEPARATOR); - } - - int fraction_begin = dest.length(); - dest.setDefaultAttribute(NumberFormat.Field.FRACTION); - for (count = 0; - count < localMaximumFractionDigits - && (fracPart != 0 || count < minimumFractionDigits); - ++count) - { - ++total_digits; - fracPart *= 10; - long dig = (long) fracPart; - if (dig == 0) - ++consecutive_zeros; - else - consecutive_zeros = 0; - dest.append((char) (symbols.getZeroDigit() + dig)); - - // Strip integer part from FRACPART. - fracPart = fracPart - Math.floor (fracPart); - } - - // Strip extraneous trailing `0's. We can't always detect - // these in the loop. - int extra_zeros = Math.min (consecutive_zeros, - total_digits - minimumFractionDigits); - if (extra_zeros > 0) - { - dest.cutTail(extra_zeros); - total_digits -= extra_zeros; - if (total_digits == 0 && !decimalSeparatorAlwaysShown) - dest.cutTail(1); - } - - if (fieldPos != null && fieldPos.getField() == FRACTION_FIELD) - { - fieldPos.setBeginIndex(fraction_begin); - fieldPos.setEndIndex(dest.length()); - } - - // Finally, print the exponent. - if (useExponentialNotation) - { - dest.append(symbols.getExponential(), NumberFormat.Field.EXPONENT_SYMBOL); - if (exponent < 0) - { - dest.append (symbols.getMinusSign (), NumberFormat.Field.EXPONENT_SIGN); - exponent = - exponent; - } - index = dest.length(); - dest.setDefaultAttribute(NumberFormat.Field.EXPONENT); - String exponentString = Long.toString ((long) exponent); - - for (count = 0; count < minExponentDigits-exponentString.length(); - count++) - dest.append((char) symbols.getZeroDigit()); - - for (count = 0; - count < exponentString.length(); - ++count) - { - int dig = exponentString.charAt(count); - dest.append((char) (zeroStart + dig)); - } - } - } - - if (fieldPos != null && - (fieldPos.getField() == INTEGER_FIELD || - fieldPos.getFieldAttribute() == NumberFormat.Field.INTEGER)) - { - fieldPos.setBeginIndex(integerBeginIndex); - fieldPos.setEndIndex(integerEndIndex); - } - - if (is_neg && negativeSuffix != null) - dest.append(negativeSuffix, negativeSuffixRanges, negativeSuffixAttrs); - else - dest.append(positiveSuffix, positiveSuffixRanges, positiveSuffixAttrs); - } - - public StringBuffer format (double number, StringBuffer dest, - FieldPosition fieldPos) - { - formatInternal (number, new StringFormatBuffer(dest), fieldPos); - return dest; - } - - public AttributedCharacterIterator formatToCharacterIterator (Object value) - { - AttributedFormatBuffer sbuf = new AttributedFormatBuffer(); - - if (value instanceof Number) - formatInternal(((Number) value).doubleValue(), sbuf, null); - else - throw new IllegalArgumentException - ("Cannot format given Object as a Number"); - - sbuf.sync(); - return new FormatCharacterIterator(sbuf.getBuffer().toString(), - sbuf.getRanges(), - sbuf.getAttributes()); - } - - public StringBuffer format (long number, StringBuffer dest, - FieldPosition fieldPos) - { - // If using exponential notation, we just format as a double. - if (useExponentialNotation) - return format ((double) number, dest, fieldPos); - - boolean is_neg = number < 0; - if (is_neg) - { - if (negativePrefix != null) - dest.append(negativePrefix); - else - { - dest.append(symbols.getMinusSign()); - dest.append(positivePrefix); - } - number = - number; - } - else - dest.append(positivePrefix); - - int integerBeginIndex = dest.length(); - int index = dest.length(); - int count = 0; - while (count < maximumIntegerDigits - && (number > 0 || count < minimumIntegerDigits)) - { - long dig = number % 10; - number /= 10; - // NUMBER and DIG will be less than 0 if the original number - // was the most negative long. - if (dig < 0) - { - dig = - dig; - number = - number; - } - - // Append group separator if required. - if (groupingUsed && count > 0 && groupingSize != 0 && count % groupingSize == 0) - dest.insert(index, symbols.getGroupingSeparator()); - - dest.insert(index, (char) (symbols.getZeroDigit() + dig)); - - ++count; - } - - if (fieldPos != null && fieldPos.getField() == INTEGER_FIELD) - { - fieldPos.setBeginIndex(integerBeginIndex); - fieldPos.setEndIndex(dest.length()); - } - - if (decimalSeparatorAlwaysShown || minimumFractionDigits > 0) - { - dest.append(symbols.getDecimalSeparator()); - if (fieldPos != null && fieldPos.getField() == FRACTION_FIELD) - { - fieldPos.setBeginIndex(dest.length()); - fieldPos.setEndIndex(dest.length() + minimumFractionDigits); - } - } - - for (count = 0; count < minimumFractionDigits; ++count) - dest.append(symbols.getZeroDigit()); - - dest.append((is_neg && negativeSuffix != null) - ? negativeSuffix - : positiveSuffix); - return dest; - } - - /** - * Returns the currency corresponding to the currency symbol stored - * in the instance of <code>DecimalFormatSymbols</code> used by this - * <code>DecimalFormat</code>. - * - * @return A new instance of <code>Currency</code> if - * the currency code matches a known one, null otherwise. - */ - public Currency getCurrency() - { - return symbols.getCurrency(); - } - - public DecimalFormatSymbols getDecimalFormatSymbols () - { - return symbols; - } - - public int getGroupingSize () - { - return groupingSize; - } - - public int getMultiplier () - { - return multiplier; - } - - public String getNegativePrefix () - { - return negativePrefix; - } - - public String getNegativeSuffix () - { - return negativeSuffix; - } - - public String getPositivePrefix () - { - return positivePrefix; - } - - public String getPositiveSuffix () - { - return positiveSuffix; - } - - public int hashCode () - { - int hash = (negativeSuffix.hashCode() ^ negativePrefix.hashCode() - ^positivePrefix.hashCode() ^ positiveSuffix.hashCode()); - // FIXME. - return hash; - } - - public boolean isDecimalSeparatorAlwaysShown () - { - return decimalSeparatorAlwaysShown; - } - - public Number parse (String str, ParsePosition pos) - { - /* - * Our strategy is simple: copy the text into separate buffers: one for the int part, - * one for the fraction part and for the exponential part. - * We translate or omit locale-specific information. - * If exponential is sufficiently big we merge the fraction and int part and - * remove the '.' and then we use Long to convert the number. In the other - * case, we use Double to convert the full number. - */ - - boolean is_neg = false; - int index = pos.getIndex(); - StringBuffer int_buf = new StringBuffer (); - - // We have to check both prefixes, because one might be empty. We - // want to pick the longest prefix that matches. - boolean got_pos = str.startsWith(positivePrefix, index); - String np = (negativePrefix != null - ? negativePrefix - : positivePrefix + symbols.getMinusSign()); - boolean got_neg = str.startsWith(np, index); - - if (got_pos && got_neg) - { - // By checking this way, we preserve ambiguity in the case - // where the negative format differs only in suffix. We - // check this again later. - if (np.length() > positivePrefix.length()) - { - is_neg = true; - index += np.length(); - } - else - index += positivePrefix.length(); - } - else if (got_neg) - { - is_neg = true; - index += np.length(); - } - else if (got_pos) - index += positivePrefix.length(); - else - { - pos.setErrorIndex (index); - return null; - } - - // FIXME: handle Inf and NaN. - - // FIXME: do we have to respect minimum digits? - // What about multiplier? - - StringBuffer buf = int_buf; - StringBuffer frac_buf = null; - StringBuffer exp_buf = null; - int start_index = index; - int max = str.length(); - int exp_index = -1; - int last = index + maximumIntegerDigits; - - if (maximumFractionDigits > 0) - last += maximumFractionDigits + 1; - - if (useExponentialNotation) - last += minExponentDigits + 1; - - if (last > 0 && max > last) - max = last; - - char zero = symbols.getZeroDigit(); - int last_group = -1; - boolean int_part = true; - boolean exp_part = false; - for (; index < max; ++index) - { - char c = str.charAt(index); - - // FIXME: what about grouping size? - if (groupingUsed && c == symbols.getGroupingSeparator()) - { - if (last_group != -1 - && groupingSize != 0 - && (index - last_group) % groupingSize != 0) - { - pos.setErrorIndex(index); - return null; - } - last_group = index+1; - } - else if (c >= zero && c <= zero + 9) - { - buf.append((char) (c - zero + '0')); - } - else if (parseIntegerOnly) - break; - else if (c == symbols.getDecimalSeparator()) - { - if (last_group != -1 - && groupingSize != 0 - && (index - last_group) % groupingSize != 0) - { - pos.setErrorIndex(index); - return null; - } - buf = frac_buf = new StringBuffer(); - frac_buf.append('.'); - int_part = false; - } - else if (c == symbols.getExponential()) - { - buf = exp_buf = new StringBuffer(); - int_part = false; - exp_part = true; - exp_index = index+1; - } - else if (exp_part - && (c == '+' || c == '-' || c == symbols.getMinusSign())) - { - // For exponential notation. - buf.append(c); - } - else - break; - } - - if (index == start_index) - { - // Didn't see any digits. - pos.setErrorIndex(index); - return null; - } - - // Check the suffix. We must do this before converting the - // buffer to a number to handle the case of a number which is - // the most negative Long. - boolean got_pos_suf = str.startsWith(positiveSuffix, index); - String ns = (negativePrefix == null ? positiveSuffix : negativeSuffix); - boolean got_neg_suf = str.startsWith(ns, index); - if (is_neg) - { - if (! got_neg_suf) - { - pos.setErrorIndex(index); - return null; - } - } - else if (got_pos && got_neg && got_neg_suf) - { - is_neg = true; - } - else if (got_pos != got_pos_suf && got_neg != got_neg_suf) - { - pos.setErrorIndex(index); - return null; - } - - String suffix = is_neg ? ns : positiveSuffix; - long multiplier = 1; - boolean use_long; - - if (is_neg) - int_buf.insert(0, '-'); - - // Now handle the exponential part if there is one. - if (exp_buf != null) - { - int exponent_value; - - try - { - exponent_value = Integer.parseInt(exp_buf.toString()); - } - catch (NumberFormatException x1) - { - pos.setErrorIndex(exp_index); - return null; - } - - if (frac_buf == null) - { - // We only have to add some zeros to the int part. - // Build a multiplier. - for (int i = 0; i < exponent_value; i++) - int_buf.append('0'); - - use_long = true; - } - else - { - boolean long_sufficient; - - if (exponent_value < frac_buf.length()-1) - { - int lastNonNull = -1; - /* We have to check the fraction buffer: it may only be full of '0' - * or be sufficiently filled with it to convert the number into Long. - */ - for (int i = 1; i < frac_buf.length(); i++) - if (frac_buf.charAt(i) != '0') - lastNonNull = i; - - long_sufficient = (lastNonNull < 0 || lastNonNull <= exponent_value); - } - else - long_sufficient = true; - - if (long_sufficient) - { - for (int i = 1; i < frac_buf.length() && i < exponent_value; i++) - int_buf.append(frac_buf.charAt(i)); - for (int i = frac_buf.length()-1; i < exponent_value; i++) - int_buf.append('0'); - use_long = true; - } - else - { - /* - * A long type is not sufficient, we build the full buffer to - * be parsed by Double. - */ - int_buf.append(frac_buf); - int_buf.append('E'); - int_buf.append(exp_buf); - use_long = false; - } - } - } - else - { - if (frac_buf != null) - { - /* Check whether the fraction buffer contains only '0' */ - int i; - for (i = 1; i < frac_buf.length(); i++) - if (frac_buf.charAt(i) != '0') - break; - - if (i != frac_buf.length()) - { - use_long = false; - int_buf.append(frac_buf); - } - else - use_long = true; - } - else - use_long = true; - } - - String t = int_buf.toString(); - Number result = null; - if (use_long) - { - try - { - result = new Long (t); - } - catch (NumberFormatException x1) - { - } - } - else - { - try - { - result = new Double (t); - } - catch (NumberFormatException x2) - { - } - } - if (result == null) - { - pos.setErrorIndex(index); - return null; - } - - pos.setIndex(index + suffix.length()); - - return result; - } - - /** - * Sets the <code>Currency</code> on the - * <code>DecimalFormatSymbols</code> used, which also sets the - * currency symbols on those symbols. - */ - public void setCurrency(Currency currency) - { - symbols.setCurrency(currency); - } - - public void setDecimalFormatSymbols (DecimalFormatSymbols newSymbols) - { - symbols = newSymbols; - } - - public void setDecimalSeparatorAlwaysShown (boolean newValue) - { - decimalSeparatorAlwaysShown = newValue; - } - - public void setGroupingSize (int groupSize) - { - groupingSize = (byte) groupSize; - } - - public void setMaximumFractionDigits (int newValue) - { - super.setMaximumFractionDigits(Math.min(newValue, 340)); - } - - public void setMaximumIntegerDigits (int newValue) - { - super.setMaximumIntegerDigits(Math.min(newValue, 309)); - } - - public void setMinimumFractionDigits (int newValue) - { - super.setMinimumFractionDigits(Math.min(newValue, 340)); - } - - public void setMinimumIntegerDigits (int newValue) - { - super.setMinimumIntegerDigits(Math.min(newValue, 309)); - } - - public void setMultiplier (int newValue) - { - multiplier = newValue; - } - - public void setNegativePrefix (String newValue) - { - negativePrefix = newValue; - } - - public void setNegativeSuffix (String newValue) - { - negativeSuffix = newValue; - } - - public void setPositivePrefix (String newValue) - { - positivePrefix = newValue; - } - - public void setPositiveSuffix (String newValue) - { - positiveSuffix = newValue; - } - - private void quoteFix(StringBuffer buf, String text, String patChars) - { - int len = text.length(); - for (int index = 0; index < len; ++index) - { - char c = text.charAt(index); - if (patChars.indexOf(c) != -1) - { - buf.append('\''); - buf.append(c); - buf.append('\''); - } - else - buf.append(c); - } - } - - private String computePattern(DecimalFormatSymbols syms) - { - StringBuffer mainPattern = new StringBuffer (); - // We have to at least emit a zero for the minimum number of - // digits. Past that we need hash marks up to the grouping - // separator (and one beyond). - int total_digits = Math.max(minimumIntegerDigits, - groupingUsed ? groupingSize + 1: groupingSize); - for (int i = 0; i < total_digits - minimumIntegerDigits; ++i) - mainPattern.append(syms.getDigit()); - for (int i = total_digits - minimumIntegerDigits; i < total_digits; ++i) - mainPattern.append(syms.getZeroDigit()); - // Inserting the gropuing operator afterwards is easier. - if (groupingUsed) - mainPattern.insert(mainPattern.length() - groupingSize, - syms.getGroupingSeparator()); - // See if we need decimal info. - if (minimumFractionDigits > 0 || maximumFractionDigits > 0 - || decimalSeparatorAlwaysShown) - mainPattern.append(syms.getDecimalSeparator()); - for (int i = 0; i < minimumFractionDigits; ++i) - mainPattern.append(syms.getZeroDigit()); - for (int i = minimumFractionDigits; i < maximumFractionDigits; ++i) - mainPattern.append(syms.getDigit()); - if (useExponentialNotation) - { - mainPattern.append(syms.getExponential()); - for (int i = 0; i < minExponentDigits; ++i) - mainPattern.append(syms.getZeroDigit()); - if (minExponentDigits == 0) - mainPattern.append(syms.getDigit()); - } - - String main = mainPattern.toString(); - String patChars = patternChars (syms); - mainPattern.setLength(0); - - quoteFix (mainPattern, positivePrefix, patChars); - mainPattern.append(main); - quoteFix (mainPattern, positiveSuffix, patChars); - - if (negativePrefix != null) - { - quoteFix (mainPattern, negativePrefix, patChars); - mainPattern.append(main); - quoteFix (mainPattern, negativeSuffix, patChars); - } - - return mainPattern.toString(); - } - - public String toLocalizedPattern () - { - return computePattern (symbols); - } - - public String toPattern () - { - return computePattern (nonLocalizedSymbols); - } - - private static final int MAXIMUM_INTEGER_DIGITS = 309; - - // These names are fixed by the serialization spec. - private boolean decimalSeparatorAlwaysShown; - private byte groupingSize; - private byte minExponentDigits; - private int exponentRound; - private int multiplier; - private String negativePrefix; - private String negativeSuffix; - private String positivePrefix; - private String positiveSuffix; - private int[] negativePrefixRanges, positivePrefixRanges; - private HashMap[] negativePrefixAttrs, positivePrefixAttrs; - private int[] negativeSuffixRanges, positiveSuffixRanges; - private HashMap[] negativeSuffixAttrs, positiveSuffixAttrs; - private int serialVersionOnStream = 1; - private DecimalFormatSymbols symbols; - private boolean useExponentialNotation; - private static final long serialVersionUID = 864413376551465018L; - - private void readObject(ObjectInputStream stream) - throws IOException, ClassNotFoundException - { - stream.defaultReadObject(); - if (serialVersionOnStream < 1) - { - useExponentialNotation = false; - serialVersionOnStream = 1; - } - } - - // The locale-independent pattern symbols happen to be the same as - // the US symbols. - private static final DecimalFormatSymbols nonLocalizedSymbols - = new DecimalFormatSymbols (Locale.US); -} diff --git a/libjava/java/text/FieldPosition.java b/libjava/java/text/FieldPosition.java deleted file mode 100644 index 427c07e8e11..00000000000 --- a/libjava/java/text/FieldPosition.java +++ /dev/null @@ -1,232 +0,0 @@ -/* FieldPosition.java -- Keeps track of field positions while formatting - Copyright (C) 1998, 1999, 2001, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.text; - -/** - * This class is used by the java.text formatting classes to track - * field positions. A field position is defined by an identifier value - * and begin and end index positions. The formatting classes in java.text - * typically define constant values for the field identifiers. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Per Bothner (bothner@cygnus.com) - */ -public class FieldPosition -{ - /** - * This is the field identifier value. - */ - private int field_id; - - /** - * This is the beginning index of the field. - */ - private int begin; - - /** - * This is the ending index of the field. - */ - private int end; - - /** - * This is the field attribute value. - */ - private Format.Field field_attribute; - - /** - * This method initializes a new instance of <code>FieldPosition</code> - * to have the specified field attribute. The attribute will be used as - * an id. It is formally equivalent to calling FieldPosition(field, -1). - * - * @param field The field format attribute. - */ - public FieldPosition (Format.Field field) - { - this(field, -1); - } - - /** - * This method initializes a new instance of <code>FieldPosition</code> - * to have the specified field attribute. The attribute will be used as - * an id is non null. The integer field id is only used if the Format.Field - * attribute is not used by the formatter. - * - * @param field The field format attribute. - * @param field_id The field identifier value. - */ - public FieldPosition (Format.Field field, int field_id) - { - this.field_attribute = field; - this.field_id = field_id; - } - - /** - * This method initializes a new instance of <code>FieldPosition</code> to - * have the specified field id. - * - * @param field_id The field identifier value. - */ - public FieldPosition (int field_id) - { - this.field_id = field_id; - } - - /** - * This method returns the field identifier value for this object. - * - * @return The field identifier. - */ - public int getField () - { - return field_id; - } - - public Format.Field getFieldAttribute () - { - return field_attribute; - } - - /** - * This method returns the beginning index for this field. - * - * @return The beginning index. - */ - public int getBeginIndex () - { - return begin; - } - - /** - * This method sets the beginning index of this field to the specified value. - * - * @param begin The new beginning index. - */ - public void setBeginIndex (int begin) - { - this.begin = begin; - } - - /** - * This method returns the ending index for the field. - * - * @return The ending index. - */ - public int getEndIndex () - { - return end; - } - - /** - * This method sets the ending index of this field to the specified value. - * - * @param end The new ending index. - */ - public void setEndIndex (int end) - { - this.end = end; - } - - /** - * This method tests this object for equality against the specified object. - * The objects will be considered equal if and only if: - * <p> - * <ul> - * <li>The specified object is not <code>null</code>. - * <li>The specified object has the same class as this object. - * <li>The specified object has the same field identifier, field attribute - * and beginning and ending index as this object. - * </ul> - * - * @param obj The object to test for equality to this object. - * - * @return <code>true</code> if the specified object is equal to - * this object, <code>false</code> otherwise. - */ - public boolean equals (Object obj) - { - if (this == obj) - return true; - - if (obj == null || obj.getClass() != this.getClass()) - return false; - - FieldPosition fp = (FieldPosition) obj; - return (field_id == fp.field_id - && (field_attribute == fp.field_attribute - || (field_attribute != null - && field_attribute.equals(fp.field_attribute))) - && begin == fp.begin - && end == fp.end); - } - - - /** - * This method returns a hash value for this object - * - * @return A hash value for this object. - */ - public int hashCode () - { - int hash = 5; - - hash = 31 * hash + field_id; - hash = 31 * hash + begin; - hash = 31 * hash + end; - hash = 31 * hash + - (null == field_attribute ? 0 : field_attribute.hashCode()); - - return hash; - } - - /** - * This method returns a <code>String</code> representation of this - * object. - * - * @return A <code>String</code> representation of this object. - */ - public String toString () - { - return (getClass ().getName () - + "[field=" + getField () - + ",attribute=" + getFieldAttribute () - + ",beginIndex=" + getBeginIndex () - + ",endIndex=" + getEndIndex () - + "]"); - } -} diff --git a/libjava/java/text/Format.java b/libjava/java/text/Format.java deleted file mode 100644 index 38fda34ff64..00000000000 --- a/libjava/java/text/Format.java +++ /dev/null @@ -1,181 +0,0 @@ -/* Format.java -- Abstract superclass for formatting/parsing strings. - Copyright (C) 1998, 1999, 2000, 2001, 2003, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.text; - -import gnu.java.text.FormatCharacterIterator; - -import java.io.Serializable; - -/** - * This class is the abstract superclass of classes that format and parse - * data to/from <code>Strings</code>. It is guaranteed that any - * <code>String</code> produced by a concrete subclass of <code>Format</code> - * will be parseable by that same subclass. - * <p> - * In addition to implementing the abstract methods in this class, subclasses - * should provide static factory methods of the form - * <code>getInstance()</code> and <code>getInstance(Locale)</code> if the - * subclass loads different formatting/parsing schemes based on locale. - * These subclasses should also implement a static method called - * <code>getAvailableLocales()</code> which returns an array of - * available locales in the current runtime environment. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Per Bothner (bothner@cygnus.com) - */ -public abstract class Format implements Serializable, Cloneable -{ - /** - * For compatability with Sun's JDK 1.4.2 rev. 5 - */ - static final long serialVersionUID = -299282585814624189L; - - public static class Field extends AttributedCharacterIterator.Attribute - { - static final long serialVersionUID = 276966692217360283L; - - protected Field(String name) - { - super(name); - } - } - - /** - * This method initializes a new instance of <code>Format</code>. - * It performs no actions, but acts as a default constructor for - * subclasses. - */ - public Format () - { - } - - /** - * This method formats an <code>Object</code> into a <code>String</code>. - * - * @param obj The <code>Object</code> to format. - * - * @return The formatted <code>String</code>. - * - * @exception IllegalArgumentException If the <code>Object</code> - * cannot be formatted. - */ - public final String format(Object obj) throws IllegalArgumentException - { - StringBuffer sb = new StringBuffer (); - format (obj, sb, new FieldPosition (0)); - return sb.toString (); - } - - /** - * This method formats an <code>Object</code> into a <code>String</code> and - * appends the <code>String</code> to a <code>StringBuffer</code>. - * - * @param obj The <code>Object</code> to format. - * @param sb The <code>StringBuffer</code> to append to. - * @param pos The desired <code>FieldPosition</code>, which is also - * updated by this call. - * - * @return The updated <code>StringBuffer</code>. - * - * @exception IllegalArgumentException If the <code>Object</code> - * cannot be formatted. - */ - public abstract StringBuffer format (Object obj, StringBuffer sb, - FieldPosition pos) - throws IllegalArgumentException; - - /** - * This method parses a <code>String</code> and converts the parsed - * contents into an <code>Object</code>. - * - * @param str The <code>String</code> to parse. - * - * @return The resulting <code>Object</code>. - * - * @exception ParseException If the <code>String</code> cannot be parsed. - */ - public Object parseObject (String str) throws ParseException - { - ParsePosition pos = new ParsePosition(0); - Object result = parseObject (str, pos); - if (result == null) - { - int index = pos.getErrorIndex(); - if (index < 0) - index = pos.getIndex(); - throw new ParseException("parseObject failed", index); - } - return result; - } - - /** - * This method parses a <code>String</code> and converts the parsed - * contents into an <code>Object</code>. - * - * @param str The <code>String</code> to parse. - * @param pos The starting parse index on input, the ending parse - * index on output. - * - * @return The parsed <code>Object</code>, or <code>null</code> in - * case of error. - */ - public abstract Object parseObject (String str, ParsePosition pos); - - public AttributedCharacterIterator formatToCharacterIterator(Object obj) - { - return new FormatCharacterIterator(format(obj), null, null); - } - - /** - * Creates a copy of this object. - * - * @return The copied <code>Object</code>. - */ - public Object clone () - { - try - { - return super.clone (); - } - catch (CloneNotSupportedException e) - { - return null; - } - } -} diff --git a/libjava/java/text/MessageFormat.java b/libjava/java/text/MessageFormat.java deleted file mode 100644 index f7a9f1687a6..00000000000 --- a/libjava/java/text/MessageFormat.java +++ /dev/null @@ -1,832 +0,0 @@ -/* MessageFormat.java - Localized message formatting. - Copyright (C) 1999, 2001, 2002, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.text; - -import gnu.java.text.FormatCharacterIterator; - -import java.io.InvalidObjectException; -import java.util.Date; -import java.util.HashMap; -import java.util.Locale; -import java.util.Vector; - -public class MessageFormat extends Format -{ - /** - * @author Tom Tromey (tromey@cygnus.com) - * @author Jorge Aliss (jaliss@hotmail.com) - * @date March 3, 1999 - */ - /* Written using "Java Class Libraries", 2nd edition, plus online - * API docs for JDK 1.2 from http://www.javasoft.com. - * Status: Believed complete and correct to 1.2, except serialization. - * and parsing. - */ - private static final class MessageFormatElement - { - // Argument number. - int argNumber; - // Formatter to be used. This is the format set by setFormat. - Format setFormat; - // Formatter to be used based on the type. - Format format; - - // Argument will be checked to make sure it is an instance of this - // class. - Class formatClass; - - // Formatter type. - String type; - // Formatter style. - String style; - - // Text to follow this element. - String trailer; - - // Recompute the locale-based formatter. - void setLocale (Locale loc) - { - if (type == null) - ; - else if (type.equals("number")) - { - formatClass = java.lang.Number.class; - - if (style == null) - format = NumberFormat.getInstance(loc); - else if (style.equals("currency")) - format = NumberFormat.getCurrencyInstance(loc); - else if (style.equals("percent")) - format = NumberFormat.getPercentInstance(loc); - else if (style.equals("integer")) - { - NumberFormat nf = NumberFormat.getNumberInstance(loc); - nf.setMaximumFractionDigits(0); - nf.setGroupingUsed(false); - format = nf; - } - else - { - format = NumberFormat.getNumberInstance(loc); - DecimalFormat df = (DecimalFormat) format; - df.applyPattern(style); - } - } - else if (type.equals("time") || type.equals("date")) - { - formatClass = java.util.Date.class; - - int val = DateFormat.DEFAULT; - boolean styleIsPattern = false; - if (style == null) - ; - else if (style.equals("short")) - val = DateFormat.SHORT; - else if (style.equals("medium")) - val = DateFormat.MEDIUM; - else if (style.equals("long")) - val = DateFormat.LONG; - else if (style.equals("full")) - val = DateFormat.FULL; - else - styleIsPattern = true; - - if (type.equals("time")) - format = DateFormat.getTimeInstance(val, loc); - else - format = DateFormat.getDateInstance(val, loc); - - if (styleIsPattern) - { - SimpleDateFormat sdf = (SimpleDateFormat) format; - sdf.applyPattern(style); - } - } - else if (type.equals("choice")) - { - formatClass = java.lang.Number.class; - - if (style == null) - throw new - IllegalArgumentException ("style required for choice format"); - format = new ChoiceFormat (style); - } - } - } - - private static final long serialVersionUID = 6479157306784022952L; - - public static class Field extends Format.Field - { - static final long serialVersionUID = 7899943957617360810L; - - /** - * This is the attribute set for all characters produced - * by MessageFormat during a formatting. - */ - public static final MessageFormat.Field ARGUMENT = new MessageFormat.Field("argument"); - - // For deserialization - private Field() - { - super(""); - } - - protected Field(String s) - { - super(s); - } - - /** - * invoked to resolve the true static constant by - * comparing the deserialized object to know name. - * - * @return object constant - */ - protected Object readResolve() throws InvalidObjectException - { - if (getName().equals(ARGUMENT.getName())) - return ARGUMENT; - - throw new InvalidObjectException("no such MessageFormat field called " + getName()); - } - - } - - // Helper that returns the text up to the next format opener. The - // text is put into BUFFER. Returns index of character after end of - // string. Throws IllegalArgumentException on error. - private static int scanString(String pat, int index, StringBuffer buffer) - { - int max = pat.length(); - buffer.setLength(0); - boolean quoted = false; - for (; index < max; ++index) - { - char c = pat.charAt(index); - if (quoted) - { - // In a quoted context, a single quote ends the quoting. - if (c == '\'') - quoted = false; - else - buffer.append(c); - } - // Check for '', which is a single quote. - else if (c == '\'' && index + 1 < max && pat.charAt(index + 1) == '\'') - { - buffer.append(c); - ++index; - } - else if (c == '\'') - { - // Start quoting. - quoted = true; - } - else if (c == '{') - break; - else - buffer.append(c); - } - // Note that we explicitly allow an unterminated quote. This is - // done for compatibility. - return index; - } - - // This helper retrieves a single part of a format element. Returns - // the index of the terminating character. - private static int scanFormatElement(String pat, int index, - StringBuffer buffer, char term) - { - int max = pat.length(); - buffer.setLength(0); - int brace_depth = 1; - boolean quoted = false; - - for (; index < max; ++index) - { - char c = pat.charAt(index); - // First see if we should turn off quoting. - if (quoted) - { - if (c == '\'') - quoted = false; - // In both cases we fall through to inserting the - // character here. - } - // See if we have just a plain quote to insert. - else if (c == '\'' && index + 1 < max - && pat.charAt(index + 1) == '\'') - { - buffer.append(c); - ++index; - } - // See if quoting should turn on. - else if (c == '\'') - quoted = true; - else if (c == '{') - ++brace_depth; - else if (c == '}') - { - if (--brace_depth == 0) - break; - } - // Check for TERM after braces, because TERM might be `}'. - else if (c == term) - break; - // All characters, including opening and closing quotes, are - // inserted here. - buffer.append(c); - } - return index; - } - - // This is used to parse a format element and whatever non-format - // text might trail it. - private static int scanFormat(String pat, int index, StringBuffer buffer, - Vector elts, Locale locale) - { - MessageFormatElement mfe = new MessageFormatElement (); - elts.addElement(mfe); - - int max = pat.length(); - - // Skip the opening `{'. - ++index; - - // Fetch the argument number. - index = scanFormatElement (pat, index, buffer, ','); - try - { - mfe.argNumber = Integer.parseInt(buffer.toString()); - } - catch (NumberFormatException nfx) - { - IllegalArgumentException iae = new IllegalArgumentException(pat); - iae.initCause(nfx); - throw iae; - } - - // Extract the element format. - if (index < max && pat.charAt(index) == ',') - { - index = scanFormatElement (pat, index + 1, buffer, ','); - mfe.type = buffer.toString(); - - // Extract the style. - if (index < max && pat.charAt(index) == ',') - { - index = scanFormatElement (pat, index + 1, buffer, '}'); - mfe.style = buffer.toString (); - } - } - - // Advance past the last terminator. - if (index >= max || pat.charAt(index) != '}') - throw new IllegalArgumentException("Missing '}' at end of message format"); - ++index; - - // Now fetch trailing string. - index = scanString (pat, index, buffer); - mfe.trailer = buffer.toString (); - - mfe.setLocale(locale); - - return index; - } - - /** - * Applies the specified pattern to this MessageFormat. - * - * @param aPattern The Pattern - */ - public void applyPattern (String newPattern) - { - pattern = newPattern; - - StringBuffer tempBuffer = new StringBuffer (); - - int index = scanString (newPattern, 0, tempBuffer); - leader = tempBuffer.toString(); - - Vector elts = new Vector (); - while (index < newPattern.length()) - index = scanFormat (newPattern, index, tempBuffer, elts, locale); - - elements = new MessageFormatElement[elts.size()]; - elts.copyInto(elements); - } - - /** - * Overrides Format.clone() - */ - public Object clone () - { - MessageFormat c = (MessageFormat) super.clone (); - c.elements = (MessageFormatElement[]) elements.clone (); - return c; - } - - /** - * Overrides Format.equals(Object obj) - */ - public boolean equals (Object obj) - { - if (! (obj instanceof MessageFormat)) - return false; - MessageFormat mf = (MessageFormat) obj; - return (pattern.equals(mf.pattern) - && locale.equals(mf.locale)); - } - - /** - * A convinience method to format patterns. - * - * @param aPattern The pattern used when formatting. - * @param arguments The array containing the objects to be formatted. - */ - public AttributedCharacterIterator formatToCharacterIterator (Object arguments) - { - Object[] arguments_array = (Object[])arguments; - FormatCharacterIterator iterator = new FormatCharacterIterator(); - - formatInternal(arguments_array, new StringBuffer(), null, iterator); - - return iterator; - } - - /** - * A convinience method to format patterns. - * - * @param aPattern The pattern used when formatting. - * @param arguments The array containing the objects to be formatted. - */ - public static String format (String pattern, Object arguments[]) - { - MessageFormat mf = new MessageFormat (pattern); - StringBuffer sb = new StringBuffer (); - FieldPosition fp = new FieldPosition (NumberFormat.INTEGER_FIELD); - return mf.formatInternal(arguments, sb, fp, null).toString(); - } - - /** - * Returns the pattern with the formatted objects. - * - * @param source The array containing the objects to be formatted. - * @param result The StringBuffer where the text is appened. - * @param fp A FieldPosition object (it is ignored). - */ - public final StringBuffer format (Object arguments[], StringBuffer appendBuf, - FieldPosition fp) - { - return formatInternal(arguments, appendBuf, fp, null); - } - - private StringBuffer formatInternal (Object arguments[], - StringBuffer appendBuf, - FieldPosition fp, - FormatCharacterIterator output_iterator) - { - appendBuf.append(leader); - if (output_iterator != null) - output_iterator.append(leader); - - for (int i = 0; i < elements.length; ++i) - { - Object thisArg = null; - boolean unavailable = false; - if (arguments == null || elements[i].argNumber >= arguments.length) - unavailable = true; - else - thisArg = arguments[elements[i].argNumber]; - - AttributedCharacterIterator iterator = null; - - Format formatter = null; - - if (fp != null && i == fp.getField() && fp.getFieldAttribute() == Field.ARGUMENT) - fp.setBeginIndex(appendBuf.length()); - - if (unavailable) - appendBuf.append("{" + elements[i].argNumber + "}"); - else - { - if (elements[i].setFormat != null) - formatter = elements[i].setFormat; - else if (elements[i].format != null) - { - if (elements[i].formatClass != null - && ! elements[i].formatClass.isInstance(thisArg)) - throw new IllegalArgumentException("Wrong format class"); - - formatter = elements[i].format; - } - else if (thisArg instanceof Number) - formatter = NumberFormat.getInstance(locale); - else if (thisArg instanceof Date) - formatter = DateFormat.getTimeInstance(DateFormat.DEFAULT, locale); - else - appendBuf.append(thisArg); - } - - if (fp != null && fp.getField() == i && fp.getFieldAttribute() == Field.ARGUMENT) - fp.setEndIndex(appendBuf.length()); - - if (formatter != null) - { - // Special-case ChoiceFormat. - if (formatter instanceof ChoiceFormat) - { - StringBuffer buf = new StringBuffer (); - formatter.format(thisArg, buf, fp); - MessageFormat mf = new MessageFormat (); - mf.setLocale(locale); - mf.applyPattern(buf.toString()); - mf.format(arguments, appendBuf, fp); - } - else - { - if (output_iterator != null) - iterator = formatter.formatToCharacterIterator(thisArg); - else - formatter.format(thisArg, appendBuf, fp); - } - - elements[i].format = formatter; - } - - if (output_iterator != null) - { - HashMap hash_argument = new HashMap(); - int position = output_iterator.getEndIndex(); - - hash_argument.put (MessageFormat.Field.ARGUMENT, - new Integer(elements[i].argNumber)); - - - if (iterator != null) - { - output_iterator.append(iterator); - output_iterator.addAttributes(hash_argument, position, - output_iterator.getEndIndex()); - } - else - output_iterator.append(thisArg.toString(), hash_argument); - - output_iterator.append(elements[i].trailer); - } - - appendBuf.append(elements[i].trailer); - } - - return appendBuf; - } - - /** - * Returns the pattern with the formatted objects. The first argument - * must be a array of Objects. - * This is equivalent to format((Object[]) objectArray, appendBuf, fpos) - * - * @param objectArray The object array to be formatted. - * @param appendBuf The StringBuffer where the text is appened. - * @param fpos A FieldPosition object (it is ignored). - */ - public final StringBuffer format (Object objectArray, StringBuffer appendBuf, - FieldPosition fpos) - { - return format ((Object[])objectArray, appendBuf, fpos); - } - - /** - * Returns an array with the Formats for - * the arguments. - */ - public Format[] getFormats () - { - Format[] f = new Format[elements.length]; - for (int i = elements.length - 1; i >= 0; --i) - f[i] = elements[i].setFormat; - return f; - } - - /** - * Returns the locale. - */ - public Locale getLocale () - { - return locale; - } - - /** - * Overrides Format.hashCode() - */ - public int hashCode () - { - // FIXME: not a very good hash. - return pattern.hashCode() + locale.hashCode(); - } - - private MessageFormat () - { - } - - /** - * Creates a new MessageFormat object with - * the specified pattern - * - * @param pattern The Pattern - */ - public MessageFormat(String pattern) - { - this(pattern, Locale.getDefault()); - } - - /** - * Creates a new MessageFormat object with - * the specified pattern - * - * @param pattern The Pattern - * @param locale The Locale to use - * - * @since 1.4 - */ - public MessageFormat(String pattern, Locale locale) - { - this.locale = locale; - applyPattern (pattern); - } - - /** - * Parse a string <code>sourceStr</code> against the pattern specified - * to the MessageFormat constructor. - * - * @param sourceStr the string to be parsed. - * @param pos the current parse position (and eventually the error position). - * @return the array of parsed objects sorted according to their argument number - * in the pattern. - */ - public Object[] parse (String sourceStr, ParsePosition pos) - { - // Check initial text. - int index = pos.getIndex(); - if (! sourceStr.startsWith(leader, index)) - { - pos.setErrorIndex(index); - return null; - } - index += leader.length(); - - Vector results = new Vector (elements.length, 1); - // Now check each format. - for (int i = 0; i < elements.length; ++i) - { - Format formatter = null; - if (elements[i].setFormat != null) - formatter = elements[i].setFormat; - else if (elements[i].format != null) - formatter = elements[i].format; - - Object value = null; - if (formatter instanceof ChoiceFormat) - { - // We must special-case a ChoiceFormat because it might - // have recursive formatting. - ChoiceFormat cf = (ChoiceFormat) formatter; - String[] formats = (String[]) cf.getFormats(); - double[] limits = (double[]) cf.getLimits(); - MessageFormat subfmt = new MessageFormat (); - subfmt.setLocale(locale); - ParsePosition subpos = new ParsePosition (index); - - int j; - for (j = 0; value == null && j < limits.length; ++j) - { - subfmt.applyPattern(formats[j]); - subpos.setIndex(index); - value = subfmt.parse(sourceStr, subpos); - } - if (value != null) - { - index = subpos.getIndex(); - value = new Double (limits[j]); - } - } - else if (formatter != null) - { - pos.setIndex(index); - value = formatter.parseObject(sourceStr, pos); - if (value != null) - index = pos.getIndex(); - } - else - { - // We have a String format. This can lose in a number - // of ways, but we give it a shot. - int next_index; - if (elements[i].trailer.length() > 0) - next_index = sourceStr.indexOf(elements[i].trailer, index); - else - next_index = sourceStr.length(); - if (next_index == -1) - { - pos.setErrorIndex(index); - return null; - } - value = sourceStr.substring(index, next_index); - index = next_index; - } - - if (value == null - || ! sourceStr.startsWith(elements[i].trailer, index)) - { - pos.setErrorIndex(index); - return null; - } - - if (elements[i].argNumber >= results.size()) - results.setSize(elements[i].argNumber + 1); - results.setElementAt(value, elements[i].argNumber); - - index += elements[i].trailer.length(); - } - - Object[] r = new Object[results.size()]; - results.copyInto(r); - return r; - } - - public Object[] parse (String sourceStr) throws ParseException - { - ParsePosition pp = new ParsePosition (0); - Object[] r = parse (sourceStr, pp); - if (r == null) - throw new ParseException ("couldn't parse string", pp.getErrorIndex()); - return r; - } - - public Object parseObject (String sourceStr, ParsePosition pos) - { - return parse (sourceStr, pos); - } - - /** - * Sets the format for the argument at an specified - * index. - * - * @param index The index. - * @format The Format object. - */ - public void setFormat (int variableNum, Format newFormat) - { - elements[variableNum].setFormat = newFormat; - } - - /** - * Sets the formats for the arguments. - * - * @param formats An array of Format objects. - */ - public void setFormats (Format[] newFormats) - { - if (newFormats.length < elements.length) - throw new IllegalArgumentException("Not enough format objects"); - - int len = Math.min(newFormats.length, elements.length); - for (int i = 0; i < len; ++i) - elements[i].setFormat = newFormats[i]; - } - - /** - * Sets the locale. - * - * @param locale A Locale - */ - public void setLocale (Locale loc) - { - locale = loc; - if (elements != null) - { - for (int i = 0; i < elements.length; ++i) - elements[i].setLocale(loc); - } - } - - /** - * Returns the pattern. - */ - public String toPattern () - { - return pattern; - } - - /** - * Return the formatters used sorted by argument index. It uses the - * internal table to fill in this array: if a format has been - * set using <code>setFormat</code> or <code>setFormatByArgumentIndex</code> - * then it returns it at the right index. If not it uses the detected - * formatters during a <code>format</code> call. If nothing is known - * about that argument index it just puts null at that position. - * To get useful informations you may have to call <code>format</code> - * at least once. - * - * @return an array of formatters sorted by argument index. - */ - public Format[] getFormatsByArgumentIndex() - { - int argNumMax = 0; - // First, find the greatest argument number. - for (int i=0;i<elements.length;i++) - if (elements[i].argNumber > argNumMax) - argNumMax = elements[i].argNumber; - - Format[] formats = new Format[argNumMax]; - for (int i=0;i<elements.length;i++) - { - if (elements[i].setFormat != null) - formats[elements[i].argNumber] = elements[i].setFormat; - else if (elements[i].format != null) - formats[elements[i].argNumber] = elements[i].format; - } - return formats; - } - - /** - * Set the format to used using the argument index number. - * - * @param argumentIndex the argument index. - * @param newFormat the format to use for this argument. - */ - public void setFormatByArgumentIndex(int argumentIndex, - Format newFormat) - { - for (int i=0;i<elements.length;i++) - { - if (elements[i].argNumber == argumentIndex) - elements[i].setFormat = newFormat; - } - } - - /** - * Set the format for argument using a specified array of formatters - * which is sorted according to the argument index. If the number of - * elements in the array is fewer than the number of arguments only - * the arguments specified by the array are touched. - * - * @param newFormats array containing the new formats to set. - * - * @throws NullPointerException if newFormats is null - */ - public void setFormatsByArgumentIndex(Format[] newFormats) - { - for (int i=0;i<newFormats.length;i++) - { - // Nothing better than that can exist here. - setFormatByArgumentIndex(i, newFormats[i]); - } - } - - // The pattern string. - private String pattern; - // The locale. - private Locale locale; - // Variables. - private MessageFormatElement[] elements; - // Leader text. - private String leader; -} diff --git a/libjava/java/text/NumberFormat.java b/libjava/java/text/NumberFormat.java deleted file mode 100644 index b58476f7256..00000000000 --- a/libjava/java/text/NumberFormat.java +++ /dev/null @@ -1,803 +0,0 @@ -/* NumberFormat.java -- Formats and parses numbers - Copyright (C) 1998, 1999, 2000, 2001, 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.text; - -import java.io.IOException; -import java.io.InvalidObjectException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.util.Currency; -import java.util.Locale; -import java.util.MissingResourceException; -import java.util.ResourceBundle; - -/** - * This is the abstract superclass of all classes which format and - * parse numeric values such as decimal numbers, integers, currency values, - * and percentages. These classes perform their parsing and formatting - * in a locale specific manner, accounting for such items as differing - * currency symbols and thousands separators. - * <p> - * To create an instance of a concrete subclass of <code>NumberFormat</code>, - * do not call a class constructor directly. Instead, use one of the - * static factory methods in this class such as - * <code>getCurrencyInstance</code>. - * - * @author Tom Tromey (tromey@cygnus.com) - * @author Aaron M. Renn (arenn@urbanophile.com) - * @date March 4, 1999 - */ -/* Written using "Java Class Libraries", 2nd edition, plus online - * API docs for JDK 1.2 from http://www.javasoft.com. - * Status: Believed complete and correct to 1.2, except getAvailableLocales. - */ -public abstract class NumberFormat extends Format implements Cloneable -{ - /** - * This is a constant used to create a <code>FieldPosition</code> object - * that will return the integer portion of a formatted number. - */ - public static final int INTEGER_FIELD = 0; - - /** - * This is a constant used to create a <code>FieldPosition</code> object - * that will return the fractional portion of a formatted number. - */ - public static final int FRACTION_FIELD = 1; - - public static class Field extends Format.Field - { - static final long serialVersionUID = 7494728892700160890L; - - /** - * Attribute set to all characters containing digits of the integer - * part. - */ - public static final NumberFormat.Field INTEGER - = new Field("integer"); - - /** - * Attribute set to all characters containing digits of the fractional - * part. - */ - public static final NumberFormat.Field FRACTION - = new Field("fraction"); - - /** - * Attribute set to all characters containing digits of the exponential - * part. - */ - public static final NumberFormat.Field EXPONENT - = new Field("exponent"); - - /** - * Attribute set to all characters containing a decimal separator. - */ - public static final NumberFormat.Field DECIMAL_SEPARATOR - = new Field("decimal separator"); - - /** - * Attribute set to all characters containing a sign (plus or minus). - */ - public static final NumberFormat.Field SIGN - = new Field("sign"); - - /** - * Attribute set to all characters containing a grouping separator (e.g. - * a comma, a white space,...). - */ - public static final NumberFormat.Field GROUPING_SEPARATOR - = new Field("grouping separator"); - - /** - * Attribute set to all characters containing an exponential symbol (e.g. - * 'E') - */ - public static final NumberFormat.Field EXPONENT_SYMBOL - = new Field("exponent symbol"); - - /** - * Attribute set to all characters containing a percent symbol (e.g. '%') - */ - public static final NumberFormat.Field PERCENT - = new Field("percent"); - - /** - * Attribute set to all characters containing a permille symbol. - */ - public static final NumberFormat.Field PERMILLE - = new Field("permille"); - - /** - * Attribute set to all characters containing the currency unit. - */ - public static final NumberFormat.Field CURRENCY - = new Field("currency"); - - /** - * Attribute set to all characters containing the exponent sign. - */ - public static final NumberFormat.Field EXPONENT_SIGN - = new Field("exponent sign"); - - /** - * Private fields to register all fields contained in this descriptor. - */ - private static final NumberFormat.Field[] allFields = - { - INTEGER, FRACTION, EXPONENT, DECIMAL_SEPARATOR, SIGN, - GROUPING_SEPARATOR, EXPONENT_SYMBOL, PERCENT, - PERMILLE, CURRENCY, EXPONENT_SIGN - }; - - /** - * This constructor is only used by the deserializer. Without it, - * it would fail to construct a valid object. - */ - private Field() - { - super(""); - } - - /** - * Create a Field instance with the specified field name. - * - * @param field_name Field name for the new Field instance. - */ - protected Field(String field_name) - { - super (field_name); - } - - /** - * This function is used by the deserializer to know which object - * to use when it encounters an encoded NumberFormat.Field in a - * serialization stream. If the stream is valid it should return - * one of the above field. In the other case we throw an exception. - * - * @return a valid official NumberFormat.Field instance. - * - * @throws InvalidObjectException if the field name is invalid. - */ - protected Object readResolve() throws InvalidObjectException - { - String s = getName(); - for (int i = 0; i < allFields.length; i++) - if (s.equals(allFields[i].getName())) - return allFields[i]; - - throw new InvalidObjectException("no such NumberFormat field called " - + s); - } - } - - /** - * This method is a specialization of the format method that performs - * a simple formatting of the specified <code>long</code> number. - * - * @param number The <code>long</code> to format. - * - * @return The formatted number - */ - public final String format (long number) - { - StringBuffer sbuf = new StringBuffer(50); - format (number, sbuf, null); - return sbuf.toString(); - } - - public final StringBuffer format (Object obj, StringBuffer sbuf, - FieldPosition pos) - { - if (obj instanceof Number) - return format(((Number) obj).doubleValue(), sbuf, pos); - else - throw new IllegalArgumentException - ("Cannot format given Object as a Number"); - } - - /** - * This method formats the specified <code>double</code> and appends it to - * a <code>StringBuffer</code>. - * - * @param number The <code>double</code> to format. - * @param sb The <code>StringBuffer</code> to append the formatted number to. - * @param pos The desired <code>FieldPosition</code>. - * - * @return The <code>StringBuffer</code> with the appended number. - */ - public abstract StringBuffer format (double number, - StringBuffer sbuf, FieldPosition pos); - - /** - * This method formats the specified <code>long</code> and appends it to - * a <code>StringBuffer</code>. - * - * @param number The <code>long</code> to format. - * @param sb The <code>StringBuffer</code> to append the formatted number to. - * @param pos The desired <code>FieldPosition</code>. - * - * @return The <code>StringBuffer</code> with the appended number. - */ - public abstract StringBuffer format (long number, - StringBuffer sbuf, FieldPosition pos); - - /** - * This method tests the specified object for equality against this object. - * This will be <code>true</code> if the following conditions are met: - * <p> - * <ul> - * <li>The specified object is not <code>null</code>. - * <li>The specified object is an instance of <code>NumberFormat</code>. - * </ul> - * <p> - * Since this method does not test much, it is highly advised that - * concrete subclasses override this method. - * - * @param obj The <code>Object</code> to test against equality with - * this object. - * - * @return <code>true</code> if the specified object is equal to - * this object, <code>false</code> otherwise. - */ - public boolean equals (Object obj) - { - if (! (obj instanceof NumberFormat)) - return false; - NumberFormat nf = (NumberFormat) obj; - return (groupingUsed == nf.groupingUsed - && maximumFractionDigits == nf.maximumFractionDigits - && maximumIntegerDigits == nf.maximumIntegerDigits - && minimumFractionDigits == nf.minimumFractionDigits - && minimumIntegerDigits == nf.minimumIntegerDigits - && parseIntegerOnly == nf.parseIntegerOnly); - } - - /** - * This method returns a list of locales for which concrete instances - * of <code>NumberFormat</code> subclasses may be created. - * - * @return The list of available locales. - */ - public static Locale[] getAvailableLocales () - { - Locale[] list = new Locale[1]; - list[0] = Locale.US; - return list; - } - - private static NumberFormat computeInstance(Locale loc, String resource, - String def) - { - ResourceBundle res; - try - { - res = ResourceBundle.getBundle("gnu.java.locale.LocaleInformation", - loc, ClassLoader.getSystemClassLoader()); - } - catch (MissingResourceException x) - { - res = null; - } - String fmt; - try - { - fmt = res == null ? def : res.getString(resource); - } - catch (MissingResourceException x) - { - fmt = def; - } - DecimalFormatSymbols dfs = new DecimalFormatSymbols (loc); - return new DecimalFormat (fmt, dfs); - } - - /** - * This method returns an instance of <code>NumberFormat</code> suitable - * for formatting and parsing currency values in the default locale. - * - * @return An instance of <code>NumberFormat</code> for handling currencies. - */ - public static final NumberFormat getCurrencyInstance () - { - return getCurrencyInstance (Locale.getDefault()); - } - - /** - * This method returns an instance of <code>NumberFormat</code> suitable - * for formatting and parsing currency values in the specified locale. - * - * @return An instance of <code>NumberFormat</code> for handling currencies. - */ - public static NumberFormat getCurrencyInstance (Locale loc) - { - return computeInstance (loc, "currencyFormat", "$#,##0.00;($#,##0.00)"); - } - - /** - * This method returns a default instance for the default locale. This - * will be a concrete subclass of <code>NumberFormat</code>, but the - * actual class returned is dependent on the locale. - * - * @return An instance of the default <code>NumberFormat</code> class. - */ - public static final NumberFormat getInstance () - { - return getInstance (Locale.getDefault()); - } - - /** - * This method returns a default instance for the specified locale. This - * will be a concrete subclass of <code>NumberFormat</code>, but the - * actual class returned is dependent on the locale. - * - * @param locale The desired locale. - * - * @return An instance of the default <code>NumberFormat</code> class. - */ - public static NumberFormat getInstance (Locale loc) - { - // For now always return a number instance. - return getNumberInstance (loc); - } - - /** - * This method returns the maximum number of digits allowed in the fraction - * portion of a number. - * - * @return The maximum number of digits allowed in the fraction - * portion of a number. - */ - public int getMaximumFractionDigits () - { - return maximumFractionDigits; - } - - /** - * This method returns the maximum number of digits allowed in the integer - * portion of a number. - * - * @return The maximum number of digits allowed in the integer - * portion of a number. - */ - public int getMaximumIntegerDigits () - { - return maximumIntegerDigits; - } - - /** - * This method returns the minimum number of digits allowed in the fraction - * portion of a number. - * - * @return The minimum number of digits allowed in the fraction - * portion of a number. - */ - public int getMinimumFractionDigits () - { - return minimumFractionDigits; - } - - /** - * This method returns the minimum number of digits allowed in the integer - * portion of a number. - * - * @return The minimum number of digits allowed in the integer - * portion of a number. - */ - public int getMinimumIntegerDigits () - { - return minimumIntegerDigits; - } - - /** - * This method returns a default instance for the specified locale. This - * will be a concrete subclass of <code>NumberFormat</code>, but the - * actual class returned is dependent on the locale. - * - * @param locale The desired locale. - * - * @return An instance of the default <code>NumberFormat</code> class. - */ - public static final NumberFormat getNumberInstance () - { - return getNumberInstance (Locale.getDefault()); - } - - /** - * This method returns a general purpose number formatting and parsing - * class for the default locale. This will be a concrete subclass of - * <code>NumberFormat</code>, but the actual class returned is dependent - * on the locale. - * - * @return An instance of a generic number formatter for the default locale. - */ - public static NumberFormat getNumberInstance (Locale loc) - { - return computeInstance (loc, "numberFormat", "#,##0.###"); - } - - /** - * This method returns an integer formatting and parsing class for the - * default locale. This will be a concrete subclass of <code>NumberFormat</code>, - * but the actual class returned is dependent on the locale. - * - * @return An instance of an integer number formatter for the default locale. - * @since 1.4 - */ - public static final NumberFormat getIntegerInstance() - { - return getIntegerInstance (Locale.getDefault()); - } - - /** - * This method returns an integer formatting and parsing class for the - * default locale. This will be a concrete subclass of <code>NumberFormat</code>, - * but the actual class returned is dependent on the locale. - * - * @param locale the desired locale. - * - * @return An instance of an integer number formatter for the desired locale. - * @since 1.4 - */ - public static NumberFormat getIntegerInstance(Locale locale) - { - NumberFormat format = computeInstance (locale, "numberFormat", "#,##0"); - format.setParseIntegerOnly (true); - return format; - } - - /** - * This method returns an instance of <code>NumberFormat</code> suitable - * for formatting and parsing percentage values in the default locale. - * - * @return An instance of <code>NumberFormat</code> for handling percentages. - */ - public static final NumberFormat getPercentInstance () - { - return getPercentInstance (Locale.getDefault()); - } - - /** - * This method returns an instance of <code>NumberFormat</code> suitable - * for formatting and parsing percentage values in the specified locale. - * - * @param locale The desired locale. - * - * @return An instance of <code>NumberFormat</code> for handling percentages. - */ - public static NumberFormat getPercentInstance (Locale loc) - { - return computeInstance (loc, "percentFormat", "#,##0%"); - } - - /** - * This method returns a hash value for this object. - * - * @return The hash code. - */ - public int hashCode () - { - int hash = super.hashCode(); - hash ^= (maximumFractionDigits + maximumIntegerDigits - + minimumFractionDigits + minimumIntegerDigits); - if (groupingUsed) - hash ^= 0xf0f0; - if (parseIntegerOnly) - hash ^= 0x0f0f; - return hash; - } - - /** - * This method tests whether or not grouping is in use. Grouping is - * a method of marking separations in numbers, such as thousand separators - * in the US English locale. The grouping positions and symbols are all - * locale specific. As an example, with grouping disabled, the number one - * million would appear as "1000000". With grouping enabled, this number - * might appear as "1,000,000". (Both of these assume the US English - * locale). - * - * @return <code>true</code> if grouping is enabled, - * <code>false</code> otherwise. - */ - public boolean isGroupingUsed () - { - return groupingUsed; - } - - /** - * This method tests whether or not only integer values should be parsed. - * If this class is parsing only integers, parsing stops at the decimal - * point. - * - * @return <code>true</code> if only integers are parsed, - * <code>false</code> otherwise. - */ - public boolean isParseIntegerOnly () - { - return parseIntegerOnly; - } - - /** - * This is a default constructor for use by subclasses. - */ - public NumberFormat () - { - } - - /** - * This method parses the specified string into a <code>Number</code>. This - * will be a <code>Long</code> if possible, otherwise it will be a - * <code>Double</code>. If no number can be parsed, no exception is - * thrown. Instead, the parse position remains at its initial index. - * - * @param str The string to parse. - * @param pp The desired <code>ParsePosition</code>. - * - * @return The parsed <code>Number</code> - */ - public abstract Number parse (String sourceStr, ParsePosition pos); - - /** - * This method parses the specified string into a <code>Number</code>. This - * will be a <code>Long</code> if possible, otherwise it will be a - * <code>Double</code>. If no number can be parsed, an exception will be - * thrown. - * - * @param str The string to parse. - * - * @return The parsed <code>Number</code> - * - * @exception ParseException If no number can be parsed. - */ - public Number parse (String sourceStr) throws ParseException - { - ParsePosition pp = new ParsePosition (0); - Number r = parse (sourceStr, pp); - if (r == null) - { - int index = pp.getErrorIndex(); - if (index < 0) - index = pp.getIndex(); - throw new ParseException ("couldn't parse number", index); - } - return r; - } - - /** - * This method parses the specified string into an <code>Object</code>. This - * will be a <code>Long</code> if possible, otherwise it will be a - * <code>Double</code>. If no number can be parsed, no exception is - * thrown. Instead, the parse position remains at its initial index. - * - * @param str The string to parse. - * @param pp The desired <code>ParsePosition</code>. - * - * @return The parsed <code>Object</code> - */ - public final Object parseObject (String sourceStr, ParsePosition pos) - { - return parse (sourceStr, pos); - } - - /** - * This method sets the grouping behavior of this formatter. Grouping is - * a method of marking separations in numbers, such as thousand separators - * in the US English locale. The grouping positions and symbols are all - * locale specific. As an example, with grouping disabled, the number one - * million would appear as "1000000". With grouping enabled, this number - * might appear as "1,000,000". (Both of these assume the US English - * locale). - * - * @param groupingUsed <code>true</code> to enable grouping, - * <code>false</code> to disable it. - */ - public void setGroupingUsed (boolean newValue) - { - groupingUsed = newValue; - } - - /** - * This method sets the maximum number of digits allowed in the fraction - * portion of a number to the specified value. If this is less than the - * current minimum allowed digits, the minimum allowed digits value will - * be lowered to be equal to the new maximum allowed digits value. - * - * @param maximumFractionDigits The new maximum fraction digits value. - */ - public void setMaximumFractionDigits (int newValue) - { - maximumFractionDigits = newValue; - if (getMinimumFractionDigits () > maximumFractionDigits) - setMinimumFractionDigits (maximumFractionDigits); - } - - /** - * This method sets the maximum number of digits allowed in the integer - * portion of a number to the specified value. If this is less than the - * current minimum allowed digits, the minimum allowed digits value will - * be lowered to be equal to the new maximum allowed digits value. - * - * @param maximumIntegerDigits The new maximum integer digits value. - */ - public void setMaximumIntegerDigits (int newValue) - { - maximumIntegerDigits = newValue; - if (getMinimumIntegerDigits () > maximumIntegerDigits) - setMinimumIntegerDigits (maximumIntegerDigits); - } - - /** - * This method sets the minimum number of digits allowed in the fraction - * portion of a number to the specified value. If this is greater than the - * current maximum allowed digits, the maximum allowed digits value will - * be raised to be equal to the new minimum allowed digits value. - * - * @param minimumFractionDigits The new minimum fraction digits value. - */ - public void setMinimumFractionDigits (int newValue) - { - minimumFractionDigits = newValue; - if (getMaximumFractionDigits () < minimumFractionDigits) - setMaximumFractionDigits (minimumFractionDigits); - } - - /** - * This method sets the minimum number of digits allowed in the integer - * portion of a number to the specified value. If this is greater than the - * current maximum allowed digits, the maximum allowed digits value will - * be raised to be equal to the new minimum allowed digits value. - * - * @param minimumIntegerDigits The new minimum integer digits value. - */ - public void setMinimumIntegerDigits (int newValue) - { - minimumIntegerDigits = newValue; - if (getMaximumIntegerDigits () < minimumIntegerDigits) - setMaximumIntegerDigits (minimumIntegerDigits); - } - - /** - * This method sets the parsing behavior of this object to parse only - * integers or not. - * - * @param parseIntegerOnly <code>true</code> to parse only integers, - * <code>false</code> otherwise. - */ - public void setParseIntegerOnly (boolean value) - { - parseIntegerOnly = value; - } - - /** - * This method is a specialization of the format method that performs - * a simple formatting of the specified <code>double</code> number. - * - * @param number The <code>double</code> to format. - * - * @return The formatted number - */ - public final String format (double number) - { - StringBuffer sbuf = new StringBuffer(50); - format (number, sbuf, null); - return sbuf.toString(); - } - - // These field names are fixed by the serialization spec. - boolean groupingUsed; - int maximumFractionDigits; - private byte maxFractionDigits; - int maximumIntegerDigits; - private byte maxIntegerDigits; - int minimumFractionDigits; - private byte minFractionDigits; - int minimumIntegerDigits; - private byte minIntegerDigits; - boolean parseIntegerOnly; - private int serialVersionOnStream; - private static final long serialVersionUID = -2308460125733713944L; - - private void readObject(ObjectInputStream stream) - throws IOException, ClassNotFoundException - { - stream.defaultReadObject(); - if (serialVersionOnStream < 1) - { - maximumFractionDigits = maxFractionDigits; - maximumIntegerDigits = maxIntegerDigits; - minimumFractionDigits = minFractionDigits; - minimumIntegerDigits = minIntegerDigits; - serialVersionOnStream = 1; - } - } - - private void writeObject(ObjectOutputStream stream) throws IOException - { - maxFractionDigits = maximumFractionDigits < Byte.MAX_VALUE ? - (byte) maximumFractionDigits : Byte.MAX_VALUE; - maxIntegerDigits = maximumIntegerDigits < Byte.MAX_VALUE ? - (byte) maximumIntegerDigits : Byte.MAX_VALUE; - minFractionDigits = minimumFractionDigits < Byte.MAX_VALUE ? - (byte) minimumFractionDigits : Byte.MAX_VALUE; - minIntegerDigits = minimumIntegerDigits < Byte.MAX_VALUE ? - (byte) minimumIntegerDigits : Byte.MAX_VALUE; - serialVersionOnStream = 1; - stream.defaultWriteObject(); - } - - /** - * Returns the currency used by this number format when formatting currency - * values. - * - * The default implementation throws UnsupportedOperationException. - * - * @return The used currency object, or null. - * - * @throws UnsupportedOperationException If the number format class doesn't - * implement currency formatting. - * - * @since 1.4 - */ - public Currency getCurrency() - { - throw new UnsupportedOperationException(); - } - - /** - * Sets the currency used by this number format when formatting currency - * values. - * - * The default implementation throws UnsupportedOperationException. - * - * @param currency The new currency to be used by this number format. - * - * @throws NullPointerException If currenc is null. - * @throws UnsupportedOperationException If the number format class doesn't - * implement currency formatting. - * - * @since 1.4 - */ - public void setCurrency(Currency currency) - { - if (currency == null) - throw new NullPointerException("currency may not be null"); - - throw new UnsupportedOperationException(); - } -} diff --git a/libjava/java/text/ParseException.java b/libjava/java/text/ParseException.java deleted file mode 100644 index 6d014effd2a..00000000000 --- a/libjava/java/text/ParseException.java +++ /dev/null @@ -1,86 +0,0 @@ -/* ParseException.java -- an error occurred while parsing - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.text; - -/** - * This exception is thrown when an unexpected error occurs during parsing. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Per Bothner (bothner@cygnus.com) - * @see Format - * @see FieldPosition - * @status updated to 1.4 - */ -public class ParseException extends Exception -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = 2703218443322787634L; - - /** - * This is the position where the error was encountered. - * - * @serial the zero-based offset in the string where the error occurred - */ - private final int errorOffset; - - /** - * This method initializes a new instance of <code>ParseException</code> - * with a detailed error message and a error position. - * - * @param msg the descriptive message describing the error - * @param offset the position where the error was encountered - */ - public ParseException(String s, int offset) - { - super(s); - errorOffset = offset; - } - - /** - * This method returns the position where the error occurred. - * - * @return the position where the error occurred - */ - public int getErrorOffset() - { - return errorOffset; - } -} // class ParseException diff --git a/libjava/java/text/ParsePosition.java b/libjava/java/text/ParsePosition.java deleted file mode 100644 index 782f5e0eda2..00000000000 --- a/libjava/java/text/ParsePosition.java +++ /dev/null @@ -1,151 +0,0 @@ -/* ParsePosition.java -- Keep track of position while parsing. - Copyright (C) 1998, 1999, 2001, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.text; - -/** - * This class is used to keep track of the current position during parsing - * operations. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Per Bothner (bothner@cygnus.com) - */ -public class ParsePosition -{ - /** - * This is the index of the current parse position. - */ - private int index; - - /** - * This is the index of the position where an error occurred during parsing. - */ - private int error_index; - - /** - * This method initializes a new instance of <code>ParsePosition</code> to - * have the specified initial index value. - * - * @param index The initial parsing index. - */ - public ParsePosition (int index) - { - this.index = index; - error_index = -1; - } - - /** - * This method returns the current parsing index. - * - * @return The current parsing index - */ - public int getIndex () - { - return index; - } - - /** - * This method sets the current parsing index to the specified value. - * - * @param index The new parsing index. - */ - public void setIndex (int index) - { - this.index = index; - } - - /** - * This method returns the error index value. This value defaults to -1 - * unless explicitly set to another value. - * - * @return The error index. - */ - public int getErrorIndex () - { - return error_index; - } - - /** - * This method sets the error index to the specified value. - * - * @param error_index The new error index - */ - public void setErrorIndex (int error_index) - { - this.error_index = error_index; - } - - /** - * This method tests the specified object for equality with this - * object. The two objects will be considered equal if and only if - * all of the following conditions are met. - * <p> - * <ul> - * <li>The specified object is not <code>null</code>.</li> - * <li>The specified object is an instance of <code>ParsePosition</code>.</li> - * <li>The specified object has the same index and error index as - * this object.</li> - * </ul> - * - * @param obj The <code>Object</code> to test for equality against - * this object. - * - * @return <code>true</code> if the specified object is equal to - * this object, <code>false</code> otherwise. - */ - public boolean equals (Object obj) - { - if (! (obj instanceof ParsePosition)) - return false; - - ParsePosition other = (ParsePosition) obj; - return index == other.index && error_index == other.error_index; - } - - /** - * This method returns a <code>String</code> representation of this - * object. - * - * @return A <code>String</code> that represents this object. - */ - public String toString () - { - return (getClass ().getName () + "[index=" + getIndex () - + ",errorIndex=" + getErrorIndex () + "]"); - } -} diff --git a/libjava/java/text/RuleBasedCollator.java b/libjava/java/text/RuleBasedCollator.java deleted file mode 100644 index ae84a41032d..00000000000 --- a/libjava/java/text/RuleBasedCollator.java +++ /dev/null @@ -1,1017 +0,0 @@ -/* RuleBasedCollator.java -- Concrete Collator Class - Copyright (C) 1998, 1999, 2000, 2001, 2003, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.text; - -import java.util.ArrayList; -import java.util.HashMap; - -/* Written using "Java Class Libraries", 2nd edition, plus online - * API docs for JDK 1.2 from http://www.javasoft.com. - * Status: Believed complete and correct - */ - -/** - * This class is a concrete subclass of <code>Collator</code> suitable - * for string collation in a wide variety of languages. An instance of - * this class is normally returned by the <code>getInstance</code> method - * of <code>Collator</code> with rules predefined for the requested - * locale. However, an instance of this class can be created manually - * with any desired rules. - * <p> - * Rules take the form of a <code>String</code> with the following syntax - * <ul> - * <li> Modifier: '@'</li> - * <li> Relation: '<' | ';' | ',' | '=' : <text></li> - * <li> Reset: '&' : <text></li> - * </ul> - * The modifier character indicates that accents sort backward as is the - * case with French. The modifier applies to all rules <b>after</b> - * the modifier but before the next primary sequence. If placed at the end - * of the sequence if applies to all unknown accented character. - * The relational operators specify how the text - * argument relates to the previous term. The relation characters have - * the following meanings: - * <ul> - * <li>'<' - The text argument is greater than the prior term at the primary - * difference level.</li> - * <li>';' - The text argument is greater than the prior term at the secondary - * difference level.</li> - * <li>',' - The text argument is greater than the prior term at the tertiary - * difference level.</li> - * <li>'=' - The text argument is equal to the prior term</li> - * </ul> - * <p> - * As for the text argument itself, this is any sequence of Unicode - * characters not in the following ranges: 0x0009-0x000D, 0x0020-0x002F, - * 0x003A-0x0040, 0x005B-0x0060, and 0x007B-0x007E. If these characters are - * desired, they must be enclosed in single quotes. If any whitespace is - * encountered, it is ignored. (For example, "a b" is equal to "ab"). - * <p> - * The reset operation inserts the following rule at the point where the - * text argument to it exists in the previously declared rule string. This - * makes it easy to add new rules to an existing string by simply including - * them in a reset sequence at the end. Note that the text argument, or - * at least the first character of it, must be present somewhere in the - * previously declared rules in order to be inserted properly. If this - * is not satisfied, a <code>ParseException</code> will be thrown. - * <p> - * This system of configuring <code>RuleBasedCollator</code> is needlessly - * complex and the people at Taligent who developed it (along with the folks - * at Sun who accepted it into the Java standard library) deserve a slow - * and agonizing death. - * <p> - * Here are a couple of example of rule strings: - * <p> - * "< a < b < c" - This string says that a is greater than b which is - * greater than c, with all differences being primary differences. - * <p> - * "< a,A < b,B < c,C" - This string says that 'A' is greater than 'a' with - * a tertiary strength comparison. Both 'b' and 'B' are greater than 'a' and - * 'A' during a primary strength comparison. But 'B' is greater than 'b' - * under a tertiary strength comparison. - * <p> - * "< a < c & a < b " - This sequence is identical in function to the - * "< a < b < c" rule string above. The '&' reset symbol indicates that - * the rule "< b" is to be inserted after the text argument "a" in the - * previous rule string segment. - * <p> - * "< a < b & y < z" - This is an error. The character 'y' does not appear - * anywhere in the previous rule string segment so the rule following the - * reset rule cannot be inserted. - * <p> - * "< a & A @ < e & E < f& F" - This sequence is equivalent to the following - * "< a & A < E & e < f & F". - * <p> - * For a description of the various comparison strength types, see the - * documentation for the <code>Collator</code> class. - * <p> - * As an additional complication to this already overly complex rule scheme, - * if any characters precede the first rule, these characters are considered - * ignorable. They will be treated as if they did not exist during - * comparisons. For example, "- < a < b ..." would make '-' an ignorable - * character such that the strings "high-tech" and "hightech" would - * be considered identical. - * <p> - * A <code>ParseException</code> will be thrown for any of the following - * conditions: - * <ul> - * <li>Unquoted punctuation characters in a text argument.</li> - * <li>A relational or reset operator not followed by a text argument</li> - * <li>A reset operator where the text argument is not present in - * the previous rule string section.</li> - * </ul> - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Tom Tromey (tromey@cygnus.com) - * @author Guilhem Lavaux (guilhem@kaffe.org) - */ -public class RuleBasedCollator extends Collator -{ - /** - * This class describes what rank has a character (or a sequence of characters) - * in the lexicographic order. Each element in a rule has a collation element. - */ - static final class CollationElement - { - String key; - int primary; - short secondary; - short tertiary; - short equality; - boolean ignore; - String expansion; - - CollationElement(String key, int primary, short secondary, short tertiary, - short equality, String expansion, boolean ignore) - { - this.key = key; - this.primary = primary; - this.secondary = secondary; - this.tertiary = tertiary; - this.equality = equality; - this.ignore = ignore; - this.expansion = expansion; - } - - int getValue() - { - return (primary << 16) + (secondary << 8) + tertiary; - } - } - - /** - * Basic collation instruction (internal format) to build the series of - * collation elements. It contains an instruction which specifies the new - * state of the generator. The sequence of instruction should not contain - * RESET (it is used by - * {@link #mergeRules(int,java.lang.String,java.util.ArrayList,java.util.ArrayList)}) - * as a temporary state while merging two sets of instructions. - */ - static final class CollationSorter - { - static final int GREATERP = 0; - static final int GREATERS = 1; - static final int GREATERT = 2; - static final int EQUAL = 3; - static final int RESET = 4; - static final int INVERSE_SECONDARY = 5; - - int comparisonType; - String textElement; - int hashText; - int offset; - boolean ignore; - - String expansionOrdering; - } - - /** - * This the the original rule string. - */ - private String rules; - - /** - * This is the table of collation element values - */ - private Object[] ce_table; - - /** - * Quick-prefix finder. - */ - HashMap prefix_tree; - - /** - * This is the value of the last sequence entered into - * <code>ce_table</code>. It is used to compute the - * ordering value of unspecified character. - */ - private int last_primary_value; - - /** - * This is the value of the last secondary sequence of the - * primary 0, entered into - * <code>ce_table</code>. It is used to compute the - * ordering value of an unspecified accented character. - */ - private int last_tertiary_value; - - /** - * This variable is true if accents need to be sorted - * in the other direction. - */ - private boolean inverseAccentComparison; - - /** - * This collation element is special to unknown sequence. - * The JDK uses it to mark and sort the characters which has - * no collation rules. - */ - static final CollationElement SPECIAL_UNKNOWN_SEQ = - new CollationElement("", (short) 32767, (short) 0, (short) 0, - (short) 0, null, false); - - /** - * This method initializes a new instance of <code>RuleBasedCollator</code> - * with the specified collation rules. Note that an application normally - * obtains an instance of <code>RuleBasedCollator</code> by calling the - * <code>getInstance</code> method of <code>Collator</code>. That method - * automatically loads the proper set of rules for the desired locale. - * - * @param rules The collation rule string. - * - * @exception ParseException If the rule string contains syntax errors. - */ - public RuleBasedCollator(String rules) throws ParseException - { - if (rules.equals("")) - throw new ParseException("empty rule set", 0); - - this.rules = rules; - - buildCollationVector(parseString(rules)); - buildPrefixAccess(); - } - - /** - * This method returns the number of common characters at the beginning - * of the string of the two parameters. - * - * @param prefix A string considered as a prefix to test against - * the other string. - * @param s A string to test the prefix against. - * @return The number of common characters. - */ - static int findPrefixLength(String prefix, String s) - { - int index; - int len = prefix.length(); - - for (index = 0; index < len && index < s.length(); ++index) - { - if (prefix.charAt(index) != s.charAt(index)) - return index; - } - - - return index; - } - - /** - * Here we are merging two sets of sorting instructions: 'patch' into 'main'. This methods - * checks whether it is possible to find an anchor point for the rules to be merged and - * then insert them at that precise point. - * - * @param offset Offset in the string containing rules of the beginning of the rules - * being merged in. - * @param starter Text of the rules being merged. - * @param main Repository of all already parsed rules. - * @param patch Rules to be merged into the repository. - * @throws ParseException if it is impossible to find an anchor point for the new rules. - */ - private void mergeRules(int offset, String starter, ArrayList main, ArrayList patch) - throws ParseException - { - int insertion_point = -1; - int max_length = 0; - - /* We must check that no rules conflict with another already present. If it - * is the case delete the old rule. - */ - - /* For the moment good old O(N^2) algorithm. - */ - for (int i = 0; i < patch.size(); i++) - { - int j = 0; - - while (j < main.size()) - { - CollationSorter rule1 = (CollationSorter) patch.get(i); - CollationSorter rule2 = (CollationSorter) main.get(j); - - if (rule1.textElement.equals(rule2.textElement)) - main.remove(j); - else - j++; - } - } - - // Find the insertion point... O(N) - for (int i = 0; i < main.size(); i++) - { - CollationSorter sorter = (CollationSorter) main.get(i); - int length = findPrefixLength(starter, sorter.textElement); - - if (length > max_length) - { - max_length = length; - insertion_point = i+1; - } - } - - if (insertion_point < 0) - throw new ParseException("no insertion point found for " + starter, offset); - - if (max_length < starter.length()) - { - /* - * We need to expand the first entry. It must be sorted - * like if it was the reference key itself (like the spec - * said. So the first entry is special: the element is - * replaced by the specified text element for the sorting. - * This text replace the old one for comparisons. However - * to preserve the behaviour we replace the first key (corresponding - * to the found prefix) by a new code rightly ordered in the - * sequence. The rest of the subsequence must be appended - * to the end of the sequence. - */ - CollationSorter sorter = (CollationSorter) patch.get(0); - CollationSorter expansionPrefix = - (CollationSorter) main.get(insertion_point-1); - - sorter.expansionOrdering = starter.substring(max_length); // Skip the first good prefix element - - main.add(insertion_point, sorter); - - /* - * This is a new set of rules. Append to the list. - */ - patch.remove(0); - insertion_point++; - } - - // Now insert all elements of patch at the insertion point. - for (int i = 0; i < patch.size(); i++) - main.add(i+insertion_point, patch.get(i)); - } - - /** - * This method parses a string and build a set of sorting instructions. The parsing - * may only be partial on the case the rules are to be merged sometime later. - * - * @param stop_on_reset If this parameter is true then the parser stops when it - * encounters a reset instruction. In the other case, it tries to parse the subrules - * and merged it in the same repository. - * @param v Output vector for the set of instructions. - * @param base_offset Offset in the string to begin parsing. - * @param rules Rules to be parsed. - * @return -1 if the parser reached the end of the string, an integer representing the - * offset in the string at which it stopped parsing. - * @throws ParseException if something turned wrong during the parsing. To get details - * decode the message. - */ - private int subParseString(boolean stop_on_reset, ArrayList v, - int base_offset, String rules) - throws ParseException - { - boolean ignoreChars = (base_offset == 0); - int operator = -1; - StringBuffer sb = new StringBuffer(); - boolean doubleQuote = false; - boolean eatingChars = false; - boolean nextIsModifier = false; - boolean isModifier = false; - int i; - -main_parse_loop: - for (i = 0; i < rules.length(); i++) - { - char c = rules.charAt(i); - int type = -1; - - if (!eatingChars && - ((c >= 0x09 && c <= 0x0D) || (c == 0x20))) - continue; - - isModifier = nextIsModifier; - nextIsModifier = false; - - if (eatingChars && c != '\'') - { - doubleQuote = false; - sb.append(c); - continue; - } - if (doubleQuote && eatingChars) - { - sb.append(c); - doubleQuote = false; - continue; - } - - switch (c) - { - case '!': - throw new ParseException - ("Modifier '!' is not yet supported by Classpath", i + base_offset); - case '<': - type = CollationSorter.GREATERP; - break; - case ';': - type = CollationSorter.GREATERS; - break; - case ',': - type = CollationSorter.GREATERT; - break; - case '=': - type = CollationSorter.EQUAL; - break; - case '\'': - eatingChars = !eatingChars; - doubleQuote = true; - break; - case '@': - if (ignoreChars) - throw new ParseException - ("comparison list has not yet been started. You may only use" - + "(<,;=&)", i + base_offset); - // Inverse the order of secondaries from now on. - nextIsModifier = true; - type = CollationSorter.INVERSE_SECONDARY; - break; - case '&': - type = CollationSorter.RESET; - if (stop_on_reset) - break main_parse_loop; - break; - default: - if (operator < 0) - throw new ParseException - ("operator missing at " + (i + base_offset), i + base_offset); - if (! eatingChars - && ((c >= 0x21 && c <= 0x2F) - || (c >= 0x3A && c <= 0x40) - || (c >= 0x5B && c <= 0x60) - || (c >= 0x7B && c <= 0x7E))) - throw new ParseException - ("unquoted punctuation character '" + c + "'", i + base_offset); - - //type = ignoreChars ? CollationSorter.IGNORE : -1; - sb.append(c); - break; - } - - if (type < 0) - continue; - - if (operator < 0) - { - operator = type; - continue; - } - - if (sb.length() == 0 && !isModifier) - throw new ParseException - ("text element empty at " + (i+base_offset), i+base_offset); - - if (operator == CollationSorter.RESET) - { - /* Reposition in the sorting list at the position - * indicated by the text element. - */ - String subrules = rules.substring(i); - ArrayList sorted_rules = new ArrayList(); - int idx; - - // Parse the subrules but do not iterate through all - // sublist. This is the priviledge of the first call. - idx = subParseString(true, sorted_rules, base_offset+i, subrules); - - // Merge new parsed rules into the list. - mergeRules(base_offset+i, sb.toString(), v, sorted_rules); - sb.setLength(0); - - // Reset state to none. - operator = -1; - type = -1; - // We have found a new subrule at 'idx' but it has not been parsed. - if (idx >= 0) - { - i += idx-1; - continue main_parse_loop; - } - else - // No more rules. - break main_parse_loop; - } - - CollationSorter sorter = new CollationSorter(); - - if (operator == CollationSorter.GREATERP) - ignoreChars = false; - - sorter.comparisonType = operator; - sorter.textElement = sb.toString(); - sorter.hashText = sorter.textElement.hashCode(); - sorter.offset = base_offset+rules.length(); - sorter.ignore = ignoreChars; - sb.setLength(0); - - v.add(sorter); - operator = type; - } - - if (operator >= 0) - { - CollationSorter sorter = new CollationSorter(); - int pos = rules.length() + base_offset; - - if ((sb.length() != 0 && nextIsModifier) - || (sb.length() == 0 && !nextIsModifier && !eatingChars)) - throw new ParseException("text element empty at " + pos, pos); - - if (operator == CollationSorter.GREATERP) - ignoreChars = false; - - sorter.comparisonType = operator; - sorter.textElement = sb.toString(); - sorter.hashText = sorter.textElement.hashCode(); - sorter.offset = base_offset+pos; - sorter.ignore = ignoreChars; - v.add(sorter); - } - - if (i == rules.length()) - return -1; - else - return i; - } - - /** - * This method creates a copy of this object. - * - * @return A copy of this object. - */ - public Object clone() - { - return super.clone(); - } - - /** - * This method completely parses a string 'rules' containing sorting rules. - * - * @param rules String containing the rules to be parsed. - * @return A set of sorting instructions stored in a Vector. - * @throws ParseException if something turned wrong during the parsing. To get details - * decode the message. - */ - private ArrayList parseString(String rules) - throws ParseException - { - ArrayList v = new ArrayList(); - - // result of the first subParseString is not absolute (may be -1 or a - // positive integer). But we do not care. - subParseString(false, v, 0, rules); - - return v; - } - - /** - * This method uses the sorting instructions built by {@link #parseString} - * to build collation elements which can be directly used to sort strings. - * - * @param parsedElements Parsed instructions stored in a ArrayList. - * @throws ParseException if the order of the instructions are not valid. - */ - private void buildCollationVector(ArrayList parsedElements) - throws ParseException - { - int primary_seq = 0; - int last_tertiary_seq = 0; - short secondary_seq = 0; - short tertiary_seq = 0; - short equality_seq = 0; - boolean inverseComparisons = false; - final boolean DECREASING = false; - final boolean INCREASING = true; - boolean secondaryType = INCREASING; - ArrayList v = new ArrayList(); - - // elts is completely sorted. -element_loop: - for (int i = 0; i < parsedElements.size(); i++) - { - CollationSorter elt = (CollationSorter) parsedElements.get(i); - boolean ignoreChar = false; - - switch (elt.comparisonType) - { - case CollationSorter.GREATERP: - primary_seq++; - if (inverseComparisons) - { - secondary_seq = Short.MAX_VALUE; - secondaryType = DECREASING; - } - else - { - secondary_seq = 0; - secondaryType = INCREASING; - } - tertiary_seq = 0; - equality_seq = 0; - inverseComparisons = false; - break; - case CollationSorter.GREATERS: - if (secondaryType == DECREASING) - secondary_seq--; - else - secondary_seq++; - tertiary_seq = 0; - equality_seq = 0; - break; - case CollationSorter.INVERSE_SECONDARY: - inverseComparisons = true; - continue element_loop; - case CollationSorter.GREATERT: - tertiary_seq++; - if (primary_seq == 0) - last_tertiary_seq = tertiary_seq; - equality_seq = 0; - break; - case CollationSorter.EQUAL: - equality_seq++; - break; - case CollationSorter.RESET: - throw new ParseException - ("Invalid reached state 'RESET'. Internal error", elt.offset); - default: - throw new ParseException - ("Invalid unknown state '" + elt.comparisonType + "'", elt.offset); - } - - v.add(new CollationElement(elt.textElement, primary_seq, - secondary_seq, tertiary_seq, - equality_seq, elt.expansionOrdering, elt.ignore)); - } - - this.inverseAccentComparison = inverseComparisons; - - ce_table = v.toArray(); - - last_primary_value = primary_seq+1; - last_tertiary_value = last_tertiary_seq+1; - } - - /** - * Build a tree where all keys are the texts of collation elements and data is - * the collation element itself. The tree is used when extracting all prefix - * for a given text. - */ - private void buildPrefixAccess() - { - prefix_tree = new HashMap(); - - for (int i = 0; i < ce_table.length; i++) - { - CollationElement e = (CollationElement) ce_table[i]; - - prefix_tree.put(e.key, e); - } - } - - /** - * This method returns an integer which indicates whether the first - * specified <code>String</code> is less than, greater than, or equal to - * the second. The value depends not only on the collation rules in - * effect, but also the strength and decomposition settings of this object. - * - * @param source The first <code>String</code> to compare. - * @param target A second <code>String</code> to compare to the first. - * - * @return A negative integer if source < target, a positive integer - * if source > target, or 0 if source == target. - */ - public int compare(String source, String target) - { - CollationElementIterator cs, ct; - CollationElement ord1block = null; - CollationElement ord2block = null; - boolean advance_block_1 = true; - boolean advance_block_2 = true; - - cs = getCollationElementIterator(source); - ct = getCollationElementIterator(target); - - for(;;) - { - int ord1; - int ord2; - - /* - * We have to check whether the characters are ignorable. - * If it is the case then forget them. - */ - if (advance_block_1) - { - ord1block = cs.nextBlock(); - if (ord1block != null && ord1block.ignore) - continue; - } - - if (advance_block_2) - { - ord2block = ct.nextBlock(); - if (ord2block != null && ord2block.ignore) - { - advance_block_1 = false; - continue; - } - } - else - advance_block_2 = true; - - if (!advance_block_1) - advance_block_1 = true; - - if (ord1block != null) - ord1 = ord1block.getValue(); - else - { - if (ord2block == null) - return 0; - return -1; - } - - if (ord2block == null) - return 1; - - ord2 = ord2block.getValue(); - - // We know chars are totally equal, so skip - if (ord1 == ord2) - { - if (getStrength() == IDENTICAL) - if (!ord1block.key.equals(ord2block.key)) - return ord1block.key.compareTo(ord2block.key); - continue; - } - - // Check for primary strength differences - int prim1 = CollationElementIterator.primaryOrder(ord1); - int prim2 = CollationElementIterator.primaryOrder(ord2); - - if (prim1 == 0 && getStrength() < TERTIARY) - { - advance_block_2 = false; - continue; - } - else if (prim2 == 0 && getStrength() < TERTIARY) - { - advance_block_1 = false; - continue; - } - - if (prim1 < prim2) - return -1; - else if (prim1 > prim2) - return 1; - else if (getStrength() == PRIMARY) - continue; - - // Check for secondary strength differences - int sec1 = CollationElementIterator.secondaryOrder(ord1); - int sec2 = CollationElementIterator.secondaryOrder(ord2); - - if (sec1 < sec2) - return -1; - else if (sec1 > sec2) - return 1; - else if (getStrength() == SECONDARY) - continue; - - // Check for tertiary differences - int tert1 = CollationElementIterator.tertiaryOrder(ord1); - int tert2 = CollationElementIterator.tertiaryOrder(ord2); - - if (tert1 < tert2) - return -1; - else if (tert1 > tert2) - return 1; - else if (getStrength() == TERTIARY) - continue; - - // Apparently JDK does this (at least for my test case). - return ord1block.key.compareTo(ord2block.key); - } - } - - /** - * This method tests this object for equality against the specified - * object. This will be true if and only if the specified object is - * another reference to this object. - * - * @param obj The <code>Object</code> to compare against this object. - * - * @return <code>true</code> if the specified object is equal to this object, - * <code>false</code> otherwise. - */ - public boolean equals(Object obj) - { - if (obj == this) - return true; - else - return false; - } - - /** - * This method builds a default collation element without invoking - * the database created from the rules passed to the constructor. - * - * @param c Character which needs a collation element. - * @return A valid brand new CollationElement instance. - */ - CollationElement getDefaultElement(char c) - { - int v; - - // Preliminary support for generic accent sorting inversion (I don't know if all - // characters in the range should be sorted backward). This is the place - // to fix this if needed. - if (inverseAccentComparison && (c >= 0x02B9 && c <= 0x0361)) - v = 0x0361 - ((int) c - 0x02B9); - else - v = (short) c; - return new CollationElement("" + c, last_primary_value + v, - (short) 0, (short) 0, (short) 0, null, false); - } - - /** - * This method builds a default collation element for an accented character - * without invoking the database created from the rules passed to the constructor. - * - * @param c Character which needs a collation element. - * @return A valid brand new CollationElement instance. - */ - CollationElement getDefaultAccentedElement(char c) - { - int v; - - // Preliminary support for generic accent sorting inversion (I don't know if all - // characters in the range should be sorted backward). This is the place - // to fix this if needed. - if (inverseAccentComparison && (c >= 0x02B9 && c <= 0x0361)) - v = 0x0361 - ((int) c - 0x02B9); - else - v = (short) c; - return new CollationElement("" + c, (short) 0, - (short) 0, (short) (last_tertiary_value + v), (short) 0, null, false); - } - - /** - * This method returns an instance for <code>CollationElementIterator</code> - * for the specified <code>String</code> under the collation rules for this - * object. - * - * @param source The <code>String</code> to return the - * <code>CollationElementIterator</code> instance for. - * - * @return A <code>CollationElementIterator</code> for the specified - * <code>String</code>. - */ - public CollationElementIterator getCollationElementIterator(String source) - { - return new CollationElementIterator(this, source); - } - - /** - * This method returns an instance of <code>CollationElementIterator</code> - * for the <code>String</code> represented by the specified - * <code>CharacterIterator</code>. - * - * @param source The <code>CharacterIterator</code> with the desired <code>String</code>. - * - * @return A <code>CollationElementIterator</code> for the specified <code>String</code>. - */ - public CollationElementIterator getCollationElementIterator(CharacterIterator source) - { - StringBuffer expand = new StringBuffer(""); - - // Right now we assume that we will read from the beginning of the string. - for (char c = source.first(); - c != CharacterIterator.DONE; - c = source.next()) - decomposeCharacter(c, expand); - - return getCollationElementIterator(expand.toString()); - } - - /** - * This method returns an instance of <code>CollationKey</code> for the - * specified <code>String</code>. The object returned will have a - * more efficient mechanism for its comparison function that could - * provide speed benefits if multiple comparisons are performed, such - * as during a sort. - * - * @param source The <code>String</code> to create a <code>CollationKey</code> for. - * - * @return A <code>CollationKey</code> for the specified <code>String</code>. - */ - public CollationKey getCollationKey(String source) - { - CollationElementIterator cei = getCollationElementIterator(source); - ArrayList vect = new ArrayList(); - - int ord = cei.next(); - cei.reset(); //set to start of string - - while (ord != CollationElementIterator.NULLORDER) - { - // If the primary order is null, it means this is an ignorable - // character. - if (CollationElementIterator.primaryOrder(ord) == 0) - { - ord = cei.next(); - continue; - } - switch (getStrength()) - { - case PRIMARY: - ord = CollationElementIterator.primaryOrder(ord); - break; - - case SECONDARY: - ord = CollationElementIterator.primaryOrder(ord) << 8; - ord |= CollationElementIterator.secondaryOrder(ord); - - default: - break; - } - - vect.add(new Integer(ord)); - ord = cei.next(); //increment to next key - } - - Object[] objarr = vect.toArray(); - byte[] key = new byte[objarr.length * 4]; - - for (int i = 0; i < objarr.length; i++) - { - int j = ((Integer) objarr[i]).intValue(); - key [i * 4] = (byte) ((j & 0xFF000000) >> 24); - key [i * 4 + 1] = (byte) ((j & 0x00FF0000) >> 16); - key [i * 4 + 2] = (byte) ((j & 0x0000FF00) >> 8); - key [i * 4 + 3] = (byte) (j & 0x000000FF); - } - - return new CollationKey(this, source, key); - } - - /** - * This method returns a <code>String</code> containing the collation rules - * for this object. - * - * @return The collation rules for this object. - */ - public String getRules() - { - return rules; - } - - /** - * This method returns a hash value for this object. - * - * @return A hash value for this object. - */ - public int hashCode() - { - return System.identityHashCode(this); - } -} diff --git a/libjava/java/text/StringCharacterIterator.java b/libjava/java/text/StringCharacterIterator.java deleted file mode 100644 index e3adc857e51..00000000000 --- a/libjava/java/text/StringCharacterIterator.java +++ /dev/null @@ -1,356 +0,0 @@ -/* StringCharacterIterator.java -- Iterate over a character range in a string - Copyright (C) 1998, 1999, 2001, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.text; - -/** - * This class iterates over a range of characters in a <code>String</code>. - * For a given range of text, a beginning and ending index, - * as well as a current index are defined. These values can be queried - * by the methods in this interface. Additionally, various methods allow - * the index to be set. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - * @author Tom Tromey (tromey@cygnus.com) - */ -public final class StringCharacterIterator implements CharacterIterator -{ - /** - * This is the string to iterate over - */ - private String text; - - /** - * This is the value of the start position of the text range. - */ - private int begin; - - /** - * This is the value of the ending position of the text range. - */ - private int end; - - /** - * This is the current value of the scan index. - */ - private int index; - - /** - * This method initializes a new instance of - * <code>StringCharacterIterator</code> to iterate over the entire - * text of the specified <code>String</code>. The initial index - * value will be set to the first character in the string. - * - * @param text The <code>String</code> to iterate through. - */ - public StringCharacterIterator (String text) - { - this (text, 0, text.length (), 0); - } - - /*************************************************************************/ - - /** - * This method initializes a new instance of - * <code>StringCharacterIterator</code> to iterate over the entire - * text of the specified <code>String</code>. The initial index - * value will be set to the specified value. - * - * @param text The <code>String</code> to iterate through. - * @param index The initial index position. - */ - public StringCharacterIterator (String text, int index) - { - this (text, 0, text.length (), index); - } - - /*************************************************************************/ - - /** - * This method initializes a new instance of - * <code>StringCharacterIterator</code> that iterates over the text - * in a subrange of the specified <code>String</code>. The - * beginning and end of the range are specified by the caller, as is - * the initial index position. - * - * @param text The <code>String</code> to iterate through. - * @param begin The beginning position in the character range. - * @param end The ending position in the character range. - * @param index The initial index position. - * - * @param IllegalArgumentException If any of the range values are - * invalid. - */ - public StringCharacterIterator (String text, int begin, int end, int index) - { - int len = text.length (); - - if ((begin < 0) || (begin > len)) - throw new IllegalArgumentException ("Bad begin position"); - - if ((end < begin) || (end > len)) - throw new IllegalArgumentException ("Bad end position"); - - if ((index < begin) || (index > end)) - throw new IllegalArgumentException ("Bad initial index position"); - - this.text = text; - this.begin = begin; - this.end = end; - this.index = index; - } - - /** - * This is a package level constructor that copies the text out of - * an existing StringCharacterIterator and resets the beginning and - * ending index. - * - * @param scci The StringCharacterIterator to copy the info from - * @param begin The beginning index of the range we are interested in. - * @param end The ending index of the range we are interested in. - */ - StringCharacterIterator (StringCharacterIterator sci, int begin, int end) - { - this (sci.text, begin, end, begin); - } - - /** - * This method returns the character at the current index position - * - * @return The character at the current index position. - */ - public char current () - { - return (index < end) ? text.charAt (index) : DONE; - } - - /*************************************************************************/ - - /** - * This method increments the current index and then returns the - * character at the new index value. If the index is already at - * <code>getEndIndex () - 1</code>, it will not be incremented. - * - * @return The character at the position of the incremented index - * value, or <code>DONE</code> if the index has reached - * getEndIndex () - 1. - */ - public char next () - { - if (index == end) - return DONE; - - ++index; - return current (); - } - - /*************************************************************************/ - - /** - * This method decrements the current index and then returns the - * character at the new index value. If the index value is already - * at the beginning index, it will not be decremented. - * - * @return The character at the position of the decremented index - * value, or <code>DONE</code> if index was already equal to the - * beginning index value. - */ - public char previous () - { - if (index == begin) - return DONE; - - --index; - return current (); - } - - /*************************************************************************/ - - /** - * This method sets the index value to the beginning of the range and returns - * the character there. - * - * @return The character at the beginning of the range, or - * <code>DONE</code> if the range is empty. - */ - public char first () - { - index = begin; - return current (); - } - - /*************************************************************************/ - - /** - * This method sets the index value to <code>getEndIndex () - 1</code> and - * returns the character there. If the range is empty, then the index value - * will be set equal to the beginning index. - * - * @return The character at the end of the range, or - * <code>DONE</code> if the range is empty. - */ - public char last () - { - if (end == begin) - return DONE; - - index = end - 1; - return current (); - } - - /*************************************************************************/ - - /** - * This method returns the current value of the index. - * - * @return The current index value - */ - public int getIndex () - { - return index; - } - - /*************************************************************************/ - - /** - * This method sets the value of the index to the specified value, then - * returns the character at that position. - * - * @param index The new index value. - * - * @return The character at the new index value or <code>DONE</code> - * if the index value is equal to <code>getEndIndex</code>. - * - * @exception IllegalArgumentException If the specified index is not valid - */ - public char setIndex (int index) - { - if ((index < begin) || (index > end)) - throw new IllegalArgumentException ("Bad index specified"); - - this.index = index; - return current (); - } - - /*************************************************************************/ - - /** - * This method returns the character position of the first character in the - * range. - * - * @return The index of the first character in the range. - */ - public int getBeginIndex () - { - return begin; - } - - /*************************************************************************/ - - /** - * This method returns the character position of the end of the text range. - * This will actually be the index of the first character following the - * end of the range. In the event the text range is empty, this will be - * equal to the first character in the range. - * - * @return The index of the end of the range. - */ - public int getEndIndex () - { - return end; - } - - /*************************************************************************/ - - /** - * This method creates a copy of this <code>CharacterIterator</code>. - * - * @return A copy of this <code>CharacterIterator</code>. - */ - public Object clone () - { - return new StringCharacterIterator (text, begin, end, index); - } - - /*************************************************************************/ - - /** - * This method tests this object for equality againt the specified - * object. This will be true if and only if the specified object: - * <p> - * <ul> - * <li>is not <code>null</code>.</li> - * <li>is an instance of <code>StringCharacterIterator</code></li> - * <li>has the same text as this object</li> - * <li>has the same beginning, ending, and current index as this object.</li> - * </ul> - * - * @param obj The object to test for equality against. - * - * @return <code>true</code> if the specified object is equal to this - * object, <code>false</code> otherwise. - */ - public boolean equals (Object obj) - { - if (! (obj instanceof StringCharacterIterator)) - return false; - - StringCharacterIterator sci = (StringCharacterIterator) obj; - - return (begin == sci.begin - && end == sci.end - && index == sci.index - && text.equals (sci.text)); - } - - /*************************************************************************/ - - /** - * This method allows other classes in java.text to change the value - * of the underlying text being iterated through. - * - * @param text The new <code>String</code> to iterate through. - */ - public void setText (String text) - { - this.text = text; - this.begin = 0; - this.end = text.length (); - this.index = 0; - } -} diff --git a/libjava/java/util/AbstractCollection.java b/libjava/java/util/AbstractCollection.java deleted file mode 100644 index 00ee23ebd43..00000000000 --- a/libjava/java/util/AbstractCollection.java +++ /dev/null @@ -1,470 +0,0 @@ -/* AbstractCollection.java -- Abstract implementation of most of Collection - Copyright (C) 1998, 2000, 2001, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util; - -import java.lang.reflect.Array; - -/** - * A basic implementation of most of the methods in the Collection interface to - * make it easier to create a collection. To create an unmodifiable Collection, - * just subclass AbstractCollection and provide implementations of the - * iterator() and size() methods. The Iterator returned by iterator() need only - * provide implementations of hasNext() and next() (that is, it may throw an - * UnsupportedOperationException if remove() is called). To create a modifiable - * Collection, you must in addition provide an implementation of the - * add(Object) method and the Iterator returned by iterator() must provide an - * implementation of remove(). Other methods should be overridden if the - * backing data structure allows for a more efficient implementation. The - * precise implementation used by AbstractCollection is documented, so that - * subclasses can tell which methods could be implemented more efficiently. - * <p> - * - * The programmer should provide a no-argument constructor, and one that - * accepts another Collection, as recommended by the Collection interface. - * Unfortunately, there is no way to enforce this in Java. - * - * @author Original author unknown - * @author Bryce McKinlay - * @author Eric Blake (ebb9@email.byu.edu) - * @see Collection - * @see AbstractSet - * @see AbstractList - * @since 1.2 - * @status updated to 1.4 - */ -public abstract class AbstractCollection implements Collection -{ - /** - * The main constructor, for use by subclasses. - */ - protected AbstractCollection() - { - } - - /** - * Return an Iterator over this collection. The iterator must provide the - * hasNext and next methods and should in addition provide remove if the - * collection is modifiable. - * - * @return an iterator - */ - public abstract Iterator iterator(); - - /** - * Return the number of elements in this collection. If there are more than - * Integer.MAX_VALUE elements, return Integer.MAX_VALUE. - * - * @return the size - */ - public abstract int size(); - - /** - * Add an object to the collection (optional operation). This implementation - * always throws an UnsupportedOperationException - it should be - * overridden if the collection is to be modifiable. If the collection - * does not accept duplicates, simply return false. Collections may specify - * limitations on what may be added. - * - * @param o the object to add - * @return true if the add operation caused the Collection to change - * @throws UnsupportedOperationException if the add operation is not - * supported on this collection - * @throws NullPointerException if the collection does not support null - * @throws ClassCastException if the object is of the wrong type - * @throws IllegalArgumentException if some aspect of the object prevents - * it from being added - */ - public boolean add(Object o) - { - throw new UnsupportedOperationException(); - } - - /** - * Add all the elements of a given collection to this collection (optional - * operation). This implementation obtains an Iterator over the given - * collection and iterates over it, adding each element with the - * add(Object) method (thus this method will fail with an - * UnsupportedOperationException if the add method does). The behavior is - * unspecified if the specified collection is modified during the iteration, - * including the special case of trying addAll(this) on a non-empty - * collection. - * - * @param c the collection to add the elements of to this collection - * @return true if the add operation caused the Collection to change - * @throws UnsupportedOperationException if the add operation is not - * supported on this collection - * @throws NullPointerException if the specified collection is null - * @throws ClassCastException if the type of any element in c is - * not a valid type for addition. - * @throws IllegalArgumentException if some aspect of any element - * in c prevents it being added. - * @throws NullPointerException if any element in c is null and this - * collection doesn't allow null values. - * @see #add(Object) - */ - public boolean addAll(Collection c) - { - Iterator itr = c.iterator(); - boolean modified = false; - int pos = c.size(); - while (--pos >= 0) - modified |= add(itr.next()); - return modified; - } - - /** - * Remove all elements from the collection (optional operation). This - * implementation obtains an iterator over the collection and calls next - * and remove on it repeatedly (thus this method will fail with an - * UnsupportedOperationException if the Iterator's remove method does) - * until there are no more elements to remove. - * Many implementations will have a faster way of doing this. - * - * @throws UnsupportedOperationException if the Iterator returned by - * iterator does not provide an implementation of remove - * @see Iterator#remove() - */ - public void clear() - { - Iterator itr = iterator(); - int pos = size(); - while (--pos >= 0) - { - itr.next(); - itr.remove(); - } - } - - /** - * Test whether this collection contains a given object. That is, if the - * collection has an element e such that (o == null ? e == null : - * o.equals(e)). This implementation obtains an iterator over the collection - * and iterates over it, testing each element for equality with the given - * object. If it is equal, true is returned. Otherwise false is returned when - * the end of the collection is reached. - * - * @param o the object to remove from this collection - * @return true if this collection contains an object equal to o - */ - public boolean contains(Object o) - { - Iterator itr = iterator(); - int pos = size(); - while (--pos >= 0) - if (equals(o, itr.next())) - return true; - return false; - } - - /** - * Tests whether this collection contains all the elements in a given - * collection. This implementation iterates over the given collection, - * testing whether each element is contained in this collection. If any one - * is not, false is returned. Otherwise true is returned. - * - * @param c the collection to test against - * @return true if this collection contains all the elements in the given - * collection - * @throws NullPointerException if the given collection is null - * @see #contains(Object) - */ - public boolean containsAll(Collection c) - { - Iterator itr = c.iterator(); - int pos = c.size(); - while (--pos >= 0) - if (!contains(itr.next())) - return false; - return true; - } - - /** - * Test whether this collection is empty. This implementation returns - * size() == 0. - * - * @return true if this collection is empty. - * @see #size() - */ - public boolean isEmpty() - { - return size() == 0; - } - - /** - * Remove a single instance of an object from this collection (optional - * operation). That is, remove one element e such that - * <code>(o == null ? e == null : o.equals(e))</code>, if such an element - * exists. This implementation obtains an iterator over the collection - * and iterates over it, testing each element for equality with the given - * object. If it is equal, it is removed by the iterator's remove method - * (thus this method will fail with an UnsupportedOperationException if - * the Iterator's remove method does). After the first element has been - * removed, true is returned; if the end of the collection is reached, false - * is returned. - * - * @param o the object to remove from this collection - * @return true if the remove operation caused the Collection to change, or - * equivalently if the collection did contain o. - * @throws UnsupportedOperationException if this collection's Iterator - * does not support the remove method - * @see Iterator#remove() - */ - public boolean remove(Object o) - { - Iterator itr = iterator(); - int pos = size(); - while (--pos >= 0) - if (equals(o, itr.next())) - { - itr.remove(); - return true; - } - return false; - } - - /** - * Remove from this collection all its elements that are contained in a given - * collection (optional operation). This implementation iterates over this - * collection, and for each element tests if it is contained in the given - * collection. If so, it is removed by the Iterator's remove method (thus - * this method will fail with an UnsupportedOperationException if the - * Iterator's remove method does). - * - * @param c the collection to remove the elements of - * @return true if the remove operation caused the Collection to change - * @throws UnsupportedOperationException if this collection's Iterator - * does not support the remove method - * @throws NullPointerException if the collection, c, is null. - * @see Iterator#remove() - */ - public boolean removeAll(Collection c) - { - return removeAllInternal(c); - } - - /** - * Remove from this collection all its elements that are contained in a given - * collection (optional operation). This implementation iterates over this - * collection, and for each element tests if it is contained in the given - * collection. If so, it is removed by the Iterator's remove method (thus - * this method will fail with an UnsupportedOperationException if the - * Iterator's remove method does). This method is necessary for ArrayList, - * which cannot publicly override removeAll but can optimize this call. - * - * @param c the collection to remove the elements of - * @return true if the remove operation caused the Collection to change - * @throws UnsupportedOperationException if this collection's Iterator - * does not support the remove method - * @throws NullPointerException if the collection, c, is null. - * @see Iterator#remove() - */ - // Package visible for use throughout java.util. - boolean removeAllInternal(Collection c) - { - Iterator itr = iterator(); - boolean modified = false; - int pos = size(); - while (--pos >= 0) - if (c.contains(itr.next())) - { - itr.remove(); - modified = true; - } - return modified; - } - - /** - * Remove from this collection all its elements that are not contained in a - * given collection (optional operation). This implementation iterates over - * this collection, and for each element tests if it is contained in the - * given collection. If not, it is removed by the Iterator's remove method - * (thus this method will fail with an UnsupportedOperationException if - * the Iterator's remove method does). - * - * @param c the collection to retain the elements of - * @return true if the remove operation caused the Collection to change - * @throws UnsupportedOperationException if this collection's Iterator - * does not support the remove method - * @throws NullPointerException if the collection, c, is null. - * @see Iterator#remove() - */ - public boolean retainAll(Collection c) - { - return retainAllInternal(c); - } - - /** - * Remove from this collection all its elements that are not contained in a - * given collection (optional operation). This implementation iterates over - * this collection, and for each element tests if it is contained in the - * given collection. If not, it is removed by the Iterator's remove method - * (thus this method will fail with an UnsupportedOperationException if - * the Iterator's remove method does). This method is necessary for - * ArrayList, which cannot publicly override retainAll but can optimize - * this call. - * - * @param c the collection to retain the elements of - * @return true if the remove operation caused the Collection to change - * @throws UnsupportedOperationException if this collection's Iterator - * does not support the remove method - * @throws NullPointerException if the collection, c, is null. - * @see Iterator#remove() - */ - // Package visible for use throughout java.util. - boolean retainAllInternal(Collection c) - { - Iterator itr = iterator(); - boolean modified = false; - int pos = size(); - while (--pos >= 0) - if (!c.contains(itr.next())) - { - itr.remove(); - modified = true; - } - return modified; - } - - /** - * Return an array containing the elements of this collection. This - * implementation creates an Object array of size size() and then iterates - * over the collection, setting each element of the array from the value - * returned by the iterator. The returned array is safe, and is not backed - * by the collection. - * - * @return an array containing the elements of this collection - */ - public Object[] toArray() - { - Iterator itr = iterator(); - int size = size(); - Object[] a = new Object[size]; - for (int pos = 0; pos < size; pos++) - a[pos] = itr.next(); - return a; - } - - /** - * Copy the collection into a given array if it will fit, or into a - * dynamically created array of the same run-time type as the given array if - * not. If there is space remaining in the array, the first element after the - * end of the collection is set to null (this is only useful if the - * collection is known to contain no null elements, however). This - * implementation first tests whether the given array is large enough to hold - * all the elements of the collection. If not, the reflection API is used to - * allocate a new array of the same run-time type. Next an iterator is - * obtained over the collection and the elements are placed in the array as - * they are returned by the iterator. Finally the first spare element, if - * any, of the array is set to null, and the created array is returned. - * The returned array is safe; it is not backed by the collection. Note that - * null may not mark the last element, if the collection allows null - * elements. - * - * @param a the array to copy into, or of the correct run-time type - * @return the array that was produced - * @throws NullPointerException if the given array is null - * @throws ArrayStoreException if the type of the array precludes holding - * one of the elements of the Collection - */ - public Object[] toArray(Object[] a) - { - int size = size(); - if (a.length < size) - a = (Object[]) Array.newInstance(a.getClass().getComponentType(), - size); - else if (a.length > size) - a[size] = null; - - Iterator itr = iterator(); - for (int pos = 0; pos < size; pos++) - a[pos] = itr.next(); - - return a; - } - - /** - * Creates a String representation of the Collection. The string returned is - * of the form "[a, b, ...]" where a and b etc are the results of calling - * toString on the elements of the collection. This implementation obtains an - * Iterator over the Collection and adds each element to a StringBuffer as it - * is returned by the iterator. - * - * @return a String representation of the Collection - */ - public String toString() - { - Iterator itr = iterator(); - StringBuffer r = new StringBuffer("["); - for (int pos = size(); pos > 0; pos--) - { - r.append(itr.next()); - if (pos > 1) - r.append(", "); - } - r.append("]"); - return r.toString(); - } - - /** - * Compare two objects according to Collection semantics. - * - * @param o1 the first object - * @param o2 the second object - * @return o1 == null ? o2 == null : o1.equals(o2) - */ - // Package visible for use throughout java.util. - // It may be inlined since it is final. - static final boolean equals(Object o1, Object o2) - { - return o1 == null ? o2 == null : o1.equals(o2); - } - - /** - * Hash an object according to Collection semantics. - * - * @param o the object to hash - * @return o1 == null ? 0 : o1.hashCode() - */ - // Package visible for use throughout java.util. - // It may be inlined since it is final. - static final int hashCode(Object o) - { - return o == null ? 0 : o.hashCode(); - } -} diff --git a/libjava/java/util/AbstractList.java b/libjava/java/util/AbstractList.java deleted file mode 100644 index 8a9b6f10d7a..00000000000 --- a/libjava/java/util/AbstractList.java +++ /dev/null @@ -1,1225 +0,0 @@ -/* AbstractList.java -- Abstract implementation of most of List - Copyright (C) 1998, 1999, 2000, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util; - -/** - * A basic implementation of most of the methods in the List interface to make - * it easier to create a List based on a random-access data structure. If - * the list is sequential (such as a linked list), use AbstractSequentialList. - * To create an unmodifiable list, it is only necessary to override the - * size() and get(int) methods (this contrasts with all other abstract - * collection classes which require an iterator to be provided). To make the - * list modifiable, the set(int, Object) method should also be overridden, and - * to make the list resizable, the add(int, Object) and remove(int) methods - * should be overridden too. Other methods should be overridden if the - * backing data structure allows for a more efficient implementation. - * The precise implementation used by AbstractList is documented, so that - * subclasses can tell which methods could be implemented more efficiently. - * <p> - * - * As recommended by Collection and List, the subclass should provide at - * least a no-argument and a Collection constructor. This class is not - * synchronized. - * - * @author Original author unknown - * @author Bryce McKinlay - * @author Eric Blake (ebb9@email.byu.edu) - * @see Collection - * @see List - * @see AbstractSequentialList - * @see AbstractCollection - * @see ListIterator - * @since 1.2 - * @status updated to 1.4 - */ -public abstract class AbstractList extends AbstractCollection implements List -{ - /** - * A count of the number of structural modifications that have been made to - * the list (that is, insertions and removals). Structural modifications - * are ones which change the list size or affect how iterations would - * behave. This field is available for use by Iterator and ListIterator, - * in order to throw a {@link ConcurrentModificationException} in response - * to the next operation on the iterator. This <i>fail-fast</i> behavior - * saves the user from many subtle bugs otherwise possible from concurrent - * modification during iteration. - * <p> - * - * To make lists fail-fast, increment this field by just 1 in the - * <code>add(int, Object)</code> and <code>remove(int)</code> methods. - * Otherwise, this field may be ignored. - */ - protected transient int modCount; - - /** - * The main constructor, for use by subclasses. - */ - protected AbstractList() - { - } - - /** - * Returns the elements at the specified position in the list. - * - * @param index the element to return - * @return the element at that position - * @throws IndexOutOfBoundsException if index < 0 || index >= size() - */ - public abstract Object get(int index); - - /** - * Insert an element into the list at a given position (optional operation). - * This shifts all existing elements from that position to the end one - * index to the right. This version of add has no return, since it is - * assumed to always succeed if there is no exception. This implementation - * always throws UnsupportedOperationException, and must be overridden to - * make a modifiable List. If you want fail-fast iterators, be sure to - * increment modCount when overriding this. - * - * @param index the location to insert the item - * @param o the object to insert - * @throws UnsupportedOperationException if this list does not support the - * add operation - * @throws IndexOutOfBoundsException if index < 0 || index > size() - * @throws ClassCastException if o cannot be added to this list due to its - * type - * @throws IllegalArgumentException if o cannot be added to this list for - * some other reason - * @see #modCount - */ - public void add(int index, Object o) - { - throw new UnsupportedOperationException(); - } - - /** - * Add an element to the end of the list (optional operation). If the list - * imposes restraints on what can be inserted, such as no null elements, - * this should be documented. This implementation calls - * <code>add(size(), o);</code>, and will fail if that version does. - * - * @param o the object to add - * @return true, as defined by Collection for a modified list - * @throws UnsupportedOperationException if this list does not support the - * add operation - * @throws ClassCastException if o cannot be added to this list due to its - * type - * @throws IllegalArgumentException if o cannot be added to this list for - * some other reason - * @see #add(int, Object) - */ - public boolean add(Object o) - { - add(size(), o); - return true; - } - - /** - * Insert the contents of a collection into the list at a given position - * (optional operation). Shift all elements at that position to the right - * by the number of elements inserted. This operation is undefined if - * this list is modified during the operation (for example, if you try - * to insert a list into itself). This implementation uses the iterator of - * the collection, repeatedly calling add(int, Object); this will fail - * if add does. This can often be made more efficient. - * - * @param index the location to insert the collection - * @param c the collection to insert - * @return true if the list was modified by this action, that is, if c is - * non-empty - * @throws UnsupportedOperationException if this list does not support the - * addAll operation - * @throws IndexOutOfBoundsException if index < 0 || index > size() - * @throws ClassCastException if some element of c cannot be added to this - * list due to its type - * @throws IllegalArgumentException if some element of c cannot be added - * to this list for some other reason - * @throws NullPointerException if the specified collection is null - * @see #add(int, Object) - */ - public boolean addAll(int index, Collection c) - { - Iterator itr = c.iterator(); - int size = c.size(); - for (int pos = size; pos > 0; pos--) - add(index++, itr.next()); - return size > 0; - } - - /** - * Clear the list, such that a subsequent call to isEmpty() would return - * true (optional operation). This implementation calls - * <code>removeRange(0, size())</code>, so it will fail unless remove - * or removeRange is overridden. - * - * @throws UnsupportedOperationException if this list does not support the - * clear operation - * @see #remove(int) - * @see #removeRange(int, int) - */ - public void clear() - { - removeRange(0, size()); - } - - /** - * Test whether this list is equal to another object. A List is defined to be - * equal to an object if and only if that object is also a List, and the two - * lists have the same sequence. Two lists l1 and l2 are equal if and only - * if <code>l1.size() == l2.size()</code>, and for every integer n between 0 - * and <code>l1.size() - 1</code> inclusive, <code>l1.get(n) == null ? - * l2.get(n) == null : l1.get(n).equals(l2.get(n))</code>. - * <p> - * - * This implementation returns true if the object is this, or false if the - * object is not a List. Otherwise, it iterates over both lists (with - * iterator()), returning false if two elements compare false or one list - * is shorter, and true if the iteration completes successfully. - * - * @param o the object to test for equality with this list - * @return true if o is equal to this list - * @see Object#equals(Object) - * @see #hashCode() - */ - public boolean equals(Object o) - { - if (o == this) - return true; - if (! (o instanceof List)) - return false; - int size = size(); - if (size != ((List) o).size()) - return false; - - Iterator itr1 = iterator(); - Iterator itr2 = ((List) o).iterator(); - - while (--size >= 0) - if (! equals(itr1.next(), itr2.next())) - return false; - return true; - } - - /** - * Obtains a hash code for this list. In order to obey the general - * contract of the hashCode method of class Object, this value is - * calculated as follows: - * -<pre>hashCode = 1; -Iterator i = list.iterator(); -while (i.hasNext()) -{ - Object obj = i.next(); - hashCode = 31 * hashCode + (obj == null ? 0 : obj.hashCode()); -}</pre> - * - * This ensures that the general contract of Object.hashCode() is adhered to. - * - * @return the hash code of this list - * - * @see Object#hashCode() - * @see #equals(Object) - */ - public int hashCode() - { - int hashCode = 1; - Iterator itr = iterator(); - int pos = size(); - while (--pos >= 0) - hashCode = 31 * hashCode + hashCode(itr.next()); - return hashCode; - } - - /** - * Obtain the first index at which a given object is to be found in this - * list. This implementation follows a listIterator() until a match is found, - * or returns -1 if the list end is reached. - * - * @param o the object to search for - * @return the least integer n such that <code>o == null ? get(n) == null : - * o.equals(get(n))</code>, or -1 if there is no such index - */ - public int indexOf(Object o) - { - ListIterator itr = listIterator(); - int size = size(); - for (int pos = 0; pos < size; pos++) - if (equals(o, itr.next())) - return pos; - return -1; - } - - /** - * Obtain an Iterator over this list, whose sequence is the list order. - * This implementation uses size(), get(int), and remove(int) of the - * backing list, and does not support remove unless the list does. This - * implementation is fail-fast if you correctly maintain modCount. - * Also, this implementation is specified by Sun to be distinct from - * listIterator, although you could easily implement it as - * <code>return listIterator(0)</code>. - * - * @return an Iterator over the elements of this list, in order - * @see #modCount - */ - public Iterator iterator() - { - // Bah, Sun's implementation forbids using listIterator(0). - return new Iterator() - { - private int pos = 0; - private int size = size(); - private int last = -1; - private int knownMod = modCount; - - // This will get inlined, since it is private. - /** - * Checks for modifications made to the list from - * elsewhere while iteration is in progress. - * - * @throws ConcurrentModificationException if the - * list has been modified elsewhere. - */ - private void checkMod() - { - if (knownMod != modCount) - throw new ConcurrentModificationException(); - } - - /** - * Tests to see if there are any more objects to - * return. - * - * @return True if the end of the list has not yet been - * reached. - * @throws ConcurrentModificationException if the - * list has been modified elsewhere. - */ - public boolean hasNext() - { - checkMod(); - return pos < size; - } - - /** - * Retrieves the next object from the list. - * - * @return The next object. - * @throws NoSuchElementException if there are - * no more objects to retrieve. - * @throws ConcurrentModificationException if the - * list has been modified elsewhere. - */ - public Object next() - { - checkMod(); - if (pos == size) - throw new NoSuchElementException(); - last = pos; - return get(pos++); - } - - /** - * Removes the last object retrieved by <code>next()</code> - * from the list, if the list supports object removal. - * - * @throws ConcurrentModificationException if the list - * has been modified elsewhere. - * @throws IllegalStateException if the iterator is positioned - * before the start of the list or the last object has already - * been removed. - * @throws UnsupportedOperationException if the list does - * not support removing elements. - */ - public void remove() - { - checkMod(); - if (last < 0) - throw new IllegalStateException(); - AbstractList.this.remove(last); - pos--; - size--; - last = -1; - knownMod = modCount; - } - }; - } - - /** - * Obtain the last index at which a given object is to be found in this - * list. This implementation grabs listIterator(size()), then searches - * backwards for a match or returns -1. - * - * @return the greatest integer n such that <code>o == null ? get(n) == null - * : o.equals(get(n))</code>, or -1 if there is no such index - */ - public int lastIndexOf(Object o) - { - int pos = size(); - ListIterator itr = listIterator(pos); - while (--pos >= 0) - if (equals(o, itr.previous())) - return pos; - return -1; - } - - /** - * Obtain a ListIterator over this list, starting at the beginning. This - * implementation returns listIterator(0). - * - * @return a ListIterator over the elements of this list, in order, starting - * at the beginning - */ - public ListIterator listIterator() - { - return listIterator(0); - } - - /** - * Obtain a ListIterator over this list, starting at a given position. - * A first call to next() would return the same as get(index), and a - * first call to previous() would return the same as get(index - 1). - * <p> - * - * This implementation uses size(), get(int), set(int, Object), - * add(int, Object), and remove(int) of the backing list, and does not - * support remove, set, or add unless the list does. This implementation - * is fail-fast if you correctly maintain modCount. - * - * @param index the position, between 0 and size() inclusive, to begin the - * iteration from - * @return a ListIterator over the elements of this list, in order, starting - * at index - * @throws IndexOutOfBoundsException if index < 0 || index > size() - * @see #modCount - */ - public ListIterator listIterator(final int index) - { - if (index < 0 || index > size()) - throw new IndexOutOfBoundsException("Index: " + index + ", Size:" - + size()); - - return new ListIterator() - { - private int knownMod = modCount; - private int position = index; - private int lastReturned = -1; - private int size = size(); - - // This will get inlined, since it is private. - /** - * Checks for modifications made to the list from - * elsewhere while iteration is in progress. - * - * @throws ConcurrentModificationException if the - * list has been modified elsewhere. - */ - private void checkMod() - { - if (knownMod != modCount) - throw new ConcurrentModificationException(); - } - - /** - * Tests to see if there are any more objects to - * return. - * - * @return True if the end of the list has not yet been - * reached. - * @throws ConcurrentModificationException if the - * list has been modified elsewhere. - */ - public boolean hasNext() - { - checkMod(); - return position < size; - } - - /** - * Tests to see if there are objects prior to the - * current position in the list. - * - * @return True if objects exist prior to the current - * position of the iterator. - * @throws ConcurrentModificationException if the - * list has been modified elsewhere. - */ - public boolean hasPrevious() - { - checkMod(); - return position > 0; - } - - /** - * Retrieves the next object from the list. - * - * @return The next object. - * @throws NoSuchElementException if there are no - * more objects to retrieve. - * @throws ConcurrentModificationException if the - * list has been modified elsewhere. - */ - public Object next() - { - checkMod(); - if (position == size) - throw new NoSuchElementException(); - lastReturned = position; - return get(position++); - } - - /** - * Retrieves the previous object from the list. - * - * @return The next object. - * @throws NoSuchElementException if there are no - * previous objects to retrieve. - * @throws ConcurrentModificationException if the - * list has been modified elsewhere. - */ - public Object previous() - { - checkMod(); - if (position == 0) - throw new NoSuchElementException(); - lastReturned = --position; - return get(lastReturned); - } - - /** - * Returns the index of the next element in the - * list, which will be retrieved by <code>next()</code> - * - * @return The index of the next element. - * @throws ConcurrentModificationException if the list - * has been modified elsewhere. - */ - public int nextIndex() - { - checkMod(); - return position; - } - - /** - * Returns the index of the previous element in the - * list, which will be retrieved by <code>previous()</code> - * - * @return The index of the previous element. - * @throws ConcurrentModificationException if the list - * has been modified elsewhere. - */ - public int previousIndex() - { - checkMod(); - return position - 1; - } - - /** - * Removes the last object retrieved by <code>next()</code> - * or <code>previous()</code> from the list, if the list - * supports object removal. - * - * @throws IllegalStateException if the iterator is positioned - * before the start of the list or the last object has already - * been removed. - * @throws UnsupportedOperationException if the list does - * not support removing elements. - * @throws ConcurrentModificationException if the list - * has been modified elsewhere. - */ - public void remove() - { - checkMod(); - if (lastReturned < 0) - throw new IllegalStateException(); - AbstractList.this.remove(lastReturned); - size--; - position = lastReturned; - lastReturned = -1; - knownMod = modCount; - } - - /** - * Replaces the last object retrieved by <code>next()</code> - * or <code>previous</code> with o, if the list supports object - * replacement and an add or remove operation has not already - * been performed. - * - * @throws IllegalStateException if the iterator is positioned - * before the start of the list or the last object has already - * been removed. - * @throws UnsupportedOperationException if the list doesn't support - * the addition or removal of elements. - * @throws ClassCastException if the type of o is not a valid type - * for this list. - * @throws IllegalArgumentException if something else related to o - * prevents its addition. - * @throws ConcurrentModificationException if the list - * has been modified elsewhere. - */ - public void set(Object o) - { - checkMod(); - if (lastReturned < 0) - throw new IllegalStateException(); - AbstractList.this.set(lastReturned, o); - } - - /** - * Adds the supplied object before the element that would be returned - * by a call to <code>next()</code>, if the list supports addition. - * - * @param o The object to add to the list. - * @throws UnsupportedOperationException if the list doesn't support - * the addition of new elements. - * @throws ClassCastException if the type of o is not a valid type - * for this list. - * @throws IllegalArgumentException if something else related to o - * prevents its addition. - * @throws ConcurrentModificationException if the list - * has been modified elsewhere. - */ - public void add(Object o) - { - checkMod(); - AbstractList.this.add(position++, o); - size++; - lastReturned = -1; - knownMod = modCount; - } - }; - } - - /** - * Remove the element at a given position in this list (optional operation). - * Shifts all remaining elements to the left to fill the gap. This - * implementation always throws an UnsupportedOperationException. - * If you want fail-fast iterators, be sure to increment modCount when - * overriding this. - * - * @param index the position within the list of the object to remove - * @return the object that was removed - * @throws UnsupportedOperationException if this list does not support the - * remove operation - * @throws IndexOutOfBoundsException if index < 0 || index >= size() - * @see #modCount - */ - public Object remove(int index) - { - throw new UnsupportedOperationException(); - } - - /** - * Remove a subsection of the list. This is called by the clear and - * removeRange methods of the class which implements subList, which are - * difficult for subclasses to override directly. Therefore, this method - * should be overridden instead by the more efficient implementation, if one - * exists. Overriding this can reduce quadratic efforts to constant time - * in some cases! - * <p> - * - * This implementation first checks for illegal or out of range arguments. It - * then obtains a ListIterator over the list using listIterator(fromIndex). - * It then calls next() and remove() on this iterator repeatedly, toIndex - - * fromIndex times. - * - * @param fromIndex the index, inclusive, to remove from. - * @param toIndex the index, exclusive, to remove to. - * @throws UnsupportedOperationException if the list does - * not support removing elements. - */ - protected void removeRange(int fromIndex, int toIndex) - { - ListIterator itr = listIterator(fromIndex); - for (int index = fromIndex; index < toIndex; index++) - { - itr.next(); - itr.remove(); - } - } - - /** - * Replace an element of this list with another object (optional operation). - * This implementation always throws an UnsupportedOperationException. - * - * @param index the position within this list of the element to be replaced - * @param o the object to replace it with - * @return the object that was replaced - * @throws UnsupportedOperationException if this list does not support the - * set operation - * @throws IndexOutOfBoundsException if index < 0 || index >= size() - * @throws ClassCastException if o cannot be added to this list due to its - * type - * @throws IllegalArgumentException if o cannot be added to this list for - * some other reason - */ - public Object set(int index, Object o) - { - throw new UnsupportedOperationException(); - } - - /** - * Obtain a List view of a subsection of this list, from fromIndex - * (inclusive) to toIndex (exclusive). If the two indices are equal, the - * sublist is empty. The returned list should be modifiable if and only - * if this list is modifiable. Changes to the returned list should be - * reflected in this list. If this list is structurally modified in - * any way other than through the returned list, the result of any subsequent - * operations on the returned list is undefined. - * <p> - * - * This implementation returns a subclass of AbstractList. It stores, in - * private fields, the offset and size of the sublist, and the expected - * modCount of the backing list. If the backing list implements RandomAccess, - * the sublist will also. - * <p> - * - * The subclass's <code>set(int, Object)</code>, <code>get(int)</code>, - * <code>add(int, Object)</code>, <code>remove(int)</code>, - * <code>addAll(int, Collection)</code> and - * <code>removeRange(int, int)</code> methods all delegate to the - * corresponding methods on the backing abstract list, after - * bounds-checking the index and adjusting for the offset. The - * <code>addAll(Collection c)</code> method merely returns addAll(size, c). - * The <code>listIterator(int)</code> method returns a "wrapper object" - * over a list iterator on the backing list, which is created with the - * corresponding method on the backing list. The <code>iterator()</code> - * method merely returns listIterator(), and the <code>size()</code> method - * merely returns the subclass's size field. - * <p> - * - * All methods first check to see if the actual modCount of the backing - * list is equal to its expected value, and throw a - * ConcurrentModificationException if it is not. - * - * @param fromIndex the index that the returned list should start from - * (inclusive) - * @param toIndex the index that the returned list should go to (exclusive) - * @return a List backed by a subsection of this list - * @throws IndexOutOfBoundsException if fromIndex < 0 - * || toIndex > size() - * @throws IllegalArgumentException if fromIndex > toIndex - * @see ConcurrentModificationException - * @see RandomAccess - */ - public List subList(int fromIndex, int toIndex) - { - // This follows the specification of AbstractList, but is inconsistent - // with the one in List. Don't you love Sun's inconsistencies? - if (fromIndex > toIndex) - throw new IllegalArgumentException(fromIndex + " > " + toIndex); - if (fromIndex < 0 || toIndex > size()) - throw new IndexOutOfBoundsException(); - - if (this instanceof RandomAccess) - return new RandomAccessSubList(this, fromIndex, toIndex); - return new SubList(this, fromIndex, toIndex); - } - - /** - * This class follows the implementation requirements set forth in - * {@link AbstractList#subList(int, int)}. It matches Sun's implementation - * by using a non-public top-level class in the same package. - * - * @author Original author unknown - * @author Eric Blake (ebb9@email.byu.edu) - */ - private static class SubList extends AbstractList - { - // Package visible, for use by iterator. - /** The original list. */ - final AbstractList backingList; - /** The index of the first element of the sublist. */ - final int offset; - /** The size of the sublist. */ - int size; - - /** - * Construct the sublist. - * - * @param backing the list this comes from - * @param fromIndex the lower bound, inclusive - * @param toIndex the upper bound, exclusive - */ - SubList(AbstractList backing, int fromIndex, int toIndex) - { - backingList = backing; - modCount = backing.modCount; - offset = fromIndex; - size = toIndex - fromIndex; - } - - /** - * This method checks the two modCount fields to ensure that there has - * not been a concurrent modification, returning if all is okay. - * - * @throws ConcurrentModificationException if the backing list has been - * modified externally to this sublist - */ - // This can be inlined. Package visible, for use by iterator. - void checkMod() - { - if (modCount != backingList.modCount) - throw new ConcurrentModificationException(); - } - - /** - * This method checks that a value is between 0 and size (inclusive). If - * it is not, an exception is thrown. - * - * @param index the value to check - * @throws IndexOutOfBoundsException if index < 0 || index > size() - */ - // This will get inlined, since it is private. - private void checkBoundsInclusive(int index) - { - if (index < 0 || index > size) - throw new IndexOutOfBoundsException("Index: " + index + ", Size:" - + size); - } - - /** - * This method checks that a value is between 0 (inclusive) and size - * (exclusive). If it is not, an exception is thrown. - * - * @param index the value to check - * @throws IndexOutOfBoundsException if index < 0 || index >= size() - */ - // This will get inlined, since it is private. - private void checkBoundsExclusive(int index) - { - if (index < 0 || index >= size) - throw new IndexOutOfBoundsException("Index: " + index + ", Size:" - + size); - } - - /** - * Specified by AbstractList.subList to return the private field size. - * - * @return the sublist size - * @throws ConcurrentModificationException if the backing list has been - * modified externally to this sublist - */ - public int size() - { - checkMod(); - return size; - } - - /** - * Specified by AbstractList.subList to delegate to the backing list. - * - * @param index the location to modify - * @param o the new value - * @return the old value - * @throws ConcurrentModificationException if the backing list has been - * modified externally to this sublist - * @throws UnsupportedOperationException if the backing list does not - * support the set operation - * @throws IndexOutOfBoundsException if index < 0 || index >= size() - * @throws ClassCastException if o cannot be added to the backing list due - * to its type - * @throws IllegalArgumentException if o cannot be added to the backing list - * for some other reason - */ - public Object set(int index, Object o) - { - checkMod(); - checkBoundsExclusive(index); - return backingList.set(index + offset, o); - } - - /** - * Specified by AbstractList.subList to delegate to the backing list. - * - * @param index the location to get from - * @return the object at that location - * @throws ConcurrentModificationException if the backing list has been - * modified externally to this sublist - * @throws IndexOutOfBoundsException if index < 0 || index >= size() - */ - public Object get(int index) - { - checkMod(); - checkBoundsExclusive(index); - return backingList.get(index + offset); - } - - /** - * Specified by AbstractList.subList to delegate to the backing list. - * - * @param index the index to insert at - * @param o the object to add - * @throws ConcurrentModificationException if the backing list has been - * modified externally to this sublist - * @throws IndexOutOfBoundsException if index < 0 || index > size() - * @throws UnsupportedOperationException if the backing list does not - * support the add operation. - * @throws ClassCastException if o cannot be added to the backing list due - * to its type. - * @throws IllegalArgumentException if o cannot be added to the backing - * list for some other reason. - */ - public void add(int index, Object o) - { - checkMod(); - checkBoundsInclusive(index); - backingList.add(index + offset, o); - size++; - modCount = backingList.modCount; - } - - /** - * Specified by AbstractList.subList to delegate to the backing list. - * - * @param index the index to remove - * @return the removed object - * @throws ConcurrentModificationException if the backing list has been - * modified externally to this sublist - * @throws IndexOutOfBoundsException if index < 0 || index >= size() - * @throws UnsupportedOperationException if the backing list does not - * support the remove operation - */ - public Object remove(int index) - { - checkMod(); - checkBoundsExclusive(index); - Object o = backingList.remove(index + offset); - size--; - modCount = backingList.modCount; - return o; - } - - /** - * Specified by AbstractList.subList to delegate to the backing list. - * This does no bounds checking, as it assumes it will only be called - * by trusted code like clear() which has already checked the bounds. - * - * @param fromIndex the lower bound, inclusive - * @param toIndex the upper bound, exclusive - * @throws ConcurrentModificationException if the backing list has been - * modified externally to this sublist - * @throws UnsupportedOperationException if the backing list does - * not support removing elements. - */ - protected void removeRange(int fromIndex, int toIndex) - { - checkMod(); - - backingList.removeRange(offset + fromIndex, offset + toIndex); - size -= toIndex - fromIndex; - modCount = backingList.modCount; - } - - /** - * Specified by AbstractList.subList to delegate to the backing list. - * - * @param index the location to insert at - * @param c the collection to insert - * @return true if this list was modified, in other words, c is non-empty - * @throws ConcurrentModificationException if the backing list has been - * modified externally to this sublist - * @throws IndexOutOfBoundsException if index < 0 || index > size() - * @throws UnsupportedOperationException if this list does not support the - * addAll operation - * @throws ClassCastException if some element of c cannot be added to this - * list due to its type - * @throws IllegalArgumentException if some element of c cannot be added - * to this list for some other reason - * @throws NullPointerException if the specified collection is null - */ - public boolean addAll(int index, Collection c) - { - checkMod(); - checkBoundsInclusive(index); - int csize = c.size(); - boolean result = backingList.addAll(offset + index, c); - size += csize; - modCount = backingList.modCount; - return result; - } - - /** - * Specified by AbstractList.subList to return addAll(size, c). - * - * @param c the collection to insert - * @return true if this list was modified, in other words, c is non-empty - * @throws ConcurrentModificationException if the backing list has been - * modified externally to this sublist - * @throws UnsupportedOperationException if this list does not support the - * addAll operation - * @throws ClassCastException if some element of c cannot be added to this - * list due to its type - * @throws IllegalArgumentException if some element of c cannot be added - * to this list for some other reason - * @throws NullPointerException if the specified collection is null - */ - public boolean addAll(Collection c) - { - return addAll(size, c); - } - - /** - * Specified by AbstractList.subList to return listIterator(). - * - * @return an iterator over the sublist - */ - public Iterator iterator() - { - return listIterator(); - } - - /** - * Specified by AbstractList.subList to return a wrapper around the - * backing list's iterator. - * - * @param index the start location of the iterator - * @return a list iterator over the sublist - * @throws ConcurrentModificationException if the backing list has been - * modified externally to this sublist - * @throws IndexOutOfBoundsException if the value is out of range - */ - public ListIterator listIterator(final int index) - { - checkMod(); - checkBoundsInclusive(index); - - return new ListIterator() - { - private final ListIterator i = backingList.listIterator(index + offset); - private int position = index; - - /** - * Tests to see if there are any more objects to - * return. - * - * @return True if the end of the list has not yet been - * reached. - * @throws ConcurrentModificationException if the - * list has been modified elsewhere. - */ - public boolean hasNext() - { - checkMod(); - return position < size; - } - - /** - * Tests to see if there are objects prior to the - * current position in the list. - * - * @return True if objects exist prior to the current - * position of the iterator. - * @throws ConcurrentModificationException if the - * list has been modified elsewhere. - */ - public boolean hasPrevious() - { - checkMod(); - return position > 0; - } - - /** - * Retrieves the next object from the list. - * - * @return The next object. - * @throws NoSuchElementException if there are no - * more objects to retrieve. - * @throws ConcurrentModificationException if the - * list has been modified elsewhere. - */ - public Object next() - { - if (position == size) - throw new NoSuchElementException(); - position++; - return i.next(); - } - - /** - * Retrieves the previous object from the list. - * - * @return The next object. - * @throws NoSuchElementException if there are no - * previous objects to retrieve. - * @throws ConcurrentModificationException if the - * list has been modified elsewhere. - */ - public Object previous() - { - if (position == 0) - throw new NoSuchElementException(); - position--; - return i.previous(); - } - - /** - * Returns the index of the next element in the - * list, which will be retrieved by <code>next()</code> - * - * @return The index of the next element. - * @throws ConcurrentModificationException if the - * list has been modified elsewhere. - */ - public int nextIndex() - { - return i.nextIndex() - offset; - } - - /** - * Returns the index of the previous element in the - * list, which will be retrieved by <code>previous()</code> - * - * @return The index of the previous element. - * @throws ConcurrentModificationException if the - * list has been modified elsewhere. - */ - public int previousIndex() - { - return i.previousIndex() - offset; - } - - /** - * Removes the last object retrieved by <code>next()</code> - * from the list, if the list supports object removal. - * - * @throws IllegalStateException if the iterator is positioned - * before the start of the list or the last object has already - * been removed. - * @throws UnsupportedOperationException if the list does - * not support removing elements. - */ - public void remove() - { - i.remove(); - size--; - position = nextIndex(); - modCount = backingList.modCount; - } - - - /** - * Replaces the last object retrieved by <code>next()</code> - * or <code>previous</code> with o, if the list supports object - * replacement and an add or remove operation has not already - * been performed. - * - * @throws IllegalStateException if the iterator is positioned - * before the start of the list or the last object has already - * been removed. - * @throws UnsupportedOperationException if the list doesn't support - * the addition or removal of elements. - * @throws ClassCastException if the type of o is not a valid type - * for this list. - * @throws IllegalArgumentException if something else related to o - * prevents its addition. - * @throws ConcurrentModificationException if the list - * has been modified elsewhere. - */ - public void set(Object o) - { - i.set(o); - } - - /** - * Adds the supplied object before the element that would be returned - * by a call to <code>next()</code>, if the list supports addition. - * - * @param o The object to add to the list. - * @throws UnsupportedOperationException if the list doesn't support - * the addition of new elements. - * @throws ClassCastException if the type of o is not a valid type - * for this list. - * @throws IllegalArgumentException if something else related to o - * prevents its addition. - * @throws ConcurrentModificationException if the list - * has been modified elsewhere. - */ - public void add(Object o) - { - i.add(o); - size++; - position++; - modCount = backingList.modCount; - } - - // Here is the reason why the various modCount fields are mostly - // ignored in this wrapper listIterator. - // If the backing listIterator is failfast, then the following holds: - // Using any other method on this list will call a corresponding - // method on the backing list *after* the backing listIterator - // is created, which will in turn cause a ConcurrentModException - // when this listIterator comes to use the backing one. So it is - // implicitly failfast. - // If the backing listIterator is NOT failfast, then the whole of - // this list isn't failfast, because the modCount field of the - // backing list is not valid. It would still be *possible* to - // make the iterator failfast wrt modifications of the sublist - // only, but somewhat pointless when the list can be changed under - // us. - // Either way, no explicit handling of modCount is needed. - // However modCount = backingList.modCount must be executed in add - // and remove, and size must also be updated in these two methods, - // since they do not go through the corresponding methods of the subList. - }; - } - } // class SubList - - /** - * This class is a RandomAccess version of SubList, as required by - * {@link AbstractList#subList(int, int)}. - * - * @author Eric Blake (ebb9@email.byu.edu) - */ - private static final class RandomAccessSubList extends SubList - implements RandomAccess - { - /** - * Construct the sublist. - * - * @param backing the list this comes from - * @param fromIndex the lower bound, inclusive - * @param toIndex the upper bound, exclusive - */ - RandomAccessSubList(AbstractList backing, int fromIndex, int toIndex) - { - super(backing, fromIndex, toIndex); - } - } // class RandomAccessSubList - -} // class AbstractList diff --git a/libjava/java/util/AbstractMap.java b/libjava/java/util/AbstractMap.java deleted file mode 100644 index 7cd6436a308..00000000000 --- a/libjava/java/util/AbstractMap.java +++ /dev/null @@ -1,749 +0,0 @@ -/* AbstractMap.java -- Abstract implementation of most of Map - Copyright (C) 1998, 1999, 2000, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util; - -/** - * An abstract implementation of Map to make it easier to create your own - * implementations. In order to create an unmodifiable Map, subclass - * AbstractMap and implement the <code>entrySet</code> (usually via an - * AbstractSet). To make it modifiable, also implement <code>put</code>, - * and have <code>entrySet().iterator()</code> support <code>remove</code>. - * <p> - * - * It is recommended that classes which extend this support at least the - * no-argument constructor, and a constructor which accepts another Map. - * Further methods in this class may be overridden if you have a more - * efficient implementation. - * - * @author Original author unknown - * @author Bryce McKinlay - * @author Eric Blake (ebb9@email.byu.edu) - * @see Map - * @see Collection - * @see HashMap - * @see LinkedHashMap - * @see TreeMap - * @see WeakHashMap - * @see IdentityHashMap - * @since 1.2 - * @status updated to 1.4 - */ -public abstract class AbstractMap implements Map -{ - /** An "enum" of iterator types. */ - // Package visible for use by subclasses. - static final int KEYS = 0, - VALUES = 1, - ENTRIES = 2; - - /** - * The cache for {@link #keySet()}. - */ - // Package visible for use by subclasses. - Set keys; - - /** - * The cache for {@link #values()}. - */ - // Package visible for use by subclasses. - Collection values; - - /** - * The main constructor, for use by subclasses. - */ - protected AbstractMap() - { - } - - /** - * Returns a set view of the mappings in this Map. Each element in the - * set must be an implementation of Map.Entry. The set is backed by - * the map, so that changes in one show up in the other. Modifications - * made while an iterator is in progress cause undefined behavior. If - * the set supports removal, these methods must be valid: - * <code>Iterator.remove</code>, <code>Set.remove</code>, - * <code>removeAll</code>, <code>retainAll</code>, and <code>clear</code>. - * Element addition is not supported via this set. - * - * @return the entry set - * @see Map.Entry - */ - public abstract Set entrySet(); - - /** - * Remove all entries from this Map (optional operation). This default - * implementation calls entrySet().clear(). NOTE: If the entry set does - * not permit clearing, then this will fail, too. Subclasses often - * override this for efficiency. Your implementation of entrySet() should - * not call <code>AbstractMap.clear</code> unless you want an infinite loop. - * - * @throws UnsupportedOperationException if <code>entrySet().clear()</code> - * does not support clearing. - * @see Set#clear() - */ - public void clear() - { - entrySet().clear(); - } - - /** - * Create a shallow copy of this Map, no keys or values are copied. The - * default implementation simply calls <code>super.clone()</code>. - * - * @return the shallow clone - * @throws CloneNotSupportedException if a subclass is not Cloneable - * @see Cloneable - * @see Object#clone() - */ - protected Object clone() throws CloneNotSupportedException - { - AbstractMap copy = (AbstractMap) super.clone(); - // Clear out the caches; they are stale. - copy.keys = null; - copy.values = null; - return copy; - } - - /** - * Returns true if this contains a mapping for the given key. This - * implementation does a linear search, O(n), over the - * <code>entrySet()</code>, returning <code>true</code> if a match - * is found, <code>false</code> if the iteration ends. Many subclasses - * can implement this more efficiently. - * - * @param key the key to search for - * @return true if the map contains the key - * @throws NullPointerException if key is <code>null</code> but the map - * does not permit null keys - * @see #containsValue(Object) - */ - public boolean containsKey(Object key) - { - Iterator entries = entrySet().iterator(); - int pos = size(); - while (--pos >= 0) - if (equals(key, ((Map.Entry) entries.next()).getKey())) - return true; - return false; - } - - /** - * Returns true if this contains at least one mapping with the given value. - * This implementation does a linear search, O(n), over the - * <code>entrySet()</code>, returning <code>true</code> if a match - * is found, <code>false</code> if the iteration ends. A match is - * defined as a value, v, where <code>(value == null ? v == null : - * value.equals(v))</code>. Subclasses are unlikely to implement - * this more efficiently. - * - * @param value the value to search for - * @return true if the map contains the value - * @see #containsKey(Object) - */ - public boolean containsValue(Object value) - { - Iterator entries = entrySet().iterator(); - int pos = size(); - while (--pos >= 0) - if (equals(value, ((Map.Entry) entries.next()).getValue())) - return true; - return false; - } - - /** - * Compares the specified object with this map for equality. Returns - * <code>true</code> if the other object is a Map with the same mappings, - * that is,<br> - * <code>o instanceof Map && entrySet().equals(((Map) o).entrySet();</code> - * - * @param o the object to be compared - * @return true if the object equals this map - * @see Set#equals(Object) - */ - public boolean equals(Object o) - { - return (o == this || - (o instanceof Map && - entrySet().equals(((Map) o).entrySet()))); - } - - /** - * Returns the value mapped by the given key. Returns <code>null</code> if - * there is no mapping. However, in Maps that accept null values, you - * must rely on <code>containsKey</code> to determine if a mapping exists. - * This iteration takes linear time, searching entrySet().iterator() of - * the key. Many implementations override this method. - * - * @param key the key to look up - * @return the value associated with the key, or null if key not in map - * @throws NullPointerException if this map does not accept null keys - * @see #containsKey(Object) - */ - public Object get(Object key) - { - Iterator entries = entrySet().iterator(); - int pos = size(); - while (--pos >= 0) - { - Map.Entry entry = (Map.Entry) entries.next(); - if (equals(key, entry.getKey())) - return entry.getValue(); - } - return null; - } - - /** - * Returns the hash code for this map. As defined in Map, this is the sum - * of all hashcodes for each Map.Entry object in entrySet, or basically - * entrySet().hashCode(). - * - * @return the hash code - * @see Map.Entry#hashCode() - * @see Set#hashCode() - */ - public int hashCode() - { - return entrySet().hashCode(); - } - - /** - * Returns true if the map contains no mappings. This is implemented by - * <code>size() == 0</code>. - * - * @return true if the map is empty - * @see #size() - */ - public boolean isEmpty() - { - return size() == 0; - } - - /** - * Returns a set view of this map's keys. The set is backed by the map, - * so changes in one show up in the other. Modifications while an iteration - * is in progress produce undefined behavior. The set supports removal - * if entrySet() does, but does not support element addition. - * <p> - * - * This implementation creates an AbstractSet, where the iterator wraps - * the entrySet iterator, size defers to the Map's size, and contains - * defers to the Map's containsKey. The set is created on first use, and - * returned on subsequent uses, although since no synchronization occurs, - * there is a slight possibility of creating two sets. - * - * @return a Set view of the keys - * @see Set#iterator() - * @see #size() - * @see #containsKey(Object) - * @see #values() - */ - public Set keySet() - { - if (keys == null) - keys = new AbstractSet() - { - /** - * Retrieves the number of keys in the backing map. - * - * @return The number of keys. - */ - public int size() - { - return AbstractMap.this.size(); - } - - /** - * Returns true if the backing map contains the - * supplied key. - * - * @param key The key to search for. - * @return True if the key was found, false otherwise. - */ - public boolean contains(Object key) - { - return containsKey(key); - } - - /** - * Returns an iterator which iterates over the keys - * in the backing map, using a wrapper around the - * iterator returned by <code>entrySet()</code>. - * - * @return An iterator over the keys. - */ - public Iterator iterator() - { - return new Iterator() - { - /** - * The iterator returned by <code>entrySet()</code>. - */ - private final Iterator map_iterator = entrySet().iterator(); - - /** - * Returns true if a call to <code>next()</code> will - * return another key. - * - * @return True if the iterator has not yet reached - * the last key. - */ - public boolean hasNext() - { - return map_iterator.hasNext(); - } - - /** - * Returns the key from the next entry retrieved - * by the underlying <code>entrySet()</code> iterator. - * - * @return The next key. - */ - public Object next() - { - return ((Map.Entry) map_iterator.next()).getKey(); - } - - /** - * Removes the map entry which has a key equal - * to that returned by the last call to - * <code>next()</code>. - * - * @throws UnsupportedOperationException if the - * map doesn't support removal. - */ - public void remove() - { - map_iterator.remove(); - } - }; - } - }; - return keys; - } - - /** - * Associates the given key to the given value (optional operation). If the - * map already contains the key, its value is replaced. This implementation - * simply throws an UnsupportedOperationException. Be aware that in a map - * that permits <code>null</code> values, a null return does not always - * imply that the mapping was created. - * - * @param key the key to map - * @param value the value to be mapped - * @return the previous value of the key, or null if there was no mapping - * @throws UnsupportedOperationException if the operation is not supported - * @throws ClassCastException if the key or value is of the wrong type - * @throws IllegalArgumentException if something about this key or value - * prevents it from existing in this map - * @throws NullPointerException if the map forbids null keys or values - * @see #containsKey(Object) - */ - public Object put(Object key, Object value) - { - throw new UnsupportedOperationException(); - } - - /** - * Copies all entries of the given map to this one (optional operation). If - * the map already contains a key, its value is replaced. This implementation - * simply iterates over the map's entrySet(), calling <code>put</code>, - * so it is not supported if puts are not. - * - * @param m the mapping to load into this map - * @throws UnsupportedOperationException if the operation is not supported - * by this map. - * @throws ClassCastException if a key or value is of the wrong type for - * adding to this map. - * @throws IllegalArgumentException if something about a key or value - * prevents it from existing in this map. - * @throws NullPointerException if the map forbids null keys or values. - * @throws NullPointerException if <code>m</code> is null. - * @see #put(Object, Object) - */ - public void putAll(Map m) - { - Iterator entries = m.entrySet().iterator(); - int pos = m.size(); - while (--pos >= 0) - { - Map.Entry entry = (Map.Entry) entries.next(); - put(entry.getKey(), entry.getValue()); - } - } - - /** - * Removes the mapping for this key if present (optional operation). This - * implementation iterates over the entrySet searching for a matching - * key, at which point it calls the iterator's <code>remove</code> method. - * It returns the result of <code>getValue()</code> on the entry, if found, - * or null if no entry is found. Note that maps which permit null values - * may also return null if the key was removed. If the entrySet does not - * support removal, this will also fail. This is O(n), so many - * implementations override it for efficiency. - * - * @param key the key to remove - * @return the value the key mapped to, or null if not present. - * Null may also be returned if null values are allowed - * in the map and the value of this mapping is null. - * @throws UnsupportedOperationException if deletion is unsupported - * @see Iterator#remove() - */ - public Object remove(Object key) - { - Iterator entries = entrySet().iterator(); - int pos = size(); - while (--pos >= 0) - { - Map.Entry entry = (Map.Entry) entries.next(); - if (equals(key, entry.getKey())) - { - // Must get the value before we remove it from iterator. - Object r = entry.getValue(); - entries.remove(); - return r; - } - } - return null; - } - - /** - * Returns the number of key-value mappings in the map. If there are more - * than Integer.MAX_VALUE mappings, return Integer.MAX_VALUE. This is - * implemented as <code>entrySet().size()</code>. - * - * @return the number of mappings - * @see Set#size() - */ - public int size() - { - return entrySet().size(); - } - - /** - * Returns a String representation of this map. This is a listing of the - * map entries (which are specified in Map.Entry as being - * <code>getKey() + "=" + getValue()</code>), separated by a comma and - * space (", "), and surrounded by braces ('{' and '}'). This implementation - * uses a StringBuffer and iterates over the entrySet to build the String. - * Note that this can fail with an exception if underlying keys or - * values complete abruptly in toString(). - * - * @return a String representation - * @see Map.Entry#toString() - */ - public String toString() - { - Iterator entries = entrySet().iterator(); - StringBuffer r = new StringBuffer("{"); - for (int pos = size(); pos > 0; pos--) - { - Map.Entry entry = (Map.Entry) entries.next(); - r.append(entry.getKey()); - r.append('='); - r.append(entry.getValue()); - if (pos > 1) - r.append(", "); - } - r.append("}"); - return r.toString(); - } - - /** - * Returns a collection or bag view of this map's values. The collection - * is backed by the map, so changes in one show up in the other. - * Modifications while an iteration is in progress produce undefined - * behavior. The collection supports removal if entrySet() does, but - * does not support element addition. - * <p> - * - * This implementation creates an AbstractCollection, where the iterator - * wraps the entrySet iterator, size defers to the Map's size, and contains - * defers to the Map's containsValue. The collection is created on first - * use, and returned on subsequent uses, although since no synchronization - * occurs, there is a slight possibility of creating two collections. - * - * @return a Collection view of the values - * @see Collection#iterator() - * @see #size() - * @see #containsValue(Object) - * @see #keySet() - */ - public Collection values() - { - if (values == null) - values = new AbstractCollection() - { - /** - * Returns the number of values stored in - * the backing map. - * - * @return The number of values. - */ - public int size() - { - return AbstractMap.this.size(); - } - - /** - * Returns true if the backing map contains - * the supplied value. - * - * @param value The value to search for. - * @return True if the value was found, false otherwise. - */ - public boolean contains(Object value) - { - return containsValue(value); - } - - /** - * Returns an iterator which iterates over the - * values in the backing map, by using a wrapper - * around the iterator returned by <code>entrySet()</code>. - * - * @return An iterator over the values. - */ - public Iterator iterator() - { - return new Iterator() - { - /** - * The iterator returned by <code>entrySet()</code>. - */ - private final Iterator map_iterator = entrySet().iterator(); - - /** - * Returns true if a call to <code>next()</call> will - * return another value. - * - * @return True if the iterator has not yet reached - * the last value. - */ - public boolean hasNext() - { - return map_iterator.hasNext(); - } - - /** - * Returns the value from the next entry retrieved - * by the underlying <code>entrySet()</code> iterator. - * - * @return The next value. - */ - public Object next() - { - return ((Map.Entry) map_iterator.next()).getValue(); - } - - /** - * Removes the map entry which has a key equal - * to that returned by the last call to - * <code>next()</code>. - * - * @throws UnsupportedOperationException if the - * map doesn't support removal. - */ - public void remove() - { - map_iterator.remove(); - } - }; - } - }; - return values; - } - - /** - * Compare two objects according to Collection semantics. - * - * @param o1 the first object - * @param o2 the second object - * @return o1 == null ? o2 == null : o1.equals(o2) - */ - // Package visible for use throughout java.util. - // It may be inlined since it is final. - static final boolean equals(Object o1, Object o2) - { - return o1 == null ? o2 == null : o1.equals(o2); - } - - /** - * Hash an object according to Collection semantics. - * - * @param o the object to hash - * @return o1 == null ? 0 : o1.hashCode() - */ - // Package visible for use throughout java.util. - // It may be inlined since it is final. - static final int hashCode(Object o) - { - return o == null ? 0 : o.hashCode(); - } - - /** - * A class which implements Map.Entry. It is shared by HashMap, TreeMap, - * Hashtable, and Collections. It is not specified by the JDK, but makes - * life much easier. - * - * @author Jon Zeppieri - * @author Eric Blake (ebb9@email.byu.edu) - */ - // XXX - FIXME Use fully qualified implements as gcj 3.1 workaround. - // Bug still exists in 3.4.1 - static class BasicMapEntry implements Map.Entry - { - /** - * The key. Package visible for direct manipulation. - */ - Object key; - - /** - * The value. Package visible for direct manipulation. - */ - Object value; - - /** - * Basic constructor initializes the fields. - * @param newKey the key - * @param newValue the value - */ - BasicMapEntry(Object newKey, Object newValue) - { - key = newKey; - value = newValue; - } - - /** - * Compares the specified object with this entry. Returns true only if - * the object is a mapping of identical key and value. In other words, - * this must be:<br> - * <pre>(o instanceof Map.Entry) - * && (getKey() == null ? ((HashMap) o).getKey() == null - * : getKey().equals(((HashMap) o).getKey())) - * && (getValue() == null ? ((HashMap) o).getValue() == null - * : getValue().equals(((HashMap) o).getValue()))</pre> - * - * @param o the object to compare - * @return <code>true</code> if it is equal - */ - public final boolean equals(Object o) - { - if (! (o instanceof Map.Entry)) - return false; - // Optimize for our own entries. - if (o instanceof BasicMapEntry) - { - BasicMapEntry e = (BasicMapEntry) o; - return (AbstractMap.equals(key, e.key) - && AbstractMap.equals(value, e.value)); - } - Map.Entry e = (Map.Entry) o; - return (AbstractMap.equals(key, e.getKey()) - && AbstractMap.equals(value, e.getValue())); - } - - /** - * Get the key corresponding to this entry. - * - * @return the key - */ - public final Object getKey() - { - return key; - } - - /** - * Get the value corresponding to this entry. If you already called - * Iterator.remove(), the behavior undefined, but in this case it works. - * - * @return the value - */ - public final Object getValue() - { - return value; - } - - /** - * Returns the hash code of the entry. This is defined as the exclusive-or - * of the hashcodes of the key and value (using 0 for null). In other - * words, this must be:<br> - * <pre>(getKey() == null ? 0 : getKey().hashCode()) - * ^ (getValue() == null ? 0 : getValue().hashCode())</pre> - * - * @return the hash code - */ - public final int hashCode() - { - return (AbstractMap.hashCode(key) ^ AbstractMap.hashCode(value)); - } - - /** - * Replaces the value with the specified object. This writes through - * to the map, unless you have already called Iterator.remove(). It - * may be overridden to restrict a null value. - * - * @param newVal the new value to store - * @return the old value - * @throws NullPointerException if the map forbids null values. - * @throws UnsupportedOperationException if the map doesn't support - * <code>put()</code>. - * @throws ClassCastException if the value is of a type unsupported - * by the map. - * @throws IllegalArgumentException if something else about this - * value prevents it being stored in the map. - */ - public Object setValue(Object newVal) - { - Object r = value; - value = newVal; - return r; - } - - /** - * This provides a string representation of the entry. It is of the form - * "key=value", where string concatenation is used on key and value. - * - * @return the string representation - */ - public final String toString() - { - return key + "=" + value; - } - } // class BasicMapEntry -} diff --git a/libjava/java/util/AbstractSequentialList.java b/libjava/java/util/AbstractSequentialList.java deleted file mode 100644 index 79583228d96..00000000000 --- a/libjava/java/util/AbstractSequentialList.java +++ /dev/null @@ -1,235 +0,0 @@ -/* AbstractSequentialList.java -- List implementation for sequential access - Copyright (C) 1998, 1999, 2000, 2001, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util; - -/** - * Abstract superclass to make it easier to implement the List interface when - * backed by a sequential-access store, such as a linked list. For random - * access data, use AbstractList. This class implements the random access - * methods (<code>get</code>, <code>set</code>, <code>add</code>, and - * <code>remove</code>) atop the list iterator, opposite of AbstractList's - * approach of implementing the iterator atop random access. - * <p> - * - * To implement a list, you need an implementation for <code>size()</code> - * and <code>listIterator</code>. With just <code>hasNext</code>, - * <code>next</code>, <code>hasPrevious</code>, <code>previous</code>, - * <code>nextIndex</code>, and <code>previousIndex</code>, you have an - * unmodifiable list. For a modifiable one, add <code>set</code>, and for - * a variable-size list, add <code>add</code> and <code>remove</code>. - * <p> - * - * The programmer should provide a no-argument constructor, and one that - * accepts another Collection, as recommended by the Collection interface. - * Unfortunately, there is no way to enforce this in Java. - * - * @author Original author unknown - * @author Bryce McKinlay - * @author Eric Blake (ebb9@email.byu.edu) - * @see Collection - * @see List - * @see AbstractList - * @see AbstractCollection - * @see ListIterator - * @see LinkedList - * @since 1.2 - * @status updated to 1.4 - */ -public abstract class AbstractSequentialList extends AbstractList -{ - /** - * The main constructor, for use by subclasses. - */ - protected AbstractSequentialList() - { - } - - /** - * Returns a ListIterator over the list, starting from position index. - * Subclasses must provide an implementation of this method. - * - * @param index the starting position of the list - * @return the list iterator - * @throws IndexOutOfBoundsException if index < 0 || index > size() - */ - public abstract ListIterator listIterator(int index); - - /** - * Insert an element into the list at a given position (optional operation). - * This shifts all existing elements from that position to the end one - * index to the right. This version of add has no return, since it is - * assumed to always succeed if there is no exception. This iteration - * uses listIterator(index).add(o). - * - * @param index the location to insert the item - * @param o the object to insert - * @throws UnsupportedOperationException if this list does not support the - * add operation - * @throws IndexOutOfBoundsException if index < 0 || index > size() - * @throws ClassCastException if o cannot be added to this list due to its - * type - * @throws IllegalArgumentException if o cannot be added to this list for - * some other reason. - * @throws NullPointerException if o is null and the list does not permit - * the addition of null values. - */ - public void add(int index, Object o) - { - listIterator(index).add(o); - } - - /** - * Insert the contents of a collection into the list at a given position - * (optional operation). Shift all elements at that position to the right - * by the number of elements inserted. This operation is undefined if - * this list is modified during the operation (for example, if you try - * to insert a list into itself). - * <p> - * - * This implementation grabs listIterator(index), then proceeds to use add - * for each element returned by c's iterator. Sun's online specs are wrong, - * claiming that this also calls next(): listIterator.add() correctly - * skips the added element. - * - * @param index the location to insert the collection - * @param c the collection to insert - * @return true if the list was modified by this action, that is, if c is - * non-empty - * @throws UnsupportedOperationException if this list does not support the - * addAll operation - * @throws IndexOutOfBoundsException if index < 0 || index > size() - * @throws ClassCastException if some element of c cannot be added to this - * list due to its type - * @throws IllegalArgumentException if some element of c cannot be added - * to this list for some other reason - * @throws NullPointerException if the specified collection is null - * @throws NullPointerException if an object, o, in c is null and the list - * does not permit the addition of null values. - * @see #add(int, Object) - */ - public boolean addAll(int index, Collection c) - { - Iterator ci = c.iterator(); - int size = c.size(); - ListIterator i = listIterator(index); - for (int pos = size; pos > 0; pos--) - i.add(ci.next()); - return size > 0; - } - - /** - * Get the element at a given index in this list. This implementation - * returns listIterator(index).next(). - * - * @param index the index of the element to be returned - * @return the element at index index in this list - * @throws IndexOutOfBoundsException if index < 0 || index >= size() - */ - public Object get(int index) - { - // This is a legal listIterator position, but an illegal get. - if (index == size()) - throw new IndexOutOfBoundsException("Index: " + index + ", Size:" - + size()); - return listIterator(index).next(); - } - - /** - * Obtain an Iterator over this list, whose sequence is the list order. This - * implementation returns listIterator(). - * - * @return an Iterator over the elements of this list, in order - */ - public Iterator iterator() - { - return listIterator(); - } - - /** - * Remove the element at a given position in this list (optional operation). - * Shifts all remaining elements to the left to fill the gap. This - * implementation uses listIterator(index) and ListIterator.remove(). - * - * @param index the position within the list of the object to remove - * @return the object that was removed - * @throws UnsupportedOperationException if this list does not support the - * remove operation - * @throws IndexOutOfBoundsException if index < 0 || index >= size() - */ - public Object remove(int index) - { - // This is a legal listIterator position, but an illegal remove. - if (index == size()) - throw new IndexOutOfBoundsException("Index: " + index + ", Size:" - + size()); - ListIterator i = listIterator(index); - Object removed = i.next(); - i.remove(); - return removed; - } - - /** - * Replace an element of this list with another object (optional operation). - * This implementation uses listIterator(index) and ListIterator.set(o). - * - * @param index the position within this list of the element to be replaced - * @param o the object to replace it with - * @return the object that was replaced - * @throws UnsupportedOperationException if this list does not support the - * set operation - * @throws IndexOutOfBoundsException if index < 0 || index >= size() - * @throws ClassCastException if o cannot be added to this list due to its - * type - * @throws IllegalArgumentException if o cannot be added to this list for - * some other reason - * @throws NullPointerException if o is null and the list does not allow - * a value to be set to null. - */ - public Object set(int index, Object o) - { - // This is a legal listIterator position, but an illegal set. - if (index == size()) - throw new IndexOutOfBoundsException("Index: " + index + ", Size:" - + size()); - ListIterator i = listIterator(index); - Object old = i.next(); - i.set(o); - return old; - } -} diff --git a/libjava/java/util/AbstractSet.java b/libjava/java/util/AbstractSet.java deleted file mode 100644 index f0d7cb19908..00000000000 --- a/libjava/java/util/AbstractSet.java +++ /dev/null @@ -1,139 +0,0 @@ -/* AbstractSet.java -- Abstract implementation of most of Set - Copyright (C) 1998, 2000, 2001, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util; - -/** - * An abstract implementation of Set to make it easier to create your own - * implementations. In order to create a Set, subclass AbstractSet and - * implement the same methods that are required for AbstractCollection - * (although these methods must of course meet the requirements that Set puts - * on them - specifically, no element may be in the set more than once). This - * class simply provides implementations of equals() and hashCode() to fulfil - * the requirements placed on them by the Set interface. - * - * @author Original author unknown - * @author Eric Blake (ebb9@email.byu.edu) - * @see Collection - * @see AbstractCollection - * @see Set - * @see HashSet - * @see TreeSet - * @see LinkedHashSet - * @since 1.2 - * @status updated to 1.4 - */ -public abstract class AbstractSet extends AbstractCollection implements Set -{ - /** - * The main constructor, for use by subclasses. - */ - protected AbstractSet() - { - } - - /** - * Tests whether the given object is equal to this Set. This implementation - * first checks whether this set <em>is</em> the given object, and returns - * true if so. Otherwise, if o is a Set and is the same size as this one, it - * returns the result of calling containsAll on the given Set. Otherwise, it - * returns false. - * - * @param o the Object to be tested for equality with this Set - * @return true if the given object is equal to this Set - */ - public boolean equals(Object o) - { - return (o == this || - (o instanceof Set && ((Set) o).size() == size() - && containsAll((Collection) o))); - } - - /** - * Returns a hash code for this Set. The hash code of a Set is the sum of the - * hash codes of all its elements, except that the hash code of null is - * defined to be zero. This implementation obtains an Iterator over the Set, - * and sums the results. - * - * @return a hash code for this Set - */ - public int hashCode() - { - Iterator itr = iterator(); - int hash = 0; - int pos = size(); - while (--pos >= 0) - hash += hashCode(itr.next()); - return hash; - } - - /** - * Removes from this set all elements in the given collection (optional - * operation). This implementation uses <code>size()</code> to determine - * the smaller collection. Then, if this set is smaller, it iterates - * over the set, calling Iterator.remove if the collection contains - * the element. If this set is larger, it iterates over the collection, - * calling Set.remove for all elements in the collection. Note that - * this operation will fail if a remove methods is not supported. - * - * @param c the collection of elements to remove - * @return true if the set was modified as a result - * @throws UnsupportedOperationException if remove is not supported - * @throws NullPointerException if the collection is null - * @see AbstractCollection#remove(Object) - * @see Collection#contains(Object) - * @see Iterator#remove() - */ - public boolean removeAll(Collection c) - { - int oldsize = size(); - int count = c.size(); - Iterator i; - if (oldsize < count) - { - for (i = iterator(), count = oldsize; count > 0; count--) - if (c.contains(i.next())) - i.remove(); - } - else - for (i = c.iterator(); count > 0; count--) - remove(i.next()); - return oldsize != size(); - } - -} diff --git a/libjava/java/util/ArrayList.java b/libjava/java/util/ArrayList.java deleted file mode 100644 index 82bcca8c3e0..00000000000 --- a/libjava/java/util/ArrayList.java +++ /dev/null @@ -1,591 +0,0 @@ -/* ArrayList.java -- JDK1.2's answer to Vector; this is an array-backed - implementation of the List interface - Copyright (C) 1998, 1999, 2000, 2001, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util; - -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; -import java.lang.reflect.Array; - -/** - * An array-backed implementation of the List interface. This implements - * all optional list operations, and permits null elements, so that it is - * better than Vector, which it replaces. Random access is roughly constant - * time, and iteration is roughly linear time, so it is nice and fast, with - * less overhead than a LinkedList. - * <p> - * - * Each list has a capacity, and as the array reaches that capacity it - * is automatically transferred to a larger array. You also have access to - * ensureCapacity and trimToSize to control the backing array's size, avoiding - * reallocation or wasted memory. - * <p> - * - * ArrayList is not synchronized, so if you need multi-threaded access, - * consider using:<br> - * <code>List l = Collections.synchronizedList(new ArrayList(...));</code> - * <p> - * - * The iterators are <i>fail-fast</i>, meaning that any structural - * modification, except for <code>remove()</code> called on the iterator - * itself, cause the iterator to throw a - * {@link ConcurrentModificationException} rather than exhibit - * non-deterministic behavior. - * - * @author Jon A. Zeppieri - * @author Bryce McKinlay - * @author Eric Blake (ebb9@email.byu.edu) - * @see Collection - * @see List - * @see LinkedList - * @see Vector - * @see Collections#synchronizedList(List) - * @see AbstractList - * @status updated to 1.4 - */ -public class ArrayList extends AbstractList - implements List, RandomAccess, Cloneable, Serializable -{ - /** - * Compatible with JDK 1.2 - */ - private static final long serialVersionUID = 8683452581122892189L; - - /** - * The default capacity for new ArrayLists. - */ - private static final int DEFAULT_CAPACITY = 16; - - /** - * The number of elements in this list. - * @serial the list size - */ - private int size; - - /** - * Where the data is stored. - */ - private transient Object[] data; - - /** - * Construct a new ArrayList with the supplied initial capacity. - * - * @param capacity initial capacity of this ArrayList - * @throws IllegalArgumentException if capacity is negative - */ - public ArrayList(int capacity) - { - // Must explicitly check, to get correct exception. - if (capacity < 0) - throw new IllegalArgumentException(); - data = new Object[capacity]; - } - - /** - * Construct a new ArrayList with the default capacity (16). - */ - public ArrayList() - { - this(DEFAULT_CAPACITY); - } - - /** - * Construct a new ArrayList, and initialize it with the elements - * in the supplied Collection. The initial capacity is 110% of the - * Collection's size. - * - * @param c the collection whose elements will initialize this list - * @throws NullPointerException if c is null - */ - public ArrayList(Collection c) - { - this((int) (c.size() * 1.1f)); - addAll(c); - } - - /** - * Trims the capacity of this List to be equal to its size; - * a memory saver. - */ - public void trimToSize() - { - // Not a structural change from the perspective of iterators on this list, - // so don't update modCount. - if (size != data.length) - { - Object[] newData = new Object[size]; - System.arraycopy(data, 0, newData, 0, size); - data = newData; - } - } - - /** - * Guarantees that this list will have at least enough capacity to - * hold minCapacity elements. This implementation will grow the list to - * max(current * 2, minCapacity) if (minCapacity > current). The JCL says - * explictly that "this method increases its capacity to minCap", while - * the JDK 1.3 online docs specify that the list will grow to at least the - * size specified. - * - * @param minCapacity the minimum guaranteed capacity - */ - public void ensureCapacity(int minCapacity) - { - int current = data.length; - - if (minCapacity > current) - { - Object[] newData = new Object[Math.max(current * 2, minCapacity)]; - System.arraycopy(data, 0, newData, 0, size); - data = newData; - } - } - - /** - * Returns the number of elements in this list. - * - * @return the list size - */ - public int size() - { - return size; - } - - /** - * Checks if the list is empty. - * - * @return true if there are no elements - */ - public boolean isEmpty() - { - return size == 0; - } - - /** - * Returns true iff element is in this ArrayList. - * - * @param e the element whose inclusion in the List is being tested - * @return true if the list contains e - */ - public boolean contains(Object e) - { - return indexOf(e) != -1; - } - - /** - * Returns the lowest index at which element appears in this List, or - * -1 if it does not appear. - * - * @param e the element whose inclusion in the List is being tested - * @return the index where e was found - */ - public int indexOf(Object e) - { - for (int i = 0; i < size; i++) - if (equals(e, data[i])) - return i; - return -1; - } - - /** - * Returns the highest index at which element appears in this List, or - * -1 if it does not appear. - * - * @param e the element whose inclusion in the List is being tested - * @return the index where e was found - */ - public int lastIndexOf(Object e) - { - for (int i = size - 1; i >= 0; i--) - if (equals(e, data[i])) - return i; - return -1; - } - - /** - * Creates a shallow copy of this ArrayList (elements are not cloned). - * - * @return the cloned object - */ - public Object clone() - { - ArrayList clone = null; - try - { - clone = (ArrayList) super.clone(); - clone.data = (Object[]) data.clone(); - } - catch (CloneNotSupportedException e) - { - // Impossible to get here. - } - return clone; - } - - /** - * Returns an Object array containing all of the elements in this ArrayList. - * The array is independent of this list. - * - * @return an array representation of this list - */ - public Object[] toArray() - { - Object[] array = new Object[size]; - System.arraycopy(data, 0, array, 0, size); - return array; - } - - /** - * Returns an Array whose component type is the runtime component type of - * the passed-in Array. The returned Array is populated with all of the - * elements in this ArrayList. If the passed-in Array is not large enough - * to store all of the elements in this List, a new Array will be created - * and returned; if the passed-in Array is <i>larger</i> than the size - * of this List, then size() index will be set to null. - * - * @param a the passed-in Array - * @return an array representation of this list - * @throws ArrayStoreException if the runtime type of a does not allow - * an element in this list - * @throws NullPointerException if a is null - */ - public Object[] toArray(Object[] a) - { - if (a.length < size) - a = (Object[]) Array.newInstance(a.getClass().getComponentType(), - size); - else if (a.length > size) - a[size] = null; - System.arraycopy(data, 0, a, 0, size); - return a; - } - - /** - * Retrieves the element at the user-supplied index. - * - * @param index the index of the element we are fetching - * @throws IndexOutOfBoundsException if index < 0 || index >= size() - */ - public Object get(int index) - { - checkBoundExclusive(index); - return data[index]; - } - - /** - * Sets the element at the specified index. The new element, e, - * can be an object of any type or null. - * - * @param index the index at which the element is being set - * @param e the element to be set - * @return the element previously at the specified index - * @throws IndexOutOfBoundsException if index < 0 || index >= 0 - */ - public Object set(int index, Object e) - { - checkBoundExclusive(index); - Object result = data[index]; - data[index] = e; - return result; - } - - /** - * Appends the supplied element to the end of this list. - * The element, e, can be an object of any type or null. - * - * @param e the element to be appended to this list - * @return true, the add will always succeed - */ - public boolean add(Object e) - { - modCount++; - if (size == data.length) - ensureCapacity(size + 1); - data[size++] = e; - return true; - } - - /** - * Adds the supplied element at the specified index, shifting all - * elements currently at that index or higher one to the right. - * The element, e, can be an object of any type or null. - * - * @param index the index at which the element is being added - * @param e the item being added - * @throws IndexOutOfBoundsException if index < 0 || index > size() - */ - public void add(int index, Object e) - { - checkBoundInclusive(index); - modCount++; - if (size == data.length) - ensureCapacity(size + 1); - if (index != size) - System.arraycopy(data, index, data, index + 1, size - index); - data[index] = e; - size++; - } - - /** - * Removes the element at the user-supplied index. - * - * @param index the index of the element to be removed - * @return the removed Object - * @throws IndexOutOfBoundsException if index < 0 || index >= size() - */ - public Object remove(int index) - { - checkBoundExclusive(index); - Object r = data[index]; - modCount++; - if (index != --size) - System.arraycopy(data, index + 1, data, index, size - index); - // Aid for garbage collection by releasing this pointer. - data[size] = null; - return r; - } - - /** - * Removes all elements from this List - */ - public void clear() - { - if (size > 0) - { - modCount++; - // Allow for garbage collection. - Arrays.fill(data, 0, size, null); - size = 0; - } - } - - /** - * Add each element in the supplied Collection to this List. It is undefined - * what happens if you modify the list while this is taking place; for - * example, if the collection contains this list. c can contain objects - * of any type, as well as null values. - * - * @param c a Collection containing elements to be added to this List - * @return true if the list was modified, in other words c is not empty - * @throws NullPointerException if c is null - */ - public boolean addAll(Collection c) - { - return addAll(size, c); - } - - /** - * Add all elements in the supplied collection, inserting them beginning - * at the specified index. c can contain objects of any type, as well - * as null values. - * - * @param index the index at which the elements will be inserted - * @param c the Collection containing the elements to be inserted - * @throws IndexOutOfBoundsException if index < 0 || index > 0 - * @throws NullPointerException if c is null - */ - public boolean addAll(int index, Collection c) - { - checkBoundInclusive(index); - Iterator itr = c.iterator(); - int csize = c.size(); - - modCount++; - if (csize + size > data.length) - ensureCapacity(size + csize); - int end = index + csize; - if (size > 0 && index != size) - System.arraycopy(data, index, data, end, size - index); - size += csize; - for ( ; index < end; index++) - data[index] = itr.next(); - return csize > 0; - } - - /** - * Removes all elements in the half-open interval [fromIndex, toIndex). - * Does nothing when toIndex is equal to fromIndex. - * - * @param fromIndex the first index which will be removed - * @param toIndex one greater than the last index which will be removed - * @throws IndexOutOfBoundsException if fromIndex > toIndex - */ - protected void removeRange(int fromIndex, int toIndex) - { - int change = toIndex - fromIndex; - if (change > 0) - { - modCount++; - System.arraycopy(data, toIndex, data, fromIndex, size - toIndex); - size -= change; - } - else if (change < 0) - throw new IndexOutOfBoundsException(); - } - - /** - * Checks that the index is in the range of possible elements (inclusive). - * - * @param index the index to check - * @throws IndexOutOfBoundsException if index > size - */ - private void checkBoundInclusive(int index) - { - // Implementation note: we do not check for negative ranges here, since - // use of a negative index will cause an ArrayIndexOutOfBoundsException, - // a subclass of the required exception, with no effort on our part. - if (index > size) - throw new IndexOutOfBoundsException("Index: " + index + ", Size: " - + size); - } - - /** - * Checks that the index is in the range of existing elements (exclusive). - * - * @param index the index to check - * @throws IndexOutOfBoundsException if index >= size - */ - private void checkBoundExclusive(int index) - { - // Implementation note: we do not check for negative ranges here, since - // use of a negative index will cause an ArrayIndexOutOfBoundsException, - // a subclass of the required exception, with no effort on our part. - if (index >= size) - throw new IndexOutOfBoundsException("Index: " + index + ", Size: " - + size); - } - - /** - * Remove from this list all elements contained in the given collection. - * This is not public, due to Sun's API, but this performs in linear - * time while the default behavior of AbstractList would be quadratic. - * - * @param c the collection to filter out - * @return true if this list changed - * @throws NullPointerException if c is null - */ - boolean removeAllInternal(Collection c) - { - int i; - int j; - for (i = 0; i < size; i++) - if (c.contains(data[i])) - break; - if (i == size) - return false; - - modCount++; - for (j = i++; i < size; i++) - if (! c.contains(data[i])) - data[j++] = data[i]; - size -= i - j; - return true; - } - - /** - * Retain in this vector only the elements contained in the given collection. - * This is not public, due to Sun's API, but this performs in linear - * time while the default behavior of AbstractList would be quadratic. - * - * @param c the collection to filter by - * @return true if this vector changed - * @throws NullPointerException if c is null - * @since 1.2 - */ - boolean retainAllInternal(Collection c) - { - int i; - int j; - for (i = 0; i < size; i++) - if (! c.contains(data[i])) - break; - if (i == size) - return false; - - modCount++; - for (j = i++; i < size; i++) - if (c.contains(data[i])) - data[j++] = data[i]; - size -= i - j; - return true; - } - - /** - * Serializes this object to the given stream. - * - * @param out the stream to write to - * @throws IOException if the underlying stream fails - * @serialData the size field (int), the length of the backing array - * (int), followed by its elements (Objects) in proper order. - */ - private void writeObject(ObjectOutputStream s) throws IOException - { - // The 'size' field. - s.defaultWriteObject(); - // We serialize unused list entries to preserve capacity. - int len = data.length; - s.writeInt(len); - // it would be more efficient to just write "size" items, - // this need readObject read "size" items too. - for (int i = 0; i < size; i++) - s.writeObject(data[i]); - } - - /** - * Deserializes this object from the given stream. - * - * @param in the stream to read from - * @throws ClassNotFoundException if the underlying stream fails - * @throws IOException if the underlying stream fails - * @serialData the size field (int), the length of the backing array - * (int), followed by its elements (Objects) in proper order. - */ - private void readObject(ObjectInputStream s) - throws IOException, ClassNotFoundException - { - // the `size' field. - s.defaultReadObject(); - int capacity = s.readInt(); - data = new Object[capacity]; - for (int i = 0; i < size; i++) - data[i] = s.readObject(); - } -} diff --git a/libjava/java/util/Arrays.java b/libjava/java/util/Arrays.java deleted file mode 100644 index 15c1a5f33bf..00000000000 --- a/libjava/java/util/Arrays.java +++ /dev/null @@ -1,2510 +0,0 @@ -/* Arrays.java -- Utility class with methods to operate on arrays - Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 - Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util; - -import java.io.Serializable; -import java.lang.reflect.Array; - -/** - * This class contains various static utility methods performing operations on - * arrays, and a method to provide a List "view" of an array to facilitate - * using arrays with Collection-based APIs. All methods throw a - * {@link NullPointerException} if the parameter array is null. - * <p> - * - * Implementations may use their own algorithms, but must obey the general - * properties; for example, the sort must be stable and n*log(n) complexity. - * Sun's implementation of sort, and therefore ours, is a tuned quicksort, - * adapted from Jon L. Bentley and M. Douglas McIlroy's "Engineering a Sort - * Function", Software-Practice and Experience, Vol. 23(11) P. 1249-1265 - * (November 1993). This algorithm offers n*log(n) performance on many data - * sets that cause other quicksorts to degrade to quadratic performance. - * - * @author Original author unknown - * @author Bryce McKinlay - * @author Eric Blake (ebb9@email.byu.edu) - * @see Comparable - * @see Comparator - * @since 1.2 - * @status updated to 1.4 - */ -public class Arrays -{ - /** - * This class is non-instantiable. - */ - private Arrays() - { - } - - -// binarySearch - /** - * Perform a binary search of a byte array for a key. The array must be - * sorted (as by the sort() method) - if it is not, the behaviour of this - * method is undefined, and may be an infinite loop. If the array contains - * the key more than once, any one of them may be found. Note: although the - * specification allows for an infinite loop if the array is unsorted, it - * will not happen in this implementation. - * - * @param a the array to search (must be sorted) - * @param key the value to search for - * @return the index at which the key was found, or -n-1 if it was not - * found, where n is the index of the first value higher than key or - * a.length if there is no such value. - */ - public static int binarySearch(byte[] a, byte key) - { - int low = 0; - int hi = a.length - 1; - int mid = 0; - while (low <= hi) - { - mid = (low + hi) >> 1; - final byte d = a[mid]; - if (d == key) - return mid; - else if (d > key) - hi = mid - 1; - else - // This gets the insertion point right on the last loop. - low = ++mid; - } - return -mid - 1; - } - - /** - * Perform a binary search of a char array for a key. The array must be - * sorted (as by the sort() method) - if it is not, the behaviour of this - * method is undefined, and may be an infinite loop. If the array contains - * the key more than once, any one of them may be found. Note: although the - * specification allows for an infinite loop if the array is unsorted, it - * will not happen in this implementation. - * - * @param a the array to search (must be sorted) - * @param key the value to search for - * @return the index at which the key was found, or -n-1 if it was not - * found, where n is the index of the first value higher than key or - * a.length if there is no such value. - */ - public static int binarySearch(char[] a, char key) - { - int low = 0; - int hi = a.length - 1; - int mid = 0; - while (low <= hi) - { - mid = (low + hi) >> 1; - final char d = a[mid]; - if (d == key) - return mid; - else if (d > key) - hi = mid - 1; - else - // This gets the insertion point right on the last loop. - low = ++mid; - } - return -mid - 1; - } - - /** - * Perform a binary search of a short array for a key. The array must be - * sorted (as by the sort() method) - if it is not, the behaviour of this - * method is undefined, and may be an infinite loop. If the array contains - * the key more than once, any one of them may be found. Note: although the - * specification allows for an infinite loop if the array is unsorted, it - * will not happen in this implementation. - * - * @param a the array to search (must be sorted) - * @param key the value to search for - * @return the index at which the key was found, or -n-1 if it was not - * found, where n is the index of the first value higher than key or - * a.length if there is no such value. - */ - public static int binarySearch(short[] a, short key) - { - int low = 0; - int hi = a.length - 1; - int mid = 0; - while (low <= hi) - { - mid = (low + hi) >> 1; - final short d = a[mid]; - if (d == key) - return mid; - else if (d > key) - hi = mid - 1; - else - // This gets the insertion point right on the last loop. - low = ++mid; - } - return -mid - 1; - } - - /** - * Perform a binary search of an int array for a key. The array must be - * sorted (as by the sort() method) - if it is not, the behaviour of this - * method is undefined, and may be an infinite loop. If the array contains - * the key more than once, any one of them may be found. Note: although the - * specification allows for an infinite loop if the array is unsorted, it - * will not happen in this implementation. - * - * @param a the array to search (must be sorted) - * @param key the value to search for - * @return the index at which the key was found, or -n-1 if it was not - * found, where n is the index of the first value higher than key or - * a.length if there is no such value. - */ - public static int binarySearch(int[] a, int key) - { - int low = 0; - int hi = a.length - 1; - int mid = 0; - while (low <= hi) - { - mid = (low + hi) >> 1; - final int d = a[mid]; - if (d == key) - return mid; - else if (d > key) - hi = mid - 1; - else - // This gets the insertion point right on the last loop. - low = ++mid; - } - return -mid - 1; - } - - /** - * Perform a binary search of a long array for a key. The array must be - * sorted (as by the sort() method) - if it is not, the behaviour of this - * method is undefined, and may be an infinite loop. If the array contains - * the key more than once, any one of them may be found. Note: although the - * specification allows for an infinite loop if the array is unsorted, it - * will not happen in this implementation. - * - * @param a the array to search (must be sorted) - * @param key the value to search for - * @return the index at which the key was found, or -n-1 if it was not - * found, where n is the index of the first value higher than key or - * a.length if there is no such value. - */ - public static int binarySearch(long[] a, long key) - { - int low = 0; - int hi = a.length - 1; - int mid = 0; - while (low <= hi) - { - mid = (low + hi) >> 1; - final long d = a[mid]; - if (d == key) - return mid; - else if (d > key) - hi = mid - 1; - else - // This gets the insertion point right on the last loop. - low = ++mid; - } - return -mid - 1; - } - - /** - * Perform a binary search of a float array for a key. The array must be - * sorted (as by the sort() method) - if it is not, the behaviour of this - * method is undefined, and may be an infinite loop. If the array contains - * the key more than once, any one of them may be found. Note: although the - * specification allows for an infinite loop if the array is unsorted, it - * will not happen in this implementation. - * - * @param a the array to search (must be sorted) - * @param key the value to search for - * @return the index at which the key was found, or -n-1 if it was not - * found, where n is the index of the first value higher than key or - * a.length if there is no such value. - */ - public static int binarySearch(float[] a, float key) - { - // Must use Float.compare to take into account NaN, +-0. - int low = 0; - int hi = a.length - 1; - int mid = 0; - while (low <= hi) - { - mid = (low + hi) >> 1; - final int r = Float.compare(a[mid], key); - if (r == 0) - return mid; - else if (r > 0) - hi = mid - 1; - else - // This gets the insertion point right on the last loop - low = ++mid; - } - return -mid - 1; - } - - /** - * Perform a binary search of a double array for a key. The array must be - * sorted (as by the sort() method) - if it is not, the behaviour of this - * method is undefined, and may be an infinite loop. If the array contains - * the key more than once, any one of them may be found. Note: although the - * specification allows for an infinite loop if the array is unsorted, it - * will not happen in this implementation. - * - * @param a the array to search (must be sorted) - * @param key the value to search for - * @return the index at which the key was found, or -n-1 if it was not - * found, where n is the index of the first value higher than key or - * a.length if there is no such value. - */ - public static int binarySearch(double[] a, double key) - { - // Must use Double.compare to take into account NaN, +-0. - int low = 0; - int hi = a.length - 1; - int mid = 0; - while (low <= hi) - { - mid = (low + hi) >> 1; - final int r = Double.compare(a[mid], key); - if (r == 0) - return mid; - else if (r > 0) - hi = mid - 1; - else - // This gets the insertion point right on the last loop - low = ++mid; - } - return -mid - 1; - } - - /** - * Perform a binary search of an Object array for a key, using the natural - * ordering of the elements. The array must be sorted (as by the sort() - * method) - if it is not, the behaviour of this method is undefined, and may - * be an infinite loop. Further, the key must be comparable with every item - * in the array. If the array contains the key more than once, any one of - * them may be found. Note: although the specification allows for an infinite - * loop if the array is unsorted, it will not happen in this (JCL) - * implementation. - * - * @param a the array to search (must be sorted) - * @param key the value to search for - * @return the index at which the key was found, or -n-1 if it was not - * found, where n is the index of the first value higher than key or - * a.length if there is no such value. - * @throws ClassCastException if key could not be compared with one of the - * elements of a - * @throws NullPointerException if a null element in a is compared - */ - public static int binarySearch(Object[] a, Object key) - { - return binarySearch(a, key, null); - } - - /** - * Perform a binary search of an Object array for a key, using a supplied - * Comparator. The array must be sorted (as by the sort() method with the - * same Comparator) - if it is not, the behaviour of this method is - * undefined, and may be an infinite loop. Further, the key must be - * comparable with every item in the array. If the array contains the key - * more than once, any one of them may be found. Note: although the - * specification allows for an infinite loop if the array is unsorted, it - * will not happen in this (JCL) implementation. - * - * @param a the array to search (must be sorted) - * @param key the value to search for - * @param c the comparator by which the array is sorted; or null to - * use the elements' natural order - * @return the index at which the key was found, or -n-1 if it was not - * found, where n is the index of the first value higher than key or - * a.length if there is no such value. - * @throws ClassCastException if key could not be compared with one of the - * elements of a - * @throws NullPointerException if a null element is compared with natural - * ordering (only possible when c is null) - */ - public static int binarySearch(Object[] a, Object key, Comparator c) - { - int low = 0; - int hi = a.length - 1; - int mid = 0; - while (low <= hi) - { - mid = (low + hi) >> 1; - final int d = Collections.compare(key, a[mid], c); - if (d == 0) - return mid; - else if (d < 0) - hi = mid - 1; - else - // This gets the insertion point right on the last loop - low = ++mid; - } - return -mid - 1; - } - - -// equals - /** - * Compare two boolean arrays for equality. - * - * @param a1 the first array to compare - * @param a2 the second array to compare - * @return true if a1 and a2 are both null, or if a2 is of the same length - * as a1, and for each 0 <= i < a1.length, a1[i] == a2[i] - */ - public static boolean equals(boolean[] a1, boolean[] a2) - { - // Quick test which saves comparing elements of the same array, and also - // catches the case that both are null. - if (a1 == a2) - return true; - - if (null == a1 || null == a2) - return false; - - // If they're the same length, test each element - if (a1.length == a2.length) - { - int i = a1.length; - while (--i >= 0) - if (a1[i] != a2[i]) - return false; - return true; - } - return false; - } - - /** - * Compare two byte arrays for equality. - * - * @param a1 the first array to compare - * @param a2 the second array to compare - * @return true if a1 and a2 are both null, or if a2 is of the same length - * as a1, and for each 0 <= i < a1.length, a1[i] == a2[i] - */ - public static boolean equals(byte[] a1, byte[] a2) - { - // Quick test which saves comparing elements of the same array, and also - // catches the case that both are null. - if (a1 == a2) - return true; - - if (null == a1 || null == a2) - return false; - - // If they're the same length, test each element - if (a1.length == a2.length) - { - int i = a1.length; - while (--i >= 0) - if (a1[i] != a2[i]) - return false; - return true; - } - return false; - } - - /** - * Compare two char arrays for equality. - * - * @param a1 the first array to compare - * @param a2 the second array to compare - * @return true if a1 and a2 are both null, or if a2 is of the same length - * as a1, and for each 0 <= i < a1.length, a1[i] == a2[i] - */ - public static boolean equals(char[] a1, char[] a2) - { - // Quick test which saves comparing elements of the same array, and also - // catches the case that both are null. - if (a1 == a2) - return true; - - if (null == a1 || null == a2) - return false; - - // If they're the same length, test each element - if (a1.length == a2.length) - { - int i = a1.length; - while (--i >= 0) - if (a1[i] != a2[i]) - return false; - return true; - } - return false; - } - - /** - * Compare two short arrays for equality. - * - * @param a1 the first array to compare - * @param a2 the second array to compare - * @return true if a1 and a2 are both null, or if a2 is of the same length - * as a1, and for each 0 <= i < a1.length, a1[i] == a2[i] - */ - public static boolean equals(short[] a1, short[] a2) - { - // Quick test which saves comparing elements of the same array, and also - // catches the case that both are null. - if (a1 == a2) - return true; - - if (null == a1 || null == a2) - return false; - - // If they're the same length, test each element - if (a1.length == a2.length) - { - int i = a1.length; - while (--i >= 0) - if (a1[i] != a2[i]) - return false; - return true; - } - return false; - } - - /** - * Compare two int arrays for equality. - * - * @param a1 the first array to compare - * @param a2 the second array to compare - * @return true if a1 and a2 are both null, or if a2 is of the same length - * as a1, and for each 0 <= i < a1.length, a1[i] == a2[i] - */ - public static boolean equals(int[] a1, int[] a2) - { - // Quick test which saves comparing elements of the same array, and also - // catches the case that both are null. - if (a1 == a2) - return true; - - if (null == a1 || null == a2) - return false; - - // If they're the same length, test each element - if (a1.length == a2.length) - { - int i = a1.length; - while (--i >= 0) - if (a1[i] != a2[i]) - return false; - return true; - } - return false; - } - - /** - * Compare two long arrays for equality. - * - * @param a1 the first array to compare - * @param a2 the second array to compare - * @return true if a1 and a2 are both null, or if a2 is of the same length - * as a1, and for each 0 <= i < a1.length, a1[i] == a2[i] - */ - public static boolean equals(long[] a1, long[] a2) - { - // Quick test which saves comparing elements of the same array, and also - // catches the case that both are null. - if (a1 == a2) - return true; - - if (null == a1 || null == a2) - return false; - - // If they're the same length, test each element - if (a1.length == a2.length) - { - int i = a1.length; - while (--i >= 0) - if (a1[i] != a2[i]) - return false; - return true; - } - return false; - } - - /** - * Compare two float arrays for equality. - * - * @param a1 the first array to compare - * @param a2 the second array to compare - * @return true if a1 and a2 are both null, or if a2 is of the same length - * as a1, and for each 0 <= i < a1.length, a1[i] == a2[i] - */ - public static boolean equals(float[] a1, float[] a2) - { - // Quick test which saves comparing elements of the same array, and also - // catches the case that both are null. - if (a1 == a2) - return true; - - if (null == a1 || null == a2) - return false; - - // Must use Float.compare to take into account NaN, +-0. - // If they're the same length, test each element - if (a1.length == a2.length) - { - int i = a1.length; - while (--i >= 0) - if (Float.compare(a1[i], a2[i]) != 0) - return false; - return true; - } - return false; - } - - /** - * Compare two double arrays for equality. - * - * @param a1 the first array to compare - * @param a2 the second array to compare - * @return true if a1 and a2 are both null, or if a2 is of the same length - * as a1, and for each 0 <= i < a1.length, a1[i] == a2[i] - */ - public static boolean equals(double[] a1, double[] a2) - { - // Quick test which saves comparing elements of the same array, and also - // catches the case that both are null. - if (a1 == a2) - return true; - - if (null == a1 || null == a2) - return false; - - // Must use Double.compare to take into account NaN, +-0. - // If they're the same length, test each element - if (a1.length == a2.length) - { - int i = a1.length; - while (--i >= 0) - if (Double.compare(a1[i], a2[i]) != 0) - return false; - return true; - } - return false; - } - - /** - * Compare two Object arrays for equality. - * - * @param a1 the first array to compare - * @param a2 the second array to compare - * @return true if a1 and a2 are both null, or if a1 is of the same length - * as a2, and for each 0 <= i < a.length, a1[i] == null ? - * a2[i] == null : a1[i].equals(a2[i]). - */ - public static boolean equals(Object[] a1, Object[] a2) - { - // Quick test which saves comparing elements of the same array, and also - // catches the case that both are null. - if (a1 == a2) - return true; - - if (null == a1 || null == a2) - return false; - - // If they're the same length, test each element - if (a1.length == a2.length) - { - int i = a1.length; - while (--i >= 0) - if (! AbstractCollection.equals(a1[i], a2[i])) - return false; - return true; - } - return false; - } - - -// fill - /** - * Fill an array with a boolean value. - * - * @param a the array to fill - * @param val the value to fill it with - */ - public static void fill(boolean[] a, boolean val) - { - fill(a, 0, a.length, val); - } - - /** - * Fill a range of an array with a boolean value. - * - * @param a the array to fill - * @param fromIndex the index to fill from, inclusive - * @param toIndex the index to fill to, exclusive - * @param val the value to fill with - * @throws IllegalArgumentException if fromIndex > toIndex - * @throws ArrayIndexOutOfBoundsException if fromIndex < 0 - * || toIndex > a.length - */ - public static void fill(boolean[] a, int fromIndex, int toIndex, boolean val) - { - if (fromIndex > toIndex) - throw new IllegalArgumentException(); - for (int i = fromIndex; i < toIndex; i++) - a[i] = val; - } - - /** - * Fill an array with a byte value. - * - * @param a the array to fill - * @param val the value to fill it with - */ - public static void fill(byte[] a, byte val) - { - fill(a, 0, a.length, val); - } - - /** - * Fill a range of an array with a byte value. - * - * @param a the array to fill - * @param fromIndex the index to fill from, inclusive - * @param toIndex the index to fill to, exclusive - * @param val the value to fill with - * @throws IllegalArgumentException if fromIndex > toIndex - * @throws ArrayIndexOutOfBoundsException if fromIndex < 0 - * || toIndex > a.length - */ - public static void fill(byte[] a, int fromIndex, int toIndex, byte val) - { - if (fromIndex > toIndex) - throw new IllegalArgumentException(); - for (int i = fromIndex; i < toIndex; i++) - a[i] = val; - } - - /** - * Fill an array with a char value. - * - * @param a the array to fill - * @param val the value to fill it with - */ - public static void fill(char[] a, char val) - { - fill(a, 0, a.length, val); - } - - /** - * Fill a range of an array with a char value. - * - * @param a the array to fill - * @param fromIndex the index to fill from, inclusive - * @param toIndex the index to fill to, exclusive - * @param val the value to fill with - * @throws IllegalArgumentException if fromIndex > toIndex - * @throws ArrayIndexOutOfBoundsException if fromIndex < 0 - * || toIndex > a.length - */ - public static void fill(char[] a, int fromIndex, int toIndex, char val) - { - if (fromIndex > toIndex) - throw new IllegalArgumentException(); - for (int i = fromIndex; i < toIndex; i++) - a[i] = val; - } - - /** - * Fill an array with a short value. - * - * @param a the array to fill - * @param val the value to fill it with - */ - public static void fill(short[] a, short val) - { - fill(a, 0, a.length, val); - } - - /** - * Fill a range of an array with a short value. - * - * @param a the array to fill - * @param fromIndex the index to fill from, inclusive - * @param toIndex the index to fill to, exclusive - * @param val the value to fill with - * @throws IllegalArgumentException if fromIndex > toIndex - * @throws ArrayIndexOutOfBoundsException if fromIndex < 0 - * || toIndex > a.length - */ - public static void fill(short[] a, int fromIndex, int toIndex, short val) - { - if (fromIndex > toIndex) - throw new IllegalArgumentException(); - for (int i = fromIndex; i < toIndex; i++) - a[i] = val; - } - - /** - * Fill an array with an int value. - * - * @param a the array to fill - * @param val the value to fill it with - */ - public static void fill(int[] a, int val) - { - fill(a, 0, a.length, val); - } - - /** - * Fill a range of an array with an int value. - * - * @param a the array to fill - * @param fromIndex the index to fill from, inclusive - * @param toIndex the index to fill to, exclusive - * @param val the value to fill with - * @throws IllegalArgumentException if fromIndex > toIndex - * @throws ArrayIndexOutOfBoundsException if fromIndex < 0 - * || toIndex > a.length - */ - public static void fill(int[] a, int fromIndex, int toIndex, int val) - { - if (fromIndex > toIndex) - throw new IllegalArgumentException(); - for (int i = fromIndex; i < toIndex; i++) - a[i] = val; - } - - /** - * Fill an array with a long value. - * - * @param a the array to fill - * @param val the value to fill it with - */ - public static void fill(long[] a, long val) - { - fill(a, 0, a.length, val); - } - - /** - * Fill a range of an array with a long value. - * - * @param a the array to fill - * @param fromIndex the index to fill from, inclusive - * @param toIndex the index to fill to, exclusive - * @param val the value to fill with - * @throws IllegalArgumentException if fromIndex > toIndex - * @throws ArrayIndexOutOfBoundsException if fromIndex < 0 - * || toIndex > a.length - */ - public static void fill(long[] a, int fromIndex, int toIndex, long val) - { - if (fromIndex > toIndex) - throw new IllegalArgumentException(); - for (int i = fromIndex; i < toIndex; i++) - a[i] = val; - } - - /** - * Fill an array with a float value. - * - * @param a the array to fill - * @param val the value to fill it with - */ - public static void fill(float[] a, float val) - { - fill(a, 0, a.length, val); - } - - /** - * Fill a range of an array with a float value. - * - * @param a the array to fill - * @param fromIndex the index to fill from, inclusive - * @param toIndex the index to fill to, exclusive - * @param val the value to fill with - * @throws IllegalArgumentException if fromIndex > toIndex - * @throws ArrayIndexOutOfBoundsException if fromIndex < 0 - * || toIndex > a.length - */ - public static void fill(float[] a, int fromIndex, int toIndex, float val) - { - if (fromIndex > toIndex) - throw new IllegalArgumentException(); - for (int i = fromIndex; i < toIndex; i++) - a[i] = val; - } - - /** - * Fill an array with a double value. - * - * @param a the array to fill - * @param val the value to fill it with - */ - public static void fill(double[] a, double val) - { - fill(a, 0, a.length, val); - } - - /** - * Fill a range of an array with a double value. - * - * @param a the array to fill - * @param fromIndex the index to fill from, inclusive - * @param toIndex the index to fill to, exclusive - * @param val the value to fill with - * @throws IllegalArgumentException if fromIndex > toIndex - * @throws ArrayIndexOutOfBoundsException if fromIndex < 0 - * || toIndex > a.length - */ - public static void fill(double[] a, int fromIndex, int toIndex, double val) - { - if (fromIndex > toIndex) - throw new IllegalArgumentException(); - for (int i = fromIndex; i < toIndex; i++) - a[i] = val; - } - - /** - * Fill an array with an Object value. - * - * @param a the array to fill - * @param val the value to fill it with - * @throws ClassCastException if val is not an instance of the element - * type of a. - */ - public static void fill(Object[] a, Object val) - { - fill(a, 0, a.length, val); - } - - /** - * Fill a range of an array with an Object value. - * - * @param a the array to fill - * @param fromIndex the index to fill from, inclusive - * @param toIndex the index to fill to, exclusive - * @param val the value to fill with - * @throws ClassCastException if val is not an instance of the element - * type of a. - * @throws IllegalArgumentException if fromIndex > toIndex - * @throws ArrayIndexOutOfBoundsException if fromIndex < 0 - * || toIndex > a.length - */ - public static void fill(Object[] a, int fromIndex, int toIndex, Object val) - { - if (fromIndex > toIndex) - throw new IllegalArgumentException(); - for (int i = fromIndex; i < toIndex; i++) - a[i] = val; - } - - -// sort - // Thanks to Paul Fisher (rao@gnu.org) for finding this quicksort algorithm - // as specified by Sun and porting it to Java. The algorithm is an optimised - // quicksort, as described in Jon L. Bentley and M. Douglas McIlroy's - // "Engineering a Sort Function", Software-Practice and Experience, Vol. - // 23(11) P. 1249-1265 (November 1993). This algorithm gives n*log(n) - // performance on many arrays that would take quadratic time with a standard - // quicksort. - - /** - * Performs a stable sort on the elements, arranging them according to their - * natural order. - * - * @param a the byte array to sort - */ - public static void sort(byte[] a) - { - qsort(a, 0, a.length); - } - - /** - * Performs a stable sort on the elements, arranging them according to their - * natural order. - * - * @param a the byte array to sort - * @param fromIndex the first index to sort (inclusive) - * @param toIndex the last index to sort (exclusive) - * @throws IllegalArgumentException if fromIndex > toIndex - * @throws ArrayIndexOutOfBoundsException if fromIndex < 0 - * || toIndex > a.length - */ - public static void sort(byte[] a, int fromIndex, int toIndex) - { - if (fromIndex > toIndex) - throw new IllegalArgumentException(); - if (fromIndex < 0) - throw new ArrayIndexOutOfBoundsException(); - qsort(a, fromIndex, toIndex - fromIndex); - } - - /** - * Finds the index of the median of three array elements. - * - * @param a the first index - * @param b the second index - * @param c the third index - * @param d the array - * @return the index (a, b, or c) which has the middle value of the three - */ - private static int med3(int a, int b, int c, byte[] d) - { - return (d[a] < d[b] - ? (d[b] < d[c] ? b : d[a] < d[c] ? c : a) - : (d[b] > d[c] ? b : d[a] > d[c] ? c : a)); - } - - /** - * Swaps the elements at two locations of an array - * - * @param i the first index - * @param j the second index - * @param a the array - */ - private static void swap(int i, int j, byte[] a) - { - byte c = a[i]; - a[i] = a[j]; - a[j] = c; - } - - /** - * Swaps two ranges of an array. - * - * @param i the first range start - * @param j the second range start - * @param n the element count - * @param a the array - */ - private static void vecswap(int i, int j, int n, byte[] a) - { - for ( ; n > 0; i++, j++, n--) - swap(i, j, a); - } - - /** - * Performs a recursive modified quicksort. - * - * @param array the array to sort - * @param from the start index (inclusive) - * @param count the number of elements to sort - */ - private static void qsort(byte[] array, int from, int count) - { - // Use an insertion sort on small arrays. - if (count <= 7) - { - for (int i = from + 1; i < from + count; i++) - for (int j = i; j > from && array[j - 1] > array[j]; j--) - swap(j, j - 1, array); - return; - } - - // Determine a good median element. - int mid = count / 2; - int lo = from; - int hi = from + count - 1; - - if (count > 40) - { // big arrays, pseudomedian of 9 - int s = count / 8; - lo = med3(lo, lo + s, lo + 2 * s, array); - mid = med3(mid - s, mid, mid + s, array); - hi = med3(hi - 2 * s, hi - s, hi, array); - } - mid = med3(lo, mid, hi, array); - - int a, b, c, d; - int comp; - - // Pull the median element out of the fray, and use it as a pivot. - swap(from, mid, array); - a = b = from; - c = d = from + count - 1; - - // Repeatedly move b and c to each other, swapping elements so - // that all elements before index b are less than the pivot, and all - // elements after index c are greater than the pivot. a and b track - // the elements equal to the pivot. - while (true) - { - while (b <= c && (comp = array[b] - array[from]) <= 0) - { - if (comp == 0) - { - swap(a, b, array); - a++; - } - b++; - } - while (c >= b && (comp = array[c] - array[from]) >= 0) - { - if (comp == 0) - { - swap(c, d, array); - d--; - } - c--; - } - if (b > c) - break; - swap(b, c, array); - b++; - c--; - } - - // Swap pivot(s) back in place, the recurse on left and right sections. - hi = from + count; - int span; - span = Math.min(a - from, b - a); - vecswap(from, b - span, span, array); - - span = Math.min(d - c, hi - d - 1); - vecswap(b, hi - span, span, array); - - span = b - a; - if (span > 1) - qsort(array, from, span); - - span = d - c; - if (span > 1) - qsort(array, hi - span, span); - } - - /** - * Performs a stable sort on the elements, arranging them according to their - * natural order. - * - * @param a the char array to sort - */ - public static void sort(char[] a) - { - qsort(a, 0, a.length); - } - - /** - * Performs a stable sort on the elements, arranging them according to their - * natural order. - * - * @param a the char array to sort - * @param fromIndex the first index to sort (inclusive) - * @param toIndex the last index to sort (exclusive) - * @throws IllegalArgumentException if fromIndex > toIndex - * @throws ArrayIndexOutOfBoundsException if fromIndex < 0 - * || toIndex > a.length - */ - public static void sort(char[] a, int fromIndex, int toIndex) - { - if (fromIndex > toIndex) - throw new IllegalArgumentException(); - if (fromIndex < 0) - throw new ArrayIndexOutOfBoundsException(); - qsort(a, fromIndex, toIndex - fromIndex); - } - - /** - * Finds the index of the median of three array elements. - * - * @param a the first index - * @param b the second index - * @param c the third index - * @param d the array - * @return the index (a, b, or c) which has the middle value of the three - */ - private static int med3(int a, int b, int c, char[] d) - { - return (d[a] < d[b] - ? (d[b] < d[c] ? b : d[a] < d[c] ? c : a) - : (d[b] > d[c] ? b : d[a] > d[c] ? c : a)); - } - - /** - * Swaps the elements at two locations of an array - * - * @param i the first index - * @param j the second index - * @param a the array - */ - private static void swap(int i, int j, char[] a) - { - char c = a[i]; - a[i] = a[j]; - a[j] = c; - } - - /** - * Swaps two ranges of an array. - * - * @param i the first range start - * @param j the second range start - * @param n the element count - * @param a the array - */ - private static void vecswap(int i, int j, int n, char[] a) - { - for ( ; n > 0; i++, j++, n--) - swap(i, j, a); - } - - /** - * Performs a recursive modified quicksort. - * - * @param array the array to sort - * @param from the start index (inclusive) - * @param count the number of elements to sort - */ - private static void qsort(char[] array, int from, int count) - { - // Use an insertion sort on small arrays. - if (count <= 7) - { - for (int i = from + 1; i < from + count; i++) - for (int j = i; j > from && array[j - 1] > array[j]; j--) - swap(j, j - 1, array); - return; - } - - // Determine a good median element. - int mid = count / 2; - int lo = from; - int hi = from + count - 1; - - if (count > 40) - { // big arrays, pseudomedian of 9 - int s = count / 8; - lo = med3(lo, lo + s, lo + 2 * s, array); - mid = med3(mid - s, mid, mid + s, array); - hi = med3(hi - 2 * s, hi - s, hi, array); - } - mid = med3(lo, mid, hi, array); - - int a, b, c, d; - int comp; - - // Pull the median element out of the fray, and use it as a pivot. - swap(from, mid, array); - a = b = from; - c = d = from + count - 1; - - // Repeatedly move b and c to each other, swapping elements so - // that all elements before index b are less than the pivot, and all - // elements after index c are greater than the pivot. a and b track - // the elements equal to the pivot. - while (true) - { - while (b <= c && (comp = array[b] - array[from]) <= 0) - { - if (comp == 0) - { - swap(a, b, array); - a++; - } - b++; - } - while (c >= b && (comp = array[c] - array[from]) >= 0) - { - if (comp == 0) - { - swap(c, d, array); - d--; - } - c--; - } - if (b > c) - break; - swap(b, c, array); - b++; - c--; - } - - // Swap pivot(s) back in place, the recurse on left and right sections. - hi = from + count; - int span; - span = Math.min(a - from, b - a); - vecswap(from, b - span, span, array); - - span = Math.min(d - c, hi - d - 1); - vecswap(b, hi - span, span, array); - - span = b - a; - if (span > 1) - qsort(array, from, span); - - span = d - c; - if (span > 1) - qsort(array, hi - span, span); - } - - /** - * Performs a stable sort on the elements, arranging them according to their - * natural order. - * - * @param a the short array to sort - */ - public static void sort(short[] a) - { - qsort(a, 0, a.length); - } - - /** - * Performs a stable sort on the elements, arranging them according to their - * natural order. - * - * @param a the short array to sort - * @param fromIndex the first index to sort (inclusive) - * @param toIndex the last index to sort (exclusive) - * @throws IllegalArgumentException if fromIndex > toIndex - * @throws ArrayIndexOutOfBoundsException if fromIndex < 0 - * || toIndex > a.length - */ - public static void sort(short[] a, int fromIndex, int toIndex) - { - if (fromIndex > toIndex) - throw new IllegalArgumentException(); - if (fromIndex < 0) - throw new ArrayIndexOutOfBoundsException(); - qsort(a, fromIndex, toIndex - fromIndex); - } - - /** - * Finds the index of the median of three array elements. - * - * @param a the first index - * @param b the second index - * @param c the third index - * @param d the array - * @return the index (a, b, or c) which has the middle value of the three - */ - private static int med3(int a, int b, int c, short[] d) - { - return (d[a] < d[b] - ? (d[b] < d[c] ? b : d[a] < d[c] ? c : a) - : (d[b] > d[c] ? b : d[a] > d[c] ? c : a)); - } - - /** - * Swaps the elements at two locations of an array - * - * @param i the first index - * @param j the second index - * @param a the array - */ - private static void swap(int i, int j, short[] a) - { - short c = a[i]; - a[i] = a[j]; - a[j] = c; - } - - /** - * Swaps two ranges of an array. - * - * @param i the first range start - * @param j the second range start - * @param n the element count - * @param a the array - */ - private static void vecswap(int i, int j, int n, short[] a) - { - for ( ; n > 0; i++, j++, n--) - swap(i, j, a); - } - - /** - * Performs a recursive modified quicksort. - * - * @param array the array to sort - * @param from the start index (inclusive) - * @param count the number of elements to sort - */ - private static void qsort(short[] array, int from, int count) - { - // Use an insertion sort on small arrays. - if (count <= 7) - { - for (int i = from + 1; i < from + count; i++) - for (int j = i; j > from && array[j - 1] > array[j]; j--) - swap(j, j - 1, array); - return; - } - - // Determine a good median element. - int mid = count / 2; - int lo = from; - int hi = from + count - 1; - - if (count > 40) - { // big arrays, pseudomedian of 9 - int s = count / 8; - lo = med3(lo, lo + s, lo + 2 * s, array); - mid = med3(mid - s, mid, mid + s, array); - hi = med3(hi - 2 * s, hi - s, hi, array); - } - mid = med3(lo, mid, hi, array); - - int a, b, c, d; - int comp; - - // Pull the median element out of the fray, and use it as a pivot. - swap(from, mid, array); - a = b = from; - c = d = from + count - 1; - - // Repeatedly move b and c to each other, swapping elements so - // that all elements before index b are less than the pivot, and all - // elements after index c are greater than the pivot. a and b track - // the elements equal to the pivot. - while (true) - { - while (b <= c && (comp = array[b] - array[from]) <= 0) - { - if (comp == 0) - { - swap(a, b, array); - a++; - } - b++; - } - while (c >= b && (comp = array[c] - array[from]) >= 0) - { - if (comp == 0) - { - swap(c, d, array); - d--; - } - c--; - } - if (b > c) - break; - swap(b, c, array); - b++; - c--; - } - - // Swap pivot(s) back in place, the recurse on left and right sections. - hi = from + count; - int span; - span = Math.min(a - from, b - a); - vecswap(from, b - span, span, array); - - span = Math.min(d - c, hi - d - 1); - vecswap(b, hi - span, span, array); - - span = b - a; - if (span > 1) - qsort(array, from, span); - - span = d - c; - if (span > 1) - qsort(array, hi - span, span); - } - - /** - * Performs a stable sort on the elements, arranging them according to their - * natural order. - * - * @param a the int array to sort - */ - public static void sort(int[] a) - { - qsort(a, 0, a.length); - } - - /** - * Performs a stable sort on the elements, arranging them according to their - * natural order. - * - * @param a the int array to sort - * @param fromIndex the first index to sort (inclusive) - * @param toIndex the last index to sort (exclusive) - * @throws IllegalArgumentException if fromIndex > toIndex - * @throws ArrayIndexOutOfBoundsException if fromIndex < 0 - * || toIndex > a.length - */ - public static void sort(int[] a, int fromIndex, int toIndex) - { - if (fromIndex > toIndex) - throw new IllegalArgumentException(); - if (fromIndex < 0) - throw new ArrayIndexOutOfBoundsException(); - qsort(a, fromIndex, toIndex - fromIndex); - } - - /** - * Finds the index of the median of three array elements. - * - * @param a the first index - * @param b the second index - * @param c the third index - * @param d the array - * @return the index (a, b, or c) which has the middle value of the three - */ - private static int med3(int a, int b, int c, int[] d) - { - return (d[a] < d[b] - ? (d[b] < d[c] ? b : d[a] < d[c] ? c : a) - : (d[b] > d[c] ? b : d[a] > d[c] ? c : a)); - } - - /** - * Swaps the elements at two locations of an array - * - * @param i the first index - * @param j the second index - * @param a the array - */ - private static void swap(int i, int j, int[] a) - { - int c = a[i]; - a[i] = a[j]; - a[j] = c; - } - - /** - * Swaps two ranges of an array. - * - * @param i the first range start - * @param j the second range start - * @param n the element count - * @param a the array - */ - private static void vecswap(int i, int j, int n, int[] a) - { - for ( ; n > 0; i++, j++, n--) - swap(i, j, a); - } - - /** - * Compares two integers in natural order, since a - b is inadequate. - * - * @param a the first int - * @param b the second int - * @return < 0, 0, or > 0 accorting to the comparison - */ - private static int compare(int a, int b) - { - return a < b ? -1 : a == b ? 0 : 1; - } - - /** - * Performs a recursive modified quicksort. - * - * @param array the array to sort - * @param from the start index (inclusive) - * @param count the number of elements to sort - */ - private static void qsort(int[] array, int from, int count) - { - // Use an insertion sort on small arrays. - if (count <= 7) - { - for (int i = from + 1; i < from + count; i++) - for (int j = i; j > from && array[j - 1] > array[j]; j--) - swap(j, j - 1, array); - return; - } - - // Determine a good median element. - int mid = count / 2; - int lo = from; - int hi = from + count - 1; - - if (count > 40) - { // big arrays, pseudomedian of 9 - int s = count / 8; - lo = med3(lo, lo + s, lo + 2 * s, array); - mid = med3(mid - s, mid, mid + s, array); - hi = med3(hi - 2 * s, hi - s, hi, array); - } - mid = med3(lo, mid, hi, array); - - int a, b, c, d; - int comp; - - // Pull the median element out of the fray, and use it as a pivot. - swap(from, mid, array); - a = b = from; - c = d = from + count - 1; - - // Repeatedly move b and c to each other, swapping elements so - // that all elements before index b are less than the pivot, and all - // elements after index c are greater than the pivot. a and b track - // the elements equal to the pivot. - while (true) - { - while (b <= c && (comp = compare(array[b], array[from])) <= 0) - { - if (comp == 0) - { - swap(a, b, array); - a++; - } - b++; - } - while (c >= b && (comp = compare(array[c], array[from])) >= 0) - { - if (comp == 0) - { - swap(c, d, array); - d--; - } - c--; - } - if (b > c) - break; - swap(b, c, array); - b++; - c--; - } - - // Swap pivot(s) back in place, the recurse on left and right sections. - hi = from + count; - int span; - span = Math.min(a - from, b - a); - vecswap(from, b - span, span, array); - - span = Math.min(d - c, hi - d - 1); - vecswap(b, hi - span, span, array); - - span = b - a; - if (span > 1) - qsort(array, from, span); - - span = d - c; - if (span > 1) - qsort(array, hi - span, span); - } - - /** - * Performs a stable sort on the elements, arranging them according to their - * natural order. - * - * @param a the long array to sort - */ - public static void sort(long[] a) - { - qsort(a, 0, a.length); - } - - /** - * Performs a stable sort on the elements, arranging them according to their - * natural order. - * - * @param a the long array to sort - * @param fromIndex the first index to sort (inclusive) - * @param toIndex the last index to sort (exclusive) - * @throws IllegalArgumentException if fromIndex > toIndex - * @throws ArrayIndexOutOfBoundsException if fromIndex < 0 - * || toIndex > a.length - */ - public static void sort(long[] a, int fromIndex, int toIndex) - { - if (fromIndex > toIndex) - throw new IllegalArgumentException(); - if (fromIndex < 0) - throw new ArrayIndexOutOfBoundsException(); - qsort(a, fromIndex, toIndex - fromIndex); - } - - /** - * Finds the index of the median of three array elements. - * - * @param a the first index - * @param b the second index - * @param c the third index - * @param d the array - * @return the index (a, b, or c) which has the middle value of the three - */ - private static int med3(int a, int b, int c, long[] d) - { - return (d[a] < d[b] - ? (d[b] < d[c] ? b : d[a] < d[c] ? c : a) - : (d[b] > d[c] ? b : d[a] > d[c] ? c : a)); - } - - /** - * Swaps the elements at two locations of an array - * - * @param i the first index - * @param j the second index - * @param a the array - */ - private static void swap(int i, int j, long[] a) - { - long c = a[i]; - a[i] = a[j]; - a[j] = c; - } - - /** - * Swaps two ranges of an array. - * - * @param i the first range start - * @param j the second range start - * @param n the element count - * @param a the array - */ - private static void vecswap(int i, int j, int n, long[] a) - { - for ( ; n > 0; i++, j++, n--) - swap(i, j, a); - } - - /** - * Compares two longs in natural order, since a - b is inadequate. - * - * @param a the first long - * @param b the second long - * @return < 0, 0, or > 0 accorting to the comparison - */ - private static int compare(long a, long b) - { - return a < b ? -1 : a == b ? 0 : 1; - } - - /** - * Performs a recursive modified quicksort. - * - * @param array the array to sort - * @param from the start index (inclusive) - * @param count the number of elements to sort - */ - private static void qsort(long[] array, int from, int count) - { - // Use an insertion sort on small arrays. - if (count <= 7) - { - for (int i = from + 1; i < from + count; i++) - for (int j = i; j > from && array[j - 1] > array[j]; j--) - swap(j, j - 1, array); - return; - } - - // Determine a good median element. - int mid = count / 2; - int lo = from; - int hi = from + count - 1; - - if (count > 40) - { // big arrays, pseudomedian of 9 - int s = count / 8; - lo = med3(lo, lo + s, lo + 2 * s, array); - mid = med3(mid - s, mid, mid + s, array); - hi = med3(hi - 2 * s, hi - s, hi, array); - } - mid = med3(lo, mid, hi, array); - - int a, b, c, d; - int comp; - - // Pull the median element out of the fray, and use it as a pivot. - swap(from, mid, array); - a = b = from; - c = d = from + count - 1; - - // Repeatedly move b and c to each other, swapping elements so - // that all elements before index b are less than the pivot, and all - // elements after index c are greater than the pivot. a and b track - // the elements equal to the pivot. - while (true) - { - while (b <= c && (comp = compare(array[b], array[from])) <= 0) - { - if (comp == 0) - { - swap(a, b, array); - a++; - } - b++; - } - while (c >= b && (comp = compare(array[c], array[from])) >= 0) - { - if (comp == 0) - { - swap(c, d, array); - d--; - } - c--; - } - if (b > c) - break; - swap(b, c, array); - b++; - c--; - } - - // Swap pivot(s) back in place, the recurse on left and right sections. - hi = from + count; - int span; - span = Math.min(a - from, b - a); - vecswap(from, b - span, span, array); - - span = Math.min(d - c, hi - d - 1); - vecswap(b, hi - span, span, array); - - span = b - a; - if (span > 1) - qsort(array, from, span); - - span = d - c; - if (span > 1) - qsort(array, hi - span, span); - } - - /** - * Performs a stable sort on the elements, arranging them according to their - * natural order. - * - * @param a the float array to sort - */ - public static void sort(float[] a) - { - qsort(a, 0, a.length); - } - - /** - * Performs a stable sort on the elements, arranging them according to their - * natural order. - * - * @param a the float array to sort - * @param fromIndex the first index to sort (inclusive) - * @param toIndex the last index to sort (exclusive) - * @throws IllegalArgumentException if fromIndex > toIndex - * @throws ArrayIndexOutOfBoundsException if fromIndex < 0 - * || toIndex > a.length - */ - public static void sort(float[] a, int fromIndex, int toIndex) - { - if (fromIndex > toIndex) - throw new IllegalArgumentException(); - if (fromIndex < 0) - throw new ArrayIndexOutOfBoundsException(); - qsort(a, fromIndex, toIndex - fromIndex); - } - - /** - * Finds the index of the median of three array elements. - * - * @param a the first index - * @param b the second index - * @param c the third index - * @param d the array - * @return the index (a, b, or c) which has the middle value of the three - */ - private static int med3(int a, int b, int c, float[] d) - { - return (Float.compare(d[a], d[b]) < 0 - ? (Float.compare(d[b], d[c]) < 0 ? b - : Float.compare(d[a], d[c]) < 0 ? c : a) - : (Float.compare(d[b], d[c]) > 0 ? b - : Float.compare(d[a], d[c]) > 0 ? c : a)); - } - - /** - * Swaps the elements at two locations of an array - * - * @param i the first index - * @param j the second index - * @param a the array - */ - private static void swap(int i, int j, float[] a) - { - float c = a[i]; - a[i] = a[j]; - a[j] = c; - } - - /** - * Swaps two ranges of an array. - * - * @param i the first range start - * @param j the second range start - * @param n the element count - * @param a the array - */ - private static void vecswap(int i, int j, int n, float[] a) - { - for ( ; n > 0; i++, j++, n--) - swap(i, j, a); - } - - /** - * Performs a recursive modified quicksort. - * - * @param array the array to sort - * @param from the start index (inclusive) - * @param count the number of elements to sort - */ - private static void qsort(float[] array, int from, int count) - { - // Use an insertion sort on small arrays. - if (count <= 7) - { - for (int i = from + 1; i < from + count; i++) - for (int j = i; - j > from && Float.compare(array[j - 1], array[j]) > 0; - j--) - { - swap(j, j - 1, array); - } - return; - } - - // Determine a good median element. - int mid = count / 2; - int lo = from; - int hi = from + count - 1; - - if (count > 40) - { // big arrays, pseudomedian of 9 - int s = count / 8; - lo = med3(lo, lo + s, lo + 2 * s, array); - mid = med3(mid - s, mid, mid + s, array); - hi = med3(hi - 2 * s, hi - s, hi, array); - } - mid = med3(lo, mid, hi, array); - - int a, b, c, d; - int comp; - - // Pull the median element out of the fray, and use it as a pivot. - swap(from, mid, array); - a = b = from; - c = d = from + count - 1; - - // Repeatedly move b and c to each other, swapping elements so - // that all elements before index b are less than the pivot, and all - // elements after index c are greater than the pivot. a and b track - // the elements equal to the pivot. - while (true) - { - while (b <= c && (comp = Float.compare(array[b], array[from])) <= 0) - { - if (comp == 0) - { - swap(a, b, array); - a++; - } - b++; - } - while (c >= b && (comp = Float.compare(array[c], array[from])) >= 0) - { - if (comp == 0) - { - swap(c, d, array); - d--; - } - c--; - } - if (b > c) - break; - swap(b, c, array); - b++; - c--; - } - - // Swap pivot(s) back in place, the recurse on left and right sections. - hi = from + count; - int span; - span = Math.min(a - from, b - a); - vecswap(from, b - span, span, array); - - span = Math.min(d - c, hi - d - 1); - vecswap(b, hi - span, span, array); - - span = b - a; - if (span > 1) - qsort(array, from, span); - - span = d - c; - if (span > 1) - qsort(array, hi - span, span); - } - - /** - * Performs a stable sort on the elements, arranging them according to their - * natural order. - * - * @param a the double array to sort - */ - public static void sort(double[] a) - { - qsort(a, 0, a.length); - } - - /** - * Performs a stable sort on the elements, arranging them according to their - * natural order. - * - * @param a the double array to sort - * @param fromIndex the first index to sort (inclusive) - * @param toIndex the last index to sort (exclusive) - * @throws IllegalArgumentException if fromIndex > toIndex - * @throws ArrayIndexOutOfBoundsException if fromIndex < 0 - * || toIndex > a.length - */ - public static void sort(double[] a, int fromIndex, int toIndex) - { - if (fromIndex > toIndex) - throw new IllegalArgumentException(); - if (fromIndex < 0) - throw new ArrayIndexOutOfBoundsException(); - qsort(a, fromIndex, toIndex - fromIndex); - } - - /** - * Finds the index of the median of three array elements. - * - * @param a the first index - * @param b the second index - * @param c the third index - * @param d the array - * @return the index (a, b, or c) which has the middle value of the three - */ - private static int med3(int a, int b, int c, double[] d) - { - return (Double.compare(d[a], d[b]) < 0 - ? (Double.compare(d[b], d[c]) < 0 ? b - : Double.compare(d[a], d[c]) < 0 ? c : a) - : (Double.compare(d[b], d[c]) > 0 ? b - : Double.compare(d[a], d[c]) > 0 ? c : a)); - } - - /** - * Swaps the elements at two locations of an array - * - * @param i the first index - * @param j the second index - * @param a the array - */ - private static void swap(int i, int j, double[] a) - { - double c = a[i]; - a[i] = a[j]; - a[j] = c; - } - - /** - * Swaps two ranges of an array. - * - * @param i the first range start - * @param j the second range start - * @param n the element count - * @param a the array - */ - private static void vecswap(int i, int j, int n, double[] a) - { - for ( ; n > 0; i++, j++, n--) - swap(i, j, a); - } - - /** - * Performs a recursive modified quicksort. - * - * @param array the array to sort - * @param from the start index (inclusive) - * @param count the number of elements to sort - */ - private static void qsort(double[] array, int from, int count) - { - // Use an insertion sort on small arrays. - if (count <= 7) - { - for (int i = from + 1; i < from + count; i++) - for (int j = i; - j > from && Double.compare(array[j - 1], array[j]) > 0; - j--) - { - swap(j, j - 1, array); - } - return; - } - - // Determine a good median element. - int mid = count / 2; - int lo = from; - int hi = from + count - 1; - - if (count > 40) - { // big arrays, pseudomedian of 9 - int s = count / 8; - lo = med3(lo, lo + s, lo + 2 * s, array); - mid = med3(mid - s, mid, mid + s, array); - hi = med3(hi - 2 * s, hi - s, hi, array); - } - mid = med3(lo, mid, hi, array); - - int a, b, c, d; - int comp; - - // Pull the median element out of the fray, and use it as a pivot. - swap(from, mid, array); - a = b = from; - c = d = from + count - 1; - - // Repeatedly move b and c to each other, swapping elements so - // that all elements before index b are less than the pivot, and all - // elements after index c are greater than the pivot. a and b track - // the elements equal to the pivot. - while (true) - { - while (b <= c && (comp = Double.compare(array[b], array[from])) <= 0) - { - if (comp == 0) - { - swap(a, b, array); - a++; - } - b++; - } - while (c >= b && (comp = Double.compare(array[c], array[from])) >= 0) - { - if (comp == 0) - { - swap(c, d, array); - d--; - } - c--; - } - if (b > c) - break; - swap(b, c, array); - b++; - c--; - } - - // Swap pivot(s) back in place, the recurse on left and right sections. - hi = from + count; - int span; - span = Math.min(a - from, b - a); - vecswap(from, b - span, span, array); - - span = Math.min(d - c, hi - d - 1); - vecswap(b, hi - span, span, array); - - span = b - a; - if (span > 1) - qsort(array, from, span); - - span = d - c; - if (span > 1) - qsort(array, hi - span, span); - } - - /** - * Sort an array of Objects according to their natural ordering. The sort is - * guaranteed to be stable, that is, equal elements will not be reordered. - * The sort algorithm is a mergesort with the merge omitted if the last - * element of one half comes before the first element of the other half. This - * algorithm gives guaranteed O(n*log(n)) time, at the expense of making a - * copy of the array. - * - * @param a the array to be sorted - * @throws ClassCastException if any two elements are not mutually - * comparable - * @throws NullPointerException if an element is null (since - * null.compareTo cannot work) - * @see Comparable - */ - public static void sort(Object[] a) - { - sort(a, 0, a.length, null); - } - - /** - * Sort an array of Objects according to a Comparator. The sort is - * guaranteed to be stable, that is, equal elements will not be reordered. - * The sort algorithm is a mergesort with the merge omitted if the last - * element of one half comes before the first element of the other half. This - * algorithm gives guaranteed O(n*log(n)) time, at the expense of making a - * copy of the array. - * - * @param a the array to be sorted - * @param c a Comparator to use in sorting the array; or null to indicate - * the elements' natural order - * @throws ClassCastException if any two elements are not mutually - * comparable by the Comparator provided - * @throws NullPointerException if a null element is compared with natural - * ordering (only possible when c is null) - */ - public static void sort(Object[] a, Comparator c) - { - sort(a, 0, a.length, c); - } - - /** - * Sort an array of Objects according to their natural ordering. The sort is - * guaranteed to be stable, that is, equal elements will not be reordered. - * The sort algorithm is a mergesort with the merge omitted if the last - * element of one half comes before the first element of the other half. This - * algorithm gives guaranteed O(n*log(n)) time, at the expense of making a - * copy of the array. - * - * @param a the array to be sorted - * @param fromIndex the index of the first element to be sorted - * @param toIndex the index of the last element to be sorted plus one - * @throws ClassCastException if any two elements are not mutually - * comparable - * @throws NullPointerException if an element is null (since - * null.compareTo cannot work) - * @throws ArrayIndexOutOfBoundsException if fromIndex and toIndex - * are not in range. - * @throws IllegalArgumentException if fromIndex > toIndex - */ - public static void sort(Object[] a, int fromIndex, int toIndex) - { - sort(a, fromIndex, toIndex, null); - } - - /** - * Sort an array of Objects according to a Comparator. The sort is - * guaranteed to be stable, that is, equal elements will not be reordered. - * The sort algorithm is a mergesort with the merge omitted if the last - * element of one half comes before the first element of the other half. This - * algorithm gives guaranteed O(n*log(n)) time, at the expense of making a - * copy of the array. - * - * @param a the array to be sorted - * @param fromIndex the index of the first element to be sorted - * @param toIndex the index of the last element to be sorted plus one - * @param c a Comparator to use in sorting the array; or null to indicate - * the elements' natural order - * @throws ClassCastException if any two elements are not mutually - * comparable by the Comparator provided - * @throws ArrayIndexOutOfBoundsException if fromIndex and toIndex - * are not in range. - * @throws IllegalArgumentException if fromIndex > toIndex - * @throws NullPointerException if a null element is compared with natural - * ordering (only possible when c is null) - */ - public static void sort(Object[] a, int fromIndex, int toIndex, Comparator c) - { - if (fromIndex > toIndex) - throw new IllegalArgumentException("fromIndex " + fromIndex - + " > toIndex " + toIndex); - if (fromIndex < 0) - throw new ArrayIndexOutOfBoundsException(); - - // In general, the code attempts to be simple rather than fast, the - // idea being that a good optimising JIT will be able to optimise it - // better than I can, and if I try it will make it more confusing for - // the JIT. First presort the array in chunks of length 6 with insertion - // sort. A mergesort would give too much overhead for this length. - for (int chunk = fromIndex; chunk < toIndex; chunk += 6) - { - int end = Math.min(chunk + 6, toIndex); - for (int i = chunk + 1; i < end; i++) - { - if (Collections.compare(a[i - 1], a[i], c) > 0) - { - // not already sorted - int j = i; - Object elem = a[j]; - do - { - a[j] = a[j - 1]; - j--; - } - while (j > chunk - && Collections.compare(a[j - 1], elem, c) > 0); - a[j] = elem; - } - } - } - - int len = toIndex - fromIndex; - // If length is smaller or equal 6 we are done. - if (len <= 6) - return; - - Object[] src = a; - Object[] dest = new Object[len]; - Object[] t = null; // t is used for swapping src and dest - - // The difference of the fromIndex of the src and dest array. - int srcDestDiff = -fromIndex; - - // The merges are done in this loop - for (int size = 6; size < len; size <<= 1) - { - for (int start = fromIndex; start < toIndex; start += size << 1) - { - // mid is the start of the second sublist; - // end the start of the next sublist (or end of array). - int mid = start + size; - int end = Math.min(toIndex, mid + size); - - // The second list is empty or the elements are already in - // order - no need to merge - if (mid >= end - || Collections.compare(src[mid - 1], src[mid], c) <= 0) - { - System.arraycopy(src, start, - dest, start + srcDestDiff, end - start); - - // The two halves just need swapping - no need to merge - } - else if (Collections.compare(src[start], src[end - 1], c) > 0) - { - System.arraycopy(src, start, - dest, end - size + srcDestDiff, size); - System.arraycopy(src, mid, - dest, start + srcDestDiff, end - mid); - - } - else - { - // Declare a lot of variables to save repeating - // calculations. Hopefully a decent JIT will put these - // in registers and make this fast - int p1 = start; - int p2 = mid; - int i = start + srcDestDiff; - - // The main merge loop; terminates as soon as either - // half is ended - while (p1 < mid && p2 < end) - { - dest[i++] = - src[(Collections.compare(src[p1], src[p2], c) <= 0 - ? p1++ : p2++)]; - } - - // Finish up by copying the remainder of whichever half - // wasn't finished. - if (p1 < mid) - System.arraycopy(src, p1, dest, i, mid - p1); - else - System.arraycopy(src, p2, dest, i, end - p2); - } - } - // swap src and dest ready for the next merge - t = src; - src = dest; - dest = t; - fromIndex += srcDestDiff; - toIndex += srcDestDiff; - srcDestDiff = -srcDestDiff; - } - - // make sure the result ends up back in the right place. Note - // that src and dest may have been swapped above, so src - // contains the sorted array. - if (src != a) - { - // Note that fromIndex == 0. - System.arraycopy(src, 0, a, srcDestDiff, toIndex); - } - } - - /** - * Returns a list "view" of the specified array. This method is intended to - * make it easy to use the Collections API with existing array-based APIs and - * programs. Changes in the list or the array show up in both places. The - * list does not support element addition or removal, but does permit - * value modification. The returned list implements both Serializable and - * RandomAccess. - * - * @param a the array to return a view of - * @return a fixed-size list, changes to which "write through" to the array - * @see Serializable - * @see RandomAccess - * @see Arrays.ArrayList - */ - public static List asList(final Object[] a) - { - return new Arrays.ArrayList(a); - } - - /** - * Inner class used by {@link #asList(Object[])} to provide a list interface - * to an array. The name, though it clashes with java.util.ArrayList, is - * Sun's choice for Serialization purposes. Element addition and removal - * is prohibited, but values can be modified. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @status updated to 1.4 - */ - private static final class ArrayList extends AbstractList - implements Serializable, RandomAccess - { - // We override the necessary methods, plus others which will be much - // more efficient with direct iteration rather than relying on iterator(). - - /** - * Compatible with JDK 1.4. - */ - private static final long serialVersionUID = -2764017481108945198L; - - /** - * The array we are viewing. - * @serial the array - */ - private final Object[] a; - - /** - * Construct a list view of the array. - * @param a the array to view - * @throws NullPointerException if a is null - */ - ArrayList(Object[] a) - { - // We have to explicitly check. - if (a == null) - throw new NullPointerException(); - this.a = a; - } - - /** - * Returns the object at the specified index in - * the array. - * - * @param index The index to retrieve an object from. - * @return The object at the array index specified. - */ - public Object get(int index) - { - return a[index]; - } - - /** - * Returns the size of the array. - * - * @return The size. - */ - public int size() - { - return a.length; - } - - /** - * Replaces the object at the specified index - * with the supplied element. - * - * @param index The index at which to place the new object. - * @param element The new object. - * @return The object replaced by this operation. - */ - public Object set(int index, Object element) - { - Object old = a[index]; - a[index] = element; - return old; - } - - /** - * Returns true if the array contains the - * supplied object. - * - * @param o The object to look for. - * @return True if the object was found. - */ - public boolean contains(Object o) - { - return lastIndexOf(o) >= 0; - } - - /** - * Returns the first index at which the - * object, o, occurs in the array. - * - * @param o The object to search for. - * @return The first relevant index. - */ - public int indexOf(Object o) - { - int size = a.length; - for (int i = 0; i < size; i++) - if (ArrayList.equals(o, a[i])) - return i; - return -1; - } - - /** - * Returns the last index at which the - * object, o, occurs in the array. - * - * @param o The object to search for. - * @return The last relevant index. - */ - public int lastIndexOf(Object o) - { - int i = a.length; - while (--i >= 0) - if (ArrayList.equals(o, a[i])) - return i; - return -1; - } - - /** - * Transforms the list into an array of - * objects, by simplying cloning the array - * wrapped by this list. - * - * @return A clone of the internal array. - */ - public Object[] toArray() - { - return (Object[]) a.clone(); - } - - /** - * Copies the objects from this list into - * the supplied array. The supplied array - * is shrunk or enlarged to the size of the - * internal array, and filled with its objects. - * - * @param array The array to fill with the objects in this list. - * @return The array containing the objects in this list, - * which may or may not be == to array. - */ - public Object[] toArray(Object[] array) - { - int size = a.length; - if (array.length < size) - array = (Object[]) - Array.newInstance(array.getClass().getComponentType(), size); - else if (array.length > size) - array[size] = null; - - System.arraycopy(a, 0, array, 0, size); - return array; - } - } -} diff --git a/libjava/java/util/BitSet.java b/libjava/java/util/BitSet.java deleted file mode 100644 index 891f185334c..00000000000 --- a/libjava/java/util/BitSet.java +++ /dev/null @@ -1,744 +0,0 @@ -/* BitSet.java -- A vector of bits. - Copyright (C) 1998, 1999, 2000, 2001, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.util; -import java.io.Serializable; - -/* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3 - * hashCode algorithm taken from JDK 1.2 docs. - */ - -/** - * This class can be thought of in two ways. You can see it as a - * vector of bits or as a set of non-negative integers. The name - * <code>BitSet</code> is a bit misleading. - * - * It is implemented by a bit vector, but its equally possible to see - * it as set of non-negative integer; each integer in the set is - * represented by a set bit at the corresponding index. The size of - * this structure is determined by the highest integer in the set. - * - * You can union, intersect and build (symmetric) remainders, by - * invoking the logical operations and, or, andNot, resp. xor. - * - * This implementation is NOT synchronized against concurrent access from - * multiple threads. Specifically, if one thread is reading from a bitset - * while another thread is simultaneously modifying it, the results are - * undefined. - * - * @author Jochen Hoenicke - * @author Tom Tromey (tromey@cygnus.com) - * @author Eric Blake (ebb9@email.byu.edu) - * @status updated to 1.4 - */ -public class BitSet implements Cloneable, Serializable -{ - /** - * Compatible with JDK 1.0. - */ - private static final long serialVersionUID = 7997698588986878753L; - - /** - * A common mask. - */ - private static final int LONG_MASK = 0x3f; - - /** - * The actual bits. - * @serial the i'th bit is in bits[i/64] at position i%64 (where position - * 0 is the least significant). - */ - private long[] bits; - - /** - * Create a new empty bit set. All bits are initially false. - */ - public BitSet() - { - this(64); - } - - /** - * Create a new empty bit set, with a given size. This - * constructor reserves enough space to represent the integers - * from <code>0</code> to <code>nbits-1</code>. - * - * @param nbits the initial size of the bit set - * @throws NegativeArraySizeException if nbits < 0 - */ - public BitSet(int nbits) - { - if (nbits < 0) - throw new NegativeArraySizeException(); - - int length = nbits >>> 6; - if ((nbits & LONG_MASK) != 0) - ++length; - bits = new long[length]; - } - - /** - * Performs the logical AND operation on this bit set and the - * given <code>set</code>. This means it builds the intersection - * of the two sets. The result is stored into this bit set. - * - * @param set the second bit set - * @throws NullPointerException if set is null - */ - public void and(BitSet bs) - { - int max = Math.min(bits.length, bs.bits.length); - int i; - for (i = 0; i < max; ++i) - bits[i] &= bs.bits[i]; - while (i < bits.length) - bits[i++] = 0; - } - - /** - * Performs the logical AND operation on this bit set and the - * complement of the given <code>set</code>. This means it - * selects every element in the first set, that isn't in the - * second set. The result is stored into this bit set and is - * effectively the set difference of the two. - * - * @param set the second bit set - * @throws NullPointerException if set is null - * @since 1.2 - */ - public void andNot(BitSet bs) - { - int i = Math.min(bits.length, bs.bits.length); - while (--i >= 0) - bits[i] &= ~bs.bits[i]; - } - - /** - * Returns the number of bits set to true. - * - * @return the number of true bits - * @since 1.4 - */ - public int cardinality() - { - int card = 0; - for (int i = bits.length - 1; i >= 0; i--) - { - long a = bits[i]; - // Take care of common cases. - if (a == 0) - continue; - if (a == -1) - { - card += 64; - continue; - } - - // Successively collapse alternating bit groups into a sum. - a = ((a >> 1) & 0x5555555555555555L) + (a & 0x5555555555555555L); - a = ((a >> 2) & 0x3333333333333333L) + (a & 0x3333333333333333L); - int b = (int) ((a >>> 32) + a); - b = ((b >> 4) & 0x0f0f0f0f) + (b & 0x0f0f0f0f); - b = ((b >> 8) & 0x00ff00ff) + (b & 0x00ff00ff); - card += ((b >> 16) & 0x0000ffff) + (b & 0x0000ffff); - } - return card; - } - - /** - * Sets all bits in the set to false. - * - * @since 1.4 - */ - public void clear() - { - Arrays.fill(bits, 0); - } - - /** - * Removes the integer <code>bitIndex</code> from this set. That is - * the corresponding bit is cleared. If the index is not in the set, - * this method does nothing. - * - * @param bitIndex a non-negative integer - * @throws IndexOutOfBoundsException if bitIndex < 0 - */ - public void clear(int pos) - { - int offset = pos >> 6; - ensure(offset); - // ArrayIndexOutOfBoundsException subclasses IndexOutOfBoundsException, - // so we'll just let that be our exception. - bits[offset] &= ~(1L << pos); - } - - /** - * Sets the bits between from (inclusive) and to (exclusive) to false. - * - * @param from the start range (inclusive) - * @param to the end range (exclusive) - * @throws IndexOutOfBoundsException if from < 0 || to < 0 || - * from > to - * @since 1.4 - */ - public void clear(int from, int to) - { - if (from < 0 || from > to) - throw new IndexOutOfBoundsException(); - if (from == to) - return; - int lo_offset = from >>> 6; - int hi_offset = to >>> 6; - ensure(hi_offset); - if (lo_offset == hi_offset) - { - bits[hi_offset] &= ((1L << from) - 1) | (-1L << to); - return; - } - - bits[lo_offset] &= (1L << from) - 1; - bits[hi_offset] &= -1L << to; - for (int i = lo_offset + 1; i < hi_offset; i++) - bits[i] = 0; - } - - /** - * Create a clone of this bit set, that is an instance of the same - * class and contains the same elements. But it doesn't change when - * this bit set changes. - * - * @return the clone of this object. - */ - public Object clone() - { - try - { - BitSet bs = (BitSet) super.clone(); - bs.bits = (long[]) bits.clone(); - return bs; - } - catch (CloneNotSupportedException e) - { - // Impossible to get here. - return null; - } - } - - /** - * Returns true if the <code>obj</code> is a bit set that contains - * exactly the same elements as this bit set, otherwise false. - * - * @param obj the object to compare to - * @return true if obj equals this bit set - */ - public boolean equals(Object obj) - { - if (!(obj instanceof BitSet)) - return false; - BitSet bs = (BitSet) obj; - int max = Math.min(bits.length, bs.bits.length); - int i; - for (i = 0; i < max; ++i) - if (bits[i] != bs.bits[i]) - return false; - // If one is larger, check to make sure all extra bits are 0. - for (int j = i; j < bits.length; ++j) - if (bits[j] != 0) - return false; - for (int j = i; j < bs.bits.length; ++j) - if (bs.bits[j] != 0) - return false; - return true; - } - - /** - * Sets the bit at the index to the opposite value. - * - * @param index the index of the bit - * @throws IndexOutOfBoundsException if index is negative - * @since 1.4 - */ - public void flip(int index) - { - int offset = index >> 6; - ensure(offset); - // ArrayIndexOutOfBoundsException subclasses IndexOutOfBoundsException, - // so we'll just let that be our exception. - bits[offset] ^= 1L << index; - } - - /** - * Sets a range of bits to the opposite value. - * - * @param from the low index (inclusive) - * @param to the high index (exclusive) - * @throws IndexOutOfBoundsException if from > to || from < 0 || - * to < 0 - * @since 1.4 - */ - public void flip(int from, int to) - { - if (from < 0 || from > to) - throw new IndexOutOfBoundsException(); - if (from == to) - return; - int lo_offset = from >>> 6; - int hi_offset = to >>> 6; - ensure(hi_offset); - if (lo_offset == hi_offset) - { - bits[hi_offset] ^= (-1L << from) & ((1L << to) - 1); - return; - } - - bits[lo_offset] ^= -1L << from; - bits[hi_offset] ^= (1L << to) - 1; - for (int i = lo_offset + 1; i < hi_offset; i++) - bits[i] ^= -1; - } - - /** - * Returns true if the integer <code>bitIndex</code> is in this bit - * set, otherwise false. - * - * @param pos a non-negative integer - * @return the value of the bit at the specified index - * @throws IndexOutOfBoundsException if the index is negative - */ - public boolean get(int pos) - { - int offset = pos >> 6; - if (offset >= bits.length) - return false; - // ArrayIndexOutOfBoundsException subclasses IndexOutOfBoundsException, - // so we'll just let that be our exception. - return (bits[offset] & (1L << pos)) != 0; - } - - /** - * Returns a new <code>BitSet</code> composed of a range of bits from - * this one. - * - * @param from the low index (inclusive) - * @param to the high index (exclusive) - * @throws IndexOutOfBoundsException if from > to || from < 0 || - * to < 0 - * @since 1.4 - */ - public BitSet get(int from, int to) - { - if (from < 0 || from > to) - throw new IndexOutOfBoundsException(); - BitSet bs = new BitSet(to - from); - int lo_offset = from >>> 6; - if (lo_offset >= bits.length) - return bs; - - int lo_bit = from & LONG_MASK; - int hi_offset = to >>> 6; - if (lo_bit == 0) - { - int len = Math.min(hi_offset - lo_offset + 1, bits.length - lo_offset); - System.arraycopy(bits, lo_offset, bs.bits, 0, len); - if (hi_offset < bits.length) - bs.bits[hi_offset - lo_offset] &= (1L << to) - 1; - return bs; - } - - int len = Math.min(hi_offset, bits.length - 1); - int reverse = 64 - lo_bit; - int i; - for (i = 0; lo_offset < len; lo_offset++, i++) - bs.bits[i] = ((bits[lo_offset] >>> lo_bit) - | (bits[lo_offset + 1] << reverse)); - if ((to & LONG_MASK) > lo_bit) - bs.bits[i++] = bits[lo_offset] >>> lo_bit; - if (hi_offset < bits.length) - bs.bits[i - 1] &= (1L << (to - from)) - 1; - return bs; - } - - /** - * Returns a hash code value for this bit set. The hash code of - * two bit sets containing the same integers is identical. The algorithm - * used to compute it is as follows: - * - * Suppose the bits in the BitSet were to be stored in an array of - * long integers called <code>bits</code>, in such a manner that - * bit <code>k</code> is set in the BitSet (for non-negative values - * of <code>k</code>) if and only if - * - * <code>((k/64) < bits.length) - * && ((bits[k/64] & (1L << (bit % 64))) != 0) - * </code> - * - * Then the following definition of the hashCode method - * would be a correct implementation of the actual algorithm: - * - * -<pre>public int hashCode() -{ - long h = 1234; - for (int i = bits.length-1; i >= 0; i--) - { - h ^= bits[i] * (i + 1); - } - - return (int)((h >> 32) ^ h); -}</pre> - * - * Note that the hash code values changes, if the set is changed. - * - * @return the hash code value for this bit set. - */ - public int hashCode() - { - long h = 1234; - for (int i = bits.length; i > 0; ) - h ^= i * bits[--i]; - return (int) ((h >> 32) ^ h); - } - - /** - * Returns true if the specified BitSet and this one share at least one - * common true bit. - * - * @param set the set to check for intersection - * @return true if the sets intersect - * @throws NullPointerException if set is null - * @since 1.4 - */ - public boolean intersects(BitSet set) - { - int i = Math.min(bits.length, set.bits.length); - while (--i >= 0) - if ((bits[i] & set.bits[i]) != 0) - return true; - return false; - } - - /** - * Returns true if this set contains no true bits. - * - * @return true if all bits are false - * @since 1.4 - */ - public boolean isEmpty() - { - for (int i = bits.length - 1; i >= 0; i--) - if (bits[i] != 0) - return false; - return true; - } - - /** - * Returns the logical number of bits actually used by this bit - * set. It returns the index of the highest set bit plus one. - * Note that this method doesn't return the number of set bits. - * - * @return the index of the highest set bit plus one. - */ - public int length() - { - // Set i to highest index that contains a non-zero value. - int i; - for (i = bits.length - 1; i >= 0 && bits[i] == 0; --i) - ; - - // if i < 0 all bits are cleared. - if (i < 0) - return 0; - - // Now determine the exact length. - long b = bits[i]; - int len = (i + 1) * 64; - // b >= 0 checks if the highest bit is zero. - while (b >= 0) - { - --len; - b <<= 1; - } - - return len; - } - - /** - * Returns the index of the next false bit, from the specified bit - * (inclusive). - * - * @param from the start location - * @return the first false bit - * @throws IndexOutOfBoundsException if from is negative - * @since 1.4 - */ - public int nextClearBit(int from) - { - int offset = from >> 6; - long mask = 1L << from; - while (offset < bits.length) - { - // ArrayIndexOutOfBoundsException subclasses IndexOutOfBoundsException, - // so we'll just let that be our exception. - long h = bits[offset]; - do - { - if ((h & mask) == 0) - return from; - mask <<= 1; - from++; - } - while (mask != 0); - mask = 1; - offset++; - } - return from; - } - - /** - * Returns the index of the next true bit, from the specified bit - * (inclusive). If there is none, -1 is returned. You can iterate over - * all true bits with this loop:<br> - * -<pre>for (int i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i + 1)) -{ - // operate on i here -}</pre> - * - * @param from the start location - * @return the first true bit, or -1 - * @throws IndexOutOfBoundsException if from is negative - * @since 1.4 - */ - public int nextSetBit(int from) - { - int offset = from >> 6; - long mask = 1L << from; - while (offset < bits.length) - { - // ArrayIndexOutOfBoundsException subclasses IndexOutOfBoundsException, - // so we'll just let that be our exception. - long h = bits[offset]; - do - { - if ((h & mask) != 0) - return from; - mask <<= 1; - from++; - } - while (mask != 0); - mask = 1; - offset++; - } - return -1; - } - - /** - * Performs the logical OR operation on this bit set and the - * given <code>set</code>. This means it builds the union - * of the two sets. The result is stored into this bit set, which - * grows as necessary. - * - * @param bs the second bit set - * @throws NullPointerException if bs is null - */ - public void or(BitSet bs) - { - ensure(bs.bits.length - 1); - for (int i = bs.bits.length - 1; i >= 0; i--) - bits[i] |= bs.bits[i]; - } - - /** - * Add the integer <code>bitIndex</code> to this set. That is - * the corresponding bit is set to true. If the index was already in - * the set, this method does nothing. The size of this structure - * is automatically increased as necessary. - * - * @param pos a non-negative integer. - * @throws IndexOutOfBoundsException if pos is negative - */ - public void set(int pos) - { - int offset = pos >> 6; - ensure(offset); - // ArrayIndexOutOfBoundsException subclasses IndexOutOfBoundsException, - // so we'll just let that be our exception. - bits[offset] |= 1L << pos; - } - - /** - * Sets the bit at the given index to the specified value. The size of - * this structure is automatically increased as necessary. - * - * @param index the position to set - * @param value the value to set it to - * @throws IndexOutOfBoundsException if index is negative - * @since 1.4 - */ - public void set(int index, boolean value) - { - if (value) - set(index); - else - clear(index); - } - - /** - * Sets the bits between from (inclusive) and to (exclusive) to true. - * - * @param from the start range (inclusive) - * @param to the end range (exclusive) - * @throws IndexOutOfBoundsException if from < 0 || from > to || - * to < 0 - * @since 1.4 - */ - public void set(int from, int to) - { - if (from < 0 || from > to) - throw new IndexOutOfBoundsException(); - if (from == to) - return; - int lo_offset = from >>> 6; - int hi_offset = to >>> 6; - ensure(hi_offset); - if (lo_offset == hi_offset) - { - bits[hi_offset] |= (-1L << from) & ((1L << to) - 1); - return; - } - - bits[lo_offset] |= -1L << from; - bits[hi_offset] |= (1L << to) - 1; - for (int i = lo_offset + 1; i < hi_offset; i++) - bits[i] = -1; - } - - /** - * Sets the bits between from (inclusive) and to (exclusive) to the - * specified value. - * - * @param from the start range (inclusive) - * @param to the end range (exclusive) - * @param value the value to set it to - * @throws IndexOutOfBoundsException if from < 0 || from > to || - * to < 0 - * @since 1.4 - */ - public void set(int from, int to, boolean value) - { - if (value) - set(from, to); - else - clear(from, to); - } - - /** - * Returns the number of bits actually used by this bit set. Note - * that this method doesn't return the number of set bits, and that - * future requests for larger bits will make this automatically grow. - * - * @return the number of bits currently used. - */ - public int size() - { - return bits.length * 64; - } - - /** - * Returns the string representation of this bit set. This - * consists of a comma separated list of the integers in this set - * surrounded by curly braces. There is a space after each comma. - * A sample string is thus "{1, 3, 53}". - * @return the string representation. - */ - public String toString() - { - StringBuffer r = new StringBuffer("{"); - boolean first = true; - for (int i = 0; i < bits.length; ++i) - { - long bit = 1; - long word = bits[i]; - if (word == 0) - continue; - for (int j = 0; j < 64; ++j) - { - if ((word & bit) != 0) - { - if (! first) - r.append(", "); - r.append(64 * i + j); - first = false; - } - bit <<= 1; - } - } - return r.append("}").toString(); - } - - /** - * Performs the logical XOR operation on this bit set and the - * given <code>set</code>. This means it builds the symmetric - * remainder of the two sets (the elements that are in one set, - * but not in the other). The result is stored into this bit set, - * which grows as necessary. - * - * @param bs the second bit set - * @throws NullPointerException if bs is null - */ - public void xor(BitSet bs) - { - ensure(bs.bits.length - 1); - for (int i = bs.bits.length - 1; i >= 0; i--) - bits[i] ^= bs.bits[i]; - } - - /** - * Make sure the vector is big enough. - * - * @param lastElt the size needed for the bits array - */ - private void ensure(int lastElt) - { - if (lastElt >= bits.length) - { - long[] nd = new long[lastElt + 1]; - System.arraycopy(bits, 0, nd, 0, bits.length); - bits = nd; - } - } -} diff --git a/libjava/java/util/Collection.java b/libjava/java/util/Collection.java deleted file mode 100644 index 29e1b3786b4..00000000000 --- a/libjava/java/util/Collection.java +++ /dev/null @@ -1,288 +0,0 @@ -/* Collection.java -- Interface that represents a collection of objects - Copyright (C) 1998, 2001, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util; - -/** - * Interface that represents a collection of objects. This interface is the - * root of the collection hierarchy, and does not provide any guarantees about - * the order of its elements or whether or not duplicate elements are - * permitted. - * <p> - * All methods of this interface that are defined to modify the collection are - * defined as <dfn>optional</dfn>. An optional operation may throw an - * UnsupportedOperationException if the data backing this collection does not - * support such a modification. This may mean that the data structure is - * immutable, or that it is read-only but may change ("unmodifiable"), or - * that it is modifiable but of fixed size (such as an array), or any number - * of other combinations. - * <p> - * A class that wishes to implement this interface should consider subclassing - * AbstractCollection, which provides basic implementations of most of the - * methods of this interface. Classes that are prepared to make guarantees - * about ordering or about absence of duplicate elements should consider - * implementing List or Set respectively, both of which are subinterfaces of - * Collection. - * <p> - * A general-purpose implementation of the Collection interface should in most - * cases provide at least two constructors: One which takes no arguments and - * creates an empty collection, and one which takes a Collection as an argument - * and returns a collection containing the same elements (that is, creates a - * copy of the argument using its own implementation). - * - * @author Original author unknown - * @author Eric Blake (ebb9@email.byu.edu) - * @see List - * @see Set - * @see Map - * @see SortedSet - * @see SortedMap - * @see HashSet - * @see TreeSet - * @see ArrayList - * @see LinkedList - * @see Vector - * @see Collections - * @see Arrays - * @see AbstractCollection - * @since 1.2 - * @status updated to 1.4 - */ -public interface Collection -{ - /** - * Add an element to this collection. - * - * @param o the object to add. - * @return true if the collection was modified as a result of this action. - * @throws UnsupportedOperationException if this collection does not - * support the add operation. - * @throws ClassCastException if o cannot be added to this collection due - * to its type. - * @throws NullPointerException if o is null and this collection doesn't - * support the addition of null values. - * @throws IllegalArgumentException if o cannot be added to this - * collection for some other reason. - */ - boolean add(Object o); - - /** - * Add the contents of a given collection to this collection. - * - * @param c the collection to add. - * @return true if the collection was modified as a result of this action. - * @throws UnsupportedOperationException if this collection does not - * support the addAll operation. - * @throws ClassCastException if some element of c cannot be added to this - * collection due to its type. - * @throws NullPointerException if some element of c is null and this - * collection does not support the addition of null values. - * @throws NullPointerException if c itself is null. - * @throws IllegalArgumentException if some element of c cannot be added - * to this collection for some other reason. - */ - boolean addAll(Collection c); - - /** - * Clear the collection, such that a subsequent call to isEmpty() would - * return true. - * - * @throws UnsupportedOperationException if this collection does not - * support the clear operation. - */ - void clear(); - - /** - * Test whether this collection contains a given object as one of its - * elements. - * - * @param o the element to look for. - * @return true if this collection contains at least one element e such that - * <code>o == null ? e == null : o.equals(e)</code>. - * @throws ClassCastException if the type of o is not a valid type for this - * collection. - * @throws NullPointerException if o is null and this collection doesn't - * support null values. - */ - boolean contains(Object o); - - /** - * Test whether this collection contains every element in a given collection. - * - * @param c the collection to test for. - * @return true if for every element o in c, contains(o) would return true. - * @throws ClassCastException if the type of any element in c is not a valid - * type for this collection. - * @throws NullPointerException if some element of c is null and this - * collection does not support null values. - * @throws NullPointerException if c itself is null. - */ - boolean containsAll(Collection c); - - /** - * Test whether this collection is equal to some object. The Collection - * interface does not explicitly require any behaviour from this method, and - * it may be left to the default implementation provided by Object. The Set - * and List interfaces do, however, require specific behaviour from this - * method. - * <p> - * If an implementation of Collection, which is not also an implementation of - * Set or List, should choose to implement this method, it should take care - * to obey the contract of the equals method of Object. In particular, care - * should be taken to return false when o is a Set or a List, in order to - * preserve the symmetry of the relation. - * - * @param o the object to compare to this collection. - * @return true if the o is equal to this collection. - */ - boolean equals(Object o); - - /** - * Obtain a hash code for this collection. The Collection interface does not - * explicitly require any behaviour from this method, and it may be left to - * the default implementation provided by Object. The Set and List interfaces - * do, however, require specific behaviour from this method. - * <p> - * If an implementation of Collection, which is not also an implementation of - * Set or List, should choose to implement this method, it should take care - * to obey the contract of the hashCode method of Object. Note that this - * method renders it impossible to correctly implement both Set and List, as - * the required implementations are mutually exclusive. - * - * @return a hash code for this collection. - */ - int hashCode(); - - /** - * Test whether this collection is empty, that is, if size() == 0. - * - * @return true if this collection contains no elements. - */ - boolean isEmpty(); - - /** - * Obtain an Iterator over this collection. - * - * @return an Iterator over the elements of this collection, in any order. - */ - Iterator iterator(); - - /** - * Remove a single occurrence of an object from this collection. That is, - * remove an element e, if one exists, such that <code>o == null ? e == null - * : o.equals(e)</code>. - * - * @param o the object to remove. - * @return true if the collection changed as a result of this call, that is, - * if the collection contained at least one occurrence of o. - * @throws UnsupportedOperationException if this collection does not - * support the remove operation. - * @throws ClassCastException if the type of o is not a valid type - * for this collection. - * @throws NullPointerException if o is null and the collection doesn't - * support null values. - */ - boolean remove(Object o); - - /** - * Remove all elements of a given collection from this collection. That is, - * remove every element e such that c.contains(e). - * - * @param c The collection of objects to be removed. - * @return true if this collection was modified as a result of this call. - * @throws UnsupportedOperationException if this collection does not - * support the removeAll operation. - * @throws ClassCastException if the type of any element in c is not a valid - * type for this collection. - * @throws NullPointerException if some element of c is null and this - * collection does not support removing null values. - * @throws NullPointerException if c itself is null. - */ - boolean removeAll(Collection c); - - /** - * Remove all elements of this collection that are not contained in a given - * collection. That is, remove every element e such that !c.contains(e). - * - * @param c The collection of objects to be retained. - * @return true if this collection was modified as a result of this call. - * @throws UnsupportedOperationException if this collection does not - * support the retainAll operation. - * @throws ClassCastException if the type of any element in c is not a valid - * type for this collection. - * @throws NullPointerException if some element of c is null and this - * collection does not support retaining null values. - * @throws NullPointerException if c itself is null. - */ - boolean retainAll(Collection c); - - /** - * Get the number of elements in this collection. - * - * @return the number of elements in the collection. - */ - int size(); - - /** - * Copy the current contents of this collection into an array. - * - * @return an array of type Object[] and length equal to the size of this - * collection, containing the elements currently in this collection, in - * any order. - */ - Object[] toArray(); - - /** - * Copy the current contents of this collection into an array. If the array - * passed as an argument has length less than the size of this collection, an - * array of the same run-time type as a, and length equal to the size of this - * collection, is allocated using Reflection. Otherwise, a itself is used. - * The elements of this collection are copied into it, and if there is space - * in the array, the following element is set to null. The resultant array is - * returned. - * Note: The fact that the following element is set to null is only useful - * if it is known that this collection does not contain any null elements. - * - * @param a the array to copy this collection into. - * @return an array containing the elements currently in this collection, in - * any order. - * @throws ArrayStoreException if the type of any element of the - * collection is not a subtype of the element type of a. - */ - Object[] toArray(Object[] a); -} diff --git a/libjava/java/util/Collections.java b/libjava/java/util/Collections.java deleted file mode 100644 index 64eb8da3585..00000000000 --- a/libjava/java/util/Collections.java +++ /dev/null @@ -1,5493 +0,0 @@ -/* Collections.java -- Utility class with methods to operate on collections - Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004, 2005 - Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util; - -import java.io.Serializable; - -/** - * Utility class consisting of static methods that operate on, or return - * Collections. Contains methods to sort, search, reverse, fill and shuffle - * Collections, methods to facilitate interoperability with legacy APIs that - * are unaware of collections, a method to return a list which consists of - * multiple copies of one element, and methods which "wrap" collections to give - * them extra properties, such as thread-safety and unmodifiability. - * <p> - * - * All methods which take a collection throw a {@link NullPointerException} if - * that collection is null. Algorithms which can change a collection may, but - * are not required, to throw the {@link UnsupportedOperationException} that - * the underlying collection would throw during an attempt at modification. - * For example, - * <code>Collections.singleton("").addAll(Collections.EMPTY_SET)</code> - * does not throw a exception, even though addAll is an unsupported operation - * on a singleton; the reason for this is that addAll did not attempt to - * modify the set. - * - * @author Original author unknown - * @author Eric Blake (ebb9@email.byu.edu) - * @see Collection - * @see Set - * @see List - * @see Map - * @see Arrays - * @since 1.2 - * @status updated to 1.4 - */ -public class Collections -{ - /** - * Constant used to decide cutoff for when a non-RandomAccess list should - * be treated as sequential-access. Basically, quadratic behavior is - * acceptable for small lists when the overhead is so small in the first - * place. I arbitrarily set it to 16, so it may need some tuning. - */ - private static final int LARGE_LIST_SIZE = 16; - - /** - * Determines if a list should be treated as a sequential-access one. - * Rather than the old method of JDK 1.3 of assuming only instanceof - * AbstractSequentialList should be sequential, this uses the new method - * of JDK 1.4 of assuming anything that does NOT implement RandomAccess - * and exceeds a large (unspecified) size should be sequential. - * - * @param l the list to check - * @return <code>true</code> if it should be treated as sequential-access - */ - private static boolean isSequential(List l) - { - return ! (l instanceof RandomAccess) && l.size() > LARGE_LIST_SIZE; - } - - /** - * This class is non-instantiable. - */ - private Collections() - { - } - - /** - * An immutable, serializable, empty Set. - * @see Serializable - */ - public static final Set EMPTY_SET = new EmptySet(); - - /** - * The implementation of {@link #EMPTY_SET}. This class name is required - * for compatibility with Sun's JDK serializability. - * - * @author Eric Blake (ebb9@email.byu.edu) - */ - private static final class EmptySet extends AbstractSet - implements Serializable - { - /** - * Compatible with JDK 1.4. - */ - private static final long serialVersionUID = 1582296315990362920L; - - /** - * A private constructor adds overhead. - */ - EmptySet() - { - } - - /** - * The size: always 0! - * @return 0. - */ - public int size() - { - return 0; - } - - /** - * Returns an iterator that does not iterate. - * @return A non-iterating iterator. - */ - // This is really cheating! I think it's perfectly valid, though. - public Iterator iterator() - { - return EMPTY_LIST.iterator(); - } - - // The remaining methods are optional, but provide a performance - // advantage by not allocating unnecessary iterators in AbstractSet. - /** - * The empty set never contains anything. - * @param o The object to search for. - * @return <code>false</code>. - */ - public boolean contains(Object o) - { - return false; - } - - /** - * This is true only if the given collection is also empty. - * @param c The collection of objects which are to be compared - * against the members of this set. - * @return <code>true</code> if c is empty. - */ - public boolean containsAll(Collection c) - { - return c.isEmpty(); - } - - /** - * Equal only if the other set is empty. - * @param o The object to compare with this set. - * @return <code>true</code> if o is an empty instance of <code>Set</code>. - */ - public boolean equals(Object o) - { - return o instanceof Set && ((Set) o).isEmpty(); - } - - /** - * The hashcode is always 0. - * @return 0. - */ - public int hashCode() - { - return 0; - } - - /** - * Always succeeds with a <code>false</code> result. - * @param o The object to remove. - * @return <code>false</code>. - */ - public boolean remove(Object o) - { - return false; - } - - /** - * Always succeeds with a <code>false</code> result. - * @param c The collection of objects which should - * all be removed from this set. - * @return <code>false</code>. - */ - public boolean removeAll(Collection c) - { - return false; - } - - /** - * Always succeeds with a <code>false</code> result. - * @param c The collection of objects which should - * all be retained within this set. - * @return <code>false</code>. - */ - public boolean retainAll(Collection c) - { - return false; - } - - /** - * The array is always empty. - * @return A new array with a size of 0. - */ - public Object[] toArray() - { - return new Object[0]; - } - - /** - * We don't even need to use reflection! - * @param a An existing array, which can be empty. - * @return The original array with any existing - * initial element set to null. - */ - public Object[] toArray(Object[] a) - { - if (a.length > 0) - a[0] = null; - return a; - } - - /** - * The string never changes. - * - * @return the string "[]". - */ - public String toString() - { - return "[]"; - } - } // class EmptySet - - /** - * An immutable, serializable, empty List, which implements RandomAccess. - * @see Serializable - * @see RandomAccess - */ - public static final List EMPTY_LIST = new EmptyList(); - - /** - * The implementation of {@link #EMPTY_LIST}. This class name is required - * for compatibility with Sun's JDK serializability. - * - * @author Eric Blake (ebb9@email.byu.edu) - */ - private static final class EmptyList extends AbstractList - implements Serializable, RandomAccess - { - /** - * Compatible with JDK 1.4. - */ - private static final long serialVersionUID = 8842843931221139166L; - - /** - * A private constructor adds overhead. - */ - EmptyList() - { - } - - /** - * The size is always 0. - * @return 0. - */ - public int size() - { - return 0; - } - - /** - * No matter the index, it is out of bounds. This - * method never returns, throwing an exception instead. - * - * @param index The index of the element to retrieve. - * @return the object at the specified index. - * @throws IndexOutofBoundsException as any given index - * is outside the bounds of an empty array. - */ - public Object get(int index) - { - throw new IndexOutOfBoundsException(); - } - - // The remaining methods are optional, but provide a performance - // advantage by not allocating unnecessary iterators in AbstractList. - /** - * Never contains anything. - * @param o The object to search for. - * @return <code>false</code>. - */ - public boolean contains(Object o) - { - return false; - } - - /** - * This is true only if the given collection is also empty. - * @param c The collection of objects, which should be compared - * against the members of this list. - * @return <code>true</code> if c is also empty. - */ - public boolean containsAll(Collection c) - { - return c.isEmpty(); - } - - /** - * Equal only if the other list is empty. - * @param o The object to compare against this list. - * @return <code>true</code> if o is also an empty instance of - * <code>List</code>. - */ - public boolean equals(Object o) - { - return o instanceof List && ((List) o).isEmpty(); - } - - /** - * The hashcode is always 1. - * @return 1. - */ - public int hashCode() - { - return 1; - } - - /** - * Returns -1. - * @param o The object to search for. - * @return -1. - */ - public int indexOf(Object o) - { - return -1; - } - - /** - * Returns -1. - * @param o The object to search for. - * @return -1. - */ - public int lastIndexOf(Object o) - { - return -1; - } - - /** - * Always succeeds with <code>false</code> result. - * @param o The object to remove. - * @return -1. - */ - public boolean remove(Object o) - { - return false; - } - - /** - * Always succeeds with <code>false</code> result. - * @param c The collection of objects which should - * all be removed from this list. - * @return <code>false</code>. - */ - public boolean removeAll(Collection c) - { - return false; - } - - /** - * Always succeeds with <code>false</code> result. - * @param c The collection of objects which should - * all be retained within this list. - * @return <code>false</code>. - */ - public boolean retainAll(Collection c) - { - return false; - } - - /** - * The array is always empty. - * @return A new array with a size of 0. - */ - public Object[] toArray() - { - return new Object[0]; - } - - /** - * We don't even need to use reflection! - * @param a An existing array, which can be empty. - * @return The original array with any existing - * initial element set to null. - */ - public Object[] toArray(Object[] a) - { - if (a.length > 0) - a[0] = null; - return a; - } - - /** - * The string never changes. - * - * @return the string "[]". - */ - public String toString() - { - return "[]"; - } - } // class EmptyList - - /** - * An immutable, serializable, empty Map. - * @see Serializable - */ - public static final Map EMPTY_MAP = new EmptyMap(); - - /** - * The implementation of {@link #EMPTY_MAP}. This class name is required - * for compatibility with Sun's JDK serializability. - * - * @author Eric Blake (ebb9@email.byu.edu) - */ - private static final class EmptyMap extends AbstractMap - implements Serializable - { - /** - * Compatible with JDK 1.4. - */ - private static final long serialVersionUID = 6428348081105594320L; - - /** - * A private constructor adds overhead. - */ - EmptyMap() - { - } - - /** - * There are no entries. - * @return The empty set. - */ - public Set entrySet() - { - return EMPTY_SET; - } - - // The remaining methods are optional, but provide a performance - // advantage by not allocating unnecessary iterators in AbstractMap. - /** - * No entries! - * @param key The key to search for. - * @return <code>false</code>. - */ - public boolean containsKey(Object key) - { - return false; - } - - /** - * No entries! - * @param value The value to search for. - * @return <code>false</code>. - */ - public boolean containsValue(Object value) - { - return false; - } - - /** - * Equal to all empty maps. - * @param o The object o to compare against this map. - * @return <code>true</code> if o is also an empty instance of - * <code>Map</code>. - */ - public boolean equals(Object o) - { - return o instanceof Map && ((Map) o).isEmpty(); - } - - /** - * No mappings, so this returns null. - * @param o The key of the object to retrieve. - * @return null. - */ - public Object get(Object o) - { - return null; - } - - /** - * The hashcode is always 0. - * @return 0. - */ - public int hashCode() - { - return 0; - } - - /** - * No entries. - * @return The empty set. - */ - public Set keySet() - { - return EMPTY_SET; - } - - /** - * Remove always succeeds, with null result. - * @param o The key of the mapping to remove. - * @return null, as there is never a mapping for o. - */ - public Object remove(Object o) - { - return null; - } - - /** - * Size is always 0. - * @return 0. - */ - public int size() - { - return 0; - } - - /** - * No entries. Technically, EMPTY_SET, while more specific than a general - * Collection, will work. Besides, that's what the JDK uses! - * @return The empty set. - */ - public Collection values() - { - return EMPTY_SET; - } - - /** - * The string never changes. - * - * @return the string "[]". - */ - public String toString() - { - return "[]"; - } - } // class EmptyMap - - - /** - * Compare two objects with or without a Comparator. If c is null, uses the - * natural ordering. Slightly slower than doing it inline if the JVM isn't - * clever, but worth it for removing a duplicate of the search code. - * Note: This code is also used in Arrays (for sort as well as search). - */ - static final int compare(Object o1, Object o2, Comparator c) - { - return c == null ? ((Comparable) o1).compareTo(o2) : c.compare(o1, o2); - } - - /** - * Perform a binary search of a List for a key, using the natural ordering of - * the elements. The list must be sorted (as by the sort() method) - if it is - * not, the behavior of this method is undefined, and may be an infinite - * loop. Further, the key must be comparable with every item in the list. If - * the list contains the key more than once, any one of them may be found. - * <p> - * - * This algorithm behaves in log(n) time for {@link RandomAccess} lists, - * and uses a linear search with O(n) link traversals and log(n) comparisons - * with {@link AbstractSequentialList} lists. Note: although the - * specification allows for an infinite loop if the list is unsorted, it will - * not happen in this (Classpath) implementation. - * - * @param l the list to search (must be sorted) - * @param key the value to search for - * @return the index at which the key was found, or -n-1 if it was not - * found, where n is the index of the first value higher than key or - * a.length if there is no such value - * @throws ClassCastException if key could not be compared with one of the - * elements of l - * @throws NullPointerException if a null element has compareTo called - * @see #sort(List) - */ - public static int binarySearch(List l, Object key) - { - return binarySearch(l, key, null); - } - - /** - * Perform a binary search of a List for a key, using a supplied Comparator. - * The list must be sorted (as by the sort() method with the same Comparator) - * - if it is not, the behavior of this method is undefined, and may be an - * infinite loop. Further, the key must be comparable with every item in the - * list. If the list contains the key more than once, any one of them may be - * found. If the comparator is null, the elements' natural ordering is used. - * <p> - * - * This algorithm behaves in log(n) time for {@link RandomAccess} lists, - * and uses a linear search with O(n) link traversals and log(n) comparisons - * with {@link AbstractSequentialList} lists. Note: although the - * specification allows for an infinite loop if the list is unsorted, it will - * not happen in this (Classpath) implementation. - * - * @param l the list to search (must be sorted) - * @param key the value to search for - * @param c the comparator by which the list is sorted - * @return the index at which the key was found, or -n-1 if it was not - * found, where n is the index of the first value higher than key or - * a.length if there is no such value - * @throws ClassCastException if key could not be compared with one of the - * elements of l - * @throws NullPointerException if a null element is compared with natural - * ordering (only possible when c is null) - * @see #sort(List, Comparator) - */ - public static int binarySearch(List l, Object key, Comparator c) - { - int pos = 0; - int low = 0; - int hi = l.size() - 1; - - // We use a linear search with log(n) comparisons using an iterator - // if the list is sequential-access. - if (isSequential(l)) - { - ListIterator itr = l.listIterator(); - int i = 0; - Object o = itr.next(); // Assumes list is not empty (see isSequential) - boolean forward = true; - while (low <= hi) - { - pos = (low + hi) >> 1; - if (i < pos) - { - if (!forward) - itr.next(); // Changing direction first. - for ( ; i != pos; i++, o = itr.next()); - forward = true; - } - else - { - if (forward) - itr.previous(); // Changing direction first. - for ( ; i != pos; i--, o = itr.previous()); - forward = false; - } - final int d = compare(key, o, c); - if (d == 0) - return pos; - else if (d < 0) - hi = pos - 1; - else - // This gets the insertion point right on the last loop - low = ++pos; - } - } - else - { - while (low <= hi) - { - pos = (low + hi) >> 1; - final int d = compare(key, l.get(pos), c); - if (d == 0) - return pos; - else if (d < 0) - hi = pos - 1; - else - // This gets the insertion point right on the last loop - low = ++pos; - } - } - - // If we failed to find it, we do the same whichever search we did. - return -pos - 1; - } - - /** - * Copy one list to another. If the destination list is longer than the - * source list, the remaining elements are unaffected. This method runs in - * linear time. - * - * @param dest the destination list - * @param source the source list - * @throws IndexOutOfBoundsException if the destination list is shorter - * than the source list (the destination will be unmodified) - * @throws UnsupportedOperationException if dest.listIterator() does not - * support the set operation - */ - public static void copy(List dest, List source) - { - int pos = source.size(); - if (dest.size() < pos) - throw new IndexOutOfBoundsException("Source does not fit in dest"); - - Iterator i1 = source.iterator(); - ListIterator i2 = dest.listIterator(); - - while (--pos >= 0) - { - i2.next(); - i2.set(i1.next()); - } - } - - /** - * Returns an Enumeration over a collection. This allows interoperability - * with legacy APIs that require an Enumeration as input. - * - * @param c the Collection to iterate over - * @return an Enumeration backed by an Iterator over c - */ - public static Enumeration enumeration(Collection c) - { - final Iterator i = c.iterator(); - return new Enumeration() - { - /** - * Returns <code>true</code> if there are more elements to - * be enumerated. - * - * @return The result of <code>hasNext()</code> - * called on the underlying iterator. - */ - public final boolean hasMoreElements() - { - return i.hasNext(); - } - - /** - * Returns the next element to be enumerated. - * - * @return The result of <code>next()</code> - * called on the underlying iterator. - */ - public final Object nextElement() - { - return i.next(); - } - }; - } - - /** - * Replace every element of a list with a given value. This method runs in - * linear time. - * - * @param l the list to fill. - * @param val the object to vill the list with. - * @throws UnsupportedOperationException if l.listIterator() does not - * support the set operation. - */ - public static void fill(List l, Object val) - { - ListIterator itr = l.listIterator(); - for (int i = l.size() - 1; i >= 0; --i) - { - itr.next(); - itr.set(val); - } - } - - /** - * Returns the starting index where the specified sublist first occurs - * in a larger list, or -1 if there is no matching position. If - * <code>target.size() > source.size()</code>, this returns -1, - * otherwise this implementation uses brute force, checking for - * <code>source.sublist(i, i + target.size()).equals(target)</code> - * for all possible i. - * - * @param source the list to search - * @param target the sublist to search for - * @return the index where found, or -1 - * @since 1.4 - */ - public static int indexOfSubList(List source, List target) - { - int ssize = source.size(); - for (int i = 0, j = target.size(); j <= ssize; i++, j++) - if (source.subList(i, j).equals(target)) - return i; - return -1; - } - - /** - * Returns the starting index where the specified sublist last occurs - * in a larger list, or -1 if there is no matching position. If - * <code>target.size() > source.size()</code>, this returns -1, - * otherwise this implementation uses brute force, checking for - * <code>source.sublist(i, i + target.size()).equals(target)</code> - * for all possible i. - * - * @param source the list to search - * @param target the sublist to search for - * @return the index where found, or -1 - * @since 1.4 - */ - public static int lastIndexOfSubList(List source, List target) - { - int ssize = source.size(); - for (int i = ssize - target.size(), j = ssize; i >= 0; i--, j--) - if (source.subList(i, j).equals(target)) - return i; - return -1; - } - - /** - * Returns an ArrayList holding the elements visited by a given - * Enumeration. This method exists for interoperability between legacy - * APIs and the new Collection API. - * - * @param e the enumeration to put in a list - * @return a list containing the enumeration elements - * @see ArrayList - * @since 1.4 - */ - public static ArrayList list(Enumeration e) - { - ArrayList l = new ArrayList(); - while (e.hasMoreElements()) - l.add(e.nextElement()); - return l; - } - - /** - * Find the maximum element in a Collection, according to the natural - * ordering of the elements. This implementation iterates over the - * Collection, so it works in linear time. - * - * @param c the Collection to find the maximum element of - * @return the maximum element of c - * @exception NoSuchElementException if c is empty - * @exception ClassCastException if elements in c are not mutually comparable - * @exception NullPointerException if null.compareTo is called - */ - public static Object max(Collection c) - { - return max(c, null); - } - - /** - * Find the maximum element in a Collection, according to a specified - * Comparator. This implementation iterates over the Collection, so it - * works in linear time. - * - * @param c the Collection to find the maximum element of - * @param order the Comparator to order the elements by, or null for natural - * ordering - * @return the maximum element of c - * @throws NoSuchElementException if c is empty - * @throws ClassCastException if elements in c are not mutually comparable - * @throws NullPointerException if null is compared by natural ordering - * (only possible when order is null) - */ - public static Object max(Collection c, Comparator order) - { - Iterator itr = c.iterator(); - Object max = itr.next(); // throws NoSuchElementException - int csize = c.size(); - for (int i = 1; i < csize; i++) - { - Object o = itr.next(); - if (compare(max, o, order) < 0) - max = o; - } - return max; - } - - /** - * Find the minimum element in a Collection, according to the natural - * ordering of the elements. This implementation iterates over the - * Collection, so it works in linear time. - * - * @param c the Collection to find the minimum element of - * @return the minimum element of c - * @throws NoSuchElementException if c is empty - * @throws ClassCastException if elements in c are not mutually comparable - * @throws NullPointerException if null.compareTo is called - */ - public static Object min(Collection c) - { - return min(c, null); - } - - /** - * Find the minimum element in a Collection, according to a specified - * Comparator. This implementation iterates over the Collection, so it - * works in linear time. - * - * @param c the Collection to find the minimum element of - * @param order the Comparator to order the elements by, or null for natural - * ordering - * @return the minimum element of c - * @throws NoSuchElementException if c is empty - * @throws ClassCastException if elements in c are not mutually comparable - * @throws NullPointerException if null is compared by natural ordering - * (only possible when order is null) - */ - public static Object min(Collection c, Comparator order) - { - Iterator itr = c.iterator(); - Object min = itr.next(); // throws NoSuchElementExcception - int csize = c.size(); - for (int i = 1; i < csize; i++) - { - Object o = itr.next(); - if (compare(min, o, order) > 0) - min = o; - } - return min; - } - - /** - * Creates an immutable list consisting of the same object repeated n times. - * The returned object is tiny, consisting of only a single reference to the - * object and a count of the number of elements. It is Serializable, and - * implements RandomAccess. You can use it in tandem with List.addAll for - * fast list construction. - * - * @param n the number of times to repeat the object - * @param o the object to repeat - * @return a List consisting of n copies of o - * @throws IllegalArgumentException if n < 0 - * @see List#addAll(Collection) - * @see Serializable - * @see RandomAccess - */ - public static List nCopies(final int n, final Object o) - { - return new CopiesList(n, o); - } - - /** - * The implementation of {@link #nCopies(int, Object)}. This class name - * is required for compatibility with Sun's JDK serializability. - * - * @author Eric Blake (ebb9@email.byu.edu) - */ - private static final class CopiesList extends AbstractList - implements Serializable, RandomAccess - { - /** - * Compatible with JDK 1.4. - */ - private static final long serialVersionUID = 2739099268398711800L; - - /** - * The count of elements in this list. - * @serial the list size - */ - private final int n; - - /** - * The repeated list element. - * @serial the list contents - */ - private final Object element; - - /** - * Constructs the list. - * - * @param n the count - * @param o the object - * @throws IllegalArgumentException if n < 0 - */ - CopiesList(int n, Object o) - { - if (n < 0) - throw new IllegalArgumentException(); - this.n = n; - element = o; - } - - /** - * The size is fixed. - * @return The size of the list. - */ - public int size() - { - return n; - } - - /** - * The same element is returned. - * @param index The index of the element to be returned (irrelevant - * as the list contains only copies of <code>element</code>). - * @return The element used by this list. - */ - public Object get(int index) - { - if (index < 0 || index >= n) - throw new IndexOutOfBoundsException(); - return element; - } - - // The remaining methods are optional, but provide a performance - // advantage by not allocating unnecessary iterators in AbstractList. - /** - * This list only contains one element. - * @param o The object to search for. - * @return <code>true</code> if o is the element used by this list. - */ - public boolean contains(Object o) - { - return n > 0 && equals(o, element); - } - - /** - * The index is either 0 or -1. - * @param o The object to find the index of. - * @return 0 if <code>o == element</code>, -1 if not. - */ - public int indexOf(Object o) - { - return (n > 0 && equals(o, element)) ? 0 : -1; - } - - /** - * The index is either n-1 or -1. - * @param o The object to find the last index of. - * @return The last index in the list if <code>o == element</code>, - * -1 if not. - */ - public int lastIndexOf(Object o) - { - return equals(o, element) ? n - 1 : -1; - } - - /** - * A subList is just another CopiesList. - * @param from The starting bound of the sublist. - * @param to The ending bound of the sublist. - * @return A list of copies containing <code>from - to</code> - * elements, all of which are equal to the element - * used by this list. - */ - public List subList(int from, int to) - { - if (from < 0 || to > n) - throw new IndexOutOfBoundsException(); - return new CopiesList(to - from, element); - } - - /** - * The array is easy. - * @return An array of size n filled with copies of - * the element used by this list. - */ - public Object[] toArray() - { - Object[] a = new Object[n]; - Arrays.fill(a, element); - return a; - } - - /** - * The string is easy to generate. - * @return A string representation of the list. - */ - public String toString() - { - StringBuffer r = new StringBuffer("{"); - for (int i = n - 1; --i > 0; ) - r.append(element).append(", "); - r.append(element).append("}"); - return r.toString(); - } - } // class CopiesList - - /** - * Replace all instances of one object with another in the specified list. - * The list does not change size. An element e is replaced if - * <code>oldval == null ? e == null : oldval.equals(e)</code>. - * - * @param list the list to iterate over - * @param oldval the element to replace - * @param newval the new value for the element - * @return <code>true</code> if a replacement occurred. - * @throws UnsupportedOperationException if the list iterator does not allow - * for the set operation - * @throws ClassCastException if newval is of a type which cannot be added - * to the list - * @throws IllegalArgumentException if some other aspect of newval stops - * it being added to the list - * @since 1.4 - */ - public static boolean replaceAll(List list, Object oldval, Object newval) - { - ListIterator itr = list.listIterator(); - boolean replace_occured = false; - for (int i = list.size(); --i >= 0; ) - if (AbstractCollection.equals(oldval, itr.next())) - { - itr.set(newval); - replace_occured = true; - } - return replace_occured; - } - - /** - * Reverse a given list. This method works in linear time. - * - * @param l the list to reverse - * @throws UnsupportedOperationException if l.listIterator() does not - * support the set operation - */ - public static void reverse(List l) - { - ListIterator i1 = l.listIterator(); - int pos1 = 1; - int pos2 = l.size(); - ListIterator i2 = l.listIterator(pos2); - while (pos1 < pos2) - { - Object o = i1.next(); - i1.set(i2.previous()); - i2.set(o); - ++pos1; - --pos2; - } - } - - /** - * Get a comparator that implements the reverse of natural ordering. In - * other words, this sorts Comparable objects opposite of how their - * compareTo method would sort. This makes it easy to sort into reverse - * order, by simply passing Collections.reverseOrder() to the sort method. - * The return value of this method is Serializable. - * - * @return a comparator that imposes reverse natural ordering - * @see Comparable - * @see Serializable - */ - public static Comparator reverseOrder() - { - return rcInstance; - } - - /** - * The object for {@link #reverseOrder()}. - */ - private static final ReverseComparator rcInstance = new ReverseComparator(); - - /** - * The implementation of {@link #reverseOrder()}. This class name - * is required for compatibility with Sun's JDK serializability. - * - * @author Eric Blake (ebb9@email.byu.edu) - */ - private static final class ReverseComparator - implements Comparator, Serializable - { - /** - * Compatible with JDK 1.4. - */ - private static final long serialVersionUID = 7207038068494060240L; - - /** - * A private constructor adds overhead. - */ - ReverseComparator() - { - } - - /** - * Compare two objects in reverse natural order. - * - * @param a the first object - * @param b the second object - * @return <, ==, or > 0 according to b.compareTo(a) - */ - public int compare(Object a, Object b) - { - return ((Comparable) b).compareTo(a); - } - } - - /** - * Rotate the elements in a list by a specified distance. After calling this - * method, the element now at index <code>i</code> was formerly at index - * <code>(i - distance) mod list.size()</code>. The list size is unchanged. - * <p> - * - * For example, suppose a list contains <code>[t, a, n, k, s]</code>. After - * either <code>Collections.rotate(l, 4)</code> or - * <code>Collections.rotate(l, -1)</code>, the new contents are - * <code>[s, t, a, n, k]</code>. This can be applied to sublists to rotate - * just a portion of the list. For example, to move element <code>a</code> - * forward two positions in the original example, use - * <code>Collections.rotate(l.subList(1, 3+1), -1)</code>, which will - * result in <code>[t, n, k, a, s]</code>. - * <p> - * - * If the list is small or implements {@link RandomAccess}, the - * implementation exchanges the first element to its destination, then the - * displaced element, and so on until a circuit has been completed. The - * process is repeated if needed on the second element, and so forth, until - * all elements have been swapped. For large non-random lists, the - * implementation breaks the list into two sublists at index - * <code>-distance mod size</code>, calls {@link #reverse(List)} on the - * pieces, then reverses the overall list. - * - * @param list the list to rotate - * @param distance the distance to rotate by; unrestricted in value - * @throws UnsupportedOperationException if the list does not support set - * @since 1.4 - */ - public static void rotate(List list, int distance) - { - int size = list.size(); - if (size == 0) - return; - distance %= size; - if (distance == 0) - return; - if (distance < 0) - distance += size; - - if (isSequential(list)) - { - reverse(list); - reverse(list.subList(0, distance)); - reverse(list.subList(distance, size)); - } - else - { - // Determine the least common multiple of distance and size, as there - // are (distance / LCM) loops to cycle through. - int a = size; - int lcm = distance; - int b = a % lcm; - while (b != 0) - { - a = lcm; - lcm = b; - b = a % lcm; - } - - // Now, make the swaps. We must take the remainder every time through - // the inner loop so that we don't overflow i to negative values. - while (--lcm >= 0) - { - Object o = list.get(lcm); - for (int i = lcm + distance; i != lcm; i = (i + distance) % size) - o = list.set(i, o); - list.set(lcm, o); - } - } - } - - /** - * Shuffle a list according to a default source of randomness. The algorithm - * used iterates backwards over the list, swapping each element with an - * element randomly selected from the elements in positions less than or - * equal to it (using r.nextInt(int)). - * <p> - * - * This algorithm would result in a perfectly fair shuffle (that is, each - * element would have an equal chance of ending up in any position) if r were - * a perfect source of randomness. In practice the results are merely very - * close to perfect. - * <p> - * - * This method operates in linear time. To do this on large lists which do - * not implement {@link RandomAccess}, a temporary array is used to acheive - * this speed, since it would be quadratic access otherwise. - * - * @param l the list to shuffle - * @throws UnsupportedOperationException if l.listIterator() does not - * support the set operation - */ - public static void shuffle(List l) - { - if (defaultRandom == null) - { - synchronized (Collections.class) - { - if (defaultRandom == null) - defaultRandom = new Random(); - } - } - shuffle(l, defaultRandom); - } - - /** - * Cache a single Random object for use by shuffle(List). This improves - * performance as well as ensuring that sequential calls to shuffle() will - * not result in the same shuffle order occurring: the resolution of - * System.currentTimeMillis() is not sufficient to guarantee a unique seed. - */ - private static Random defaultRandom = null; - - /** - * Shuffle a list according to a given source of randomness. The algorithm - * used iterates backwards over the list, swapping each element with an - * element randomly selected from the elements in positions less than or - * equal to it (using r.nextInt(int)). - * <p> - * - * This algorithm would result in a perfectly fair shuffle (that is, each - * element would have an equal chance of ending up in any position) if r were - * a perfect source of randomness. In practise (eg if r = new Random()) the - * results are merely very close to perfect. - * <p> - * - * This method operates in linear time. To do this on large lists which do - * not implement {@link RandomAccess}, a temporary array is used to acheive - * this speed, since it would be quadratic access otherwise. - * - * @param l the list to shuffle - * @param r the source of randomness to use for the shuffle - * @throws UnsupportedOperationException if l.listIterator() does not - * support the set operation - */ - public static void shuffle(List l, Random r) - { - int lsize = l.size(); - ListIterator i = l.listIterator(lsize); - boolean sequential = isSequential(l); - Object[] a = null; // stores a copy of the list for the sequential case - - if (sequential) - a = l.toArray(); - - for (int pos = lsize - 1; pos > 0; --pos) - { - // Obtain a random position to swap with. pos + 1 is used so that the - // range of the random number includes the current position. - int swap = r.nextInt(pos + 1); - - // Swap the desired element. - Object o; - if (sequential) - { - o = a[swap]; - a[swap] = i.previous(); - } - else - o = l.set(swap, i.previous()); - - i.set(o); - } - } - - - /** - * Obtain an immutable Set consisting of a single element. The return value - * of this method is Serializable. - * - * @param o the single element - * @return an immutable Set containing only o - * @see Serializable - */ - public static Set singleton(Object o) - { - return new SingletonSet(o); - } - - /** - * The implementation of {@link #singleton(Object)}. This class name - * is required for compatibility with Sun's JDK serializability. - * - * @author Eric Blake (ebb9@email.byu.edu) - */ - private static final class SingletonSet extends AbstractSet - implements Serializable - { - /** - * Compatible with JDK 1.4. - */ - private static final long serialVersionUID = 3193687207550431679L; - - - /** - * The single element; package visible for use in nested class. - * @serial the singleton - */ - final Object element; - - /** - * Construct a singleton. - * @param o the element - */ - SingletonSet(Object o) - { - element = o; - } - - /** - * The size: always 1! - * @return 1. - */ - public int size() - { - return 1; - } - - /** - * Returns an iterator over the lone element. - */ - public Iterator iterator() - { - return new Iterator() - { - /** - * Flag to indicate whether or not the element has - * been retrieved. - */ - private boolean hasNext = true; - - /** - * Returns <code>true</code> if elements still remain to be - * iterated through. - * - * @return <code>true</code> if the element has not yet been returned. - */ - public boolean hasNext() - { - return hasNext; - } - - /** - * Returns the element. - * - * @return The element used by this singleton. - * @throws NoSuchElementException if the object - * has already been retrieved. - */ - public Object next() - { - if (hasNext) - { - hasNext = false; - return element; - } - else - throw new NoSuchElementException(); - } - - /** - * Removes the element from the singleton. - * As this set is immutable, this will always - * throw an exception. - * - * @throws UnsupportedOperationException as the - * singleton set doesn't support - * <code>remove()</code>. - */ - public void remove() - { - throw new UnsupportedOperationException(); - } - }; - } - - // The remaining methods are optional, but provide a performance - // advantage by not allocating unnecessary iterators in AbstractSet. - /** - * The set only contains one element. - * - * @param o The object to search for. - * @return <code>true</code> if o == the element of the singleton. - */ - public boolean contains(Object o) - { - return equals(o, element); - } - - /** - * This is true if the other collection only contains the element. - * - * @param c A collection to compare against this singleton. - * @return <code>true</code> if c only contains either no elements or - * elements equal to the element in this singleton. - */ - public boolean containsAll(Collection c) - { - Iterator i = c.iterator(); - int pos = c.size(); - while (--pos >= 0) - if (! equals(i.next(), element)) - return false; - return true; - } - - /** - * The hash is just that of the element. - * - * @return The hashcode of the element. - */ - public int hashCode() - { - return hashCode(element); - } - - /** - * Returning an array is simple. - * - * @return An array containing the element. - */ - public Object[] toArray() - { - return new Object[] {element}; - } - - /** - * Obvious string. - * - * @return The string surrounded by enclosing - * square brackets. - */ - public String toString() - { - return "[" + element + "]"; - } - } // class SingletonSet - - /** - * Obtain an immutable List consisting of a single element. The return value - * of this method is Serializable, and implements RandomAccess. - * - * @param o the single element - * @return an immutable List containing only o - * @see Serializable - * @see RandomAccess - * @since 1.3 - */ - public static List singletonList(Object o) - { - return new SingletonList(o); - } - - /** - * The implementation of {@link #singletonList(Object)}. This class name - * is required for compatibility with Sun's JDK serializability. - * - * @author Eric Blake (ebb9@email.byu.edu) - */ - private static final class SingletonList extends AbstractList - implements Serializable, RandomAccess - { - /** - * Compatible with JDK 1.4. - */ - private static final long serialVersionUID = 3093736618740652951L; - - /** - * The single element. - * @serial the singleton - */ - private final Object element; - - /** - * Construct a singleton. - * @param o the element - */ - SingletonList(Object o) - { - element = o; - } - - /** - * The size: always 1! - * @return 1. - */ - public int size() - { - return 1; - } - - /** - * Only index 0 is valid. - * @param index The index of the element - * to retrieve. - * @return The singleton's element if the - * index is 0. - * @throws IndexOutOfBoundsException if - * index is not 0. - */ - public Object get(int index) - { - if (index == 0) - return element; - throw new IndexOutOfBoundsException(); - } - - // The remaining methods are optional, but provide a performance - // advantage by not allocating unnecessary iterators in AbstractList. - /** - * The set only contains one element. - * - * @param o The object to search for. - * @return <code>true</code> if o == the singleton element. - */ - public boolean contains(Object o) - { - return equals(o, element); - } - - /** - * This is true if the other collection only contains the element. - * - * @param c A collection to compare against this singleton. - * @return <code>true</code> if c only contains either no elements or - * elements equal to the element in this singleton. - */ - public boolean containsAll(Collection c) - { - Iterator i = c.iterator(); - int pos = c.size(); - while (--pos >= 0) - if (! equals(i.next(), element)) - return false; - return true; - } - - /** - * Speed up the hashcode computation. - * - * @return The hashcode of the list, based - * on the hashcode of the singleton element. - */ - public int hashCode() - { - return 31 + hashCode(element); - } - - /** - * Either the list has it or not. - * - * @param o The object to find the first index of. - * @return 0 if o is the singleton element, -1 if not. - */ - public int indexOf(Object o) - { - return equals(o, element) ? 0 : -1; - } - - /** - * Either the list has it or not. - * - * @param o The object to find the last index of. - * @return 0 if o is the singleton element, -1 if not. - */ - public int lastIndexOf(Object o) - { - return equals(o, element) ? 0 : -1; - } - - /** - * Sublists are limited in scope. - * - * @param from The starting bound for the sublist. - * @param to The ending bound for the sublist. - * @return Either an empty list if both bounds are - * 0 or 1, or this list if the bounds are 0 and 1. - * @throws IllegalArgumentException if <code>from > to</code> - * @throws IndexOutOfBoundsException if either bound is greater - * than 1. - */ - public List subList(int from, int to) - { - if (from == to && (to == 0 || to == 1)) - return EMPTY_LIST; - if (from == 0 && to == 1) - return this; - if (from > to) - throw new IllegalArgumentException(); - throw new IndexOutOfBoundsException(); - } - - /** - * Returning an array is simple. - * - * @return An array containing the element. - */ - public Object[] toArray() - { - return new Object[] {element}; - } - - /** - * Obvious string. - * - * @return The string surrounded by enclosing - * square brackets. - */ - public String toString() - { - return "[" + element + "]"; - } - } // class SingletonList - - /** - * Obtain an immutable Map consisting of a single key-value pair. - * The return value of this method is Serializable. - * - * @param key the single key - * @param value the single value - * @return an immutable Map containing only the single key-value pair - * @see Serializable - * @since 1.3 - */ - public static Map singletonMap(Object key, Object value) - { - return new SingletonMap(key, value); - } - - /** - * The implementation of {@link #singletonMap(Object)}. This class name - * is required for compatibility with Sun's JDK serializability. - * - * @author Eric Blake (ebb9@email.byu.edu) - */ - private static final class SingletonMap extends AbstractMap - implements Serializable - { - /** - * Compatible with JDK 1.4. - */ - private static final long serialVersionUID = -6979724477215052911L; - - /** - * The single key. - * @serial the singleton key - */ - private final Object k; - - /** - * The corresponding value. - * @serial the singleton value - */ - private final Object v; - - /** - * Cache the entry set. - */ - private transient Set entries; - - /** - * Construct a singleton. - * @param key the key - * @param value the value - */ - SingletonMap(Object key, Object value) - { - k = key; - v = value; - } - - /** - * There is a single immutable entry. - * - * @return A singleton containing the map entry. - */ - public Set entrySet() - { - if (entries == null) - entries = singleton(new AbstractMap.BasicMapEntry(k, v) - { - /** - * Sets the value of the map entry to the supplied value. - * An exception is always thrown, as the map is immutable. - * - * @param o The new value. - * @return The old value. - * @throws UnsupportedOperationException as setting the value - * is not supported. - */ - public Object setValue(Object o) - { - throw new UnsupportedOperationException(); - } - }); - return entries; - } - - // The remaining methods are optional, but provide a performance - // advantage by not allocating unnecessary iterators in AbstractMap. - /** - * Single entry. - * - * @param key The key to look for. - * @return <code>true</code> if the key is the same as the one used by - * this map. - */ - public boolean containsKey(Object key) - { - return equals(key, k); - } - - /** - * Single entry. - * - * @param value The value to look for. - * @return <code>true</code> if the value is the same as the one used by - * this map. - */ - public boolean containsValue(Object value) - { - return equals(value, v); - } - - /** - * Single entry. - * - * @param key The key of the value to be retrieved. - * @return The singleton value if the key is the same as the - * singleton key, null otherwise. - */ - public Object get(Object key) - { - return equals(key, k) ? v : null; - } - - /** - * Calculate the hashcode directly. - * - * @return The hashcode computed from the singleton key - * and the singleton value. - */ - public int hashCode() - { - return hashCode(k) ^ hashCode(v); - } - - /** - * Return the keyset. - * - * @return A singleton containing the key. - */ - public Set keySet() - { - if (keys == null) - keys = singleton(k); - return keys; - } - - /** - * The size: always 1! - * - * @return 1. - */ - public int size() - { - return 1; - } - - /** - * Return the values. Technically, a singleton, while more specific than - * a general Collection, will work. Besides, that's what the JDK uses! - * - * @return A singleton containing the value. - */ - public Collection values() - { - if (values == null) - values = singleton(v); - return values; - } - - /** - * Obvious string. - * - * @return A string containing the string representations of the key - * and its associated value. - */ - public String toString() - { - return "{" + k + "=" + v + "}"; - } - } // class SingletonMap - - /** - * Sort a list according to the natural ordering of its elements. The list - * must be modifiable, but can be of fixed size. The sort algorithm is - * precisely that used by Arrays.sort(Object[]), which offers guaranteed - * nlog(n) performance. This implementation dumps the list into an array, - * sorts the array, and then iterates over the list setting each element from - * the array. - * - * @param l the List to sort - * @throws ClassCastException if some items are not mutually comparable - * @throws UnsupportedOperationException if the List is not modifiable - * @throws NullPointerException if some element is null - * @see Arrays#sort(Object[]) - */ - public static void sort(List l) - { - sort(l, null); - } - - /** - * Sort a list according to a specified Comparator. The list must be - * modifiable, but can be of fixed size. The sort algorithm is precisely that - * used by Arrays.sort(Object[], Comparator), which offers guaranteed - * nlog(n) performance. This implementation dumps the list into an array, - * sorts the array, and then iterates over the list setting each element from - * the array. - * - * @param l the List to sort - * @param c the Comparator specifying the ordering for the elements, or - * null for natural ordering - * @throws ClassCastException if c will not compare some pair of items - * @throws UnsupportedOperationException if the List is not modifiable - * @throws NullPointerException if null is compared by natural ordering - * (only possible when c is null) - * @see Arrays#sort(Object[], Comparator) - */ - public static void sort(List l, Comparator c) - { - Object[] a = l.toArray(); - Arrays.sort(a, c); - ListIterator i = l.listIterator(); - for (int pos = 0, alen = a.length; pos < alen; pos++) - { - i.next(); - i.set(a[pos]); - } - } - - /** - * Swaps the elements at the specified positions within the list. Equal - * positions have no effect. - * - * @param l the list to work on - * @param i the first index to swap - * @param j the second index - * @throws UnsupportedOperationException if list.set is not supported - * @throws IndexOutOfBoundsException if either i or j is < 0 or >= - * list.size() - * @since 1.4 - */ - public static void swap(List l, int i, int j) - { - l.set(i, l.set(j, l.get(i))); - } - - - /** - * Returns a synchronized (thread-safe) collection wrapper backed by the - * given collection. Notice that element access through the iterators - * is thread-safe, but if the collection can be structurally modified - * (adding or removing elements) then you should synchronize around the - * iteration to avoid non-deterministic behavior:<br> - * <pre> - * Collection c = Collections.synchronizedCollection(new Collection(...)); - * ... - * synchronized (c) - * { - * Iterator i = c.iterator(); - * while (i.hasNext()) - * foo(i.next()); - * } - * </pre><p> - * - * Since the collection might be a List or a Set, and those have incompatible - * equals and hashCode requirements, this relies on Object's implementation - * rather than passing those calls on to the wrapped collection. The returned - * Collection implements Serializable, but can only be serialized if - * the collection it wraps is likewise Serializable. - * - * @param c the collection to wrap - * @return a synchronized view of the collection - * @see Serializable - */ - public static Collection synchronizedCollection(Collection c) - { - return new SynchronizedCollection(c); - } - - /** - * The implementation of {@link #synchronizedCollection(Collection)}. This - * class name is required for compatibility with Sun's JDK serializability. - * Package visible, so that collections such as the one for - * Hashtable.values() can specify which object to synchronize on. - * - * @author Eric Blake (ebb9@email.byu.edu) - */ - static class SynchronizedCollection - implements Collection, Serializable - { - /** - * Compatible with JDK 1.4. - */ - private static final long serialVersionUID = 3053995032091335093L; - - /** - * The wrapped collection. Package visible for use by subclasses. - * @serial the real collection - */ - final Collection c; - - /** - * The object to synchronize on. When an instance is created via public - * methods, it will be this; but other uses like SynchronizedMap.values() - * must specify another mutex. Package visible for use by subclasses. - * @serial the lock - */ - final Object mutex; - - /** - * Wrap a given collection. - * @param c the collection to wrap - * @throws NullPointerException if c is null - */ - SynchronizedCollection(Collection c) - { - this.c = c; - mutex = this; - if (c == null) - throw new NullPointerException(); - } - - /** - * Called only by trusted code to specify the mutex as well as the - * collection. - * @param sync the mutex - * @param c the collection - */ - SynchronizedCollection(Object sync, Collection c) - { - this.c = c; - mutex = sync; - } - - /** - * Adds the object to the underlying collection, first - * obtaining a lock on the mutex. - * - * @param o The object to add. - * @return <code>true</code> if the collection was modified as a result - * of this action. - * @throws UnsupportedOperationException if this collection does not - * support the add operation. - * @throws ClassCastException if o cannot be added to this collection due - * to its type. - * @throws NullPointerException if o is null and this collection doesn't - * support the addition of null values. - * @throws IllegalArgumentException if o cannot be added to this - * collection for some other reason. - */ - public boolean add(Object o) - { - synchronized (mutex) - { - return c.add(o); - } - } - - /** - * Adds the objects in col to the underlying collection, first - * obtaining a lock on the mutex. - * - * @param col The collection to take the new objects from. - * @return <code>true</code> if the collection was modified as a result - * of this action. - * @throws UnsupportedOperationException if this collection does not - * support the addAll operation. - * @throws ClassCastException if some element of col cannot be added to this - * collection due to its type. - * @throws NullPointerException if some element of col is null and this - * collection does not support the addition of null values. - * @throws NullPointerException if col itself is null. - * @throws IllegalArgumentException if some element of col cannot be added - * to this collection for some other reason. - */ - public boolean addAll(Collection col) - { - synchronized (mutex) - { - return c.addAll(col); - } - } - - /** - * Removes all objects from the underlying collection, - * first obtaining a lock on the mutex. - * - * @throws UnsupportedOperationException if this collection does not - * support the clear operation. - */ - public void clear() - { - synchronized (mutex) - { - c.clear(); - } - } - - /** - * Checks for the existence of o within the underlying - * collection, first obtaining a lock on the mutex. - * - * @param o the element to look for. - * @return <code>true</code> if this collection contains at least one - * element e such that <code>o == null ? e == null : o.equals(e)</code>. - * @throws ClassCastException if the type of o is not a valid type for this - * collection. - * @throws NullPointerException if o is null and this collection doesn't - * support null values. - */ - public boolean contains(Object o) - { - synchronized (mutex) - { - return c.contains(o); - } - } - - /** - * Checks for the existence of each object in cl - * within the underlying collection, first obtaining - * a lock on the mutex. - * - * @param cl the collection to test for. - * @return <code>true</code> if for every element o in c, contains(o) - * would return <code>true</code>. - * @throws ClassCastException if the type of any element in cl is not a valid - * type for this collection. - * @throws NullPointerException if some element of cl is null and this - * collection does not support null values. - * @throws NullPointerException if cl itself is null. - */ - public boolean containsAll(Collection c1) - { - synchronized (mutex) - { - return c.containsAll(c1); - } - } - - /** - * Returns <code>true</code> if there are no objects in the underlying - * collection. A lock on the mutex is obtained before the - * check is performed. - * - * @return <code>true</code> if this collection contains no elements. - */ - public boolean isEmpty() - { - synchronized (mutex) - { - return c.isEmpty(); - } - } - - /** - * Returns a synchronized iterator wrapper around the underlying - * collection's iterator. A lock on the mutex is obtained before - * retrieving the collection's iterator. - * - * @return An iterator over the elements in the underlying collection, - * which returns each element in any order. - */ - public Iterator iterator() - { - synchronized (mutex) - { - return new SynchronizedIterator(mutex, c.iterator()); - } - } - - /** - * Removes the specified object from the underlying collection, - * first obtaining a lock on the mutex. - * - * @param o The object to remove. - * @return <code>true</code> if the collection changed as a result of this call, that is, - * if the collection contained at least one occurrence of o. - * @throws UnsupportedOperationException if this collection does not - * support the remove operation. - * @throws ClassCastException if the type of o is not a valid type - * for this collection. - * @throws NullPointerException if o is null and the collection doesn't - * support null values. - */ - public boolean remove(Object o) - { - synchronized (mutex) - { - return c.remove(o); - } - } - - /** - * Removes all elements, e, of the underlying - * collection for which <code>col.contains(e)</code> - * returns <code>true</code>. A lock on the mutex is obtained - * before the operation proceeds. - * - * @param col The collection of objects to be removed. - * @return <code>true</code> if this collection was modified as a result of this call. - * @throws UnsupportedOperationException if this collection does not - * support the removeAll operation. - * @throws ClassCastException if the type of any element in c is not a valid - * type for this collection. - * @throws NullPointerException if some element of c is null and this - * collection does not support removing null values. - * @throws NullPointerException if c itself is null. - */ - public boolean removeAll(Collection col) - { - synchronized (mutex) - { - return c.removeAll(col); - } - } - - /** - * Retains all elements, e, of the underlying - * collection for which <code>col.contains(e)</code> - * returns <code>true</code>. That is, every element that doesn't - * exist in col is removed. A lock on the mutex is obtained - * before the operation proceeds. - * - * @param col The collection of objects to be removed. - * @return <code>true</code> if this collection was modified as a result of this call. - * @throws UnsupportedOperationException if this collection does not - * support the removeAll operation. - * @throws ClassCastException if the type of any element in c is not a valid - * type for this collection. - * @throws NullPointerException if some element of c is null and this - * collection does not support removing null values. - * @throws NullPointerException if c itself is null. - */ - public boolean retainAll(Collection col) - { - synchronized (mutex) - { - return c.retainAll(col); - } - } - - /** - * Retrieves the size of the underlying collection. - * A lock on the mutex is obtained before the collection - * is accessed. - * - * @return The size of the collection. - */ - public int size() - { - synchronized (mutex) - { - return c.size(); - } - } - - /** - * Returns an array containing each object within the underlying - * collection. A lock is obtained on the mutex before the collection - * is accessed. - * - * @return An array of objects, matching the collection in size. The - * elements occur in any order. - */ - public Object[] toArray() - { - synchronized (mutex) - { - return c.toArray(); - } - } - - /** - * Copies the elements in the underlying collection to the supplied - * array. If <code>a.length < size()</code>, a new array of the - * same run-time type is created, with a size equal to that of - * the collection. If <code>a.length > size()</code>, then the - * elements from 0 to <code>size() - 1</code> contain the elements - * from this collection. The following element is set to null - * to indicate the end of the collection objects. However, this - * only makes a difference if null is not a permitted value within - * the collection. - * Before the copying takes place, a lock is obtained on the mutex. - * - * @param a An array to copy elements to. - * @return An array containing the elements of the underlying collection. - * @throws ArrayStoreException if the type of any element of the - * collection is not a subtype of the element type of a. - */ - public Object[] toArray(Object[] a) - { - synchronized (mutex) - { - return c.toArray(a); - } - } - - /** - * Returns a string representation of the underlying collection. - * A lock is obtained on the mutex before the string is created. - * - * @return A string representation of the collection. - */ - public String toString() - { - synchronized (mutex) - { - return c.toString(); - } - } - } // class SynchronizedCollection - - /** - * The implementation of the various iterator methods in the - * synchronized classes. These iterators must "sync" on the same object - * as the collection they iterate over. - * - * @author Eric Blake (ebb9@email.byu.edu) - */ - private static class SynchronizedIterator implements Iterator - { - /** - * The object to synchronize on. Package visible for use by subclass. - */ - final Object mutex; - - /** - * The wrapped iterator. - */ - private final Iterator i; - - /** - * Only trusted code creates a wrapper, with the specified sync. - * @param sync the mutex - * @param i the wrapped iterator - */ - SynchronizedIterator(Object sync, Iterator i) - { - this.i = i; - mutex = sync; - } - - /** - * Retrieves the next object in the underlying collection. - * A lock is obtained on the mutex before the collection is accessed. - * - * @return The next object in the collection. - * @throws NoSuchElementException if there are no more elements - */ - public Object next() - { - synchronized (mutex) - { - return i.next(); - } - } - - /** - * Returns <code>true</code> if objects can still be retrieved from the iterator - * using <code>next()</code>. A lock is obtained on the mutex before - * the collection is accessed. - * - * @return <code>true</code> if at least one element is still to be returned by - * <code>next()</code>. - */ - public boolean hasNext() - { - synchronized (mutex) - { - return i.hasNext(); - } - } - - /** - * Removes the object that was last returned by <code>next()</code> - * from the underlying collection. Only one call to this method is - * allowed per call to the <code>next()</code> method, and it does - * not affect the value that will be returned by <code>next()</code>. - * Thus, if element n was retrieved from the collection by - * <code>next()</code>, it is this element that gets removed. - * Regardless of whether this takes place or not, element n+1 is - * still returned on the subsequent <code>next()</code> call. - * - * @throws IllegalStateException if next has not yet been called or remove - * has already been called since the last call to next. - * @throws UnsupportedOperationException if this Iterator does not support - * the remove operation. - */ - public void remove() - { - synchronized (mutex) - { - i.remove(); - } - } - } // class SynchronizedIterator - - /** - * Returns a synchronized (thread-safe) list wrapper backed by the - * given list. Notice that element access through the iterators - * is thread-safe, but if the list can be structurally modified - * (adding or removing elements) then you should synchronize around the - * iteration to avoid non-deterministic behavior:<br> - * <pre> - * List l = Collections.synchronizedList(new List(...)); - * ... - * synchronized (l) - * { - * Iterator i = l.iterator(); - * while (i.hasNext()) - * foo(i.next()); - * } - * </pre><p> - * - * The returned List implements Serializable, but can only be serialized if - * the list it wraps is likewise Serializable. In addition, if the wrapped - * list implements RandomAccess, this does too. - * - * @param l the list to wrap - * @return a synchronized view of the list - * @see Serializable - * @see RandomAccess - */ - public static List synchronizedList(List l) - { - if (l instanceof RandomAccess) - return new SynchronizedRandomAccessList(l); - return new SynchronizedList(l); - } - - /** - * The implementation of {@link #synchronizedList(List)} for sequential - * lists. This class name is required for compatibility with Sun's JDK - * serializability. Package visible, so that lists such as Vector.subList() - * can specify which object to synchronize on. - * - * @author Eric Blake (ebb9@email.byu.edu) - */ - static class SynchronizedList extends SynchronizedCollection - implements List - { - /** - * Compatible with JDK 1.4. - */ - private static final long serialVersionUID = -7754090372962971524L; - - /** - * The wrapped list; stored both here and in the superclass to avoid - * excessive casting. Package visible for use by subclass. - * @serial the wrapped list - */ - final List list; - - /** - * Wrap a given list. - * @param l the list to wrap - * @throws NullPointerException if l is null - */ - SynchronizedList(List l) - { - super(l); - list = l; - } - - /** - * Called only by trusted code to specify the mutex as well as the list. - * @param sync the mutex - * @param l the list - */ - SynchronizedList(Object sync, List l) - { - super(sync, l); - list = l; - } - - /** - * Insert an element into the underlying list at a given position (optional - * operation). This shifts all existing elements from that position to the - * end one index to the right. This version of add has no return, since it is - * assumed to always succeed if there is no exception. Before the - * addition takes place, a lock is obtained on the mutex. - * - * @param index the location to insert the item - * @param o the object to insert - * @throws UnsupportedOperationException if this list does not support the - * add operation - * @throws IndexOutOfBoundsException if index < 0 || index > size() - * @throws ClassCastException if o cannot be added to this list due to its - * type - * @throws IllegalArgumentException if o cannot be added to this list for - * some other reason - * @throws NullPointerException if o is null and this list doesn't support - * the addition of null values. - */ - public void add(int index, Object o) - { - synchronized (mutex) - { - list.add(index, o); - } - } - - /** - * Add an element to the end of the underlying list (optional operation). - * If the list imposes restraints on what can be inserted, such as no null - * elements, this should be documented. A lock is obtained on the mutex before - * any of the elements are added. - * - * @param o the object to add - * @return <code>true</code>, as defined by Collection for a modified list - * @throws UnsupportedOperationException if this list does not support the - * add operation - * @throws ClassCastException if o cannot be added to this list due to its - * type - * @throws IllegalArgumentException if o cannot be added to this list for - * some other reason - * @throws NullPointerException if o is null and this list doesn't support - * the addition of null values. - */ - public boolean addAll(int index, Collection c) - { - synchronized (mutex) - { - return list.addAll(index, c); - } - } - - /** - * Tests whether the underlying list is equal to the supplied object. - * The object is deemed to be equal if it is also a <code>List</code> - * of equal size and with the same elements (i.e. each element, e1, - * in list, l1, and each element, e2, in l2, must return <code>true</code> for - * <code>e1 == null ? e2 == null : e1.equals(e2)</code>. Before the - * comparison is made, a lock is obtained on the mutex. - * - * @param o The object to test for equality with the underlying list. - * @return <code>true</code> if o is equal to the underlying list under the above - * definition. - */ - public boolean equals(Object o) - { - synchronized (mutex) - { - return list.equals(o); - } - } - - /** - * Retrieves the object at the specified index. A lock - * is obtained on the mutex before the list is accessed. - * - * @param index the index of the element to be returned - * @return the element at index index in this list - * @throws IndexOutOfBoundsException if index < 0 || index >= size() - */ - public Object get(int index) - { - synchronized (mutex) - { - return list.get(index); - } - } - - /** - * Obtains a hashcode for the underlying list, first obtaining - * a lock on the mutex. The calculation of the hashcode is - * detailed in the documentation for the <code>List</code> - * interface. - * - * @return The hashcode of the underlying list. - * @see List#hashCode() - */ - public int hashCode() - { - synchronized (mutex) - { - return list.hashCode(); - } - } - - /** - * Obtain the first index at which a given object is to be found in the - * underlying list. A lock is obtained on the mutex before the list is - * accessed. - * - * @param o the object to search for - * @return the least integer n such that <code>o == null ? get(n) == null : - * o.equals(get(n))</code>, or -1 if there is no such index. - * @throws ClassCastException if the type of o is not a valid - * type for this list. - * @throws NullPointerException if o is null and this - * list does not support null values. - */ - - public int indexOf(Object o) - { - synchronized (mutex) - { - return list.indexOf(o); - } - } - - /** - * Obtain the last index at which a given object is to be found in this - * underlying list. A lock is obtained on the mutex before the list - * is accessed. - * - * @return the greatest integer n such that <code>o == null ? get(n) == null - * : o.equals(get(n))</code>, or -1 if there is no such index. - * @throws ClassCastException if the type of o is not a valid - * type for this list. - * @throws NullPointerException if o is null and this - * list does not support null values. - */ - public int lastIndexOf(Object o) - { - synchronized (mutex) - { - return list.lastIndexOf(o); - } - } - - /** - * Retrieves a synchronized wrapper around the underlying list's - * list iterator. A lock is obtained on the mutex before the - * list iterator is retrieved. - * - * @return A list iterator over the elements in the underlying list. - * The list iterator allows additional list-specific operations - * to be performed, in addition to those supplied by the - * standard iterator. - */ - public ListIterator listIterator() - { - synchronized (mutex) - { - return new SynchronizedListIterator(mutex, list.listIterator()); - } - } - - /** - * Retrieves a synchronized wrapper around the underlying list's - * list iterator. A lock is obtained on the mutex before the - * list iterator is retrieved. The iterator starts at the - * index supplied, leading to the element at that index being - * the first one returned by <code>next()</code>. Calling - * <code>previous()</code> from this initial position returns - * index - 1. - * - * @param index the position, between 0 and size() inclusive, to begin the - * iteration from - * @return A list iterator over the elements in the underlying list. - * The list iterator allows additional list-specific operations - * to be performed, in addition to those supplied by the - * standard iterator. - * @throws IndexOutOfBoundsException if index < 0 || index > size() - */ - public ListIterator listIterator(int index) - { - synchronized (mutex) - { - return new SynchronizedListIterator(mutex, list.listIterator(index)); - } - } - - /** - * Remove the element at a given position in the underlying list (optional - * operation). All remaining elements are shifted to the left to fill the gap. - * A lock on the mutex is obtained before the element is removed. - * - * @param index the position within the list of the object to remove - * @return the object that was removed - * @throws UnsupportedOperationException if this list does not support the - * remove operation - * @throws IndexOutOfBoundsException if index < 0 || index >= size() - */ - public Object remove(int index) - { - synchronized (mutex) - { - return list.remove(index); - } - } - - /** - * Replace an element of the underlying list with another object (optional - * operation). A lock is obtained on the mutex before the element is - * replaced. - * - * @param index the position within this list of the element to be replaced - * @param o the object to replace it with - * @return the object that was replaced - * @throws UnsupportedOperationException if this list does not support the - * set operation. - * @throws IndexOutOfBoundsException if index < 0 || index >= size() - * @throws ClassCastException if o cannot be added to this list due to its - * type - * @throws IllegalArgumentException if o cannot be added to this list for - * some other reason - * @throws NullPointerException if o is null and this - * list does not support null values. - */ - public Object set(int index, Object o) - { - synchronized (mutex) - { - return list.set(index, o); - } - } - - /** - * Obtain a List view of a subsection of the underlying list, from fromIndex - * (inclusive) to toIndex (exclusive). If the two indices are equal, the - * sublist is empty. The returned list should be modifiable if and only - * if this list is modifiable. Changes to the returned list should be - * reflected in this list. If this list is structurally modified in - * any way other than through the returned list, the result of any subsequent - * operations on the returned list is undefined. A lock is obtained - * on the mutex before the creation of the sublist. The returned list - * is also synchronized, using the same mutex. - * - * @param fromIndex the index that the returned list should start from - * (inclusive) - * @param toIndex the index that the returned list should go to (exclusive) - * @return a List backed by a subsection of this list - * @throws IndexOutOfBoundsException if fromIndex < 0 - * || toIndex > size() || fromIndex > toIndex - */ - public List subList(int fromIndex, int toIndex) - { - synchronized (mutex) - { - return new SynchronizedList(mutex, list.subList(fromIndex, toIndex)); - } - } - } // class SynchronizedList - - /** - * The implementation of {@link #synchronizedList(List)} for random-access - * lists. This class name is required for compatibility with Sun's JDK - * serializability. - * - * @author Eric Blake (ebb9@email.byu.edu) - */ - private static final class SynchronizedRandomAccessList - extends SynchronizedList implements RandomAccess - { - /** - * Compatible with JDK 1.4. - */ - private static final long serialVersionUID = 1530674583602358482L; - - /** - * Wrap a given list. - * @param l the list to wrap - * @throws NullPointerException if l is null - */ - SynchronizedRandomAccessList(List l) - { - super(l); - } - - /** - * Called only by trusted code to specify the mutex as well as the - * collection. - * @param sync the mutex - * @param l the list - */ - SynchronizedRandomAccessList(Object sync, List l) - { - super(sync, l); - } - - /** - * Obtain a List view of a subsection of the underlying list, from fromIndex - * (inclusive) to toIndex (exclusive). If the two indices are equal, the - * sublist is empty. The returned list should be modifiable if and only - * if this list is modifiable. Changes to the returned list should be - * reflected in this list. If this list is structurally modified in - * any way other than through the returned list, the result of any subsequent - * operations on the returned list is undefined. A lock is obtained - * on the mutex before the creation of the sublist. The returned list - * is also synchronized, using the same mutex. Random accessibility - * is also extended to the new list. - * - * @param fromIndex the index that the returned list should start from - * (inclusive) - * @param toIndex the index that the returned list should go to (exclusive) - * @return a List backed by a subsection of this list - * @throws IndexOutOfBoundsException if fromIndex < 0 - * || toIndex > size() || fromIndex > toIndex - */ - public List subList(int fromIndex, int toIndex) - { - synchronized (mutex) - { - return new SynchronizedRandomAccessList(mutex, - list.subList(fromIndex, - toIndex)); - } - } - } // class SynchronizedRandomAccessList - - /** - * The implementation of {@link SynchronizedList#listIterator()}. This - * iterator must "sync" on the same object as the list it iterates over. - * - * @author Eric Blake (ebb9@email.byu.edu) - */ - private static final class SynchronizedListIterator - extends SynchronizedIterator implements ListIterator - { - /** - * The wrapped iterator, stored both here and in the superclass to - * avoid excessive casting. - */ - private final ListIterator li; - - /** - * Only trusted code creates a wrapper, with the specified sync. - * @param sync the mutex - * @param li the wrapped iterator - */ - SynchronizedListIterator(Object sync, ListIterator li) - { - super(sync, li); - this.li = li; - } - - /** - * Insert an element into the underlying list at the current position of - * the iterator (optional operation). The element is inserted in between - * the element that would be returned by <code>previous()</code> and the - * element that would be returned by <code>next()</code>. After the - * insertion, a subsequent call to next is unaffected, but - * a call to previous returns the item that was added. The values returned - * by nextIndex() and previousIndex() are incremented. A lock is obtained - * on the mutex before the addition takes place. - * - * @param o the object to insert into the list - * @throws ClassCastException if the object is of a type which cannot be added - * to this list. - * @throws IllegalArgumentException if some other aspect of the object stops - * it being added to this list. - * @throws UnsupportedOperationException if this ListIterator does not - * support the add operation. - */ - public void add(Object o) - { - synchronized (mutex) - { - li.add(o); - } - } - - /** - * Tests whether there are elements remaining in the underlying list - * in the reverse direction. In other words, <code>previous()</code> - * will not fail with a NoSuchElementException. A lock is obtained - * on the mutex before the check takes place. - * - * @return <code>true</code> if the list continues in the reverse direction - */ - public boolean hasPrevious() - { - synchronized (mutex) - { - return li.hasPrevious(); - } - } - - /** - * Find the index of the element that would be returned by a call to - * <code>next()</code>. If hasNext() returns <code>false</code>, this - * returns the list size. A lock is obtained on the mutex before the - * query takes place. - * - * @return the index of the element that would be returned by next() - */ - public int nextIndex() - { - synchronized (mutex) - { - return li.nextIndex(); - } - } - - /** - * Obtain the previous element from the underlying list. Repeated - * calls to previous may be used to iterate backwards over the entire list, - * or calls to next and previous may be used together to go forwards and - * backwards. Alternating calls to next and previous will return the same - * element. A lock is obtained on the mutex before the object is retrieved. - * - * @return the next element in the list in the reverse direction - * @throws NoSuchElementException if there are no more elements - */ - public Object previous() - { - synchronized (mutex) - { - return li.previous(); - } - } - - /** - * Find the index of the element that would be returned by a call to - * previous. If hasPrevious() returns <code>false</code>, this returns -1. - * A lock is obtained on the mutex before the query takes place. - * - * @return the index of the element that would be returned by previous() - */ - public int previousIndex() - { - synchronized (mutex) - { - return li.previousIndex(); - } - } - - /** - * Replace the element last returned by a call to <code>next()</code> or - * <code>previous()</code> with a given object (optional operation). This - * method may only be called if neither <code>add()</code> nor - * <code>remove()</code> have been called since the last call to - * <code>next()</code> or <code>previous</code>. A lock is obtained - * on the mutex before the list is modified. - * - * @param o the object to replace the element with - * @throws ClassCastException the object is of a type which cannot be added - * to this list - * @throws IllegalArgumentException some other aspect of the object stops - * it being added to this list - * @throws IllegalStateException if neither next or previous have been - * called, or if add or remove has been called since the last call - * to next or previous - * @throws UnsupportedOperationException if this ListIterator does not - * support the set operation - */ - public void set(Object o) - { - synchronized (mutex) - { - li.set(o); - } - } - } // class SynchronizedListIterator - - /** - * Returns a synchronized (thread-safe) map wrapper backed by the given - * map. Notice that element access through the collection views and their - * iterators are thread-safe, but if the map can be structurally modified - * (adding or removing elements) then you should synchronize around the - * iteration to avoid non-deterministic behavior:<br> - * <pre> - * Map m = Collections.synchronizedMap(new Map(...)); - * ... - * Set s = m.keySet(); // safe outside a synchronized block - * synchronized (m) // synch on m, not s - * { - * Iterator i = s.iterator(); - * while (i.hasNext()) - * foo(i.next()); - * } - * </pre><p> - * - * The returned Map implements Serializable, but can only be serialized if - * the map it wraps is likewise Serializable. - * - * @param m the map to wrap - * @return a synchronized view of the map - * @see Serializable - */ - public static Map synchronizedMap(Map m) - { - return new SynchronizedMap(m); - } - - /** - * The implementation of {@link #synchronizedMap(Map)}. This - * class name is required for compatibility with Sun's JDK serializability. - * - * @author Eric Blake (ebb9@email.byu.edu) - */ - private static class SynchronizedMap implements Map, Serializable - { - /** - * Compatible with JDK 1.4. - */ - private static final long serialVersionUID = 1978198479659022715L; - - /** - * The wrapped map. - * @serial the real map - */ - private final Map m; - - /** - * The object to synchronize on. When an instance is created via public - * methods, it will be this; but other uses like - * SynchronizedSortedMap.subMap() must specify another mutex. Package - * visible for use by subclass. - * @serial the lock - */ - final Object mutex; - - /** - * Cache the entry set. - */ - private transient Set entries; - - /** - * Cache the key set. - */ - private transient Set keys; - - /** - * Cache the value collection. - */ - private transient Collection values; - - /** - * Wrap a given map. - * @param m the map to wrap - * @throws NullPointerException if m is null - */ - SynchronizedMap(Map m) - { - this.m = m; - mutex = this; - if (m == null) - throw new NullPointerException(); - } - - /** - * Called only by trusted code to specify the mutex as well as the map. - * @param sync the mutex - * @param m the map - */ - SynchronizedMap(Object sync, Map m) - { - this.m = m; - mutex = sync; - } - - /** - * Clears all the entries from the underlying map. A lock is obtained - * on the mutex before the map is cleared. - * - * @throws UnsupportedOperationException if clear is not supported - */ - public void clear() - { - synchronized (mutex) - { - m.clear(); - } - } - - /** - * Returns <code>true</code> if the underlying map contains a entry for the given key. - * A lock is obtained on the mutex before the map is queried. - * - * @param key the key to search for. - * @return <code>true</code> if the underlying map contains the key. - * @throws ClassCastException if the key is of an inappropriate type. - * @throws NullPointerException if key is <code>null</code> but the map - * does not permit null keys. - */ - public boolean containsKey(Object key) - { - synchronized (mutex) - { - return m.containsKey(key); - } - } - - /** - * Returns <code>true</code> if the underlying map contains at least one entry with the - * given value. In other words, returns <code>true</code> if a value v exists where - * <code>(value == null ? v == null : value.equals(v))</code>. This usually - * requires linear time. A lock is obtained on the mutex before the map - * is queried. - * - * @param value the value to search for - * @return <code>true</code> if the map contains the value - * @throws ClassCastException if the type of the value is not a valid type - * for this map. - * @throws NullPointerException if the value is null and the map doesn't - * support null values. - */ - public boolean containsValue(Object value) - { - synchronized (mutex) - { - return m.containsValue(value); - } - } - - // This is one of the ickiest cases of nesting I've ever seen. It just - // means "return a SynchronizedSet, except that the iterator() method - // returns an SynchronizedIterator whose next() method returns a - // synchronized wrapper around its normal return value". - public Set entrySet() - { - // Define this here to spare some nesting. - class SynchronizedMapEntry implements Map.Entry - { - final Map.Entry e; - SynchronizedMapEntry(Object o) - { - e = (Map.Entry) o; - } - - /** - * Returns <code>true</code> if the object, o, implements <code>Map.Entry</code> - * with the same key and value as the underlying entry. A lock is - * obtained on the mutex before the comparison takes place. - * - * @param o The object to compare with this entry. - * @return <code>true</code> if o is equivalent to the underlying map entry. - */ - public boolean equals(Object o) - { - synchronized (mutex) - { - return e.equals(o); - } - } - - /** - * Returns the key used in the underlying map entry. A lock is obtained - * on the mutex before the key is retrieved. - * - * @return The key of the underlying map entry. - */ - public Object getKey() - { - synchronized (mutex) - { - return e.getKey(); - } - } - - /** - * Returns the value used in the underlying map entry. A lock is obtained - * on the mutex before the value is retrieved. - * - * @return The value of the underlying map entry. - */ - public Object getValue() - { - synchronized (mutex) - { - return e.getValue(); - } - } - - /** - * Computes the hash code for the underlying map entry. - * This computation is described in the documentation for the - * <code>Map</code> interface. A lock is obtained on the mutex - * before the underlying map is accessed. - * - * @return The hash code of the underlying map entry. - * @see Map#hashCode() - */ - public int hashCode() - { - synchronized (mutex) - { - return e.hashCode(); - } - } - - /** - * Replaces the value in the underlying map entry with the specified - * object (optional operation). A lock is obtained on the mutex - * before the map is altered. The map entry, in turn, will alter - * the underlying map object. The operation is undefined if the - * <code>remove()</code> method of the iterator has been called - * beforehand. - * - * @param value the new value to store - * @return the old value - * @throws UnsupportedOperationException if the operation is not supported. - * @throws ClassCastException if the value is of the wrong type. - * @throws IllegalArgumentException if something about the value - * prevents it from existing in this map. - * @throws NullPointerException if the map forbids null values. - */ - public Object setValue(Object value) - { - synchronized (mutex) - { - return e.setValue(value); - } - } - - /** - * Returns a textual representation of the underlying map entry. - * A lock is obtained on the mutex before the entry is accessed. - * - * @return The contents of the map entry in <code>String</code> form. - */ - public String toString() - { - synchronized (mutex) - { - return e.toString(); - } - } - } // class SynchronizedMapEntry - - // Now the actual code. - if (entries == null) - synchronized (mutex) - { - entries = new SynchronizedSet(mutex, m.entrySet()) - { - /** - * Returns an iterator over the set. The iterator has no specific order, - * unless further specified. A lock is obtained on the set's mutex - * before the iterator is created. The created iterator is also - * thread-safe. - * - * @return A synchronized set iterator. - */ - public Iterator iterator() - { - synchronized (super.mutex) - { - return new SynchronizedIterator(super.mutex, c.iterator()) - { - /** - * Retrieves the next map entry from the iterator. - * A lock is obtained on the iterator's mutex before - * the entry is created. The new map entry is enclosed in - * a thread-safe wrapper. - * - * @return A synchronized map entry. - */ - public Object next() - { - synchronized (super.mutex) - { - return new SynchronizedMapEntry(super.next()); - } - } - }; - } - } - }; - } - return entries; - } - - /** - * Returns <code>true</code> if the object, o, is also an instance - * of <code>Map</code> and contains an equivalent - * entry set to that of the underlying map. A lock - * is obtained on the mutex before the objects are - * compared. - * - * @param o The object to compare. - * @return <code>true</code> if o and the underlying map are equivalent. - */ - public boolean equals(Object o) - { - synchronized (mutex) - { - return m.equals(o); - } - } - - /** - * Returns the value associated with the given key, or null - * if no such mapping exists. An ambiguity exists with maps - * that accept null values as a return value of null could - * be due to a non-existent mapping or simply a null value - * for that key. To resolve this, <code>containsKey</code> - * should be used. A lock is obtained on the mutex before - * the value is retrieved from the underlying map. - * - * @param key The key of the required mapping. - * @return The value associated with the given key, or - * null if no such mapping exists. - * @throws ClassCastException if the key is an inappropriate type. - * @throws NullPointerException if this map does not accept null keys. - */ - public Object get(Object key) - { - synchronized (mutex) - { - return m.get(key); - } - } - - /** - * Calculates the hash code of the underlying map as the - * sum of the hash codes of all entries. A lock is obtained - * on the mutex before the hash code is computed. - * - * @return The hash code of the underlying map. - */ - public int hashCode() - { - synchronized (mutex) - { - return m.hashCode(); - } - } - - /** - * Returns <code>true</code> if the underlying map contains no entries. - * A lock is obtained on the mutex before the map is examined. - * - * @return <code>true</code> if the map is empty. - */ - public boolean isEmpty() - { - synchronized (mutex) - { - return m.isEmpty(); - } - } - - /** - * Returns a thread-safe set view of the keys in the underlying map. The - * set is backed by the map, so that changes in one show up in the other. - * Modifications made while an iterator is in progress cause undefined - * behavior. If the set supports removal, these methods remove the - * underlying mapping from the map: <code>Iterator.remove</code>, - * <code>Set.remove</code>, <code>removeAll</code>, <code>retainAll</code>, - * and <code>clear</code>. Element addition, via <code>add</code> or - * <code>addAll</code>, is not supported via this set. A lock is obtained - * on the mutex before the set is created. - * - * @return A synchronized set containing the keys of the underlying map. - */ - public Set keySet() - { - if (keys == null) - synchronized (mutex) - { - keys = new SynchronizedSet(mutex, m.keySet()); - } - return keys; - } - - /** - * Associates the given key to the given value (optional operation). If the - * underlying map already contains the key, its value is replaced. Be aware - * that in a map that permits <code>null</code> values, a null return does not - * always imply that the mapping was created. A lock is obtained on the mutex - * before the modification is made. - * - * @param key the key to map. - * @param value the value to be mapped. - * @return the previous value of the key, or null if there was no mapping - * @throws UnsupportedOperationException if the operation is not supported - * @throws ClassCastException if the key or value is of the wrong type - * @throws IllegalArgumentException if something about this key or value - * prevents it from existing in this map - * @throws NullPointerException if either the key or the value is null, - * and the map forbids null keys or values - * @see #containsKey(Object) - */ - public Object put(Object key, Object value) - { - synchronized (mutex) - { - return m.put(key, value); - } - } - - /** - * Copies all entries of the given map to the underlying one (optional - * operation). If the map already contains a key, its value is replaced. - * A lock is obtained on the mutex before the operation proceeds. - * - * @param m the mapping to load into this map - * @throws UnsupportedOperationException if the operation is not supported - * @throws ClassCastException if a key or value is of the wrong type - * @throws IllegalArgumentException if something about a key or value - * prevents it from existing in this map - * @throws NullPointerException if the map forbids null keys or values, or - * if <code>m</code> is null. - * @see #put(Object, Object) - */ - public void putAll(Map map) - { - synchronized (mutex) - { - m.putAll(map); - } - } - - /** - * Removes the mapping for the key, o, if present (optional operation). If - * the key is not present, this returns null. Note that maps which permit - * null values may also return null if the key was removed. A prior - * <code>containsKey()</code> check is required to avoid this ambiguity. - * Before the mapping is removed, a lock is obtained on the mutex. - * - * @param key the key to remove - * @return the value the key mapped to, or null if not present - * @throws UnsupportedOperationException if deletion is unsupported - * @throws NullPointerException if the key is null and this map doesn't - * support null keys. - * @throws ClassCastException if the type of the key is not a valid type - * for this map. - */ - public Object remove(Object o) - { - synchronized (mutex) - { - return m.remove(o); - } - } - - /** - * Retrieves the size of the underlying map. A lock - * is obtained on the mutex before access takes place. - * Maps with a size greater than <code>Integer.MAX_VALUE</code> - * return <code>Integer.MAX_VALUE</code> instead. - * - * @return The size of the underlying map. - */ - public int size() - { - synchronized (mutex) - { - return m.size(); - } - } - - /** - * Returns a textual representation of the underlying - * map. A lock is obtained on the mutex before the map - * is accessed. - * - * @return The map in <code>String</code> form. - */ - public String toString() - { - synchronized (mutex) - { - return m.toString(); - } - } - - /** - * Returns a synchronized collection view of the values in the underlying - * map. The collection is backed by the map, so that changes in one show up in - * the other. Modifications made while an iterator is in progress cause - * undefined behavior. If the collection supports removal, these methods - * remove the underlying mapping from the map: <code>Iterator.remove</code>, - * <code>Collection.remove</code>, <code>removeAll</code>, - * <code>retainAll</code>, and <code>clear</code>. Element addition, via - * <code>add</code> or <code>addAll</code>, is not supported via this - * collection. A lock is obtained on the mutex before the collection - * is created. - * - * @return the collection of all values in the underlying map. - */ - public Collection values() - { - if (values == null) - synchronized (mutex) - { - values = new SynchronizedCollection(mutex, m.values()); - } - return values; - } - } // class SynchronizedMap - - /** - * Returns a synchronized (thread-safe) set wrapper backed by the given - * set. Notice that element access through the iterator is thread-safe, but - * if the set can be structurally modified (adding or removing elements) - * then you should synchronize around the iteration to avoid - * non-deterministic behavior:<br> - * <pre> - * Set s = Collections.synchronizedSet(new Set(...)); - * ... - * synchronized (s) - * { - * Iterator i = s.iterator(); - * while (i.hasNext()) - * foo(i.next()); - * } - * </pre><p> - * - * The returned Set implements Serializable, but can only be serialized if - * the set it wraps is likewise Serializable. - * - * @param s the set to wrap - * @return a synchronized view of the set - * @see Serializable - */ - public static Set synchronizedSet(Set s) - { - return new SynchronizedSet(s); - } - - /** - * The implementation of {@link #synchronizedSet(Set)}. This class - * name is required for compatibility with Sun's JDK serializability. - * Package visible, so that sets such as Hashtable.keySet() - * can specify which object to synchronize on. - * - * @author Eric Blake (ebb9@email.byu.edu) - */ - static class SynchronizedSet extends SynchronizedCollection - implements Set - { - /** - * Compatible with JDK 1.4. - */ - private static final long serialVersionUID = 487447009682186044L; - - /** - * Wrap a given set. - * @param s the set to wrap - * @throws NullPointerException if s is null - */ - SynchronizedSet(Set s) - { - super(s); - } - - /** - * Called only by trusted code to specify the mutex as well as the set. - * @param sync the mutex - * @param s the set - */ - SynchronizedSet(Object sync, Set s) - { - super(sync, s); - } - - /** - * Returns <code>true</code> if the object, o, is a <code>Set</code> - * of the same size as the underlying set, and contains - * each element, e, which occurs in the underlying set. - * A lock is obtained on the mutex before the comparison - * takes place. - * - * @param o The object to compare against. - * @return <code>true</code> if o is an equivalent set. - */ - public boolean equals(Object o) - { - synchronized (mutex) - { - return c.equals(o); - } - } - - /** - * Computes the hash code for the underlying set as the - * sum of the hash code of all elements within the set. - * A lock is obtained on the mutex before the computation - * occurs. - * - * @return The hash code for the underlying set. - */ - public int hashCode() - { - synchronized (mutex) - { - return c.hashCode(); - } - } - } // class SynchronizedSet - - /** - * Returns a synchronized (thread-safe) sorted map wrapper backed by the - * given map. Notice that element access through the collection views, - * subviews, and their iterators are thread-safe, but if the map can be - * structurally modified (adding or removing elements) then you should - * synchronize around the iteration to avoid non-deterministic behavior:<br> - * <pre> - * SortedMap m = Collections.synchronizedSortedMap(new SortedMap(...)); - * ... - * Set s = m.keySet(); // safe outside a synchronized block - * SortedMap m2 = m.headMap(foo); // safe outside a synchronized block - * Set s2 = m2.keySet(); // safe outside a synchronized block - * synchronized (m) // synch on m, not m2, s or s2 - * { - * Iterator i = s.iterator(); - * while (i.hasNext()) - * foo(i.next()); - * i = s2.iterator(); - * while (i.hasNext()) - * bar(i.next()); - * } - * </pre><p> - * - * The returned SortedMap implements Serializable, but can only be - * serialized if the map it wraps is likewise Serializable. - * - * @param m the sorted map to wrap - * @return a synchronized view of the sorted map - * @see Serializable - */ - public static SortedMap synchronizedSortedMap(SortedMap m) - { - return new SynchronizedSortedMap(m); - } - - /** - * The implementation of {@link #synchronizedSortedMap(SortedMap)}. This - * class name is required for compatibility with Sun's JDK serializability. - * - * @author Eric Blake (ebb9@email.byu.edu) - */ - private static final class SynchronizedSortedMap extends SynchronizedMap - implements SortedMap - { - /** - * Compatible with JDK 1.4. - */ - private static final long serialVersionUID = -8798146769416483793L; - - /** - * The wrapped map; stored both here and in the superclass to avoid - * excessive casting. - * @serial the wrapped map - */ - private final SortedMap sm; - - /** - * Wrap a given map. - * @param sm the map to wrap - * @throws NullPointerException if sm is null - */ - SynchronizedSortedMap(SortedMap sm) - { - super(sm); - this.sm = sm; - } - - /** - * Called only by trusted code to specify the mutex as well as the map. - * @param sync the mutex - * @param sm the map - */ - SynchronizedSortedMap(Object sync, SortedMap sm) - { - super(sync, sm); - this.sm = sm; - } - - /** - * Returns the comparator used in sorting the underlying map, or null if - * it is the keys' natural ordering. A lock is obtained on the mutex - * before the comparator is retrieved. - * - * @return the sorting comparator. - */ - public Comparator comparator() - { - synchronized (mutex) - { - return sm.comparator(); - } - } - - /** - * Returns the first, lowest sorted, key from the underlying map. - * A lock is obtained on the mutex before the map is accessed. - * - * @return the first key. - * @throws NoSuchElementException if this map is empty. - */ - public Object firstKey() - { - synchronized (mutex) - { - return sm.firstKey(); - } - } - - /** - * Returns a submap containing the keys from the first - * key (as returned by <code>firstKey()</code>) to - * the key before that specified. The submap supports all - * operations supported by the underlying map and all actions - * taking place on the submap are also reflected in the underlying - * map. A lock is obtained on the mutex prior to submap creation. - * This operation is equivalent to <code>subMap(firstKey(), toKey)</code>. - * The submap retains the thread-safe status of this map. - * - * @param toKey the exclusive upper range of the submap. - * @return a submap from <code>firstKey()</code> to the - * the key preceding toKey. - * @throws ClassCastException if toKey is not comparable to the underlying - * map's contents. - * @throws IllegalArgumentException if toKey is outside the map's range. - * @throws NullPointerException if toKey is null. but the map does not allow - * null keys. - */ - public SortedMap headMap(Object toKey) - { - synchronized (mutex) - { - return new SynchronizedSortedMap(mutex, sm.headMap(toKey)); - } - } - - /** - * Returns the last, highest sorted, key from the underlying map. - * A lock is obtained on the mutex before the map is accessed. - * - * @return the last key. - * @throws NoSuchElementException if this map is empty. - */ - public Object lastKey() - { - synchronized (mutex) - { - return sm.lastKey(); - } - } - - /** - * Returns a submap containing the keys from fromKey to - * the key before toKey. The submap supports all - * operations supported by the underlying map and all actions - * taking place on the submap are also reflected in the underlying - * map. A lock is obtained on the mutex prior to submap creation. - * The submap retains the thread-safe status of this map. - * - * @param fromKey the inclusive lower range of the submap. - * @param toKey the exclusive upper range of the submap. - * @return a submap from fromKey to the key preceding toKey. - * @throws ClassCastException if fromKey or toKey is not comparable - * to the underlying map's contents. - * @throws IllegalArgumentException if fromKey or toKey is outside the map's - * range. - * @throws NullPointerException if fromKey or toKey is null. but the map does - * not allow null keys. - */ - public SortedMap subMap(Object fromKey, Object toKey) - { - synchronized (mutex) - { - return new SynchronizedSortedMap(mutex, sm.subMap(fromKey, toKey)); - } - } - - /** - * Returns a submap containing all the keys from fromKey onwards. - * The submap supports all operations supported by the underlying - * map and all actions taking place on the submap are also reflected - * in the underlying map. A lock is obtained on the mutex prior to - * submap creation. The submap retains the thread-safe status of - * this map. - * - * @param fromKey the inclusive lower range of the submap. - * @return a submap from fromKey to <code>lastKey()</code>. - * @throws ClassCastException if fromKey is not comparable to the underlying - * map's contents. - * @throws IllegalArgumentException if fromKey is outside the map's range. - * @throws NullPointerException if fromKey is null. but the map does not allow - * null keys. - */ - public SortedMap tailMap(Object fromKey) - { - synchronized (mutex) - { - return new SynchronizedSortedMap(mutex, sm.tailMap(fromKey)); - } - } - } // class SynchronizedSortedMap - - /** - * Returns a synchronized (thread-safe) sorted set wrapper backed by the - * given set. Notice that element access through the iterator and through - * subviews are thread-safe, but if the set can be structurally modified - * (adding or removing elements) then you should synchronize around the - * iteration to avoid non-deterministic behavior:<br> - * <pre> - * SortedSet s = Collections.synchronizedSortedSet(new SortedSet(...)); - * ... - * SortedSet s2 = s.headSet(foo); // safe outside a synchronized block - * synchronized (s) // synch on s, not s2 - * { - * Iterator i = s2.iterator(); - * while (i.hasNext()) - * foo(i.next()); - * } - * </pre><p> - * - * The returned SortedSet implements Serializable, but can only be - * serialized if the set it wraps is likewise Serializable. - * - * @param s the sorted set to wrap - * @return a synchronized view of the sorted set - * @see Serializable - */ - public static SortedSet synchronizedSortedSet(SortedSet s) - { - return new SynchronizedSortedSet(s); - } - - /** - * The implementation of {@link #synchronizedSortedSet(SortedSet)}. This - * class name is required for compatibility with Sun's JDK serializability. - * - * @author Eric Blake (ebb9@email.byu.edu) - */ - private static final class SynchronizedSortedSet extends SynchronizedSet - implements SortedSet - { - /** - * Compatible with JDK 1.4. - */ - private static final long serialVersionUID = 8695801310862127406L; - - /** - * The wrapped set; stored both here and in the superclass to avoid - * excessive casting. - * @serial the wrapped set - */ - private final SortedSet ss; - - /** - * Wrap a given set. - * @param ss the set to wrap - * @throws NullPointerException if ss is null - */ - SynchronizedSortedSet(SortedSet ss) - { - super(ss); - this.ss = ss; - } - - /** - * Called only by trusted code to specify the mutex as well as the set. - * @param sync the mutex - * @param l the list - */ - SynchronizedSortedSet(Object sync, SortedSet ss) - { - super(sync, ss); - this.ss = ss; - } - - /** - * Returns the comparator used in sorting the underlying set, or null if - * it is the elements' natural ordering. A lock is obtained on the mutex - * before the comparator is retrieved. - * - * @return the sorting comparator. - */ - public Comparator comparator() - { - synchronized (mutex) - { - return ss.comparator(); - } - } - - /** - * Returns the first, lowest sorted, element from the underlying set. - * A lock is obtained on the mutex before the set is accessed. - * - * @return the first element. - * @throws NoSuchElementException if this set is empty. - */ - public Object first() - { - synchronized (mutex) - { - return ss.first(); - } - } - - /** - * Returns a subset containing the element from the first - * element (as returned by <code>first()</code>) to - * the element before that specified. The subset supports all - * operations supported by the underlying set and all actions - * taking place on the subset are also reflected in the underlying - * set. A lock is obtained on the mutex prior to subset creation. - * This operation is equivalent to <code>subSet(first(), toElement)</code>. - * The subset retains the thread-safe status of this set. - * - * @param toElement the exclusive upper range of the subset. - * @return a subset from <code>first()</code> to the - * the element preceding toElement. - * @throws ClassCastException if toElement is not comparable to the underlying - * set's contents. - * @throws IllegalArgumentException if toElement is outside the set's range. - * @throws NullPointerException if toElement is null. but the set does not allow - * null elements. - */ - public SortedSet headSet(Object toElement) - { - synchronized (mutex) - { - return new SynchronizedSortedSet(mutex, ss.headSet(toElement)); - } - } - - /** - * Returns the last, highest sorted, element from the underlying set. - * A lock is obtained on the mutex before the set is accessed. - * - * @return the last element. - * @throws NoSuchElementException if this set is empty. - */ - public Object last() - { - synchronized (mutex) - { - return ss.last(); - } - } - - /** - * Returns a subset containing the elements from fromElement to - * the element before toElement. The subset supports all - * operations supported by the underlying set and all actions - * taking place on the subset are also reflected in the underlying - * set. A lock is obtained on the mutex prior to subset creation. - * The subset retains the thread-safe status of this set. - * - * @param fromElement the inclusive lower range of the subset. - * @param toElement the exclusive upper range of the subset. - * @return a subset from fromElement to the element preceding toElement. - * @throws ClassCastException if fromElement or toElement is not comparable - * to the underlying set's contents. - * @throws IllegalArgumentException if fromElement or toElement is outside the set's - * range. - * @throws NullPointerException if fromElement or toElement is null. but the set does - * not allow null elements. - */ - public SortedSet subSet(Object fromElement, Object toElement) - { - synchronized (mutex) - { - return new SynchronizedSortedSet(mutex, - ss.subSet(fromElement, toElement)); - } - } - - /** - * Returns a subset containing all the elements from fromElement onwards. - * The subset supports all operations supported by the underlying - * set and all actions taking place on the subset are also reflected - * in the underlying set. A lock is obtained on the mutex prior to - * subset creation. The subset retains the thread-safe status of - * this set. - * - * @param fromElement the inclusive lower range of the subset. - * @return a subset from fromElement to <code>last()</code>. - * @throws ClassCastException if fromElement is not comparable to the underlying - * set's contents. - * @throws IllegalArgumentException if fromElement is outside the set's range. - * @throws NullPointerException if fromElement is null. but the set does not allow - * null elements. - */ - public SortedSet tailSet(Object fromElement) - { - synchronized (mutex) - { - return new SynchronizedSortedSet(mutex, ss.tailSet(fromElement)); - } - } - } // class SynchronizedSortedSet - - - /** - * Returns an unmodifiable view of the given collection. This allows - * "read-only" access, although changes in the backing collection show up - * in this view. Attempts to modify the collection directly or via iterators - * will fail with {@link UnsupportedOperationException}. Although this view - * prevents changes to the structure of the collection and its elements, the values - * referenced by the objects in the collection can still be modified. - * <p> - * - * Since the collection might be a List or a Set, and those have incompatible - * equals and hashCode requirements, this relies on Object's implementation - * rather than passing those calls on to the wrapped collection. The returned - * Collection implements Serializable, but can only be serialized if - * the collection it wraps is likewise Serializable. - * - * @param c the collection to wrap - * @return a read-only view of the collection - * @see Serializable - */ - public static Collection unmodifiableCollection(Collection c) - { - return new UnmodifiableCollection(c); - } - - /** - * The implementation of {@link #unmodifiableCollection(Collection)}. This - * class name is required for compatibility with Sun's JDK serializability. - * - * @author Eric Blake (ebb9@email.byu.edu) - */ - private static class UnmodifiableCollection - implements Collection, Serializable - { - /** - * Compatible with JDK 1.4. - */ - private static final long serialVersionUID = 1820017752578914078L; - - /** - * The wrapped collection. Package visible for use by subclasses. - * @serial the real collection - */ - final Collection c; - - /** - * Wrap a given collection. - * @param c the collection to wrap - * @throws NullPointerException if c is null - */ - UnmodifiableCollection(Collection c) - { - this.c = c; - if (c == null) - throw new NullPointerException(); - } - - /** - * Blocks the addition of elements to the underlying collection. - * This method never returns, throwing an exception instead. - * - * @param o the object to add. - * @return <code>true</code> if the collection was modified as a result of this action. - * @throws UnsupportedOperationException as an unmodifiable collection does not - * support the add operation. - */ - public boolean add(Object o) - { - throw new UnsupportedOperationException(); - } - - /** - * Blocks the addition of a collection of elements to the underlying - * collection. This method never returns, throwing an exception instead. - * - * @param c the collection to add. - * @return <code>true</code> if the collection was modified as a result of this action. - * @throws UnsupportedOperationException as an unmodifiable collection does not - * support the <code>addAll</code> operation. - */ - public boolean addAll(Collection c) - { - throw new UnsupportedOperationException(); - } - - /** - * Blocks the clearing of the underlying collection. This method never - * returns, throwing an exception instead. - * - * @throws UnsupportedOperationException as an unmodifiable collection does - * not support the <code>clear()</code> operation. - */ - public void clear() - { - throw new UnsupportedOperationException(); - } - - /** - * Test whether the underlying collection contains a given object as one of its - * elements. - * - * @param o the element to look for. - * @return <code>true</code> if the underlying collection contains at least - * one element e such that - * <code>o == null ? e == null : o.equals(e)</code>. - * @throws ClassCastException if the type of o is not a valid type for the - * underlying collection. - * @throws NullPointerException if o is null and the underlying collection - * doesn't support null values. - */ - public boolean contains(Object o) - { - return c.contains(o); - } - - /** - * Test whether the underlying collection contains every element in a given - * collection. - * - * @param c the collection to test for. - * @return <code>true</code> if for every element o in c, contains(o) would - * return <code>true</code>. - * @throws ClassCastException if the type of any element in c is not a valid - * type for the underlying collection. - * @throws NullPointerException if some element of c is null and the underlying - * collection does not support null values. - * @throws NullPointerException if c itself is null. - */ - public boolean containsAll(Collection c1) - { - return c.containsAll(c1); - } - - /** - * Tests whether the underlying collection is empty, that is, - * if size() == 0. - * - * @return <code>true</code> if this collection contains no elements. - */ - public boolean isEmpty() - { - return c.isEmpty(); - } - - /** - * Obtain an Iterator over the underlying collection, which maintains - * its unmodifiable nature. - * - * @return an UnmodifiableIterator over the elements of the underlying - * collection, in any order. - */ - public Iterator iterator() - { - return new UnmodifiableIterator(c.iterator()); - } - - /** - * Blocks the removal of an object from the underlying collection. - * This method never returns, throwing an exception instead. - * - * @param o The object to remove. - * @return <code>true</code> if the object was removed (i.e. the underlying - * collection returned 1 or more instances of o). - * @throws UnsupportedOperationException as an unmodifiable collection - * does not support the <code>remove()</code> operation. - */ - public boolean remove(Object o) - { - throw new UnsupportedOperationException(); - } - - /** - * Blocks the removal of a collection of objects from the underlying - * collection. This method never returns, throwing an exception - * instead. - * - * @param c The collection of objects to remove. - * @return <code>true</code> if the collection was modified. - * @throws UnsupportedOperationException as an unmodifiable collection - * does not support the <code>removeAll()</code> operation. - */ - public boolean removeAll(Collection c) - { - throw new UnsupportedOperationException(); - } - - /** - * Blocks the removal of all elements from the underlying collection, - * except those in the supplied collection. This method never returns, - * throwing an exception instead. - * - * @param c The collection of objects to retain. - * @return <code>true</code> if the collection was modified. - * @throws UnsupportedOperationException as an unmodifiable collection - * does not support the <code>retainAll()</code> operation. - */ - public boolean retainAll(Collection c) - { - throw new UnsupportedOperationException(); - } - - /** - * Retrieves the number of elements in the underlying collection. - * - * @return the number of elements in the collection. - */ - public int size() - { - return c.size(); - } - - /** - * Copy the current contents of the underlying collection into an array. - * - * @return an array of type Object[] with a length equal to the size of the - * underlying collection and containing the elements currently in - * the underlying collection, in any order. - */ - public Object[] toArray() - { - return c.toArray(); - } - - /** - * Copy the current contents of the underlying collection into an array. If - * the array passed as an argument has length less than the size of the - * underlying collection, an array of the same run-time type as a, with a length - * equal to the size of the underlying collection, is allocated using reflection. - * Otherwise, a itself is used. The elements of the underlying collection are - * copied into it, and if there is space in the array, the following element is - * set to null. The resultant array is returned. - * Note: The fact that the following element is set to null is only useful - * if it is known that this collection does not contain any null elements. - * - * @param a the array to copy this collection into. - * @return an array containing the elements currently in the underlying - * collection, in any order. - * @throws ArrayStoreException if the type of any element of the - * collection is not a subtype of the element type of a. - */ - public Object[] toArray(Object[] a) - { - return c.toArray(a); - } - - /** - * A textual representation of the unmodifiable collection. - * - * @return The unmodifiable collection in the form of a <code>String</code>. - */ - public String toString() - { - return c.toString(); - } - } // class UnmodifiableCollection - - /** - * The implementation of the various iterator methods in the - * unmodifiable classes. - * - * @author Eric Blake (ebb9@email.byu.edu) - */ - private static class UnmodifiableIterator implements Iterator - { - /** - * The wrapped iterator. - */ - private final Iterator i; - - /** - * Only trusted code creates a wrapper. - * @param i the wrapped iterator - */ - UnmodifiableIterator(Iterator i) - { - this.i = i; - } - - /** - * Obtains the next element in the underlying collection. - * - * @return the next element in the collection. - * @throws NoSuchElementException if there are no more elements. - */ - public Object next() - { - return i.next(); - } - /** - * Tests whether there are still elements to be retrieved from the - * underlying collection by <code>next()</code>. When this method - * returns <code>true</code>, an exception will not be thrown on calling - * <code>next()</code>. - * - * @return <code>true</code> if there is at least one more element in the underlying - * collection. - */ - public boolean hasNext() - { - return i.hasNext(); - } - - /** - * Blocks the removal of elements from the underlying collection by the - * iterator. - * - * @throws UnsupportedOperationException as an unmodifiable collection - * does not support the removal of elements by its iterator. - */ - public void remove() - { - throw new UnsupportedOperationException(); - } - } // class UnmodifiableIterator - - /** - * Returns an unmodifiable view of the given list. This allows - * "read-only" access, although changes in the backing list show up - * in this view. Attempts to modify the list directly, via iterators, or - * via sublists, will fail with {@link UnsupportedOperationException}. - * Although this view prevents changes to the structure of the list and - * its elements, the values referenced by the objects in the list can - * still be modified. - * <p> - * - * The returned List implements Serializable, but can only be serialized if - * the list it wraps is likewise Serializable. In addition, if the wrapped - * list implements RandomAccess, this does too. - * - * @param l the list to wrap - * @return a read-only view of the list - * @see Serializable - * @see RandomAccess - */ - public static List unmodifiableList(List l) - { - if (l instanceof RandomAccess) - return new UnmodifiableRandomAccessList(l); - return new UnmodifiableList(l); - } - - /** - * The implementation of {@link #unmodifiableList(List)} for sequential - * lists. This class name is required for compatibility with Sun's JDK - * serializability. - * - * @author Eric Blake (ebb9@email.byu.edu) - */ - private static class UnmodifiableList extends UnmodifiableCollection - implements List - { - /** - * Compatible with JDK 1.4. - */ - private static final long serialVersionUID = -283967356065247728L; - - - /** - * The wrapped list; stored both here and in the superclass to avoid - * excessive casting. Package visible for use by subclass. - * @serial the wrapped list - */ - final List list; - - /** - * Wrap a given list. - * @param l the list to wrap - * @throws NullPointerException if l is null - */ - UnmodifiableList(List l) - { - super(l); - list = l; - } - - /** - * Blocks the addition of an element to the underlying - * list at a specific index. This method never returns, - * throwing an exception instead. - * - * @param index The index at which to place the new element. - * @param o the object to add. - * @throws UnsupportedOperationException as an unmodifiable - * list doesn't support the <code>add()</code> operation. - */ - public void add(int index, Object o) - { - throw new UnsupportedOperationException(); - } - - /** - * Blocks the addition of a collection of elements to the - * underlying list at a specific index. This method never - * returns, throwing an exception instead. - * - * @param index The index at which to place the new element. - * @param c the collections of objects to add. - * @throws UnsupportedOperationException as an unmodifiable - * list doesn't support the <code>addAll()</code> operation. - */ - public boolean addAll(int index, Collection c) - { - throw new UnsupportedOperationException(); - } - - /** - * Returns <code>true</code> if the object, o, is an instance of - * <code>List</code> with the same size and elements - * as the underlying list. - * - * @param o The object to compare. - * @return <code>true</code> if o is equivalent to the underlying list. - */ - public boolean equals(Object o) - { - return list.equals(o); - } - - /** - * Retrieves the element at a given index in the underlying list. - * - * @param index the index of the element to be returned - * @return the element at index index in this list - * @throws IndexOutOfBoundsException if index < 0 || index >= size() - */ - public Object get(int index) - { - return list.get(index); - } - - /** - * Computes the hash code for the underlying list. - * The exact computation is described in the documentation - * of the <code>List</code> interface. - * - * @return The hash code of the underlying list. - * @see List#hashCode() - */ - public int hashCode() - { - return list.hashCode(); - } - - /** - * Obtain the first index at which a given object is to be found in the - * underlying list. - * - * @param o the object to search for - * @return the least integer n such that <code>o == null ? get(n) == null : - * o.equals(get(n))</code>, or -1 if there is no such index. - * @throws ClassCastException if the type of o is not a valid - * type for the underlying list. - * @throws NullPointerException if o is null and the underlying - * list does not support null values. - */ - public int indexOf(Object o) - { - return list.indexOf(o); - } - - /** - * Obtain the last index at which a given object is to be found in the - * underlying list. - * - * @return the greatest integer n such that <code>o == null ? get(n) == null - * : o.equals(get(n))</code>, or -1 if there is no such index. - * @throws ClassCastException if the type of o is not a valid - * type for the underlying list. - * @throws NullPointerException if o is null and the underlying - * list does not support null values. - */ - public int lastIndexOf(Object o) - { - return list.lastIndexOf(o); - } - - /** - * Obtains a list iterator over the underlying list, starting at the beginning - * and maintaining the unmodifiable nature of this list. - * - * @return a <code>UnmodifiableListIterator</code> over the elements of the - * underlying list, in order, starting at the beginning. - */ - public ListIterator listIterator() - { - return new UnmodifiableListIterator(list.listIterator()); - } - - /** - * Obtains a list iterator over the underlying list, starting at the specified - * index and maintaining the unmodifiable nature of this list. An initial call - * to <code>next()</code> will retrieve the element at the specified index, - * and an initial call to <code>previous()</code> will retrieve the element - * at index - 1. - * - * - * @param index the position, between 0 and size() inclusive, to begin the - * iteration from. - * @return a <code>UnmodifiableListIterator</code> over the elements of the - * underlying list, in order, starting at the specified index. - * @throws IndexOutOfBoundsException if index < 0 || index > size() - */ - public ListIterator listIterator(int index) - { - return new UnmodifiableListIterator(list.listIterator(index)); - } - - /** - * Blocks the removal of the element at the specified index. - * This method never returns, throwing an exception instead. - * - * @param index The index of the element to remove. - * @return the removed element. - * @throws UnsupportedOperationException as an unmodifiable - * list does not support the <code>remove()</code> - * operation. - */ - public Object remove(int index) - { - throw new UnsupportedOperationException(); - } - - /** - * Blocks the replacement of the element at the specified index. - * This method never returns, throwing an exception instead. - * - * @param index The index of the element to replace. - * @param o The new object to place at the specified index. - * @return the replaced element. - * @throws UnsupportedOperationException as an unmodifiable - * list does not support the <code>set()</code> - * operation. - */ - public Object set(int index, Object o) - { - throw new UnsupportedOperationException(); - } - - /** - * Obtain a List view of a subsection of the underlying list, from - * fromIndex (inclusive) to toIndex (exclusive). If the two indices - * are equal, the sublist is empty. The returned list will be - * unmodifiable, like this list. Changes to the elements of the - * returned list will be reflected in the underlying list. No structural - * modifications can take place in either list. - * - * @param fromIndex the index that the returned list should start from - * (inclusive). - * @param toIndex the index that the returned list should go to (exclusive). - * @return a List backed by a subsection of the underlying list. - * @throws IndexOutOfBoundsException if fromIndex < 0 - * || toIndex > size() || fromIndex > toIndex. - */ - public List subList(int fromIndex, int toIndex) - { - return unmodifiableList(list.subList(fromIndex, toIndex)); - } - } // class UnmodifiableList - - /** - * The implementation of {@link #unmodifiableList(List)} for random-access - * lists. This class name is required for compatibility with Sun's JDK - * serializability. - * - * @author Eric Blake (ebb9@email.byu.edu) - */ - private static final class UnmodifiableRandomAccessList - extends UnmodifiableList implements RandomAccess - { - /** - * Compatible with JDK 1.4. - */ - private static final long serialVersionUID = -2542308836966382001L; - - /** - * Wrap a given list. - * @param l the list to wrap - * @throws NullPointerException if l is null - */ - UnmodifiableRandomAccessList(List l) - { - super(l); - } - } // class UnmodifiableRandomAccessList - - /** - * The implementation of {@link UnmodifiableList#listIterator()}. - * - * @author Eric Blake (ebb9@email.byu.edu) - */ - private static final class UnmodifiableListIterator - extends UnmodifiableIterator implements ListIterator - { - /** - * The wrapped iterator, stored both here and in the superclass to - * avoid excessive casting. - */ - private final ListIterator li; - - /** - * Only trusted code creates a wrapper. - * @param li the wrapped iterator - */ - UnmodifiableListIterator(ListIterator li) - { - super(li); - this.li = li; - } - - /** - * Blocks the addition of an object to the list underlying this iterator. - * This method never returns, throwing an exception instead. - * - * @param o The object to add. - * @throws UnsupportedOperationException as the iterator of an unmodifiable - * list does not support the <code>add()</code> operation. - */ - public void add(Object o) - { - throw new UnsupportedOperationException(); - } - - /** - * Tests whether there are still elements to be retrieved from the - * underlying collection by <code>previous()</code>. When this method - * returns <code>true</code>, an exception will not be thrown on calling - * <code>previous()</code>. - * - * @return <code>true</code> if there is at least one more element prior to the - * current position in the underlying list. - */ - public boolean hasPrevious() - { - return li.hasPrevious(); - } - - /** - * Find the index of the element that would be returned by a call to next. - * If <code>hasNext()</code> returns <code>false</code>, this returns the list size. - * - * @return the index of the element that would be returned by - * <code>next()</code>. - */ - public int nextIndex() - { - return li.nextIndex(); - } - - /** - * Obtains the previous element in the underlying list. - * - * @return the previous element in the list. - * @throws NoSuchElementException if there are no more prior elements. - */ - public Object previous() - { - return li.previous(); - } - - /** - * Find the index of the element that would be returned by a call to - * previous. If <code>hasPrevious()</code> returns <code>false</code>, - * this returns -1. - * - * @return the index of the element that would be returned by - * <code>previous()</code>. - */ - public int previousIndex() - { - return li.previousIndex(); - } - - /** - * Blocks the replacement of an element in the list underlying this - * iterator. This method never returns, throwing an exception instead. - * - * @param o The new object to replace the existing one. - * @throws UnsupportedOperationException as the iterator of an unmodifiable - * list does not support the <code>set()</code> operation. - */ - public void set(Object o) - { - throw new UnsupportedOperationException(); - } - } // class UnmodifiableListIterator - - /** - * Returns an unmodifiable view of the given map. This allows "read-only" - * access, although changes in the backing map show up in this view. - * Attempts to modify the map directly, or via collection views or their - * iterators will fail with {@link UnsupportedOperationException}. - * Although this view prevents changes to the structure of the map and its - * entries, the values referenced by the objects in the map can still be - * modified. - * <p> - * - * The returned Map implements Serializable, but can only be serialized if - * the map it wraps is likewise Serializable. - * - * @param m the map to wrap - * @return a read-only view of the map - * @see Serializable - */ - public static Map unmodifiableMap(Map m) - { - return new UnmodifiableMap(m); - } - - /** - * The implementation of {@link #unmodifiableMap(Map)}. This - * class name is required for compatibility with Sun's JDK serializability. - * - * @author Eric Blake (ebb9@email.byu.edu) - */ - private static class UnmodifiableMap implements Map, Serializable - { - /** - * Compatible with JDK 1.4. - */ - private static final long serialVersionUID = -1034234728574286014L; - - /** - * The wrapped map. - * @serial the real map - */ - private final Map m; - - /** - * Cache the entry set. - */ - private transient Set entries; - - /** - * Cache the key set. - */ - private transient Set keys; - - /** - * Cache the value collection. - */ - private transient Collection values; - - /** - * Wrap a given map. - * @param m the map to wrap - * @throws NullPointerException if m is null - */ - UnmodifiableMap(Map m) - { - this.m = m; - if (m == null) - throw new NullPointerException(); - } - - /** - * Blocks the clearing of entries from the underlying map. - * This method never returns, throwing an exception instead. - * - * @throws UnsupportedOperationException as an unmodifiable - * map does not support the <code>clear()</code> operation. - */ - public void clear() - { - throw new UnsupportedOperationException(); - } - - /** - * Returns <code>true</code> if the underlying map contains a mapping for - * the given key. - * - * @param key the key to search for - * @return <code>true</code> if the map contains the key - * @throws ClassCastException if the key is of an inappropriate type - * @throws NullPointerException if key is <code>null</code> but the map - * does not permit null keys - */ - public boolean containsKey(Object key) - { - return m.containsKey(key); - } - - /** - * Returns <code>true</code> if the underlying map contains at least one mapping with - * the given value. In other words, it returns <code>true</code> if a value v exists where - * <code>(value == null ? v == null : value.equals(v))</code>. This usually - * requires linear time. - * - * @param value the value to search for - * @return <code>true</code> if the map contains the value - * @throws ClassCastException if the type of the value is not a valid type - * for this map. - * @throws NullPointerException if the value is null and the map doesn't - * support null values. - */ - public boolean containsValue(Object value) - { - return m.containsValue(value); - } - - /** - * Returns a unmodifiable set view of the entries in the underlying map. - * Each element in the set is a unmodifiable variant of <code>Map.Entry</code>. - * The set is backed by the map, so that changes in one show up in the other. - * Modifications made while an iterator is in progress cause undefined - * behavior. These modifications are again limited to the values of - * the objects. - * - * @return the unmodifiable set view of all mapping entries. - * @see Map.Entry - */ - public Set entrySet() - { - if (entries == null) - entries = new UnmodifiableEntrySet(m.entrySet()); - return entries; - } - - /** - * The implementation of {@link UnmodifiableMap#entrySet()}. This class - * name is required for compatibility with Sun's JDK serializability. - * - * @author Eric Blake (ebb9@email.byu.edu) - */ - private static final class UnmodifiableEntrySet extends UnmodifiableSet - implements Serializable - { - /** - * Compatible with JDK 1.4. - */ - private static final long serialVersionUID = 7854390611657943733L; - - /** - * Wrap a given set. - * @param s the set to wrap - */ - UnmodifiableEntrySet(Set s) - { - super(s); - } - - // The iterator must return unmodifiable map entries. - public Iterator iterator() - { - return new UnmodifiableIterator(c.iterator()) - { - /** - * Obtains the next element from the underlying set of - * map entries. - * - * @return the next element in the collection. - * @throws NoSuchElementException if there are no more elements. - */ - public Object next() - { - final Map.Entry e = (Map.Entry) super.next(); - return new Map.Entry() - { - /** - * Returns <code>true</code> if the object, o, is also a map entry with an - * identical key and value. - * - * @param o the object to compare. - * @return <code>true</code> if o is an equivalent map entry. - */ - public boolean equals(Object o) - { - return e.equals(o); - } - - /** - * Returns the key of this map entry. - * - * @return the key. - */ - public Object getKey() - { - return e.getKey(); - } - - /** - * Returns the value of this map entry. - * - * @return the value. - */ - public Object getValue() - { - return e.getValue(); - } - - /** - * Computes the hash code of this map entry. - * The computation is described in the <code>Map</code> - * interface documentation. - * - * @return the hash code of this entry. - * @see Map#hashCode() - */ - public int hashCode() - { - return e.hashCode(); - } - - /** - * Blocks the alteration of the value of this map entry. - * This method never returns, throwing an exception instead. - * - * @param value The new value. - * @throws UnsupportedOperationException as an unmodifiable - * map entry does not support the <code>setValue()</code> - * operation. - */ - public Object setValue(Object value) - { - throw new UnsupportedOperationException(); - } - - /** - * Returns a textual representation of the map entry. - * - * @return The map entry as a <code>String</code>. - */ - public String toString() - { - return e.toString(); - } - }; - } - }; - } - } // class UnmodifiableEntrySet - - /** - * Returns <code>true</code> if the object, o, is also an instance - * of <code>Map</code> with an equal set of map entries. - * - * @param o The object to compare. - * @return <code>true</code> if o is an equivalent map. - */ - public boolean equals(Object o) - { - return m.equals(o); - } - - /** - * Returns the value associated with the supplied key or - * null if no such mapping exists. An ambiguity can occur - * if null values are accepted by the underlying map. - * In this case, <code>containsKey()</code> can be used - * to separate the two possible cases of a null result. - * - * @param key The key to look up. - * @return the value associated with the key, or null if key not in map. - * @throws ClassCastException if the key is an inappropriate type. - * @throws NullPointerException if this map does not accept null keys. - * @see #containsKey(Object) - */ - public Object get(Object key) - { - return m.get(key); - } - - /** - * Blocks the addition of a new entry to the underlying map. - * This method never returns, throwing an exception instead. - * - * @param key The new key. - * @param value The new value. - * @return the previous value of the key, or null if there was no mapping. - * @throws UnsupportedOperationException as an unmodifiable - * map does not support the <code>put()</code> operation. - */ - public Object put(Object key, Object value) - { - throw new UnsupportedOperationException(); - } - - /** - * Computes the hash code for the underlying map, as the sum - * of the hash codes of all entries. - * - * @return The hash code of the underlying map. - * @see Map.Entry#hashCode() - */ - public int hashCode() - { - return m.hashCode(); - } - - /** - * Returns <code>true</code> if the underlying map contains no entries. - * - * @return <code>true</code> if the map is empty. - */ - public boolean isEmpty() - { - return m.isEmpty(); - } - - /** - * Returns a unmodifiable set view of the keys in the underlying map. - * The set is backed by the map, so that changes in one show up in the other. - * Modifications made while an iterator is in progress cause undefined - * behavior. These modifications are again limited to the values of - * the keys. - * - * @return the set view of all keys. - */ - public Set keySet() - { - if (keys == null) - keys = new UnmodifiableSet(m.keySet()); - return keys; - } - - /** - * Blocks the addition of the entries in the supplied map. - * This method never returns, throwing an exception instead. - * - * @param m The map, the entries of which should be added - * to the underlying map. - * @throws UnsupportedOperationException as an unmodifiable - * map does not support the <code>putAll</code> operation. - */ - public void putAll(Map m) - { - throw new UnsupportedOperationException(); - } - - /** - * Blocks the removal of an entry from the map. - * This method never returns, throwing an exception instead. - * - * @param o The key of the entry to remove. - * @return The value the key was associated with, or null - * if no such mapping existed. Null is also returned - * if the removed entry had a null key. - * @throws UnsupportedOperationException as an unmodifiable - * map does not support the <code>remove</code> operation. - */ - public Object remove(Object o) - { - throw new UnsupportedOperationException(); - } - - - /** - * Returns the number of key-value mappings in the underlying map. - * If there are more than Integer.MAX_VALUE mappings, Integer.MAX_VALUE - * is returned. - * - * @return the number of mappings. - */ - public int size() - { - return m.size(); - } - - /** - * Returns a textual representation of the map. - * - * @return The map in the form of a <code>String</code>. - */ - public String toString() - { - return m.toString(); - } - - /** - * Returns a unmodifiable collection view of the values in the underlying map. - * The collection is backed by the map, so that changes in one show up in the other. - * Modifications made while an iterator is in progress cause undefined - * behavior. These modifications are again limited to the values of - * the keys. - * - * @return the collection view of all values. - */ - public Collection values() - { - if (values == null) - values = new UnmodifiableCollection(m.values()); - return values; - } - } // class UnmodifiableMap - - /** - * Returns an unmodifiable view of the given set. This allows - * "read-only" access, although changes in the backing set show up - * in this view. Attempts to modify the set directly or via iterators - * will fail with {@link UnsupportedOperationException}. - * Although this view prevents changes to the structure of the set and its - * entries, the values referenced by the objects in the set can still be - * modified. - * <p> - * - * The returned Set implements Serializable, but can only be serialized if - * the set it wraps is likewise Serializable. - * - * @param s the set to wrap - * @return a read-only view of the set - * @see Serializable - */ - public static Set unmodifiableSet(Set s) - { - return new UnmodifiableSet(s); - } - - /** - * The implementation of {@link #unmodifiableSet(Set)}. This class - * name is required for compatibility with Sun's JDK serializability. - * - * @author Eric Blake (ebb9@email.byu.edu) - */ - private static class UnmodifiableSet extends UnmodifiableCollection - implements Set - { - /** - * Compatible with JDK 1.4. - */ - private static final long serialVersionUID = -9215047833775013803L; - - /** - * Wrap a given set. - * @param s the set to wrap - * @throws NullPointerException if s is null - */ - UnmodifiableSet(Set s) - { - super(s); - } - - /** - * Returns <code>true</code> if the object, o, is also an instance of - * <code>Set</code> of the same size and with the same entries. - * - * @return <code>true</code> if o is an equivalent set. - */ - public boolean equals(Object o) - { - return c.equals(o); - } - - /** - * Computes the hash code of this set, as the sum of the - * hash codes of all elements within the set. - * - * @return the hash code of the set. - */ - public int hashCode() - { - return c.hashCode(); - } - } // class UnmodifiableSet - - /** - * Returns an unmodifiable view of the given sorted map. This allows - * "read-only" access, although changes in the backing map show up in this - * view. Attempts to modify the map directly, via subviews, via collection - * views, or iterators, will fail with {@link UnsupportedOperationException}. - * Although this view prevents changes to the structure of the map and its - * entries, the values referenced by the objects in the map can still be - * modified. - * <p> - * - * The returned SortedMap implements Serializable, but can only be - * serialized if the map it wraps is likewise Serializable. - * - * @param m the map to wrap - * @return a read-only view of the map - * @see Serializable - */ - public static SortedMap unmodifiableSortedMap(SortedMap m) - { - return new UnmodifiableSortedMap(m); - } - - /** - * The implementation of {@link #unmodifiableSortedMap(SortedMap)}. This - * class name is required for compatibility with Sun's JDK serializability. - * - * @author Eric Blake (ebb9@email.byu.edu) - */ - private static class UnmodifiableSortedMap extends UnmodifiableMap - implements SortedMap - { - /** - * Compatible with JDK 1.4. - */ - private static final long serialVersionUID = -8806743815996713206L; - - /** - * The wrapped map; stored both here and in the superclass to avoid - * excessive casting. - * @serial the wrapped map - */ - private final SortedMap sm; - - /** - * Wrap a given map. - * @param sm the map to wrap - * @throws NullPointerException if sm is null - */ - UnmodifiableSortedMap(SortedMap sm) - { - super(sm); - this.sm = sm; - } - - /** - * Returns the comparator used in sorting the underlying map, - * or null if it is the keys' natural ordering. - * - * @return the sorting comparator. - */ - public Comparator comparator() - { - return sm.comparator(); - } - - /** - * Returns the first (lowest sorted) key in the map. - * - * @return the first key. - * @throws NoSuchElementException if this map is empty. - */ - public Object firstKey() - { - return sm.firstKey(); - } - - /** - * Returns a unmodifiable view of the portion of the map strictly less - * than toKey. The view is backed by the underlying map, so changes in - * one show up in the other. The submap supports all optional operations - * of the original. This operation is equivalent to - * <code>subMap(firstKey(), toKey)</code>. - * <p> - * - * The returned map throws an IllegalArgumentException any time a key is - * used which is out of the range of toKey. Note that the endpoint, toKey, - * is not included; if you want this value to be included, pass its successor - * object in to toKey. For example, for Integers, you could request - * <code>headMap(new Integer(limit.intValue() + 1))</code>. - * - * @param toKey the exclusive upper range of the submap. - * @return the submap. - * @throws ClassCastException if toKey is not comparable to the map contents. - * @throws IllegalArgumentException if this is a subMap, and toKey is out - * of range. - * @throws NullPointerException if toKey is null but the map does not allow - * null keys. - */ - public SortedMap headMap(Object toKey) - { - return new UnmodifiableSortedMap(sm.headMap(toKey)); - } - - /** - * Returns the last (highest sorted) key in the map. - * - * @return the last key. - * @throws NoSuchElementException if this map is empty. - */ - public Object lastKey() - { - return sm.lastKey(); - } - - /** - * Returns a unmodifiable view of the portion of the map greater than or - * equal to fromKey, and strictly less than toKey. The view is backed by - * the underlying map, so changes in one show up in the other. The submap - * supports all optional operations of the original. - * <p> - * - * The returned map throws an IllegalArgumentException any time a key is - * used which is out of the range of fromKey and toKey. Note that the - * lower endpoint is included, but the upper is not; if you want to - * change the inclusion or exclusion of an endpoint, pass its successor - * object in instead. For example, for Integers, you could request - * <code>subMap(new Integer(lowlimit.intValue() + 1), - * new Integer(highlimit.intValue() + 1))</code> to reverse - * the inclusiveness of both endpoints. - * - * @param fromKey the inclusive lower range of the submap. - * @param toKey the exclusive upper range of the submap. - * @return the submap. - * @throws ClassCastException if fromKey or toKey is not comparable to - * the map contents. - * @throws IllegalArgumentException if this is a subMap, and fromKey or - * toKey is out of range. - * @throws NullPointerException if fromKey or toKey is null but the map - * does not allow null keys. - */ - public SortedMap subMap(Object fromKey, Object toKey) - { - return new UnmodifiableSortedMap(sm.subMap(fromKey, toKey)); - } - - /** - * Returns a unmodifiable view of the portion of the map greater than or - * equal to fromKey. The view is backed by the underlying map, so changes - * in one show up in the other. The submap supports all optional operations - * of the original. - * <p> - * - * The returned map throws an IllegalArgumentException any time a key is - * used which is out of the range of fromKey. Note that the endpoint, fromKey, is - * included; if you do not want this value to be included, pass its successor object in - * to fromKey. For example, for Integers, you could request - * <code>tailMap(new Integer(limit.intValue() + 1))</code>. - * - * @param fromKey the inclusive lower range of the submap - * @return the submap - * @throws ClassCastException if fromKey is not comparable to the map - * contents - * @throws IllegalArgumentException if this is a subMap, and fromKey is out - * of range - * @throws NullPointerException if fromKey is null but the map does not allow - * null keys - */ - public SortedMap tailMap(Object fromKey) - { - return new UnmodifiableSortedMap(sm.tailMap(fromKey)); - } - } // class UnmodifiableSortedMap - - /** - * Returns an unmodifiable view of the given sorted set. This allows - * "read-only" access, although changes in the backing set show up - * in this view. Attempts to modify the set directly, via subsets, or via - * iterators, will fail with {@link UnsupportedOperationException}. - * Although this view prevents changes to the structure of the set and its - * entries, the values referenced by the objects in the set can still be - * modified. - * <p> - * - * The returns SortedSet implements Serializable, but can only be - * serialized if the set it wraps is likewise Serializable. - * - * @param s the set to wrap - * @return a read-only view of the set - * @see Serializable - */ - public static SortedSet unmodifiableSortedSet(SortedSet s) - { - return new UnmodifiableSortedSet(s); - } - - /** - * The implementation of {@link #synchronizedSortedMap(SortedMap)}. This - * class name is required for compatibility with Sun's JDK serializability. - * - * @author Eric Blake (ebb9@email.byu.edu) - */ - private static class UnmodifiableSortedSet extends UnmodifiableSet - implements SortedSet - { - /** - * Compatible with JDK 1.4. - */ - private static final long serialVersionUID = -4929149591599911165L; - - /** - * The wrapped set; stored both here and in the superclass to avoid - * excessive casting. - * @serial the wrapped set - */ - private SortedSet ss; - - /** - * Wrap a given set. - * @param ss the set to wrap - * @throws NullPointerException if ss is null - */ - UnmodifiableSortedSet(SortedSet ss) - { - super(ss); - this.ss = ss; - } - - /** - * Returns the comparator used in sorting the underlying set, - * or null if it is the elements' natural ordering. - * - * @return the sorting comparator - */ - public Comparator comparator() - { - return ss.comparator(); - } - - /** - * Returns the first (lowest sorted) element in the underlying - * set. - * - * @return the first element. - * @throws NoSuchElementException if the set is empty. - */ - public Object first() - { - return ss.first(); - } - - /** - * Returns a unmodifiable view of the portion of the set strictly - * less than toElement. The view is backed by the underlying set, - * so changes in one show up in the other. The subset supports - * all optional operations of the original. This operation - * is equivalent to <code>subSet(first(), toElement)</code>. - * <p> - * - * The returned set throws an IllegalArgumentException any time an element is - * used which is out of the range of toElement. Note that the endpoint, toElement, - * is not included; if you want this value included, pass its successor object in to - * toElement. For example, for Integers, you could request - * <code>headSet(new Integer(limit.intValue() + 1))</code>. - * - * @param toElement the exclusive upper range of the subset - * @return the subset. - * @throws ClassCastException if toElement is not comparable to the set - * contents. - * @throws IllegalArgumentException if this is a subSet, and toElement is out - * of range. - * @throws NullPointerException if toElement is null but the set does not - * allow null elements. - */ - public SortedSet headSet(Object toElement) - { - return new UnmodifiableSortedSet(ss.headSet(toElement)); - } - - /** - * Returns the last (highest sorted) element in the underlying - * set. - * - * @return the last element. - * @throws NoSuchElementException if the set is empty. - */ - public Object last() - { - return ss.last(); - } - - /** - * Returns a unmodifiable view of the portion of the set greater than or - * equal to fromElement, and strictly less than toElement. The view is backed by - * the underlying set, so changes in one show up in the other. The subset - * supports all optional operations of the original. - * <p> - * - * The returned set throws an IllegalArgumentException any time an element is - * used which is out of the range of fromElement and toElement. Note that the - * lower endpoint is included, but the upper is not; if you want to - * change the inclusion or exclusion of an endpoint, pass its successor - * object in instead. For example, for Integers, you can request - * <code>subSet(new Integer(lowlimit.intValue() + 1), - * new Integer(highlimit.intValue() + 1))</code> to reverse - * the inclusiveness of both endpoints. - * - * @param fromElement the inclusive lower range of the subset. - * @param toElement the exclusive upper range of the subset. - * @return the subset. - * @throws ClassCastException if fromElement or toElement is not comparable - * to the set contents. - * @throws IllegalArgumentException if this is a subSet, and fromElement or - * toElement is out of range. - * @throws NullPointerException if fromElement or toElement is null but the - * set does not allow null elements. - */ - public SortedSet subSet(Object fromElement, Object toElement) - { - return new UnmodifiableSortedSet(ss.subSet(fromElement, toElement)); - } - - /** - * Returns a unmodifiable view of the portion of the set greater than or equal to - * fromElement. The view is backed by the underlying set, so changes in one show up - * in the other. The subset supports all optional operations of the original. - * <p> - * - * The returned set throws an IllegalArgumentException any time an element is - * used which is out of the range of fromElement. Note that the endpoint, - * fromElement, is included; if you do not want this value to be included, pass its - * successor object in to fromElement. For example, for Integers, you could request - * <code>tailSet(new Integer(limit.intValue() + 1))</code>. - * - * @param fromElement the inclusive lower range of the subset - * @return the subset. - * @throws ClassCastException if fromElement is not comparable to the set - * contents. - * @throws IllegalArgumentException if this is a subSet, and fromElement is - * out of range. - * @throws NullPointerException if fromElement is null but the set does not - * allow null elements. - */ - public SortedSet tailSet(Object fromElement) - { - return new UnmodifiableSortedSet(ss.tailSet(fromElement)); - } - } // class UnmodifiableSortedSet -} // class Collections diff --git a/libjava/java/util/Comparator.java b/libjava/java/util/Comparator.java deleted file mode 100644 index 386bdc1d6a2..00000000000 --- a/libjava/java/util/Comparator.java +++ /dev/null @@ -1,119 +0,0 @@ -/* Comparator.java -- Interface for objects that specify an ordering - Copyright (C) 1998, 2001, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util; - -/** - * Interface for objects that specify an ordering between objects. The ordering - * should be <em>total</em>, such that any two objects of the correct type - * can be compared, and the comparison is reflexive, anti-symmetric, and - * transitive. It is also recommended that the comparator be <em>consistent - * with equals</em>, although this is not a strict requirement. A relation - * is consistent with equals if these two statements always have the same - * results (if no exceptions occur):<br> - * <code>compare((Object) e1, (Object) e2) == 0</code> and - * <code>e1.equals((Object) e2)</code><br> - * Comparators that violate consistency with equals may cause strange behavior - * in sorted lists and sets. For example, a case-sensitive dictionary order - * comparison of Strings is consistent with equals, but if it is - * case-insensitive it is not, because "abc" and "ABC" compare as equal even - * though "abc".equals("ABC") returns false. - * <P> - * In general, Comparators should be Serializable, because when they are passed - * to Serializable data structures such as SortedMap or SortedSet, the entire - * data structure will only serialize correctly if the comparator is - * Serializable. - * - * @author Original author unknown - * @author Eric Blake (ebb9@email.byu.edu) - * @see Comparable - * @see TreeMap - * @see TreeSet - * @see SortedMap - * @see SortedSet - * @see Arrays#sort(Object[], Comparator) - * @see java.io.Serializable - * @since 1.2 - * @status updated to 1.4 - */ -public interface Comparator -{ - /** - * Return an integer that is negative, zero or positive depending on whether - * the first argument is less than, equal to or greater than the second - * according to this ordering. This method should obey the following - * contract: - * <ul> - * <li>if compare(a, b) < 0 then compare(b, a) > 0</li> - * <li>if compare(a, b) throws an exception, so does compare(b, a)</li> - * <li>if compare(a, b) < 0 and compare(b, c) < 0 then compare(a, c) - * < 0</li> - * <li>if compare(a, b) == 0 then compare(a, c) and compare(b, c) must - * have the same sign</li> - * </ul> - * To be consistent with equals, the following additional constraint is - * in place: - * <ul> - * <li>if a.equals(b) or both a and b are null, then - * compare(a, b) == 0.</li> - * </ul><p> - * - * Although it is permissible for a comparator to provide an order - * inconsistent with equals, that should be documented. - * - * @param o1 the first object - * @param o2 the second object - * @return the comparison - * @throws ClassCastException if the elements are not of types that can be - * compared by this ordering. - */ - int compare(Object o1, Object o2); - - /** - * Return true if the object is equal to this object. To be - * considered equal, the argument object must satisfy the constraints - * of <code>Object.equals()</code>, be a Comparator, and impose the - * same ordering as this Comparator. The default implementation - * inherited from Object is usually adequate. - * - * @param obj The object - * @return true if it is a Comparator that imposes the same order - * @see Object#equals(Object) - */ - boolean equals(Object obj); -} diff --git a/libjava/java/util/ConcurrentModificationException.java b/libjava/java/util/ConcurrentModificationException.java deleted file mode 100644 index 3d7ae108415..00000000000 --- a/libjava/java/util/ConcurrentModificationException.java +++ /dev/null @@ -1,92 +0,0 @@ -/* ConcurrentModificationException.java -- Data structure concurrently modified - Copyright (C) 1998, 1999, 2001, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util; - -/* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3 - * "The Java Language Specification", ISBN 0-201-63451-1 - * plus online API docs for JDK 1.2 beta from http://www.javasoft.com. - */ - -/** - * Exception that is thrown by the collections classes when it is detected that - * a modification has been made to a data structure when this is not allowed, - * such as when a collection is structurally modified while an Iterator is - * operating over it. In cases where this can be detected, a - * ConcurrentModificationException will be thrown. An Iterator that detects - * this condition is referred to as fail-fast. Notice that this can occur - * even in single-threaded designs, if you call methods out of order. - * - * @author Warren Levy (warrenl@cygnus.com) - * @author Eric Blake (ebb9@email.byu.edu) - * @see Collection - * @see Iterator - * @see ListIterator - * @see Vector - * @see LinkedList - * @see HashSet - * @see Hashtable - * @see TreeMap - * @see AbstractList - * @since 1.2 - * @status updated to 1.4 - */ -public class ConcurrentModificationException extends RuntimeException -{ - /** - * Compatible with JDK 1.2. - */ - private static final long serialVersionUID = -3666751008965953603L; - - /** - * Constructs a ConcurrentModificationException with no detail message. - */ - public ConcurrentModificationException() - { - } - - /** - * Constructs a ConcurrentModificationException with a detail message. - * - * @param detail the detail message for the exception - */ - public ConcurrentModificationException(String detail) - { - super(detail); - } -} diff --git a/libjava/java/util/Dictionary.java b/libjava/java/util/Dictionary.java deleted file mode 100644 index 0d44ab67de1..00000000000 --- a/libjava/java/util/Dictionary.java +++ /dev/null @@ -1,136 +0,0 @@ -/* Dictionary.java -- an abstract (and essentially worthless) - class which is Hashtable's superclass - Copyright (C) 1998, 2001, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util; - -/** - * A Dictionary maps keys to values; <i>how</i> it does that is - * implementation-specific. - * - * This is an abstract class which has really gone by the wayside. - * People at Javasoft are probably embarrassed by it. At this point, - * it might as well be an interface rather than a class, but it remains - * this poor, laughable skeleton for the sake of backwards compatibility. - * At any rate, this was what came before the {@link Map} interface - * in the Collections framework. - * - * @author Jon Zeppieri - * @author Eric Blake (ebb9@email.byu.edu) - * @see Map - * @see Hashtable - * @since 1.0 - * @status updated to 1.4 - */ -public abstract class Dictionary -{ - // WARNING: Dictionary is a CORE class in the bootstrap cycle. See the - // comments in vm/reference/java/lang/Runtime for implications of this fact. - - /** - * Sole constructor (often called implicitly). - */ - public Dictionary() - { - } - - /** - * Returns an Enumeration of the values in this Dictionary. - * - * @return an Enumeration of the values - * @see #keys() - */ - public abstract Enumeration elements(); - - /** - * Returns the value associated with the supplied key, or null - * if no such value exists. Since Dictionaries are not allowed null keys - * or elements, a null result always means the key is not present. - * - * @param key the key to use to fetch the value - * @return the mapped value - * @throws NullPointerException if key is null - * @see #put(Object, Object) - */ - public abstract Object get(Object key); - - /** - * Returns true when there are no elements in this Dictionary. - * - * @return <code>size() == 0</code> - */ - public abstract boolean isEmpty(); - - /** - * Returns an Enumeration of the keys in this Dictionary - * - * @return an Enumeration of the keys - * @see #elements() - */ - public abstract Enumeration keys(); - - /** - * Inserts a new value into this Dictionary, located by the - * supplied key. Dictionary does not support null keys or values, so - * a null return can safely be interpreted as adding a new key. - * - * @param key the key which locates the value - * @param value the value to put into the Dictionary - * @return the previous value of the key, or null if there was none - * @throws NullPointerException if key or value is null - * @see #get(Object) - */ - public abstract Object put(Object key, Object value); - - /** - * Removes from the Dictionary the value located by the given key. A null - * return safely means that the key was not mapped in the Dictionary. - * - * @param key the key used to locate the value to be removed - * @return the value associated with the removed key - * @throws NullPointerException if key is null - */ - public abstract Object remove(Object key); - - /** - * Returns the number of values currently in this Dictionary. - * - * @return the number of keys in the Dictionary - */ - public abstract int size(); -} // class Dictionary diff --git a/libjava/java/util/EmptyStackException.java b/libjava/java/util/EmptyStackException.java deleted file mode 100644 index e8b4509ee5c..00000000000 --- a/libjava/java/util/EmptyStackException.java +++ /dev/null @@ -1,69 +0,0 @@ -/* EmptyStackException.java -- Attempt to pop from an empty stack - Copyright (C) 1998, 1999, 2001, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util; - -/* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3 - * "The Java Language Specification", ISBN 0-201-63451-1 - * plus online API docs for JDK 1.2 beta from http://www.javasoft.com. - */ - -/** - * This exception is thrown by the Stack class when an attempt is made to pop - * or otherwise access elements from an empty stack. - * - * @author Warren Levy (warrenl@cygnus.com) - * @author Eric Blake (ebb9@email.byu.edu) - * @see Stack - * @since 1.0 - * @status updated to 1.4 - */ -public class EmptyStackException extends RuntimeException -{ - /** - * Compatible with JDK 1.0. - */ - private static final long serialVersionUID = 5084686378493302095L; - - /** - * Constructs an EmptyStackException with no detail message. - */ - public EmptyStackException() - { - } -} diff --git a/libjava/java/util/Enumeration.java b/libjava/java/util/Enumeration.java deleted file mode 100644 index 1365bbb2f0f..00000000000 --- a/libjava/java/util/Enumeration.java +++ /dev/null @@ -1,81 +0,0 @@ -/* Enumeration.java -- Interface for enumerating lists of objects - Copyright (C) 1998, 1999, 2001, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.util; - -/* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3 - * "The Java Language Specification", ISBN 0-201-63451-1. - * Status: Believed complete and correct - */ - -/** - * Interface for lists of objects that can be returned in sequence. Successive - * objects are obtained by the nextElement method. - * <p> - * As of Java 1.2, the Iterator interface provides the same functionality, but - * with shorter method names and a new optional method to remove items from the - * list. If writing for 1.2, consider using Iterator instead. Enumerations over - * the new collections classes, for use with legacy APIs that require them, can - * be obtained by the enumeration method in class Collections. - * - * @author Warren Levy (warrenl@cygnus.com) - * @author Eric Blake (ebb9@email.byu.edu) - * @see Iterator - * @see Hashtable - * @see Vector - * @since 1.0 - * @status updated to 1.4 - */ -public interface Enumeration -{ - /** - * Tests whether there are elements remaining in the enumeration. - * - * @return true if there is at least one more element in the enumeration, - * that is, if the next call to nextElement will not throw a - * NoSuchElementException. - */ - boolean hasMoreElements(); - - /** - * Obtain the next element in the enumeration. - * - * @return the next element in the enumeration - * @throws NoSuchElementException if there are no more elements - */ - Object nextElement(); -} diff --git a/libjava/java/util/EventListener.java b/libjava/java/util/EventListener.java deleted file mode 100644 index c9a1795f900..00000000000 --- a/libjava/java/util/EventListener.java +++ /dev/null @@ -1,54 +0,0 @@ -/* EventListener.java -- tagging interface for all event listeners - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util; - -/** - * Empty interface that is implemented by classes that need to receive - * events. Subinterfaces define methods that can be called to fire an - * event notification. Normally the name of these subinterfaces end in - * <code>Listener</code> and all method described by the subinterface - * take as argument an subclass of <code>EventObject</code>. - * - * @author Tom Tromey (tromey@cygnus.com) - * @see EventObject - * @status updated to 1.4 - */ -public interface EventListener -{ -} diff --git a/libjava/java/util/EventListenerProxy.java b/libjava/java/util/EventListenerProxy.java deleted file mode 100644 index 245c5ffb458..00000000000 --- a/libjava/java/util/EventListenerProxy.java +++ /dev/null @@ -1,75 +0,0 @@ -/* EventListenerProxy.java -- abstract wrapper for event listeners - Copyright (C) 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util; - -/** - * An abstract wrapper for event listeners. This allows subclasses to - * attach additional parameters to an existing event listener to create - * a new one. Subclasses are expected to add methods to set and retrieve - * any attached properties. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @since 1.4 - * @status updated to 1.4 - */ -public abstract class EventListenerProxy implements EventListener -{ - /** The listener that this proxy wraps. */ - private final EventListener listener; - - /** - * Construct a proxy event listener, given an existing one to augment. - * - * @param listener the listener to wrap - */ - public EventListenerProxy(EventListener listener) - { - this.listener = listener; - } - - /** - * Return the wrapped event listener. - * - * @return the listener associated with this proxy - */ - public EventListener getListener() - { - return listener; - } -} // class EventListenerProxy diff --git a/libjava/java/util/EventObject.java b/libjava/java/util/EventObject.java deleted file mode 100644 index 7ced18aa4ba..00000000000 --- a/libjava/java/util/EventObject.java +++ /dev/null @@ -1,101 +0,0 @@ -/* EventObject.java -- represents an event on an object - Copyright (C) 1999, 2000, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util; - -import java.io.Serializable; - -/** - * Represents Events fired by Objects. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @see EventListener - * @since 1.1 - * @status updated to 1.4 - */ -public class EventObject implements Serializable -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = 5516075349620653480L; - - /** - * The source object; in other words, the object which this event takes - * place on. - */ - protected transient Object source; - - /** - * Constructs an EventObject with the specified source. - * - * @param source the source of the event - * @throws IllegalArgumentException if source is null (This is not - * specified, but matches the behavior of the JDK) - */ - public EventObject(Object source) - { - // This check for null is stupid, if you ask me, since source is - // protected and non-final, so a subclass can set it to null later on. - if (source == null) - throw new IllegalArgumentException(); - this.source = source; - } - - /** - * Returns the source of the event. - * - * @return the event source - */ - public Object getSource() - { - return source; - } - - /** - * Converts the event to a String. The format is not specified, but by - * observation, the JDK uses: - * <code>getClass().getName() + "[source=" + source + "]";</code>. - * - * @return String representation of the Event - */ - public String toString() - { - return getClass().getName() + "[source=" + source + "]"; - } -} // class EventObject diff --git a/libjava/java/util/HashMap.java b/libjava/java/util/HashMap.java deleted file mode 100644 index 5ca9cf6d500..00000000000 --- a/libjava/java/util/HashMap.java +++ /dev/null @@ -1,906 +0,0 @@ -/* HashMap.java -- a class providing a basic hashtable data structure, - mapping Object --> Object - Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util; - -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; - -// NOTE: This implementation is very similar to that of Hashtable. If you fix -// a bug in here, chances are you should make a similar change to the Hashtable -// code. - -// NOTE: This implementation has some nasty coding style in order to -// support LinkedHashMap, which extends this. - -/** - * This class provides a hashtable-backed implementation of the - * Map interface. - * <p> - * - * It uses a hash-bucket approach; that is, hash collisions are handled - * by linking the new node off of the pre-existing node (or list of - * nodes). In this manner, techniques such as linear probing (which - * can cause primary clustering) and rehashing (which does not fit very - * well with Java's method of precomputing hash codes) are avoided. - * <p> - * - * Under ideal circumstances (no collisions), HashMap offers O(1) - * performance on most operations (<code>containsValue()</code> is, - * of course, O(n)). In the worst case (all keys map to the same - * hash code -- very unlikely), most operations are O(n). - * <p> - * - * HashMap is part of the JDK1.2 Collections API. It differs from - * Hashtable in that it accepts the null key and null values, and it - * does not support "Enumeration views." Also, it is not synchronized; - * if you plan to use it in multiple threads, consider using:<br> - * <code>Map m = Collections.synchronizedMap(new HashMap(...));</code> - * <p> - * - * The iterators are <i>fail-fast</i>, meaning that any structural - * modification, except for <code>remove()</code> called on the iterator - * itself, cause the iterator to throw a - * <code>ConcurrentModificationException</code> rather than exhibit - * non-deterministic behavior. - * - * @author Jon Zeppieri - * @author Jochen Hoenicke - * @author Bryce McKinlay - * @author Eric Blake (ebb9@email.byu.edu) - * @see Object#hashCode() - * @see Collection - * @see Map - * @see TreeMap - * @see LinkedHashMap - * @see IdentityHashMap - * @see Hashtable - * @since 1.2 - * @status updated to 1.4 - */ -public class HashMap extends AbstractMap - implements Map, Cloneable, Serializable -{ - /** - * Default number of buckets. This is the value the JDK 1.3 uses. Some - * early documentation specified this value as 101. That is incorrect. - * Package visible for use by HashSet. - */ - static final int DEFAULT_CAPACITY = 11; - - /** - * The default load factor; this is explicitly specified by the spec. - * Package visible for use by HashSet. - */ - static final float DEFAULT_LOAD_FACTOR = 0.75f; - - /** - * Compatible with JDK 1.2. - */ - private static final long serialVersionUID = 362498820763181265L; - - /** - * The rounded product of the capacity and the load factor; when the number - * of elements exceeds the threshold, the HashMap calls - * <code>rehash()</code>. - * @serial the threshold for rehashing - */ - private int threshold; - - /** - * Load factor of this HashMap: used in computing the threshold. - * Package visible for use by HashSet. - * @serial the load factor - */ - final float loadFactor; - - /** - * Array containing the actual key-value mappings. - * Package visible for use by nested and subclasses. - */ - transient HashEntry[] buckets; - - /** - * Counts the number of modifications this HashMap has undergone, used - * by Iterators to know when to throw ConcurrentModificationExceptions. - * Package visible for use by nested and subclasses. - */ - transient int modCount; - - /** - * The size of this HashMap: denotes the number of key-value pairs. - * Package visible for use by nested and subclasses. - */ - transient int size; - - /** - * The cache for {@link #entrySet()}. - */ - private transient Set entries; - - /** - * Class to represent an entry in the hash table. Holds a single key-value - * pair. Package visible for use by subclass. - * - * @author Eric Blake (ebb9@email.byu.edu) - */ - static class HashEntry extends AbstractMap.BasicMapEntry - { - /** - * The next entry in the linked list. Package visible for use by subclass. - */ - HashEntry next; - - /** - * Simple constructor. - * @param key the key - * @param value the value - */ - HashEntry(Object key, Object value) - { - super(key, value); - } - - /** - * Called when this entry is accessed via {@link #put(Object, Object)}. - * This version does nothing, but in LinkedHashMap, it must do some - * bookkeeping for access-traversal mode. - */ - void access() - { - } - - /** - * Called when this entry is removed from the map. This version simply - * returns the value, but in LinkedHashMap, it must also do bookkeeping. - * - * @return the value of this key as it is removed - */ - Object cleanup() - { - return value; - } - } - - /** - * Construct a new HashMap with the default capacity (11) and the default - * load factor (0.75). - */ - public HashMap() - { - this(DEFAULT_CAPACITY, DEFAULT_LOAD_FACTOR); - } - - /** - * Construct a new HashMap from the given Map, with initial capacity - * the greater of the size of <code>m</code> or the default of 11. - * <p> - * - * Every element in Map m will be put into this new HashMap. - * - * @param m a Map whose key / value pairs will be put into the new HashMap. - * <b>NOTE: key / value pairs are not cloned in this constructor.</b> - * @throws NullPointerException if m is null - */ - public HashMap(Map m) - { - this(Math.max(m.size() * 2, DEFAULT_CAPACITY), DEFAULT_LOAD_FACTOR); - putAll(m); - } - - /** - * Construct a new HashMap with a specific inital capacity and - * default load factor of 0.75. - * - * @param initialCapacity the initial capacity of this HashMap (>=0) - * @throws IllegalArgumentException if (initialCapacity < 0) - */ - public HashMap(int initialCapacity) - { - this(initialCapacity, DEFAULT_LOAD_FACTOR); - } - - /** - * Construct a new HashMap with a specific inital capacity and load factor. - * - * @param initialCapacity the initial capacity (>=0) - * @param loadFactor the load factor (> 0, not NaN) - * @throws IllegalArgumentException if (initialCapacity < 0) || - * ! (loadFactor > 0.0) - */ - public HashMap(int initialCapacity, float loadFactor) - { - if (initialCapacity < 0) - throw new IllegalArgumentException("Illegal Capacity: " - + initialCapacity); - if (! (loadFactor > 0)) // check for NaN too - throw new IllegalArgumentException("Illegal Load: " + loadFactor); - - if (initialCapacity == 0) - initialCapacity = 1; - buckets = new HashEntry[initialCapacity]; - this.loadFactor = loadFactor; - threshold = (int) (initialCapacity * loadFactor); - } - - /** - * Returns the number of kay-value mappings currently in this Map. - * - * @return the size - */ - public int size() - { - return size; - } - - /** - * Returns true if there are no key-value mappings currently in this Map. - * - * @return <code>size() == 0</code> - */ - public boolean isEmpty() - { - return size == 0; - } - - /** - * Return the value in this HashMap associated with the supplied key, - * or <code>null</code> if the key maps to nothing. NOTE: Since the value - * could also be null, you must use containsKey to see if this key - * actually maps to something. - * - * @param key the key for which to fetch an associated value - * @return what the key maps to, if present - * @see #put(Object, Object) - * @see #containsKey(Object) - */ - public Object get(Object key) - { - int idx = hash(key); - HashEntry e = buckets[idx]; - while (e != null) - { - if (equals(key, e.key)) - return e.value; - e = e.next; - } - return null; - } - - /** - * Returns true if the supplied object <code>equals()</code> a key - * in this HashMap. - * - * @param key the key to search for in this HashMap - * @return true if the key is in the table - * @see #containsValue(Object) - */ - public boolean containsKey(Object key) - { - int idx = hash(key); - HashEntry e = buckets[idx]; - while (e != null) - { - if (equals(key, e.key)) - return true; - e = e.next; - } - return false; - } - - /** - * Puts the supplied value into the Map, mapped by the supplied key. - * The value may be retrieved by any object which <code>equals()</code> - * this key. NOTE: Since the prior value could also be null, you must - * first use containsKey if you want to see if you are replacing the - * key's mapping. - * - * @param key the key used to locate the value - * @param value the value to be stored in the HashMap - * @return the prior mapping of the key, or null if there was none - * @see #get(Object) - * @see Object#equals(Object) - */ - public Object put(Object key, Object value) - { - int idx = hash(key); - HashEntry e = buckets[idx]; - - while (e != null) - { - if (equals(key, e.key)) - { - e.access(); // Must call this for bookkeeping in LinkedHashMap. - Object r = e.value; - e.value = value; - return r; - } - else - e = e.next; - } - - // At this point, we know we need to add a new entry. - modCount++; - if (++size > threshold) - { - rehash(); - // Need a new hash value to suit the bigger table. - idx = hash(key); - } - - // LinkedHashMap cannot override put(), hence this call. - addEntry(key, value, idx, true); - return null; - } - - /** - * Copies all elements of the given map into this hashtable. If this table - * already has a mapping for a key, the new mapping replaces the current - * one. - * - * @param m the map to be hashed into this - */ - public void putAll(Map m) - { - Iterator itr = m.entrySet().iterator(); - while (itr.hasNext()) - { - Map.Entry e = (Map.Entry) itr.next(); - // Optimize in case the Entry is one of our own. - if (e instanceof AbstractMap.BasicMapEntry) - { - AbstractMap.BasicMapEntry entry = (AbstractMap.BasicMapEntry) e; - put(entry.key, entry.value); - } - else - put(e.getKey(), e.getValue()); - } - } - - /** - * Removes from the HashMap and returns the value which is mapped by the - * supplied key. If the key maps to nothing, then the HashMap remains - * unchanged, and <code>null</code> is returned. NOTE: Since the value - * could also be null, you must use containsKey to see if you are - * actually removing a mapping. - * - * @param key the key used to locate the value to remove - * @return whatever the key mapped to, if present - */ - public Object remove(Object key) - { - int idx = hash(key); - HashEntry e = buckets[idx]; - HashEntry last = null; - - while (e != null) - { - if (equals(key, e.key)) - { - modCount++; - if (last == null) - buckets[idx] = e.next; - else - last.next = e.next; - size--; - // Method call necessary for LinkedHashMap to work correctly. - return e.cleanup(); - } - last = e; - e = e.next; - } - return null; - } - - /** - * Clears the Map so it has no keys. This is O(1). - */ - public void clear() - { - if (size != 0) - { - modCount++; - Arrays.fill(buckets, null); - size = 0; - } - } - - /** - * Returns true if this HashMap contains a value <code>o</code>, such that - * <code>o.equals(value)</code>. - * - * @param value the value to search for in this HashMap - * @return true if at least one key maps to the value - * @see containsKey(Object) - */ - public boolean containsValue(Object value) - { - for (int i = buckets.length - 1; i >= 0; i--) - { - HashEntry e = buckets[i]; - while (e != null) - { - if (equals(value, e.value)) - return true; - e = e.next; - } - } - return false; - } - - /** - * Returns a shallow clone of this HashMap. The Map itself is cloned, - * but its contents are not. This is O(n). - * - * @return the clone - */ - public Object clone() - { - HashMap copy = null; - try - { - copy = (HashMap) super.clone(); - } - catch (CloneNotSupportedException x) - { - // This is impossible. - } - copy.buckets = new HashEntry[buckets.length]; - copy.putAllInternal(this); - // Clear the entry cache. AbstractMap.clone() does the others. - copy.entries = null; - return copy; - } - - /** - * Returns a "set view" of this HashMap's keys. The set is backed by the - * HashMap, so changes in one show up in the other. The set supports - * element removal, but not element addition. - * - * @return a set view of the keys - * @see #values() - * @see #entrySet() - */ - public Set keySet() - { - if (keys == null) - // Create an AbstractSet with custom implementations of those methods - // that can be overridden easily and efficiently. - keys = new AbstractSet() - { - public int size() - { - return size; - } - - public Iterator iterator() - { - // Cannot create the iterator directly, because of LinkedHashMap. - return HashMap.this.iterator(KEYS); - } - - public void clear() - { - HashMap.this.clear(); - } - - public boolean contains(Object o) - { - return containsKey(o); - } - - public boolean remove(Object o) - { - // Test against the size of the HashMap to determine if anything - // really got removed. This is necessary because the return value - // of HashMap.remove() is ambiguous in the null case. - int oldsize = size; - HashMap.this.remove(o); - return oldsize != size; - } - }; - return keys; - } - - /** - * Returns a "collection view" (or "bag view") of this HashMap's values. - * The collection is backed by the HashMap, so changes in one show up - * in the other. The collection supports element removal, but not element - * addition. - * - * @return a bag view of the values - * @see #keySet() - * @see #entrySet() - */ - public Collection values() - { - if (values == null) - // We don't bother overriding many of the optional methods, as doing so - // wouldn't provide any significant performance advantage. - values = new AbstractCollection() - { - public int size() - { - return size; - } - - public Iterator iterator() - { - // Cannot create the iterator directly, because of LinkedHashMap. - return HashMap.this.iterator(VALUES); - } - - public void clear() - { - HashMap.this.clear(); - } - }; - return values; - } - - /** - * Returns a "set view" of this HashMap's entries. The set is backed by - * the HashMap, so changes in one show up in the other. The set supports - * element removal, but not element addition.<p> - * - * Note that the iterators for all three views, from keySet(), entrySet(), - * and values(), traverse the HashMap in the same sequence. - * - * @return a set view of the entries - * @see #keySet() - * @see #values() - * @see Map.Entry - */ - public Set entrySet() - { - if (entries == null) - // Create an AbstractSet with custom implementations of those methods - // that can be overridden easily and efficiently. - entries = new AbstractSet() - { - public int size() - { - return size; - } - - public Iterator iterator() - { - // Cannot create the iterator directly, because of LinkedHashMap. - return HashMap.this.iterator(ENTRIES); - } - - public void clear() - { - HashMap.this.clear(); - } - - public boolean contains(Object o) - { - return getEntry(o) != null; - } - - public boolean remove(Object o) - { - HashEntry e = getEntry(o); - if (e != null) - { - HashMap.this.remove(e.key); - return true; - } - return false; - } - }; - return entries; - } - - /** - * Helper method for put, that creates and adds a new Entry. This is - * overridden in LinkedHashMap for bookkeeping purposes. - * - * @param key the key of the new Entry - * @param value the value - * @param idx the index in buckets where the new Entry belongs - * @param callRemove whether to call the removeEldestEntry method - * @see #put(Object, Object) - */ - void addEntry(Object key, Object value, int idx, boolean callRemove) - { - HashEntry e = new HashEntry(key, value); - e.next = buckets[idx]; - buckets[idx] = e; - } - - /** - * Helper method for entrySet(), which matches both key and value - * simultaneously. - * - * @param o the entry to match - * @return the matching entry, if found, or null - * @see #entrySet() - */ - // Package visible, for use in nested classes. - final HashEntry getEntry(Object o) - { - if (! (o instanceof Map.Entry)) - return null; - Map.Entry me = (Map.Entry) o; - Object key = me.getKey(); - int idx = hash(key); - HashEntry e = buckets[idx]; - while (e != null) - { - if (equals(e.key, key)) - return equals(e.value, me.getValue()) ? e : null; - e = e.next; - } - return null; - } - - /** - * Helper method that returns an index in the buckets array for `key' - * based on its hashCode(). Package visible for use by subclasses. - * - * @param key the key - * @return the bucket number - */ - final int hash(Object key) - { - return key == null ? 0 : Math.abs(key.hashCode() % buckets.length); - } - - /** - * Generates a parameterized iterator. Must be overrideable, since - * LinkedHashMap iterates in a different order. - * - * @param type {@link #KEYS}, {@link #VALUES}, or {@link #ENTRIES} - * @return the appropriate iterator - */ - Iterator iterator(int type) - { - return new HashIterator(type); - } - - /** - * A simplified, more efficient internal implementation of putAll(). clone() - * should not call putAll or put, in order to be compatible with the JDK - * implementation with respect to subclasses. - * - * @param m the map to initialize this from - */ - void putAllInternal(Map m) - { - Iterator itr = m.entrySet().iterator(); - size = 0; - while (itr.hasNext()) - { - size++; - Map.Entry e = (Map.Entry) itr.next(); - Object key = e.getKey(); - int idx = hash(key); - addEntry(key, e.getValue(), idx, false); - } - } - - /** - * Increases the size of the HashMap and rehashes all keys to new - * array indices; this is called when the addition of a new value - * would cause size() > threshold. Note that the existing Entry - * objects are reused in the new hash table. - * - * <p>This is not specified, but the new size is twice the current size - * plus one; this number is not always prime, unfortunately. - */ - private void rehash() - { - HashEntry[] oldBuckets = buckets; - - int newcapacity = (buckets.length * 2) + 1; - threshold = (int) (newcapacity * loadFactor); - buckets = new HashEntry[newcapacity]; - - for (int i = oldBuckets.length - 1; i >= 0; i--) - { - HashEntry e = oldBuckets[i]; - while (e != null) - { - int idx = hash(e.key); - HashEntry dest = buckets[idx]; - HashEntry next = e.next; - e.next = buckets[idx]; - buckets[idx] = e; - e = next; - } - } - } - - /** - * Serializes this object to the given stream. - * - * @param s the stream to write to - * @throws IOException if the underlying stream fails - * @serialData the <i>capacity</i>(int) that is the length of the - * bucket array, the <i>size</i>(int) of the hash map - * are emitted first. They are followed by size entries, - * each consisting of a key (Object) and a value (Object). - */ - private void writeObject(ObjectOutputStream s) throws IOException - { - // Write the threshold and loadFactor fields. - s.defaultWriteObject(); - - s.writeInt(buckets.length); - s.writeInt(size); - // Avoid creating a wasted Set by creating the iterator directly. - Iterator it = iterator(ENTRIES); - while (it.hasNext()) - { - HashEntry entry = (HashEntry) it.next(); - s.writeObject(entry.key); - s.writeObject(entry.value); - } - } - - /** - * Deserializes this object from the given stream. - * - * @param s the stream to read from - * @throws ClassNotFoundException if the underlying stream fails - * @throws IOException if the underlying stream fails - * @serialData the <i>capacity</i>(int) that is the length of the - * bucket array, the <i>size</i>(int) of the hash map - * are emitted first. They are followed by size entries, - * each consisting of a key (Object) and a value (Object). - */ - private void readObject(ObjectInputStream s) - throws IOException, ClassNotFoundException - { - // Read the threshold and loadFactor fields. - s.defaultReadObject(); - - // Read and use capacity, followed by key/value pairs. - buckets = new HashEntry[s.readInt()]; - int len = s.readInt(); - size = len; - while (len-- > 0) - { - Object key = s.readObject(); - addEntry(key, s.readObject(), hash(key), false); - } - } - - /** - * Iterate over HashMap's entries. - * This implementation is parameterized to give a sequential view of - * keys, values, or entries. - * - * @author Jon Zeppieri - */ - private final class HashIterator implements Iterator - { - /** - * The type of this Iterator: {@link #KEYS}, {@link #VALUES}, - * or {@link #ENTRIES}. - */ - private final int type; - /** - * The number of modifications to the backing HashMap that we know about. - */ - private int knownMod = modCount; - /** The number of elements remaining to be returned by next(). */ - private int count = size; - /** Current index in the physical hash table. */ - private int idx = buckets.length; - /** The last Entry returned by a next() call. */ - private HashEntry last; - /** - * The next entry that should be returned by next(). It is set to something - * if we're iterating through a bucket that contains multiple linked - * entries. It is null if next() needs to find a new bucket. - */ - private HashEntry next; - - /** - * Construct a new HashIterator with the supplied type. - * @param type {@link #KEYS}, {@link #VALUES}, or {@link #ENTRIES} - */ - HashIterator(int type) - { - this.type = type; - } - - /** - * Returns true if the Iterator has more elements. - * @return true if there are more elements - * @throws ConcurrentModificationException if the HashMap was modified - */ - public boolean hasNext() - { - if (knownMod != modCount) - throw new ConcurrentModificationException(); - return count > 0; - } - - /** - * Returns the next element in the Iterator's sequential view. - * @return the next element - * @throws ConcurrentModificationException if the HashMap was modified - * @throws NoSuchElementException if there is none - */ - public Object next() - { - if (knownMod != modCount) - throw new ConcurrentModificationException(); - if (count == 0) - throw new NoSuchElementException(); - count--; - HashEntry e = next; - - while (e == null) - e = buckets[--idx]; - - next = e.next; - last = e; - if (type == VALUES) - return e.value; - if (type == KEYS) - return e.key; - return e; - } - - /** - * Removes from the backing HashMap the last element which was fetched - * with the <code>next()</code> method. - * @throws ConcurrentModificationException if the HashMap was modified - * @throws IllegalStateException if called when there is no last element - */ - public void remove() - { - if (knownMod != modCount) - throw new ConcurrentModificationException(); - if (last == null) - throw new IllegalStateException(); - - HashMap.this.remove(last.key); - last = null; - knownMod++; - } - } -} diff --git a/libjava/java/util/HashSet.java b/libjava/java/util/HashSet.java deleted file mode 100644 index 681d5bb1b07..00000000000 --- a/libjava/java/util/HashSet.java +++ /dev/null @@ -1,293 +0,0 @@ -/* HashSet.java -- a class providing a HashMap-backed Set - Copyright (C) 1998, 1999, 2001, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util; - -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; - -/** - * This class provides a HashMap-backed implementation of the Set interface. - * <p> - * - * Most operations are O(1), assuming no hash collisions. In the worst - * case (where all hashes collide), operations are O(n). Setting the - * initial capacity too low will force many resizing operations, but - * setting the initial capacity too high (or loadfactor too low) leads - * to wasted memory and slower iteration. - * <p> - * - * HashSet accepts the null key and null values. It is not synchronized, - * so if you need multi-threaded access, consider using:<br> - * <code>Set s = Collections.synchronizedSet(new HashSet(...));</code> - * <p> - * - * The iterators are <i>fail-fast</i>, meaning that any structural - * modification, except for <code>remove()</code> called on the iterator - * itself, cause the iterator to throw a - * {@link ConcurrentModificationException} rather than exhibit - * non-deterministic behavior. - * - * @author Jon Zeppieri - * @author Eric Blake (ebb9@email.byu.edu) - * @see Collection - * @see Set - * @see TreeSet - * @see Collections#synchronizedSet(Set) - * @see HashMap - * @see LinkedHashSet - * @since 1.2 - * @status updated to 1.4 - */ -public class HashSet extends AbstractSet - implements Set, Cloneable, Serializable -{ - /** - * Compatible with JDK 1.2. - */ - private static final long serialVersionUID = -5024744406713321676L; - - /** - * The HashMap which backs this Set. - */ - private transient HashMap map; - - /** - * Construct a new, empty HashSet whose backing HashMap has the default - * capacity (11) and loadFacor (0.75). - */ - public HashSet() - { - this(HashMap.DEFAULT_CAPACITY, HashMap.DEFAULT_LOAD_FACTOR); - } - - /** - * Construct a new, empty HashSet whose backing HashMap has the supplied - * capacity and the default load factor (0.75). - * - * @param initialCapacity the initial capacity of the backing HashMap - * @throws IllegalArgumentException if the capacity is negative - */ - public HashSet(int initialCapacity) - { - this(initialCapacity, HashMap.DEFAULT_LOAD_FACTOR); - } - - /** - * Construct a new, empty HashSet whose backing HashMap has the supplied - * capacity and load factor. - * - * @param initialCapacity the initial capacity of the backing HashMap - * @param loadFactor the load factor of the backing HashMap - * @throws IllegalArgumentException if either argument is negative, or - * if loadFactor is POSITIVE_INFINITY or NaN - */ - public HashSet(int initialCapacity, float loadFactor) - { - map = init(initialCapacity, loadFactor); - } - - /** - * Construct a new HashSet with the same elements as are in the supplied - * collection (eliminating any duplicates, of course). The backing storage - * has twice the size of the collection, or the default size of 11, - * whichever is greater; and the default load factor (0.75). - * - * @param c a collection of initial set elements - * @throws NullPointerException if c is null - */ - public HashSet(Collection c) - { - this(Math.max(2 * c.size(), HashMap.DEFAULT_CAPACITY)); - addAll(c); - } - - /** - * Adds the given Object to the set if it is not already in the Set. - * This set permits a null element. - * - * @param o the Object to add to this Set - * @return true if the set did not already contain o - */ - public boolean add(Object o) - { - return map.put(o, "") == null; - } - - /** - * Empties this Set of all elements; this takes constant time. - */ - public void clear() - { - map.clear(); - } - - /** - * Returns a shallow copy of this Set. The Set itself is cloned; its - * elements are not. - * - * @return a shallow clone of the set - */ - public Object clone() - { - HashSet copy = null; - try - { - copy = (HashSet) super.clone(); - } - catch (CloneNotSupportedException x) - { - // Impossible to get here. - } - copy.map = (HashMap) map.clone(); - return copy; - } - - /** - * Returns true if the supplied element is in this Set. - * - * @param o the Object to look for - * @return true if it is in the set - */ - public boolean contains(Object o) - { - return map.containsKey(o); - } - - /** - * Returns true if this set has no elements in it. - * - * @return <code>size() == 0</code>. - */ - public boolean isEmpty() - { - return map.size == 0; - } - - /** - * Returns an Iterator over the elements of this Set, which visits the - * elements in no particular order. For this class, the Iterator allows - * removal of elements. The iterator is fail-fast, and will throw a - * ConcurrentModificationException if the set is modified externally. - * - * @return a set iterator - * @see ConcurrentModificationException - */ - public Iterator iterator() - { - // Avoid creating intermediate keySet() object by using non-public API. - return map.iterator(HashMap.KEYS); - } - - /** - * Removes the supplied Object from this Set if it is in the Set. - * - * @param o the object to remove - * @return true if an element was removed - */ - public boolean remove(Object o) - { - return (map.remove(o) != null); - } - - /** - * Returns the number of elements in this Set (its cardinality). - * - * @return the size of the set - */ - public int size() - { - return map.size; - } - - /** - * Helper method which initializes the backing Map. Overridden by - * LinkedHashSet for correct semantics. - * - * @param capacity the initial capacity - * @param load the initial load factor - * @return the backing HashMap - */ - HashMap init(int capacity, float load) - { - return new HashMap(capacity, load); - } - - /** - * Serializes this object to the given stream. - * - * @param s the stream to write to - * @throws IOException if the underlying stream fails - * @serialData the <i>capacity</i> (int) and <i>loadFactor</i> (float) - * of the backing store, followed by the set size (int), - * then a listing of its elements (Object) in no order - */ - private void writeObject(ObjectOutputStream s) throws IOException - { - s.defaultWriteObject(); - // Avoid creating intermediate keySet() object by using non-public API. - Iterator it = map.iterator(HashMap.KEYS); - s.writeInt(map.buckets.length); - s.writeFloat(map.loadFactor); - s.writeInt(map.size); - while (it.hasNext()) - s.writeObject(it.next()); - } - - /** - * Deserializes this object from the given stream. - * - * @param s the stream to read from - * @throws ClassNotFoundException if the underlying stream fails - * @throws IOException if the underlying stream fails - * @serialData the <i>capacity</i> (int) and <i>loadFactor</i> (float) - * of the backing store, followed by the set size (int), - * then a listing of its elements (Object) in no order - */ - private void readObject(ObjectInputStream s) - throws IOException, ClassNotFoundException - { - s.defaultReadObject(); - - map = init(s.readInt(), s.readFloat()); - for (int size = s.readInt(); size > 0; size--) - map.put(s.readObject(), ""); - } -} diff --git a/libjava/java/util/Hashtable.java b/libjava/java/util/Hashtable.java deleted file mode 100644 index 78d5fa10c69..00000000000 --- a/libjava/java/util/Hashtable.java +++ /dev/null @@ -1,1151 +0,0 @@ -/* Hashtable.java -- a class providing a basic hashtable data structure, - mapping Object --> Object - Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.util; - -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; - -// NOTE: This implementation is very similar to that of HashMap. If you fix -// a bug in here, chances are you should make a similar change to the HashMap -// code. - -/** - * A class which implements a hashtable data structure. - * <p> - * - * This implementation of Hashtable uses a hash-bucket approach. That is: - * linear probing and rehashing is avoided; instead, each hashed value maps - * to a simple linked-list which, in the best case, only has one node. - * Assuming a large enough table, low enough load factor, and / or well - * implemented hashCode() methods, Hashtable should provide O(1) - * insertion, deletion, and searching of keys. Hashtable is O(n) in - * the worst case for all of these (if all keys hash to the same bucket). - * <p> - * - * This is a JDK-1.2 compliant implementation of Hashtable. As such, it - * belongs, partially, to the Collections framework (in that it implements - * Map). For backwards compatibility, it inherits from the obsolete and - * utterly useless Dictionary class. - * <p> - * - * Being a hybrid of old and new, Hashtable has methods which provide redundant - * capability, but with subtle and even crucial differences. - * For example, one can iterate over various aspects of a Hashtable with - * either an Iterator (which is the JDK-1.2 way of doing things) or with an - * Enumeration. The latter can end up in an undefined state if the Hashtable - * changes while the Enumeration is open. - * <p> - * - * Unlike HashMap, Hashtable does not accept `null' as a key value. Also, - * all accesses are synchronized: in a single thread environment, this is - * expensive, but in a multi-thread environment, this saves you the effort - * of extra synchronization. However, the old-style enumerators are not - * synchronized, because they can lead to unspecified behavior even if - * they were synchronized. You have been warned. - * <p> - * - * The iterators are <i>fail-fast</i>, meaning that any structural - * modification, except for <code>remove()</code> called on the iterator - * itself, cause the iterator to throw a - * <code>ConcurrentModificationException</code> rather than exhibit - * non-deterministic behavior. - * - * @author Jon Zeppieri - * @author Warren Levy - * @author Bryce McKinlay - * @author Eric Blake (ebb9@email.byu.edu) - * @see HashMap - * @see TreeMap - * @see IdentityHashMap - * @see LinkedHashMap - * @since 1.0 - * @status updated to 1.4 - */ -public class Hashtable extends Dictionary - implements Map, Cloneable, Serializable -{ - // WARNING: Hashtable is a CORE class in the bootstrap cycle. See the - // comments in vm/reference/java/lang/Runtime for implications of this fact. - - /** Default number of buckets. This is the value the JDK 1.3 uses. Some - * early documentation specified this value as 101. That is incorrect. - */ - private static final int DEFAULT_CAPACITY = 11; - - /** An "enum" of iterator types. */ - // Package visible for use by nested classes. - static final int KEYS = 0, - VALUES = 1, - ENTRIES = 2; - - /** - * The default load factor; this is explicitly specified by the spec. - */ - private static final float DEFAULT_LOAD_FACTOR = 0.75f; - - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = 1421746759512286392L; - - /** - * The rounded product of the capacity and the load factor; when the number - * of elements exceeds the threshold, the Hashtable calls - * <code>rehash()</code>. - * @serial - */ - private int threshold; - - /** - * Load factor of this Hashtable: used in computing the threshold. - * @serial - */ - private final float loadFactor; - - /** - * Array containing the actual key-value mappings. - */ - // Package visible for use by nested classes. - transient HashEntry[] buckets; - - /** - * Counts the number of modifications this Hashtable has undergone, used - * by Iterators to know when to throw ConcurrentModificationExceptions. - */ - // Package visible for use by nested classes. - transient int modCount; - - /** - * The size of this Hashtable: denotes the number of key-value pairs. - */ - // Package visible for use by nested classes. - transient int size; - - /** - * The cache for {@link #keySet()}. - */ - private transient Set keys; - - /** - * The cache for {@link #values()}. - */ - private transient Collection values; - - /** - * The cache for {@link #entrySet()}. - */ - private transient Set entries; - - /** - * Class to represent an entry in the hash table. Holds a single key-value - * pair. A Hashtable Entry is identical to a HashMap Entry, except that - * `null' is not allowed for keys and values. - */ - private static final class HashEntry extends AbstractMap.BasicMapEntry - { - /** The next entry in the linked list. */ - HashEntry next; - - /** - * Simple constructor. - * @param key the key, already guaranteed non-null - * @param value the value, already guaranteed non-null - */ - HashEntry(Object key, Object value) - { - super(key, value); - } - - /** - * Resets the value. - * @param newValue the new value - * @return the prior value - * @throws NullPointerException if <code>newVal</code> is null - */ - public Object setValue(Object newVal) - { - if (newVal == null) - throw new NullPointerException(); - return super.setValue(newVal); - } - } - - /** - * Construct a new Hashtable with the default capacity (11) and the default - * load factor (0.75). - */ - public Hashtable() - { - this(DEFAULT_CAPACITY, DEFAULT_LOAD_FACTOR); - } - - /** - * Construct a new Hashtable from the given Map, with initial capacity - * the greater of the size of <code>m</code> or the default of 11. - * <p> - * - * Every element in Map m will be put into this new Hashtable. - * - * @param m a Map whose key / value pairs will be put into - * the new Hashtable. <b>NOTE: key / value pairs - * are not cloned in this constructor.</b> - * @throws NullPointerException if m is null, or if m contains a mapping - * to or from `null'. - * @since 1.2 - */ - public Hashtable(Map m) - { - this(Math.max(m.size() * 2, DEFAULT_CAPACITY), DEFAULT_LOAD_FACTOR); - putAll(m); - } - - /** - * Construct a new Hashtable with a specific inital capacity and - * default load factor of 0.75. - * - * @param initialCapacity the initial capacity of this Hashtable (>= 0) - * @throws IllegalArgumentException if (initialCapacity < 0) - */ - public Hashtable(int initialCapacity) - { - this(initialCapacity, DEFAULT_LOAD_FACTOR); - } - - /** - * Construct a new Hashtable with a specific initial capacity and - * load factor. - * - * @param initialCapacity the initial capacity (>= 0) - * @param loadFactor the load factor (> 0, not NaN) - * @throws IllegalArgumentException if (initialCapacity < 0) || - * ! (loadFactor > 0.0) - */ - public Hashtable(int initialCapacity, float loadFactor) - { - if (initialCapacity < 0) - throw new IllegalArgumentException("Illegal Capacity: " - + initialCapacity); - if (! (loadFactor > 0)) // check for NaN too - throw new IllegalArgumentException("Illegal Load: " + loadFactor); - - if (initialCapacity == 0) - initialCapacity = 1; - buckets = new HashEntry[initialCapacity]; - this.loadFactor = loadFactor; - threshold = (int) (initialCapacity * loadFactor); - } - - /** - * Returns the number of key-value mappings currently in this hashtable. - * @return the size - */ - public synchronized int size() - { - return size; - } - - /** - * Returns true if there are no key-value mappings currently in this table. - * @return <code>size() == 0</code> - */ - public synchronized boolean isEmpty() - { - return size == 0; - } - - /** - * Return an enumeration of the keys of this table. There's no point - * in synchronizing this, as you have already been warned that the - * enumeration is not specified to be thread-safe. - * - * @return the keys - * @see #elements() - * @see #keySet() - */ - public Enumeration keys() - { - return new Enumerator(KEYS); - } - - /** - * Return an enumeration of the values of this table. There's no point - * in synchronizing this, as you have already been warned that the - * enumeration is not specified to be thread-safe. - * - * @return the values - * @see #keys() - * @see #values() - */ - public Enumeration elements() - { - return new Enumerator(VALUES); - } - - /** - * Returns true if this Hashtable contains a value <code>o</code>, - * such that <code>o.equals(value)</code>. This is the same as - * <code>containsValue()</code>, and is O(n). - * <p> - * - * @param value the value to search for in this Hashtable - * @return true if at least one key maps to the value - * @throws NullPointerException if <code>value</code> is null - * @see #containsValue(Object) - * @see #containsKey(Object) - */ - public synchronized boolean contains(Object value) - { - for (int i = buckets.length - 1; i >= 0; i--) - { - HashEntry e = buckets[i]; - while (e != null) - { - if (value.equals(e.value)) - return true; - e = e.next; - } - } - - // Must throw on null argument even if the table is empty - if (value == null) - throw new NullPointerException(); - - return false; - } - - /** - * Returns true if this Hashtable contains a value <code>o</code>, such that - * <code>o.equals(value)</code>. This is the new API for the old - * <code>contains()</code>. - * - * @param value the value to search for in this Hashtable - * @return true if at least one key maps to the value - * @see #contains(Object) - * @see #containsKey(Object) - * @throws NullPointerException if <code>value</code> is null - * @since 1.2 - */ - public boolean containsValue(Object value) - { - // Delegate to older method to make sure code overriding it continues - // to work. - return contains(value); - } - - /** - * Returns true if the supplied object <code>equals()</code> a key - * in this Hashtable. - * - * @param key the key to search for in this Hashtable - * @return true if the key is in the table - * @throws NullPointerException if key is null - * @see #containsValue(Object) - */ - public synchronized boolean containsKey(Object key) - { - int idx = hash(key); - HashEntry e = buckets[idx]; - while (e != null) - { - if (key.equals(e.key)) - return true; - e = e.next; - } - return false; - } - - /** - * Return the value in this Hashtable associated with the supplied key, - * or <code>null</code> if the key maps to nothing. - * - * @param key the key for which to fetch an associated value - * @return what the key maps to, if present - * @throws NullPointerException if key is null - * @see #put(Object, Object) - * @see #containsKey(Object) - */ - public synchronized Object get(Object key) - { - int idx = hash(key); - HashEntry e = buckets[idx]; - while (e != null) - { - if (key.equals(e.key)) - return e.value; - e = e.next; - } - return null; - } - - /** - * Puts the supplied value into the Map, mapped by the supplied key. - * Neither parameter may be null. The value may be retrieved by any - * object which <code>equals()</code> this key. - * - * @param key the key used to locate the value - * @param value the value to be stored in the table - * @return the prior mapping of the key, or null if there was none - * @throws NullPointerException if key or value is null - * @see #get(Object) - * @see Object#equals(Object) - */ - public synchronized Object put(Object key, Object value) - { - int idx = hash(key); - HashEntry e = buckets[idx]; - - // Check if value is null since it is not permitted. - if (value == null) - throw new NullPointerException(); - - while (e != null) - { - if (key.equals(e.key)) - { - // Bypass e.setValue, since we already know value is non-null. - Object r = e.value; - e.value = value; - return r; - } - else - { - e = e.next; - } - } - - // At this point, we know we need to add a new entry. - modCount++; - if (++size > threshold) - { - rehash(); - // Need a new hash value to suit the bigger table. - idx = hash(key); - } - - e = new HashEntry(key, value); - - e.next = buckets[idx]; - buckets[idx] = e; - - return null; - } - - /** - * Removes from the table and returns the value which is mapped by the - * supplied key. If the key maps to nothing, then the table remains - * unchanged, and <code>null</code> is returned. - * - * @param key the key used to locate the value to remove - * @return whatever the key mapped to, if present - */ - public synchronized Object remove(Object key) - { - int idx = hash(key); - HashEntry e = buckets[idx]; - HashEntry last = null; - - while (e != null) - { - if (key.equals(e.key)) - { - modCount++; - if (last == null) - buckets[idx] = e.next; - else - last.next = e.next; - size--; - return e.value; - } - last = e; - e = e.next; - } - return null; - } - - /** - * Copies all elements of the given map into this hashtable. However, no - * mapping can contain null as key or value. If this table already has - * a mapping for a key, the new mapping replaces the current one. - * - * @param m the map to be hashed into this - * @throws NullPointerException if m is null, or contains null keys or values - */ - public synchronized void putAll(Map m) - { - Iterator itr = m.entrySet().iterator(); - - while (itr.hasNext()) - { - Map.Entry e = (Map.Entry) itr.next(); - // Optimize in case the Entry is one of our own. - if (e instanceof AbstractMap.BasicMapEntry) - { - AbstractMap.BasicMapEntry entry = (AbstractMap.BasicMapEntry) e; - put(entry.key, entry.value); - } - else - { - put(e.getKey(), e.getValue()); - } - } - } - - /** - * Clears the hashtable so it has no keys. This is O(1). - */ - public synchronized void clear() - { - if (size > 0) - { - modCount++; - Arrays.fill(buckets, null); - size = 0; - } - } - - /** - * Returns a shallow clone of this Hashtable. The Map itself is cloned, - * but its contents are not. This is O(n). - * - * @return the clone - */ - public synchronized Object clone() - { - Hashtable copy = null; - try - { - copy = (Hashtable) super.clone(); - } - catch (CloneNotSupportedException x) - { - // This is impossible. - } - copy.buckets = new HashEntry[buckets.length]; - copy.putAllInternal(this); - // Clear the caches. - copy.keys = null; - copy.values = null; - copy.entries = null; - return copy; - } - - /** - * Converts this Hashtable to a String, surrounded by braces, and with - * key/value pairs listed with an equals sign between, separated by a - * comma and space. For example, <code>"{a=1, b=2}"</code>.<p> - * - * NOTE: if the <code>toString()</code> method of any key or value - * throws an exception, this will fail for the same reason. - * - * @return the string representation - */ - public synchronized String toString() - { - // Since we are already synchronized, and entrySet().iterator() - // would repeatedly re-lock/release the monitor, we directly use the - // unsynchronized HashIterator instead. - Iterator entries = new HashIterator(ENTRIES); - StringBuffer r = new StringBuffer("{"); - for (int pos = size; pos > 0; pos--) - { - r.append(entries.next()); - if (pos > 1) - r.append(", "); - } - r.append("}"); - return r.toString(); - } - - /** - * Returns a "set view" of this Hashtable's keys. The set is backed by - * the hashtable, so changes in one show up in the other. The set supports - * element removal, but not element addition. The set is properly - * synchronized on the original hashtable. Sun has not documented the - * proper interaction of null with this set, but has inconsistent behavior - * in the JDK. Therefore, in this implementation, contains, remove, - * containsAll, retainAll, removeAll, and equals just ignore a null key - * rather than throwing a {@link NullPointerException}. - * - * @return a set view of the keys - * @see #values() - * @see #entrySet() - * @since 1.2 - */ - public Set keySet() - { - if (keys == null) - { - // Create a synchronized AbstractSet with custom implementations of - // those methods that can be overridden easily and efficiently. - Set r = new AbstractSet() - { - public int size() - { - return size; - } - - public Iterator iterator() - { - return new HashIterator(KEYS); - } - - public void clear() - { - Hashtable.this.clear(); - } - - public boolean contains(Object o) - { - if (o == null) - return false; - return containsKey(o); - } - - public boolean remove(Object o) - { - return Hashtable.this.remove(o) != null; - } - }; - // We must specify the correct object to synchronize upon, hence the - // use of a non-public API - keys = new Collections.SynchronizedSet(this, r); - } - return keys; - } - - /** - * Returns a "collection view" (or "bag view") of this Hashtable's values. - * The collection is backed by the hashtable, so changes in one show up - * in the other. The collection supports element removal, but not element - * addition. The collection is properly synchronized on the original - * hashtable. Sun has not documented the proper interaction of null with - * this set, but has inconsistent behavior in the JDK. Therefore, in this - * implementation, contains, remove, containsAll, retainAll, removeAll, and - * equals just ignore a null value rather than throwing a - * {@link NullPointerException}. - * - * @return a bag view of the values - * @see #keySet() - * @see #entrySet() - * @since 1.2 - */ - public Collection values() - { - if (values == null) - { - // We don't bother overriding many of the optional methods, as doing so - // wouldn't provide any significant performance advantage. - Collection r = new AbstractCollection() - { - public int size() - { - return size; - } - - public Iterator iterator() - { - return new HashIterator(VALUES); - } - - public void clear() - { - Hashtable.this.clear(); - } - }; - // We must specify the correct object to synchronize upon, hence the - // use of a non-public API - values = new Collections.SynchronizedCollection(this, r); - } - return values; - } - - /** - * Returns a "set view" of this Hashtable's entries. The set is backed by - * the hashtable, so changes in one show up in the other. The set supports - * element removal, but not element addition. The set is properly - * synchronized on the original hashtable. Sun has not documented the - * proper interaction of null with this set, but has inconsistent behavior - * in the JDK. Therefore, in this implementation, contains, remove, - * containsAll, retainAll, removeAll, and equals just ignore a null entry, - * or an entry with a null key or value, rather than throwing a - * {@link NullPointerException}. However, calling entry.setValue(null) - * will fail. - * <p> - * - * Note that the iterators for all three views, from keySet(), entrySet(), - * and values(), traverse the hashtable in the same sequence. - * - * @return a set view of the entries - * @see #keySet() - * @see #values() - * @see Map.Entry - * @since 1.2 - */ - public Set entrySet() - { - if (entries == null) - { - // Create an AbstractSet with custom implementations of those methods - // that can be overridden easily and efficiently. - Set r = new AbstractSet() - { - public int size() - { - return size; - } - - public Iterator iterator() - { - return new HashIterator(ENTRIES); - } - - public void clear() - { - Hashtable.this.clear(); - } - - public boolean contains(Object o) - { - return getEntry(o) != null; - } - - public boolean remove(Object o) - { - HashEntry e = getEntry(o); - if (e != null) - { - Hashtable.this.remove(e.key); - return true; - } - return false; - } - }; - // We must specify the correct object to synchronize upon, hence the - // use of a non-public API - entries = new Collections.SynchronizedSet(this, r); - } - return entries; - } - - /** - * Returns true if this Hashtable equals the supplied Object <code>o</code>. - * As specified by Map, this is: - * <code> - * (o instanceof Map) && entrySet().equals(((Map) o).entrySet()); - * </code> - * - * @param o the object to compare to - * @return true if o is an equal map - * @since 1.2 - */ - public boolean equals(Object o) - { - // no need to synchronize, entrySet().equals() does that - if (o == this) - return true; - if (!(o instanceof Map)) - return false; - - return entrySet().equals(((Map) o).entrySet()); - } - - /** - * Returns the hashCode for this Hashtable. As specified by Map, this is - * the sum of the hashCodes of all of its Map.Entry objects - * - * @return the sum of the hashcodes of the entries - * @since 1.2 - */ - public synchronized int hashCode() - { - // Since we are already synchronized, and entrySet().iterator() - // would repeatedly re-lock/release the monitor, we directly use the - // unsynchronized HashIterator instead. - Iterator itr = new HashIterator(ENTRIES); - int hashcode = 0; - for (int pos = size; pos > 0; pos--) - hashcode += itr.next().hashCode(); - - return hashcode; - } - - /** - * Helper method that returns an index in the buckets array for `key' - * based on its hashCode(). - * - * @param key the key - * @return the bucket number - * @throws NullPointerException if key is null - */ - private int hash(Object key) - { - // Note: Inline Math.abs here, for less method overhead, and to avoid - // a bootstrap dependency, since Math relies on native methods. - int hash = key.hashCode() % buckets.length; - return hash < 0 ? -hash : hash; - } - - /** - * Helper method for entrySet(), which matches both key and value - * simultaneously. Ignores null, as mentioned in entrySet(). - * - * @param o the entry to match - * @return the matching entry, if found, or null - * @see #entrySet() - */ - // Package visible, for use in nested classes. - HashEntry getEntry(Object o) - { - if (! (o instanceof Map.Entry)) - return null; - Object key = ((Map.Entry) o).getKey(); - if (key == null) - return null; - - int idx = hash(key); - HashEntry e = buckets[idx]; - while (e != null) - { - if (o.equals(e)) - return e; - e = e.next; - } - return null; - } - - /** - * A simplified, more efficient internal implementation of putAll(). clone() - * should not call putAll or put, in order to be compatible with the JDK - * implementation with respect to subclasses. - * - * @param m the map to initialize this from - */ - void putAllInternal(Map m) - { - Iterator itr = m.entrySet().iterator(); - size = 0; - - while (itr.hasNext()) - { - size++; - Map.Entry e = (Map.Entry) itr.next(); - Object key = e.getKey(); - int idx = hash(key); - HashEntry he = new HashEntry(key, e.getValue()); - he.next = buckets[idx]; - buckets[idx] = he; - } - } - - /** - * Increases the size of the Hashtable and rehashes all keys to new array - * indices; this is called when the addition of a new value would cause - * size() > threshold. Note that the existing Entry objects are reused in - * the new hash table. - * <p> - * - * This is not specified, but the new size is twice the current size plus - * one; this number is not always prime, unfortunately. This implementation - * is not synchronized, as it is only invoked from synchronized methods. - */ - protected void rehash() - { - HashEntry[] oldBuckets = buckets; - - int newcapacity = (buckets.length * 2) + 1; - threshold = (int) (newcapacity * loadFactor); - buckets = new HashEntry[newcapacity]; - - for (int i = oldBuckets.length - 1; i >= 0; i--) - { - HashEntry e = oldBuckets[i]; - while (e != null) - { - int idx = hash(e.key); - HashEntry dest = buckets[idx]; - - if (dest != null) - { - while (dest.next != null) - dest = dest.next; - dest.next = e; - } - else - { - buckets[idx] = e; - } - - HashEntry next = e.next; - e.next = null; - e = next; - } - } - } - - /** - * Serializes this object to the given stream. - * - * @param s the stream to write to - * @throws IOException if the underlying stream fails - * @serialData the <i>capacity</i> (int) that is the length of the - * bucket array, the <i>size</i> (int) of the hash map - * are emitted first. They are followed by size entries, - * each consisting of a key (Object) and a value (Object). - */ - private synchronized void writeObject(ObjectOutputStream s) - throws IOException - { - // Write the threshold and loadFactor fields. - s.defaultWriteObject(); - - s.writeInt(buckets.length); - s.writeInt(size); - // Since we are already synchronized, and entrySet().iterator() - // would repeatedly re-lock/release the monitor, we directly use the - // unsynchronized HashIterator instead. - Iterator it = new HashIterator(ENTRIES); - while (it.hasNext()) - { - HashEntry entry = (HashEntry) it.next(); - s.writeObject(entry.key); - s.writeObject(entry.value); - } - } - - /** - * Deserializes this object from the given stream. - * - * @param s the stream to read from - * @throws ClassNotFoundException if the underlying stream fails - * @throws IOException if the underlying stream fails - * @serialData the <i>capacity</i> (int) that is the length of the - * bucket array, the <i>size</i> (int) of the hash map - * are emitted first. They are followed by size entries, - * each consisting of a key (Object) and a value (Object). - */ - private void readObject(ObjectInputStream s) - throws IOException, ClassNotFoundException - { - // Read the threshold and loadFactor fields. - s.defaultReadObject(); - - // Read and use capacity. - buckets = new HashEntry[s.readInt()]; - int len = s.readInt(); - - // Read and use key/value pairs. - // TODO: should we be defensive programmers, and check for illegal nulls? - while (--len >= 0) - put(s.readObject(), s.readObject()); - } - - /** - * A class which implements the Iterator interface and is used for - * iterating over Hashtables. - * This implementation is parameterized to give a sequential view of - * keys, values, or entries; it also allows the removal of elements, - * as per the Javasoft spec. Note that it is not synchronized; this is - * a performance enhancer since it is never exposed externally and is - * only used within synchronized blocks above. - * - * @author Jon Zeppieri - */ - private final class HashIterator implements Iterator - { - /** - * The type of this Iterator: {@link #KEYS}, {@link #VALUES}, - * or {@link #ENTRIES}. - */ - final int type; - /** - * The number of modifications to the backing Hashtable that we know about. - */ - int knownMod = modCount; - /** The number of elements remaining to be returned by next(). */ - int count = size; - /** Current index in the physical hash table. */ - int idx = buckets.length; - /** The last Entry returned by a next() call. */ - HashEntry last; - /** - * The next entry that should be returned by next(). It is set to something - * if we're iterating through a bucket that contains multiple linked - * entries. It is null if next() needs to find a new bucket. - */ - HashEntry next; - - /** - * Construct a new HashIterator with the supplied type. - * @param type {@link #KEYS}, {@link #VALUES}, or {@link #ENTRIES} - */ - HashIterator(int type) - { - this.type = type; - } - - /** - * Returns true if the Iterator has more elements. - * @return true if there are more elements - * @throws ConcurrentModificationException if the hashtable was modified - */ - public boolean hasNext() - { - if (knownMod != modCount) - throw new ConcurrentModificationException(); - return count > 0; - } - - /** - * Returns the next element in the Iterator's sequential view. - * @return the next element - * @throws ConcurrentModificationException if the hashtable was modified - * @throws NoSuchElementException if there is none - */ - public Object next() - { - if (knownMod != modCount) - throw new ConcurrentModificationException(); - if (count == 0) - throw new NoSuchElementException(); - count--; - HashEntry e = next; - - while (e == null) - e = buckets[--idx]; - - next = e.next; - last = e; - if (type == VALUES) - return e.value; - if (type == KEYS) - return e.key; - return e; - } - - /** - * Removes from the backing Hashtable the last element which was fetched - * with the <code>next()</code> method. - * @throws ConcurrentModificationException if the hashtable was modified - * @throws IllegalStateException if called when there is no last element - */ - public void remove() - { - if (knownMod != modCount) - throw new ConcurrentModificationException(); - if (last == null) - throw new IllegalStateException(); - - Hashtable.this.remove(last.key); - last = null; - knownMod++; - } - } // class HashIterator - - - /** - * Enumeration view of this Hashtable, providing sequential access to its - * elements; this implementation is parameterized to provide access either - * to the keys or to the values in the Hashtable. - * - * <b>NOTE</b>: Enumeration is not safe if new elements are put in the table - * as this could cause a rehash and we'd completely lose our place. Even - * without a rehash, it is undetermined if a new element added would - * appear in the enumeration. The spec says nothing about this, but - * the "Java Class Libraries" book infers that modifications to the - * hashtable during enumeration causes indeterminate results. Don't do it! - * - * @author Jon Zeppieri - */ - private final class Enumerator implements Enumeration - { - /** - * The type of this Iterator: {@link #KEYS} or {@link #VALUES}. - */ - final int type; - /** The number of elements remaining to be returned by next(). */ - int count = size; - /** Current index in the physical hash table. */ - int idx = buckets.length; - /** - * Entry which will be returned by the next nextElement() call. It is - * set if we are iterating through a bucket with multiple entries, or null - * if we must look in the next bucket. - */ - HashEntry next; - - /** - * Construct the enumeration. - * @param type either {@link #KEYS} or {@link #VALUES}. - */ - Enumerator(int type) - { - this.type = type; - } - - /** - * Checks whether more elements remain in the enumeration. - * @return true if nextElement() will not fail. - */ - public boolean hasMoreElements() - { - return count > 0; - } - - /** - * Returns the next element. - * @return the next element - * @throws NoSuchElementException if there is none. - */ - public Object nextElement() - { - if (count == 0) - throw new NoSuchElementException("Hashtable Enumerator"); - count--; - HashEntry e = next; - - while (e == null) - e = buckets[--idx]; - - next = e.next; - return type == VALUES ? e.value : e.key; - } - } // class Enumerator -} // class Hashtable diff --git a/libjava/java/util/IdentityHashMap.java b/libjava/java/util/IdentityHashMap.java deleted file mode 100644 index 6369fac691b..00000000000 --- a/libjava/java/util/IdentityHashMap.java +++ /dev/null @@ -1,935 +0,0 @@ -/* IdentityHashMap.java -- a class providing a hashtable data structure, - mapping Object --> Object, which uses object identity for hashing. - Copyright (C) 2001, 2002, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.util; - -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; - -/** - * This class provides a hashtable-backed implementation of the - * Map interface, but uses object identity to do its hashing. In fact, - * it uses object identity for comparing values, as well. It uses a - * linear-probe hash table, which may have faster performance - * than the chaining employed by HashMap. - * <p> - * - * <em>WARNING: This is not a general purpose map. Because it uses - * System.identityHashCode and ==, instead of hashCode and equals, for - * comparison, it violated Map's general contract, and may cause - * undefined behavior when compared to other maps which are not - * IdentityHashMaps. This is designed only for the rare cases when - * identity semantics are needed.</em> An example use is - * topology-preserving graph transformations, such as deep cloning, - * or as proxy object mapping such as in debugging. - * <p> - * - * This map permits <code>null</code> keys and values, and does not - * guarantee that elements will stay in the same order over time. The - * basic operations (<code>get</code> and <code>put</code>) take - * constant time, provided System.identityHashCode is decent. You can - * tune the behavior by specifying the expected maximum size. As more - * elements are added, the map may need to allocate a larger table, - * which can be expensive. - * <p> - * - * This implementation is unsynchronized. If you want multi-thread - * access to be consistent, you must synchronize it, perhaps by using - * <code>Collections.synchronizedMap(new IdentityHashMap(...));</code>. - * The iterators are <i>fail-fast</i>, meaning that a structural modification - * made to the map outside of an iterator's remove method cause the - * iterator, and in the case of the entrySet, the Map.Entry, to - * fail with a {@link ConcurrentModificationException}. - * - * @author Tom Tromey (tromey@redhat.com) - * @author Eric Blake (ebb9@email.byu.edu) - * @see System#identityHashCode(Object) - * @see Collection - * @see Map - * @see HashMap - * @see TreeMap - * @see LinkedHashMap - * @see WeakHashMap - * @since 1.4 - * @status updated to 1.4 - */ -public class IdentityHashMap extends AbstractMap - implements Map, Serializable, Cloneable -{ - /** The default capacity. */ - private static final int DEFAULT_CAPACITY = 21; - - /** - * This object is used to mark deleted items. Package visible for use by - * nested classes. - */ - static final Object tombstone = new Object(); - - /** - * This object is used to mark empty slots. We need this because - * using null is ambiguous. Package visible for use by nested classes. - */ - static final Object emptyslot = new Object(); - - /** - * Compatible with JDK 1.4. - */ - private static final long serialVersionUID = 8188218128353913216L; - - /** - * The number of mappings in the table. Package visible for use by nested - * classes. - * @serial - */ - int size; - - /** - * The table itself. Package visible for use by nested classes. - */ - transient Object[] table; - - /** - * The number of structural modifications made so far. Package visible for - * use by nested classes. - */ - transient int modCount; - - /** - * The cache for {@link #entrySet()}. - */ - private transient Set entries; - - /** - * The threshold for rehashing, which is 75% of (table.length / 2). - */ - private transient int threshold; - - /** - * Create a new IdentityHashMap with the default capacity (21 entries). - */ - public IdentityHashMap() - { - this(DEFAULT_CAPACITY); - } - - /** - * Create a new IdentityHashMap with the indicated number of - * entries. If the number of elements added to this hash map - * exceeds this maximum, the map will grow itself; however, that - * incurs a performance penalty. - * - * @param max initial size - * @throws IllegalArgumentException if max is negative - */ - public IdentityHashMap(int max) - { - if (max < 0) - throw new IllegalArgumentException(); - // Need at least two slots, or hash() will break. - if (max < 2) - max = 2; - table = new Object[max << 1]; - Arrays.fill(table, emptyslot); - threshold = (max >> 2) * 3; - } - - /** - * Create a new IdentityHashMap whose contents are taken from the - * given Map. - * - * @param m The map whose elements are to be put in this map - * @throws NullPointerException if m is null - */ - public IdentityHashMap(Map m) - { - this(Math.max(m.size() << 1, DEFAULT_CAPACITY)); - putAll(m); - } - - /** - * Remove all mappings from this map. - */ - public void clear() - { - if (size != 0) - { - modCount++; - Arrays.fill(table, emptyslot); - size = 0; - } - } - - /** - * Creates a shallow copy where keys and values are not cloned. - */ - public Object clone() - { - try - { - IdentityHashMap copy = (IdentityHashMap) super.clone(); - copy.table = (Object[]) table.clone(); - copy.entries = null; // invalidate the cache - return copy; - } - catch (CloneNotSupportedException e) - { - // Can't happen. - return null; - } - } - - /** - * Tests whether the specified key is in this map. Unlike normal Maps, - * this test uses <code>entry == key</code> instead of - * <code>entry == null ? key == null : entry.equals(key)</code>. - * - * @param key the key to look for - * @return true if the key is contained in the map - * @see #containsValue(Object) - * @see #get(Object) - */ - public boolean containsKey(Object key) - { - return key == table[hash(key)]; - } - - /** - * Returns true if this HashMap contains the value. Unlike normal maps, - * this test uses <code>entry == value</code> instead of - * <code>entry == null ? value == null : entry.equals(value)</code>. - * - * @param value the value to search for in this HashMap - * @return true if at least one key maps to the value - * @see #containsKey(Object) - */ - public boolean containsValue(Object value) - { - for (int i = table.length - 1; i > 0; i -= 2) - if (table[i] == value) - return true; - return false; - } - - /** - * Returns a "set view" of this Map's entries. The set is backed by - * the Map, so changes in one show up in the other. The set supports - * element removal, but not element addition. - * <p> - * - * <em>The semantics of this set, and of its contained entries, are - * different from the contract of Set and Map.Entry in order to make - * IdentityHashMap work. This means that while you can compare these - * objects between IdentityHashMaps, comparing them with regular sets - * or entries is likely to have undefined behavior.</em> The entries - * in this set are reference-based, rather than the normal object - * equality. Therefore, <code>e1.equals(e2)</code> returns - * <code>e1.getKey() == e2.getKey() && e1.getValue() == e2.getValue()</code>, - * and <code>e.hashCode()</code> returns - * <code>System.identityHashCode(e.getKey()) ^ - * System.identityHashCode(e.getValue())</code>. - * <p> - * - * Note that the iterators for all three views, from keySet(), entrySet(), - * and values(), traverse the Map in the same sequence. - * - * @return a set view of the entries - * @see #keySet() - * @see #values() - * @see Map.Entry - */ - public Set entrySet() - { - if (entries == null) - entries = new AbstractSet() - { - public int size() - { - return size; - } - - public Iterator iterator() - { - return new IdentityIterator(ENTRIES); - } - - public void clear() - { - IdentityHashMap.this.clear(); - } - - public boolean contains(Object o) - { - if (! (o instanceof Map.Entry)) - return false; - Map.Entry m = (Map.Entry) o; - return m.getValue() == table[hash(m.getKey()) + 1]; - } - - public int hashCode() - { - return IdentityHashMap.this.hashCode(); - } - - public boolean remove(Object o) - { - if (! (o instanceof Map.Entry)) - return false; - Object key = ((Map.Entry) o).getKey(); - int h = hash(key); - if (table[h] == key) - { - size--; - modCount++; - table[h] = tombstone; - table[h + 1] = tombstone; - return true; - } - return false; - } - }; - return entries; - } - - /** - * Compares two maps for equality. This returns true only if both maps - * have the same reference-identity comparisons. While this returns - * <code>this.entrySet().equals(m.entrySet())</code> as specified by Map, - * this will not work with normal maps, since the entry set compares - * with == instead of .equals. - * - * @param o the object to compare to - * @return true if it is equal - */ - public boolean equals(Object o) - { - // Why did Sun specify this one? The superclass does the right thing. - return super.equals(o); - } - - /** - * Return the value in this Map associated with the supplied key, or - * <code>null</code> if the key maps to nothing. - * - * <p>NOTE: Since the value could also be null, you must use - * containsKey to see if this key actually maps to something. - * Unlike normal maps, this tests for the key with <code>entry == - * key</code> instead of <code>entry == null ? key == null : - * entry.equals(key)</code>. - * - * @param key the key for which to fetch an associated value - * @return what the key maps to, if present - * @see #put(Object, Object) - * @see #containsKey(Object) - */ - public Object get(Object key) - { - int h = hash(key); - return table[h] == key ? table[h + 1] : null; - } - - /** - * Returns the hashcode of this map. This guarantees that two - * IdentityHashMaps that compare with equals() will have the same hash code, - * but may break with comparison to normal maps since it uses - * System.identityHashCode() instead of hashCode(). - * - * @return the hash code - */ - public int hashCode() - { - int hash = 0; - for (int i = table.length - 2; i >= 0; i -= 2) - { - Object key = table[i]; - if (key == emptyslot || key == tombstone) - continue; - hash += (System.identityHashCode(key) - ^ System.identityHashCode(table[i + 1])); - } - return hash; - } - - /** - * Returns true if there are no key-value mappings currently in this Map - * @return <code>size() == 0</code> - */ - public boolean isEmpty() - { - return size == 0; - } - - /** - * Returns a "set view" of this Map's keys. The set is backed by the - * Map, so changes in one show up in the other. The set supports - * element removal, but not element addition. - * <p> - * - * <em>The semantics of this set are different from the contract of Set - * in order to make IdentityHashMap work. This means that while you can - * compare these objects between IdentityHashMaps, comparing them with - * regular sets is likely to have undefined behavior.</em> The hashCode - * of the set is the sum of the identity hash codes, instead of the - * regular hashCodes, and equality is determined by reference instead - * of by the equals method. - * <p> - * - * @return a set view of the keys - * @see #values() - * @see #entrySet() - */ - public Set keySet() - { - if (keys == null) - keys = new AbstractSet() - { - public int size() - { - return size; - } - - public Iterator iterator() - { - return new IdentityIterator(KEYS); - } - - public void clear() - { - IdentityHashMap.this.clear(); - } - - public boolean contains(Object o) - { - return containsKey(o); - } - - public int hashCode() - { - int hash = 0; - for (int i = table.length - 2; i >= 0; i -= 2) - { - Object key = table[i]; - if (key == emptyslot || key == tombstone) - continue; - hash += System.identityHashCode(key); - } - return hash; - - } - - public boolean remove(Object o) - { - int h = hash(o); - if (table[h] == o) - { - size--; - modCount++; - table[h] = tombstone; - table[h + 1] = tombstone; - return true; - } - return false; - } - }; - return keys; - } - - /** - * Puts the supplied value into the Map, mapped by the supplied key. - * The value may be retrieved by any object which <code>equals()</code> - * this key. NOTE: Since the prior value could also be null, you must - * first use containsKey if you want to see if you are replacing the - * key's mapping. Unlike normal maps, this tests for the key - * with <code>entry == key</code> instead of - * <code>entry == null ? key == null : entry.equals(key)</code>. - * - * @param key the key used to locate the value - * @param value the value to be stored in the HashMap - * @return the prior mapping of the key, or null if there was none - * @see #get(Object) - */ - public Object put(Object key, Object value) - { - // Rehash if the load factor is too high. - if (size > threshold) - { - Object[] old = table; - // This isn't necessarily prime, but it is an odd number of key/value - // slots, which has a higher probability of fewer collisions. - table = new Object[(old.length * 2) + 2]; - Arrays.fill(table, emptyslot); - size = 0; - threshold = (table.length >>> 3) * 3; - - for (int i = old.length - 2; i >= 0; i -= 2) - { - Object oldkey = old[i]; - if (oldkey != tombstone && oldkey != emptyslot) - // Just use put. This isn't very efficient, but it is ok. - put(oldkey, old[i + 1]); - } - } - - int h = hash(key); - if (table[h] == key) - { - Object r = table[h + 1]; - table[h + 1] = value; - return r; - } - - // At this point, we add a new mapping. - modCount++; - size++; - table[h] = key; - table[h + 1] = value; - return null; - } - - /** - * Copies all of the mappings from the specified map to this. If a key - * is already in this map, its value is replaced. - * - * @param m the map to copy - * @throws NullPointerException if m is null - */ - public void putAll(Map m) - { - // Why did Sun specify this one? The superclass does the right thing. - super.putAll(m); - } - - /** - * Removes from the HashMap and returns the value which is mapped by - * the supplied key. If the key maps to nothing, then the HashMap - * remains unchanged, and <code>null</code> is returned. - * - * NOTE: Since the value could also be null, you must use - * containsKey to see if you are actually removing a mapping. - * Unlike normal maps, this tests for the key with <code>entry == - * key</code> instead of <code>entry == null ? key == null : - * entry.equals(key)</code>. - * - * @param key the key used to locate the value to remove - * @return whatever the key mapped to, if present - */ - public Object remove(Object key) - { - int h = hash(key); - if (table[h] == key) - { - modCount++; - size--; - Object r = table[h + 1]; - table[h] = tombstone; - table[h + 1] = tombstone; - return r; - } - return null; - } - - /** - * Returns the number of kay-value mappings currently in this Map - * @return the size - */ - public int size() - { - return size; - } - - /** - * Returns a "collection view" (or "bag view") of this Map's values. - * The collection is backed by the Map, so changes in one show up - * in the other. The collection supports element removal, but not element - * addition. - * <p> - * - * <em>The semantics of this set are different from the contract of - * Collection in order to make IdentityHashMap work. This means that - * while you can compare these objects between IdentityHashMaps, comparing - * them with regular sets is likely to have undefined behavior.</em> - * Likewise, contains and remove go by == instead of equals(). - * <p> - * - * @return a bag view of the values - * @see #keySet() - * @see #entrySet() - */ - public Collection values() - { - if (values == null) - values = new AbstractCollection() - { - public int size() - { - return size; - } - - public Iterator iterator() - { - return new IdentityIterator(VALUES); - } - - public void clear() - { - IdentityHashMap.this.clear(); - } - - public boolean remove(Object o) - { - for (int i = table.length - 1; i > 0; i -= 2) - if (table[i] == o) - { - modCount++; - table[i - 1] = tombstone; - table[i] = tombstone; - size--; - return true; - } - return false; - } - }; - return values; - } - - /** - * Helper method which computes the hash code, then traverses the table - * until it finds the key, or the spot where the key would go. - * - * @param key the key to check - * @return the index where the key belongs - * @see #IdentityHashMap(int) - * @see #put(Object, Object) - */ - // Package visible for use by nested classes. - int hash(Object key) - { - // Implementation note: it is feasible for the table to have no - // emptyslots, if it is full with entries and tombstones, so we must - // remember where we started. If we encounter the key or an emptyslot, - // we are done. If we encounter a tombstone, the key may still be in - // the array. If we don't encounter the key, we use the first emptyslot - // or tombstone we encountered as the location where the key would go. - // By requiring at least 2 key/value slots, and rehashing at 75% - // capacity, we guarantee that there will always be either an emptyslot - // or a tombstone somewhere in the table. - int h = Math.abs(System.identityHashCode(key) % (table.length >> 1)) << 1; - int del = -1; - int save = h; - - do - { - if (table[h] == key) - return h; - if (table[h] == emptyslot) - break; - if (table[h] == tombstone && del < 0) - del = h; - h -= 2; - if (h < 0) - h = table.length - 2; - } - while (h != save); - - return del < 0 ? h : del; - } - - /** - * This class allows parameterized iteration over IdentityHashMaps. Based - * on its construction, it returns the key or value of a mapping, or - * creates the appropriate Map.Entry object with the correct fail-fast - * semantics and identity comparisons. - * - * @author Tom Tromey (tromey@redhat.com) - * @author Eric Blake (ebb9@email.byu.edu) - */ - private class IdentityIterator implements Iterator - { - /** - * The type of this Iterator: {@link #KEYS}, {@link #VALUES}, - * or {@link #ENTRIES}. - */ - final int type; - /** The number of modifications to the backing Map that we know about. */ - int knownMod = modCount; - /** The number of elements remaining to be returned by next(). */ - int count = size; - /** Location in the table. */ - int loc = table.length; - - /** - * Construct a new Iterator with the supplied type. - * @param type {@link #KEYS}, {@link #VALUES}, or {@link #ENTRIES} - */ - IdentityIterator(int type) - { - this.type = type; - } - - /** - * Returns true if the Iterator has more elements. - * @return true if there are more elements - * @throws ConcurrentModificationException if the Map was modified - */ - public boolean hasNext() - { - if (knownMod != modCount) - throw new ConcurrentModificationException(); - return count > 0; - } - - /** - * Returns the next element in the Iterator's sequential view. - * @return the next element - * @throws ConcurrentModificationException if the Map was modified - * @throws NoSuchElementException if there is none - */ - public Object next() - { - if (knownMod != modCount) - throw new ConcurrentModificationException(); - if (count == 0) - throw new NoSuchElementException(); - count--; - - Object key; - do - { - loc -= 2; - key = table[loc]; - } - while (key == emptyslot || key == tombstone); - - return type == KEYS ? key : (type == VALUES ? table[loc + 1] - : new IdentityEntry(loc)); - } - - /** - * Removes from the backing Map the last element which was fetched - * with the <code>next()</code> method. - * - * @throws ConcurrentModificationException if the Map was modified - * @throws IllegalStateException if called when there is no last element - */ - public void remove() - { - if (knownMod != modCount) - throw new ConcurrentModificationException(); - if (loc == table.length || table[loc] == tombstone) - throw new IllegalStateException(); - modCount++; - size--; - table[loc] = tombstone; - table[loc + 1] = tombstone; - knownMod++; - } - } // class IdentityIterator - - /** - * This class provides Map.Entry objects for IdentityHashMaps. The entry - * is fail-fast, and will throw a ConcurrentModificationException if - * the underlying map is modified, or if remove is called on the iterator - * that generated this object. It is identity based, so it violates - * the general contract of Map.Entry, and is probably unsuitable for - * comparison to normal maps; but it works among other IdentityHashMaps. - * - * @author Eric Blake (ebb9@email.byu.edu) - */ - private final class IdentityEntry implements Map.Entry - { - /** The location of this entry. */ - final int loc; - /** The number of modifications to the backing Map that we know about. */ - final int knownMod = modCount; - - /** - * Constructs the Entry. - * - * @param loc the location of this entry in table - */ - IdentityEntry(int loc) - { - this.loc = loc; - } - - /** - * Compares the specified object with this entry, using identity - * semantics. Note that this can lead to undefined results with - * Entry objects created by normal maps. - * - * @param o the object to compare - * @return true if it is equal - * @throws ConcurrentModificationException if the entry was invalidated - * by modifying the Map or calling Iterator.remove() - */ - public boolean equals(Object o) - { - if (knownMod != modCount || table[loc] == tombstone) - throw new ConcurrentModificationException(); - if (! (o instanceof Map.Entry)) - return false; - Map.Entry e = (Map.Entry) o; - return table[loc] == e.getKey() && table[loc + 1] == e.getValue(); - } - - /** - * Returns the key of this entry. - * - * @return the key - * @throws ConcurrentModificationException if the entry was invalidated - * by modifying the Map or calling Iterator.remove() - */ - public Object getKey() - { - if (knownMod != modCount || table[loc] == tombstone) - throw new ConcurrentModificationException(); - return table[loc]; - } - - /** - * Returns the value of this entry. - * - * @return the value - * @throws ConcurrentModificationException if the entry was invalidated - * by modifying the Map or calling Iterator.remove() - */ - public Object getValue() - { - if (knownMod != modCount || table[loc] == tombstone) - throw new ConcurrentModificationException(); - return table[loc + 1]; - } - - /** - * Returns the hashcode of the entry, using identity semantics. - * Note that this can lead to undefined results with Entry objects - * created by normal maps. - * - * @return the hash code - * @throws ConcurrentModificationException if the entry was invalidated - * by modifying the Map or calling Iterator.remove() - */ - public int hashCode() - { - if (knownMod != modCount || table[loc] == tombstone) - throw new ConcurrentModificationException(); - return (System.identityHashCode(table[loc]) - ^ System.identityHashCode(table[loc + 1])); - } - - /** - * Replaces the value of this mapping, and returns the old value. - * - * @param value the new value - * @return the old value - * @throws ConcurrentModificationException if the entry was invalidated - * by modifying the Map or calling Iterator.remove() - */ - public Object setValue(Object value) - { - if (knownMod != modCount || table[loc] == tombstone) - throw new ConcurrentModificationException(); - Object r = table[loc + 1]; - table[loc + 1] = value; - return r; - } - - /** - * This provides a string representation of the entry. It is of the form - * "key=value", where string concatenation is used on key and value. - * - * @return the string representation - * @throws ConcurrentModificationException if the entry was invalidated - * by modifying the Map or calling Iterator.remove() - */ - public String toString() - { - if (knownMod != modCount || table[loc] == tombstone) - throw new ConcurrentModificationException(); - return table[loc] + "=" + table[loc + 1]; - } - } // class IdentityEntry - - /** - * Reads the object from a serial stream. - * - * @param s the stream to read from - * @throws ClassNotFoundException if the underlying stream fails - * @throws IOException if the underlying stream fails - * @serialData expects the size (int), followed by that many key (Object) - * and value (Object) pairs, with the pairs in no particular - * order - */ - private void readObject(ObjectInputStream s) - throws IOException, ClassNotFoundException - { - s.defaultReadObject(); - - int num = s.readInt(); - table = new Object[Math.max(num << 1, DEFAULT_CAPACITY) << 1]; - // Read key/value pairs. - while (--num >= 0) - put(s.readObject(), s.readObject()); - } - - /** - * Writes the object to a serial stream. - * - * @param s the stream to write to - * @throws IOException if the underlying stream fails - * @serialData outputs the size (int), followed by that many key (Object) - * and value (Object) pairs, with the pairs in no particular - * order - */ - private void writeObject(ObjectOutputStream s) - throws IOException - { - s.defaultWriteObject(); - s.writeInt(size); - for (int i = table.length - 2; i >= 0; i -= 2) - { - Object key = table[i]; - if (key != tombstone && key != emptyslot) - { - s.writeObject(key); - s.writeObject(table[i + 1]); - } - } - } -} diff --git a/libjava/java/util/Iterator.java b/libjava/java/util/Iterator.java deleted file mode 100644 index 31ecff8a257..00000000000 --- a/libjava/java/util/Iterator.java +++ /dev/null @@ -1,87 +0,0 @@ -/* Iterator.java -- Interface for iterating over collections - Copyright (C) 1998, 2001, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util; - -/** - * An object which iterates over a collection. An Iterator is used to return - * the items once only, in sequence, by successive calls to the next method. - * It is also possible to remove elements from the underlying collection by - * using the optional remove method. Iterator is intended as a replacement - * for the Enumeration interface of previous versions of Java, which did not - * have the remove method and had less conveniently named methods. - * - * @author Original author unknown - * @author Eric Blake (ebb9@email.byu.edu) - * @see Collection - * @see ListIterator - * @see Enumeration - * @since 1.2 - * @status updated to 1.4 - */ -public interface Iterator -{ - /** - * Tests whether there are elements remaining in the collection. In other - * words, calling <code>next()</code> will not throw an exception. - * - * @return true if there is at least one more element in the collection - */ - boolean hasNext(); - - /** - * Obtain the next element in the collection. - * - * @return the next element in the collection - * @throws NoSuchElementException if there are no more elements - */ - Object next(); - - /** - * Remove from the underlying collection the last element returned by next - * (optional operation). This method can be called only once after each - * call to <code>next()</code>. It does not affect what will be returned - * by subsequent calls to next. - * - * @throws IllegalStateException if next has not yet been called or remove - * has already been called since the last call to next. - * @throws UnsupportedOperationException if this Iterator does not support - * the remove operation. - */ - void remove(); -} diff --git a/libjava/java/util/LinkedHashMap.java b/libjava/java/util/LinkedHashMap.java deleted file mode 100644 index 8e895a9e0d8..00000000000 --- a/libjava/java/util/LinkedHashMap.java +++ /dev/null @@ -1,501 +0,0 @@ -/* LinkedHashMap.java -- a class providing hashtable data structure, - mapping Object --> Object, with linked list traversal - Copyright (C) 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util; - -/** - * This class provides a hashtable-backed implementation of the - * Map interface, with predictable traversal order. - * <p> - * - * It uses a hash-bucket approach; that is, hash collisions are handled - * by linking the new node off of the pre-existing node (or list of - * nodes). In this manner, techniques such as linear probing (which - * can cause primary clustering) and rehashing (which does not fit very - * well with Java's method of precomputing hash codes) are avoided. In - * addition, this maintains a doubly-linked list which tracks either - * insertion or access order. - * <p> - * - * In insertion order, calling <code>put</code> adds the key to the end of - * traversal, unless the key was already in the map; changing traversal order - * requires removing and reinserting a key. On the other hand, in access - * order, all calls to <code>put</code> and <code>get</code> cause the - * accessed key to move to the end of the traversal list. Note that any - * accesses to the map's contents via its collection views and iterators do - * not affect the map's traversal order, since the collection views do not - * call <code>put</code> or <code>get</code>. - * <p> - * - * One of the nice features of tracking insertion order is that you can - * copy a hashtable, and regardless of the implementation of the original, - * produce the same results when iterating over the copy. This is possible - * without needing the overhead of <code>TreeMap</code>. - * <p> - * - * When using this {@link #LinkedHashMap(int, float, boolean) constructor}, - * you can build an access-order mapping. This can be used to implement LRU - * caches, for example. By overriding {@link #removeEldestEntry(Map.Entry)}, - * you can also control the removal of the oldest entry, and thereby do - * things like keep the map at a fixed size. - * <p> - * - * Under ideal circumstances (no collisions), LinkedHashMap offers O(1) - * performance on most operations (<code>containsValue()</code> is, - * of course, O(n)). In the worst case (all keys map to the same - * hash code -- very unlikely), most operations are O(n). Traversal is - * faster than in HashMap (proportional to the map size, and not the space - * allocated for the map), but other operations may be slower because of the - * overhead of the maintaining the traversal order list. - * <p> - * - * LinkedHashMap accepts the null key and null values. It is not - * synchronized, so if you need multi-threaded access, consider using:<br> - * <code>Map m = Collections.synchronizedMap(new LinkedHashMap(...));</code> - * <p> - * - * The iterators are <i>fail-fast</i>, meaning that any structural - * modification, except for <code>remove()</code> called on the iterator - * itself, cause the iterator to throw a - * {@link ConcurrentModificationException} rather than exhibit - * non-deterministic behavior. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @see Object#hashCode() - * @see Collection - * @see Map - * @see HashMap - * @see TreeMap - * @see Hashtable - * @since 1.4 - * @status updated to 1.4 - */ -public class LinkedHashMap extends HashMap -{ - /** - * Compatible with JDK 1.4. - */ - private static final long serialVersionUID = 3801124242820219131L; - - /** - * The oldest Entry to begin iteration at. - */ - transient LinkedHashEntry root; - - /** - * The iteration order of this linked hash map: <code>true</code> for - * access-order, <code>false</code> for insertion-order. - * - * @serial true for access order traversal - */ - final boolean accessOrder; - - /** - * Class to represent an entry in the hash table. Holds a single key-value - * pair and the doubly-linked insertion order list. - */ - class LinkedHashEntry extends HashEntry - { - /** - * The predecessor in the iteration list. If this entry is the root - * (eldest), pred points to the newest entry. - */ - LinkedHashEntry pred; - - /** The successor in the iteration list, null if this is the newest. */ - LinkedHashEntry succ; - - /** - * Simple constructor. - * - * @param key the key - * @param value the value - */ - LinkedHashEntry(Object key, Object value) - { - super(key, value); - if (root == null) - { - root = this; - pred = this; - } - else - { - pred = root.pred; - pred.succ = this; - root.pred = this; - } - } - - /** - * Called when this entry is accessed via put or get. This version does - * the necessary bookkeeping to keep the doubly-linked list in order, - * after moving this element to the newest position in access order. - */ - void access() - { - if (accessOrder && succ != null) - { - modCount++; - if (this == root) - { - root = succ; - pred.succ = this; - succ = null; - } - else - { - pred.succ = succ; - succ.pred = pred; - succ = null; - pred = root.pred; - pred.succ = this; - root.pred = this; - } - } - } - - /** - * Called when this entry is removed from the map. This version does - * the necessary bookkeeping to keep the doubly-linked list in order. - * - * @return the value of this key as it is removed - */ - Object cleanup() - { - if (this == root) - { - root = succ; - if (succ != null) - succ.pred = pred; - } - else if (succ == null) - { - pred.succ = null; - root.pred = pred; - } - else - { - pred.succ = succ; - succ.pred = pred; - } - return value; - } - } // class LinkedHashEntry - - /** - * Construct a new insertion-ordered LinkedHashMap with the default - * capacity (11) and the default load factor (0.75). - */ - public LinkedHashMap() - { - super(); - accessOrder = false; - } - - /** - * Construct a new insertion-ordered LinkedHashMap from the given Map, - * with initial capacity the greater of the size of <code>m</code> or - * the default of 11. - * <p> - * - * Every element in Map m will be put into this new HashMap, in the - * order of m's iterator. - * - * @param m a Map whose key / value pairs will be put into - * the new HashMap. <b>NOTE: key / value pairs - * are not cloned in this constructor.</b> - * @throws NullPointerException if m is null - */ - public LinkedHashMap(Map m) - { - super(m); - accessOrder = false; - } - - /** - * Construct a new insertion-ordered LinkedHashMap with a specific - * inital capacity and default load factor of 0.75. - * - * @param initialCapacity the initial capacity of this HashMap (>= 0) - * @throws IllegalArgumentException if (initialCapacity < 0) - */ - public LinkedHashMap(int initialCapacity) - { - super(initialCapacity); - accessOrder = false; - } - - /** - * Construct a new insertion-orderd LinkedHashMap with a specific - * inital capacity and load factor. - * - * @param initialCapacity the initial capacity (>= 0) - * @param loadFactor the load factor (> 0, not NaN) - * @throws IllegalArgumentException if (initialCapacity < 0) || - * ! (loadFactor > 0.0) - */ - public LinkedHashMap(int initialCapacity, float loadFactor) - { - super(initialCapacity, loadFactor); - accessOrder = false; - } - - /** - * Construct a new LinkedHashMap with a specific inital capacity, load - * factor, and ordering mode. - * - * @param initialCapacity the initial capacity (>=0) - * @param loadFactor the load factor (>0, not NaN) - * @param accessOrder true for access-order, false for insertion-order - * @throws IllegalArgumentException if (initialCapacity < 0) || - * ! (loadFactor > 0.0) - */ - public LinkedHashMap(int initialCapacity, float loadFactor, - boolean accessOrder) - { - super(initialCapacity, loadFactor); - this.accessOrder = accessOrder; - } - - /** - * Clears the Map so it has no keys. This is O(1). - */ - public void clear() - { - super.clear(); - root = null; - } - - /** - * Returns <code>true</code> if this HashMap contains a value - * <code>o</code>, such that <code>o.equals(value)</code>. - * - * @param value the value to search for in this HashMap - * @return <code>true</code> if at least one key maps to the value - */ - public boolean containsValue(Object value) - { - LinkedHashEntry e = root; - while (e != null) - { - if (equals(value, e.value)) - return true; - e = e.succ; - } - return false; - } - - /** - * Return the value in this Map associated with the supplied key, - * or <code>null</code> if the key maps to nothing. If this is an - * access-ordered Map and the key is found, this performs structural - * modification, moving the key to the newest end of the list. NOTE: - * Since the value could also be null, you must use containsKey to - * see if this key actually maps to something. - * - * @param key the key for which to fetch an associated value - * @return what the key maps to, if present - * @see #put(Object, Object) - * @see #containsKey(Object) - */ - public Object get(Object key) - { - int idx = hash(key); - HashEntry e = buckets[idx]; - while (e != null) - { - if (equals(key, e.key)) - { - e.access(); - return e.value; - } - e = e.next; - } - return null; - } - - /** - * Returns <code>true</code> if this map should remove the eldest entry. - * This method is invoked by all calls to <code>put</code> and - * <code>putAll</code> which place a new entry in the map, providing - * the implementer an opportunity to remove the eldest entry any time - * a new one is added. This can be used to save memory usage of the - * hashtable, as well as emulating a cache, by deleting stale entries. - * <p> - * - * For example, to keep the Map limited to 100 entries, override as follows: - * <pre> - * private static final int MAX_ENTRIES = 100; - * protected boolean removeEldestEntry(Map.Entry eldest) - * { - * return size() > MAX_ENTRIES; - * } - * </pre><p> - * - * Typically, this method does not modify the map, but just uses the - * return value as an indication to <code>put</code> whether to proceed. - * However, if you override it to modify the map, you must return false - * (indicating that <code>put</code> should leave the modified map alone), - * or you face unspecified behavior. Remember that in access-order mode, - * even calling <code>get</code> is a structural modification, but using - * the collections views (such as <code>keySet</code>) is not. - * <p> - * - * This method is called after the eldest entry has been inserted, so - * if <code>put</code> was called on a previously empty map, the eldest - * entry is the one you just put in! The default implementation just - * returns <code>false</code>, so that this map always behaves like - * a normal one with unbounded growth. - * - * @param eldest the eldest element which would be removed if this - * returns true. For an access-order map, this is the least - * recently accessed; for an insertion-order map, this is the - * earliest element inserted. - * @return true if <code>eldest</code> should be removed - */ - protected boolean removeEldestEntry(Map.Entry eldest) - { - return false; - } - - /** - * Helper method called by <code>put</code>, which creates and adds a - * new Entry, followed by performing bookkeeping (like removeEldestEntry). - * - * @param key the key of the new Entry - * @param value the value - * @param idx the index in buckets where the new Entry belongs - * @param callRemove whether to call the removeEldestEntry method - * @see #put(Object, Object) - * @see #removeEldestEntry(Map.Entry) - * @see LinkedHashEntry#LinkedHashEntry(Object, Object) - */ - void addEntry(Object key, Object value, int idx, boolean callRemove) - { - LinkedHashEntry e = new LinkedHashEntry(key, value); - e.next = buckets[idx]; - buckets[idx] = e; - if (callRemove && removeEldestEntry(root)) - remove(root.key); - } - - /** - * Helper method, called by clone() to reset the doubly-linked list. - * - * @param m the map to add entries from - * @see #clone() - */ - void putAllInternal(Map m) - { - root = null; - super.putAllInternal(m); - } - - /** - * Generates a parameterized iterator. This allows traversal to follow - * the doubly-linked list instead of the random bin order of HashMap. - * - * @param type {@link #KEYS}, {@link #VALUES}, or {@link #ENTRIES} - * @return the appropriate iterator - */ - Iterator iterator(final int type) - { - return new Iterator() - { - /** The current Entry. */ - LinkedHashEntry current = root; - - /** The previous Entry returned by next(). */ - LinkedHashEntry last; - - /** The number of known modifications to the backing Map. */ - int knownMod = modCount; - - /** - * Returns true if the Iterator has more elements. - * - * @return true if there are more elements - * @throws ConcurrentModificationException if the HashMap was modified - */ - public boolean hasNext() - { - if (knownMod != modCount) - throw new ConcurrentModificationException(); - return current != null; - } - - /** - * Returns the next element in the Iterator's sequential view. - * - * @return the next element - * @throws ConcurrentModificationException if the HashMap was modified - * @throws NoSuchElementException if there is none - */ - public Object next() - { - if (knownMod != modCount) - throw new ConcurrentModificationException(); - if (current == null) - throw new NoSuchElementException(); - last = current; - current = current.succ; - return type == VALUES ? last.value : type == KEYS ? last.key : last; - } - - /** - * Removes from the backing HashMap the last element which was fetched - * with the <code>next()</code> method. - * - * @throws ConcurrentModificationException if the HashMap was modified - * @throws IllegalStateException if called when there is no last element - */ - public void remove() - { - if (knownMod != modCount) - throw new ConcurrentModificationException(); - if (last == null) - throw new IllegalStateException(); - LinkedHashMap.this.remove(last.key); - last = null; - knownMod++; - } - }; - } -} // class LinkedHashMap diff --git a/libjava/java/util/LinkedHashSet.java b/libjava/java/util/LinkedHashSet.java deleted file mode 100644 index 6c68195c3bd..00000000000 --- a/libjava/java/util/LinkedHashSet.java +++ /dev/null @@ -1,160 +0,0 @@ -/* LinkedHashSet.java -- a set backed by a LinkedHashMap, for linked - list traversal. - Copyright (C) 2001, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util; - -import java.io.Serializable; - -/** - * This class provides a hashtable-backed implementation of the - * Set interface, with predictable traversal order. - * <p> - * - * It uses a hash-bucket approach; that is, hash collisions are handled - * by linking the new node off of the pre-existing node (or list of - * nodes). In this manner, techniques such as linear probing (which - * can cause primary clustering) and rehashing (which does not fit very - * well with Java's method of precomputing hash codes) are avoided. In - * addition, this maintains a doubly-linked list which tracks insertion - * order. Note that the insertion order is not modified if an - * <code>add</code> simply reinserts an element in the set. - * <p> - * - * One of the nice features of tracking insertion order is that you can - * copy a set, and regardless of the implementation of the original, - * produce the same results when iterating over the copy. This is possible - * without needing the overhead of <code>TreeSet</code>. - * <p> - * - * Under ideal circumstances (no collisions), LinkedHashSet offers O(1) - * performance on most operations. In the worst case (all elements map - * to the same hash code -- very unlikely), most operations are O(n). - * <p> - * - * LinkedHashSet accepts the null entry. It is not synchronized, so if - * you need multi-threaded access, consider using:<br> - * <code>Set s = Collections.synchronizedSet(new LinkedHashSet(...));</code> - * <p> - * - * The iterators are <i>fail-fast</i>, meaning that any structural - * modification, except for <code>remove()</code> called on the iterator - * itself, cause the iterator to throw a - * {@link ConcurrentModificationException} rather than exhibit - * non-deterministic behavior. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @see Object#hashCode() - * @see Collection - * @see Set - * @see HashSet - * @see TreeSet - * @see Collections#synchronizedSet(Set) - * @since 1.4 - * @status updated to 1.4 - */ -public class LinkedHashSet extends HashSet - implements Set, Cloneable, Serializable -{ - /** - * Compatible with JDK 1.4. - */ - private static final long serialVersionUID = -2851667679971038690L; - - /** - * Construct a new, empty HashSet whose backing HashMap has the default - * capacity (11) and loadFacor (0.75). - */ - public LinkedHashSet() - { - super(); - } - - /** - * Construct a new, empty HashSet whose backing HashMap has the supplied - * capacity and the default load factor (0.75). - * - * @param initialCapacity the initial capacity of the backing HashMap - * @throws IllegalArgumentException if the capacity is negative - */ - public LinkedHashSet(int initialCapacity) - { - super(initialCapacity); - } - - /** - * Construct a new, empty HashSet whose backing HashMap has the supplied - * capacity and load factor. - * - * @param initialCapacity the initial capacity of the backing HashMap - * @param loadFactor the load factor of the backing HashMap - * @throws IllegalArgumentException if either argument is negative, or - * if loadFactor is POSITIVE_INFINITY or NaN - */ - public LinkedHashSet(int initialCapacity, float loadFactor) - { - super(initialCapacity, loadFactor); - } - - /** - * Construct a new HashSet with the same elements as are in the supplied - * collection (eliminating any duplicates, of course). The backing storage - * has twice the size of the collection, or the default size of 11, - * whichever is greater; and the default load factor (0.75). - * - * @param c a collection of initial set elements - * @throws NullPointerException if c is null - */ - public LinkedHashSet(Collection c) - { - super(c); - } - - /** - * Helper method which initializes the backing Map. - * - * @param capacity the initial capacity - * @param load the initial load factor - * @return the backing HashMap - */ - HashMap init(int capacity, float load) - { - return new LinkedHashMap(capacity, load); - } - -} diff --git a/libjava/java/util/LinkedList.java b/libjava/java/util/LinkedList.java deleted file mode 100644 index f611050df1d..00000000000 --- a/libjava/java/util/LinkedList.java +++ /dev/null @@ -1,958 +0,0 @@ -/* LinkedList.java -- Linked list implementation of the List interface - Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; -import java.lang.reflect.Array; - -/** - * Linked list implementation of the List interface. In addition to the - * methods of the List interface, this class provides access to the first - * and last list elements in O(1) time for easy stack, queue, or double-ended - * queue (deque) creation. The list is doubly-linked, with traversal to a - * given index starting from the end closest to the element.<p> - * - * LinkedList is not synchronized, so if you need multi-threaded access, - * consider using:<br> - * <code>List l = Collections.synchronizedList(new LinkedList(...));</code> - * <p> - * - * The iterators are <i>fail-fast</i>, meaning that any structural - * modification, except for <code>remove()</code> called on the iterator - * itself, cause the iterator to throw a - * {@link ConcurrentModificationException} rather than exhibit - * non-deterministic behavior. - * - * @author Original author unknown - * @author Bryce McKinlay - * @author Eric Blake (ebb9@email.byu.edu) - * @see List - * @see ArrayList - * @see Vector - * @see Collections#synchronizedList(List) - * @since 1.2 - * @status missing javadoc, but complete to 1.4 - */ -public class LinkedList extends AbstractSequentialList - implements List, Cloneable, Serializable -{ - /** - * Compatible with JDK 1.2. - */ - private static final long serialVersionUID = 876323262645176354L; - - /** - * The first element in the list. - */ - transient Entry first; - - /** - * The last element in the list. - */ - transient Entry last; - - /** - * The current length of the list. - */ - transient int size = 0; - - /** - * Class to represent an entry in the list. Holds a single element. - */ - private static final class Entry - { - /** The element in the list. */ - Object data; - - /** The next list entry, null if this is last. */ - Entry next; - - /** The previous list entry, null if this is first. */ - Entry previous; - - /** - * Construct an entry. - * @param data the list element - */ - Entry(Object data) - { - this.data = data; - } - } // class Entry - - /** - * Obtain the Entry at a given position in a list. This method of course - * takes linear time, but it is intelligent enough to take the shorter of the - * paths to get to the Entry required. This implies that the first or last - * entry in the list is obtained in constant time, which is a very desirable - * property. - * For speed and flexibility, range checking is not done in this method: - * Incorrect values will be returned if (n < 0) or (n >= size). - * - * @param n the number of the entry to get - * @return the entry at position n - */ - // Package visible for use in nested classes. - Entry getEntry(int n) - { - Entry e; - if (n < size / 2) - { - e = first; - // n less than size/2, iterate from start - while (n-- > 0) - e = e.next; - } - else - { - e = last; - // n greater than size/2, iterate from end - while (++n < size) - e = e.previous; - } - return e; - } - - /** - * Remove an entry from the list. This will adjust size and deal with - * `first' and `last' appropriatly. - * - * @param e the entry to remove - */ - // Package visible for use in nested classes. - void removeEntry(Entry e) - { - modCount++; - size--; - if (size == 0) - first = last = null; - else - { - if (e == first) - { - first = e.next; - e.next.previous = null; - } - else if (e == last) - { - last = e.previous; - e.previous.next = null; - } - else - { - e.next.previous = e.previous; - e.previous.next = e.next; - } - } - } - - /** - * Checks that the index is in the range of possible elements (inclusive). - * - * @param index the index to check - * @throws IndexOutOfBoundsException if index < 0 || index > size - */ - private void checkBoundsInclusive(int index) - { - if (index < 0 || index > size) - throw new IndexOutOfBoundsException("Index: " + index + ", Size:" - + size); - } - - /** - * Checks that the index is in the range of existing elements (exclusive). - * - * @param index the index to check - * @throws IndexOutOfBoundsException if index < 0 || index >= size - */ - private void checkBoundsExclusive(int index) - { - if (index < 0 || index >= size) - throw new IndexOutOfBoundsException("Index: " + index + ", Size:" - + size); - } - - /** - * Create an empty linked list. - */ - public LinkedList() - { - } - - /** - * Create a linked list containing the elements, in order, of a given - * collection. - * - * @param c the collection to populate this list from - * @throws NullPointerException if c is null - */ - public LinkedList(Collection c) - { - addAll(c); - } - - /** - * Returns the first element in the list. - * - * @return the first list element - * @throws NoSuchElementException if the list is empty - */ - public Object getFirst() - { - if (size == 0) - throw new NoSuchElementException(); - return first.data; - } - - /** - * Returns the last element in the list. - * - * @return the last list element - * @throws NoSuchElementException if the list is empty - */ - public Object getLast() - { - if (size == 0) - throw new NoSuchElementException(); - return last.data; - } - - /** - * Remove and return the first element in the list. - * - * @return the former first element in the list - * @throws NoSuchElementException if the list is empty - */ - public Object removeFirst() - { - if (size == 0) - throw new NoSuchElementException(); - modCount++; - size--; - Object r = first.data; - - if (first.next != null) - first.next.previous = null; - else - last = null; - - first = first.next; - - return r; - } - - /** - * Remove and return the last element in the list. - * - * @return the former last element in the list - * @throws NoSuchElementException if the list is empty - */ - public Object removeLast() - { - if (size == 0) - throw new NoSuchElementException(); - modCount++; - size--; - Object r = last.data; - - if (last.previous != null) - last.previous.next = null; - else - first = null; - - last = last.previous; - - return r; - } - - /** - * Insert an element at the first of the list. - * - * @param o the element to insert - */ - public void addFirst(Object o) - { - Entry e = new Entry(o); - - modCount++; - if (size == 0) - first = last = e; - else - { - e.next = first; - first.previous = e; - first = e; - } - size++; - } - - /** - * Insert an element at the last of the list. - * - * @param o the element to insert - */ - public void addLast(Object o) - { - addLastEntry(new Entry(o)); - } - - /** - * Inserts an element at the end of the list. - * - * @param e the entry to add - */ - private void addLastEntry(Entry e) - { - modCount++; - if (size == 0) - first = last = e; - else - { - e.previous = last; - last.next = e; - last = e; - } - size++; - } - - /** - * Returns true if the list contains the given object. Comparison is done by - * <code>o == null ? e = null : o.equals(e)</code>. - * - * @param o the element to look for - * @return true if it is found - */ - public boolean contains(Object o) - { - Entry e = first; - while (e != null) - { - if (equals(o, e.data)) - return true; - e = e.next; - } - return false; - } - - /** - * Returns the size of the list. - * - * @return the list size - */ - public int size() - { - return size; - } - - /** - * Adds an element to the end of the list. - * - * @param e the entry to add - * @return true, as it always succeeds - */ - public boolean add(Object o) - { - addLastEntry(new Entry(o)); - return true; - } - - /** - * Removes the entry at the lowest index in the list that matches the given - * object, comparing by <code>o == null ? e = null : o.equals(e)</code>. - * - * @param o the object to remove - * @return true if an instance of the object was removed - */ - public boolean remove(Object o) - { - Entry e = first; - while (e != null) - { - if (equals(o, e.data)) - { - removeEntry(e); - return true; - } - e = e.next; - } - return false; - } - - /** - * Append the elements of the collection in iteration order to the end of - * this list. If this list is modified externally (for example, if this - * list is the collection), behavior is unspecified. - * - * @param c the collection to append - * @return true if the list was modified - * @throws NullPointerException if c is null - */ - public boolean addAll(Collection c) - { - return addAll(size, c); - } - - /** - * Insert the elements of the collection in iteration order at the given - * index of this list. If this list is modified externally (for example, - * if this list is the collection), behavior is unspecified. - * - * @param c the collection to append - * @return true if the list was modified - * @throws NullPointerException if c is null - * @throws IndexOutOfBoundsException if index < 0 || index > size() - */ - public boolean addAll(int index, Collection c) - { - checkBoundsInclusive(index); - int csize = c.size(); - - if (csize == 0) - return false; - - Iterator itr = c.iterator(); - - // Get the entries just before and after index. If index is at the start - // of the list, BEFORE is null. If index is at the end of the list, AFTER - // is null. If the list is empty, both are null. - Entry after = null; - Entry before = null; - if (index != size) - { - after = getEntry(index); - before = after.previous; - } - else - before = last; - - // Create the first new entry. We do not yet set the link from `before' - // to the first entry, in order to deal with the case where (c == this). - // [Actually, we don't have to handle this case to fufill the - // contract for addAll(), but Sun's implementation appears to.] - Entry e = new Entry(itr.next()); - e.previous = before; - Entry prev = e; - Entry firstNew = e; - - // Create and link all the remaining entries. - for (int pos = 1; pos < csize; pos++) - { - e = new Entry(itr.next()); - e.previous = prev; - prev.next = e; - prev = e; - } - - // Link the new chain of entries into the list. - modCount++; - size += csize; - prev.next = after; - if (after != null) - after.previous = e; - else - last = e; - - if (before != null) - before.next = firstNew; - else - first = firstNew; - return true; - } - - /** - * Remove all elements from this list. - */ - public void clear() - { - if (size > 0) - { - modCount++; - first = null; - last = null; - size = 0; - } - } - - /** - * Return the element at index. - * - * @param index the place to look - * @return the element at index - * @throws IndexOutOfBoundsException if index < 0 || index >= size() - */ - public Object get(int index) - { - checkBoundsExclusive(index); - return getEntry(index).data; - } - - /** - * Replace the element at the given location in the list. - * - * @param index which index to change - * @param o the new element - * @return the prior element - * @throws IndexOutOfBoundsException if index < 0 || index >= size() - */ - public Object set(int index, Object o) - { - checkBoundsExclusive(index); - Entry e = getEntry(index); - Object old = e.data; - e.data = o; - return old; - } - - /** - * Inserts an element in the given position in the list. - * - * @param index where to insert the element - * @param o the element to insert - * @throws IndexOutOfBoundsException if index < 0 || index > size() - */ - public void add(int index, Object o) - { - checkBoundsInclusive(index); - Entry e = new Entry(o); - - if (index < size) - { - modCount++; - Entry after = getEntry(index); - e.next = after; - e.previous = after.previous; - if (after.previous == null) - first = e; - else - after.previous.next = e; - after.previous = e; - size++; - } - else - addLastEntry(e); - } - - /** - * Removes the element at the given position from the list. - * - * @param index the location of the element to remove - * @return the removed element - * @throws IndexOutOfBoundsException if index < 0 || index > size() - */ - public Object remove(int index) - { - checkBoundsExclusive(index); - Entry e = getEntry(index); - removeEntry(e); - return e.data; - } - - /** - * Returns the first index where the element is located in the list, or -1. - * - * @param o the element to look for - * @return its position, or -1 if not found - */ - public int indexOf(Object o) - { - int index = 0; - Entry e = first; - while (e != null) - { - if (equals(o, e.data)) - return index; - index++; - e = e.next; - } - return -1; - } - - /** - * Returns the last index where the element is located in the list, or -1. - * - * @param o the element to look for - * @return its position, or -1 if not found - */ - public int lastIndexOf(Object o) - { - int index = size - 1; - Entry e = last; - while (e != null) - { - if (equals(o, e.data)) - return index; - index--; - e = e.previous; - } - return -1; - } - - /** - * Obtain a ListIterator over this list, starting at a given index. The - * ListIterator returned by this method supports the add, remove and set - * methods. - * - * @param index the index of the element to be returned by the first call to - * next(), or size() to be initially positioned at the end of the list - * @throws IndexOutOfBoundsException if index < 0 || index > size() - */ - public ListIterator listIterator(int index) - { - checkBoundsInclusive(index); - return new LinkedListItr(index); - } - - /** - * Create a shallow copy of this LinkedList (the elements are not cloned). - * - * @return an object of the same class as this object, containing the - * same elements in the same order - */ - public Object clone() - { - LinkedList copy = null; - try - { - copy = (LinkedList) super.clone(); - } - catch (CloneNotSupportedException ex) - { - } - copy.clear(); - copy.addAll(this); - return copy; - } - - /** - * Returns an array which contains the elements of the list in order. - * - * @return an array containing the list elements - */ - public Object[] toArray() - { - Object[] array = new Object[size]; - Entry e = first; - for (int i = 0; i < size; i++) - { - array[i] = e.data; - e = e.next; - } - return array; - } - - /** - * Returns an Array whose component type is the runtime component type of - * the passed-in Array. The returned Array is populated with all of the - * elements in this LinkedList. If the passed-in Array is not large enough - * to store all of the elements in this List, a new Array will be created - * and returned; if the passed-in Array is <i>larger</i> than the size - * of this List, then size() index will be set to null. - * - * @param a the passed-in Array - * @return an array representation of this list - * @throws ArrayStoreException if the runtime type of a does not allow - * an element in this list - * @throws NullPointerException if a is null - */ - public Object[] toArray(Object[] a) - { - if (a.length < size) - a = (Object[]) Array.newInstance(a.getClass().getComponentType(), size); - else if (a.length > size) - a[size] = null; - Entry e = first; - for (int i = 0; i < size; i++) - { - a[i] = e.data; - e = e.next; - } - return a; - } - - /** - * Serializes this object to the given stream. - * - * @param s the stream to write to - * @throws IOException if the underlying stream fails - * @serialData the size of the list (int), followed by all the elements - * (Object) in proper order - */ - private void writeObject(ObjectOutputStream s) throws IOException - { - s.defaultWriteObject(); - s.writeInt(size); - Entry e = first; - while (e != null) - { - s.writeObject(e.data); - e = e.next; - } - } - - /** - * Deserializes this object from the given stream. - * - * @param s the stream to read from - * @throws ClassNotFoundException if the underlying stream fails - * @throws IOException if the underlying stream fails - * @serialData the size of the list (int), followed by all the elements - * (Object) in proper order - */ - private void readObject(ObjectInputStream s) - throws IOException, ClassNotFoundException - { - s.defaultReadObject(); - int i = s.readInt(); - while (--i >= 0) - addLastEntry(new Entry(s.readObject())); - } - - /** - * A ListIterator over the list. This class keeps track of its - * position in the list and the two list entries it is between. - * - * @author Original author unknown - * @author Eric Blake (ebb9@email.byu.edu) - */ - private final class LinkedListItr implements ListIterator - { - /** Number of modifications we know about. */ - private int knownMod = modCount; - - /** Entry that will be returned by next(). */ - private Entry next; - - /** Entry that will be returned by previous(). */ - private Entry previous; - - /** Entry that will be affected by remove() or set(). */ - private Entry lastReturned; - - /** Index of `next'. */ - private int position; - - /** - * Initialize the iterator. - * - * @param index the initial index - */ - LinkedListItr(int index) - { - if (index == size) - { - next = null; - previous = last; - } - else - { - next = getEntry(index); - previous = next.previous; - } - position = index; - } - - /** - * Checks for iterator consistency. - * - * @throws ConcurrentModificationException if the list was modified - */ - private void checkMod() - { - if (knownMod != modCount) - throw new ConcurrentModificationException(); - } - - /** - * Returns the index of the next element. - * - * @return the next index - * @throws ConcurrentModificationException if the list was modified - */ - public int nextIndex() - { - checkMod(); - return position; - } - - /** - * Returns the index of the previous element. - * - * @return the previous index - * @throws ConcurrentModificationException if the list was modified - */ - public int previousIndex() - { - checkMod(); - return position - 1; - } - - /** - * Returns true if more elements exist via next. - * - * @return true if next will succeed - * @throws ConcurrentModificationException if the list was modified - */ - public boolean hasNext() - { - checkMod(); - return (next != null); - } - - /** - * Returns true if more elements exist via previous. - * - * @return true if previous will succeed - * @throws ConcurrentModificationException if the list was modified - */ - public boolean hasPrevious() - { - checkMod(); - return (previous != null); - } - - /** - * Returns the next element. - * - * @return the next element - * @throws ConcurrentModificationException if the list was modified - * @throws NoSuchElementException if there is no next - */ - public Object next() - { - checkMod(); - if (next == null) - throw new NoSuchElementException(); - position++; - lastReturned = previous = next; - next = lastReturned.next; - return lastReturned.data; - } - - /** - * Returns the previous element. - * - * @return the previous element - * @throws ConcurrentModificationException if the list was modified - * @throws NoSuchElementException if there is no previous - */ - public Object previous() - { - checkMod(); - if (previous == null) - throw new NoSuchElementException(); - position--; - lastReturned = next = previous; - previous = lastReturned.previous; - return lastReturned.data; - } - - /** - * Remove the most recently returned element from the list. - * - * @throws ConcurrentModificationException if the list was modified - * @throws IllegalStateException if there was no last element - */ - public void remove() - { - checkMod(); - if (lastReturned == null) - throw new IllegalStateException(); - - // Adjust the position to before the removed element, if the element - // being removed is behind the cursor. - if (lastReturned == previous) - position--; - - next = lastReturned.next; - previous = lastReturned.previous; - removeEntry(lastReturned); - knownMod++; - - lastReturned = null; - } - - /** - * Adds an element between the previous and next, and advance to the next. - * - * @param o the element to add - * @throws ConcurrentModificationException if the list was modified - */ - public void add(Object o) - { - checkMod(); - modCount++; - knownMod++; - size++; - position++; - Entry e = new Entry(o); - e.previous = previous; - e.next = next; - - if (previous != null) - previous.next = e; - else - first = e; - - if (next != null) - next.previous = e; - else - last = e; - - previous = e; - lastReturned = null; - } - - /** - * Changes the contents of the element most recently returned. - * - * @param o the new element - * @throws ConcurrentModificationException if the list was modified - * @throws IllegalStateException if there was no last element - */ - public void set(Object o) - { - checkMod(); - if (lastReturned == null) - throw new IllegalStateException(); - lastReturned.data = o; - } - } // class LinkedListItr -} diff --git a/libjava/java/util/List.java b/libjava/java/util/List.java deleted file mode 100644 index 445811292ac..00000000000 --- a/libjava/java/util/List.java +++ /dev/null @@ -1,451 +0,0 @@ -/* List.java -- An ordered collection which allows indexed access - Copyright (C) 1998, 2001, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util; - -/** - * An ordered collection (also known as a list). This collection allows - * access to elements by position, as well as control on where elements - * are inserted. Unlike sets, duplicate elements are permitted by this - * general contract (if a subclass forbids duplicates, this should be - * documented). - * <p> - * - * List places additional requirements on <code>iterator</code>, - * <code>add</code>, <code>remove</code>, <code>equals</code>, and - * <code>hashCode</code>, in addition to requiring more methods. List - * indexing is 0-based (like arrays), although some implementations may - * require time proportional to the index to obtain an arbitrary element. - * The List interface is incompatible with Set; you cannot implement both - * simultaneously. - * <p> - * - * Lists also provide a <code>ListIterator</code> which allows bidirectional - * traversal and other features atop regular iterators. Lists can be - * searched for arbitrary elements, and allow easy insertion and removal - * of multiple elements in one method call. - * <p> - * - * Note: While lists may contain themselves as elements, this leads to - * undefined (usually infinite recursive) behavior for some methods like - * hashCode or equals. - * - * @author Original author unknown - * @author Eric Blake (ebb9@email.byu.edu) - * @see Collection - * @see Set - * @see ArrayList - * @see LinkedList - * @see Vector - * @see Arrays#asList(Object[]) - * @see Collections#nCopies(int, Object) - * @see Collections#EMPTY_LIST - * @see AbstractList - * @see AbstractSequentialList - * @since 1.2 - * @status updated to 1.4 - */ -public interface List extends Collection -{ - /** - * Insert an element into the list at a given position (optional operation). - * This shifts all existing elements from that position to the end one - * index to the right. This version of add has no return, since it is - * assumed to always succeed if there is no exception. - * - * @param index the location to insert the item - * @param o the object to insert - * @throws UnsupportedOperationException if this list does not support the - * add operation - * @throws IndexOutOfBoundsException if index < 0 || index > size() - * @throws ClassCastException if o cannot be added to this list due to its - * type - * @throws IllegalArgumentException if o cannot be added to this list for - * some other reason - * @throws NullPointerException if o is null and this list doesn't support - * the addition of null values. - */ - void add(int index, Object o); - - /** - * Add an element to the end of the list (optional operation). If the list - * imposes restraints on what can be inserted, such as no null elements, - * this should be documented. - * - * @param o the object to add - * @return true, as defined by Collection for a modified list - * @throws UnsupportedOperationException if this list does not support the - * add operation - * @throws ClassCastException if o cannot be added to this list due to its - * type - * @throws IllegalArgumentException if o cannot be added to this list for - * some other reason - * @throws NullPointerException if o is null and this list doesn't support - * the addition of null values. - */ - boolean add(Object o); - - /** - * Insert the contents of a collection into the list at a given position - * (optional operation). Shift all elements at that position to the right - * by the number of elements inserted. This operation is undefined if - * this list is modified during the operation (for example, if you try - * to insert a list into itself). - * - * @param index the location to insert the collection - * @param c the collection to insert - * @return true if the list was modified by this action, that is, if c is - * non-empty - * @throws UnsupportedOperationException if this list does not support the - * addAll operation - * @throws IndexOutOfBoundsException if index < 0 || index > size() - * @throws ClassCastException if some element of c cannot be added to this - * list due to its type - * @throws IllegalArgumentException if some element of c cannot be added - * to this list for some other reason - * @throws NullPointerException if some element of c is null and this list - * doesn't support the addition of null values. - * @throws NullPointerException if the specified collection is null - * @see #add(int, Object) - */ - boolean addAll(int index, Collection c); - - /** - * Add the contents of a collection to the end of the list (optional - * operation). This operation is undefined if this list is modified - * during the operation (for example, if you try to insert a list into - * itself). - * - * @param c the collection to add - * @return true if the list was modified by this action, that is, if c is - * non-empty - * @throws UnsupportedOperationException if this list does not support the - * addAll operation - * @throws ClassCastException if some element of c cannot be added to this - * list due to its type - * @throws IllegalArgumentException if some element of c cannot be added - * to this list for some other reason - * @throws NullPointerException if the specified collection is null - * @throws NullPointerException if some element of c is null and this list - * doesn't support the addition of null values. - * @see #add(Object) - */ - boolean addAll(Collection c); - - /** - * Clear the list, such that a subsequent call to isEmpty() would return - * true (optional operation). - * - * @throws UnsupportedOperationException if this list does not support the - * clear operation - */ - void clear(); - - /** - * Test whether this list contains a given object as one of its elements. - * This is defined as the existence of an element e such that - * <code>o == null ? e == null : o.equals(e)</code>. - * - * @param o the element to look for - * @return true if this list contains the element - * @throws ClassCastException if the type of o is not a valid type - * for this list. - * @throws NullPointerException if o is null and the list doesn't - * support null values. - */ - boolean contains(Object o); - - /** - * Test whether this list contains every element in a given collection. - * - * @param c the collection to test for - * @return true if for every element o in c, contains(o) would return true - * @throws NullPointerException if the collection is null - * @throws ClassCastException if the type of any element in c is not a valid - * type for this list. - * @throws NullPointerException if some element of c is null and this - * list does not support null values. - * @see #contains(Object) - */ - boolean containsAll(Collection c); - - /** - * Test whether this list is equal to another object. A List is defined to be - * equal to an object if and only if that object is also a List, and the two - * lists have the same sequence. Two lists l1 and l2 are equal if and only - * if <code>l1.size() == l2.size()</code>, and for every integer n between 0 - * and <code>l1.size() - 1</code> inclusive, <code>l1.get(n) == null ? - * l2.get(n) == null : l1.get(n).equals(l2.get(n))</code>. - * - * @param o the object to test for equality with this list - * @return true if o is equal to this list - * @see Object#equals(Object) - * @see #hashCode() - */ - boolean equals(Object o); - - /** - * Get the element at a given index in this list. - * - * @param index the index of the element to be returned - * @return the element at index index in this list - * @throws IndexOutOfBoundsException if index < 0 || index >= size() - */ - Object get(int index); - - /** - * Obtains a hash code for this list. In order to obey the general - * contract of the hashCode method of class Object, this value is - * calculated as follows: - * -<p><pre>hashCode = 1; -Iterator i = list.iterator(); -while (i.hasNext()) -{ - Object obj = i.next(); - hashCode = 31 * hashCode + (obj == null ? 0 : obj.hashCode()); -}</pre> - * - * <p>This ensures that the general contract of Object.hashCode() - * is adhered to. - * - * @return the hash code of this list - * @see Object#hashCode() - * @see #equals(Object) - */ - int hashCode(); - - /** - * Obtain the first index at which a given object is to be found in this - * list. - * - * @param o the object to search for - * @return the least integer n such that <code>o == null ? get(n) == null : - * o.equals(get(n))</code>, or -1 if there is no such index. - * @throws ClassCastException if the type of o is not a valid - * type for this list. - * @throws NullPointerException if o is null and this - * list does not support null values. - */ - int indexOf(Object o); - - /** - * Test whether this list is empty, that is, if size() == 0. - * - * @return true if this list contains no elements - */ - boolean isEmpty(); - - /** - * Obtain an Iterator over this list, whose sequence is the list order. - * - * @return an Iterator over the elements of this list, in order - */ - Iterator iterator(); - - /** - * Obtain the last index at which a given object is to be found in this - * list. - * - * @return the greatest integer n such that <code>o == null ? get(n) == null - * : o.equals(get(n))</code>, or -1 if there is no such index. - * @throws ClassCastException if the type of o is not a valid - * type for this list. - * @throws NullPointerException if o is null and this - * list does not support null values. - */ - int lastIndexOf(Object o); - - /** - * Obtain a ListIterator over this list, starting at the beginning. - * - * @return a ListIterator over the elements of this list, in order, starting - * at the beginning - */ - ListIterator listIterator(); - - /** - * Obtain a ListIterator over this list, starting at a given position. - * A first call to next() would return the same as get(index), and a - * first call to previous() would return the same as get(index - 1). - * - * @param index the position, between 0 and size() inclusive, to begin the - * iteration from - * @return a ListIterator over the elements of this list, in order, starting - * at index - * @throws IndexOutOfBoundsException if index < 0 || index > size() - */ - ListIterator listIterator(int index); - - /** - * Remove the element at a given position in this list (optional operation). - * Shifts all remaining elements to the left to fill the gap. - * - * @param index the position within the list of the object to remove - * @return the object that was removed - * @throws UnsupportedOperationException if this list does not support the - * remove operation - * @throws IndexOutOfBoundsException if index < 0 || index >= size() - */ - Object remove(int index); - - /** - * Remove the first occurence of an object from this list (optional - * operation). That is, remove the first element e such that - * <code>o == null ? e == null : o.equals(e)</code>. - * - * @param o the object to remove - * @return true if the list changed as a result of this call, that is, if - * the list contained at least one occurrence of o - * @throws UnsupportedOperationException if this list does not support the - * remove operation - * @throws ClassCastException if the type of o is not a valid - * type for this list. - * @throws NullPointerException if o is null and this - * list does not support removing null values. - */ - boolean remove(Object o); - - /** - * Remove all elements of a given collection from this list (optional - * operation). That is, remove every element e such that c.contains(e). - * - * @param c the collection to filter out - * @return true if this list was modified as a result of this call - * @throws UnsupportedOperationException if this list does not support the - * removeAll operation - * @throws NullPointerException if the collection is null - * @throws ClassCastException if the type of any element in c is not a valid - * type for this list. - * @throws NullPointerException if some element of c is null and this - * list does not support removing null values. - * @see #remove(Object) - * @see #contains(Object) - */ - boolean removeAll(Collection c); - - /** - * Remove all elements of this list that are not contained in a given - * collection (optional operation). That is, remove every element e such - * that !c.contains(e). - * - * @param c the collection to retain - * @return true if this list was modified as a result of this call - * @throws UnsupportedOperationException if this list does not support the - * retainAll operation - * @throws NullPointerException if the collection is null - * @throws ClassCastException if the type of any element in c is not a valid - * type for this list. - * @throws NullPointerException if some element of c is null and this - * list does not support retaining null values. - * @see #remove(Object) - * @see #contains(Object) - */ - boolean retainAll(Collection c); - - /** - * Replace an element of this list with another object (optional operation). - * - * @param index the position within this list of the element to be replaced - * @param o the object to replace it with - * @return the object that was replaced - * @throws UnsupportedOperationException if this list does not support the - * set operation - * @throws IndexOutOfBoundsException if index < 0 || index >= size() - * @throws ClassCastException if o cannot be added to this list due to its - * type - * @throws IllegalArgumentException if o cannot be added to this list for - * some other reason - * @throws NullPointerException if o is null and this - * list does not support null values. - */ - Object set(int index, Object o); - - /** - * Get the number of elements in this list. If the list contains more - * than Integer.MAX_VALUE elements, return Integer.MAX_VALUE. - * - * @return the number of elements in the list - */ - int size(); - - /** - * Obtain a List view of a subsection of this list, from fromIndex - * (inclusive) to toIndex (exclusive). If the two indices are equal, the - * sublist is empty. The returned list should be modifiable if and only - * if this list is modifiable. Changes to the returned list should be - * reflected in this list. If this list is structurally modified in - * any way other than through the returned list, the result of any subsequent - * operations on the returned list is undefined. - * - * @param fromIndex the index that the returned list should start from - * (inclusive) - * @param toIndex the index that the returned list should go to (exclusive) - * @return a List backed by a subsection of this list - * @throws IndexOutOfBoundsException if fromIndex < 0 - * || toIndex > size() || fromIndex > toIndex - */ - List subList(int fromIndex, int toIndex); - - /** - * Copy the current contents of this list into an array. - * - * @return an array of type Object[] and length equal to the length of this - * list, containing the elements currently in this list, in order - */ - Object[] toArray(); - - /** - * Copy the current contents of this list into an array. If the array passed - * as an argument has length less than that of this list, an array of the - * same run-time type as a, and length equal to the length of this list, is - * allocated using Reflection. Otherwise, a itself is used. The elements of - * this list are copied into it, and if there is space in the array, the - * following element is set to null. The resultant array is returned. - * Note: The fact that the following element is set to null is only useful - * if it is known that this list does not contain any null elements. - * - * @param a the array to copy this list into - * @return an array containing the elements currently in this list, in - * order - * @throws ArrayStoreException if the type of any element of the - * collection is not a subtype of the element type of a - * @throws NullPointerException if the specified array is null - */ - Object[] toArray(Object[] a); -} diff --git a/libjava/java/util/ListIterator.java b/libjava/java/util/ListIterator.java deleted file mode 100644 index 5e17108c991..00000000000 --- a/libjava/java/util/ListIterator.java +++ /dev/null @@ -1,170 +0,0 @@ -/* ListIterator.java -- Extended Iterator for iterating over ordered lists - Copyright (C) 1998, 1999, 2001, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util; - -/** - * An extended version of Iterator to support the extra features of Lists. The - * elements may be accessed in forward or reverse order, elements may be - * replaced as well as removed, and new elements may be inserted, during the - * traversal of the list. - * <p> - * - * A list with n elements provides n+1 iterator positions (the front, the end, - * or between two elements). Note that <code>remove</code> and <code>set</code> - * operate on the last element returned, whether it was by <code>next</code> - * or <code>previous</code>. - * - * @author Original author unknown - * @author Eric Blake (ebb9@email.byu.edu) - * @see Collection - * @see List - * @see Iterator - * @see Enumeration - * @since 1.2 - * @status updated to 1.4 - */ -public interface ListIterator extends Iterator -{ - /** - * Tests whether there are elements remaining in the list in the forward - * direction. In other words, next() will not fail with a - * NoSuchElementException. - * - * @return true if the list continues in the forward direction - */ - boolean hasNext(); - - /** - * Tests whether there are elements remaining in the list in the reverse - * direction. In other words, previous() will not fail with a - * NoSuchElementException. - * - * @return true if the list continues in the reverse direction - */ - boolean hasPrevious(); - - /** - * Obtain the next element in the list in the forward direction. Repeated - * calls to next may be used to iterate over the entire list, or calls to - * next and previous may be used together to go forwards and backwards. - * Alternating calls to next and previous will return the same element. - * - * @return the next element in the list in the forward direction - * @throws NoSuchElementException if there are no more elements - */ - Object next(); - - /** - * Obtain the next element in the list in the reverse direction. Repeated - * calls to previous may be used to iterate backwards over the entire list, - * or calls to next and previous may be used together to go forwards and - * backwards. Alternating calls to next and previous will return the same - * element. - * - * @return the next element in the list in the reverse direction - * @throws NoSuchElementException if there are no more elements - */ - Object previous(); - - /** - * Find the index of the element that would be returned by a call to next. - * If hasNext() returns false, this returns the list size. - * - * @return the index of the element that would be returned by next() - */ - int nextIndex(); - - /** - * Find the index of the element that would be returned by a call to - * previous. If hasPrevious() returns false, this returns -1. - * - * @return the index of the element that would be returned by previous() - */ - int previousIndex(); - - /** - * Insert an element into the list at the current position of the iterator - * (optional operation). The element is inserted in between the element that - * would be returned by previous and the element that would be returned by - * next. After the insertion, a subsequent call to next is unaffected, but - * a call to previous returns the item that was added. The values returned - * by nextIndex() and previousIndex() are incremented. - * - * @param o the object to insert into the list - * @throws ClassCastException if the object is of a type which cannot be added - * to this list. - * @throws IllegalArgumentException if some other aspect of the object stops - * it being added to this list. - * @throws UnsupportedOperationException if this ListIterator does not - * support the add operation. - */ - void add(Object o); - - /** - * Remove from the list the element last returned by a call to next or - * previous (optional operation). This method may only be called if neither - * add nor remove have been called since the last call to next or previous. - * - * @throws IllegalStateException if neither next or previous have been - * called, or if add or remove has been called since the last call - * to next or previous - * @throws UnsupportedOperationException if this ListIterator does not - * support the remove operation - */ - void remove(); - - /** - * Replace the element last returned by a call to next or previous with a - * given object (optional operation). This method may only be called if - * neither add nor remove have been called since the last call to next or - * previous. - * - * @param o the object to replace the element with - * @throws ClassCastException the object is of a type which cannot be added - * to this list - * @throws IllegalArgumentException some other aspect of the object stops - * it being added to this list - * @throws IllegalStateException if neither next or previous have been - * called, or if add or remove has been called since the last call - * to next or previous - * @throws UnsupportedOperationException if this ListIterator does not - * support the set operation - */ - void set(Object o); -} diff --git a/libjava/java/util/ListResourceBundle.java b/libjava/java/util/ListResourceBundle.java deleted file mode 100644 index 2bc51c3b013..00000000000 --- a/libjava/java/util/ListResourceBundle.java +++ /dev/null @@ -1,140 +0,0 @@ -/* ListResourceBundle -- a resource bundle build around a list - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util; - -/** - * A <code>ListResouceBundle</code> provides an easy way, to create your own - * resource bundle. It is an abstract class that you can subclass. You should - * then overwrite the getContents method, that provides a key/value list. - * - * <p>The key/value list is a two dimensional list of Object. The first - * dimension ranges over the resources. The second dimension ranges from - * zero (key) to one (value). The keys must be of type String, and they are - * case-sensitive. For example: - * -<br><pre>public class MyResources - extends ListResourceBundle -{ - public Object[][] getContents() - { - return contents; - } - - static final Object[][] contents = - { - // LOCALIZED STRINGS - {"s1", "The disk \"{1}\" contains {0}."}, // MessageFormat pattern - {"s2", "1"}, // location of {0} in pattern - {"s3", "My Disk"}, // sample disk name - {"s4", "no files"}, // first ChoiceFormat choice - {"s5", "one file"}, // second ChoiceFormat choice - {"s6", "{0,number} files"} // third ChoiceFormat choice - {"s7", "3 Mar 96"}, // sample date - {"s8", new Dimension(1,5)} // real object, not just string - // END OF LOCALIZED MATERIAL - }; -}</pre> - * - * @author Jochen Hoenicke - * @author Eric Blake (ebb9@email.byu.edu) - * @see Locale - * @see PropertyResourceBundle - * @since 1.1 - * @status updated to 1.4 - */ -public abstract class ListResourceBundle extends ResourceBundle -{ - /** - * The constructor. It does nothing special. - */ - public ListResourceBundle() - { - } - - /** - * Gets a resource for a given key. This is called by <code>getObject</code>. - * - * @param key the key of the resource - * @return the resource for the key, or null if it doesn't exist - */ - public final Object handleGetObject(String key) - { - Object[][] contents = getContents(); - int i = contents.length; - while (--i >= 0) - if (key.equals(contents[i][0])) - return contents[i][1]; - return null; - } - - /** - * This method should return all keys for which a resource exists. - * - * @return an enumeration of the keys - */ - public Enumeration getKeys() - { - // We make a new Set that holds all the keys, then return an enumeration - // for that. This prevents modifications from ruining the enumeration, - // as well as ignoring duplicates. - final Object[][] contents = getContents(); - Set s = new HashSet(); - int i = contents.length; - while (--i >= 0) - s.add(contents[i][0]); - ResourceBundle bundle = parent; - // Eliminate tail recursion. - while (bundle != null) - { - Enumeration e = bundle.getKeys(); - while (e.hasMoreElements()) - s.add(e.nextElement()); - bundle = bundle.parent; - } - return Collections.enumeration(s); - } - - /** - * Gets the key/value list. You must override this method, and should not - * provide duplicate keys or null entries. - * - * @return a two dimensional list of String key / Object resouce pairs - */ - protected abstract Object[][] getContents(); -} // class ListResourceBundle diff --git a/libjava/java/util/Map.java b/libjava/java/util/Map.java deleted file mode 100644 index 256e98899f6..00000000000 --- a/libjava/java/util/Map.java +++ /dev/null @@ -1,338 +0,0 @@ -/* Map.java: interface Map -- An object that maps keys to values - interface Map.Entry -- an Entry in a Map - Copyright (C) 1998, 2001, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util; - -/** - * An object that maps keys onto values. Keys cannot be duplicated. This - * interface replaces the obsolete {@link Dictionary} abstract class. - * <p> - * - * The map has three collection views, which are backed by the map - * (modifications on one show up on the other): a set of keys, a collection - * of values, and a set of key-value mappings. Some maps have a guaranteed - * order, but not all do. - * <p> - * - * Note: Be careful about using mutable keys. Behavior is unspecified if - * a key's comparison behavior is changed after the fact. As a corollary - * to this rule, don't use a Map as one of its own keys or values, as it makes - * hashCode and equals have undefined behavior. - * <p> - * - * All maps are recommended to provide a no argument constructor, which builds - * an empty map, and one that accepts a Map parameter and copies the mappings - * (usually by putAll), to create an equivalent map. Unfortunately, Java - * cannot enforce these suggestions. - * <p> - * - * The map may be unmodifiable, in which case unsupported operations will - * throw an UnsupportedOperationException. Note that some operations may be - * safe, such as putAll(m) where m is empty, even if the operation would - * normally fail with a non-empty argument. - * - * @author Original author unknown - * @author Eric Blake (ebb9@email.byu.edu) - * @see HashMap - * @see TreeMap - * @see Hashtable - * @see SortedMap - * @see Collection - * @see Set - * @since 1.2 - * @status updated to 1.4 - */ -public interface Map -{ - /** - * Remove all entries from this Map (optional operation). - * - * @throws UnsupportedOperationException if clear is not supported - */ - void clear(); - - /** - * Returns true if this contains a mapping for the given key. - * - * @param key the key to search for - * @return true if the map contains the key - * @throws ClassCastException if the key is of an inappropriate type - * @throws NullPointerException if key is <code>null</code> but the map - * does not permit null keys - */ - boolean containsKey(Object key); - - /** - * Returns true if this contains at least one mapping with the given value. - * In other words, returns true if a value v exists where - * <code>(value == null ? v == null : value.equals(v))</code>. This usually - * requires linear time. - * - * @param value the value to search for - * @return true if the map contains the value - * @throws ClassCastException if the type of the value is not a valid type - * for this map. - * @throws NullPointerException if the value is null and the map doesn't - * support null values. - */ - boolean containsValue(Object value); - - /** - * Returns a set view of the mappings in this Map. Each element in the - * set is a Map.Entry. The set is backed by the map, so that changes in - * one show up in the other. Modifications made while an iterator is - * in progress cause undefined behavior. If the set supports removal, - * these methods remove the underlying mapping from the map: - * <code>Iterator.remove</code>, <code>Set.remove</code>, - * <code>removeAll</code>, <code>retainAll</code>, and <code>clear</code>. - * Element addition, via <code>add</code> or <code>addAll</code>, is - * not supported via this set. - * - * @return the set view of all mapping entries - * @see Map.Entry - */ - Set entrySet(); - - /** - * Compares the specified object with this map for equality. Returns - * <code>true</code> if the other object is a Map with the same mappings, - * that is,<br> - * <code>o instanceof Map && entrySet().equals(((Map) o).entrySet();</code> - * This allows comparison of maps, regardless of implementation. - * - * @param o the object to be compared - * @return true if the object equals this map - * @see Set#equals(Object) - */ - boolean equals(Object o); - - /** - * Returns the value mapped by the given key. Returns <code>null</code> if - * there is no mapping. However, in Maps that accept null values, you - * must rely on <code>containsKey</code> to determine if a mapping exists. - * - * @param key the key to look up - * @return the value associated with the key, or null if key not in map - * @throws ClassCastException if the key is an inappropriate type - * @throws NullPointerException if this map does not accept null keys - * @see #containsKey(Object) - */ - Object get(Object key); - - /** - * Associates the given key to the given value (optional operation). If the - * map already contains the key, its value is replaced. Be aware that in - * a map that permits <code>null</code> values, a null return does not - * always imply that the mapping was created. - * - * @param key the key to map - * @param value the value to be mapped - * @return the previous value of the key, or null if there was no mapping - * @throws UnsupportedOperationException if the operation is not supported - * @throws ClassCastException if the key or value is of the wrong type - * @throws IllegalArgumentException if something about this key or value - * prevents it from existing in this map - * @throws NullPointerException if either the key or the value is null, - * and the map forbids null keys or values - * @see #containsKey(Object) - */ - Object put(Object key, Object value); - - /** - * Returns the hash code for this map. This is the sum of all hashcodes - * for each Map.Entry object in entrySet. This allows comparison of maps, - * regardless of implementation, and satisfies the contract of - * Object.hashCode. - * - * @return the hash code - * @see Map.Entry#hashCode() - */ - int hashCode(); - - /** - * Returns true if the map contains no mappings. - * - * @return true if the map is empty - */ - boolean isEmpty(); - - /** - * Returns a set view of the keys in this Map. The set is backed by the - * map, so that changes in one show up in the other. Modifications made - * while an iterator is in progress cause undefined behavior. If the set - * supports removal, these methods remove the underlying mapping from - * the map: <code>Iterator.remove</code>, <code>Set.remove</code>, - * <code>removeAll</code>, <code>retainAll</code>, and <code>clear</code>. - * Element addition, via <code>add</code> or <code>addAll</code>, is - * not supported via this set. - * - * @return the set view of all keys - */ - Set keySet(); - - /** - * Copies all entries of the given map to this one (optional operation). If - * the map already contains a key, its value is replaced. - * - * @param m the mapping to load into this map - * @throws UnsupportedOperationException if the operation is not supported - * @throws ClassCastException if a key or value is of the wrong type - * @throws IllegalArgumentException if something about a key or value - * prevents it from existing in this map - * @throws NullPointerException if the map forbids null keys or values, or - * if <code>m</code> is null. - * @see #put(Object, Object) - */ - void putAll(Map m); - - /** - * Removes the mapping for this key if present (optional operation). If - * the key is not present, this returns null. Note that maps which permit - * null values may also return null if the key was removed. - * - * @param key the key to remove - * @return the value the key mapped to, or null if not present. - * @throws UnsupportedOperationException if deletion is unsupported - * @throws NullPointerException if the key is null and this map doesn't - * support null keys. - * @throws ClassCastException if the type of the key is not a valid type - * for this map. - */ - Object remove(Object key); - - /** - * Returns the number of key-value mappings in the map. If there are more - * than Integer.MAX_VALUE mappings, return Integer.MAX_VALUE. - * - * @return the number of mappings - */ - int size(); - - /** - * Returns a collection (or bag) view of the values in this Map. The - * collection is backed by the map, so that changes in one show up in - * the other. Modifications made while an iterator is in progress cause - * undefined behavior. If the collection supports removal, these methods - * remove the underlying mapping from the map: <code>Iterator.remove</code>, - * <code>Collection.remove</code>, <code>removeAll</code>, - * <code>retainAll</code>, and <code>clear</code>. Element addition, via - * <code>add</code> or <code>addAll</code>, is not supported via this - * collection. - * - * @return the collection view of all values - */ - Collection values(); - - /** - * A map entry (key-value pair). The Map.entrySet() method returns a set - * view of these objects; there is no other valid way to come across them. - * These objects are only valid for the duration of an iteration; in other - * words, if you mess with one after modifying the map, you are asking - * for undefined behavior. - * - * @author Original author unknown - * @author Eric Blake (ebb9@email.byu.edu) - * @see Map - * @see Map#entrySet() - * @since 1.2 - * @status updated to 1.4 - */ - interface Entry - { - /** - * Get the key corresponding to this entry. - * - * @return the key - */ - Object getKey(); - - /** - * Get the value corresponding to this entry. If you already called - * Iterator.remove(), this is undefined. - * - * @return the value - */ - Object getValue(); - - /** - * Replaces the value with the specified object (optional operation). - * This writes through to the map, and is undefined if you already - * called Iterator.remove(). - * - * @param value the new value to store - * @return the old value - * @throws UnsupportedOperationException if the operation is not supported - * @throws ClassCastException if the value is of the wrong type - * @throws IllegalArgumentException if something about the value - * prevents it from existing in this map - * @throws NullPointerException if the map forbids null values - */ - Object setValue(Object value); - - - /** - * Returns the hash code of the entry. This is defined as the - * exclusive-or of the hashcodes of the key and value (using 0 for - * <code>null</code>). In other words, this must be: - * -<p><pre>(getKey() == null ? 0 : getKey().hashCode()) -^ (getValue() == null ? 0 : getValue().hashCode())</pre> - * - * @return the hash code - */ - int hashCode(); - - /** - * Compares the specified object with this entry. Returns true only if - * the object is a mapping of identical key and value. In other words, - * this must be: - * -<p><pre>(o instanceof Map.Entry) -&& (getKey() == null ? ((HashMap) o).getKey() == null - : getKey().equals(((HashMap) o).getKey())) -&& (getValue() == null ? ((HashMap) o).getValue() == null - : getValue().equals(((HashMap) o).getValue()))</pre> - * - * @param o the object to compare - * - * @return <code>true</code> if it is equal - */ - boolean equals(Object o); - } -} diff --git a/libjava/java/util/MissingResourceException.java b/libjava/java/util/MissingResourceException.java deleted file mode 100644 index 26640de90df..00000000000 --- a/libjava/java/util/MissingResourceException.java +++ /dev/null @@ -1,105 +0,0 @@ -/* MissingResourceException.java -- thrown for a missing resource - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util; - -/** - * This exception is thrown when a resource is missing. - * - * @author Jochen Hoenicke - * @author Warren Levy (warrenl@cygnus.com) - * @see ResourceBundle - * @since 1.1 - * @status updated to 1.4 - */ -public class MissingResourceException extends RuntimeException -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = -4876345176062000401L; - - /** - * The name of the resource bundle requested by user. - * - * @serial the class name of the resource bundle - */ - private final String className; - - /** - * The key of the resource in the bundle requested by user. - * - * @serial the name of the resouce - */ - private final String key; - - /** - * Creates a new exception, with the specified parameters. - * - * @param s the detail message - * @param className the name of the resource bundle - * @param key the key of the missing resource - */ - public MissingResourceException(String s, String className, String key) - { - super(s); - this.className = className; - this.key = key; - } - - /** - * Gets the name of the resource bundle, for which a resource is missing. - * - * @return the name of the resource bundle - */ - public String getClassName() - { - return className; - } - - /** - * Gets the key of the resource that is missing bundle, this is an empty - * string if the whole resource bundle is missing. - * - * @return the name of the resource bundle - */ - public String getKey() - { - return key; - } -} diff --git a/libjava/java/util/NoSuchElementException.java b/libjava/java/util/NoSuchElementException.java deleted file mode 100644 index 5e1a2176d62..00000000000 --- a/libjava/java/util/NoSuchElementException.java +++ /dev/null @@ -1,88 +0,0 @@ -/* NoSuchElementException.java -- Attempt to access element that does not exist - Copyright (C) 1998, 1999, 2001, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util; - -/* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3 - * "The Java Language Specification", ISBN 0-201-63451-1 - * plus online API docs for JDK 1.2 beta from http://www.javasoft.com. - */ - -/** - * Exception thrown when an attempt is made to access an element that does not - * exist. This exception is thrown by the Enumeration, Iterator and - * ListIterator classes if the nextElement, next or previous method goes - * beyond the end of the list of elements that are being accessed. It is also - * thrown by Vector and Stack when attempting to access the first or last - * element of an empty collection. - * - * @author Warren Levy (warrenl@cygnus.com) - * @author Eric Blake (ebb9@email.byu.edu) - * @see Enumeration - * @see Iterator - * @see ListIterator - * @see Enumeration#nextElement() - * @see Iterator#next() - * @see ListIterator#previous() - * @since 1.0 - * @status updated to 1.4 - */ -public class NoSuchElementException extends RuntimeException -{ - /** - * Compatible with JDK 1.0. - */ - private static final long serialVersionUID = 6769829250639411880L; - - /** - * Constructs a NoSuchElementException with no detail message. - */ - public NoSuchElementException() - { - } - - /** - * Constructs a NoSuchElementException with a detail message. - * - * @param detail the detail message for the exception - */ - public NoSuchElementException(String detail) - { - super(detail); - } -} diff --git a/libjava/java/util/Observable.java b/libjava/java/util/Observable.java deleted file mode 100644 index 4c2cddb5496..00000000000 --- a/libjava/java/util/Observable.java +++ /dev/null @@ -1,180 +0,0 @@ -/* Observable.java -- an object to be observed - Copyright (C) 1999, 2000, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util; - -/** - * This class represents an object which is observable. Other objects may - * register their intent to be notified when this object changes; and when - * this object does change, it will trigger the <code>update</code> method - * of each observer. - * - * Note that the <code>notifyObservers()</code> method of this class is - * unrelated to the <code>notify()</code> of Object. - * - * @author Warren Levy (warrenl@cygnus.com) - * @author Eric Blake (ebb9@email.byu.edu) - * @see Observer - * @status updated to 1.4 - */ -public class Observable -{ - /** Tracks whether this object has changed. */ - private boolean changed; - - /* List of the Observers registered as interested in this Observable. */ - private LinkedHashSet observers; - - /** - * Constructs an Observable with zero Observers. - */ - public Observable() - { - observers = new LinkedHashSet(); - } - - /** - * Adds an Observer. If the observer was already added this method does - * nothing. - * - * @param observer Observer to add - * @throws NullPointerException if observer is null - */ - public synchronized void addObserver(Observer observer) - { - observers.add(observer); - } - - /** - * Reset this Observable's state to unchanged. This is called automatically - * by <code>notifyObservers</code> once all observers have been notified. - * - * @see #notifyObservers() - */ - protected synchronized void clearChanged() - { - changed = false; - } - - /** - * Returns the number of observers for this object. - * - * @return number of Observers for this - */ - public synchronized int countObservers() - { - return observers.size(); - } - - /** - * Deletes an Observer of this Observable. - * - * @param victim Observer to delete - */ - public synchronized void deleteObserver(Observer victim) - { - observers.remove(victim); - } - - /** - * Deletes all Observers of this Observable. - */ - public synchronized void deleteObservers() - { - observers.clear(); - } - - /** - * True if <code>setChanged</code> has been called more recently than - * <code>clearChanged</code>. - * - * @return whether or not this Observable has changed - */ - public synchronized boolean hasChanged() - { - return changed; - } - - /** - * If the Observable has actually changed then tell all Observers about it, - * then reset state to unchanged. - * - * @see #notifyObservers(Object) - * @see Observer#update(Observable, Object) - */ - public void notifyObservers() - { - notifyObservers(null); - } - - /** - * If the Observable has actually changed then tell all Observers about it, - * then reset state to unchanged. Note that though the order of - * notification is unspecified in subclasses, in Observable it is in the - * order of registration. - * - * @param obj argument to Observer's update method - * @see Observer#update(Observable, Object) - */ - public void notifyObservers(Object obj) - { - if (! hasChanged()) - return; - // Create clone inside monitor, as that is relatively fast and still - // important to keep threadsafe, but update observers outside of the - // lock since update() can call arbitrary code. - Set s; - synchronized (this) - { - s = (Set) observers.clone(); - } - int i = s.size(); - Iterator iter = s.iterator(); - while (--i >= 0) - ((Observer) iter.next()).update(this, obj); - clearChanged(); - } - - /** - * Marks this Observable as having changed. - */ - protected synchronized void setChanged() - { - changed = true; - } -} diff --git a/libjava/java/util/Observer.java b/libjava/java/util/Observer.java deleted file mode 100644 index c59a0ca6c68..00000000000 --- a/libjava/java/util/Observer.java +++ /dev/null @@ -1,60 +0,0 @@ -/* Observer.java -- an object that will be informed of changes in an Observable - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util; - -/** - * Interface that is implemented when a class wants to be informed of changes - * in Observable objects. - * - * @author Warren Levy (warrenl@cygnus.com) - * @see Observable - * @status updated to 1.4 - */ -public interface Observer -{ - /** - * This method is called whenever the observable object changes, and has - * called <code>notifyObservers</code>. The Observable object can pass - * arbitrary information in the second parameter. - * - * @param observable the Observable object that changed - * @param arg arbitrary information, usually relating to the change - */ - void update(Observable observable, Object arg); -} diff --git a/libjava/java/util/Properties.java b/libjava/java/util/Properties.java deleted file mode 100644 index dd442fc396f..00000000000 --- a/libjava/java/util/Properties.java +++ /dev/null @@ -1,574 +0,0 @@ -/* Properties.java -- a set of persistent properties - Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.PrintStream; -import java.io.PrintWriter; - -/** - * A set of persistent properties, which can be saved or loaded from a stream. - * A property list may also contain defaults, searched if the main list - * does not contain a property for a given key. - * - * An example of a properties file for the german language is given - * here. This extends the example given in ListResourceBundle. - * Create a file MyResource_de.properties with the following contents - * and put it in the CLASSPATH. (The character - * <code>\</code><code>u00e4</code> is the german umlaut) - * - * -<pre>s1=3 -s2=MeineDisk -s3=3. M\<code></code>u00e4rz 96 -s4=Die Diskette ''{1}'' enth\<code></code>u00e4lt {0} in {2}. -s5=0 -s6=keine Dateien -s7=1 -s8=eine Datei -s9=2 -s10={0,number} Dateien -s11=Das Formatieren schlug fehl mit folgender Exception: {0} -s12=FEHLER -s13=Ergebnis -s14=Dialog -s15=Auswahlkriterium -s16=1,3</pre> - * - * <p>Although this is a sub class of a hash table, you should never - * insert anything other than strings to this property, or several - * methods, that need string keys and values, will fail. To ensure - * this, you should use the <code>get/setProperty</code> method instead - * of <code>get/put</code>. - * - * Properties are saved in ISO 8859-1 encoding, using Unicode escapes with - * a single <code>u</code> for any character which cannot be represented. - * - * @author Jochen Hoenicke - * @author Eric Blake (ebb9@email.byu.edu) - * @see PropertyResourceBundle - * @status updated to 1.4 - */ -public class Properties extends Hashtable -{ - // WARNING: Properties is a CORE class in the bootstrap cycle. See the - // comments in vm/reference/java/lang/Runtime for implications of this fact. - - /** - * The property list that contains default values for any keys not - * in this property list. - * - * @serial the default properties - */ - protected Properties defaults; - - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = 4112578634029874840L; - - /** - * Creates a new empty property list with no default values. - */ - public Properties() - { - } - - /** - * Create a new empty property list with the specified default values. - * - * @param defaults a Properties object containing the default values - */ - public Properties(Properties defaults) - { - this.defaults = defaults; - } - - /** - * Adds the given key/value pair to this properties. This calls - * the hashtable method put. - * - * @param key the key for this property - * @param value the value for this property - * @return The old value for the given key - * @see #getProperty(String) - * @since 1.2 - */ - public Object setProperty(String key, String value) - { - return put(key, value); - } - - /** - * Reads a property list from an input stream. The stream should - * have the following format: <br> - * - * An empty line or a line starting with <code>#</code> or - * <code>!</code> is ignored. An backslash (<code>\</code>) at the - * end of the line makes the line continueing on the next line - * (but make sure there is no whitespace after the backslash). - * Otherwise, each line describes a key/value pair. <br> - * - * The chars up to the first whitespace, = or : are the key. You - * can include this caracters in the key, if you precede them with - * a backslash (<code>\</code>). The key is followed by optional - * whitespaces, optionally one <code>=</code> or <code>:</code>, - * and optionally some more whitespaces. The rest of the line is - * the resource belonging to the key. <br> - * - * Escape sequences <code>\t, \n, \r, \\, \", \', \!, \#, \ </code>(a - * space), and unicode characters with the - * <code>\\u</code><em>xxxx</em> notation are detected, and - * converted to the corresponding single character. <br> - * - * -<pre># This is a comment -key = value -k\:5 \ a string starting with space and ending with newline\n -# This is a multiline specification; note that the value contains -# no white space. -weekdays: Sunday,Monday,Tuesday,Wednesday,\\ - Thursday,Friday,Saturday -# The safest way to include a space at the end of a value: -label = Name:\\u0020</pre> - * - * @param in the input stream - * @throws IOException if an error occurred when reading the input - * @throws NullPointerException if in is null - */ - public void load(InputStream inStream) throws IOException - { - // The spec says that the file must be encoded using ISO-8859-1. - BufferedReader reader = - new BufferedReader(new InputStreamReader(inStream, "ISO-8859-1")); - String line; - - while ((line = reader.readLine()) != null) - { - char c = 0; - int pos = 0; - // Leading whitespaces must be deleted first. - while (pos < line.length() - && Character.isWhitespace(c = line.charAt(pos))) - pos++; - - // If empty line or begins with a comment character, skip this line. - if ((line.length() - pos) == 0 - || line.charAt(pos) == '#' || line.charAt(pos) == '!') - continue; - - // The characters up to the next Whitespace, ':', or '=' - // describe the key. But look for escape sequences. - StringBuffer key = new StringBuffer(); - while (pos < line.length() - && ! Character.isWhitespace(c = line.charAt(pos++)) - && c != '=' && c != ':') - { - if (c == '\\') - { - if (pos == line.length()) - { - // The line continues on the next line. - line = reader.readLine(); - pos = 0; - while (pos < line.length() - && Character.isWhitespace(c = line.charAt(pos))) - pos++; - } - else - { - c = line.charAt(pos++); - switch (c) - { - case 'n': - key.append('\n'); - break; - case 't': - key.append('\t'); - break; - case 'r': - key.append('\r'); - break; - case 'u': - if (pos + 4 <= line.length()) - { - char uni = (char) Integer.parseInt - (line.substring(pos, pos + 4), 16); - key.append(uni); - pos += 4; - } // else throw exception? - break; - default: - key.append(c); - break; - } - } - } - else - key.append(c); - } - - boolean isDelim = (c == ':' || c == '='); - while (pos < line.length() - && Character.isWhitespace(c = line.charAt(pos))) - pos++; - - if (! isDelim && (c == ':' || c == '=')) - { - pos++; - while (pos < line.length() - && Character.isWhitespace(c = line.charAt(pos))) - pos++; - } - - StringBuffer element = new StringBuffer(line.length() - pos); - while (pos < line.length()) - { - c = line.charAt(pos++); - if (c == '\\') - { - if (pos == line.length()) - { - // The line continues on the next line. - line = reader.readLine(); - - // We might have seen a backslash at the end of - // the file. The JDK ignores the backslash in - // this case, so we follow for compatibility. - if (line == null) - break; - - pos = 0; - while (pos < line.length() - && Character.isWhitespace(c = line.charAt(pos))) - pos++; - element.ensureCapacity(line.length() - pos + - element.length()); - } - else - { - c = line.charAt(pos++); - switch (c) - { - case 'n': - element.append('\n'); - break; - case 't': - element.append('\t'); - break; - case 'r': - element.append('\r'); - break; - case 'u': - if (pos + 4 <= line.length()) - { - char uni = (char) Integer.parseInt - (line.substring(pos, pos + 4), 16); - element.append(uni); - pos += 4; - } // else throw exception? - break; - default: - element.append(c); - break; - } - } - } - else - element.append(c); - } - put(key.toString(), element.toString()); - } - } - - /** - * Calls <code>store(OutputStream out, String header)</code> and - * ignores the IOException that may be thrown. - * - * @param out the stream to write to - * @param header a description of the property list - * @throws ClassCastException if this property contains any key or - * value that are not strings - * @deprecated use {@link #store(OutputStream, String)} instead - */ - public void save(OutputStream out, String header) - { - try - { - store(out, header); - } - catch (IOException ex) - { - } - } - - /** - * Writes the key/value pairs to the given output stream, in a format - * suitable for <code>load</code>.<br> - * - * If header is not null, this method writes a comment containing - * the header as first line to the stream. The next line (or first - * line if header is null) contains a comment with the current date. - * Afterwards the key/value pairs are written to the stream in the - * following format.<br> - * - * Each line has the form <code>key = value</code>. Newlines, - * Returns and tabs are written as <code>\n,\t,\r</code> resp. - * The characters <code>\, !, #, =</code> and <code>:</code> are - * preceeded by a backslash. Spaces are preceded with a backslash, - * if and only if they are at the beginning of the key. Characters - * that are not in the ascii range 33 to 127 are written in the - * <code>\</code><code>u</code>xxxx Form.<br> - * - * Following the listing, the output stream is flushed but left open. - * - * @param out the output stream - * @param header the header written in the first line, may be null - * @throws ClassCastException if this property contains any key or - * value that isn't a string - * @throws IOException if writing to the stream fails - * @throws NullPointerException if out is null - * @since 1.2 - */ - public void store(OutputStream out, String header) throws IOException - { - // The spec says that the file must be encoded using ISO-8859-1. - PrintWriter writer - = new PrintWriter(new OutputStreamWriter(out, "ISO-8859-1")); - if (header != null) - writer.println("#" + header); - writer.println ("#" + Calendar.getInstance ().getTime ()); - - Iterator iter = entrySet ().iterator (); - int i = size (); - StringBuffer s = new StringBuffer (); // Reuse the same buffer. - while (--i >= 0) - { - Map.Entry entry = (Map.Entry) iter.next (); - formatForOutput ((String) entry.getKey (), s, true); - s.append ('='); - formatForOutput ((String) entry.getValue (), s, false); - writer.println (s); - } - - writer.flush (); - } - - /** - * Gets the property with the specified key in this property list. - * If the key is not found, the default property list is searched. - * If the property is not found in the default, null is returned. - * - * @param key The key for this property - * @return the value for the given key, or null if not found - * @throws ClassCastException if this property contains any key or - * value that isn't a string - * @see #defaults - * @see #setProperty(String, String) - * @see #getProperty(String, String) - */ - public String getProperty(String key) - { - return getProperty(key, null); - } - - /** - * Gets the property with the specified key in this property list. If - * the key is not found, the default property list is searched. If the - * property is not found in the default, the specified defaultValue is - * returned. - * - * @param key The key for this property - * @param defaultValue A default value - * @return The value for the given key - * @throws ClassCastException if this property contains any key or - * value that isn't a string - * @see #defaults - * @see #setProperty(String, String) - */ - public String getProperty(String key, String defaultValue) - { - Properties prop = this; - // Eliminate tail recursion. - do - { - String value = (String) prop.get(key); - if (value != null) - return value; - prop = prop.defaults; - } - while (prop != null); - return defaultValue; - } - - /** - * Returns an enumeration of all keys in this property list, including - * the keys in the default property list. - * - * @return an Enumeration of all defined keys - */ - public Enumeration propertyNames() - { - // We make a new Set that holds all the keys, then return an enumeration - // for that. This prevents modifications from ruining the enumeration, - // as well as ignoring duplicates. - Properties prop = this; - Set s = new HashSet(); - // Eliminate tail recursion. - do - { - s.addAll(prop.keySet()); - prop = prop.defaults; - } - while (prop != null); - return Collections.enumeration(s); - } - - /** - * Prints the key/value pairs to the given print stream. This is - * mainly useful for debugging purposes. - * - * @param out the print stream, where the key/value pairs are written to - * @throws ClassCastException if this property contains a key or a - * value that isn't a string - * @see #list(PrintWriter) - */ - public void list(PrintStream out) - { - PrintWriter writer = new PrintWriter (out); - list (writer); - } - - /** - * Prints the key/value pairs to the given print writer. This is - * mainly useful for debugging purposes. - * - * @param out the print writer where the key/value pairs are written to - * @throws ClassCastException if this property contains a key or a - * value that isn't a string - * @see #list(PrintStream) - * @since 1.1 - */ - public void list(PrintWriter out) - { - out.println ("-- listing properties --"); - - Iterator iter = entrySet ().iterator (); - int i = size (); - while (--i >= 0) - { - Map.Entry entry = (Map.Entry) iter.next (); - out.print ((String) entry.getKey () + "="); - - // JDK 1.3/1.4 restrict the printed value, but not the key, - // to 40 characters, including the truncating ellipsis. - String s = (String ) entry.getValue (); - if (s != null && s.length () > 40) - out.println (s.substring (0, 37) + "..."); - else - out.println (s); - } - out.flush (); - } - - /** - * Formats a key or value for output in a properties file. - * See store for a description of the format. - * - * @param str the string to format - * @param buffer the buffer to add it to - * @param key true if all ' ' must be escaped for the key, false if only - * leading spaces must be escaped for the value - * @see #store(OutputStream, String) - */ - private void formatForOutput(String str, StringBuffer buffer, boolean key) - { - if (key) - { - buffer.setLength(0); - buffer.ensureCapacity(str.length()); - } - else - buffer.ensureCapacity(buffer.length() + str.length()); - boolean head = true; - int size = str.length(); - for (int i = 0; i < size; i++) - { - char c = str.charAt(i); - switch (c) - { - case '\n': - buffer.append("\\n"); - break; - case '\r': - buffer.append("\\r"); - break; - case '\t': - buffer.append("\\t"); - break; - case ' ': - buffer.append(head ? "\\ " : " "); - break; - case '\\': - case '!': - case '#': - case '=': - case ':': - buffer.append('\\').append(c); - break; - default: - if (c < ' ' || c > '~') - { - String hex = Integer.toHexString(c); - buffer.append("\\u0000".substring(0, 6 - hex.length())); - buffer.append(hex); - } - else - buffer.append(c); - } - if (c != ' ') - head = key; - } - } -} // class Properties diff --git a/libjava/java/util/PropertyPermission.java b/libjava/java/util/PropertyPermission.java deleted file mode 100644 index d1bdbd1d058..00000000000 --- a/libjava/java/util/PropertyPermission.java +++ /dev/null @@ -1,271 +0,0 @@ -/* PropertyPermission.java -- permission to get and set System properties - Copyright (C) 1999, 2000, 2002, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util; - -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.ObjectStreamField; -import java.security.BasicPermission; -import java.security.Permission; -import java.security.PermissionCollection; - -/** - * This class represents the permission to access and modify a property.<br> - * - * The name is the name of the property, e.g. xxx. You can also - * use an asterisk "*" as described in BasicPermission.<br> - * - * The action string is a comma-separated list of keywords. There are - * two possible actions: - * <dl> - * <dt>read</dt> - * <dd>Allows to read the property via <code>System.getProperty</code>.</dd> - * <dt>write</dt> - * <dd>Allows to write the property via <code>System.setProperty</code>.</dd> - * </dl> - * - * The action string is case insensitive (it is converted to lower case). - * - * @see Permission - * @see BasicPermission - * @see SecurityManager - * @author Jochen Hoenicke - * @since 1.2 - * @status updated to 1.4 - */ -public final class PropertyPermission extends BasicPermission -{ - /** - * PropertyPermission uses a more efficient representation than the - * serialized form; this documents the difference. - * - * @serialField action String the action string - */ - private static final ObjectStreamField[] serialPersistentFields = - { - new ObjectStreamField("action", String.class) - }; - - /** - * Compatible with JDK 1.2+. - */ - private static final long serialVersionUID = 885438825399942851L; - - /** Permission to read. */ - private static final int READ = 1; - /** Permission to write. */ - private static final int WRITE = 2; - - /** The set of actions permitted. */ - // Package visible for use by PropertyPermissionCollection. - transient int actions; - - /** - * The String forms of the actions permitted. - */ - private static final String actionStrings[] = - { - "", "read", "write", "read,write" - }; - - /** - * Constructs a PropertyPermission with the specified property. Possible - * actions are read and write, comma-separated and case-insensitive. - * - * @param name the name of the property - * @param actions the action string - * @throws NullPointerException if name is null - * @throws IllegalArgumentException if name string contains an - * illegal wildcard or actions string contains an illegal action - * (this includes a null actions string) - */ - public PropertyPermission(String name, String actions) - { - super(name); - if (actions == null) - throw new IllegalArgumentException(); - setActions(actions); - } - - /** - * Parse the action string and convert actions from external to internal - * form. This will set the internal actions field. - * - * @param str the action string - * @throws IllegalArgumentException if actions string contains an - * illegal action - */ - private void setActions(String str) - { - // Initialising the class java.util.Locale ... - // tries to initialise the Locale.defaultLocale static - // which calls System.getProperty, - // which calls SecurityManager.checkPropertiesAccess, - // which creates a PropertyPermission with action "read,write", - // which calls setActions("read,write"). - // If we now were to call toLowerCase on 'str', - // this would call Locale.getDefault() which returns null - // because Locale.defaultLocale hasn't been set yet - // then toLowerCase will fail with a null pointer exception. - // - // The solution is to take a punt on 'str' being lower case, and - // test accordingly. If that fails, we convert 'str' to lower case - // and try the tests again. - if ("read".equals(str)) - actions = READ; - else if ("write".equals(str)) - actions = WRITE; - else if ("read,write".equals(str) || "write,read".equals(str)) - actions = READ | WRITE; - else - { - String lstr = str.toLowerCase(); - if ("read".equals(lstr)) - actions = READ; - else if ("write".equals(lstr)) - actions = WRITE; - else if ("read,write".equals(lstr) || "write,read".equals(lstr)) - actions = READ | WRITE; - else - throw new IllegalArgumentException("illegal action " + str); - } - } - - /** - * Reads an object from the stream. This converts the external to the - * internal representation. - * - * @param s the stream to read from - * @throws IOException if the stream fails - * @throws ClassNotFoundException if reserialization fails - */ - private void readObject(ObjectInputStream s) - throws IOException, ClassNotFoundException - { - ObjectInputStream.GetField fields = s.readFields(); - setActions((String) fields.get("actions", null)); - } - - /** - * Writes an object to the stream. This converts the internal to the - * external representation. - * - * @param s the stram to write to - * @throws IOException if the stream fails - */ - private void writeObject(ObjectOutputStream s) throws IOException - { - ObjectOutputStream.PutField fields = s.putFields(); - fields.put("actions", getActions()); - s.writeFields(); - } - - /** - * Check if this permission implies p. This returns true iff all of - * the following conditions are true: - * <ul> - * <li> p is a PropertyPermission </li> - * <li> this.getName() implies p.getName(), - * e.g. <code>java.*</code> implies <code>java.home</code> </li> - * <li> this.getActions is a subset of p.getActions </li> - * </ul> - * - * @param p the permission to check - * @return true if this permission implies p - */ - public boolean implies(Permission p) - { - // BasicPermission checks for name and type. - if (super.implies(p)) - { - // We have to check the actions. - PropertyPermission pp = (PropertyPermission) p; - return (pp.actions & ~actions) == 0; - } - return false; - } - - /** - * Check to see whether this object is the same as another - * PropertyPermission object; this is true if it has the same name and - * actions. - * - * @param obj the other object - * @return true if the two are equivalent - */ - public boolean equals(Object obj) - { - return super.equals(obj) && actions == ((PropertyPermission) obj).actions; - } - - /** - * Returns the hash code for this permission. It is equivalent to - * <code>getName().hashCode()</code>. - * - * @return the hash code - */ - public int hashCode() - { - return super.hashCode(); - } - - /** - * Returns the action string. Note that this may differ from the string - * given at the constructor: The actions are converted to lowercase and - * may be reordered. - * - * @return one of "read", "write", or "read,write" - */ - public String getActions() - { - return actionStrings[actions]; - } - - /** - * Returns a permission collection suitable to take - * PropertyPermission objects. - * - * @return a new empty PermissionCollection - */ - public PermissionCollection newPermissionCollection() - { - return new PropertyPermissionCollection(); - } -} diff --git a/libjava/java/util/PropertyPermissionCollection.java b/libjava/java/util/PropertyPermissionCollection.java deleted file mode 100644 index c95fa4e66bf..00000000000 --- a/libjava/java/util/PropertyPermissionCollection.java +++ /dev/null @@ -1,166 +0,0 @@ -/* PropertyPermissionCollection.java -- a collection of PropertyPermissions - Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util; - -import java.security.Permission; -import java.security.PermissionCollection; - -/** - * This class provides the implementation for - * <code>PropertyPermission.newPermissionCollection()</code>. It only accepts - * PropertyPermissions, and correctly implements <code>implies</code>. It - * is synchronized, as specified in the superclass. - * - * @author Eric Blake (ebb9@email.byu.edu) - * @status an undocumented class, but this matches Sun's serialization - */ -class PropertyPermissionCollection extends PermissionCollection -{ - /** - * Compatible with JDK 1.4. - */ - private static final long serialVersionUID = 7015263904581634791L; - - /** - * The permissions. - * - * @serial the table of permissions in the collection - */ - private final Hashtable permissions = new Hashtable(); - - /** - * A flag to detect if "*" is in the collection. - * - * @serial true if "*" is in the collection - */ - private boolean all_allowed; - - /** - * Adds a PropertyPermission to this collection. - * - * @param permission the permission to add - * @throws IllegalArgumentException if permission is not a PropertyPermission - * @throws SecurityException if collection is read-only - */ - public void add(Permission permission) - { - if (isReadOnly()) - throw new SecurityException("readonly"); - if (! (permission instanceof PropertyPermission)) - throw new IllegalArgumentException(); - PropertyPermission pp = (PropertyPermission) permission; - String name = pp.getName(); - if (name.equals("*")) - all_allowed = true; - PropertyPermission old = (PropertyPermission) permissions.get(name); - if (old != null) - { - if ((pp.actions | old.actions) == old.actions) - pp = old; // Old implies pp. - else if ((pp.actions | old.actions) != pp.actions) - // Here pp doesn't imply old; the only case left is both actions. - pp = new PropertyPermission(name, "read,write"); - } - permissions.put(name, pp); - } - - /** - * Returns true if this collection implies the given permission. This even - * returns true for this case: - * - * <pre> - * collection.add(new PropertyPermission("a.*", "read")); - * collection.add(new PropertyPermission("a.b.*", "write")); - * collection.implies(new PropertyPermission("a.b.c", "read,write")); - * </pre> - * - * @param permission the permission to check - * @return true if it is implied by this - */ - public boolean implies(Permission permission) - { - if (! (permission instanceof PropertyPermission)) - return false; - PropertyPermission toImply = (PropertyPermission) permission; - int actions = toImply.actions; - - if (all_allowed) - { - int all_actions = ((PropertyPermission) permissions.get("*")).actions; - actions &= ~all_actions; - if (actions == 0) - return true; - } - - String name = toImply.getName(); - if (name.equals("*")) - return false; - - int prefixLength = name.length(); - if (name.endsWith("*")) - prefixLength -= 2; - - while (true) - { - PropertyPermission forName = - (PropertyPermission) permissions.get(name); - if (forName != null) - { - actions &= ~forName.actions; - if (actions == 0) - return true; - } - - prefixLength = name.lastIndexOf('.', prefixLength - 1); - if (prefixLength < 0) - return false; - name = name.substring(0, prefixLength + 1) + '*'; - } - } - - /** - * Enumerate over the collection. - * - * @return an enumeration of the collection contents - */ - public Enumeration elements() - { - return permissions.elements(); - } -} diff --git a/libjava/java/util/PropertyResourceBundle.java b/libjava/java/util/PropertyResourceBundle.java deleted file mode 100644 index 86318654719..00000000000 --- a/libjava/java/util/PropertyResourceBundle.java +++ /dev/null @@ -1,152 +0,0 @@ -/* PropertyResourceBundle -- a resource bundle built from a Property file - Copyright (C) 1998, 1999, 2001, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util; - -import java.io.IOException; -import java.io.InputStream; - -/** - * This class is a concrete <code>ResourceBundle</code> that gets it - * resources from a property file. This implies that the resources are - * strings. For more information about resource bundles see the class - * <code>ResourceBundle</code>. - * - * You should not use this class directly, or subclass it, but you get - * an object of this class automatically when you call - * <code>ResourceBundle.getBundle()</code> and there is a properties - * file. - * - * If there is also a class for this resource and the same locale, the - * class will be chosen. The properties file should have the name of the - * resource bundle, appended with the locale (e.g. <code>_de</code> and the - * extension <code>.properties</code>. The file should have the same format - * as for <code>Properties.load()</code> - * - * An example of a properties file for the german language is given - * here. This extends the example given in ListResourceBundle. - * Create a file MyResource_de.properties with the following contents - * and put it in the CLASSPATH. (The char <code>\u00e4</code> is the - * german umlaut) - * - * -<pre> -s1=3 -s2=MeineDisk -s3=3. M\u00e4rz 96 -s4=Die Diskette ''{1}'' enth\u00e4lt {0} in {2}. -s5=0 -s6=keine Dateien -s7=1 -s8=eine Datei -s9=2 -s10={0,number} Dateien -s11=Die Formatierung warf eine Exception: {0} -s12=FEHLER -s13=Ergebnis -s14=Dialog -s15=Auswahlkriterium -s16=1,3 -</pre> - * - * @author Jochen Hoenicke - * @see ResourceBundle - * @see ListResourceBundle - * @see Properties#load() - * @since 1.1 - * @status updated to 1.4 - */ -public class PropertyResourceBundle extends ResourceBundle -{ - /** The properties file this bundle is based on. */ - private Properties properties; - - /** - * Creates a new property resource bundle. - * - * @param stream an input stream, where the resources are read from - * @throws NullPointerException if stream is null - * @throws IOException if reading the stream fails - */ - public PropertyResourceBundle(InputStream stream) throws IOException - { - properties = new Properties(); - properties.load(stream); - } - - /** - * Called by <code>getObject</code> when a resource is needed. This - * returns the resource given by the key. - * - * @param key the key of the resource - * @return the resource for the key, or null if it doesn't exist - */ - public Object handleGetObject(String key) - { - return properties.getProperty(key); - } - - /** - * This method should return all keys for which a resource exists. - * - * @return an enumeration of the keys - */ - public Enumeration getKeys() - { - if (parent == null) - return properties.propertyNames(); - // We make a new Set that holds all the keys, then return an enumeration - // for that. This prevents modifications from ruining the enumeration, - // as well as ignoring duplicates. - Set s = new HashSet(); - Enumeration e = properties.propertyNames(); - while (e.hasMoreElements()) - s.add(e.nextElement()); - ResourceBundle bundle = parent; - // Eliminate tail recursion. - do - { - e = bundle.getKeys(); - while (e.hasMoreElements()) - s.add(e.nextElement()); - bundle = bundle.parent; - } - while (bundle != null); - return Collections.enumeration(s); - } -} // class PropertyResourceBundle diff --git a/libjava/java/util/Random.java b/libjava/java/util/Random.java deleted file mode 100644 index bc005075140..00000000000 --- a/libjava/java/util/Random.java +++ /dev/null @@ -1,429 +0,0 @@ -/* Random.java -- a pseudo-random number generator - Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util; - -import java.io.Serializable; - -/** - * This class generates pseudorandom numbers. It uses the same - * algorithm as the original JDK-class, so that your programs behave - * exactly the same way, if started with the same seed. - * - * The algorithm is described in <em>The Art of Computer Programming, - * Volume 2</em> by Donald Knuth in Section 3.2.1. It is a 48-bit seed, - * linear congruential formula. - * - * If two instances of this class are created with the same seed and - * the same calls to these classes are made, they behave exactly the - * same way. This should be even true for foreign implementations - * (like this), so every port must use the same algorithm as described - * here. - * - * If you want to implement your own pseudorandom algorithm, you - * should extend this class and overload the <code>next()</code> and - * <code>setSeed(long)</code> method. In that case the above - * paragraph doesn't apply to you. - * - * This class shouldn't be used for security sensitive purposes (like - * generating passwords or encryption keys. See <code>SecureRandom</code> - * in package <code>java.security</code> for this purpose. - * - * For simple random doubles between 0.0 and 1.0, you may consider using - * Math.random instead. - * - * @see java.security.SecureRandom - * @see Math#random() - * @author Jochen Hoenicke - * @author Eric Blake (ebb9@email.byu.edu) - * @status updated to 1.4 - */ -public class Random implements Serializable -{ - /** - * True if the next nextGaussian is available. This is used by - * nextGaussian, which generates two gaussian numbers by one call, - * and returns the second on the second call. - * - * @serial whether nextNextGaussian is available - * @see #nextGaussian() - * @see #nextNextGaussian - */ - private boolean haveNextNextGaussian; - - /** - * The next nextGaussian, when available. This is used by nextGaussian, - * which generates two gaussian numbers by one call, and returns the - * second on the second call. - * - * @serial the second gaussian of a pair - * @see #nextGaussian() - * @see #haveNextNextGaussian - */ - private double nextNextGaussian; - - /** - * The seed. This is the number set by setSeed and which is used - * in next. - * - * @serial the internal state of this generator - * @see #next() - */ - private long seed; - - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = 3905348978240129619L; - - /** - * Creates a new pseudorandom number generator. The seed is initialized - * to the current time, as if by - * <code>setSeed(System.currentTimeMillis());</code>. - * - * @see System#currentTimeMillis() - */ - public Random() - { - this(System.currentTimeMillis()); - } - - /** - * Creates a new pseudorandom number generator, starting with the - * specified seed, using <code>setSeed(seed);</code>. - * - * @param seed the initial seed - */ - public Random(long seed) - { - setSeed(seed); - } - - /** - * Sets the seed for this pseudorandom number generator. As described - * above, two instances of the same random class, starting with the - * same seed, should produce the same results, if the same methods - * are called. The implementation for java.util.Random is: - * -<pre>public synchronized void setSeed(long seed) -{ - this.seed = (seed ^ 0x5DEECE66DL) & ((1L << 48) - 1); - haveNextNextGaussian = false; -}</pre> - * - * @param seed the new seed - */ - public synchronized void setSeed(long seed) - { - this.seed = (seed ^ 0x5DEECE66DL) & ((1L << 48) - 1); - haveNextNextGaussian = false; - } - - /** - * Generates the next pseudorandom number. This returns - * an int value whose <code>bits</code> low order bits are - * independent chosen random bits (0 and 1 are equally likely). - * The implementation for java.util.Random is: - * -<pre>protected synchronized int next(int bits) -{ - seed = (seed * 0x5DEECE66DL + 0xBL) & ((1L << 48) - 1); - return (int) (seed >>> (48 - bits)); -}</pre> - * - * @param bits the number of random bits to generate, in the range 1..32 - * @return the next pseudorandom value - * @since 1.1 - */ - protected synchronized int next(int bits) - { - seed = (seed * 0x5DEECE66DL + 0xBL) & ((1L << 48) - 1); - return (int) (seed >>> (48 - bits)); - } - - /** - * Fills an array of bytes with random numbers. All possible values - * are (approximately) equally likely. - * The JDK documentation gives no implementation, but it seems to be: - * -<pre>public void nextBytes(byte[] bytes) -{ - for (int i = 0; i < bytes.length; i += 4) - { - int random = next(32); - for (int j = 0; i + j < bytes.length && j < 4; j++) - { - bytes[i+j] = (byte) (random & 0xff) - random >>= 8; - } - } -}</pre> - * - * @param bytes the byte array that should be filled - * @throws NullPointerException if bytes is null - * @since 1.1 - */ - public void nextBytes(byte[] bytes) - { - int random; - // Do a little bit unrolling of the above algorithm. - int max = bytes.length & ~0x3; - for (int i = 0; i < max; i += 4) - { - random = next(32); - bytes[i] = (byte) random; - bytes[i + 1] = (byte) (random >> 8); - bytes[i + 2] = (byte) (random >> 16); - bytes[i + 3] = (byte) (random >> 24); - } - if (max < bytes.length) - { - random = next(32); - for (int j = max; j < bytes.length; j++) - { - bytes[j] = (byte) random; - random >>= 8; - } - } - } - - /** - * Generates the next pseudorandom number. This returns - * an int value whose 32 bits are independent chosen random bits - * (0 and 1 are equally likely). The implementation for - * java.util.Random is: - * -<pre>public int nextInt() -{ - return next(32); -}</pre> - * - * @return the next pseudorandom value - */ - public int nextInt() - { - return next(32); - } - - /** - * Generates the next pseudorandom number. This returns - * a value between 0(inclusive) and <code>n</code>(exclusive), and - * each value has the same likelihodd (1/<code>n</code>). - * (0 and 1 are equally likely). The implementation for - * java.util.Random is: - * -<pre> -public int nextInt(int n) -{ - if (n <= 0) - throw new IllegalArgumentException("n must be positive"); - - if ((n & -n) == n) // i.e., n is a power of 2 - return (int)((n * (long) next(31)) >> 31); - - int bits, val; - do - { - bits = next(31); - val = bits % n; - } - while(bits - val + (n-1) < 0); - - return val; -}</pre> - * - * <p>This algorithm would return every value with exactly the same - * probability, if the next()-method would be a perfect random number - * generator. - * - * The loop at the bottom only accepts a value, if the random - * number was between 0 and the highest number less then 1<<31, - * which is divisible by n. The probability for this is high for small - * n, and the worst case is 1/2 (for n=(1<<30)+1). - * - * The special treatment for n = power of 2, selects the high bits of - * the random number (the loop at the bottom would select the low order - * bits). This is done, because the low order bits of linear congruential - * number generators (like the one used in this class) are known to be - * ``less random'' than the high order bits. - * - * @param n the upper bound - * @throws IllegalArgumentException if the given upper bound is negative - * @return the next pseudorandom value - * @since 1.2 - */ - public int nextInt(int n) - { - if (n <= 0) - throw new IllegalArgumentException("n must be positive"); - if ((n & -n) == n) // i.e., n is a power of 2 - return (int) ((n * (long) next(31)) >> 31); - int bits, val; - do - { - bits = next(31); - val = bits % n; - } - while (bits - val + (n - 1) < 0); - return val; - } - - /** - * Generates the next pseudorandom long number. All bits of this - * long are independently chosen and 0 and 1 have equal likelihood. - * The implementation for java.util.Random is: - * -<pre>public long nextLong() -{ - return ((long) next(32) << 32) + next(32); -}</pre> - * - * @return the next pseudorandom value - */ - public long nextLong() - { - return ((long) next(32) << 32) + next(32); - } - - /** - * Generates the next pseudorandom boolean. True and false have - * the same probability. The implementation is: - * -<pre>public boolean nextBoolean() -{ - return next(1) != 0; -}</pre> - * - * @return the next pseudorandom boolean - * @since 1.2 - */ - public boolean nextBoolean() - { - return next(1) != 0; - } - - /** - * Generates the next pseudorandom float uniformly distributed - * between 0.0f (inclusive) and 1.0f (exclusive). The - * implementation is as follows. - * -<pre>public float nextFloat() -{ - return next(24) / ((float)(1 << 24)); -}</pre> - * - * @return the next pseudorandom float - */ - public float nextFloat() - { - return next(24) / (float) (1 << 24); - } - - /** - * Generates the next pseudorandom double uniformly distributed - * between 0.0 (inclusive) and 1.0 (exclusive). The - * implementation is as follows. - * -<pre>public double nextDouble() -{ - return (((long) next(26) << 27) + next(27)) / (double)(1L << 53); -}</pre> - * - * @return the next pseudorandom double - */ - public double nextDouble() - { - return (((long) next(26) << 27) + next(27)) / (double) (1L << 53); - } - - /** - * Generates the next pseudorandom, Gaussian (normally) distributed - * double value, with mean 0.0 and standard deviation 1.0. - * The algorithm is as follows. - * -<pre>public synchronized double nextGaussian() -{ - if (haveNextNextGaussian) - { - haveNextNextGaussian = false; - return nextNextGaussian; - } - else - { - double v1, v2, s; - do - { - v1 = 2 * nextDouble() - 1; // between -1.0 and 1.0 - v2 = 2 * nextDouble() - 1; // between -1.0 and 1.0 - s = v1 * v1 + v2 * v2; - } - while (s >= 1); - - double norm = Math.sqrt(-2 * Math.log(s) / s); - nextNextGaussian = v2 * norm; - haveNextNextGaussian = true; - return v1 * norm; - } -}</pre> - * - * <p>This is described in section 3.4.1 of <em>The Art of Computer - * Programming, Volume 2</em> by Donald Knuth. - * - * @return the next pseudorandom Gaussian distributed double - */ - public synchronized double nextGaussian() - { - if (haveNextNextGaussian) - { - haveNextNextGaussian = false; - return nextNextGaussian; - } - double v1, v2, s; - do - { - v1 = 2 * nextDouble() - 1; // Between -1.0 and 1.0. - v2 = 2 * nextDouble() - 1; // Between -1.0 and 1.0. - s = v1 * v1 + v2 * v2; - } - while (s >= 1); - double norm = Math.sqrt(-2 * Math.log(s) / s); - nextNextGaussian = v2 * norm; - haveNextNextGaussian = true; - return v1 * norm; - } -} diff --git a/libjava/java/util/RandomAccess.java b/libjava/java/util/RandomAccess.java deleted file mode 100644 index 054266a1c74..00000000000 --- a/libjava/java/util/RandomAccess.java +++ /dev/null @@ -1,64 +0,0 @@ -/* RandomAccess.java -- A tagging interface that lists can use to tailor - operations to the correct algorithm - Copyright (C) 2001, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util; - -/** - * Marker interface used to inform <code>List</code> implementations that - * they support fast (usually constant time) random access. This allows - * generic list algorithms to tailor their behavior based on the list - * type. - * <p> - * - * For example, some sorts are n*log(n) on an array, but decay to quadratic - * time on a linked list. As a rule of thumb, this interface should be - * used is this loop:<br> - * <code>for (int i = 0, n = list.size(); i < n; i++) list.get(i);</code> - * <br>runs faster than this loop:<br> - * <code>for (Iterator i = list.iterator(); i.hasNext(); ) i.next();</code> - * - * @author Eric Blake (ebb9@email.byu.edu) - * @see List - * @since 1.4 - * @status updated to 1.4 - */ -public interface RandomAccess -{ - // Tagging interface only. -} diff --git a/libjava/java/util/Set.java b/libjava/java/util/Set.java deleted file mode 100644 index 839959e620c..00000000000 --- a/libjava/java/util/Set.java +++ /dev/null @@ -1,264 +0,0 @@ -/* Set.java -- A collection that prohibits duplicates - Copyright (C) 1998, 2001, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util; - -/** - * A collection that contains no duplicates. In other words, for two set - * elements e1 and e2, <code>e1.equals(e2)</code> returns false. There - * are additional stipulations on <code>add</code>, <code>equals</code> - * and <code>hashCode</code>, as well as the requirements that constructors - * do not permit duplicate elements. The Set interface is incompatible with - * List; you cannot implement both simultaneously. - * <p> - * - * Note: Be careful about using mutable objects in sets. In particular, - * if a mutable object changes to become equal to another set element, you - * have violated the contract. As a special case of this, a Set is not - * allowed to be an element of itself, without risking undefined behavior. - * - * @author Original author unknown - * @author Eric Blake (ebb9@email.byu.edu) - * @see Collection - * @see List - * @see SortedSet - * @see HashSet - * @see TreeSet - * @see LinkedHashSet - * @see AbstractSet - * @see Collections#singleton(Object) - * @see Collections#EMPTY_SET - * @since 1.2 - * @status updated to 1.4 - */ -public interface Set extends Collection -{ - /** - * Adds the specified element to the set if it is not already present - * (optional operation). In particular, the comparison algorithm is - * <code>o == null ? e == null : o.equals(e)</code>. Sets need not permit - * all values, and may document what exceptions will be thrown if - * a value is not permitted. - * - * @param o the object to add - * @return true if the object was not previously in the set - * @throws UnsupportedOperationException if this operation is not allowed - * @throws ClassCastException if the class of o prevents it from being added - * @throws IllegalArgumentException if some aspect of o prevents it from - * being added - * @throws NullPointerException if null is not permitted in this set - */ - boolean add(Object o); - - /** - * Adds all of the elements of the given collection to this set (optional - * operation). If the argument is also a Set, this returns the mathematical - * <i>union</i> of the two. The behavior is unspecified if the set is - * modified while this is taking place. - * - * @param c the collection to add - * @return true if the set changed as a result - * @throws UnsupportedOperationException if this operation is not allowed - * @throws ClassCastException if the class of an element prevents it from - * being added - * @throws IllegalArgumentException if something about an element prevents - * it from being added - * @throws NullPointerException if null is not permitted in this set, or - * if the argument c is null - * @see #add(Object) - */ - boolean addAll(Collection c); - - /** - * Removes all elements from this set (optional operation). This set will - * be empty afterwords, unless an exception occurs. - * - * @throws UnsupportedOperationException if this operation is not allowed - */ - void clear(); - - /** - * Returns true if the set contains the specified element. In other words, - * this looks for <code>o == null ? e == null : o.equals(e)</code>. - * - * @param o the object to look for - * @return true if it is found in the set - * @throws ClassCastException if the type of o is not a valid type - * for this set. - * @throws NullPointerException if o is null and this set doesn't - * support null values. - */ - boolean contains(Object o); - - /** - * Returns true if this set contains all elements in the specified - * collection. If the argument is also a set, this is the <i>subset</i> - * relationship. - * - * @param c the collection to check membership in - * @return true if all elements in this set are in c - * @throws NullPointerException if c is null - * @throws ClassCastException if the type of any element in c is not - * a valid type for this set. - * @throws NullPointerException if some element of c is null and this - * set doesn't support null values. - * @see #contains(Object) - */ - boolean containsAll(Collection c); - - /** - * Compares the specified object to this for equality. For sets, the object - * must be a set, the two must have the same size, and every element in - * one must be in the other. - * - * @param o the object to compare to - * @return true if it is an equal set - */ - boolean equals(Object o); - - /** - * Returns the hash code for this set. In order to satisfy the contract of - * equals, this is the sum of the hashcode of all elements in the set. - * - * @return the sum of the hashcodes of all set elements - * @see #equals(Object) - */ - int hashCode(); - - /** - * Returns true if the set contains no elements. - * - * @return true if the set is empty - */ - boolean isEmpty(); - - /** - * Returns an iterator over the set. The iterator has no specific order, - * unless further specified. - * - * @return a set iterator - */ - Iterator iterator(); - - /** - * Removes the specified element from this set (optional operation). If - * an element e exists, <code>o == null ? e == null : o.equals(e)</code>, - * it is removed from the set. - * - * @param o the object to remove - * @return true if the set changed (an object was removed) - * @throws UnsupportedOperationException if this operation is not allowed - * @throws ClassCastException if the type of o is not a valid type - * for this set. - * @throws NullPointerException if o is null and this set doesn't allow - * the removal of a null value. - */ - boolean remove(Object o); - - /** - * Removes from this set all elements contained in the specified collection - * (optional operation). If the argument is a set, this returns the - * <i>asymmetric set difference</i> of the two sets. - * - * @param c the collection to remove from this set - * @return true if this set changed as a result - * @throws UnsupportedOperationException if this operation is not allowed - * @throws NullPointerException if c is null - * @throws ClassCastException if the type of any element in c is not - * a valid type for this set. - * @throws NullPointerException if some element of c is null and this - * set doesn't support removing null values. - * @see #remove(Object) - */ - boolean removeAll(Collection c); - - /** - * Retains only the elements in this set that are also in the specified - * collection (optional operation). If the argument is also a set, this - * performs the <i>intersection</i> of the two sets. - * - * @param c the collection to keep - * @return true if this set was modified - * @throws UnsupportedOperationException if this operation is not allowed - * @throws NullPointerException if c is null - * @throws ClassCastException if the type of any element in c is not - * a valid type for this set. - * @throws NullPointerException if some element of c is null and this - * set doesn't support retaining null values. - * @see #remove(Object) - */ - boolean retainAll(Collection c); - - /** - * Returns the number of elements in the set. If there are more - * than Integer.MAX_VALUE mappings, return Integer.MAX_VALUE. This is - * the <i>cardinality</i> of the set. - * - * @return the number of elements - */ - int size(); - - /** - * Returns an array containing the elements of this set. If the set - * makes a guarantee about iteration order, the array has the same - * order. The array is distinct from the set; modifying one does not - * affect the other. - * - * @return an array of this set's elements - * @see #toArray(Object[]) - */ - Object[] toArray(); - - /** - * Returns an array containing the elements of this set, of the same runtime - * type of the argument. If the given set is large enough, it is reused, - * and null is inserted in the first unused slot. Otherwise, reflection - * is used to build a new array. If the set makes a guarantee about iteration - * order, the array has the same order. The array is distinct from the set; - * modifying one does not affect the other. - * - * @param a the array to determine the return type; if it is big enough - * it is used and returned - * @return an array holding the elements of the set - * @throws ArrayStoreException if the runtime type of a is not a supertype - * of all elements in the set - * @throws NullPointerException if a is null - * @see #toArray() - */ - Object[] toArray(Object[] a); -} diff --git a/libjava/java/util/SortedMap.java b/libjava/java/util/SortedMap.java deleted file mode 100644 index acfbd0d3639..00000000000 --- a/libjava/java/util/SortedMap.java +++ /dev/null @@ -1,173 +0,0 @@ -/* SortedMap.java -- A map that makes guarantees about the order of its keys - Copyright (C) 1998, 2001, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util; - -/** - * A map which guarantees its key's iteration order. The entries in the - * map are related by the <i>natural ordering</i> of the keys if they - * are Comparable, or by the provided Comparator. Additional operations - * take advantage of the sorted nature of the map. - * <p> - * - * All keys entered in the map must be mutually comparable; in other words, - * <code>k1.compareTo(k2)</code> or <code>comparator.compare(k1, k2)</code> - * must not throw a ClassCastException. The ordering must be <i>consistent - * with equals</i> (see {@link Comparator} for this definition), if the - * map is to obey the general contract of the Map interface. If not, - * the results are well-defined, but probably not what you wanted. - * <p> - * - * It is recommended that all implementing classes provide four constructors: - * 1) one that takes no arguments and builds an empty map sorted by natural - * order of the keys; 2) one that takes a Comparator for the sorting order; - * 3) one that takes a Map and sorts according to the natural order of its - * keys; and 4) one that takes a SortedMap and sorts by the same comparator. - * Unfortunately, the Java language does not provide a way to enforce this. - * - * @author Original author unknown - * @author Eric Blake (ebb9@email.byu.edu) - * @see Map - * @see TreeMap - * @see SortedSet - * @see Comparable - * @see Comparator - * @see Collection - * @see ClassCastException - * @since 1.2 - * @status updated to 1.4 - */ -public interface SortedMap extends Map -{ - /** - * Returns the comparator used in sorting this map, or null if it is - * the keys' natural ordering. - * - * @return the sorting comparator - */ - Comparator comparator(); - - /** - * Returns the first (lowest sorted) key in the map. - * - * @return the first key - * @throws NoSuchElementException if this map is empty. - */ - Object firstKey(); - - /** - * Returns a view of the portion of the map strictly less than toKey. The - * view is backed by this map, so changes in one show up in the other. - * The submap supports all optional operations of the original. - * <p> - * - * The returned map throws an IllegalArgumentException any time a key is - * used which is out of the range of toKey. Note that the endpoint, toKey, - * is not included; if you want this value to be included, pass its successor - * object in to toKey. For example, for Integers, you could request - * <code>headMap(new Integer(limit.intValue() + 1))</code>. - * - * @param toKey the exclusive upper range of the submap - * @return the submap - * @throws ClassCastException if toKey is not comparable to the map contents - * @throws IllegalArgumentException if this is a subMap, and toKey is out - * of range - * @throws NullPointerException if toKey is null but the map does not allow - * null keys - */ - SortedMap headMap(Object toKey); - - /** - * Returns the last (highest sorted) key in the map. - * - * @return the last key - * @throws NoSuchElementException if this map is empty. - */ - Object lastKey(); - - /** - * Returns a view of the portion of the map greater than or equal to - * fromKey, and strictly less than toKey. The view is backed by this map, - * so changes in one show up in the other. The submap supports all - * optional operations of the original. - * <p> - * - * The returned map throws an IllegalArgumentException any time a key is - * used which is out of the range of fromKey and toKey. Note that the - * lower endpoint is included, but the upper is not; if you want to - * change the inclusion or exclusion of an endpoint, pass its successor - * object in instead. For example, for Integers, you could request - * <code>subMap(new Integer(lowlimit.intValue() + 1), - * new Integer(highlimit.intValue() + 1))</code> to reverse - * the inclusiveness of both endpoints. - * - * @param fromKey the inclusive lower range of the submap - * @param toKey the exclusive upper range of the submap - * @return the submap - * @throws ClassCastException if fromKey or toKey is not comparable to - * the map contents - * @throws IllegalArgumentException if this is a subMap, and fromKey or - * toKey is out of range - * @throws NullPointerException if fromKey or toKey is null but the map - * does not allow null keys - */ - SortedMap subMap(Object fromKey, Object toKey); - - /** - * Returns a view of the portion of the map greater than or equal to - * fromKey. The view is backed by this map, so changes in one show up - * in the other. The submap supports all optional operations of the original. - * <p> - * - * The returned map throws an IllegalArgumentException any time a key is - * used which is out of the range of fromKey. Note that the endpoint, fromKey, is - * included; if you do not want this value to be included, pass its successor object in - * to fromKey. For example, for Integers, you could request - * <code>tailMap(new Integer(limit.intValue() + 1))</code>. - * - * @param fromKey the inclusive lower range of the submap - * @return the submap - * @throws ClassCastException if fromKey is not comparable to the map - * contents - * @throws IllegalArgumentException if this is a subMap, and fromKey is out - * of range - * @throws NullPointerException if fromKey is null but the map does not allow - * null keys - */ - SortedMap tailMap(Object fromKey); -} diff --git a/libjava/java/util/SortedSet.java b/libjava/java/util/SortedSet.java deleted file mode 100644 index 48a24a8e0f9..00000000000 --- a/libjava/java/util/SortedSet.java +++ /dev/null @@ -1,176 +0,0 @@ -/* SortedSet.java -- A set that makes guarantees about the order of its - elements - Copyright (C) 1998, 2001, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util; - -/** - * A set which guarantees its iteration order. The elements in the set - * are related by the <i>natural ordering</i> if they are Comparable, or - * by the provided Comparator. Additional operations take advantage of - * the sorted nature of the set. - * <p> - * - * All elements entered in the set must be mutually comparable; in other words, - * <code>k1.compareTo(k2)</code> or <code>comparator.compare(k1, k2)</code> - * must not throw a ClassCastException. The ordering must be <i>consistent - * with equals</i> (see {@link Comparator} for this definition), if the - * set is to obey the general contract of the Set interface. If not, - * the results are well-defined, but probably not what you wanted. - * <p> - * - * It is recommended that all implementing classes provide four constructors: - * 1) one that takes no arguments and builds an empty set sorted by natural - * order of the elements; 2) one that takes a Comparator for the sorting order; - * 3) one that takes a Set and sorts according to the natural order of its - * elements; and 4) one that takes a SortedSet and sorts by the same - * comparator. Unfortunately, the Java language does not provide a way to - * enforce this. - * - * @author Original author unknown - * @author Eric Blake (ebb9@email.byu.edu) - * @see Set - * @see TreeSet - * @see SortedMap - * @see Collection - * @see Comparable - * @see Comparator - * @see ClassCastException - * @since 1.2 - * @status updated to 1.4 - */ -public interface SortedSet extends Set -{ - /** - * Returns the comparator used in sorting this set, or null if it is - * the elements' natural ordering. - * - * @return the sorting comparator - */ - Comparator comparator(); - - /** - * Returns the first (lowest sorted) element in the set. - * - * @return the first element - * @throws NoSuchElementException if the set is empty. - */ - Object first(); - - /** - * Returns a view of the portion of the set strictly less than toElement. The - * view is backed by this set, so changes in one show up in the other. - * The subset supports all optional operations of the original. - * <p> - * - * The returned set throws an IllegalArgumentException any time an element is - * used which is out of the range of toElement. Note that the endpoint, toElement, - * is not included; if you want this value included, pass its successor object in to - * toElement. For example, for Integers, you could request - * <code>headSet(new Integer(limit.intValue() + 1))</code>. - * - * @param toElement the exclusive upper range of the subset - * @return the subset - * @throws ClassCastException if toElement is not comparable to the set - * contents - * @throws IllegalArgumentException if this is a subSet, and toElement is out - * of range - * @throws NullPointerException if toElement is null but the set does not - * allow null elements - */ - SortedSet headSet(Object toElement); - - /** - * Returns the last (highest sorted) element in the set. - * - * @return the last element - * @throws NoSuchElementException if the set is empty. - */ - Object last(); - - /** - * Returns a view of the portion of the set greater than or equal to - * fromElement, and strictly less than toElement. The view is backed by - * this set, so changes in one show up in the other. The subset supports all - * optional operations of the original. - * <p> - * - * The returned set throws an IllegalArgumentException any time an element is - * used which is out of the range of fromElement and toElement. Note that the - * lower endpoint is included, but the upper is not; if you want to - * change the inclusion or exclusion of an endpoint, pass its successor - * object in instead. For example, for Integers, you can request - * <code>subSet(new Integer(lowlimit.intValue() + 1), - * new Integer(highlimit.intValue() + 1))</code> to reverse - * the inclusiveness of both endpoints. - * - * @param fromElement the inclusive lower range of the subset - * @param toElement the exclusive upper range of the subset - * @return the subset - * @throws ClassCastException if fromElement or toElement is not comparable - * to the set contents - * @throws IllegalArgumentException if this is a subSet, and fromElement or - * toElement is out of range - * @throws NullPointerException if fromElement or toElement is null but the - * set does not allow null elements - */ - SortedSet subSet(Object fromElement, Object toElement); - - /** - * Returns a view of the portion of the set greater than or equal to - * fromElement. The view is backed by this set, so changes in one show up - * in the other. The subset supports all optional operations of the original. - * <p> - * - * The returned set throws an IllegalArgumentException any time an element is - * used which is out of the range of fromElement. Note that the endpoint, - * fromElement, is included; if you do not want this value to be included, pass its - * successor object in to fromElement. For example, for Integers, you could request - * <code>tailSet(new Integer(limit.intValue() + 1))</code>. - * - * @param fromElement the inclusive lower range of the subset - * @return the subset - * @throws ClassCastException if fromElement is not comparable to the set - * contents - * @throws IllegalArgumentException if this is a subSet, and fromElement is - * out of range - * @throws NullPointerException if fromElement is null but the set does not - * allow null elements - */ - SortedSet tailSet(Object fromElement); -} diff --git a/libjava/java/util/Stack.java b/libjava/java/util/Stack.java deleted file mode 100644 index 730ce177cd1..00000000000 --- a/libjava/java/util/Stack.java +++ /dev/null @@ -1,158 +0,0 @@ -/* Stack.java - Class that provides a Last In First Out (LIFO) - datatype, known more commonly as a Stack - Copyright (C) 1998, 1999, 2001, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util; - -/* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3 - * "The Java Language Specification", ISBN 0-201-63451-1 - * plus online API docs for JDK 1.2 beta from http://www.javasoft.com. - * Status: Believed complete and correct - -/** - * Stack provides a Last In First Out (LIFO) data type, commonly known - * as a Stack. Stack itself extends Vector and provides the additional - * methods for stack manipulation (push, pop, peek). You can also seek for - * the 1-based position of an element on the stack. - * - * @author Warren Levy (warrenl@cygnus.com) - * @author Eric Blake (ebb9@email.byu.edu) - * @see List - * @see AbstractList - * @see LinkedList - * @since 1.0 - * @status updated to 1.4 - */ -public class Stack extends Vector -{ - // We could use Vector methods internally for the following methods, - // but have used Vector fields directly for efficiency (i.e. this - // often reduces out duplicate bounds checking). - - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = 1224463164541339165L; - - /** - * This constructor creates a new Stack, initially empty - */ - public Stack() - { - } - - /** - * Pushes an Object onto the top of the stack. This method is effectively - * the same as addElement(item). - * - * @param item the Object to push onto the stack - * @return the Object pushed onto the stack - * @see Vector#addElement(Object) - */ - public Object push(Object item) - { - // When growing the Stack, use the Vector routines in case more - // memory is needed. - // Note: spec indicates that this method *always* returns obj passed in! - - addElement(item); - return item; - } - - /** - * Pops an item from the stack and returns it. The item popped is - * removed from the Stack. - * - * @return the Object popped from the stack - * @throws EmptyStackException if the stack is empty - */ - public synchronized Object pop() - { - if (elementCount == 0) - throw new EmptyStackException(); - - modCount++; - Object obj = elementData[--elementCount]; - - // Set topmost element to null to assist the gc in cleanup. - elementData[elementCount] = null; - return obj; - } - - /** - * Returns the top Object on the stack without removing it. - * - * @return the top Object on the stack - * @throws EmptyStackException if the stack is empty - */ - public synchronized Object peek() - { - if (elementCount == 0) - throw new EmptyStackException(); - - return elementData[elementCount - 1]; - } - - /** - * Tests if the stack is empty. - * - * @return true if the stack contains no items, false otherwise - */ - public synchronized boolean empty() - { - return elementCount == 0; - } - - /** - * Returns the position of an Object on the stack, with the top - * most Object being at position 1, and each Object deeper in the - * stack at depth + 1. - * - * @param o The object to search for - * @return The 1 based depth of the Object, or -1 if the Object - * is not on the stack - */ - public synchronized int search(Object o) - { - int i = elementCount; - while (--i >= 0) - if (equals(o, elementData[i])) - return elementCount - i; - return -1; - } -} diff --git a/libjava/java/util/StringTokenizer.java b/libjava/java/util/StringTokenizer.java deleted file mode 100644 index dcc192c855a..00000000000 --- a/libjava/java/util/StringTokenizer.java +++ /dev/null @@ -1,268 +0,0 @@ -/* StringTokenizer -- breaks a String into tokens - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util; - -/** - * This class splits a string into tokens. The caller can set on which - * delimiters the string should be split and if the delimiters should be - * returned. This is much simpler than {@link java.io.StreamTokenizer}. - * - * <p>You may change the delimiter set on the fly by calling - * nextToken(String). But the semantic is quite difficult; it even - * depends on calling <code>hasMoreTokens()</code>. You should call - * <code>hasMoreTokens()</code> before, otherwise the old delimiters - * after the last token are candidates for being returned. - * - * <p>If you want to get the delimiters, you have to use the three argument - * constructor. The delimiters are returned as token consisting of a - * single character. - * - * @author Jochen Hoenicke - * @author Warren Levy (warrenl@cygnus.com) - * @see java.io.StreamTokenizer - * @status updated to 1.4 - */ -public class StringTokenizer implements Enumeration -{ - // WARNING: StringTokenizer is a CORE class in the bootstrap cycle. See the - // comments in vm/reference/java/lang/Runtime for implications of this fact. - - /** - * The position in the str, where we currently are. - */ - private int pos; - - /** - * The string that should be split into tokens. - */ - private final String str; - - /** - * The length of the string. - */ - private final int len; - - /** - * The string containing the delimiter characters. - */ - private String delim; - - /** - * Tells, if we should return the delimiters. - */ - private final boolean retDelims; - - /** - * Creates a new StringTokenizer for the string <code>str</code>, - * that should split on the default delimiter set (space, tab, - * newline, return and formfeed), and which doesn't return the - * delimiters. - * - * @param str The string to split - * @throws NullPointerException if str is null - */ - public StringTokenizer(String str) - { - this(str, " \t\n\r\f", false); - } - - /** - * Create a new StringTokenizer, that splits the given string on - * the given delimiter characters. It doesn't return the delimiter - * characters. - * - * @param str the string to split - * @param delim a string containing all delimiter characters - * @throws NullPointerException if either argument is null - */ - public StringTokenizer(String str, String delim) - { - this(str, delim, false); - } - - /** - * Create a new StringTokenizer, that splits the given string on - * the given delimiter characters. If you set - * <code>returnDelims</code> to <code>true</code>, the delimiter - * characters are returned as tokens of their own. The delimiter - * tokens always consist of a single character. - * - * @param str the string to split - * @param delim a string containing all delimiter characters - * @param returnDelims tells, if you want to get the delimiters - * @throws NullPointerException if str or delim is null - */ - public StringTokenizer(String str, String delim, boolean returnDelims) - { - len = str.length(); - this.str = str; - // The toString() hack causes the NullPointerException. - this.delim = delim.toString(); - this.retDelims = returnDelims; - this.pos = 0; - } - - /** - * Tells if there are more tokens. - * - * @return true if the next call of nextToken() will succeed - */ - public boolean hasMoreTokens() - { - if (! retDelims) - { - while (pos < len && delim.indexOf(str.charAt(pos)) >= 0) - pos++; - } - return pos < len; - } - - /** - * Returns the nextToken, changing the delimiter set to the given - * <code>delim</code>. The change of the delimiter set is - * permanent, ie. the next call of nextToken(), uses the same - * delimiter set. - * - * @param delim a string containing the new delimiter characters - * @return the next token with respect to the new delimiter characters - * @throws NoSuchElementException if there are no more tokens - * @throws NullPointerException if delim is null - */ - public String nextToken(String delim) throws NoSuchElementException - { - this.delim = delim; - return nextToken(); - } - - /** - * Returns the nextToken of the string. - * - * @return the next token with respect to the current delimiter characters - * @throws NoSuchElementException if there are no more tokens - */ - public String nextToken() throws NoSuchElementException - { - if (pos < len && delim.indexOf(str.charAt(pos)) >= 0) - { - if (retDelims) - return str.substring(pos, ++pos); - while (++pos < len && delim.indexOf(str.charAt(pos)) >= 0); - } - if (pos < len) - { - int start = pos; - while (++pos < len && delim.indexOf(str.charAt(pos)) < 0); - - return str.substring(start, pos); - } - throw new NoSuchElementException(); - } - - /** - * This does the same as hasMoreTokens. This is the - * <code>Enumeration</code> interface method. - * - * @return true, if the next call of nextElement() will succeed - * @see #hasMoreTokens() - */ - public boolean hasMoreElements() - { - return hasMoreTokens(); - } - - /** - * This does the same as nextTokens. This is the - * <code>Enumeration</code> interface method. - * - * @return the next token with respect to the current delimiter characters - * @throws NoSuchElementException if there are no more tokens - * @see #nextToken() - */ - public Object nextElement() throws NoSuchElementException - { - return nextToken(); - } - - /** - * This counts the number of remaining tokens in the string, with - * respect to the current delimiter set. - * - * @return the number of times <code>nextTokens()</code> will succeed - * @see #nextToken() - */ - public int countTokens() - { - int count = 0; - int delimiterCount = 0; - boolean tokenFound = false; // Set when a non-delimiter is found - int tmpPos = pos; - - // Note for efficiency, we count up the delimiters rather than check - // retDelims every time we encounter one. That way, we can - // just do the conditional once at the end of the method - while (tmpPos < len) - { - if (delim.indexOf(str.charAt(tmpPos++)) >= 0) - { - if (tokenFound) - { - // Got to the end of a token - count++; - tokenFound = false; - } - delimiterCount++; // Increment for this delimiter - } - else - { - tokenFound = true; - // Get to the end of the token - while (tmpPos < len - && delim.indexOf(str.charAt(tmpPos)) < 0) - ++tmpPos; - } - } - - // Make sure to count the last token - if (tokenFound) - count++; - - // if counting delmiters add them into the token count - return retDelims ? count + delimiterCount : count; - } -} // class StringTokenizer diff --git a/libjava/java/util/TimeZone.java b/libjava/java/util/TimeZone.java deleted file mode 100644 index 6850043f2b4..00000000000 --- a/libjava/java/util/TimeZone.java +++ /dev/null @@ -1,1331 +0,0 @@ -/* java.util.TimeZone - Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004 - Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util; - -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.text.DateFormatSymbols; - -/** - * This class represents a time zone offset and handles daylight savings. - * - * You can get the default time zone with <code>getDefault</code>. - * This represents the time zone where program is running. - * - * Another way to create a time zone is <code>getTimeZone</code>, where - * you can give an identifier as parameter. For instance, the identifier - * of the Central European Time zone is "CET". - * - * With the <code>getAvailableIDs</code> method, you can get all the - * supported time zone identifiers. - * - * @see Calendar - * @see SimpleTimeZone - * @author Jochen Hoenicke - */ -public abstract class TimeZone implements java.io.Serializable, Cloneable -{ - - /** - * Constant used to indicate that a short timezone abbreviation should - * be returned, such as "EST" - */ - public static final int SHORT = 0; - - /** - * Constant used to indicate that a long timezone name should be - * returned, such as "Eastern Standard Time". - */ - public static final int LONG = 1; - - /** - * The time zone identifier, e.g. PST. - */ - private String ID; - - /** - * The default time zone, as returned by getDefault. - */ - private static TimeZone defaultZone0; - - /** - * Tries to get the default TimeZone for this system if not already - * set. It will call <code>getDefaultTimeZone(String)</code> with - * the result of <code>System.getProperty("user.timezone")</code>. - * If that fails it calls <code>VMTimeZone.getDefaultTimeZoneId()</code>. - * If that also fails GMT is returned. - */ - private static synchronized TimeZone defaultZone() - { - /* Look up default timezone */ - if (defaultZone0 == null) - { - defaultZone0 = (TimeZone) AccessController.doPrivileged - (new PrivilegedAction() - { - public Object run() - { - TimeZone zone = null; - - // Prefer System property user.timezone. - String tzid = System.getProperty("user.timezone"); - if (tzid != null && !tzid.equals("")) - zone = getDefaultTimeZone(tzid); - - // Try platfom specific way. - if (zone == null) - zone = VMTimeZone.getDefaultTimeZoneId(); - - // Fall back on GMT. - if (zone == null) - zone = (TimeZone) timezones().get("GMT"); - - return zone; - } - }); - } - - return defaultZone0; - } - - private static final long serialVersionUID = 3581463369166924961L; - - /** - * HashMap for timezones by ID. - */ - private static HashMap timezones0; - /* initialize this static field lazily to overhead if - * it is not needed: - */ - // Package-private to avoid a trampoline. - static synchronized HashMap timezones() - { - if (timezones0 == null) - { - HashMap timezones = new HashMap(); - timezones0 = timezones; - - TimeZone tz; - // Automatically generated by scripts/timezones.pl - // XXX - Should we read this data from a file? - tz = new SimpleTimeZone(-11000 * 3600, "MIT"); - timezones0.put("MIT", tz); - timezones0.put("Pacific/Apia", tz); - timezones0.put("Pacific/Midway", tz); - timezones0.put("Pacific/Niue", tz); - timezones0.put("Pacific/Pago_Pago", tz); - tz = new SimpleTimeZone - (-10000 * 3600, "America/Adak", - Calendar.APRIL, 1, Calendar.SUNDAY, 2000 * 3600, - Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600); - timezones0.put("America/Adak", tz); - tz = new SimpleTimeZone(-10000 * 3600, "HST"); - timezones0.put("HST", tz); - timezones0.put("Pacific/Fakaofo", tz); - timezones0.put("Pacific/Honolulu", tz); - timezones0.put("Pacific/Johnston", tz); - timezones0.put("Pacific/Rarotonga", tz); - timezones0.put("Pacific/Tahiti", tz); - tz = new SimpleTimeZone(-9500 * 3600, "Pacific/Marquesas"); - timezones0.put("Pacific/Marquesas", tz); - tz = new SimpleTimeZone - (-9000 * 3600, "AST", - Calendar.APRIL, 1, Calendar.SUNDAY, 2000 * 3600, - Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600); - timezones0.put("AST", tz); - timezones0.put("America/Anchorage", tz); - timezones0.put("America/Juneau", tz); - timezones0.put("America/Nome", tz); - timezones0.put("America/Yakutat", tz); - tz = new SimpleTimeZone(-9000 * 3600, "Pacific/Gambier"); - timezones0.put("Pacific/Gambier", tz); - tz = new SimpleTimeZone - (-8000 * 3600, "PST", - Calendar.APRIL, 1, Calendar.SUNDAY, 2000 * 3600, - Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600); - timezones0.put("PST", tz); - timezones0.put("PST8PDT", tz); - timezones0.put("America/Dawson", tz); - timezones0.put("America/Los_Angeles", tz); - timezones0.put("America/Tijuana", tz); - timezones0.put("America/Vancouver", tz); - timezones0.put("America/Whitehorse", tz); - timezones0.put("US/Pacific-New", tz); - tz = new SimpleTimeZone(-8000 * 3600, "Pacific/Pitcairn"); - timezones0.put("Pacific/Pitcairn", tz); - tz = new SimpleTimeZone - (-7000 * 3600, "MST", - Calendar.APRIL, 1, Calendar.SUNDAY, 2000 * 3600, - Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600); - timezones0.put("MST", tz); - timezones0.put("MST7MDT", tz); - timezones0.put("America/Boise", tz); - timezones0.put("America/Chihuahua", tz); - timezones0.put("America/Denver", tz); - timezones0.put("America/Edmonton", tz); - timezones0.put("America/Inuvik", tz); - timezones0.put("America/Mazatlan", tz); - timezones0.put("America/Shiprock", tz); - timezones0.put("America/Yellowknife", tz); - tz = new SimpleTimeZone(-7000 * 3600, "MST7"); - timezones0.put("MST7", tz); - timezones0.put("PNT", tz); - timezones0.put("America/Dawson_Creek", tz); - timezones0.put("America/Hermosillo", tz); - timezones0.put("America/Phoenix", tz); - tz = new SimpleTimeZone - (-6000 * 3600, "CST", - Calendar.APRIL, 1, Calendar.SUNDAY, 2000 * 3600, - Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600); - timezones0.put("CST", tz); - timezones0.put("CST6CDT", tz); - timezones0.put("America/Cambridge_Bay", tz); - timezones0.put("America/Cancun", tz); - timezones0.put("America/Chicago", tz); - timezones0.put("America/Menominee", tz); - timezones0.put("America/Merida", tz); - timezones0.put("America/Mexico_City", tz); - timezones0.put("America/Monterrey", tz); - timezones0.put("America/Rainy_River", tz); - timezones0.put("America/Winnipeg", tz); - tz = new SimpleTimeZone(-6000 * 3600, "America/Belize"); - timezones0.put("America/Belize", tz); - timezones0.put("America/Costa_Rica", tz); - timezones0.put("America/El_Salvador", tz); - timezones0.put("America/Guatemala", tz); - timezones0.put("America/Managua", tz); - timezones0.put("America/Regina", tz); - timezones0.put("America/Swift_Current", tz); - timezones0.put("America/Tegucigalpa", tz); - timezones0.put("Pacific/Galapagos", tz); - tz = new SimpleTimeZone - (-6000 * 3600, "Pacific/Easter", - Calendar.OCTOBER, 9, -Calendar.SUNDAY, 0 * 3600, - Calendar.MARCH, 9, -Calendar.SUNDAY, 0 * 3600); - timezones0.put("Pacific/Easter", tz); - tz = new SimpleTimeZone - (-5000 * 3600, "America/Grand_Turk", - Calendar.APRIL, 1, Calendar.SUNDAY, 0 * 3600, - Calendar.OCTOBER, -1, Calendar.SUNDAY, 0 * 3600); - timezones0.put("America/Grand_Turk", tz); - timezones0.put("America/Havana", tz); - tz = new SimpleTimeZone(-5000 * 3600, "EST5"); - timezones0.put("EST5", tz); - timezones0.put("IET", tz); - timezones0.put("America/Bogota", tz); - timezones0.put("America/Cayman", tz); - timezones0.put("America/Eirunepe", tz); - timezones0.put("America/Guayaquil", tz); - timezones0.put("America/Indiana/Indianapolis", tz); - timezones0.put("America/Indiana/Knox", tz); - timezones0.put("America/Indiana/Marengo", tz); - timezones0.put("America/Indiana/Vevay", tz); - timezones0.put("America/Indianapolis", tz); - timezones0.put("America/Iqaluit", tz); - timezones0.put("America/Jamaica", tz); - timezones0.put("America/Lima", tz); - timezones0.put("America/Panama", tz); - timezones0.put("America/Pangnirtung", tz); - timezones0.put("America/Port-au-Prince", tz); - timezones0.put("America/Porto_Acre", tz); - timezones0.put("America/Rankin_Inlet", tz); - tz = new SimpleTimeZone - (-5000 * 3600, "EST", - Calendar.APRIL, 1, Calendar.SUNDAY, 2000 * 3600, - Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600); - timezones0.put("EST", tz); - timezones0.put("EST5EDT", tz); - timezones0.put("America/Detroit", tz); - timezones0.put("America/Kentucky/Louisville", tz); - timezones0.put("America/Kentucky/Monticello", tz); - timezones0.put("America/Louisville", tz); - timezones0.put("America/Montreal", tz); - timezones0.put("America/Nassau", tz); - timezones0.put("America/New_York", tz); - timezones0.put("America/Nipigon", tz); - timezones0.put("America/Thunder_Bay", tz); - tz = new SimpleTimeZone(-4000 * 3600, "PRT"); - timezones0.put("PRT", tz); - timezones0.put("America/Anguilla", tz); - timezones0.put("America/Antigua", tz); - timezones0.put("America/Aruba", tz); - timezones0.put("America/Barbados", tz); - timezones0.put("America/Boa_Vista", tz); - timezones0.put("America/Caracas", tz); - timezones0.put("America/Curacao", tz); - timezones0.put("America/Dominica", tz); - timezones0.put("America/Grenada", tz); - timezones0.put("America/Guadeloupe", tz); - timezones0.put("America/Guyana", tz); - timezones0.put("America/La_Paz", tz); - timezones0.put("America/Manaus", tz); - timezones0.put("America/Martinique", tz); - timezones0.put("America/Montserrat", tz); - timezones0.put("America/Port_of_Spain", tz); - timezones0.put("America/Porto_Velho", tz); - timezones0.put("America/Puerto_Rico", tz); - timezones0.put("America/Santo_Domingo", tz); - timezones0.put("America/St_Kitts", tz); - timezones0.put("America/St_Lucia", tz); - timezones0.put("America/St_Thomas", tz); - timezones0.put("America/St_Vincent", tz); - timezones0.put("America/Tortola", tz); - tz = new SimpleTimeZone - (-4000 * 3600, "America/Asuncion", - Calendar.OCTOBER, 1, Calendar.SUNDAY, 0 * 3600, - Calendar.FEBRUARY, -1, Calendar.SUNDAY, 0 * 3600); - timezones0.put("America/Asuncion", tz); - tz = new SimpleTimeZone - (-4000 * 3600, "America/Cuiaba", - Calendar.OCTOBER, 2, Calendar.SUNDAY, 0 * 3600, - Calendar.FEBRUARY, 3, Calendar.SUNDAY, 0 * 3600); - timezones0.put("America/Cuiaba", tz); - tz = new SimpleTimeZone - (-4000 * 3600, "America/Goose_Bay", - Calendar.APRIL, 1, Calendar.SUNDAY, 60000, - Calendar.OCTOBER, -1, Calendar.SUNDAY, 60000); - timezones0.put("America/Goose_Bay", tz); - tz = new SimpleTimeZone - (-4000 * 3600, "America/Glace_Bay", - Calendar.APRIL, 1, Calendar.SUNDAY, 2000 * 3600, - Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600); - timezones0.put("America/Glace_Bay", tz); - timezones0.put("America/Halifax", tz); - timezones0.put("America/Thule", tz); - timezones0.put("Atlantic/Bermuda", tz); - tz = new SimpleTimeZone - (-4000 * 3600, "America/Santiago", - Calendar.OCTOBER, 9, -Calendar.SUNDAY, 0 * 3600, - Calendar.MARCH, 9, -Calendar.SUNDAY, 0 * 3600); - timezones0.put("America/Santiago", tz); - timezones0.put("Antarctica/Palmer", tz); - tz = new SimpleTimeZone - (-4000 * 3600, "Atlantic/Stanley", - Calendar.SEPTEMBER, 2, Calendar.SUNDAY, 0 * 3600, - Calendar.APRIL, 16, -Calendar.SUNDAY, 0 * 3600); - timezones0.put("Atlantic/Stanley", tz); - tz = new SimpleTimeZone - (-3500 * 3600, "CNT", - Calendar.APRIL, 1, Calendar.SUNDAY, 60000, - Calendar.OCTOBER, -1, Calendar.SUNDAY, 60000); - timezones0.put("CNT", tz); - timezones0.put("America/St_Johns", tz); - tz = new SimpleTimeZone - (-3000 * 3600, "America/Araguaina", - Calendar.OCTOBER, 2, Calendar.SUNDAY, 0 * 3600, - Calendar.FEBRUARY, 3, Calendar.SUNDAY, 0 * 3600); - timezones0.put("America/Araguaina", tz); - timezones0.put("America/Sao_Paulo", tz); - tz = new SimpleTimeZone(-3000 * 3600, "AGT"); - timezones0.put("AGT", tz); - timezones0.put("America/Belem", tz); - timezones0.put("America/Buenos_Aires", tz); - timezones0.put("America/Catamarca", tz); - timezones0.put("America/Cayenne", tz); - timezones0.put("America/Cordoba", tz); - timezones0.put("America/Fortaleza", tz); - timezones0.put("America/Jujuy", tz); - timezones0.put("America/Maceio", tz); - timezones0.put("America/Mendoza", tz); - timezones0.put("America/Montevideo", tz); - timezones0.put("America/Paramaribo", tz); - timezones0.put("America/Recife", tz); - timezones0.put("America/Rosario", tz); - tz = new SimpleTimeZone - (-3000 * 3600, "America/Godthab", - Calendar.MARCH, 30, -Calendar.SATURDAY, 22000 * 3600, - Calendar.OCTOBER, 30, -Calendar.SATURDAY, 22000 * 3600); - timezones0.put("America/Godthab", tz); - tz = new SimpleTimeZone - (-3000 * 3600, "America/Miquelon", - Calendar.APRIL, 1, Calendar.SUNDAY, 2000 * 3600, - Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600); - timezones0.put("America/Miquelon", tz); - tz = new SimpleTimeZone(-2000 * 3600, "America/Noronha"); - timezones0.put("America/Noronha", tz); - timezones0.put("Atlantic/South_Georgia", tz); - tz = new SimpleTimeZone - (-1000 * 3600, "America/Scoresbysund", - Calendar.MARCH, -1, Calendar.SUNDAY, 0 * 3600, - Calendar.OCTOBER, -1, Calendar.SUNDAY, 0 * 3600); - timezones0.put("America/Scoresbysund", tz); - timezones0.put("Atlantic/Azores", tz); - tz = new SimpleTimeZone(-1000 * 3600, "Atlantic/Cape_Verde"); - timezones0.put("Atlantic/Cape_Verde", tz); - timezones0.put("Atlantic/Jan_Mayen", tz); - tz = new SimpleTimeZone(0 * 3600, "GMT"); - timezones0.put("GMT", tz); - timezones0.put("UTC", tz); - timezones0.put("Africa/Abidjan", tz); - timezones0.put("Africa/Accra", tz); - timezones0.put("Africa/Bamako", tz); - timezones0.put("Africa/Banjul", tz); - timezones0.put("Africa/Bissau", tz); - timezones0.put("Africa/Casablanca", tz); - timezones0.put("Africa/Conakry", tz); - timezones0.put("Africa/Dakar", tz); - timezones0.put("Africa/El_Aaiun", tz); - timezones0.put("Africa/Freetown", tz); - timezones0.put("Africa/Lome", tz); - timezones0.put("Africa/Monrovia", tz); - timezones0.put("Africa/Nouakchott", tz); - timezones0.put("Africa/Ouagadougou", tz); - timezones0.put("Africa/Sao_Tome", tz); - timezones0.put("Africa/Timbuktu", tz); - timezones0.put("Atlantic/Reykjavik", tz); - timezones0.put("Atlantic/St_Helena", tz); - timezones0.put("Europe/Belfast", tz); - timezones0.put("Europe/Dublin", tz); - timezones0.put("Europe/London", tz); - tz = new SimpleTimeZone - (0 * 3600, "WET", - Calendar.MARCH, -1, Calendar.SUNDAY, 1000 * 3600, - Calendar.OCTOBER, -1, Calendar.SUNDAY, 1000 * 3600); - timezones0.put("WET", tz); - timezones0.put("Atlantic/Canary", tz); - timezones0.put("Atlantic/Faeroe", tz); - timezones0.put("Atlantic/Madeira", tz); - timezones0.put("Europe/Lisbon", tz); - tz = new SimpleTimeZone(1000 * 3600, "Africa/Algiers"); - timezones0.put("Africa/Algiers", tz); - timezones0.put("Africa/Bangui", tz); - timezones0.put("Africa/Brazzaville", tz); - timezones0.put("Africa/Douala", tz); - timezones0.put("Africa/Kinshasa", tz); - timezones0.put("Africa/Lagos", tz); - timezones0.put("Africa/Libreville", tz); - timezones0.put("Africa/Luanda", tz); - timezones0.put("Africa/Malabo", tz); - timezones0.put("Africa/Ndjamena", tz); - timezones0.put("Africa/Niamey", tz); - timezones0.put("Africa/Porto-Novo", tz); - timezones0.put("Africa/Tunis", tz); - tz = new SimpleTimeZone - (1000 * 3600, "Africa/Windhoek", - Calendar.SEPTEMBER, 1, Calendar.SUNDAY, 2000 * 3600, - Calendar.APRIL, 1, Calendar.SUNDAY, 2000 * 3600); - timezones0.put("Africa/Windhoek", tz); - tz = new SimpleTimeZone - (1000 * 3600, "CET", - Calendar.MARCH, -1, Calendar.SUNDAY, 2000 * 3600, - Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600); - timezones0.put("CET", tz); - timezones0.put("CEST", tz); - timezones0.put("ECT", tz); - timezones0.put("MET", tz); - timezones0.put("Africa/Ceuta", tz); - timezones0.put("Arctic/Longyearbyen", tz); - timezones0.put("Europe/Amsterdam", tz); - timezones0.put("Europe/Andorra", tz); - timezones0.put("Europe/Belgrade", tz); - timezones0.put("Europe/Berlin", tz); - timezones0.put("Europe/Bratislava", tz); - timezones0.put("Europe/Brussels", tz); - timezones0.put("Europe/Budapest", tz); - timezones0.put("Europe/Copenhagen", tz); - timezones0.put("Europe/Gibraltar", tz); - timezones0.put("Europe/Ljubljana", tz); - timezones0.put("Europe/Luxembourg", tz); - timezones0.put("Europe/Madrid", tz); - timezones0.put("Europe/Malta", tz); - timezones0.put("Europe/Monaco", tz); - timezones0.put("Europe/Oslo", tz); - timezones0.put("Europe/Paris", tz); - timezones0.put("Europe/Prague", tz); - timezones0.put("Europe/Rome", tz); - timezones0.put("Europe/San_Marino", tz); - timezones0.put("Europe/Sarajevo", tz); - timezones0.put("Europe/Skopje", tz); - timezones0.put("Europe/Stockholm", tz); - timezones0.put("Europe/Tirane", tz); - timezones0.put("Europe/Vaduz", tz); - timezones0.put("Europe/Vatican", tz); - timezones0.put("Europe/Vienna", tz); - timezones0.put("Europe/Warsaw", tz); - timezones0.put("Europe/Zagreb", tz); - timezones0.put("Europe/Zurich", tz); - tz = new SimpleTimeZone - (2000 * 3600, "ART", - Calendar.APRIL, -1, Calendar.FRIDAY, 0 * 3600, - Calendar.SEPTEMBER, -1, Calendar.THURSDAY, 23000 * 3600); - timezones0.put("ART", tz); - timezones0.put("Africa/Cairo", tz); - tz = new SimpleTimeZone(2000 * 3600, "CAT"); - timezones0.put("CAT", tz); - timezones0.put("Africa/Blantyre", tz); - timezones0.put("Africa/Bujumbura", tz); - timezones0.put("Africa/Gaborone", tz); - timezones0.put("Africa/Harare", tz); - timezones0.put("Africa/Johannesburg", tz); - timezones0.put("Africa/Kigali", tz); - timezones0.put("Africa/Lubumbashi", tz); - timezones0.put("Africa/Lusaka", tz); - timezones0.put("Africa/Maputo", tz); - timezones0.put("Africa/Maseru", tz); - timezones0.put("Africa/Mbabane", tz); - timezones0.put("Africa/Tripoli", tz); - timezones0.put("Europe/Riga", tz); - timezones0.put("Europe/Tallinn", tz); - timezones0.put("Europe/Vilnius", tz); - tz = new SimpleTimeZone - (2000 * 3600, "Asia/Amman", - Calendar.MARCH, -1, Calendar.THURSDAY, 0 * 3600, - Calendar.SEPTEMBER, -1, Calendar.THURSDAY, 0 * 3600); - timezones0.put("Asia/Amman", tz); - tz = new SimpleTimeZone - (2000 * 3600, "Asia/Beirut", - Calendar.MARCH, -1, Calendar.SUNDAY, 0 * 3600, - Calendar.OCTOBER, -1, Calendar.SUNDAY, 0 * 3600); - timezones0.put("Asia/Beirut", tz); - tz = new SimpleTimeZone - (2000 * 3600, "Asia/Damascus", - Calendar.APRIL, 1, 0, 0 * 3600, - Calendar.OCTOBER, 1, 0, 0 * 3600); - timezones0.put("Asia/Damascus", tz); - tz = new SimpleTimeZone - (2000 * 3600, "Asia/Gaza", - Calendar.APRIL, 3, Calendar.FRIDAY, 0 * 3600, - Calendar.OCTOBER, 3, Calendar.FRIDAY, 0 * 3600); - timezones0.put("Asia/Gaza", tz); - tz = new SimpleTimeZone - (2000 * 3600, "Asia/Jerusalem", - Calendar.APRIL, 1, 0, 1000 * 3600, - Calendar.OCTOBER, 1, 0, 1000 * 3600); - timezones0.put("Asia/Jerusalem", tz); - tz = new SimpleTimeZone - (2000 * 3600, "EET", - Calendar.MARCH, -1, Calendar.SUNDAY, 3000 * 3600, - Calendar.OCTOBER, -1, Calendar.SUNDAY, 3000 * 3600); - timezones0.put("EET", tz); - timezones0.put("Asia/Istanbul", tz); - timezones0.put("Asia/Nicosia", tz); - timezones0.put("Europe/Athens", tz); - timezones0.put("Europe/Bucharest", tz); - timezones0.put("Europe/Chisinau", tz); - timezones0.put("Europe/Helsinki", tz); - timezones0.put("Europe/Istanbul", tz); - timezones0.put("Europe/Kiev", tz); - timezones0.put("Europe/Nicosia", tz); - timezones0.put("Europe/Simferopol", tz); - timezones0.put("Europe/Sofia", tz); - timezones0.put("Europe/Uzhgorod", tz); - timezones0.put("Europe/Zaporozhye", tz); - tz = new SimpleTimeZone - (2000 * 3600, "Europe/Kaliningrad", - Calendar.MARCH, -1, Calendar.SUNDAY, 2000 * 3600, - Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600); - timezones0.put("Europe/Kaliningrad", tz); - timezones0.put("Europe/Minsk", tz); - tz = new SimpleTimeZone - (3000 * 3600, "Asia/Baghdad", - Calendar.APRIL, 1, 0, 3000 * 3600, - Calendar.OCTOBER, 1, 0, 3000 * 3600); - timezones0.put("Asia/Baghdad", tz); - tz = new SimpleTimeZone - (3000 * 3600, "Europe/Moscow", - Calendar.MARCH, -1, Calendar.SUNDAY, 2000 * 3600, - Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600); - timezones0.put("Europe/Moscow", tz); - timezones0.put("Europe/Tiraspol", tz); - tz = new SimpleTimeZone(3000 * 3600, "EAT"); - timezones0.put("EAT", tz); - timezones0.put("Africa/Addis_Ababa", tz); - timezones0.put("Africa/Asmera", tz); - timezones0.put("Africa/Dar_es_Salaam", tz); - timezones0.put("Africa/Djibouti", tz); - timezones0.put("Africa/Kampala", tz); - timezones0.put("Africa/Khartoum", tz); - timezones0.put("Africa/Mogadishu", tz); - timezones0.put("Africa/Nairobi", tz); - timezones0.put("Antarctica/Syowa", tz); - timezones0.put("Asia/Aden", tz); - timezones0.put("Asia/Bahrain", tz); - timezones0.put("Asia/Kuwait", tz); - timezones0.put("Asia/Qatar", tz); - timezones0.put("Asia/Riyadh", tz); - timezones0.put("Indian/Antananarivo", tz); - timezones0.put("Indian/Comoro", tz); - timezones0.put("Indian/Mayotte", tz); - tz = new SimpleTimeZone(3500 * 3600, "Asia/Tehran"); - timezones0.put("Asia/Tehran", tz); - tz = new SimpleTimeZone - (4000 * 3600, "Asia/Baku", - Calendar.MARCH, -1, Calendar.SUNDAY, 1000 * 3600, - Calendar.OCTOBER, -1, Calendar.SUNDAY, 1000 * 3600); - timezones0.put("Asia/Baku", tz); - tz = new SimpleTimeZone - (4000 * 3600, "Asia/Aqtau", - Calendar.MARCH, -1, Calendar.SUNDAY, 0 * 3600, - Calendar.OCTOBER, -1, Calendar.SUNDAY, 0 * 3600); - timezones0.put("Asia/Aqtau", tz); - timezones0.put("Asia/Tbilisi", tz); - tz = new SimpleTimeZone - (4000 * 3600, "Asia/Yerevan", - Calendar.MARCH, -1, Calendar.SUNDAY, 2000 * 3600, - Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600); - timezones0.put("Asia/Yerevan", tz); - timezones0.put("Europe/Samara", tz); - tz = new SimpleTimeZone(4000 * 3600, "NET"); - timezones0.put("NET", tz); - timezones0.put("Asia/Dubai", tz); - timezones0.put("Asia/Muscat", tz); - timezones0.put("Indian/Mahe", tz); - timezones0.put("Indian/Mauritius", tz); - timezones0.put("Indian/Reunion", tz); - tz = new SimpleTimeZone(4500 * 3600, "Asia/Kabul"); - timezones0.put("Asia/Kabul", tz); - tz = new SimpleTimeZone - (5000 * 3600, "Asia/Aqtobe", - Calendar.MARCH, -1, Calendar.SUNDAY, 0 * 3600, - Calendar.OCTOBER, -1, Calendar.SUNDAY, 0 * 3600); - timezones0.put("Asia/Aqtobe", tz); - tz = new SimpleTimeZone - (5000 * 3600, "Asia/Bishkek", - Calendar.MARCH, -1, Calendar.SUNDAY, 2500 * 3600, - Calendar.OCTOBER, -1, Calendar.SUNDAY, 2500 * 3600); - timezones0.put("Asia/Bishkek", tz); - tz = new SimpleTimeZone - (5000 * 3600, "Asia/Yekaterinburg", - Calendar.MARCH, -1, Calendar.SUNDAY, 2000 * 3600, - Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600); - timezones0.put("Asia/Yekaterinburg", tz); - tz = new SimpleTimeZone(5000 * 3600, "PLT"); - timezones0.put("PLT", tz); - timezones0.put("Asia/Ashgabat", tz); - timezones0.put("Asia/Dushanbe", tz); - timezones0.put("Asia/Karachi", tz); - timezones0.put("Asia/Samarkand", tz); - timezones0.put("Asia/Tashkent", tz); - timezones0.put("Indian/Chagos", tz); - timezones0.put("Indian/Kerguelen", tz); - timezones0.put("Indian/Maldives", tz); - tz = new SimpleTimeZone(5500 * 3600, "IST"); - timezones0.put("IST", tz); - timezones0.put("Asia/Calcutta", tz); - tz = new SimpleTimeZone(5750 * 3600, "Asia/Katmandu"); - timezones0.put("Asia/Katmandu", tz); - tz = new SimpleTimeZone(6000 * 3600, "BST"); - timezones0.put("BST", tz); - timezones0.put("Antarctica/Mawson", tz); - timezones0.put("Asia/Colombo", tz); - timezones0.put("Asia/Dhaka", tz); - timezones0.put("Asia/Thimphu", tz); - tz = new SimpleTimeZone - (6000 * 3600, "Asia/Almaty", - Calendar.MARCH, -1, Calendar.SUNDAY, 0 * 3600, - Calendar.OCTOBER, -1, Calendar.SUNDAY, 0 * 3600); - timezones0.put("Asia/Almaty", tz); - tz = new SimpleTimeZone - (6000 * 3600, "Asia/Novosibirsk", - Calendar.MARCH, -1, Calendar.SUNDAY, 2000 * 3600, - Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600); - timezones0.put("Asia/Novosibirsk", tz); - timezones0.put("Asia/Omsk", tz); - tz = new SimpleTimeZone(6500 * 3600, "Asia/Rangoon"); - timezones0.put("Asia/Rangoon", tz); - timezones0.put("Indian/Cocos", tz); - tz = new SimpleTimeZone(7000 * 3600, "VST"); - timezones0.put("VST", tz); - timezones0.put("Antarctica/Davis", tz); - timezones0.put("Asia/Bangkok", tz); - timezones0.put("Asia/Hovd", tz); - timezones0.put("Asia/Jakarta", tz); - timezones0.put("Asia/Phnom_Penh", tz); - timezones0.put("Asia/Saigon", tz); - timezones0.put("Asia/Vientiane", tz); - timezones0.put("Indian/Christmas", tz); - tz = new SimpleTimeZone - (7000 * 3600, "Asia/Krasnoyarsk", - Calendar.MARCH, -1, Calendar.SUNDAY, 2000 * 3600, - Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600); - timezones0.put("Asia/Krasnoyarsk", tz); - tz = new SimpleTimeZone(8000 * 3600, "CTT"); - timezones0.put("CTT", tz); - timezones0.put("Antarctica/Casey", tz); - timezones0.put("Asia/Brunei", tz); - timezones0.put("Asia/Chungking", tz); - timezones0.put("Asia/Harbin", tz); - timezones0.put("Asia/Hong_Kong", tz); - timezones0.put("Asia/Kashgar", tz); - timezones0.put("Asia/Kuala_Lumpur", tz); - timezones0.put("Asia/Kuching", tz); - timezones0.put("Asia/Macao", tz); - timezones0.put("Asia/Manila", tz); - timezones0.put("Asia/Shanghai", tz); - timezones0.put("Asia/Singapore", tz); - timezones0.put("Asia/Taipei", tz); - timezones0.put("Asia/Ujung_Pandang", tz); - timezones0.put("Asia/Ulaanbaatar", tz); - timezones0.put("Asia/Urumqi", tz); - timezones0.put("Australia/Perth", tz); - tz = new SimpleTimeZone - (8000 * 3600, "Asia/Irkutsk", - Calendar.MARCH, -1, Calendar.SUNDAY, 2000 * 3600, - Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600); - timezones0.put("Asia/Irkutsk", tz); - tz = new SimpleTimeZone(9000 * 3600, "JST"); - timezones0.put("JST", tz); - timezones0.put("Asia/Dili", tz); - timezones0.put("Asia/Jayapura", tz); - timezones0.put("Asia/Pyongyang", tz); - timezones0.put("Asia/Seoul", tz); - timezones0.put("Asia/Tokyo", tz); - timezones0.put("Pacific/Palau", tz); - tz = new SimpleTimeZone - (9000 * 3600, "Asia/Yakutsk", - Calendar.MARCH, -1, Calendar.SUNDAY, 2000 * 3600, - Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600); - timezones0.put("Asia/Yakutsk", tz); - tz = new SimpleTimeZone - (9500 * 3600, "Australia/Adelaide", - Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600, - Calendar.MARCH, -1, Calendar.SUNDAY, 2000 * 3600); - timezones0.put("Australia/Adelaide", tz); - timezones0.put("Australia/Broken_Hill", tz); - tz = new SimpleTimeZone(9500 * 3600, "ACT"); - timezones0.put("ACT", tz); - timezones0.put("Australia/Darwin", tz); - tz = new SimpleTimeZone(10000 * 3600, "Antarctica/DumontDUrville"); - timezones0.put("Antarctica/DumontDUrville", tz); - timezones0.put("Australia/Brisbane", tz); - timezones0.put("Australia/Lindeman", tz); - timezones0.put("Pacific/Guam", tz); - timezones0.put("Pacific/Port_Moresby", tz); - timezones0.put("Pacific/Saipan", tz); - timezones0.put("Pacific/Truk", tz); - timezones0.put("Pacific/Yap", tz); - tz = new SimpleTimeZone - (10000 * 3600, "Asia/Vladivostok", - Calendar.MARCH, -1, Calendar.SUNDAY, 2000 * 3600, - Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600); - timezones0.put("Asia/Vladivostok", tz); - tz = new SimpleTimeZone - (10000 * 3600, "Australia/Hobart", - Calendar.OCTOBER, 1, Calendar.SUNDAY, 2000 * 3600, - Calendar.MARCH, -1, Calendar.SUNDAY, 2000 * 3600); - timezones0.put("Australia/Hobart", tz); - tz = new SimpleTimeZone - (10000 * 3600, "AET", - Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600, - Calendar.MARCH, -1, Calendar.SUNDAY, 2000 * 3600); - timezones0.put("AET", tz); - timezones0.put("Australia/Melbourne", tz); - timezones0.put("Australia/Sydney", tz); - tz = new SimpleTimeZone - (10500 * 3600, "Australia/Lord_Howe", - Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600, - Calendar.MARCH, -1, Calendar.SUNDAY, 2000 * 3600, 500 * 3600); - timezones0.put("Australia/Lord_Howe", tz); - tz = new SimpleTimeZone - (11000 * 3600, "Asia/Magadan", - Calendar.MARCH, -1, Calendar.SUNDAY, 2000 * 3600, - Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600); - timezones0.put("Asia/Magadan", tz); - tz = new SimpleTimeZone(11000 * 3600, "SST"); - timezones0.put("SST", tz); - timezones0.put("Pacific/Efate", tz); - timezones0.put("Pacific/Guadalcanal", tz); - timezones0.put("Pacific/Kosrae", tz); - timezones0.put("Pacific/Noumea", tz); - timezones0.put("Pacific/Ponape", tz); - tz = new SimpleTimeZone(11500 * 3600, "Pacific/Norfolk"); - timezones0.put("Pacific/Norfolk", tz); - tz = new SimpleTimeZone - (12000 * 3600, "NST", - Calendar.OCTOBER, 1, Calendar.SUNDAY, 2000 * 3600, - Calendar.MARCH, 3, Calendar.SUNDAY, 2000 * 3600); - timezones0.put("NST", tz); - timezones0.put("Antarctica/McMurdo", tz); - timezones0.put("Antarctica/South_Pole", tz); - timezones0.put("Pacific/Auckland", tz); - tz = new SimpleTimeZone - (12000 * 3600, "Asia/Anadyr", - Calendar.MARCH, -1, Calendar.SUNDAY, 2000 * 3600, - Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600); - timezones0.put("Asia/Anadyr", tz); - timezones0.put("Asia/Kamchatka", tz); - tz = new SimpleTimeZone(12000 * 3600, "Pacific/Fiji"); - timezones0.put("Pacific/Fiji", tz); - timezones0.put("Pacific/Funafuti", tz); - timezones0.put("Pacific/Kwajalein", tz); - timezones0.put("Pacific/Majuro", tz); - timezones0.put("Pacific/Nauru", tz); - timezones0.put("Pacific/Tarawa", tz); - timezones0.put("Pacific/Wake", tz); - timezones0.put("Pacific/Wallis", tz); - tz = new SimpleTimeZone - (12750 * 3600, "Pacific/Chatham", - Calendar.OCTOBER, 1, Calendar.SUNDAY, 2750 * 3600, - Calendar.MARCH, 3, Calendar.SUNDAY, 2750 * 3600); - timezones0.put("Pacific/Chatham", tz); - tz = new SimpleTimeZone(13000 * 3600, "Pacific/Enderbury"); - timezones0.put("Pacific/Enderbury", tz); - timezones0.put("Pacific/Tongatapu", tz); - tz = new SimpleTimeZone(14000 * 3600, "Pacific/Kiritimati"); - timezones0.put("Pacific/Kiritimati", tz); - } - return timezones0; - } - - /** - * Maps a time zone name (with optional GMT offset and daylight time - * zone name) to one of the known time zones. This method called - * with the result of <code>System.getProperty("user.timezone")</code> - * or <code>getDefaultTimeZoneId()</code>. Note that giving one of - * the standard tz data names from ftp://elsie.nci.nih.gov/pub/ is - * preferred. The time zone name can be given as follows: - * <code>(standard zone name)[(GMT offset)[(daylight time zone name)]]</code> - * <p> - * If only a (standard zone name) is given (no numbers in the - * String) then it gets mapped directly to the TimeZone with that - * name, if that fails null is returned. - * <p> - * A GMT offset is the offset to add to the local time to get GMT. - * If a (GMT offset) is included (either in seconds or hours) then - * an attempt is made to find a TimeZone name matching both the name - * and the offset (that doesn't observe daylight time, if the - * timezone observes daylight time then you must include a daylight - * time zone name after the offset), if that fails then a TimeZone - * with the given GMT offset is returned (whether or not the - * TimeZone observes daylight time is ignored), if that also fails - * the GMT TimeZone is returned. - * <p> - * If the String ends with (GMT offset)(daylight time zone name) - * then an attempt is made to find a TimeZone with the given name and - * GMT offset that also observes (the daylight time zone name is not - * currently used in any other way), if that fails a TimeZone with - * the given GMT offset that observes daylight time is returned, if - * that also fails the GMT TimeZone is returned. - * <p> - * Examples: In Chicago, the time zone id could be "CST6CDT", but - * the preferred name would be "America/Chicago". In Indianapolis - * (which does not have Daylight Savings Time) the string could be - * "EST5", but the preferred name would be "America/Indianapolis". - * The standard time zone name for The Netherlands is "Europe/Amsterdam", - * but can also be given as "CET-1CEST". - */ - static TimeZone getDefaultTimeZone(String sysTimeZoneId) - { - // First find start of GMT offset info and any Daylight zone name. - int startGMToffset = 0; - int sysTimeZoneIdLength = sysTimeZoneId.length(); - for (int i = 0; i < sysTimeZoneIdLength && startGMToffset == 0; i++) - { - char c = sysTimeZoneId.charAt(i); - if (Character.isDigit(c)) - startGMToffset = i; - else if ((c == '+' || c == '-') - && i + 1 < sysTimeZoneIdLength - && Character.isDigit(sysTimeZoneId.charAt(i + 1))) - startGMToffset = i; - } - - String tzBasename; - if (startGMToffset == 0) - tzBasename = sysTimeZoneId; - else - tzBasename = sysTimeZoneId.substring (0, startGMToffset); - - int startDaylightZoneName = 0; - for (int i = sysTimeZoneIdLength - 1; - i >= 0 && !Character.isDigit(sysTimeZoneId.charAt(i)); --i) - startDaylightZoneName = i; - - boolean useDaylightTime = startDaylightZoneName > 0; - - // Integer.parseInt() doesn't handle leading +. - if (sysTimeZoneId.charAt(startGMToffset) == '+') - startGMToffset++; - - int gmtOffset = 0; - if (startGMToffset > 0) - { - gmtOffset = Integer.parseInt - (startDaylightZoneName == 0 - ? sysTimeZoneId.substring(startGMToffset) - : sysTimeZoneId.substring(startGMToffset, - startDaylightZoneName)); - - // Offset could be in hours or seconds. Convert to millis. - // The offset is given as the time to add to local time to get GMT - // we need the time to add to GMT to get localtime. - if (Math.abs(gmtOffset) < 24) - gmtOffset *= 60 * 60; - gmtOffset *= -1000; - } - - // Try to be optimistic and get the timezone that matches the base name. - // If we only have the base name then just accept this timezone. - // Otherwise check the gmtOffset and day light attributes. - TimeZone tz = (TimeZone) timezones().get(tzBasename); - if (tz != null - && (tzBasename == sysTimeZoneId - || (tz.getRawOffset() == gmtOffset - && tz.useDaylightTime() == useDaylightTime))) - return tz; - - // Maybe there is one with the daylight zone name? - if (useDaylightTime) - { - String daylightZoneName; - daylightZoneName = sysTimeZoneId.substring(startDaylightZoneName); - if (!daylightZoneName.equals(tzBasename)) - { - tz = (TimeZone) timezones().get(tzBasename); - if (tz != null - && tz.getRawOffset() == gmtOffset - && tz.useDaylightTime()) - return tz; - } - } - - // If no match, see if a valid timezone has similar attributes as this - // and then use it instead. We take the first one that looks OKish. - if (startGMToffset > 0) - { - String[] ids = getAvailableIDs(gmtOffset); - for (int i = 0; i < ids.length; i++) - { - tz = (TimeZone) timezones().get(ids[i]); - if (tz.useDaylightTime() == useDaylightTime) - return tz; - } - } - - return null; - } - - /** - * Gets the time zone offset, for current date, modified in case of - * daylight savings. This is the offset to add to UTC to get the local - * time. - * @param era the era of the given date - * @param year the year of the given date - * @param month the month of the given date, 0 for January. - * @param day the day of month - * @param dayOfWeek the day of week - * @param milliseconds the millis in the day (in local standard time) - * @return the time zone offset in milliseconds. - */ - public abstract int getOffset(int era, int year, int month, - int day, int dayOfWeek, int milliseconds); - - /** - * Get the time zone offset for the specified date, modified in case of - * daylight savings. This is the offset to add to UTC to get the local - * time. - * @param date the date represented in millisecends - * since January 1, 1970 00:00:00 GMT. - * @since 1.4 - */ - public int getOffset(long date) - { - return (inDaylightTime(new Date(date)) - ? getRawOffset() + getDSTSavings() - : getRawOffset()); - } - - /** - * Gets the time zone offset, ignoring daylight savings. This is - * the offset to add to UTC to get the local time. - * @return the time zone offset in milliseconds. - */ - public abstract int getRawOffset(); - - /** - * Sets the time zone offset, ignoring daylight savings. This is - * the offset to add to UTC to get the local time. - * @param offsetMillis the time zone offset to GMT. - */ - public abstract void setRawOffset(int offsetMillis); - - /** - * Gets the identifier of this time zone. For instance, PST for - * Pacific Standard Time. - * @returns the ID of this time zone. - */ - public String getID() - { - return ID; - } - - /** - * Sets the identifier of this time zone. For instance, PST for - * Pacific Standard Time. - * @param id the new time zone ID. - * @throws NullPointerException if <code>id</code> is <code>null</code> - */ - public void setID(String id) - { - if (id == null) - throw new NullPointerException(); - - this.ID = id; - } - - /** - * This method returns a string name of the time zone suitable - * for displaying to the user. The string returned will be the long - * description of the timezone in the current locale. The name - * displayed will assume daylight savings time is not in effect. - * - * @return The name of the time zone. - */ - public final String getDisplayName() - { - return (getDisplayName(false, LONG, Locale.getDefault())); - } - - /** - * This method returns a string name of the time zone suitable - * for displaying to the user. The string returned will be the long - * description of the timezone in the specified locale. The name - * displayed will assume daylight savings time is not in effect. - * - * @param locale The locale for this timezone name. - * - * @return The name of the time zone. - */ - public final String getDisplayName(Locale locale) - { - return (getDisplayName(false, LONG, locale)); - } - - /** - * This method returns a string name of the time zone suitable - * for displaying to the user. The string returned will be of the - * specified type in the current locale. - * - * @param dst Whether or not daylight savings time is in effect. - * @param style <code>LONG</code> for a long name, <code>SHORT</code> for - * a short abbreviation. - * - * @return The name of the time zone. - */ - public final String getDisplayName(boolean dst, int style) - { - return (getDisplayName(dst, style, Locale.getDefault())); - } - - - /** - * This method returns a string name of the time zone suitable - * for displaying to the user. The string returned will be of the - * specified type in the specified locale. - * - * @param dst Whether or not daylight savings time is in effect. - * @param style <code>LONG</code> for a long name, <code>SHORT</code> for - * a short abbreviation. - * @param locale The locale for this timezone name. - * - * @return The name of the time zone. - */ - public String getDisplayName(boolean dst, int style, Locale locale) - { - DateFormatSymbols dfs; - try - { - dfs = new DateFormatSymbols(locale); - - // The format of the value returned is defined by us. - String[][]zoneinfo = dfs.getZoneStrings(); - for (int i = 0; i < zoneinfo.length; i++) - { - if (zoneinfo[i][0].equals(getID())) - { - if (!dst) - { - if (style == SHORT) - return (zoneinfo[i][2]); - else - return (zoneinfo[i][1]); - } - else - { - if (style == SHORT) - return (zoneinfo[i][4]); - else - return (zoneinfo[i][3]); - } - } - } - } - catch (MissingResourceException e) - { - } - - return getDefaultDisplayName(dst); - } - - private String getDefaultDisplayName(boolean dst) - { - int offset = getRawOffset(); - if (dst && this instanceof SimpleTimeZone) - { - // ugly, but this is a design failure of the API: - // getDisplayName takes a dst parameter even though - // TimeZone knows nothing about daylight saving offsets. - offset += ((SimpleTimeZone) this).getDSTSavings(); - } - - StringBuffer sb = new StringBuffer(9); - sb.append("GMT"); - - offset = offset / (1000 * 60); - int hours = Math.abs(offset) / 60; - int minutes = Math.abs(offset) % 60; - - if (minutes != 0 || hours != 0) - { - sb.append(offset >= 0 ? '+' : '-'); - sb.append((char) ('0' + hours / 10)); - sb.append((char) ('0' + hours % 10)); - sb.append(':'); - sb.append((char) ('0' + minutes / 10)); - sb.append((char) ('0' + minutes % 10)); - } - - return sb.toString(); - } - - /** - * Returns true, if this time zone uses Daylight Savings Time. - */ - public abstract boolean useDaylightTime(); - - /** - * Returns true, if the given date is in Daylight Savings Time in this - * time zone. - * @param date the given Date. - */ - public abstract boolean inDaylightTime(Date date); - - /** - * Gets the daylight savings offset. This is a positive offset in - * milliseconds with respect to standard time. Typically this - * is one hour, but for some time zones this may be half an our. - * <p>The default implementation returns 3600000 milliseconds - * (one hour) if the time zone uses daylight savings time - * (as specified by {@link #useDaylightTime()}), otherwise - * it returns 0. - * @return the daylight savings offset in milliseconds. - * @since 1.4 - */ - public int getDSTSavings () - { - return useDaylightTime () ? 3600000 : 0; - } - - /** - * Gets the TimeZone for the given ID. - * @param ID the time zone identifier. - * @return The time zone for the identifier or GMT, if no such time - * zone exists. - */ - // FIXME: XXX: JCL indicates this and other methods are synchronized. - public static TimeZone getTimeZone(String ID) - { - // First check timezones hash - TimeZone tz = (TimeZone) timezones().get(ID); - if (tz != null) - { - if (tz.getID().equals(ID)) - return tz; - - // We always return a timezone with the requested ID. - // This is the same behaviour as with JDK1.2. - tz = (TimeZone) tz.clone(); - tz.setID(ID); - // We also save the alias, so that we return the same - // object again if getTimeZone is called with the same - // alias. - timezones().put(ID, tz); - return tz; - } - - // See if the ID is really a GMT offset form. - // Note that GMT is in the table so we know it is different. - if (ID.startsWith("GMT")) - { - int pos = 3; - int offset_direction = 1; - - if (ID.charAt(pos) == '-') - { - offset_direction = -1; - pos++; - } - else if (ID.charAt(pos) == '+') - { - pos++; - } - - try - { - int hour, minute; - - String offset_str = ID.substring(pos); - int idx = offset_str.indexOf(":"); - if (idx != -1) - { - hour = Integer.parseInt(offset_str.substring(0, idx)); - minute = Integer.parseInt(offset_str.substring(idx + 1)); - } - else - { - int offset_length = offset_str.length(); - if (offset_length <= 2) - { - // Only hour - hour = Integer.parseInt(offset_str); - minute = 0; - } - else - { - // hour and minute, not separated by colon - hour = Integer.parseInt - (offset_str.substring(0, offset_length - 2)); - minute = Integer.parseInt - (offset_str.substring(offset_length - 2)); - } - } - - return new SimpleTimeZone((hour * (60 * 60 * 1000) + - minute * (60 * 1000)) - * offset_direction, ID); - } - catch (NumberFormatException e) - { - } - } - - // Finally, return GMT per spec - return getTimeZone("GMT"); - } - - /** - * Gets the available IDs according to the given time zone - * offset. - * @param rawOffset the given time zone GMT offset. - * @return An array of IDs, where the time zone has the specified GMT - * offset. For example <code>{"Phoenix", "Denver"}</code>, since both have - * GMT-07:00, but differ in daylight savings behaviour. - */ - public static String[] getAvailableIDs(int rawOffset) - { - int count = 0; - Iterator iter = timezones().entrySet().iterator(); - while (iter.hasNext()) - { - // Don't iterate the values, since we want to count - // doubled values (aliases) - Map.Entry entry = (Map.Entry) iter.next(); - if (((TimeZone) entry.getValue()).getRawOffset() == rawOffset) - count++; - } - - String[] ids = new String[count]; - count = 0; - iter = timezones().entrySet().iterator(); - while (iter.hasNext()) - { - Map.Entry entry = (Map.Entry) iter.next(); - if (((TimeZone) entry.getValue()).getRawOffset() == rawOffset) - ids[count++] = (String) entry.getKey(); - } - return ids; - } - - /** - * Gets all available IDs. - * @return An array of all supported IDs. - */ - public static String[] getAvailableIDs() - { - return (String[]) - timezones().keySet().toArray(new String[timezones().size()]); - } - - /** - * Returns the time zone under which the host is running. This - * can be changed with setDefault. - * - * @return A clone of the current default time zone for this host. - * @see #setDefault - */ - public static TimeZone getDefault() - { - return (TimeZone) defaultZone().clone(); - } - - public static void setDefault(TimeZone zone) - { - // Hmmmm. No Security checks? - defaultZone0 = zone; - } - - /** - * Test if the other time zone uses the same rule and only - * possibly differs in ID. This implementation for this particular - * class will return true if the raw offsets are identical. Subclasses - * should override this method if they use daylight savings. - * @return true if this zone has the same raw offset - */ - public boolean hasSameRules(TimeZone other) - { - return other.getRawOffset() == getRawOffset(); - } - - /** - * Returns a clone of this object. I can't imagine, why this is - * useful for a time zone. - */ - public Object clone() - { - try - { - return super.clone(); - } - catch (CloneNotSupportedException ex) - { - return null; - } - } -} diff --git a/libjava/java/util/Timer.java b/libjava/java/util/Timer.java deleted file mode 100644 index 715f06cf641..00000000000 --- a/libjava/java/util/Timer.java +++ /dev/null @@ -1,615 +0,0 @@ -/* Timer.java -- Timer that runs TimerTasks at a later time. - Copyright (C) 2000, 2001 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.util; - -/** - * Timer that can run TimerTasks at a later time. - * TimerTasks can be scheduled for one time execution at some time in the - * future. They can be scheduled to be rescheduled at a time period after the - * task was last executed. Or they can be scheduled to be executed repeatedly - * at a fixed rate. - * <p> - * The normal scheduling will result in a more or less even delay in time - * between successive executions, but the executions could drift in time if - * the task (or other tasks) takes a long time to execute. Fixed delay - * scheduling guarantees more or less that the task will be executed at a - * specific time, but if there is ever a delay in execution then the period - * between successive executions will be shorter. The first method of - * repeated scheduling is preferred for repeated tasks in response to user - * interaction, the second method of repeated scheduling is preferred for tasks - * that act like alarms. - * <p> - * The Timer keeps a binary heap as a task priority queue which means that - * scheduling and serving of a task in a queue of n tasks costs O(log n). - * - * @see TimerTask - * @since 1.3 - * @author Mark Wielaard (mark@klomp.org) - */ -public class Timer -{ - /** - * Priority Task Queue. - * TimerTasks are kept in a binary heap. - * The scheduler calls sleep() on the queue when it has nothing to do or - * has to wait. A sleeping scheduler can be notified by calling interrupt() - * which is automatically called by the enqueue(), cancel() and - * timerFinalized() methods. - */ - private static final class TaskQueue - { - /** Default size of this queue */ - private static final int DEFAULT_SIZE = 32; - - /** Whether to return null when there is nothing in the queue */ - private boolean nullOnEmpty; - - /** - * The heap containing all the scheduled TimerTasks - * sorted by the TimerTask.scheduled field. - * Null when the stop() method has been called. - */ - private TimerTask heap[]; - - /** - * The actual number of elements in the heap - * Can be less then heap.length. - * Note that heap[0] is used as a sentinel. - */ - private int elements; - - /** - * Creates a TaskQueue of default size without any elements in it. - */ - public TaskQueue() - { - heap = new TimerTask[DEFAULT_SIZE]; - elements = 0; - nullOnEmpty = false; - } - - /** - * Adds a TimerTask at the end of the heap. - * Grows the heap if necessary by doubling the heap in size. - */ - private void add(TimerTask task) - { - elements++; - if (elements == heap.length) - { - TimerTask new_heap[] = new TimerTask[heap.length * 2]; - System.arraycopy(heap, 0, new_heap, 0, heap.length); - heap = new_heap; - } - heap[elements] = task; - } - - /** - * Removes the last element from the heap. - * Shrinks the heap in half if - * elements+DEFAULT_SIZE/2 <= heap.length/4. - */ - private void remove() - { - // clear the entry first - heap[elements] = null; - elements--; - if (elements + DEFAULT_SIZE / 2 <= (heap.length / 4)) - { - TimerTask new_heap[] = new TimerTask[heap.length / 2]; - System.arraycopy(heap, 0, new_heap, 0, elements + 1); - heap = new_heap; - } - } - - /** - * Adds a task to the queue and puts it at the correct place - * in the heap. - */ - public synchronized void enqueue(TimerTask task) - { - // Check if it is legal to add another element - if (heap == null) - { - throw new IllegalStateException - ("cannot enqueue when stop() has been called on queue"); - } - - heap[0] = task; // sentinel - add(task); // put the new task at the end - // Now push the task up in the heap until it has reached its place - int child = elements; - int parent = child / 2; - while (heap[parent].scheduled > task.scheduled) - { - heap[child] = heap[parent]; - child = parent; - parent = child / 2; - } - // This is the correct place for the new task - heap[child] = task; - heap[0] = null; // clear sentinel - // Maybe sched() is waiting for a new element - this.notify(); - } - - /** - * Returns the top element of the queue. - * Can return null when no task is in the queue. - */ - private TimerTask top() - { - if (elements == 0) - { - return null; - } - else - { - return heap[1]; - } - } - - /** - * Returns the top task in the Queue. - * Removes the element from the heap and reorders the heap first. - * Can return null when there is nothing in the queue. - */ - public synchronized TimerTask serve() - { - // The task to return - TimerTask task = null; - - while (task == null) - { - // Get the next task - task = top(); - - // return null when asked to stop - // or if asked to return null when the queue is empty - if ((heap == null) || (task == null && nullOnEmpty)) - { - return null; - } - - // Do we have a task? - if (task != null) - { - // The time to wait until the task should be served - long time = task.scheduled - System.currentTimeMillis(); - if (time > 0) - { - // This task should not yet be served - // So wait until this task is ready - // or something else happens to the queue - task = null; // set to null to make sure we call top() - try - { - this.wait(time); - } - catch (InterruptedException _) - { - } - } - } - else - { - // wait until a task is added - // or something else happens to the queue - try - { - this.wait(); - } - catch (InterruptedException _) - { - } - } - } - - // reconstruct the heap - TimerTask lastTask = heap[elements]; - remove(); - - // drop lastTask at the beginning and move it down the heap - int parent = 1; - int child = 2; - heap[1] = lastTask; - while (child <= elements) - { - if (child < elements) - { - if (heap[child].scheduled > heap[child + 1].scheduled) - { - child++; - } - } - - if (lastTask.scheduled <= heap[child].scheduled) - break; // found the correct place (the parent) - done - - heap[parent] = heap[child]; - parent = child; - child = parent * 2; - } - - // this is the correct new place for the lastTask - heap[parent] = lastTask; - - // return the task - return task; - } - - /** - * When nullOnEmpty is true the serve() method will return null when - * there are no tasks in the queue, otherwise it will wait until - * a new element is added to the queue. It is used to indicate to - * the scheduler that no new tasks will ever be added to the queue. - */ - public synchronized void setNullOnEmpty(boolean nullOnEmpty) - { - this.nullOnEmpty = nullOnEmpty; - this.notify(); - } - - /** - * When this method is called the current and all future calls to - * serve() will return null. It is used to indicate to the Scheduler - * that it should stop executing since no more tasks will come. - */ - public synchronized void stop() - { - this.heap = null; - this.elements = 0; - this.notify(); - } - - } // TaskQueue - - /** - * The scheduler that executes all the tasks on a particular TaskQueue, - * reschedules any repeating tasks and that waits when no task has to be - * executed immediatly. Stops running when canceled or when the parent - * Timer has been finalized and no more tasks have to be executed. - */ - private static final class Scheduler implements Runnable - { - // The priority queue containing all the TimerTasks. - private TaskQueue queue; - - /** - * Creates a new Scheduler that will schedule the tasks on the - * given TaskQueue. - */ - public Scheduler(TaskQueue queue) - { - this.queue = queue; - } - - public void run() - { - TimerTask task; - while ((task = queue.serve()) != null) - { - // If this task has not been canceled - if (task.scheduled >= 0) - { - - // Mark execution time - task.lastExecutionTime = task.scheduled; - - // Repeatable task? - if (task.period < 0) - { - // Last time this task is executed - task.scheduled = -1; - } - - // Run the task - try - { - task.run(); - } - catch (ThreadDeath death) - { - // If an exception escapes, the Timer becomes invalid. - queue.stop(); - throw death; - } - catch (Throwable t) - { - // If an exception escapes, the Timer becomes invalid. - queue.stop(); - } - } - - // Calculate next time and possibly re-enqueue. - if (task.scheduled >= 0) - { - if (task.fixed) - { - task.scheduled += task.period; - } - else - { - task.scheduled = task.period + System.currentTimeMillis(); - } - - try - { - queue.enqueue(task); - } - catch (IllegalStateException ise) - { - // Ignore. Apparently the Timer queue has been stopped. - } - } - } - } - } // Scheduler - - // Number of Timers created. - // Used for creating nice Thread names. - private static int nr; - - // The queue that all the tasks are put in. - // Given to the scheduler - private TaskQueue queue; - - // The Scheduler that does all the real work - private Scheduler scheduler; - - // Used to run the scheduler. - // Also used to checked if the Thread is still running by calling - // thread.isAlive(). Sometimes a Thread is suddenly killed by the system - // (if it belonged to an Applet). - private Thread thread; - - // When cancelled we don't accept any more TimerTasks. - private boolean canceled; - - /** - * Creates a new Timer with a non daemon Thread as Scheduler, with normal - * priority and a default name. - */ - public Timer() - { - this(false); - } - - /** - * Creates a new Timer with a daemon Thread as scheduler if daemon is true, - * with normal priority and a default name. - */ - public Timer(boolean daemon) - { - this(daemon, Thread.NORM_PRIORITY); - } - - /** - * Creates a new Timer with a daemon Thread as scheduler if daemon is true, - * with the priority given and a default name. - */ - private Timer(boolean daemon, int priority) - { - this(daemon, priority, "Timer-" + (++nr)); - } - - /** - * Creates a new Timer with a daemon Thread as scheduler if daemon is true, - * with the priority and name given.E - */ - private Timer(boolean daemon, int priority, String name) - { - canceled = false; - queue = new TaskQueue(); - scheduler = new Scheduler(queue); - thread = new Thread(scheduler, name); - thread.setDaemon(daemon); - thread.setPriority(priority); - thread.start(); - } - - /** - * Cancels the execution of the scheduler. If a task is executing it will - * normally finish execution, but no other tasks will be executed and no - * more tasks can be scheduled. - */ - public void cancel() - { - canceled = true; - queue.stop(); - } - - /** - * Schedules the task at Time time, repeating every period - * milliseconds if period is positive and at a fixed rate if fixed is true. - * - * @exception IllegalArgumentException if time is negative - * @exception IllegalStateException if the task was already scheduled or - * canceled or this Timer is canceled or the scheduler thread has died - */ - private void schedule(TimerTask task, long time, long period, boolean fixed) - { - if (time < 0) - throw new IllegalArgumentException("negative time"); - - if (task.scheduled == 0 && task.lastExecutionTime == -1) - { - task.scheduled = time; - task.period = period; - task.fixed = fixed; - } - else - { - throw new IllegalStateException - ("task was already scheduled or canceled"); - } - - if (!this.canceled && this.thread != null) - { - queue.enqueue(task); - } - else - { - throw new IllegalStateException - ("timer was canceled or scheduler thread has died"); - } - } - - private static void positiveDelay(long delay) - { - if (delay < 0) - { - throw new IllegalArgumentException("delay is negative"); - } - } - - private static void positivePeriod(long period) - { - if (period < 0) - { - throw new IllegalArgumentException("period is negative"); - } - } - - /** - * Schedules the task at the specified data for one time execution. - * - * @exception IllegalArgumentException if date.getTime() is negative - * @exception IllegalStateException if the task was already scheduled or - * canceled or this Timer is canceled or the scheduler thread has died - */ - public void schedule(TimerTask task, Date date) - { - long time = date.getTime(); - schedule(task, time, -1, false); - } - - /** - * Schedules the task at the specified date and reschedules the task every - * period milliseconds after the last execution of the task finishes until - * this timer or the task is canceled. - * - * @exception IllegalArgumentException if period or date.getTime() is - * negative - * @exception IllegalStateException if the task was already scheduled or - * canceled or this Timer is canceled or the scheduler thread has died - */ - public void schedule(TimerTask task, Date date, long period) - { - positivePeriod(period); - long time = date.getTime(); - schedule(task, time, period, false); - } - - /** - * Schedules the task after the specified delay milliseconds for one time - * execution. - * - * @exception IllegalArgumentException if delay or - * System.currentTimeMillis + delay is negative - * @exception IllegalStateException if the task was already scheduled or - * canceled or this Timer is canceled or the scheduler thread has died - */ - public void schedule(TimerTask task, long delay) - { - positiveDelay(delay); - long time = System.currentTimeMillis() + delay; - schedule(task, time, -1, false); - } - - /** - * Schedules the task after the delay milliseconds and reschedules the - * task every period milliseconds after the last execution of the task - * finishes until this timer or the task is canceled. - * - * @exception IllegalArgumentException if delay or period is negative - * @exception IllegalStateException if the task was already scheduled or - * canceled or this Timer is canceled or the scheduler thread has died - */ - public void schedule(TimerTask task, long delay, long period) - { - positiveDelay(delay); - positivePeriod(period); - long time = System.currentTimeMillis() + delay; - schedule(task, time, period, false); - } - - /** - * Schedules the task at the specified date and reschedules the task at a - * fixed rate every period milliseconds until this timer or the task is - * canceled. - * - * @exception IllegalArgumentException if period or date.getTime() is - * negative - * @exception IllegalStateException if the task was already scheduled or - * canceled or this Timer is canceled or the scheduler thread has died - */ - public void scheduleAtFixedRate(TimerTask task, Date date, long period) - { - positivePeriod(period); - long time = date.getTime(); - schedule(task, time, period, true); - } - - /** - * Schedules the task after the delay milliseconds and reschedules the task - * at a fixed rate every period milliseconds until this timer or the task - * is canceled. - * - * @exception IllegalArgumentException if delay or - * System.currentTimeMillis + delay is negative - * @exception IllegalStateException if the task was already scheduled or - * canceled or this Timer is canceled or the scheduler thread has died - */ - public void scheduleAtFixedRate(TimerTask task, long delay, long period) - { - positiveDelay(delay); - positivePeriod(period); - long time = System.currentTimeMillis() + delay; - schedule(task, time, period, true); - } - - /** - * Tells the scheduler that the Timer task died - * so there will be no more new tasks scheduled. - */ - protected void finalize() throws Throwable - { - queue.setNullOnEmpty(true); - } -} diff --git a/libjava/java/util/TimerTask.java b/libjava/java/util/TimerTask.java deleted file mode 100644 index b03118ad0fe..00000000000 --- a/libjava/java/util/TimerTask.java +++ /dev/null @@ -1,145 +0,0 @@ -/* TimerTask.java -- Task that can be run at a later time if given to a Timer. - Copyright (C) 2000 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.util; - -/** - * Task that can be run at a later time if given to a Timer. - * The TimerTask must implement a run method that will be called by the - * Timer when the task is scheduled for execution. The task can check when - * it should have been scheduled and cancel itself when no longer needed. - * <p> - * Example: - * <pre> - * Timer timer = new Timer(); - * TimerTask task = new TimerTask() { - * public void run() { - * if (this.scheduledExecutionTime() < System.currentTimeMillis() + 500) - * // Do something - * else - * // Complain: We are more then half a second late! - * if (someStopCondition) - * this.cancel(); // This was our last execution - * }; - * timer.scheduleAtFixedRate(task, 1000, 1000); // schedule every second - * </pre> - * <p> - * Note that a TimerTask object is a one shot object and can only given once - * to a Timer. (The Timer will use the TimerTask object for bookkeeping, - * in this implementation). - * <p> - * This class also implements <code>Runnable</code> to make it possible to - * give a TimerTask directly as a target to a <code>Thread</code>. - * - * @see Timer - * @since 1.3 - * @author Mark Wielaard (mark@klomp.org) - */ -public abstract class TimerTask implements Runnable -{ - /** - * If positive the next time this task should be run. - * If negative this TimerTask is canceled or executed for the last time. - */ - long scheduled; - - /** - * If positive the last time this task was run. - * If negative this TimerTask has not yet been scheduled. - */ - long lastExecutionTime; - - /** - * If positive the number of milliseconds between runs of this task. - * If -1 this task doesn't have to be run more then once. - */ - long period; - - /** - * If true the next time this task should be run is relative to - * the last scheduled time, otherwise it can drift in time. - */ - boolean fixed; - - /** - * Creates a TimerTask and marks it as not yet scheduled. - */ - protected TimerTask() - { - this.scheduled = 0; - this.lastExecutionTime = -1; - } - - /** - * Marks the task as canceled and prevents any further execution. - * Returns true if the task was scheduled for any execution in the future - * and this cancel operation prevents that execution from happening. - * <p> - * A task that has been canceled can never be scheduled again. - * <p> - * In this implementation the TimerTask it is possible that the Timer does - * keep a reference to the TimerTask until the first time the TimerTask - * is actually scheduled. But the reference will disappear immediatly when - * cancel is called from within the TimerTask run method. - */ - public boolean cancel() - { - boolean prevented_execution = (this.scheduled >= 0); - this.scheduled = -1; - return prevented_execution; - } - - /** - * Method that is called when this task is scheduled for execution. - */ - public abstract void run(); - - /** - * Returns the last time this task was scheduled or (when called by the - * task from the run method) the time the current execution of the task - * was scheduled. When the task has not yet run the return value is - * undefined. - * <p> - * Can be used (when the task is scheduled at fixed rate) to see the - * difference between the requested schedule time and the actual time - * that can be found with <code>System.currentTimeMillis()</code>. - */ - public long scheduledExecutionTime() - { - return lastExecutionTime; - } -} diff --git a/libjava/java/util/TooManyListenersException.java b/libjava/java/util/TooManyListenersException.java deleted file mode 100644 index 92ad772f2bb..00000000000 --- a/libjava/java/util/TooManyListenersException.java +++ /dev/null @@ -1,78 +0,0 @@ -/* TooManyListenersException.java -- thrown when a unicast event can't accept - another Listener - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util; - -/** - * This exception is part of the java event model. It is thrown if an - * event listener is added via the addXyzEventListener method, but the - * object doesn't support any more listeners, e.g. it only supports a - * single event listener. - * - * @author Jochen Hoenicke - * @author Warren Levy (warrenl@cygnus.com) - * @see EventListener - * @see EventObject - * @since 1.1 - * @status updated to 1.4 - */ -public class TooManyListenersException extends Exception -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = 5074640544770687831L; - - /** - * Constructs a TooManyListenersException with no detail message. - */ - public TooManyListenersException() - { - } - - /** - * Constructs a TooManyListenersException with a detail message. - * - * @param detail the detail message - */ - public TooManyListenersException(String detail) - { - super(detail); - } -} diff --git a/libjava/java/util/TreeMap.java b/libjava/java/util/TreeMap.java deleted file mode 100644 index bddf97d9a33..00000000000 --- a/libjava/java/util/TreeMap.java +++ /dev/null @@ -1,1781 +0,0 @@ -/* TreeMap.java -- a class providing a basic Red-Black Tree data structure, - mapping Object --> Object - Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util; - -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; - -/** - * This class provides a red-black tree implementation of the SortedMap - * interface. Elements in the Map will be sorted by either a user-provided - * Comparator object, or by the natural ordering of the keys. - * - * The algorithms are adopted from Corman, Leiserson, and Rivest's - * <i>Introduction to Algorithms.</i> TreeMap guarantees O(log n) - * insertion and deletion of elements. That being said, there is a large - * enough constant coefficient in front of that "log n" (overhead involved - * in keeping the tree balanced), that TreeMap may not be the best choice - * for small collections. If something is already sorted, you may want to - * just use a LinkedHashMap to maintain the order while providing O(1) access. - * - * TreeMap is a part of the JDK1.2 Collections API. Null keys are allowed - * only if a Comparator is used which can deal with them; natural ordering - * cannot cope with null. Null values are always allowed. Note that the - * ordering must be <i>consistent with equals</i> to correctly implement - * the Map interface. If this condition is violated, the map is still - * well-behaved, but you may have suprising results when comparing it to - * other maps.<p> - * - * This implementation is not synchronized. If you need to share this between - * multiple threads, do something like:<br> - * <code>SortedMap m - * = Collections.synchronizedSortedMap(new TreeMap(...));</code><p> - * - * The iterators are <i>fail-fast</i>, meaning that any structural - * modification, except for <code>remove()</code> called on the iterator - * itself, cause the iterator to throw a - * <code>ConcurrentModificationException</code> rather than exhibit - * non-deterministic behavior. - * - * @author Jon Zeppieri - * @author Bryce McKinlay - * @author Eric Blake (ebb9@email.byu.edu) - * @see Map - * @see HashMap - * @see Hashtable - * @see LinkedHashMap - * @see Comparable - * @see Comparator - * @see Collection - * @see Collections#synchronizedSortedMap(SortedMap) - * @since 1.2 - * @status updated to 1.4 - */ -public class TreeMap extends AbstractMap - implements SortedMap, Cloneable, Serializable -{ - // Implementation note: - // A red-black tree is a binary search tree with the additional properties - // that all paths to a leaf node visit the same number of black nodes, - // and no red node has red children. To avoid some null-pointer checks, - // we use the special node nil which is always black, has no relatives, - // and has key and value of null (but is not equal to a mapping of null). - - /** - * Compatible with JDK 1.2. - */ - private static final long serialVersionUID = 919286545866124006L; - - /** - * Color status of a node. Package visible for use by nested classes. - */ - static final int RED = -1, - BLACK = 1; - - /** - * Sentinal node, used to avoid null checks for corner cases and make the - * delete rebalance code simpler. The rebalance code must never assign - * the parent, left, or right of nil, but may safely reassign the color - * to be black. This object must never be used as a key in a TreeMap, or - * it will break bounds checking of a SubMap. - */ - static final Node nil = new Node(null, null, BLACK); - static - { - // Nil is self-referential, so we must initialize it after creation. - nil.parent = nil; - nil.left = nil; - nil.right = nil; - } - - /** - * The root node of this TreeMap. - */ - private transient Node root; - - /** - * The size of this TreeMap. Package visible for use by nested classes. - */ - transient int size; - - /** - * The cache for {@link #entrySet()}. - */ - private transient Set entries; - - /** - * Counts the number of modifications this TreeMap has undergone, used - * by Iterators to know when to throw ConcurrentModificationExceptions. - * Package visible for use by nested classes. - */ - transient int modCount; - - /** - * This TreeMap's comparator, or null for natural ordering. - * Package visible for use by nested classes. - * @serial the comparator ordering this tree, or null - */ - final Comparator comparator; - - /** - * Class to represent an entry in the tree. Holds a single key-value pair, - * plus pointers to parent and child nodes. - * - * @author Eric Blake (ebb9@email.byu.edu) - */ - private static final class Node extends AbstractMap.BasicMapEntry - { - // All fields package visible for use by nested classes. - /** The color of this node. */ - int color; - - /** The left child node. */ - Node left = nil; - /** The right child node. */ - Node right = nil; - /** The parent node. */ - Node parent = nil; - - /** - * Simple constructor. - * @param key the key - * @param value the value - */ - Node(Object key, Object value, int color) - { - super(key, value); - this.color = color; - } - } - - /** - * Instantiate a new TreeMap with no elements, using the keys' natural - * ordering to sort. All entries in the map must have a key which implements - * Comparable, and which are <i>mutually comparable</i>, otherwise map - * operations may throw a {@link ClassCastException}. Attempts to use - * a null key will throw a {@link NullPointerException}. - * - * @see Comparable - */ - public TreeMap() - { - this((Comparator) null); - } - - /** - * Instantiate a new TreeMap with no elements, using the provided comparator - * to sort. All entries in the map must have keys which are mutually - * comparable by the Comparator, otherwise map operations may throw a - * {@link ClassCastException}. - * - * @param comparator the sort order for the keys of this map, or null - * for the natural order - */ - public TreeMap(Comparator c) - { - comparator = c; - fabricateTree(0); - } - - /** - * Instantiate a new TreeMap, initializing it with all of the elements in - * the provided Map. The elements will be sorted using the natural - * ordering of the keys. This algorithm runs in n*log(n) time. All entries - * in the map must have keys which implement Comparable and are mutually - * comparable, otherwise map operations may throw a - * {@link ClassCastException}. - * - * @param map a Map, whose entries will be put into this TreeMap - * @throws ClassCastException if the keys in the provided Map are not - * comparable - * @throws NullPointerException if map is null - * @see Comparable - */ - public TreeMap(Map map) - { - this((Comparator) null); - putAll(map); - } - - /** - * Instantiate a new TreeMap, initializing it with all of the elements in - * the provided SortedMap. The elements will be sorted using the same - * comparator as in the provided SortedMap. This runs in linear time. - * - * @param sm a SortedMap, whose entries will be put into this TreeMap - * @throws NullPointerException if sm is null - */ - public TreeMap(SortedMap sm) - { - this(sm.comparator()); - int pos = sm.size(); - Iterator itr = sm.entrySet().iterator(); - - fabricateTree(pos); - Node node = firstNode(); - - while (--pos >= 0) - { - Map.Entry me = (Map.Entry) itr.next(); - node.key = me.getKey(); - node.value = me.getValue(); - node = successor(node); - } - } - - /** - * Clears the Map so it has no keys. This is O(1). - */ - public void clear() - { - if (size > 0) - { - modCount++; - root = nil; - size = 0; - } - } - - /** - * Returns a shallow clone of this TreeMap. The Map itself is cloned, - * but its contents are not. - * - * @return the clone - */ - public Object clone() - { - TreeMap copy = null; - try - { - copy = (TreeMap) super.clone(); - } - catch (CloneNotSupportedException x) - { - } - copy.entries = null; - copy.fabricateTree(size); - - Node node = firstNode(); - Node cnode = copy.firstNode(); - - while (node != nil) - { - cnode.key = node.key; - cnode.value = node.value; - node = successor(node); - cnode = copy.successor(cnode); - } - return copy; - } - - /** - * Return the comparator used to sort this map, or null if it is by - * natural order. - * - * @return the map's comparator - */ - public Comparator comparator() - { - return comparator; - } - - /** - * Returns true if the map contains a mapping for the given key. - * - * @param key the key to look for - * @return true if the key has a mapping - * @throws ClassCastException if key is not comparable to map elements - * @throws NullPointerException if key is null and the comparator is not - * tolerant of nulls - */ - public boolean containsKey(Object key) - { - return getNode(key) != nil; - } - - /** - * Returns true if the map contains at least one mapping to the given value. - * This requires linear time. - * - * @param value the value to look for - * @return true if the value appears in a mapping - */ - public boolean containsValue(Object value) - { - Node node = firstNode(); - while (node != nil) - { - if (equals(value, node.value)) - return true; - node = successor(node); - } - return false; - } - - /** - * Returns a "set view" of this TreeMap's entries. The set is backed by - * the TreeMap, so changes in one show up in the other. The set supports - * element removal, but not element addition.<p> - * - * Note that the iterators for all three views, from keySet(), entrySet(), - * and values(), traverse the TreeMap in sorted sequence. - * - * @return a set view of the entries - * @see #keySet() - * @see #values() - * @see Map.Entry - */ - public Set entrySet() - { - if (entries == null) - // Create an AbstractSet with custom implementations of those methods - // that can be overriden easily and efficiently. - entries = new AbstractSet() - { - public int size() - { - return size; - } - - public Iterator iterator() - { - return new TreeIterator(ENTRIES); - } - - public void clear() - { - TreeMap.this.clear(); - } - - public boolean contains(Object o) - { - if (! (o instanceof Map.Entry)) - return false; - Map.Entry me = (Map.Entry) o; - Node n = getNode(me.getKey()); - return n != nil && AbstractSet.equals(me.getValue(), n.value); - } - - public boolean remove(Object o) - { - if (! (o instanceof Map.Entry)) - return false; - Map.Entry me = (Map.Entry) o; - Node n = getNode(me.getKey()); - if (n != nil && AbstractSet.equals(me.getValue(), n.value)) - { - removeNode(n); - return true; - } - return false; - } - }; - return entries; - } - - /** - * Returns the first (lowest) key in the map. - * - * @return the first key - * @throws NoSuchElementException if the map is empty - */ - public Object firstKey() - { - if (root == nil) - throw new NoSuchElementException(); - return firstNode().key; - } - - /** - * Return the value in this TreeMap associated with the supplied key, - * or <code>null</code> if the key maps to nothing. NOTE: Since the value - * could also be null, you must use containsKey to see if this key - * actually maps to something. - * - * @param key the key for which to fetch an associated value - * @return what the key maps to, if present - * @throws ClassCastException if key is not comparable to elements in the map - * @throws NullPointerException if key is null but the comparator does not - * tolerate nulls - * @see #put(Object, Object) - * @see #containsKey(Object) - */ - public Object get(Object key) - { - // Exploit fact that nil.value == null. - return getNode(key).value; - } - - /** - * Returns a view of this Map including all entries with keys less than - * <code>toKey</code>. The returned map is backed by the original, so changes - * in one appear in the other. The submap will throw an - * {@link IllegalArgumentException} for any attempt to access or add an - * element beyond the specified cutoff. The returned map does not include - * the endpoint; if you want inclusion, pass the successor element. - * - * @param toKey the (exclusive) cutoff point - * @return a view of the map less than the cutoff - * @throws ClassCastException if <code>toKey</code> is not compatible with - * the comparator (or is not Comparable, for natural ordering) - * @throws NullPointerException if toKey is null, but the comparator does not - * tolerate null elements - */ - public SortedMap headMap(Object toKey) - { - return new SubMap(nil, toKey); - } - - /** - * Returns a "set view" of this TreeMap's keys. The set is backed by the - * TreeMap, so changes in one show up in the other. The set supports - * element removal, but not element addition. - * - * @return a set view of the keys - * @see #values() - * @see #entrySet() - */ - public Set keySet() - { - if (keys == null) - // Create an AbstractSet with custom implementations of those methods - // that can be overriden easily and efficiently. - keys = new AbstractSet() - { - public int size() - { - return size; - } - - public Iterator iterator() - { - return new TreeIterator(KEYS); - } - - public void clear() - { - TreeMap.this.clear(); - } - - public boolean contains(Object o) - { - return containsKey(o); - } - - public boolean remove(Object key) - { - Node n = getNode(key); - if (n == nil) - return false; - removeNode(n); - return true; - } - }; - return keys; - } - - /** - * Returns the last (highest) key in the map. - * - * @return the last key - * @throws NoSuchElementException if the map is empty - */ - public Object lastKey() - { - if (root == nil) - throw new NoSuchElementException("empty"); - return lastNode().key; - } - - /** - * Puts the supplied value into the Map, mapped by the supplied key. - * The value may be retrieved by any object which <code>equals()</code> - * this key. NOTE: Since the prior value could also be null, you must - * first use containsKey if you want to see if you are replacing the - * key's mapping. - * - * @param key the key used to locate the value - * @param value the value to be stored in the Map - * @return the prior mapping of the key, or null if there was none - * @throws ClassCastException if key is not comparable to current map keys - * @throws NullPointerException if key is null, but the comparator does - * not tolerate nulls - * @see #get(Object) - * @see Object#equals(Object) - */ - public Object put(Object key, Object value) - { - Node current = root; - Node parent = nil; - int comparison = 0; - - // Find new node's parent. - while (current != nil) - { - parent = current; - comparison = compare(key, current.key); - if (comparison > 0) - current = current.right; - else if (comparison < 0) - current = current.left; - else // Key already in tree. - return current.setValue(value); - } - - // Set up new node. - Node n = new Node(key, value, RED); - n.parent = parent; - - // Insert node in tree. - modCount++; - size++; - if (parent == nil) - { - // Special case inserting into an empty tree. - root = n; - return null; - } - if (comparison > 0) - parent.right = n; - else - parent.left = n; - - // Rebalance after insert. - insertFixup(n); - return null; - } - - /** - * Copies all elements of the given map into this TreeMap. If this map - * already has a mapping for a key, the new mapping replaces the current - * one. - * - * @param m the map to be added - * @throws ClassCastException if a key in m is not comparable with keys - * in the map - * @throws NullPointerException if a key in m is null, and the comparator - * does not tolerate nulls - */ - public void putAll(Map m) - { - Iterator itr = m.entrySet().iterator(); - int pos = m.size(); - while (--pos >= 0) - { - Map.Entry e = (Map.Entry) itr.next(); - put(e.getKey(), e.getValue()); - } - } - - /** - * Removes from the TreeMap and returns the value which is mapped by the - * supplied key. If the key maps to nothing, then the TreeMap remains - * unchanged, and <code>null</code> is returned. NOTE: Since the value - * could also be null, you must use containsKey to see if you are - * actually removing a mapping. - * - * @param key the key used to locate the value to remove - * @return whatever the key mapped to, if present - * @throws ClassCastException if key is not comparable to current map keys - * @throws NullPointerException if key is null, but the comparator does - * not tolerate nulls - */ - public Object remove(Object key) - { - Node n = getNode(key); - if (n == nil) - return null; - // Note: removeNode can alter the contents of n, so save value now. - Object result = n.value; - removeNode(n); - return result; - } - - /** - * Returns the number of key-value mappings currently in this Map. - * - * @return the size - */ - public int size() - { - return size; - } - - /** - * Returns a view of this Map including all entries with keys greater or - * equal to <code>fromKey</code> and less than <code>toKey</code> (a - * half-open interval). The returned map is backed by the original, so - * changes in one appear in the other. The submap will throw an - * {@link IllegalArgumentException} for any attempt to access or add an - * element beyond the specified cutoffs. The returned map includes the low - * endpoint but not the high; if you want to reverse this behavior on - * either end, pass in the successor element. - * - * @param fromKey the (inclusive) low cutoff point - * @param toKey the (exclusive) high cutoff point - * @return a view of the map between the cutoffs - * @throws ClassCastException if either cutoff is not compatible with - * the comparator (or is not Comparable, for natural ordering) - * @throws NullPointerException if fromKey or toKey is null, but the - * comparator does not tolerate null elements - * @throws IllegalArgumentException if fromKey is greater than toKey - */ - public SortedMap subMap(Object fromKey, Object toKey) - { - return new SubMap(fromKey, toKey); - } - - /** - * Returns a view of this Map including all entries with keys greater or - * equal to <code>fromKey</code>. The returned map is backed by the - * original, so changes in one appear in the other. The submap will throw an - * {@link IllegalArgumentException} for any attempt to access or add an - * element beyond the specified cutoff. The returned map includes the - * endpoint; if you want to exclude it, pass in the successor element. - * - * @param fromKey the (inclusive) low cutoff point - * @return a view of the map above the cutoff - * @throws ClassCastException if <code>fromKey</code> is not compatible with - * the comparator (or is not Comparable, for natural ordering) - * @throws NullPointerException if fromKey is null, but the comparator - * does not tolerate null elements - */ - public SortedMap tailMap(Object fromKey) - { - return new SubMap(fromKey, nil); - } - - /** - * Returns a "collection view" (or "bag view") of this TreeMap's values. - * The collection is backed by the TreeMap, so changes in one show up - * in the other. The collection supports element removal, but not element - * addition. - * - * @return a bag view of the values - * @see #keySet() - * @see #entrySet() - */ - public Collection values() - { - if (values == null) - // We don't bother overriding many of the optional methods, as doing so - // wouldn't provide any significant performance advantage. - values = new AbstractCollection() - { - public int size() - { - return size; - } - - public Iterator iterator() - { - return new TreeIterator(VALUES); - } - - public void clear() - { - TreeMap.this.clear(); - } - }; - return values; - } - - /** - * Compares two elements by the set comparator, or by natural ordering. - * Package visible for use by nested classes. - * - * @param o1 the first object - * @param o2 the second object - * @throws ClassCastException if o1 and o2 are not mutually comparable, - * or are not Comparable with natural ordering - * @throws NullPointerException if o1 or o2 is null with natural ordering - */ - final int compare(Object o1, Object o2) - { - return (comparator == null - ? ((Comparable) o1).compareTo(o2) - : comparator.compare(o1, o2)); - } - - /** - * Maintain red-black balance after deleting a node. - * - * @param node the child of the node just deleted, possibly nil - * @param parent the parent of the node just deleted, never nil - */ - private void deleteFixup(Node node, Node parent) - { - // if (parent == nil) - // throw new InternalError(); - // If a black node has been removed, we need to rebalance to avoid - // violating the "same number of black nodes on any path" rule. If - // node is red, we can simply recolor it black and all is well. - while (node != root && node.color == BLACK) - { - if (node == parent.left) - { - // Rebalance left side. - Node sibling = parent.right; - // if (sibling == nil) - // throw new InternalError(); - if (sibling.color == RED) - { - // Case 1: Sibling is red. - // Recolor sibling and parent, and rotate parent left. - sibling.color = BLACK; - parent.color = RED; - rotateLeft(parent); - sibling = parent.right; - } - - if (sibling.left.color == BLACK && sibling.right.color == BLACK) - { - // Case 2: Sibling has no red children. - // Recolor sibling, and move to parent. - sibling.color = RED; - node = parent; - parent = parent.parent; - } - else - { - if (sibling.right.color == BLACK) - { - // Case 3: Sibling has red left child. - // Recolor sibling and left child, rotate sibling right. - sibling.left.color = BLACK; - sibling.color = RED; - rotateRight(sibling); - sibling = parent.right; - } - // Case 4: Sibling has red right child. Recolor sibling, - // right child, and parent, and rotate parent left. - sibling.color = parent.color; - parent.color = BLACK; - sibling.right.color = BLACK; - rotateLeft(parent); - node = root; // Finished. - } - } - else - { - // Symmetric "mirror" of left-side case. - Node sibling = parent.left; - // if (sibling == nil) - // throw new InternalError(); - if (sibling.color == RED) - { - // Case 1: Sibling is red. - // Recolor sibling and parent, and rotate parent right. - sibling.color = BLACK; - parent.color = RED; - rotateRight(parent); - sibling = parent.left; - } - - if (sibling.right.color == BLACK && sibling.left.color == BLACK) - { - // Case 2: Sibling has no red children. - // Recolor sibling, and move to parent. - sibling.color = RED; - node = parent; - parent = parent.parent; - } - else - { - if (sibling.left.color == BLACK) - { - // Case 3: Sibling has red right child. - // Recolor sibling and right child, rotate sibling left. - sibling.right.color = BLACK; - sibling.color = RED; - rotateLeft(sibling); - sibling = parent.left; - } - // Case 4: Sibling has red left child. Recolor sibling, - // left child, and parent, and rotate parent right. - sibling.color = parent.color; - parent.color = BLACK; - sibling.left.color = BLACK; - rotateRight(parent); - node = root; // Finished. - } - } - } - node.color = BLACK; - } - - /** - * Construct a perfectly balanced tree consisting of n "blank" nodes. This - * permits a tree to be generated from pre-sorted input in linear time. - * - * @param count the number of blank nodes, non-negative - */ - private void fabricateTree(final int count) - { - if (count == 0) - { - root = nil; - size = 0; - return; - } - - // We color every row of nodes black, except for the overflow nodes. - // I believe that this is the optimal arrangement. We construct the tree - // in place by temporarily linking each node to the next node in the row, - // then updating those links to the children when working on the next row. - - // Make the root node. - root = new Node(null, null, BLACK); - size = count; - Node row = root; - int rowsize; - - // Fill each row that is completely full of nodes. - for (rowsize = 2; rowsize + rowsize <= count; rowsize <<= 1) - { - Node parent = row; - Node last = null; - for (int i = 0; i < rowsize; i += 2) - { - Node left = new Node(null, null, BLACK); - Node right = new Node(null, null, BLACK); - left.parent = parent; - left.right = right; - right.parent = parent; - parent.left = left; - Node next = parent.right; - parent.right = right; - parent = next; - if (last != null) - last.right = left; - last = right; - } - row = row.left; - } - - // Now do the partial final row in red. - int overflow = count - rowsize; - Node parent = row; - int i; - for (i = 0; i < overflow; i += 2) - { - Node left = new Node(null, null, RED); - Node right = new Node(null, null, RED); - left.parent = parent; - right.parent = parent; - parent.left = left; - Node next = parent.right; - parent.right = right; - parent = next; - } - // Add a lone left node if necessary. - if (i - overflow == 0) - { - Node left = new Node(null, null, RED); - left.parent = parent; - parent.left = left; - parent = parent.right; - left.parent.right = nil; - } - // Unlink the remaining nodes of the previous row. - while (parent != nil) - { - Node next = parent.right; - parent.right = nil; - parent = next; - } - } - - /** - * Returns the first sorted node in the map, or nil if empty. Package - * visible for use by nested classes. - * - * @return the first node - */ - final Node firstNode() - { - // Exploit fact that nil.left == nil. - Node node = root; - while (node.left != nil) - node = node.left; - return node; - } - - /** - * Return the TreeMap.Node associated with key, or the nil node if no such - * node exists in the tree. Package visible for use by nested classes. - * - * @param key the key to search for - * @return the node where the key is found, or nil - */ - final Node getNode(Object key) - { - Node current = root; - while (current != nil) - { - int comparison = compare(key, current.key); - if (comparison > 0) - current = current.right; - else if (comparison < 0) - current = current.left; - else - return current; - } - return current; - } - - /** - * Find the "highest" node which is < key. If key is nil, return last - * node. Package visible for use by nested classes. - * - * @param key the upper bound, exclusive - * @return the previous node - */ - final Node highestLessThan(Object key) - { - if (key == nil) - return lastNode(); - - Node last = nil; - Node current = root; - int comparison = 0; - - while (current != nil) - { - last = current; - comparison = compare(key, current.key); - if (comparison > 0) - current = current.right; - else if (comparison < 0) - current = current.left; - else // Exact match. - return predecessor(last); - } - return comparison <= 0 ? predecessor(last) : last; - } - - /** - * Maintain red-black balance after inserting a new node. - * - * @param n the newly inserted node - */ - private void insertFixup(Node n) - { - // Only need to rebalance when parent is a RED node, and while at least - // 2 levels deep into the tree (ie: node has a grandparent). Remember - // that nil.color == BLACK. - while (n.parent.color == RED && n.parent.parent != nil) - { - if (n.parent == n.parent.parent.left) - { - Node uncle = n.parent.parent.right; - // Uncle may be nil, in which case it is BLACK. - if (uncle.color == RED) - { - // Case 1. Uncle is RED: Change colors of parent, uncle, - // and grandparent, and move n to grandparent. - n.parent.color = BLACK; - uncle.color = BLACK; - uncle.parent.color = RED; - n = uncle.parent; - } - else - { - if (n == n.parent.right) - { - // Case 2. Uncle is BLACK and x is right child. - // Move n to parent, and rotate n left. - n = n.parent; - rotateLeft(n); - } - // Case 3. Uncle is BLACK and x is left child. - // Recolor parent, grandparent, and rotate grandparent right. - n.parent.color = BLACK; - n.parent.parent.color = RED; - rotateRight(n.parent.parent); - } - } - else - { - // Mirror image of above code. - Node uncle = n.parent.parent.left; - // Uncle may be nil, in which case it is BLACK. - if (uncle.color == RED) - { - // Case 1. Uncle is RED: Change colors of parent, uncle, - // and grandparent, and move n to grandparent. - n.parent.color = BLACK; - uncle.color = BLACK; - uncle.parent.color = RED; - n = uncle.parent; - } - else - { - if (n == n.parent.left) - { - // Case 2. Uncle is BLACK and x is left child. - // Move n to parent, and rotate n right. - n = n.parent; - rotateRight(n); - } - // Case 3. Uncle is BLACK and x is right child. - // Recolor parent, grandparent, and rotate grandparent left. - n.parent.color = BLACK; - n.parent.parent.color = RED; - rotateLeft(n.parent.parent); - } - } - } - root.color = BLACK; - } - - /** - * Returns the last sorted node in the map, or nil if empty. - * - * @return the last node - */ - private Node lastNode() - { - // Exploit fact that nil.right == nil. - Node node = root; - while (node.right != nil) - node = node.right; - return node; - } - - /** - * Find the "lowest" node which is >= key. If key is nil, return either - * nil or the first node, depending on the parameter first. - * Package visible for use by nested classes. - * - * @param key the lower bound, inclusive - * @param first true to return the first element instead of nil for nil key - * @return the next node - */ - final Node lowestGreaterThan(Object key, boolean first) - { - if (key == nil) - return first ? firstNode() : nil; - - Node last = nil; - Node current = root; - int comparison = 0; - - while (current != nil) - { - last = current; - comparison = compare(key, current.key); - if (comparison > 0) - current = current.right; - else if (comparison < 0) - current = current.left; - else - return current; - } - return comparison > 0 ? successor(last) : last; - } - - /** - * Return the node preceding the given one, or nil if there isn't one. - * - * @param node the current node, not nil - * @return the prior node in sorted order - */ - private Node predecessor(Node node) - { - if (node.left != nil) - { - node = node.left; - while (node.right != nil) - node = node.right; - return node; - } - - Node parent = node.parent; - // Exploit fact that nil.left == nil and node is non-nil. - while (node == parent.left) - { - node = parent; - parent = node.parent; - } - return parent; - } - - /** - * Construct a tree from sorted keys in linear time. Package visible for - * use by TreeSet. - * - * @param s the stream to read from - * @param count the number of keys to read - * @param readValue true to read values, false to insert "" as the value - * @throws ClassNotFoundException if the underlying stream fails - * @throws IOException if the underlying stream fails - * @see #readObject(ObjectInputStream) - * @see TreeSet#readObject(ObjectInputStream) - */ - final void putFromObjStream(ObjectInputStream s, int count, - boolean readValues) - throws IOException, ClassNotFoundException - { - fabricateTree(count); - Node node = firstNode(); - - while (--count >= 0) - { - node.key = s.readObject(); - node.value = readValues ? s.readObject() : ""; - node = successor(node); - } - } - - /** - * Construct a tree from sorted keys in linear time, with values of "". - * Package visible for use by TreeSet. - * - * @param keys the iterator over the sorted keys - * @param count the number of nodes to insert - * @see TreeSet#TreeSet(SortedSet) - */ - final void putKeysLinear(Iterator keys, int count) - { - fabricateTree(count); - Node node = firstNode(); - - while (--count >= 0) - { - node.key = keys.next(); - node.value = ""; - node = successor(node); - } - } - - /** - * Deserializes this object from the given stream. - * - * @param s the stream to read from - * @throws ClassNotFoundException if the underlying stream fails - * @throws IOException if the underlying stream fails - * @serialData the <i>size</i> (int), followed by key (Object) and value - * (Object) pairs in sorted order - */ - private void readObject(ObjectInputStream s) - throws IOException, ClassNotFoundException - { - s.defaultReadObject(); - int size = s.readInt(); - putFromObjStream(s, size, true); - } - - /** - * Remove node from tree. This will increment modCount and decrement size. - * Node must exist in the tree. Package visible for use by nested classes. - * - * @param node the node to remove - */ - final void removeNode(Node node) - { - Node splice; - Node child; - - modCount++; - size--; - - // Find splice, the node at the position to actually remove from the tree. - if (node.left == nil) - { - // Node to be deleted has 0 or 1 children. - splice = node; - child = node.right; - } - else if (node.right == nil) - { - // Node to be deleted has 1 child. - splice = node; - child = node.left; - } - else - { - // Node has 2 children. Splice is node's predecessor, and we swap - // its contents into node. - splice = node.left; - while (splice.right != nil) - splice = splice.right; - child = splice.left; - node.key = splice.key; - node.value = splice.value; - } - - // Unlink splice from the tree. - Node parent = splice.parent; - if (child != nil) - child.parent = parent; - if (parent == nil) - { - // Special case for 0 or 1 node remaining. - root = child; - return; - } - if (splice == parent.left) - parent.left = child; - else - parent.right = child; - - if (splice.color == BLACK) - deleteFixup(child, parent); - } - - /** - * Rotate node n to the left. - * - * @param node the node to rotate - */ - private void rotateLeft(Node node) - { - Node child = node.right; - // if (node == nil || child == nil) - // throw new InternalError(); - - // Establish node.right link. - node.right = child.left; - if (child.left != nil) - child.left.parent = node; - - // Establish child->parent link. - child.parent = node.parent; - if (node.parent != nil) - { - if (node == node.parent.left) - node.parent.left = child; - else - node.parent.right = child; - } - else - root = child; - - // Link n and child. - child.left = node; - node.parent = child; - } - - /** - * Rotate node n to the right. - * - * @param node the node to rotate - */ - private void rotateRight(Node node) - { - Node child = node.left; - // if (node == nil || child == nil) - // throw new InternalError(); - - // Establish node.left link. - node.left = child.right; - if (child.right != nil) - child.right.parent = node; - - // Establish child->parent link. - child.parent = node.parent; - if (node.parent != nil) - { - if (node == node.parent.right) - node.parent.right = child; - else - node.parent.left = child; - } - else - root = child; - - // Link n and child. - child.right = node; - node.parent = child; - } - - /** - * Return the node following the given one, or nil if there isn't one. - * Package visible for use by nested classes. - * - * @param node the current node, not nil - * @return the next node in sorted order - */ - final Node successor(Node node) - { - if (node.right != nil) - { - node = node.right; - while (node.left != nil) - node = node.left; - return node; - } - - Node parent = node.parent; - // Exploit fact that nil.right == nil and node is non-nil. - while (node == parent.right) - { - node = parent; - parent = parent.parent; - } - return parent; - } - - /** - * Serializes this object to the given stream. - * - * @param s the stream to write to - * @throws IOException if the underlying stream fails - * @serialData the <i>size</i> (int), followed by key (Object) and value - * (Object) pairs in sorted order - */ - private void writeObject(ObjectOutputStream s) throws IOException - { - s.defaultWriteObject(); - - Node node = firstNode(); - s.writeInt(size); - while (node != nil) - { - s.writeObject(node.key); - s.writeObject(node.value); - node = successor(node); - } - } - - /** - * Iterate over TreeMap's entries. This implementation is parameterized - * to give a sequential view of keys, values, or entries. - * - * @author Eric Blake (ebb9@email.byu.edu) - */ - private final class TreeIterator implements Iterator - { - /** - * The type of this Iterator: {@link #KEYS}, {@link #VALUES}, - * or {@link #ENTRIES}. - */ - private final int type; - /** The number of modifications to the backing Map that we know about. */ - private int knownMod = modCount; - /** The last Entry returned by a next() call. */ - private Node last; - /** The next entry that should be returned by next(). */ - private Node next; - /** - * The last node visible to this iterator. This is used when iterating - * on a SubMap. - */ - private final Node max; - - /** - * Construct a new TreeIterator with the supplied type. - * @param type {@link #KEYS}, {@link #VALUES}, or {@link #ENTRIES} - */ - TreeIterator(int type) - { - // FIXME gcj cannot handle this. Bug java/4695 - // this(type, firstNode(), nil); - this.type = type; - this.next = firstNode(); - this.max = nil; - } - - /** - * Construct a new TreeIterator with the supplied type. Iteration will - * be from "first" (inclusive) to "max" (exclusive). - * - * @param type {@link #KEYS}, {@link #VALUES}, or {@link #ENTRIES} - * @param first where to start iteration, nil for empty iterator - * @param max the cutoff for iteration, nil for all remaining nodes - */ - TreeIterator(int type, Node first, Node max) - { - this.type = type; - this.next = first; - this.max = max; - } - - /** - * Returns true if the Iterator has more elements. - * @return true if there are more elements - * @throws ConcurrentModificationException if the TreeMap was modified - */ - public boolean hasNext() - { - if (knownMod != modCount) - throw new ConcurrentModificationException(); - return next != max; - } - - /** - * Returns the next element in the Iterator's sequential view. - * @return the next element - * @throws ConcurrentModificationException if the TreeMap was modified - * @throws NoSuchElementException if there is none - */ - public Object next() - { - if (knownMod != modCount) - throw new ConcurrentModificationException(); - if (next == max) - throw new NoSuchElementException(); - last = next; - next = successor(last); - - if (type == VALUES) - return last.value; - else if (type == KEYS) - return last.key; - return last; - } - - /** - * Removes from the backing TreeMap the last element which was fetched - * with the <code>next()</code> method. - * @throws ConcurrentModificationException if the TreeMap was modified - * @throws IllegalStateException if called when there is no last element - */ - public void remove() - { - if (last == null) - throw new IllegalStateException(); - if (knownMod != modCount) - throw new ConcurrentModificationException(); - - removeNode(last); - last = null; - knownMod++; - } - } // class TreeIterator - - /** - * Implementation of {@link #subMap(Object, Object)} and other map - * ranges. This class provides a view of a portion of the original backing - * map, and throws {@link IllegalArgumentException} for attempts to - * access beyond that range. - * - * @author Eric Blake (ebb9@email.byu.edu) - */ - private final class SubMap extends AbstractMap implements SortedMap - { - /** - * The lower range of this view, inclusive, or nil for unbounded. - * Package visible for use by nested classes. - */ - final Object minKey; - - /** - * The upper range of this view, exclusive, or nil for unbounded. - * Package visible for use by nested classes. - */ - final Object maxKey; - - /** - * The cache for {@link #entrySet()}. - */ - private Set entries; - - /** - * Create a SubMap representing the elements between minKey (inclusive) - * and maxKey (exclusive). If minKey is nil, SubMap has no lower bound - * (headMap). If maxKey is nil, the SubMap has no upper bound (tailMap). - * - * @param minKey the lower bound - * @param maxKey the upper bound - * @throws IllegalArgumentException if minKey > maxKey - */ - SubMap(Object minKey, Object maxKey) - { - if (minKey != nil && maxKey != nil && compare(minKey, maxKey) > 0) - throw new IllegalArgumentException("fromKey > toKey"); - this.minKey = minKey; - this.maxKey = maxKey; - } - - /** - * Check if "key" is in within the range bounds for this SubMap. The - * lower ("from") SubMap range is inclusive, and the upper ("to") bound - * is exclusive. Package visible for use by nested classes. - * - * @param key the key to check - * @return true if the key is in range - */ - boolean keyInRange(Object key) - { - return ((minKey == nil || compare(key, minKey) >= 0) - && (maxKey == nil || compare(key, maxKey) < 0)); - } - - public void clear() - { - Node next = lowestGreaterThan(minKey, true); - Node max = lowestGreaterThan(maxKey, false); - while (next != max) - { - Node current = next; - next = successor(current); - removeNode(current); - } - } - - public Comparator comparator() - { - return comparator; - } - - public boolean containsKey(Object key) - { - return keyInRange(key) && TreeMap.this.containsKey(key); - } - - public boolean containsValue(Object value) - { - Node node = lowestGreaterThan(minKey, true); - Node max = lowestGreaterThan(maxKey, false); - while (node != max) - { - if (equals(value, node.getValue())) - return true; - node = successor(node); - } - return false; - } - - public Set entrySet() - { - if (entries == null) - // Create an AbstractSet with custom implementations of those methods - // that can be overriden easily and efficiently. - entries = new AbstractSet() - { - public int size() - { - return SubMap.this.size(); - } - - public Iterator iterator() - { - Node first = lowestGreaterThan(minKey, true); - Node max = lowestGreaterThan(maxKey, false); - return new TreeIterator(ENTRIES, first, max); - } - - public void clear() - { - SubMap.this.clear(); - } - - public boolean contains(Object o) - { - if (! (o instanceof Map.Entry)) - return false; - Map.Entry me = (Map.Entry) o; - Object key = me.getKey(); - if (! keyInRange(key)) - return false; - Node n = getNode(key); - return n != nil && AbstractSet.equals(me.getValue(), n.value); - } - - public boolean remove(Object o) - { - if (! (o instanceof Map.Entry)) - return false; - Map.Entry me = (Map.Entry) o; - Object key = me.getKey(); - if (! keyInRange(key)) - return false; - Node n = getNode(key); - if (n != nil && AbstractSet.equals(me.getValue(), n.value)) - { - removeNode(n); - return true; - } - return false; - } - }; - return entries; - } - - public Object firstKey() - { - Node node = lowestGreaterThan(minKey, true); - if (node == nil || ! keyInRange(node.key)) - throw new NoSuchElementException(); - return node.key; - } - - public Object get(Object key) - { - if (keyInRange(key)) - return TreeMap.this.get(key); - return null; - } - - public SortedMap headMap(Object toKey) - { - if (! keyInRange(toKey)) - throw new IllegalArgumentException("key outside range"); - return new SubMap(minKey, toKey); - } - - public Set keySet() - { - if (this.keys == null) - // Create an AbstractSet with custom implementations of those methods - // that can be overriden easily and efficiently. - this.keys = new AbstractSet() - { - public int size() - { - return SubMap.this.size(); - } - - public Iterator iterator() - { - Node first = lowestGreaterThan(minKey, true); - Node max = lowestGreaterThan(maxKey, false); - return new TreeIterator(KEYS, first, max); - } - - public void clear() - { - SubMap.this.clear(); - } - - public boolean contains(Object o) - { - if (! keyInRange(o)) - return false; - return getNode(o) != nil; - } - - public boolean remove(Object o) - { - if (! keyInRange(o)) - return false; - Node n = getNode(o); - if (n != nil) - { - removeNode(n); - return true; - } - return false; - } - }; - return this.keys; - } - - public Object lastKey() - { - Node node = highestLessThan(maxKey); - if (node == nil || ! keyInRange(node.key)) - throw new NoSuchElementException(); - return node.key; - } - - public Object put(Object key, Object value) - { - if (! keyInRange(key)) - throw new IllegalArgumentException("Key outside range"); - return TreeMap.this.put(key, value); - } - - public Object remove(Object key) - { - if (keyInRange(key)) - return TreeMap.this.remove(key); - return null; - } - - public int size() - { - Node node = lowestGreaterThan(minKey, true); - Node max = lowestGreaterThan(maxKey, false); - int count = 0; - while (node != max) - { - count++; - node = successor(node); - } - return count; - } - - public SortedMap subMap(Object fromKey, Object toKey) - { - if (! keyInRange(fromKey) || ! keyInRange(toKey)) - throw new IllegalArgumentException("key outside range"); - return new SubMap(fromKey, toKey); - } - - public SortedMap tailMap(Object fromKey) - { - if (! keyInRange(fromKey)) - throw new IllegalArgumentException("key outside range"); - return new SubMap(fromKey, maxKey); - } - - public Collection values() - { - if (this.values == null) - // Create an AbstractCollection with custom implementations of those - // methods that can be overriden easily and efficiently. - this.values = new AbstractCollection() - { - public int size() - { - return SubMap.this.size(); - } - - public Iterator iterator() - { - Node first = lowestGreaterThan(minKey, true); - Node max = lowestGreaterThan(maxKey, false); - return new TreeIterator(VALUES, first, max); - } - - public void clear() - { - SubMap.this.clear(); - } - }; - return this.values; - } - } // class SubMap -} // class TreeMap diff --git a/libjava/java/util/TreeSet.java b/libjava/java/util/TreeSet.java deleted file mode 100644 index 34cb39acc07..00000000000 --- a/libjava/java/util/TreeSet.java +++ /dev/null @@ -1,416 +0,0 @@ -/* TreeSet.java -- a class providing a TreeMap-backed SortedSet - Copyright (C) 1999, 2000, 2001, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util; - -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; - -/** - * This class provides a TreeMap-backed implementation of the SortedSet - * interface. The elements will be sorted according to their <i>natural - * order</i>, or according to the provided <code>Comparator</code>.<p> - * - * Most operations are O(log n), but there is so much overhead that this - * makes small sets expensive. Note that the ordering must be <i>consistent - * with equals</i> to correctly implement the Set interface. If this - * condition is violated, the set is still well-behaved, but you may have - * suprising results when comparing it to other sets.<p> - * - * This implementation is not synchronized. If you need to share this between - * multiple threads, do something like:<br> - * <code>SortedSet s - * = Collections.synchronizedSortedSet(new TreeSet(...));</code><p> - * - * The iterators are <i>fail-fast</i>, meaning that any structural - * modification, except for <code>remove()</code> called on the iterator - * itself, cause the iterator to throw a - * <code>ConcurrentModificationException</code> rather than exhibit - * non-deterministic behavior. - * - * @author Jon Zeppieri - * @author Bryce McKinlay - * @author Eric Blake (ebb9@email.byu.edu) - * @see Collection - * @see Set - * @see HashSet - * @see LinkedHashSet - * @see Comparable - * @see Comparator - * @see Collections#synchronizedSortedSet(SortedSet) - * @see TreeMap - * @since 1.2 - * @status updated to 1.4 - */ -public class TreeSet extends AbstractSet - implements SortedSet, Cloneable, Serializable -{ - /** - * Compatible with JDK 1.2. - */ - private static final long serialVersionUID = -2479143000061671589L; - - /** - * The SortedMap which backs this Set. - */ - // Not final because of readObject. This will always be one of TreeMap or - // TreeMap.SubMap, which both extend AbstractMap. - private transient SortedMap map; - - /** - * Construct a new TreeSet whose backing TreeMap using the "natural" - * ordering of keys. Elements that are not mutually comparable will cause - * ClassCastExceptions down the road. - * - * @see Comparable - */ - public TreeSet() - { - map = new TreeMap(); - } - - /** - * Construct a new TreeSet whose backing TreeMap uses the supplied - * Comparator. Elements that are not mutually comparable will cause - * ClassCastExceptions down the road. - * - * @param comparator the Comparator this Set will use - */ - public TreeSet(Comparator comparator) - { - map = new TreeMap(comparator); - } - - /** - * Construct a new TreeSet whose backing TreeMap uses the "natural" - * orering of the keys and which contains all of the elements in the - * supplied Collection. This runs in n*log(n) time. - * - * @param collection the new Set will be initialized with all - * of the elements in this Collection - * @throws ClassCastException if the elements of the collection are not - * comparable - * @throws NullPointerException if the collection is null - * @see Comparable - */ - public TreeSet(Collection collection) - { - map = new TreeMap(); - addAll(collection); - } - - /** - * Construct a new TreeSet, using the same key ordering as the supplied - * SortedSet and containing all of the elements in the supplied SortedSet. - * This constructor runs in linear time. - * - * @param sortedSet the new TreeSet will use this SortedSet's comparator - * and will initialize itself with all its elements - * @throws NullPointerException if sortedSet is null - */ - public TreeSet(SortedSet sortedSet) - { - map = new TreeMap(sortedSet.comparator()); - Iterator itr = sortedSet.iterator(); - ((TreeMap) map).putKeysLinear(itr, sortedSet.size()); - } - - /** - * This private constructor is used to implement the subSet() calls around - * a backing TreeMap.SubMap. - * - * @param backingMap the submap - */ - private TreeSet(SortedMap backingMap) - { - map = backingMap; - } - - /** - * Adds the spplied Object to the Set if it is not already in the Set; - * returns true if the element is added, false otherwise. - * - * @param obj the Object to be added to this Set - * @throws ClassCastException if the element cannot be compared with objects - * already in the set - */ - public boolean add(Object obj) - { - return map.put(obj, "") == null; - } - - /** - * Adds all of the elements in the supplied Collection to this TreeSet. - * - * @param c The collection to add - * @return true if the Set is altered, false otherwise - * @throws NullPointerException if c is null - * @throws ClassCastException if an element in c cannot be compared with - * objects already in the set - */ - public boolean addAll(Collection c) - { - boolean result = false; - int pos = c.size(); - Iterator itr = c.iterator(); - while (--pos >= 0) - result |= (map.put(itr.next(), "") == null); - return result; - } - - /** - * Removes all elements in this Set. - */ - public void clear() - { - map.clear(); - } - - /** - * Returns a shallow copy of this Set. The elements are not cloned. - * - * @return the cloned set - */ - public Object clone() - { - TreeSet copy = null; - try - { - copy = (TreeSet) super.clone(); - // Map may be either TreeMap or TreeMap.SubMap, hence the ugly casts. - copy.map = (SortedMap) ((AbstractMap) map).clone(); - } - catch (CloneNotSupportedException x) - { - // Impossible result. - } - return copy; - } - - /** - * Returns this Set's comparator. - * - * @return the comparator, or null if the set uses natural ordering - */ - public Comparator comparator() - { - return map.comparator(); - } - - /** - * Returns true if this Set contains the supplied Object, false otherwise. - * - * @param obj the Object to check for - * @return true if it is in the set - * @throws ClassCastException if obj cannot be compared with objects - * already in the set - */ - public boolean contains(Object obj) - { - return map.containsKey(obj); - } - - /** - * Returns the first (by order) element in this Set. - * - * @return the first element - * @throws NoSuchElementException if the set is empty - */ - public Object first() - { - return map.firstKey(); - } - - /** - * Returns a view of this Set including all elements less than - * <code>to</code>. The returned set is backed by the original, so changes - * in one appear in the other. The subset will throw an - * {@link IllegalArgumentException} for any attempt to access or add an - * element beyond the specified cutoff. The returned set does not include - * the endpoint; if you want inclusion, pass the successor element. - * - * @param to the (exclusive) cutoff point - * @return a view of the set less than the cutoff - * @throws ClassCastException if <code>to</code> is not compatible with - * the comparator (or is not Comparable, for natural ordering) - * @throws NullPointerException if to is null, but the comparator does not - * tolerate null elements - */ - public SortedSet headSet(Object to) - { - return new TreeSet(map.headMap(to)); - } - - /** - * Returns true if this Set has size 0, false otherwise. - * - * @return true if the set is empty - */ - public boolean isEmpty() - { - return map.isEmpty(); - } - - /** - * Returns in Iterator over the elements in this TreeSet, which traverses - * in ascending order. - * - * @return an iterator - */ - public Iterator iterator() - { - return map.keySet().iterator(); - } - - /** - * Returns the last (by order) element in this Set. - * - * @return the last element - * @throws NoSuchElementException if the set is empty - */ - public Object last() - { - return map.lastKey(); - } - - /** - * If the supplied Object is in this Set, it is removed, and true is - * returned; otherwise, false is returned. - * - * @param obj the Object to remove from this Set - * @return true if the set was modified - * @throws ClassCastException if obj cannot be compared to set elements - */ - public boolean remove(Object obj) - { - return map.remove(obj) != null; - } - - /** - * Returns the number of elements in this Set - * - * @return the set size - */ - public int size() - { - return map.size(); - } - - /** - * Returns a view of this Set including all elements greater or equal to - * <code>from</code> and less than <code>to</code> (a half-open interval). - * The returned set is backed by the original, so changes in one appear in - * the other. The subset will throw an {@link IllegalArgumentException} - * for any attempt to access or add an element beyond the specified cutoffs. - * The returned set includes the low endpoint but not the high; if you want - * to reverse this behavior on either end, pass in the successor element. - * - * @param from the (inclusive) low cutoff point - * @param to the (exclusive) high cutoff point - * @return a view of the set between the cutoffs - * @throws ClassCastException if either cutoff is not compatible with - * the comparator (or is not Comparable, for natural ordering) - * @throws NullPointerException if from or to is null, but the comparator - * does not tolerate null elements - * @throws IllegalArgumentException if from is greater than to - */ - public SortedSet subSet(Object from, Object to) - { - return new TreeSet(map.subMap(from, to)); - } - - /** - * Returns a view of this Set including all elements greater or equal to - * <code>from</code>. The returned set is backed by the original, so - * changes in one appear in the other. The subset will throw an - * {@link IllegalArgumentException} for any attempt to access or add an - * element beyond the specified cutoff. The returned set includes the - * endpoint; if you want to exclude it, pass in the successor element. - * - * @param from the (inclusive) low cutoff point - * @return a view of the set above the cutoff - * @throws ClassCastException if <code>from</code> is not compatible with - * the comparator (or is not Comparable, for natural ordering) - * @throws NullPointerException if from is null, but the comparator - * does not tolerate null elements - */ - public SortedSet tailSet(Object from) - { - return new TreeSet(map.tailMap(from)); - } - - /** - * Serializes this object to the given stream. - * - * @param s the stream to write to - * @throws IOException if the underlying stream fails - * @serialData the <i>comparator</i> (Object), followed by the set size - * (int), the the elements in sorted order (Object) - */ - private void writeObject(ObjectOutputStream s) throws IOException - { - s.defaultWriteObject(); - Iterator itr = map.keySet().iterator(); - int pos = map.size(); - s.writeObject(map.comparator()); - s.writeInt(pos); - while (--pos >= 0) - s.writeObject(itr.next()); - } - - /** - * Deserializes this object from the given stream. - * - * @param s the stream to read from - * @throws ClassNotFoundException if the underlying stream fails - * @throws IOException if the underlying stream fails - * @serialData the <i>comparator</i> (Object), followed by the set size - * (int), the the elements in sorted order (Object) - */ - private void readObject(ObjectInputStream s) - throws IOException, ClassNotFoundException - { - s.defaultReadObject(); - Comparator comparator = (Comparator) s.readObject(); - int size = s.readInt(); - map = new TreeMap(comparator); - ((TreeMap) map).putFromObjStream(s, size, false); - } -} diff --git a/libjava/java/util/Vector.java b/libjava/java/util/Vector.java deleted file mode 100644 index e26d7aaa4dd..00000000000 --- a/libjava/java/util/Vector.java +++ /dev/null @@ -1,931 +0,0 @@ -/* Vector.java -- Class that provides growable arrays. - Copyright (C) 1998, 1999, 2000, 2001, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util; -import java.io.IOException; -import java.io.ObjectOutputStream; -import java.io.Serializable; -import java.lang.reflect.Array; - -/** - * The <code>Vector</code> classes implements growable arrays of Objects. - * You can access elements in a Vector with an index, just as you - * can in a built in array, but Vectors can grow and shrink to accommodate - * more or fewer objects.<p> - * - * Vectors try to mantain efficiency in growing by having a - * <code>capacityIncrement</code> that can be specified at instantiation. - * When a Vector can no longer hold a new Object, it grows by the amount - * in <code>capacityIncrement</code>. If this value is 0, the vector doubles in - * size.<p> - * - * Vector implements the JDK 1.2 List interface, and is therefore a fully - * compliant Collection object. The iterators are fail-fast - if external - * code structurally modifies the vector, any operation on the iterator will - * then throw a {@link ConcurrentModificationException}. The Vector class is - * fully synchronized, but the iterators are not. So, when iterating over a - * vector, be sure to synchronize on the vector itself. If you don't want the - * expense of synchronization, use ArrayList instead. On the other hand, the - * Enumeration of elements() is not thread-safe, nor is it fail-fast; so it - * can lead to undefined behavior even in a single thread if you modify the - * vector during iteration.<p> - * - * Note: Some methods, especially those specified by List, specify throwing - * {@link IndexOutOfBoundsException}, but it is easier to implement by - * throwing the subclass {@link ArrayIndexOutOfBoundsException}. Others - * directly specify this subclass. - * - * @author Scott G. Miller - * @author Bryce McKinlay - * @author Eric Blake (ebb9@email.byu.edu) - * @see Collection - * @see List - * @see ArrayList - * @see LinkedList - * @since 1.0 - * @status updated to 1.4 - */ -public class Vector extends AbstractList - implements List, RandomAccess, Cloneable, Serializable -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = -2767605614048989439L; - - /** - * The internal array used to hold members of a Vector. The elements are - * in positions 0 through elementCount - 1, and all remaining slots are null. - * @serial the elements - */ - protected Object[] elementData; - - /** - * The number of elements currently in the vector, also returned by - * {@link #size}. - * @serial the size - */ - protected int elementCount; - - /** - * The amount the Vector's internal array should be increased in size when - * a new element is added that exceeds the current size of the array, - * or when {@link #ensureCapacity} is called. If <= 0, the vector just - * doubles in size. - * @serial the amount to grow the vector by - */ - protected int capacityIncrement; - - /** - * Constructs an empty vector with an initial size of 10, and - * a capacity increment of 0 - */ - public Vector() - { - this(10, 0); - } - - /** - * Constructs a vector containing the contents of Collection, in the - * order given by the collection. - * - * @param c collection of elements to add to the new vector - * @throws NullPointerException if c is null - * @since 1.2 - */ - public Vector(Collection c) - { - elementCount = c.size(); - elementData = c.toArray(new Object[elementCount]); - } - - /** - * Constructs a Vector with the initial capacity and capacity - * increment specified. - * - * @param initialCapacity the initial size of the Vector's internal array - * @param capacityIncrement the amount the internal array should be - * increased by when necessary, 0 to double the size - * @throws IllegalArgumentException if initialCapacity < 0 - */ - public Vector(int initialCapacity, int capacityIncrement) - { - if (initialCapacity < 0) - throw new IllegalArgumentException(); - elementData = new Object[initialCapacity]; - this.capacityIncrement = capacityIncrement; - } - - /** - * Constructs a Vector with the initial capacity specified, and a capacity - * increment of 0 (double in size). - * - * @param initialCapacity the initial size of the Vector's internal array - * @throws IllegalArgumentException if initialCapacity < 0 - */ - public Vector(int initialCapacity) - { - this(initialCapacity, 0); - } - - /** - * Copies the contents of a provided array into the Vector. If the - * array is too large to fit in the Vector, an IndexOutOfBoundsException - * is thrown without modifying the array. Old elements in the Vector are - * overwritten by the new elements. - * - * @param a target array for the copy - * @throws IndexOutOfBoundsException the array is not large enough - * @throws NullPointerException the array is null - * @see #toArray(Object[]) - */ - public synchronized void copyInto(Object[] a) - { - System.arraycopy(elementData, 0, a, 0, elementCount); - } - - /** - * Trims the Vector down to size. If the internal data array is larger - * than the number of Objects its holding, a new array is constructed - * that precisely holds the elements. Otherwise this does nothing. - */ - public synchronized void trimToSize() - { - // Don't bother checking for the case where size() == the capacity of the - // vector since that is a much less likely case; it's more efficient to - // not do the check and lose a bit of performance in that infrequent case - - Object[] newArray = new Object[elementCount]; - System.arraycopy(elementData, 0, newArray, 0, elementCount); - elementData = newArray; - } - - /** - * Ensures that <code>minCapacity</code> elements can fit within this Vector. - * If <code>elementData</code> is too small, it is expanded as follows: - * If the <code>elementCount + capacityIncrement</code> is adequate, that - * is the new size. If <code>capacityIncrement</code> is non-zero, the - * candidate size is double the current. If that is not enough, the new - * size is <code>minCapacity</code>. - * - * @param minCapacity the desired minimum capacity, negative values ignored - */ - public synchronized void ensureCapacity(int minCapacity) - { - if (elementData.length >= minCapacity) - return; - - int newCapacity; - if (capacityIncrement <= 0) - newCapacity = elementData.length * 2; - else - newCapacity = elementData.length + capacityIncrement; - - Object[] newArray = new Object[Math.max(newCapacity, minCapacity)]; - - System.arraycopy(elementData, 0, newArray, 0, elementCount); - elementData = newArray; - } - - /** - * Explicitly sets the size of the vector (but not necessarily the size of - * the internal data array). If the new size is smaller than the old one, - * old values that don't fit are lost. If the new size is larger than the - * old one, the vector is padded with null entries. - * - * @param newSize The new size of the internal array - * @throws ArrayIndexOutOfBoundsException if the new size is negative - */ - public synchronized void setSize(int newSize) - { - // Don't bother checking for the case where size() == the capacity of the - // vector since that is a much less likely case; it's more efficient to - // not do the check and lose a bit of performance in that infrequent case - modCount++; - ensureCapacity(newSize); - if (newSize < elementCount) - Arrays.fill(elementData, newSize, elementCount, null); - elementCount = newSize; - } - - /** - * Returns the size of the internal data array (not the amount of elements - * contained in the Vector). - * - * @return capacity of the internal data array - */ - public synchronized int capacity() - { - return elementData.length; - } - - /** - * Returns the number of elements stored in this Vector. - * - * @return the number of elements in this Vector - */ - public synchronized int size() - { - return elementCount; - } - - /** - * Returns true if this Vector is empty, false otherwise - * - * @return true if the Vector is empty, false otherwise - */ - public synchronized boolean isEmpty() - { - return elementCount == 0; - } - - /** - * Returns an Enumeration of the elements of this Vector. The enumeration - * visits the elements in increasing index order, but is NOT thread-safe. - * - * @return an Enumeration - * @see #iterator() - */ - // No need to synchronize as the Enumeration is not thread-safe! - public Enumeration elements() - { - return new Enumeration() - { - private int i = 0; - - public boolean hasMoreElements() - { - return i < elementCount; - } - - public Object nextElement() - { - if (i >= elementCount) - throw new NoSuchElementException(); - return elementData[i++]; - } - }; - } - - /** - * Returns true when <code>elem</code> is contained in this Vector. - * - * @param elem the element to check - * @return true if the object is contained in this Vector, false otherwise - */ - public boolean contains(Object elem) - { - return indexOf(elem, 0) >= 0; - } - - /** - * Returns the first occurrence of <code>elem</code> in the Vector, or -1 if - * <code>elem</code> is not found. - * - * @param elem the object to search for - * @return the index of the first occurrence, or -1 if not found - */ - public int indexOf(Object elem) - { - return indexOf(elem, 0); - } - - /** - * Searches the vector starting at <code>index</code> for object - * <code>elem</code> and returns the index of the first occurrence of this - * Object. If the object is not found, or index is larger than the size - * of the vector, -1 is returned. - * - * @param e the Object to search for - * @param index start searching at this index - * @return the index of the next occurrence, or -1 if it is not found - * @throws IndexOutOfBoundsException if index < 0 - */ - public synchronized int indexOf(Object e, int index) - { - for (int i = index; i < elementCount; i++) - if (equals(e, elementData[i])) - return i; - return -1; - } - - /** - * Returns the last index of <code>elem</code> within this Vector, or -1 - * if the object is not within the Vector. - * - * @param elem the object to search for - * @return the last index of the object, or -1 if not found - */ - public int lastIndexOf(Object elem) - { - return lastIndexOf(elem, elementCount - 1); - } - - /** - * Returns the index of the first occurrence of <code>elem</code>, when - * searching backwards from <code>index</code>. If the object does not - * occur in this Vector, or index is less than 0, -1 is returned. - * - * @param e the object to search for - * @param index the index to start searching in reverse from - * @return the index of the Object if found, -1 otherwise - * @throws IndexOutOfBoundsException if index >= size() - */ - public synchronized int lastIndexOf(Object e, int index) - { - checkBoundExclusive(index); - for (int i = index; i >= 0; i--) - if (equals(e, elementData[i])) - return i; - return -1; - } - - /** - * Returns the Object stored at <code>index</code>. - * - * @param index the index of the Object to retrieve - * @return the object at <code>index</code> - * @throws ArrayIndexOutOfBoundsException index < 0 || index >= size() - * @see #get(int) - */ - public synchronized Object elementAt(int index) - { - checkBoundExclusive(index); - return elementData[index]; - } - - /** - * Returns the first element (index 0) in the Vector. - * - * @return the first Object in the Vector - * @throws NoSuchElementException the Vector is empty - */ - public synchronized Object firstElement() - { - if (elementCount == 0) - throw new NoSuchElementException(); - - return elementData[0]; - } - - /** - * Returns the last element in the Vector. - * - * @return the last Object in the Vector - * @throws NoSuchElementException the Vector is empty - */ - public synchronized Object lastElement() - { - if (elementCount == 0) - throw new NoSuchElementException(); - - return elementData[elementCount - 1]; - } - - /** - * Changes the element at <code>index</code> to be <code>obj</code> - * - * @param obj the object to store - * @param index the position in the Vector to store the object - * @throws ArrayIndexOutOfBoundsException the index is out of range - * @see #set(int, Object) - */ - public void setElementAt(Object obj, int index) - { - set(index, obj); - } - - /** - * Removes the element at <code>index</code>, and shifts all elements at - * positions greater than index to their index - 1. - * - * @param index the index of the element to remove - * @throws ArrayIndexOutOfBoundsException index < 0 || index >= size(); - * @see #remove(int) - */ - public void removeElementAt(int index) - { - remove(index); - } - - /** - * Inserts a new element into the Vector at <code>index</code>. Any elements - * at or greater than index are shifted up one position. - * - * @param obj the object to insert - * @param index the index at which the object is inserted - * @throws ArrayIndexOutOfBoundsException index < 0 || index > size() - * @see #add(int, Object) - */ - public synchronized void insertElementAt(Object obj, int index) - { - checkBoundInclusive(index); - if (elementCount == elementData.length) - ensureCapacity(elementCount + 1); - modCount++; - System.arraycopy(elementData, index, elementData, index + 1, - elementCount - index); - elementCount++; - elementData[index] = obj; - } - - /** - * Adds an element to the Vector at the end of the Vector. The vector - * is increased by ensureCapacity(size() + 1) if needed. - * - * @param obj the object to add to the Vector - */ - public synchronized void addElement(Object obj) - { - if (elementCount == elementData.length) - ensureCapacity(elementCount + 1); - modCount++; - elementData[elementCount++] = obj; - } - - /** - * Removes the first (the lowestindex) occurance of the given object from - * the Vector. If such a remove was performed (the object was found), true - * is returned. If there was no such object, false is returned. - * - * @param obj the object to remove from the Vector - * @return true if the Object was in the Vector, false otherwise - * @see #remove(Object) - */ - public synchronized boolean removeElement(Object obj) - { - int idx = indexOf(obj, 0); - if (idx >= 0) - { - remove(idx); - return true; - } - return false; - } - - /** - * Removes all elements from the Vector. Note that this does not - * resize the internal data array. - * - * @see #clear() - */ - public synchronized void removeAllElements() - { - if (elementCount == 0) - return; - - modCount++; - Arrays.fill(elementData, 0, elementCount, null); - elementCount = 0; - } - - /** - * Creates a new Vector with the same contents as this one. The clone is - * shallow; elements are not cloned. - * - * @return the clone of this vector - */ - public synchronized Object clone() - { - try - { - Vector clone = (Vector) super.clone(); - clone.elementData = (Object[]) elementData.clone(); - return clone; - } - catch (CloneNotSupportedException ex) - { - // Impossible to get here. - throw new InternalError(ex.toString()); - } - } - - /** - * Returns an Object array with the contents of this Vector, in the order - * they are stored within this Vector. Note that the Object array returned - * is not the internal data array, and that it holds only the elements - * within the Vector. This is similar to creating a new Object[] with the - * size of this Vector, then calling Vector.copyInto(yourArray). - * - * @return an Object[] containing the contents of this Vector in order - * @since 1.2 - */ - public synchronized Object[] toArray() - { - Object[] newArray = new Object[elementCount]; - copyInto(newArray); - return newArray; - } - - /** - * Returns an array containing the contents of this Vector. - * If the provided array is large enough, the contents are copied - * into that array, and a null is placed in the position size(). - * In this manner, you can obtain the size of a Vector by the position - * of the null element, if you know the vector does not itself contain - * null entries. If the array is not large enough, reflection is used - * to create a bigger one of the same runtime type. - * - * @param a an array to copy the Vector into if large enough - * @return an array with the contents of this Vector in order - * @throws ArrayStoreException the runtime type of the provided array - * cannot hold the elements of the Vector - * @throws NullPointerException if <code>a</code> is null - * @since 1.2 - */ - public synchronized Object[] toArray(Object[] a) - { - if (a.length < elementCount) - a = (Object[]) Array.newInstance(a.getClass().getComponentType(), - elementCount); - else if (a.length > elementCount) - a[elementCount] = null; - System.arraycopy(elementData, 0, a, 0, elementCount); - return a; - } - - /** - * Returns the element at position <code>index</code>. - * - * @param index the position from which an element will be retrieved - * @return the element at that position - * @throws ArrayIndexOutOfBoundsException index < 0 || index >= size() - * @since 1.2 - */ - public Object get(int index) - { - return elementAt(index); - } - - /** - * Puts <code>element</code> into the Vector at position <code>index</code> - * and returns the Object that previously occupied that position. - * - * @param index the index within the Vector to place the Object - * @param element the Object to store in the Vector - * @return the previous object at the specified index - * @throws ArrayIndexOutOfBoundsException index < 0 || index >= size() - * @since 1.2 - */ - public synchronized Object set(int index, Object element) - { - checkBoundExclusive(index); - Object temp = elementData[index]; - elementData[index] = element; - return temp; - } - - /** - * Adds an object to the Vector. - * - * @param o the element to add to the Vector - * @return true, as specified by List - * @since 1.2 - */ - public boolean add(Object o) - { - addElement(o); - return true; - } - - /** - * Removes the given Object from the Vector. If it exists, true - * is returned, if not, false is returned. - * - * @param o the object to remove from the Vector - * @return true if the Object existed in the Vector, false otherwise - * @since 1.2 - */ - public boolean remove(Object o) - { - return removeElement(o); - } - - /** - * Adds an object at the specified index. Elements at or above - * index are shifted up one position. - * - * @param index the index at which to add the element - * @param element the element to add to the Vector - * @throws ArrayIndexOutOfBoundsException index < 0 || index > size() - * @since 1.2 - */ - public void add(int index, Object element) - { - insertElementAt(element, index); - } - - /** - * Removes the element at the specified index, and returns it. - * - * @param index the position from which to remove the element - * @return the object removed - * @throws ArrayIndexOutOfBoundsException index < 0 || index >= size() - * @since 1.2 - */ - public synchronized Object remove(int index) - { - checkBoundExclusive(index); - Object temp = elementData[index]; - modCount++; - elementCount--; - if (index < elementCount) - System.arraycopy(elementData, index + 1, elementData, index, - elementCount - index); - elementData[elementCount] = null; - return temp; - } - - /** - * Clears all elements in the Vector and sets its size to 0. - */ - public void clear() - { - removeAllElements(); - } - - /** - * Returns true if this Vector contains all the elements in c. - * - * @param c the collection to compare to - * @return true if this vector contains all elements of c - * @throws NullPointerException if c is null - * @since 1.2 - */ - public synchronized boolean containsAll(Collection c) - { - // Here just for the sychronization. - return super.containsAll(c); - } - - /** - * Appends all elements of the given collection to the end of this Vector. - * Behavior is undefined if the collection is modified during this operation - * (for example, if this == c). - * - * @param c the collection to append - * @return true if this vector changed, in other words c was not empty - * @throws NullPointerException if c is null - * @since 1.2 - */ - public synchronized boolean addAll(Collection c) - { - return addAll(elementCount, c); - } - - /** - * Remove from this vector all elements contained in the given collection. - * - * @param c the collection to filter out - * @return true if this vector changed - * @throws NullPointerException if c is null - * @since 1.2 - */ - public synchronized boolean removeAll(Collection c) - { - if (c == null) - throw new NullPointerException(); - - int i; - int j; - for (i = 0; i < elementCount; i++) - if (c.contains(elementData[i])) - break; - if (i == elementCount) - return false; - - modCount++; - for (j = i++; i < elementCount; i++) - if (! c.contains(elementData[i])) - elementData[j++] = elementData[i]; - elementCount -= i - j; - return true; - } - - /** - * Retain in this vector only the elements contained in the given collection. - * - * @param c the collection to filter by - * @return true if this vector changed - * @throws NullPointerException if c is null - * @since 1.2 - */ - public synchronized boolean retainAll(Collection c) - { - if (c == null) - throw new NullPointerException(); - - int i; - int j; - for (i = 0; i < elementCount; i++) - if (! c.contains(elementData[i])) - break; - if (i == elementCount) - return false; - - modCount++; - for (j = i++; i < elementCount; i++) - if (c.contains(elementData[i])) - elementData[j++] = elementData[i]; - elementCount -= i - j; - return true; - } - - /** - * Inserts all elements of the given collection at the given index of - * this Vector. Behavior is undefined if the collection is modified during - * this operation (for example, if this == c). - * - * @param c the collection to append - * @return true if this vector changed, in other words c was not empty - * @throws NullPointerException if c is null - * @throws ArrayIndexOutOfBoundsException index < 0 || index > size() - * @since 1.2 - */ - public synchronized boolean addAll(int index, Collection c) - { - checkBoundInclusive(index); - Iterator itr = c.iterator(); - int csize = c.size(); - - modCount++; - ensureCapacity(elementCount + csize); - int end = index + csize; - if (elementCount > 0 && index != elementCount) - System.arraycopy(elementData, index, - elementData, end, elementCount - index); - elementCount += csize; - for ( ; index < end; index++) - elementData[index] = itr.next(); - return (csize > 0); - } - - /** - * Compares this to the given object. - * - * @param o the object to compare to - * @return true if the two are equal - * @since 1.2 - */ - public synchronized boolean equals(Object o) - { - // Here just for the sychronization. - return super.equals(o); - } - - /** - * Computes the hashcode of this object. - * - * @return the hashcode - * @since 1.2 - */ - public synchronized int hashCode() - { - // Here just for the sychronization. - return super.hashCode(); - } - - /** - * Returns a string representation of this Vector in the form - * "[element0, element1, ... elementN]". - * - * @return the String representation of this Vector - */ - public synchronized String toString() - { - // Here just for the sychronization. - return super.toString(); - } - - /** - * Obtain a List view of a subsection of this list, from fromIndex - * (inclusive) to toIndex (exclusive). If the two indices are equal, the - * sublist is empty. The returned list is modifiable, and changes in one - * reflect in the other. If this list is structurally modified in - * any way other than through the returned list, the result of any subsequent - * operations on the returned list is undefined. - * <p> - * - * @param fromIndex the index that the returned list should start from - * (inclusive) - * @param toIndex the index that the returned list should go to (exclusive) - * @return a List backed by a subsection of this vector - * @throws IndexOutOfBoundsException if fromIndex < 0 - * || toIndex > size() - * @throws IllegalArgumentException if fromIndex > toIndex - * @see ConcurrentModificationException - * @since 1.2 - */ - public synchronized List subList(int fromIndex, int toIndex) - { - List sub = super.subList(fromIndex, toIndex); - // We must specify the correct object to synchronize upon, hence the - // use of a non-public API - return new Collections.SynchronizedList(this, sub); - } - - /** - * Removes a range of elements from this list. - * Does nothing when toIndex is equal to fromIndex. - * - * @param fromIndex the index to start deleting from (inclusive) - * @param toIndex the index to delete up to (exclusive) - * @throws IndexOutOfBoundsException if fromIndex > toIndex - */ - // This does not need to be synchronized, because it is only called through - // clear() of a sublist, and clear() had already synchronized. - protected void removeRange(int fromIndex, int toIndex) - { - int change = toIndex - fromIndex; - if (change > 0) - { - modCount++; - System.arraycopy(elementData, toIndex, elementData, fromIndex, - elementCount - toIndex); - int save = elementCount; - elementCount -= change; - Arrays.fill(elementData, elementCount, save, null); - } - else if (change < 0) - throw new IndexOutOfBoundsException(); - } - - /** - * Checks that the index is in the range of possible elements (inclusive). - * - * @param index the index to check - * @throws ArrayIndexOutOfBoundsException if index > size - */ - private void checkBoundInclusive(int index) - { - // Implementation note: we do not check for negative ranges here, since - // use of a negative index will cause an ArrayIndexOutOfBoundsException - // with no effort on our part. - if (index > elementCount) - throw new ArrayIndexOutOfBoundsException(index + " > " + elementCount); - } - - /** - * Checks that the index is in the range of existing elements (exclusive). - * - * @param index the index to check - * @throws ArrayIndexOutOfBoundsException if index >= size - */ - private void checkBoundExclusive(int index) - { - // Implementation note: we do not check for negative ranges here, since - // use of a negative index will cause an ArrayIndexOutOfBoundsException - // with no effort on our part. - if (index >= elementCount) - throw new ArrayIndexOutOfBoundsException(index + " >= " + elementCount); - } - - /** - * Serializes this object to the given stream. - * - * @param s the stream to write to - * @throws IOException if the underlying stream fails - * @serialData just calls default write function - */ - private synchronized void writeObject(ObjectOutputStream s) - throws IOException - { - s.defaultWriteObject(); - } - -} diff --git a/libjava/java/util/WeakHashMap.java b/libjava/java/util/WeakHashMap.java deleted file mode 100644 index 7593f7e330e..00000000000 --- a/libjava/java/util/WeakHashMap.java +++ /dev/null @@ -1,881 +0,0 @@ -/* WeakHashMap -- a hashtable that keeps only weak references - to its keys, allowing the virtual machine to reclaim them - Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util; - -import java.lang.ref.ReferenceQueue; -import java.lang.ref.WeakReference; - -/** - * A weak hash map has only weak references to the key. This means that it - * allows the key to be garbage collected if it is not used otherwise. If - * this happens, the entry will eventually disappear from the map, - * asynchronously. - * - * <p>A weak hash map makes most sense when the keys doesn't override the - * <code>equals</code> method: If there is no other reference to the - * key nobody can ever look up the key in this table and so the entry - * can be removed. This table also works when the <code>equals</code> - * method is overloaded, such as String keys, but you should be prepared - * to deal with some entries disappearing spontaneously. - * - * <p>Other strange behaviors to be aware of: The size of this map may - * spontaneously shrink (even if you use a synchronized map and synchronize - * it); it behaves as if another thread removes entries from this table - * without synchronization. The entry set returned by <code>entrySet</code> - * has similar phenomenons: The size may spontaneously shrink, or an - * entry, that was in the set before, suddenly disappears. - * - * <p>A weak hash map is not meant for caches; use a normal map, with - * soft references as values instead, or try {@link LinkedHashMap}. - * - * <p>The weak hash map supports null values and null keys. The null key - * is never deleted from the map (except explictly of course). The - * performance of the methods are similar to that of a hash map. - * - * <p>The value objects are strongly referenced by this table. So if a - * value object maintains a strong reference to the key (either direct - * or indirect) the key will never be removed from this map. According - * to Sun, this problem may be fixed in a future release. It is not - * possible to do it with the jdk 1.2 reference model, though. - * - * @author Jochen Hoenicke - * @author Eric Blake (ebb9@email.byu.edu) - * - * @see HashMap - * @see WeakReference - * @see LinkedHashMap - * @since 1.2 - * @status updated to 1.4 - */ -public class WeakHashMap extends AbstractMap implements Map -{ - // WARNING: WeakHashMap is a CORE class in the bootstrap cycle. See the - // comments in vm/reference/java/lang/Runtime for implications of this fact. - - /** - * The default capacity for an instance of HashMap. - * Sun's documentation mildly suggests that this (11) is the correct - * value. - */ - private static final int DEFAULT_CAPACITY = 11; - - /** - * The default load factor of a HashMap. - */ - private static final float DEFAULT_LOAD_FACTOR = 0.75F; - - /** - * This is used instead of the key value <i>null</i>. It is needed - * to distinguish between an null key and a removed key. - */ - // Package visible for use by nested classes. - static final Object NULL_KEY = new Object() - { - /** - * Sets the hashCode to 0, since that's what null would map to. - * @return the hash code 0 - */ - public int hashCode() - { - return 0; - } - - /** - * Compares this key to the given object. Normally, an object should - * NEVER compare equal to null, but since we don't publicize NULL_VALUE, - * it saves bytecode to do so here. - * @return true iff o is this or null - */ - public boolean equals(Object o) - { - return null == o || this == o; - } - }; - - /** - * The reference queue where our buckets (which are WeakReferences) are - * registered to. - */ - private final ReferenceQueue queue; - - /** - * The number of entries in this hash map. - */ - // Package visible for use by nested classes. - int size; - - /** - * The load factor of this WeakHashMap. This is the maximum ratio of - * size versus number of buckets. If size grows the number of buckets - * must grow, too. - */ - private float loadFactor; - - /** - * The rounded product of the capacity (i.e. number of buckets) and - * the load factor. When the number of elements exceeds the - * threshold, the HashMap calls <code>rehash()</code>. - */ - private int threshold; - - /** - * The number of structural modifications. This is used by - * iterators, to see if they should fail. This doesn't count - * the silent key removals, when a weak reference is cleared - * by the garbage collection. Instead the iterators must make - * sure to have strong references to the entries they rely on. - */ - // Package visible for use by nested classes. - int modCount; - - /** - * The entry set. There is only one instance per hashmap, namely - * theEntrySet. Note that the entry set may silently shrink, just - * like the WeakHashMap. - */ - private final class WeakEntrySet extends AbstractSet - { - /** - * Non-private constructor to reduce bytecode emitted. - */ - WeakEntrySet() - { - } - - /** - * Returns the size of this set. - * - * @return the set size - */ - public int size() - { - return size; - } - - /** - * Returns an iterator for all entries. - * - * @return an Entry iterator - */ - public Iterator iterator() - { - return new Iterator() - { - /** - * The entry that was returned by the last - * <code>next()</code> call. This is also the entry whose - * bucket should be removed by the <code>remove</code> call. <br> - * - * It is null, if the <code>next</code> method wasn't - * called yet, or if the entry was already removed. <br> - * - * Remembering this entry here will also prevent it from - * being removed under us, since the entry strongly refers - * to the key. - */ - WeakBucket.WeakEntry lastEntry; - - /** - * The entry that will be returned by the next - * <code>next()</code> call. It is <code>null</code> if there - * is no further entry. <br> - * - * Remembering this entry here will also prevent it from - * being removed under us, since the entry strongly refers - * to the key. - */ - WeakBucket.WeakEntry nextEntry = findNext(null); - - /** - * The known number of modification to the list, if it differs - * from the real number, we throw an exception. - */ - int knownMod = modCount; - - /** - * Check the known number of modification to the number of - * modifications of the table. If it differs from the real - * number, we throw an exception. - * @throws ConcurrentModificationException if the number - * of modifications doesn't match. - */ - private void checkMod() - { - // This method will get inlined. - cleanQueue(); - if (knownMod != modCount) - throw new ConcurrentModificationException(); - } - - /** - * Get a strong reference to the next entry after - * lastBucket. - * @param lastEntry the previous bucket, or null if we should - * get the first entry. - * @return the next entry. - */ - private WeakBucket.WeakEntry findNext(WeakBucket.WeakEntry lastEntry) - { - int slot; - WeakBucket nextBucket; - if (lastEntry != null) - { - nextBucket = lastEntry.getBucket().next; - slot = lastEntry.getBucket().slot; - } - else - { - nextBucket = buckets[0]; - slot = 0; - } - - while (true) - { - while (nextBucket != null) - { - WeakBucket.WeakEntry entry = nextBucket.getEntry(); - if (entry != null) - // This is the next entry. - return entry; - - // Entry was cleared, try next. - nextBucket = nextBucket.next; - } - - slot++; - if (slot == buckets.length) - // No more buckets, we are through. - return null; - - nextBucket = buckets[slot]; - } - } - - /** - * Checks if there are more entries. - * @return true, iff there are more elements. - * @throws ConcurrentModificationException if the hash map was - * modified. - */ - public boolean hasNext() - { - checkMod(); - return nextEntry != null; - } - - /** - * Returns the next entry. - * @return the next entry. - * @throws ConcurrentModificationException if the hash map was - * modified. - * @throws NoSuchElementException if there is no entry. - */ - public Object next() - { - checkMod(); - if (nextEntry == null) - throw new NoSuchElementException(); - lastEntry = nextEntry; - nextEntry = findNext(lastEntry); - return lastEntry; - } - - /** - * Removes the last returned entry from this set. This will - * also remove the bucket of the underlying weak hash map. - * @throws ConcurrentModificationException if the hash map was - * modified. - * @throws IllegalStateException if <code>next()</code> was - * never called or the element was already removed. - */ - public void remove() - { - checkMod(); - if (lastEntry == null) - throw new IllegalStateException(); - modCount++; - internalRemove(lastEntry.getBucket()); - lastEntry = null; - knownMod++; - } - }; - } - } - - /** - * A bucket is a weak reference to the key, that contains a strong - * reference to the value, a pointer to the next bucket and its slot - * number. <br> - * - * It would be cleaner to have a WeakReference as field, instead of - * extending it, but if a weak reference gets cleared, we only get - * the weak reference (by queue.poll) and wouldn't know where to - * look for this reference in the hashtable, to remove that entry. - * - * @author Jochen Hoenicke - */ - private static class WeakBucket extends WeakReference - { - /** - * The value of this entry. The key is stored in the weak - * reference that we extend. - */ - Object value; - - /** - * The next bucket describing another entry that uses the same - * slot. - */ - WeakBucket next; - - /** - * The slot of this entry. This should be - * <code>Math.abs(key.hashCode() % buckets.length)</code>. - * - * But since the key may be silently removed we have to remember - * the slot number. - * - * If this bucket was removed the slot is -1. This marker will - * prevent the bucket from being removed twice. - */ - int slot; - - /** - * Creates a new bucket for the given key/value pair and the specified - * slot. - * @param key the key - * @param queue the queue the weak reference belongs to - * @param value the value - * @param slot the slot. This must match the slot where this bucket - * will be enqueued. - */ - public WeakBucket(Object key, ReferenceQueue queue, Object value, - int slot) - { - super(key, queue); - this.value = value; - this.slot = slot; - } - - /** - * This class gives the <code>Entry</code> representation of the - * current bucket. It also keeps a strong reference to the - * key; bad things may happen otherwise. - */ - class WeakEntry implements Map.Entry - { - /** - * The strong ref to the key. - */ - Object key; - - /** - * Creates a new entry for the key. - * @param key the key - */ - public WeakEntry(Object key) - { - this.key = key; - } - - /** - * Returns the underlying bucket. - * @return the owning bucket - */ - public WeakBucket getBucket() - { - return WeakBucket.this; - } - - /** - * Returns the key. - * @return the key - */ - public Object getKey() - { - return key == NULL_KEY ? null : key; - } - - /** - * Returns the value. - * @return the value - */ - public Object getValue() - { - return value; - } - - /** - * This changes the value. This change takes place in - * the underlying hash map. - * @param newVal the new value - * @return the old value - */ - public Object setValue(Object newVal) - { - Object oldVal = value; - value = newVal; - return oldVal; - } - - /** - * The hashCode as specified in the Entry interface. - * @return the hash code - */ - public int hashCode() - { - return key.hashCode() ^ WeakHashMap.hashCode(value); - } - - /** - * The equals method as specified in the Entry interface. - * @param o the object to compare to - * @return true iff o represents the same key/value pair - */ - public boolean equals(Object o) - { - if (o instanceof Map.Entry) - { - Map.Entry e = (Map.Entry) o; - return key.equals(e.getKey()) - && WeakHashMap.equals(value, e.getValue()); - } - return false; - } - - public String toString() - { - return key + "=" + value; - } - } - - /** - * This returns the entry stored in this bucket, or null, if the - * bucket got cleared in the mean time. - * @return the Entry for this bucket, if it exists - */ - WeakEntry getEntry() - { - final Object key = this.get(); - if (key == null) - return null; - return new WeakEntry(key); - } - } - - /** - * The entry set returned by <code>entrySet()</code>. - */ - private final WeakEntrySet theEntrySet; - - /** - * The hash buckets. These are linked lists. Package visible for use in - * nested classes. - */ - WeakBucket[] buckets; - - /** - * Creates a new weak hash map with default load factor and default - * capacity. - */ - public WeakHashMap() - { - this(DEFAULT_CAPACITY, DEFAULT_LOAD_FACTOR); - } - - /** - * Creates a new weak hash map with default load factor and the given - * capacity. - * @param initialCapacity the initial capacity - * @throws IllegalArgumentException if initialCapacity is negative - */ - public WeakHashMap(int initialCapacity) - { - this(initialCapacity, DEFAULT_LOAD_FACTOR); - } - - /** - * Creates a new weak hash map with the given initial capacity and - * load factor. - * @param initialCapacity the initial capacity. - * @param loadFactor the load factor (see class description of HashMap). - * @throws IllegalArgumentException if initialCapacity is negative, or - * loadFactor is non-positive - */ - public WeakHashMap(int initialCapacity, float loadFactor) - { - // Check loadFactor for NaN as well. - if (initialCapacity < 0 || ! (loadFactor > 0)) - throw new IllegalArgumentException(); - if (initialCapacity == 0) - initialCapacity = 1; - this.loadFactor = loadFactor; - threshold = (int) (initialCapacity * loadFactor); - theEntrySet = new WeakEntrySet(); - queue = new ReferenceQueue(); - buckets = new WeakBucket[initialCapacity]; - } - - /** - * Construct a new WeakHashMap with the same mappings as the given map. - * The WeakHashMap has a default load factor of 0.75. - * - * @param m the map to copy - * @throws NullPointerException if m is null - * @since 1.3 - */ - public WeakHashMap(Map m) - { - this(m.size(), DEFAULT_LOAD_FACTOR); - putAll(m); - } - - /** - * Simply hashes a non-null Object to its array index. - * @param key the key to hash - * @return its slot number - */ - private int hash(Object key) - { - return Math.abs(key.hashCode() % buckets.length); - } - - /** - * Cleans the reference queue. This will poll all references (which - * are WeakBuckets) from the queue and remove them from this map. - * This will not change modCount, even if it modifies the map. The - * iterators have to make sure that nothing bad happens. <br> - * - * Currently the iterator maintains a strong reference to the key, so - * that is no problem. - */ - // Package visible for use by nested classes. - void cleanQueue() - { - Object bucket = queue.poll(); - while (bucket != null) - { - internalRemove((WeakBucket) bucket); - bucket = queue.poll(); - } - } - - /** - * Rehashes this hashtable. This will be called by the - * <code>add()</code> method if the size grows beyond the threshold. - * It will grow the bucket size at least by factor two and allocates - * new buckets. - */ - private void rehash() - { - WeakBucket[] oldBuckets = buckets; - int newsize = buckets.length * 2 + 1; // XXX should be prime. - threshold = (int) (newsize * loadFactor); - buckets = new WeakBucket[newsize]; - - // Now we have to insert the buckets again. - for (int i = 0; i < oldBuckets.length; i++) - { - WeakBucket bucket = oldBuckets[i]; - WeakBucket nextBucket; - while (bucket != null) - { - nextBucket = bucket.next; - - Object key = bucket.get(); - if (key == null) - { - // This bucket should be removed; it is probably - // already on the reference queue. We don't insert it - // at all, and mark it as cleared. - bucket.slot = -1; - size--; - } - else - { - // Add this bucket to its new slot. - int slot = hash(key); - bucket.slot = slot; - bucket.next = buckets[slot]; - buckets[slot] = bucket; - } - bucket = nextBucket; - } - } - } - - /** - * Finds the entry corresponding to key. Since it returns an Entry - * it will also prevent the key from being removed under us. - * @param key the key, may be null - * @return The WeakBucket.WeakEntry or null, if the key wasn't found. - */ - private WeakBucket.WeakEntry internalGet(Object key) - { - if (key == null) - key = NULL_KEY; - int slot = hash(key); - WeakBucket bucket = buckets[slot]; - while (bucket != null) - { - WeakBucket.WeakEntry entry = bucket.getEntry(); - if (entry != null && key.equals(entry.key)) - return entry; - - bucket = bucket.next; - } - return null; - } - - /** - * Adds a new key/value pair to the hash map. - * @param key the key. This mustn't exists in the map. It may be null. - * @param value the value. - */ - private void internalAdd(Object key, Object value) - { - if (key == null) - key = NULL_KEY; - int slot = hash(key); - WeakBucket bucket = new WeakBucket(key, queue, value, slot); - bucket.next = buckets[slot]; - buckets[slot] = bucket; - size++; - } - - /** - * Removes a bucket from this hash map, if it wasn't removed before - * (e.g. one time through rehashing and one time through reference queue). - * Package visible for use in nested classes. - * - * @param bucket the bucket to remove. - */ - void internalRemove(WeakBucket bucket) - { - int slot = bucket.slot; - if (slot == -1) - // This bucket was already removed. - return; - - // Mark the bucket as removed. This is necessary, since the - // bucket may be enqueued later by the garbage collection, and - // internalRemove will be called a second time. - bucket.slot = -1; - if (buckets[slot] == bucket) - buckets[slot] = bucket.next; - else - { - WeakBucket prev = buckets[slot]; - /* This may throw a NullPointerException. It shouldn't but if - * a race condition occurred (two threads removing the same - * bucket at the same time) it may happen. <br> - * But with race condition many much worse things may happen - * anyway. - */ - while (prev.next != bucket) - prev = prev.next; - prev.next = bucket.next; - } - size--; - } - - /** - * Returns the size of this hash map. Note that the size() may shrink - * spontaneously, if the some of the keys were only weakly reachable. - * @return the number of entries in this hash map. - */ - public int size() - { - cleanQueue(); - return size; - } - - /** - * Tells if the map is empty. Note that the result may change - * spontanously, if all of the keys were only weakly reachable. - * @return true, iff the map is empty. - */ - public boolean isEmpty() - { - cleanQueue(); - return size == 0; - } - - /** - * Tells if the map contains the given key. Note that the result - * may change spontanously, if the key was only weakly - * reachable. - * @param key the key to look for - * @return true, iff the map contains an entry for the given key. - */ - public boolean containsKey(Object key) - { - cleanQueue(); - return internalGet(key) != null; - } - - /** - * Gets the value the key is mapped to. - * @return the value the key was mapped to. It returns null if - * the key wasn't in this map, or if the mapped value was - * explicitly set to null. - */ - public Object get(Object key) - { - cleanQueue(); - WeakBucket.WeakEntry entry = internalGet(key); - return entry == null ? null : entry.getValue(); - } - - /** - * Adds a new key/value mapping to this map. - * @param key the key, may be null - * @param value the value, may be null - * @return the value the key was mapped to previously. It returns - * null if the key wasn't in this map, or if the mapped value - * was explicitly set to null. - */ - public Object put(Object key, Object value) - { - cleanQueue(); - WeakBucket.WeakEntry entry = internalGet(key); - if (entry != null) - return entry.setValue(value); - - modCount++; - if (size >= threshold) - rehash(); - - internalAdd(key, value); - return null; - } - - /** - * Removes the key and the corresponding value from this map. - * @param key the key. This may be null. - * @return the value the key was mapped to previously. It returns - * null if the key wasn't in this map, or if the mapped value was - * explicitly set to null. - */ - public Object remove(Object key) - { - cleanQueue(); - WeakBucket.WeakEntry entry = internalGet(key); - if (entry == null) - return null; - - modCount++; - internalRemove(entry.getBucket()); - return entry.getValue(); - } - - /** - * Returns a set representation of the entries in this map. This - * set will not have strong references to the keys, so they can be - * silently removed. The returned set has therefore the same - * strange behaviour (shrinking size(), disappearing entries) as - * this weak hash map. - * @return a set representation of the entries. - */ - public Set entrySet() - { - cleanQueue(); - return theEntrySet; - } - - /** - * Clears all entries from this map. - */ - public void clear() - { - super.clear(); - } - - /** - * Returns true if the map contains at least one key which points to - * the specified object as a value. Note that the result - * may change spontanously, if its key was only weakly reachable. - * @param value the value to search for - * @return true if it is found in the set. - */ - public boolean containsValue(Object value) - { - cleanQueue(); - return super.containsValue(value); - } - - /** - * Returns a set representation of the keys in this map. This - * set will not have strong references to the keys, so they can be - * silently removed. The returned set has therefore the same - * strange behaviour (shrinking size(), disappearing entries) as - * this weak hash map. - * @return a set representation of the keys. - */ - public Set keySet() - { - cleanQueue(); - return super.keySet(); - } - - /** - * Puts all of the mappings from the given map into this one. If the - * key already exists in this map, its value is replaced. - * @param m the map to copy in - */ - public void putAll(Map m) - { - super.putAll(m); - } - - /** - * Returns a collection representation of the values in this map. This - * collection will not have strong references to the keys, so mappings - * can be silently removed. The returned collection has therefore the same - * strange behaviour (shrinking size(), disappearing entries) as - * this weak hash map. - * @return a collection representation of the values. - */ - public Collection values() - { - cleanQueue(); - return super.values(); - } -} // class WeakHashMap diff --git a/libjava/java/util/jar/Attributes.java b/libjava/java/util/jar/Attributes.java deleted file mode 100644 index 4db2c72e75b..00000000000 --- a/libjava/java/util/jar/Attributes.java +++ /dev/null @@ -1,630 +0,0 @@ -/* Attributes.java -- Represents attribute name/value pairs from a Manifest - Copyright (C) 2000, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.util.jar; - -import java.util.Collection; -import java.util.Hashtable; -import java.util.Map; -import java.util.Set; - -/** - * Represents attribute name/value pairs from a Manifest as a Map. - * The names of an attribute are represented by the - * <code>Attributes.Name</code> class and should confirm to the restrictions - * described in that class. Note that the Map interface that Attributes - * implements allows you to put names and values into the attribute that don't - * follow these restriction (and are not really Atrribute.Names, but if you do - * that it might cause undefined behaviour later). - * <p> - * If you use the constants defined in the inner class Name then you can be - * sure that you always access the right attribute names. This makes - * manipulating the Attributes more or less type safe. - * <p> - * Most of the methods are wrappers to implement the Map interface. The really - * useful and often used methods are <code>getValue(Name)</code> and - * <code>getValue(String)</code>. If you actually want to set attributes you - * may want to use the <code>putValue(String, String)</code> method - * (sorry there is no public type safe <code>putValue(Name, String)</code> - * method). - * - * @see java.util.jar.Attributes.Name - * @author Mark Wielaard (mark@klomp.org) - */ -public class Attributes implements Cloneable, Map -{ - - // Fields - - /** - * The map that holds all the attribute name/value pairs. In this - * implementation it is actually a Hashtable, but that can be different in - * other implementations. - */ - protected Map map; - - // Inner class - - /** - * Represents a name of a Manifest Attribute. Defines a couple of well - * know names for the general main attributes, stand alone application - * attributes, applet attributes, extension identification attributes, - * package versioning and sealing attributes, file contents attributes, - * bean objects attribute and signing attributes. See the - * - * <p>The characters of a Name must obey the following restrictions:</p> - * - * <ul> - * <li>Must contain at least one character</li> - * <li>The first character must be alphanumeric (a-z, A-Z, 0-9)</li> - * <li>All other characters must be alphanumeric, a '-' or a '_'</li> - * </ul> - * - * <p>When comparing Names (with <code>equals</code>) all characters are - * converted to lowercase. But you can get the original case sensitive - * string with the <code>toString()</code> method.</p> - * - * <p>Most important attributes have a constant defined in this - * class. Some other attributes used in Manifest files are: - * <ul> - * <li> "Created-By" - General main attribute, tool and version - * that created this Manifest file.</li> - * <li> "Java-Bean" - Bean objects attribute, whether the entry is a Bean. - * Value is either "true" or "false".</li> - * <li> "Magic" - Signing attribute, application specific signing attribute. - * Must be understood by the manifest parser when present to validate the - * jar (entry).</li> - * </ul> - * - * @since 1.2 - * @author Mark Wielaard (mark@klomp.org) - */ - public static class Name - { - // General Main Attributes - - /** - * General main attribute - - * the version of this Manifest file. - */ - public static final Name MANIFEST_VERSION = new Name("Manifest-Version"); - - /** - * General main attribute - - * the version of the jar file signature. - */ - public static final Name SIGNATURE_VERSION - = new Name("Signature-Version"); - - /** - * General main attribute - - * (relative) file paths of the libraries/classpaths that the Classes in - * this jar file depend on. Paths are separated by spaces. - */ - public static final Name CLASS_PATH = new Name("Class-Path"); - - /** - * Stand alone application attribute - - * the entry (without the .class ending) that is the main - * class of this jar file. - */ - public static final Name MAIN_CLASS = new Name("Main-Class"); - - /** - * Applet attribute - - * a list of extension libraries that the applet in this - * jar file depends on. - * For every named extension there should be some Attributes in the - * Manifest manifest file with the following Names: - * <ul> - * <li> <extension>-Extension-Name: - * unique name of the extension</li> - * <li> <extension>-Specification-Version: - * minimum specification version</li> - * <li> <extension>-Implementation-Version: - * minimum implementation version</li> - * <li> <extension>-Implementation-Vendor-Id: - * unique id of implementation vendor</li> - * <li> <extension>-Implementation-URL: - * where the latest version of the extension library can be found</li> - * </ul> - */ - public static final Name EXTENSION_LIST = new Name("Extension-List"); - - /** - * Extension identification attribute - - * the name if the extension library contained in the jar. - */ - public static final Name EXTENSION_NAME = new Name("Extension-Name"); - - /** - * Extension identification attribute - - * synonym for <code>EXTENSTION_NAME</code>. - */ - public static final Name EXTENSION_INSTALLATION = EXTENSION_NAME; - - // Package versioning and sealing attributes - - /** - * Package versioning - - * name of extension library contained in this jar. - */ - public static final Name IMPLEMENTATION_TITLE - = new Name("Implementation-Title"); - - /** - * Package versioning - - * version of the extension library contained in this jar. - */ - public static final Name IMPLEMENTATION_VERSION - = new Name("Implementation-Version"); - - /** - * Package versioning - - * name of extension library creator contained in this jar. - */ - public static final Name IMPLEMENTATION_VENDOR - = new Name("Implementation-Vendor"); - - /** - * Package versioning - - * unique id of extension library creator. - */ - public static final Name IMPLEMENTATION_VENDOR_ID - = new Name("Implementation-Vendor-Id"); - - /** - * Package versioning - - * location where this implementation can be downloaded. - */ - public static final Name IMPLEMENTATION_URL - = new Name("Implementation-URL"); - - /** - * Package versioning - - * title of the specification contained in this jar. - */ - public static final Name SPECIFICATION_TITLE - = new Name("Specification-Title"); - - /** - * Package versioning - - * version of the specification contained in this jar. - */ - public static final Name SPECIFICATION_VERSION - = new Name("Specification-Version"); - - /** - * Package versioning - - * organisation that maintains the specification contains in this - * jar. - */ - public static final Name SPECIFICATION_VENDOR - = new Name("Specification-Vendor"); - - /** - * Package sealing - - * whether (all) package(s) is(/are) sealed. Value is either "true" - * or "false". - */ - public static final Name SEALED = new Name("Sealed"); - - /** - * File contents attribute - - * Mime type and subtype for the jar entry. - */ - public static final Name CONTENT_TYPE = new Name("Content-Type"); - - /** The (lowercase) String representation of this Name */ - private final String name; - - /** The original String given to the constructor */ - private final String origName; - - // Constructor - - /** - * Creates a new Name from the given String. - * Throws an IllegalArgumentException if the given String is empty or - * contains any illegal Name characters. - * - * @param name the name of the new Name - * @exception IllegalArgumentException if name isn't a valid String - * representation of a Name - * @exception NullPointerException if name is null - */ - public Name(String name) throws IllegalArgumentException, - NullPointerException - { - // name must not be null - // this will throw a NullPointerException if it is - char chars[] = name.toCharArray(); - - // there must be at least one character - if (chars.length == 0) - throw new - IllegalArgumentException - ("There must be at least one character in a name"); - - // first character must be alphanum - char c = chars[0]; - if (!((c >= 'a' && c <= 'z') || - (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9'))) - throw new - IllegalArgumentException("First character must be alphanum"); - - // all other characters must be alphanums, '-' or '_' - for (int i = 1; i < chars.length; i++) - { - c = chars[i]; - if (!((c >= 'a' && c <= 'z') || - (c >= 'A' && c <= 'Z') || - (c >= '0' && c <= '9') || (c == '-') || (c == '_'))) - throw new - IllegalArgumentException - ("Characters must be alphanums, '-' or '_'"); - } - - // Still here? Then convert to lower case and be done. - // Store the original name for toString(); - this.origName = name; - this.name = name.toLowerCase(); - } - - /** - * Returns the hash code of the (lowercase) String representation of - * this Name. - */ - public int hashCode() - { - return name.hashCode(); - } - - /** - * Checks if another object is equal to this Name object. - * Another object is equal to this Name object if it is an instance of - * Name and the (lowercase) string representation of the name is equal. - */ - public boolean equals(Object o) - { - // Quick and dirty check - if (name == o) - return true; - - try - { - // Note that the constructor already converts the strings to - // lowercase. - String otherName = ((Name) o).name; - return name.equals(otherName); - } - catch (ClassCastException cce) - { - return false; - } - catch (NullPointerException npe) - { - return false; - } - } - - /** - * Returns the string representation of this Name as given to the - * constructor (not neccesarily the lower case representation). - */ - public String toString() - { - return origName; - } - } - - // Constructors - - /** - * Creates an empty Attributes map. - */ - public Attributes() - { - map = new Hashtable(); - } - - /** - * Creates an empty Attributes map with the given initial size. - * @param size the initial size of the underlying map - */ - public Attributes(int size) - { - map = new Hashtable(size); - } - - /** - * Creates an Attributes map with the initial values taken from another - * Attributes map. - * @param attr Attributes map to take the initial values from - */ - public Attributes(Attributes attr) - { - map = new Hashtable(attr.map); - } - - // Methods - - /** - * Gets the value of an attribute name given as a String. - * - * @param name a String describing the Name to look for - * @return the value gotten from the map of null when not found - */ - public String getValue(String name) - { - return (String) get(new Name(name)); - } - - /** - * Gets the value of the given attribute name. - * - * @param name the Name to look for - * @return the value gotten from the map of null when not found - */ - public String getValue(Name name) - { - return (String) get(name); - } - - /** - * Stores an attribute name (represented by a String) and value in this - * Attributes map. - * When the (case insensitive string) name already exists the value is - * replaced and the old value is returned. - * - * @param name a (case insensitive) String representation of the attribite - * name to add/replace - * @param value the (new) value of the attribute name - * @returns the old value of the attribute name or null if it didn't exist - * yet - */ - public String putValue(String name, String value) - { - return putValue(new Name(name), value); - } - - /** - * Stores an attribute name (represented by a String) and value in this - * Attributes map. - * When the name already exists the value is replaced and the old value - * is returned. - * <p> - * I don't know why there is no public method with this signature. I think - * there should be one. - * - * @param name the attribite name to add/replace - * @param value the (new) value of the attribute name - * @returns the old value of the attribute name or null if it didn't exist - * yet - */ - String putValue(Name name, String value) - { - return (String) put(name, value); - } - - // Methods from Cloneable interface - - /** - * Return a clone of this attribute map. - */ - public Object clone() - { - return new Attributes(this); - } - - // Methods from Map interface - - /** - * Removes all attributes. - */ - public void clear() - { - map.clear(); - } - - /** - * Checks to see if there is an attribute with the specified name. - * XXX - what if the object is a String? - * - * @param attrName the name of the attribute to check - * @return true if there is an attribute with the specified name, false - * otherwise - */ - public boolean containsKey(Object attrName) - { - return map.containsKey(attrName); - } - - /** - * Checks to see if there is an attribute name with the specified value. - * - * @param attrValue the value of a attribute to check - * @return true if there is an attribute name with the specified value, - * false otherwise - */ - public boolean containsValue(Object attrValue) - { - return map.containsValue(attrValue); - } - - /** - * Gives a Set of attribute name and values pairs as MapEntries. - * @see java.util.Map.Entry - * @see java.util.Map#entrySet() - * - * @return a set of attribute name value pairs - */ - public Set entrySet() - { - return map.entrySet(); - } - - /** - * Checks to see if two Attributes are equal. The supplied object must be - * a real instance of Attributes and contain the same attribute name/value - * pairs. - * - * @param o another Attribute object which should be checked for equality - * @return true if the object is an instance of Attributes and contains the - * same name/value pairs, false otherwise - */ - public boolean equals(Object o) - { - // quick and dirty check - if (this == o) - return true; - - try - { - return map.equals(((Attributes) o).map); - } - catch (ClassCastException cce) - { - return false; - } - catch (NullPointerException npe) - { - return false; - } - } - - /** - * Gets the value of a specified attribute name. - * XXX - what if the object is a String? - * - * @param attrName the name of the attribute we want the value of - * @return the value of the specified attribute name or null when there is - * no such attribute name - */ - public Object get(Object attrName) - { - return map.get(attrName); - } - - /** - * Returns the hashcode of the attribute name/value map. - */ - public int hashCode() - { - return map.hashCode(); - } - - /** - * Returns true if there are no attributes set, false otherwise. - */ - public boolean isEmpty() - { - return map.isEmpty(); - } - - /** - * Gives a Set of all the values of defined attribute names. - */ - public Set keySet() - { - return map.keySet(); - } - - /** - * Adds or replaces a attribute name/value pair. - * XXX - What if the name is a string? What if the name is neither a Name - * nor a String? What if the value is not a string? - * - * @param name the name of the attribute - * @param value the (new) value of the attribute - * @return the old value of the attribute or null when there was no old - * attribute with this name - */ - public Object put(Object name, Object value) - { - return map.put(name, value); - } - - /** - * Adds or replaces all attribute name/value pairs from another - * Attributes object to this one. The supplied Map must be an instance of - * Attributes. - * - * @param attr the Attributes object to merge with this one - * @exception ClassCastException if the supplied map is not an instance of - * Attributes - */ - public void putAll(Map attr) - { - if (!(attr instanceof Attributes)) - { - throw new - ClassCastException("Supplied Map is not an instance of Attributes"); - } - map.putAll(attr); - } - - /** - * Remove a attribute name/value pair. - * XXX - What if the name is a String? - * - * @param name the name of the attribute name/value pair to remove - * @return the old value of the attribute or null if the attribute didn't - * exist - */ - public Object remove(Object name) - { - return map.remove(name); - } - - /** - * Returns the number of defined attribute name/value pairs. - */ - public int size() - { - return map.size(); - } - - /** - * Returns all the values of the defined attribute name/value pairs as a - * Collection. - */ - public Collection values() - { - return map.values(); - } -} diff --git a/libjava/java/util/jar/JarEntry.java b/libjava/java/util/jar/JarEntry.java deleted file mode 100644 index 722a283bba3..00000000000 --- a/libjava/java/util/jar/JarEntry.java +++ /dev/null @@ -1,165 +0,0 @@ -/* JarEntry.java - Represents an entry in a jar file - Copyright (C) 2000 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.util.jar; - -import java.io.IOException; -import java.security.cert.Certificate; -import java.util.zip.ZipEntry; - -/** - * Extension to a ZipEntry that contains manifest attributes and certificates. - * Both the Atrributes and the Certificates can be null when not set. - * Note that the <code>getCertificates()</code> method only returns a - * valid value after all of the data of the entry has been read. - * <p> - * There are no public methods to set the attributes or certificate of an - * Entru. Only JarEntries created by the classes in <code>java.util.jar</code> - * will have these properties set. - * - * @since 1.2 - * @author Mark Wielaard (mark@klomp.org) - */ - -public class JarEntry extends ZipEntry -{ - // (Package local) fields - - Attributes attr; - Certificate certs[]; - - // Constructors - - /** - * Creates a new JarEntry with the specified name and no attributes or - * or certificates. Calls <code>super(name)</code> so all other (zip)entry - * fields are null or -1. - * - * @param name the name of the new jar entry - * @exception NullPointerException when the supplied name is null - * @exception IllegalArgumentException when the supplied name is longer - * than 65535 bytes - */ - public JarEntry(String name) throws NullPointerException, - IllegalArgumentException - { - super(name); - attr = null; - certs = null; - } - - /** - * Creates a new JarEntry with the specified ZipEntry as template for - * all properties of the entry. Both attributes and certificates will be - * null. - * - * @param entry the ZipEntry whose fields should be copied - */ - public JarEntry(ZipEntry entry) - { - super(entry); - attr = null; - certs = null; - } - - /** - * Creates a new JarEntry with the specified JarEntry as template for - * all properties of the entry. - * - * @param entry the jarEntry whose fields should be copied - */ - public JarEntry(JarEntry entry) - { - super(entry); - try - { - attr = entry.getAttributes(); - } - catch (IOException _) - { - } - certs = entry.getCertificates(); - } - - // Methods - - /** - * Returns a copy of the Attributes set for this entry. - * When no Attributes are set in the manifest null is returned. - * - * @return a copy of the Attributes set for this entry - * @exception IOException This will never be thrown. It is here for - * binary compatibility. - */ - public Attributes getAttributes() throws IOException - { - if (attr != null) - { - return (Attributes) attr.clone(); - } - else - { - return null; - } - } - - /** - * Returns a copy of the certificates set for this entry. - * When no certificates are set or when not all data of this entry has - * been read null is returned. - * <p> - * To make sure that this call returns a valid value you must read all - * data from the JarInputStream for this entry. - * When you don't need the data for an entry but want to know the - * certificates that are set for the entry then you can skip all data by - * calling <code>skip(entry.getSize())</code> on the JarInputStream for - * the entry. - * - * @return a copy of the certificates set for this entry - */ - public Certificate[] getCertificates() - { - if (certs != null) - { - return (Certificate[])certs.clone(); - } - else - { - return null; - } - } -} diff --git a/libjava/java/util/jar/JarException.java b/libjava/java/util/jar/JarException.java deleted file mode 100644 index d6f0634fe71..00000000000 --- a/libjava/java/util/jar/JarException.java +++ /dev/null @@ -1,77 +0,0 @@ -/* JarException.java -- thrown to indicate an problem with a jar file - Copyright (C) 2000, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.util.jar; - -import java.util.zip.ZipException; - -/** - * This exception is thrown to indicate an problem with a jar file. - * Note that none of the methods in the java.util.jar package actually declare - * to throw this exception, most just declare that they throw an IOException - * which is super class of JarException. - * - * @author Mark Wielaard (mark@klomp.org) - * @since 1.2 - */ -public class JarException extends ZipException -{ - /** - * Compatible with JDK 1.2+. - */ - private static final long serialVersionUID = 7159778400963954473L; - - /** - * Create a new JarException without a descriptive error message. - */ - public JarException() - { - } - - /** - * Create a new JarException with a descriptive error message indicating - * what went wrong. This message can later be retrieved by calling the - * <code>getMessage()</code> method. - * - * @param message The descriptive error message - * @see #getMessage() - */ - public JarException(String message) - { - super(message); - } -} diff --git a/libjava/java/util/jar/JarFile.java b/libjava/java/util/jar/JarFile.java deleted file mode 100644 index 3550ad8e0fb..00000000000 --- a/libjava/java/util/jar/JarFile.java +++ /dev/null @@ -1,1058 +0,0 @@ -/* JarFile.java - Representation of a jar file - Copyright (C) 2000, 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util.jar; - -import gnu.java.io.Base64InputStream; -import gnu.java.security.OID; -import gnu.java.security.pkcs.PKCS7SignedData; -import gnu.java.security.pkcs.SignerInfo; - -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FilterInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.security.InvalidKeyException; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.security.Signature; -import java.security.SignatureException; -import java.security.cert.CRLException; -import java.security.cert.Certificate; -import java.security.cert.CertificateException; -import java.security.cert.X509Certificate; -import java.util.Arrays; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.zip.ZipEntry; -import java.util.zip.ZipException; -import java.util.zip.ZipFile; - -/** - * Representation of a jar file. - * <p> - * Note that this class is not a subclass of java.io.File but a subclass of - * java.util.zip.ZipFile and you can only read JarFiles with it (although - * there are constructors that take a File object). - * - * @since 1.2 - * @author Mark Wielaard (mark@klomp.org) - * @author Casey Marshall (csm@gnu.org) wrote the certificate and entry - * verification code. - */ -public class JarFile extends ZipFile -{ - // Fields - - /** The name of the manifest entry: META-INF/MANIFEST.MF */ - public static final String MANIFEST_NAME = "META-INF/MANIFEST.MF"; - - /** The META-INF directory entry. */ - private static final String META_INF = "META-INF/"; - - /** The suffix for PKCS7 DSA signature entries. */ - private static final String PKCS7_DSA_SUFFIX = ".DSA"; - - /** The suffix for PKCS7 RSA signature entries. */ - private static final String PKCS7_RSA_SUFFIX = ".RSA"; - - /** The suffix for digest attributes. */ - private static final String DIGEST_KEY_SUFFIX = "-Digest"; - - /** The suffix for signature files. */ - private static final String SF_SUFFIX = ".SF"; - - // Signature OIDs. - private static final OID MD2_OID = new OID("1.2.840.113549.2.2"); - private static final OID MD4_OID = new OID("1.2.840.113549.2.4"); - private static final OID MD5_OID = new OID("1.2.840.113549.2.5"); - private static final OID SHA1_OID = new OID("1.3.14.3.2.26"); - private static final OID DSA_ENCRYPTION_OID = new OID("1.2.840.10040.4.1"); - private static final OID RSA_ENCRYPTION_OID = new OID("1.2.840.113549.1.1.1"); - - /** - * The manifest of this file, if any, otherwise null. - * Read when first needed. - */ - private Manifest manifest; - - /** Whether to verify the manifest and all entries. */ - boolean verify; - - /** Whether the has already been loaded. */ - private boolean manifestRead = false; - - /** Whether the signature files have been loaded. */ - boolean signaturesRead = false; - - /** - * A map between entry names and booleans, signaling whether or - * not that entry has been verified. - * Only be accessed with lock on this JarFile*/ - HashMap verified = new HashMap(); - - /** - * A mapping from entry name to certificates, if any. - * Only accessed with lock on this JarFile. - */ - HashMap entryCerts; - - static boolean DEBUG = false; - static void debug(Object msg) - { - System.err.print(JarFile.class.getName()); - System.err.print(" >>> "); - System.err.println(msg); - } - - // Constructors - - /** - * Creates a new JarFile. All jar entries are verified (when a Manifest file - * for this JarFile exists). You need to actually open and read the complete - * jar entry (with <code>getInputStream()</code>) to check its signature. - * - * @param fileName the name of the file to open - * @exception FileNotFoundException if the fileName cannot be found - * @exception IOException if another IO exception occurs while reading - */ - public JarFile(String fileName) throws FileNotFoundException, IOException - { - this(fileName, true); - } - - /** - * Creates a new JarFile. If verify is true then all jar entries are - * verified (when a Manifest file for this JarFile exists). You need to - * actually open and read the complete jar entry - * (with <code>getInputStream()</code>) to check its signature. - * - * @param fileName the name of the file to open - * @param verify checks manifest and entries when true and a manifest - * exists, when false no checks are made - * @exception FileNotFoundException if the fileName cannot be found - * @exception IOException if another IO exception occurs while reading - */ - public JarFile(String fileName, boolean verify) throws - FileNotFoundException, IOException - { - super(fileName); - if (verify) - { - manifest = readManifest(); - verify(); - } - } - - /** - * Creates a new JarFile. All jar entries are verified (when a Manifest file - * for this JarFile exists). You need to actually open and read the complete - * jar entry (with <code>getInputStream()</code>) to check its signature. - * - * @param file the file to open as a jar file - * @exception FileNotFoundException if the file does not exits - * @exception IOException if another IO exception occurs while reading - */ - public JarFile(File file) throws FileNotFoundException, IOException - { - this(file, true); - } - - /** - * Creates a new JarFile. If verify is true then all jar entries are - * verified (when a Manifest file for this JarFile exists). You need to - * actually open and read the complete jar entry - * (with <code>getInputStream()</code>) to check its signature. - * - * @param file the file to open to open as a jar file - * @param verify checks manifest and entries when true and a manifest - * exists, when false no checks are made - * @exception FileNotFoundException if file does not exist - * @exception IOException if another IO exception occurs while reading - */ - public JarFile(File file, boolean verify) throws FileNotFoundException, - IOException - { - super(file); - if (verify) - { - manifest = readManifest(); - verify(); - } - } - - /** - * Creates a new JarFile with the indicated mode. If verify is true then - * all jar entries are verified (when a Manifest file for this JarFile - * exists). You need to actually open and read the complete jar entry - * (with <code>getInputStream()</code>) to check its signature. - * manifest and if the manifest exists and verify is true verfies it. - * - * @param file the file to open to open as a jar file - * @param verify checks manifest and entries when true and a manifest - * exists, when false no checks are made - * @param mode either ZipFile.OPEN_READ or - * (ZipFile.OPEN_READ | ZipFile.OPEN_DELETE) - * @exception FileNotFoundException if the file does not exist - * @exception IOException if another IO exception occurs while reading - * @exception IllegalArgumentException when given an illegal mode - * - * @since 1.3 - */ - public JarFile(File file, boolean verify, int mode) throws - FileNotFoundException, IOException, IllegalArgumentException - { - super(file, mode); - if (verify) - { - manifest = readManifest(); - verify(); - } - } - - // Methods - - /** - * XXX - should verify the manifest file - */ - private void verify() - { - // only check if manifest is not null - if (manifest == null) - { - verify = false; - return; - } - - verify = true; - // XXX - verify manifest - } - - /** - * Parses and returns the manifest if it exists, otherwise returns null. - */ - private Manifest readManifest() - { - try - { - ZipEntry manEntry = super.getEntry(MANIFEST_NAME); - if (manEntry != null) - { - InputStream in = super.getInputStream(manEntry); - manifestRead = true; - return new Manifest(in); - } - else - { - manifestRead = true; - return null; - } - } - catch (IOException ioe) - { - manifestRead = true; - return null; - } - } - - /** - * Returns a enumeration of all the entries in the JarFile. - * Note that also the Jar META-INF entries are returned. - * - * @exception IllegalStateException when the JarFile is already closed - */ - public Enumeration entries() throws IllegalStateException - { - return new JarEnumeration(super.entries(), this); - } - - /** - * Wraps a given Zip Entries Enumeration. For every zip entry a - * JarEntry is created and the corresponding Attributes are looked up. - */ - private static class JarEnumeration implements Enumeration - { - - private final Enumeration entries; - private final JarFile jarfile; - - JarEnumeration(Enumeration e, JarFile f) - { - entries = e; - jarfile = f; - } - - public boolean hasMoreElements() - { - return entries.hasMoreElements(); - } - - public Object nextElement() - { - ZipEntry zip = (ZipEntry) entries.nextElement(); - JarEntry jar = new JarEntry(zip); - Manifest manifest; - try - { - manifest = jarfile.getManifest(); - } - catch (IOException ioe) - { - manifest = null; - } - - if (manifest != null) - { - jar.attr = manifest.getAttributes(jar.getName()); - } - - synchronized(jarfile) - { - if (!jarfile.signaturesRead) - try - { - jarfile.readSignatures(); - } - catch (IOException ioe) - { - if (JarFile.DEBUG) - { - JarFile.debug(ioe); - ioe.printStackTrace(); - } - jarfile.signaturesRead = true; // fudge it. - } - - // Include the certificates only if we have asserted that the - // signatures are valid. This means the certificates will not be - // available if the entry hasn't been read yet. - if (jarfile.entryCerts != null - && jarfile.verified.get(zip.getName()) == Boolean.TRUE) - { - Set certs = (Set) jarfile.entryCerts.get(jar.getName()); - if (certs != null) - jar.certs = (Certificate[]) - certs.toArray(new Certificate[certs.size()]); - } - } - return jar; - } - } - - /** - * XXX - * It actually returns a JarEntry not a zipEntry - * @param name XXX - */ - public synchronized ZipEntry getEntry(String name) - { - ZipEntry entry = super.getEntry(name); - if (entry != null) - { - JarEntry jarEntry = new JarEntry(entry); - Manifest manifest; - try - { - manifest = getManifest(); - } - catch (IOException ioe) - { - manifest = null; - } - - if (manifest != null) - { - jarEntry.attr = manifest.getAttributes(name); - } - - if (!signaturesRead) - try - { - readSignatures(); - } - catch (IOException ioe) - { - if (DEBUG) - { - debug(ioe); - ioe.printStackTrace(); - } - signaturesRead = true; - } - // See the comments in the JarEnumeration for why we do this - // check. - if (DEBUG) - debug("entryCerts=" + entryCerts + " verified " + name - + " ? " + verified.get(name)); - if (entryCerts != null && verified.get(name) == Boolean.TRUE) - { - Set certs = (Set) entryCerts.get(name); - if (certs != null) - jarEntry.certs = (Certificate[]) - certs.toArray(new Certificate[certs.size()]); - } - return jarEntry; - } - return null; - } - - /** - * Returns an input stream for the given entry. If configured to - * verify entries, the input stream returned will verify them while - * the stream is read, but only on the first time. - * - * @param entry The entry to get the input stream for. - * @exception ZipException XXX - * @exception IOException XXX - */ - public synchronized InputStream getInputStream(ZipEntry entry) throws - ZipException, IOException - { - // If we haven't verified the hash, do it now. - if (!verified.containsKey(entry.getName()) && verify) - { - if (DEBUG) - debug("reading and verifying " + entry); - return new EntryInputStream(entry, super.getInputStream(entry), this); - } - else - { - if (DEBUG) - debug("reading already verified entry " + entry); - if (verify && verified.get(entry.getName()) == Boolean.FALSE) - throw new ZipException("digest for " + entry + " is invalid"); - return super.getInputStream(entry); - } - } - - /** - * Returns the JarEntry that belongs to the name if such an entry - * exists in the JarFile. Returns null otherwise - * Convenience method that just casts the result from <code>getEntry</code> - * to a JarEntry. - * - * @param name the jar entry name to look up - * @return the JarEntry if it exists, null otherwise - */ - public JarEntry getJarEntry(String name) - { - return (JarEntry) getEntry(name); - } - - /** - * Returns the manifest for this JarFile or null when the JarFile does not - * contain a manifest file. - */ - public synchronized Manifest getManifest() throws IOException - { - if (!manifestRead) - manifest = readManifest(); - - return manifest; - } - - // Only called with lock on this JarFile. - private void readSignatures() throws IOException - { - Map pkcs7Dsa = new HashMap(); - Map pkcs7Rsa = new HashMap(); - Map sigFiles = new HashMap(); - - // Phase 1: Read all signature files. These contain the user - // certificates as well as the signatures themselves. - for (Enumeration e = super.entries(); e.hasMoreElements(); ) - { - ZipEntry ze = (ZipEntry) e.nextElement(); - String name = ze.getName(); - if (name.startsWith(META_INF)) - { - String alias = name.substring(META_INF.length()); - if (alias.lastIndexOf('.') >= 0) - alias = alias.substring(0, alias.lastIndexOf('.')); - - if (name.endsWith(PKCS7_DSA_SUFFIX) || name.endsWith(PKCS7_RSA_SUFFIX)) - { - if (DEBUG) - debug("reading PKCS7 info from " + name + ", alias=" + alias); - PKCS7SignedData sig = null; - try - { - sig = new PKCS7SignedData(super.getInputStream(ze)); - } - catch (CertificateException ce) - { - IOException ioe = new IOException("certificate parsing error"); - ioe.initCause(ce); - throw ioe; - } - catch (CRLException crle) - { - IOException ioe = new IOException("CRL parsing error"); - ioe.initCause(crle); - throw ioe; - } - if (name.endsWith(PKCS7_DSA_SUFFIX)) - pkcs7Dsa.put(alias, sig); - else if (name.endsWith(PKCS7_RSA_SUFFIX)) - pkcs7Rsa.put(alias, sig); - } - else if (name.endsWith(SF_SUFFIX)) - { - if (DEBUG) - debug("reading signature file for " + alias + ": " + name); - Manifest sf = new Manifest(super.getInputStream(ze)); - sigFiles.put(alias, sf); - if (DEBUG) - debug("result: " + sf); - } - } - } - - // Phase 2: verify the signatures on any signature files. - Set validCerts = new HashSet(); - Map entryCerts = new HashMap(); - for (Iterator it = sigFiles.entrySet().iterator(); it.hasNext(); ) - { - int valid = 0; - Map.Entry e = (Map.Entry) it.next(); - String alias = (String) e.getKey(); - - PKCS7SignedData sig = (PKCS7SignedData) pkcs7Dsa.get(alias); - if (sig != null) - { - Certificate[] certs = sig.getCertificates(); - Set signerInfos = sig.getSignerInfos(); - for (Iterator it2 = signerInfos.iterator(); it2.hasNext(); ) - verify(certs, (SignerInfo) it2.next(), alias, validCerts); - } - - sig = (PKCS7SignedData) pkcs7Rsa.get(alias); - if (sig != null) - { - Certificate[] certs = sig.getCertificates(); - Set signerInfos = sig.getSignerInfos(); - for (Iterator it2 = signerInfos.iterator(); it2.hasNext(); ) - verify(certs, (SignerInfo) it2.next(), alias, validCerts); - } - - // It isn't a signature for anything. Punt it. - if (validCerts.isEmpty()) - { - it.remove(); - continue; - } - - entryCerts.put(e.getValue(), new HashSet(validCerts)); - validCerts.clear(); - } - - // Phase 3: verify the signature file signatures against the manifest, - // mapping the entry name to the target certificates. - this.entryCerts = new HashMap(); - for (Iterator it = entryCerts.entrySet().iterator(); it.hasNext(); ) - { - Map.Entry e = (Map.Entry) it.next(); - Manifest sigfile = (Manifest) e.getKey(); - Map entries = sigfile.getEntries(); - Set certificates = (Set) e.getValue(); - - for (Iterator it2 = entries.entrySet().iterator(); it2.hasNext(); ) - { - Map.Entry e2 = (Map.Entry) it2.next(); - String entryname = String.valueOf(e2.getKey()); - Attributes attr = (Attributes) e2.getValue(); - if (verifyHashes(entryname, attr)) - { - if (DEBUG) - debug("entry " + entryname + " has certificates " + certificates); - Set s = (Set) this.entryCerts.get(entryname); - if (s != null) - s.addAll(certificates); - else - this.entryCerts.put(entryname, new HashSet(certificates)); - } - } - } - - signaturesRead = true; - } - - /** - * Tell if the given signer info is over the given alias's signature file, - * given one of the certificates specified. - */ - private void verify(Certificate[] certs, SignerInfo signerInfo, - String alias, Set validCerts) - { - Signature sig = null; - try - { - OID alg = signerInfo.getDigestEncryptionAlgorithmId(); - if (alg.equals(DSA_ENCRYPTION_OID)) - { - if (!signerInfo.getDigestAlgorithmId().equals(SHA1_OID)) - return; - sig = Signature.getInstance("SHA1withDSA"); - } - else if (alg.equals(RSA_ENCRYPTION_OID)) - { - OID hash = signerInfo.getDigestAlgorithmId(); - if (hash.equals(MD2_OID)) - sig = Signature.getInstance("md2WithRsaEncryption"); - else if (hash.equals(MD4_OID)) - sig = Signature.getInstance("md4WithRsaEncryption"); - else if (hash.equals(MD5_OID)) - sig = Signature.getInstance("md5WithRsaEncryption"); - else if (hash.equals(SHA1_OID)) - sig = Signature.getInstance("sha1WithRsaEncryption"); - else - return; - } - else - { - if (DEBUG) - debug("unsupported signature algorithm: " + alg); - return; - } - } - catch (NoSuchAlgorithmException nsae) - { - if (DEBUG) - { - debug(nsae); - nsae.printStackTrace(); - } - return; - } - ZipEntry sigFileEntry = super.getEntry(META_INF + alias + SF_SUFFIX); - if (sigFileEntry == null) - return; - for (int i = 0; i < certs.length; i++) - { - if (!(certs[i] instanceof X509Certificate)) - continue; - X509Certificate cert = (X509Certificate) certs[i]; - if (!cert.getIssuerX500Principal().equals(signerInfo.getIssuer()) || - !cert.getSerialNumber().equals(signerInfo.getSerialNumber())) - continue; - try - { - sig.initVerify(cert.getPublicKey()); - InputStream in = super.getInputStream(sigFileEntry); - if (in == null) - continue; - byte[] buf = new byte[1024]; - int len = 0; - while ((len = in.read(buf)) != -1) - sig.update(buf, 0, len); - if (sig.verify(signerInfo.getEncryptedDigest())) - { - if (DEBUG) - debug("signature for " + cert.getSubjectDN() + " is good"); - validCerts.add(cert); - } - } - catch (IOException ioe) - { - continue; - } - catch (InvalidKeyException ike) - { - continue; - } - catch (SignatureException se) - { - continue; - } - } - } - - /** - * Verifies that the digest(s) in a signature file were, in fact, made - * over the manifest entry for ENTRY. - * - * @param entry The entry name. - * @param attr The attributes from the signature file to verify. - */ - private boolean verifyHashes(String entry, Attributes attr) - { - int verified = 0; - - // The bytes for ENTRY's manifest entry, which are signed in the - // signature file. - byte[] entryBytes = null; - try - { - ZipEntry e = super.getEntry(entry); - if (e == null) - { - if (DEBUG) - debug("verifyHashes: no entry '" + entry + "'"); - return false; - } - entryBytes = readManifestEntry(e); - } - catch (IOException ioe) - { - if (DEBUG) - { - debug(ioe); - ioe.printStackTrace(); - } - return false; - } - - for (Iterator it = attr.entrySet().iterator(); it.hasNext(); ) - { - Map.Entry e = (Map.Entry) it.next(); - String key = String.valueOf(e.getKey()); - if (!key.endsWith(DIGEST_KEY_SUFFIX)) - continue; - String alg = key.substring(0, key.length() - DIGEST_KEY_SUFFIX.length()); - try - { - byte[] hash = Base64InputStream.decode((String) e.getValue()); - MessageDigest md = MessageDigest.getInstance(alg); - md.update(entryBytes); - byte[] hash2 = md.digest(); - if (DEBUG) - debug("verifying SF entry " + entry + " alg: " + md.getAlgorithm() - + " expect=" + new java.math.BigInteger(hash).toString(16) - + " comp=" + new java.math.BigInteger(hash2).toString(16)); - if (!Arrays.equals(hash, hash2)) - return false; - verified++; - } - catch (IOException ioe) - { - if (DEBUG) - { - debug(ioe); - ioe.printStackTrace(); - } - return false; - } - catch (NoSuchAlgorithmException nsae) - { - if (DEBUG) - { - debug(nsae); - nsae.printStackTrace(); - } - return false; - } - } - - // We have to find at least one valid digest. - return verified > 0; - } - - /** - * Read the raw bytes that comprise a manifest entry. We can't use the - * Manifest object itself, because that loses information (such as line - * endings, and order of entries). - */ - private byte[] readManifestEntry(ZipEntry entry) throws IOException - { - InputStream in = super.getInputStream(super.getEntry(MANIFEST_NAME)); - ByteArrayOutputStream out = new ByteArrayOutputStream(); - byte[] target = ("Name: " + entry.getName()).getBytes(); - int t = 0, c, prev = -1, state = 0, l = -1; - - while ((c = in.read()) != -1) - { -// if (DEBUG) -// debug("read " -// + (c == '\n' ? "\\n" : (c == '\r' ? "\\r" : String.valueOf((char) c))) -// + " state=" + state + " prev=" -// + (prev == '\n' ? "\\n" : (prev == '\r' ? "\\r" : String.valueOf((char) prev))) -// + " t=" + t + (t < target.length ? (" target[t]=" + (char) target[t]) : "") -// + " l=" + l); - switch (state) - { - - // Step 1: read until we find the "target" bytes: the start - // of the entry we need to read. - case 0: - if (((byte) c) != target[t]) - t = 0; - else - { - t++; - if (t == target.length) - { - out.write(target); - state = 1; - } - } - break; - - // Step 2: assert that there is a newline character after - // the "target" bytes. - case 1: - if (c != '\n' && c != '\r') - { - out.reset(); - t = 0; - state = 0; - } - else - { - out.write(c); - state = 2; - } - break; - - // Step 3: read this whole entry, until we reach an empty - // line. - case 2: - if (c == '\n') - { - out.write(c); - // NL always terminates a line. - if (l == 0 || (l == 1 && prev == '\r')) - return out.toByteArray(); - l = 0; - } - else - { - // Here we see a blank line terminated by a CR, - // followed by the next entry. Technically, `c' should - // always be 'N' at this point. - if (l == 1 && prev == '\r') - return out.toByteArray(); - out.write(c); - l++; - } - prev = c; - break; - - default: - throw new RuntimeException("this statement should be unreachable"); - } - } - - // The last entry, with a single CR terminating the line. - if (state == 2 && prev == '\r' && l == 0) - return out.toByteArray(); - - // We should not reach this point, we didn't find the entry (or, possibly, - // it is the last entry and is malformed). - throw new IOException("could not find " + entry + " in manifest"); - } - - /** - * A utility class that verifies jar entries as they are read. - */ - private static class EntryInputStream extends FilterInputStream - { - private final JarFile jarfile; - private final long length; - private long pos; - private final ZipEntry entry; - private final byte[][] hashes; - private final MessageDigest[] md; - private boolean checked; - - EntryInputStream(final ZipEntry entry, - final InputStream in, - final JarFile jar) - throws IOException - { - super(in); - this.entry = entry; - this.jarfile = jar; - - length = entry.getSize(); - pos = 0; - checked = false; - - Attributes attr; - Manifest manifest = jarfile.getManifest(); - if (manifest != null) - attr = manifest.getAttributes(entry.getName()); - else - attr = null; - if (DEBUG) - debug("verifying entry " + entry + " attr=" + attr); - if (attr == null) - { - hashes = new byte[0][]; - md = new MessageDigest[0]; - } - else - { - List hashes = new LinkedList(); - List md = new LinkedList(); - for (Iterator it = attr.entrySet().iterator(); it.hasNext(); ) - { - Map.Entry e = (Map.Entry) it.next(); - String key = String.valueOf(e.getKey()); - if (key == null) - continue; - if (!key.endsWith(DIGEST_KEY_SUFFIX)) - continue; - hashes.add(Base64InputStream.decode((String) e.getValue())); - try - { - md.add(MessageDigest.getInstance - (key.substring(0, key.length() - DIGEST_KEY_SUFFIX.length()))); - } - catch (NoSuchAlgorithmException nsae) - { - IOException ioe = new IOException("no such message digest: " + key); - ioe.initCause(nsae); - throw ioe; - } - } - if (DEBUG) - debug("digests=" + md); - this.hashes = (byte[][]) hashes.toArray(new byte[hashes.size()][]); - this.md = (MessageDigest[]) md.toArray(new MessageDigest[md.size()]); - } - } - - public boolean markSupported() - { - return false; - } - - public void mark(int readLimit) - { - } - - public void reset() - { - } - - public int read() throws IOException - { - int b = super.read(); - if (b == -1) - { - eof(); - return -1; - } - for (int i = 0; i < md.length; i++) - md[i].update((byte) b); - pos++; - if (length > 0 && pos >= length) - eof(); - return b; - } - - public int read(byte[] buf, int off, int len) throws IOException - { - int count = super.read(buf, off, (int) Math.min(len, (length != 0 - ? length - pos - : Integer.MAX_VALUE))); - if (count == -1 || (length > 0 && pos >= length)) - { - eof(); - return -1; - } - for (int i = 0; i < md.length; i++) - md[i].update(buf, off, count); - pos += count; - if (length != 0 && pos >= length) - eof(); - return count; - } - - public int read(byte[] buf) throws IOException - { - return read(buf, 0, buf.length); - } - - public long skip(long bytes) throws IOException - { - byte[] b = new byte[1024]; - long amount = 0; - while (amount < bytes) - { - int l = read(b, 0, (int) Math.min(b.length, bytes - amount)); - if (l == -1) - break; - amount += l; - } - return amount; - } - - private void eof() throws IOException - { - if (checked) - return; - checked = true; - for (int i = 0; i < md.length; i++) - { - byte[] hash = md[i].digest(); - if (DEBUG) - debug("verifying " + md[i].getAlgorithm() + " expect=" - + new java.math.BigInteger(hashes[i]).toString(16) - + " comp=" + new java.math.BigInteger(hash).toString(16)); - if (!Arrays.equals(hash, hashes[i])) - { - synchronized(jarfile) - { - if (DEBUG) - debug(entry + " could NOT be verified"); - jarfile.verified.put(entry.getName(), Boolean.FALSE); - } - return; - // XXX ??? what do we do here? - // throw new ZipException("message digest mismatch"); - } - } - - synchronized(jarfile) - { - if (DEBUG) - debug(entry + " has been VERIFIED"); - jarfile.verified.put(entry.getName(), Boolean.TRUE); - } - } - } -} diff --git a/libjava/java/util/jar/JarInputStream.java b/libjava/java/util/jar/JarInputStream.java deleted file mode 100644 index 1788af6add5..00000000000 --- a/libjava/java/util/jar/JarInputStream.java +++ /dev/null @@ -1,200 +0,0 @@ -/* JarInputStream.java - InputStream for reading jar files - Copyright (C) 2000, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.util.jar; - -import java.io.IOException; -import java.io.InputStream; -import java.util.zip.ZipEntry; -import java.util.zip.ZipInputStream; - -/** - * InputStream for reading jar files. - * XXX - verification of the signatures in the Manifest file is not yet - * implemented. - * - * @since 1.2 - * @author Mark Wielaard (mark@klomp.org) - */ - -public class JarInputStream extends ZipInputStream -{ - // Fields - - /** The manifest for this file or null when there was no manifest. */ - private Manifest manifest; - - /** The first real JarEntry for this file. Used by readManifest() to store - an entry that isn't the manifest but that should be returned by - getNextEntry next time it is called. Null when no firstEntry was read - while searching for the manifest entry, or when it has already been - returned by getNextEntry(). */ - private JarEntry firstEntry; - - // Constructors - - /** - * Creates a new JarInputStream and tries to read the manifest. - * If such a manifest is present the JarInputStream tries to verify all - * the entry signatures while reading. - * - * @param in InputStream to read the jar from - * @exception IOException when an error occurs when opening or reading - */ - public JarInputStream(InputStream in) throws IOException - { - this(in, true); - } - - /** - * Creates a new JarInputStream and tries to read the manifest. - * If such a manifest is present and verify is true, the JarInputStream - * tries to verify all the entry signatures while reading. - * - * @param in InputStream to read the jar from - * @param verify whether or not to verify the manifest entries - * @exception IOException when an error occurs when opening or reading - */ - public JarInputStream(InputStream in, boolean verify) throws IOException - { - super(in); - readManifest(verify); - } - - // Methods - - /** - * Set the manifest if found. Skips all entries that start with "META-INF/" - * - * @param verify when true (and a Manifest is found) checks the Manifest, - * when false no check is performed - * @exception IOException if an error occurs while reading - */ - private void readManifest(boolean verify) throws IOException - { - firstEntry = (JarEntry) super.getNextEntry(); - while ((firstEntry != null) && - firstEntry.getName().startsWith("META-INF/")) - { - if (firstEntry.getName().equals(JarFile.MANIFEST_NAME)) - { - manifest = new Manifest(this); - } - firstEntry = (JarEntry) super.getNextEntry(); - } - - if (verify) - { - // XXX - } - } - - /** - * Creates a JarEntry for a particular name and consults the manifest - * for the Attributes of the entry. - * Used by <code>ZipEntry.getNextEntry()</code> - * - * @param name the name of the new entry - */ - protected ZipEntry createZipEntry(String name) - { - ZipEntry zipEntry = super.createZipEntry(name); - JarEntry jarEntry = new JarEntry(zipEntry); - if (manifest != null) - { - jarEntry.attr = manifest.getAttributes(name); - } - return jarEntry; - } - - /** - * Returns the Manifest for the jar file or null if there was no Manifest. - */ - public Manifest getManifest() - { - return manifest; - } - - /** - * Returns the next entry or null when there are no more entries. - * Does actually return a JarEntry, if you don't want to cast it yourself - * use <code>getNextJarEntry()</code>. Does not return any entries found - * at the beginning of the ZipFile that are special - * (those that start with "META-INF/"). - * - * @exception IOException if an IO error occurs when reading the entry - */ - public ZipEntry getNextEntry() throws IOException - { - ZipEntry entry; - if (firstEntry != null) - { - entry = firstEntry; - firstEntry = null; - } - else - { - entry = super.getNextEntry(); - } - return entry; - } - - /** - * Returns the next jar entry or null when there are no more entries. - * - * @exception IOException if an IO error occurs when reading the entry - */ - public JarEntry getNextJarEntry() throws IOException - { - return (JarEntry) getNextEntry(); - } - - /** - * XXX - * - * @param buf XXX - * @param off XXX - * @param len XXX - * @return XXX - * @exception IOException XXX - */ - public int read(byte[]buf, int off, int len) throws IOException - { - // XXX if (verify) {} - return super.read(buf, off, len); - } -} diff --git a/libjava/java/util/jar/JarOutputStream.java b/libjava/java/util/jar/JarOutputStream.java deleted file mode 100644 index 2c8c2f08d8f..00000000000 --- a/libjava/java/util/jar/JarOutputStream.java +++ /dev/null @@ -1,113 +0,0 @@ -/* JarOutputStream.java - OutputStream for writing jar files - Copyright (C) 2000, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.util.jar; - -import java.io.IOException; -import java.io.OutputStream; -import java.util.zip.ZipEntry; -import java.util.zip.ZipOutputStream; - -/** - * OutputStream for writing jar files. - * A special ZipOutputStream that can take JarEntries and can have a optional - * Manifest as first entry. - * - * @author Mark Wielaard (mark@klomp.org) - */ - -public class JarOutputStream extends ZipOutputStream -{ - // Constructors - - /** - * Creates a new JarOutputStream without a manifest entry. - * - * @param out the stream to create the new jar on - * @exception IOException if something unexpected happend - */ - public JarOutputStream(OutputStream out) throws IOException - { - this(out, null); - } - - /** - * Creates a new JarOutputStream with a manifest entry. - * The manifest will be the first entry in the jar. - * - * @param out the stream to create the new jar on - * @param man the manifest that should be put in the jar file or null - * for no manifest entry - * @exception IOException if something unexpected happend - */ - public JarOutputStream(OutputStream out, Manifest man) throws IOException - { - super(out); - if (man != null) - writeManifest(man); - } - - // Methods - - /** - * Writes the manifest to a new JarEntry in this JarOutputStream with as - * name JarFile.MANIFEST_NAME. - * - * @param manifest the non null manifest to be written - * @exception IOException if something unexpected happend - */ - private void writeManifest(Manifest manifest) throws IOException - { - // Create a new Jar Entry for the Manifest - JarEntry entry = new JarEntry(JarFile.MANIFEST_NAME); - putNextEntry(entry); - manifest.write(this); - closeEntry(); - } - - /** - * Prepares the JarOutputStream for writing the next entry. - * This implementation just calls <code>super.putNextEntre()</code>. - * - * @param entry The information for the next entry - * @exception IOException when some unexpected I/O exception occurred - */ - public void putNextEntry(ZipEntry entry) throws IOException - { - super.putNextEntry(entry); // XXX - } -} diff --git a/libjava/java/util/jar/Manifest.java b/libjava/java/util/jar/Manifest.java deleted file mode 100644 index fdc76ff97ee..00000000000 --- a/libjava/java/util/jar/Manifest.java +++ /dev/null @@ -1,472 +0,0 @@ -/* Manifest.java -- Reads, writes and manipulaties jar manifest files - Copyright (C) 2000, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.util.jar; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.PrintWriter; -import java.util.Hashtable; -import java.util.Iterator; -import java.util.Map; - -/** - * Reads, writes and manipulaties jar manifest files. - * XXX - * - * @since 1.2 - * @author Mark Wielaard (mark@klomp.org) - */ -public class Manifest implements Cloneable -{ - // Fields - - /** The main attributes of the manifest (jar file). */ - private final Attributes mainAttr; - - /** A map of atrributes for all entries described in this Manifest. */ - private final Map entries; - - // Constructors - - /** - * Creates a new empty Manifest. - */ - public Manifest() - { - mainAttr = new Attributes(); - entries = new Hashtable(); - } - - /** - * Creates a Manifest from the supplied input stream. - * - * @see read(Inputstream) - * @see write(OutputStream) - * - * @param InputStream the input stream to read the manifest from - * @exception IOException when an i/o exception occurs or the input stream - * does not describe a valid manifest - */ - public Manifest(InputStream in) throws IOException - { - this(); - read(in); - } - - /** - * Creates a Manifest from another Manifest. - * Makes a deep copy of the main attributes, but a shallow copy of - * the other entries. This means that you can freely add, change or remove - * the main attributes or the entries of the new manifest without effecting - * the original manifest, but adding, changing or removing attributes from - * a particular entry also changes the attributes of that entry in the - * original manifest. - * - * @see clone() - * @param man the Manifest to copy from - */ - public Manifest(Manifest man) - { - mainAttr = new Attributes(man.getMainAttributes()); - entries = new Hashtable(man.getEntries()); - } - - // Methods - - /** - * Gets the main attributes of this Manifest. - */ - public Attributes getMainAttributes() - { - return mainAttr; - } - - /** - * Gets a map of entry Strings to Attributes for all the entries described - * in this manifest. Adding, changing or removing from this entries map - * changes the entries of this manifest. - */ - public Map getEntries() - { - return entries; - } - - /** - * Returns the Attributes associated with the Entry. - * <p> - * Implemented as: - * <code>return (Attributes)getEntries().get(entryName)</code> - * - * @param entryName the name of the entry to look up - * @return the attributes associated with the entry or null when none - */ - public Attributes getAttributes(String entryName) - { - return (Attributes) getEntries().get(entryName); - } - - /** - * Clears the main attributes and removes all the entries from the - * manifest. - */ - public void clear() - { - mainAttr.clear(); - entries.clear(); - } - - /** - * XXX - */ - public void read(InputStream in) throws IOException - { - BufferedReader br = - new BufferedReader(new InputStreamReader(in, "8859_1")); - read_main_section(getMainAttributes(), br); - read_individual_sections(getEntries(), br); - } - - // Private Static methods for reading the Manifest file from BufferedReader - - private static void read_main_section(Attributes attr, - BufferedReader br) throws IOException - { - // According to the spec we should actually call read_version_info() here. - read_attributes(attr, br); - // Explicitly set Manifest-Version attribute if not set in Main - // attributes of Manifest. - if (attr.getValue(Attributes.Name.MANIFEST_VERSION) == null) - attr.putValue(Attributes.Name.MANIFEST_VERSION, "0.0"); - } - - /** - * Pedantic method that requires the next attribute in the Manifest to be - * the "Manifest-Version". This follows the Manifest spec closely but - * reject some jar Manifest files out in the wild. - */ - private static void read_version_info(Attributes attr, - BufferedReader br) throws IOException - { - String version_header = Attributes.Name.MANIFEST_VERSION.toString(); - try - { - String value = expect_header(version_header, br); - attr.putValue(Attributes.Name.MANIFEST_VERSION, value); - } - catch (IOException ioe) - { - throw new JarException("Manifest should start with a " + - version_header + ": " + ioe.getMessage()); - } - } - - private static String expect_header(String header, BufferedReader br) - throws IOException - { - String s = br.readLine(); - if (s == null) - { - throw new JarException("unexpected end of file"); - } - return expect_header(header, br, s); - } - - private static String expect_header(String header, BufferedReader br, - String s) throws IOException - { - try - { - String name = s.substring(0, header.length() + 1); - if (name.equalsIgnoreCase(header + ":")) - { - String value_start = s.substring(header.length() + 2); - return read_header_value(value_start, br); - } - } - catch (IndexOutOfBoundsException iobe) - { - } - // If we arrive here, something went wrong - throw new JarException("unexpected '" + s + "'"); - } - - private static String read_header_value(String s, BufferedReader br) - throws IOException - { - boolean try_next = true; - while (try_next) - { - // Lets see if there is something on the next line - br.mark(1); - if (br.read() == ' ') - { - s += br.readLine(); - } - else - { - br.reset(); - try_next = false; - } - } - return s; - } - - private static void read_attributes(Attributes attr, - BufferedReader br) throws IOException - { - String s = br.readLine(); - while (s != null && (!s.equals(""))) - { - read_attribute(attr, s, br); - s = br.readLine(); - } - } - - private static void read_attribute(Attributes attr, String s, - BufferedReader br) throws IOException - { - try - { - int colon = s.indexOf(": "); - String name = s.substring(0, colon); - String value_start = s.substring(colon + 2); - String value = read_header_value(value_start, br); - attr.putValue(name, value); - } - catch (IndexOutOfBoundsException iobe) - { - throw new JarException("Manifest contains a bad header: " + s); - } - } - - private static void read_individual_sections(Map entries, - BufferedReader br) throws - IOException - { - String s = br.readLine(); - while (s != null && (!s.equals(""))) - { - Attributes attr = read_section_name(s, br, entries); - read_attributes(attr, br); - s = br.readLine(); - } - } - - private static Attributes read_section_name(String s, BufferedReader br, - Map entries) throws JarException - { - try - { - String name = expect_header("Name", br, s); - Attributes attr = new Attributes(); - entries.put(name, attr); - return attr; - } - catch (IOException ioe) - { - throw new JarException - ("Section should start with a Name header: " + ioe.getMessage()); - } - } - - /** - * XXX - */ - public void write(OutputStream out) throws IOException - { - PrintWriter pw = - new PrintWriter(new - BufferedWriter(new OutputStreamWriter(out, "8859_1"))); - write_main_section(getMainAttributes(), pw); - pw.println(); - write_individual_sections(getEntries(), pw); - if (pw.checkError()) - { - throw new JarException("Error while writing manifest"); - } - } - - // Private Static functions for writing the Manifest file to a PrintWriter - - private static void write_main_section(Attributes attr, - PrintWriter pw) throws JarException - { - write_version_info(attr, pw); - write_main_attributes(attr, pw); - } - - private static void write_version_info(Attributes attr, PrintWriter pw) - { - // First check if there is already a version attribute set - String version = attr.getValue(Attributes.Name.MANIFEST_VERSION); - if (version == null) - { - version = "1.0"; - } - write_header(Attributes.Name.MANIFEST_VERSION.toString(), version, pw); - } - - private static void write_header(String name, String value, PrintWriter pw) - { - pw.print(name + ": "); - - int last = 68 - name.length(); - if (last > value.length()) - { - pw.println(value); - } - else - { - pw.println(value.substring(0, last)); - } - while (last < value.length()) - { - pw.print(" "); - int end = (last + 69); - if (end > value.length()) - { - pw.println(value.substring(last)); - } - else - { - pw.println(value.substring(last, end)); - } - last = end; - } - } - - private static void write_main_attributes(Attributes attr, PrintWriter pw) - throws JarException - { - Iterator it = attr.entrySet().iterator(); - while (it.hasNext()) - { - Map.Entry entry = (Map.Entry) it.next(); - // Don't print the manifest version again - if (!Attributes.Name.MANIFEST_VERSION.equals(entry.getKey())) - { - write_attribute_entry(entry, pw); - } - } - } - - private static void write_attribute_entry(Map.Entry entry, PrintWriter pw) - throws JarException - { - String name = entry.getKey().toString(); - String value = entry.getValue().toString(); - - if (name.equalsIgnoreCase("Name")) - { - throw new JarException("Attributes cannot be called 'Name'"); - } - if (name.startsWith("From")) - { - throw new - JarException("Header cannot start with the four letters 'From'" + - name); - } - write_header(name, value, pw); - } - - private static void write_individual_sections(Map entries, PrintWriter pw) - throws JarException - { - - Iterator it = entries.entrySet().iterator(); - while (it.hasNext()) - { - Map.Entry entry = (Map.Entry) it.next(); - write_header("Name", entry.getKey().toString(), pw); - write_entry_attributes((Attributes) entry.getValue(), pw); - pw.println(); - } - } - - private static void write_entry_attributes(Attributes attr, PrintWriter pw) - throws JarException - { - Iterator it = attr.entrySet().iterator(); - while (it.hasNext()) - { - Map.Entry entry = (Map.Entry) it.next(); - write_attribute_entry(entry, pw); - } - } - - /** - * Makes a deep copy of the main attributes, but a shallow copy of - * the other entries. This means that you can freely add, change or remove - * the main attributes or the entries of the new manifest without effecting - * the original manifest, but adding, changing or removing attributes from - * a particular entry also changes the attributes of that entry in the - * original manifest. Calls <CODE>new Manifest(this)</CODE>. - */ - public Object clone() - { - return new Manifest(this); - } - - /** - * Checks if another object is equal to this Manifest object. - * Another Object is equal to this Manifest object if it is an instance of - * Manifest and the main attributes and the entries of the other manifest - * are equal to this one. - */ - public boolean equals(Object o) - { - return (o instanceof Manifest) && - (mainAttr.equals(((Manifest) o).mainAttr)) && - (entries.equals(((Manifest) o).entries)); - } - - /** - * Calculates the hash code of the manifest. Implemented by a xor of the - * hash code of the main attributes with the hash code of the entries map. - */ - public int hashCode() - { - return mainAttr.hashCode() ^ entries.hashCode(); - } - -} diff --git a/libjava/java/util/logging/ConsoleHandler.java b/libjava/java/util/logging/ConsoleHandler.java deleted file mode 100644 index 3cf4bca3354..00000000000 --- a/libjava/java/util/logging/ConsoleHandler.java +++ /dev/null @@ -1,125 +0,0 @@ -/* ConsoleHandler.java -- a class for publishing log messages to System.err - Copyright (C) 2002, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util.logging; - -/** - * A <code>ConsoleHandler</code> publishes log records to - * <code>System.err</code>. - * - * <p><strong>Configuration:</strong> Values of the subsequent - * <code>LogManager</code> properties are taken into consideration - * when a <code>ConsoleHandler</code> is initialized. - * If a property is not defined, or if it has an invalid - * value, a default is taken without an exception being thrown. - * - * <ul> - * - * <li><code>java.util.logging.ConsoleHandler.level</code> - specifies - * the initial severity level threshold. Default value: - * <code>Level.INFO</code>.</li> - * - * <li><code>java.util.logging.ConsoleHandler.filter</code> - specifies - * the name of a Filter class. Default value: No Filter.</li> - * - * <li><code>java.util.logging.ConsoleHandler.formatter</code> - specifies - * the name of a Formatter class. Default value: - * <code>java.util.logging.SimpleFormatter</code>.</li> - * - * <li><code>java.util.logging.ConsoleHandler.encoding</code> - specifies - * the name of the character encoding. Default value: - * the default platform encoding.</li> - * - * </ul> - * - * @author Sascha Brawer (brawer@acm.org) - */ -public class ConsoleHandler - extends StreamHandler -{ - /** - * Constructs a <code>StreamHandler</code> that publishes - * log records to <code>System.err</code>. The initial - * configuration is determined by the <code>LogManager</code> - * properties described above. - */ - public ConsoleHandler() - { - super(System.err, "java.util.logging.ConsoleHandler", Level.INFO, - /* formatter */ null, SimpleFormatter.class); - } - - - /** - * Forces any data that may have been buffered to the underlying - * output device, but does <i>not</i> close <code>System.err</code>. - * - * <p>In case of an I/O failure, the <code>ErrorManager</code> - * of this <code>ConsoleHandler</code> will be informed, but the caller - * of this method will not receive an exception. - */ - public void close() - { - flush(); - } - - - /** - * Publishes a <code>LogRecord</code> to the console, provided the - * record passes all tests for being loggable. - * - * <p>Most applications do not need to call this method directly. - * Instead, they will use use a <code>Logger</code>, which will - * create LogRecords and distribute them to registered handlers. - * - * <p>In case of an I/O failure, the <code>ErrorManager</code> - * of this <code>SocketHandler</code> will be informed, but the caller - * of this method will not receive an exception. - * - * <p>The GNU implementation of <code>ConsoleHandler.publish</code> - * calls flush() for every request to publish a record, so - * they appear immediately on the console. - * - * @param record the log event to be published. - */ - public void publish(LogRecord record) - { - super.publish(record); - flush(); - } -} diff --git a/libjava/java/util/logging/ErrorManager.java b/libjava/java/util/logging/ErrorManager.java deleted file mode 100644 index 57c079fe25b..00000000000 --- a/libjava/java/util/logging/ErrorManager.java +++ /dev/null @@ -1,194 +0,0 @@ -/* ErrorManager.java -- - A class for dealing with errors that a Handler encounters - during logging - Copyright (C) 2002, 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util.logging; - -/** - * An <code>ErrorManager</code> deals with errors that a <code>Handler</code> - * encounters while logging. - * - * @see Handler#setErrorManager(ErrorManager) - * - * @author Sascha Brawer (brawer@acm.org) - */ -public class ErrorManager -{ - /* The values have been taken from Sun's public J2SE 1.4 API - * documentation. - * See http://java.sun.com/j2se/1.4/docs/api/constant-values.html - */ - - /** - * Indicates that there was a failure that does not readily - * fall into any of the other categories. - */ - public static final int GENERIC_FAILURE = 0; - - - /** - * Indicates that there was a problem upon writing to - * an output stream. - */ - public static final int WRITE_FAILURE = 1; - - - /** - * Indicates that there was a problem upon flushing - * an output stream. - */ - public static final int FLUSH_FAILURE = 2; - - - /** - * Indicates that there was a problem upon closing - * an output stream. - */ - public static final int CLOSE_FAILURE = 3; - - - /** - * Indicates that there was a problem upon opening - * an output stream. - */ - public static final int OPEN_FAILURE = 4; - - - /** - * Indicates that there was a problem upon formatting - * the message of a log record. - */ - public static final int FORMAT_FAILURE = 5; - - - /** - * Indicates whether the {@link #error} method of this ErrorManager - * has ever been used. - * - * Declared volatile in order to correctly support the - * double-checked locking idiom (once the revised Java Memory Model - * gets adopted); see Classpath bug #2944. - */ - private volatile boolean everUsed = false; - - - public ErrorManager() - { - } - - - /** - * Reports an error that occured upon logging. The default implementation - * emits the very first error to System.err, ignoring subsequent errors. - * - * @param message a message describing the error, or <code>null</code> if - * there is no suitable description. - * - * @param ex an exception, or <code>null</code> if the error is not - * related to an exception. - * - * @param errorCode one of the defined error codes, for example - * <code>ErrorManager.CLOSE_FAILURE</code>. - */ - public void error(String message, Exception ex, int errorCode) - { - if (everUsed) - return; - - synchronized (this) - { - /* The double check is intentional. If the first check was - * omitted, the monitor would have to be entered every time - * error() method was called. If the second check was - * omitted, the code below could be executed by multiple - * threads simultaneously. - * - * This is the 'double-checked locking' idiom, which is broken - * with the current version of the Java memory model. However, - * we assume that JVMs will have adopted a revised version of - * the Java Memory Model by the time GNU Classpath gains - * widespread acceptance. See Classpath bug #2944. - */ - if (everUsed) - return; - - everUsed = true; - } - - String codeMsg; - switch (errorCode) - { - case GENERIC_FAILURE: - codeMsg = "GENERIC_FAILURE"; - break; - - case WRITE_FAILURE: - codeMsg = "WRITE_FAILURE"; - break; - - case FLUSH_FAILURE: - codeMsg = "FLUSH_FAILURE"; - break; - - case CLOSE_FAILURE: - codeMsg = "CLOSE_FAILURE"; - break; - - case OPEN_FAILURE: - codeMsg = "OPEN_FAILURE"; - break; - - case FORMAT_FAILURE: - codeMsg = "FORMAT_FAILURE"; - break; - - default: - codeMsg = String.valueOf(errorCode); - break; - } - - System.err.println("Error upon logging: " + codeMsg); - if ((message != null) && (message.length() > 0)) - System.err.println(message); - - if (ex != null) - ex.printStackTrace(); - } -} - diff --git a/libjava/java/util/logging/FileHandler.java b/libjava/java/util/logging/FileHandler.java deleted file mode 100644 index a948ba389f4..00000000000 --- a/libjava/java/util/logging/FileHandler.java +++ /dev/null @@ -1,506 +0,0 @@ -/* FileHandler.java -- a class for publishing log messages to log files - Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util.logging; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; - -/** - * A <code>FileHandler</code> publishes log records to a set of log - * files. A maximum file size can be specified; as soon as a log file - * reaches the size limit, it is closed and the next file in the set - * is taken. - * - * <p><strong>Configuration:</strong> Values of the subsequent - * <code>LogManager</code> properties are taken into consideration - * when a <code>FileHandler</code> is initialized. If a property is - * not defined, or if it has an invalid value, a default is taken - * without an exception being thrown. - * - * <ul> - * - * <li><code>java.util.FileHandler.level</code> - specifies - * the initial severity level threshold. Default value: - * <code>Level.ALL</code>.</li> - * - * <li><code>java.util.FileHandler.filter</code> - specifies - * the name of a Filter class. Default value: No Filter.</li> - * - * <li><code>java.util.FileHandler.formatter</code> - specifies - * the name of a Formatter class. Default value: - * <code>java.util.logging.XMLFormatter</code>.</li> - * - * <li><code>java.util.FileHandler.encoding</code> - specifies - * the name of the character encoding. Default value: - * the default platform encoding.</li> - * - * <li><code>java.util.FileHandler.limit</code> - specifies the number - * of bytes a log file is approximately allowed to reach before it - * is closed and the handler switches to the next file in the - * rotating set. A value of zero means that files can grow - * without limit. Default value: 0 (unlimited growth).</li> - * - * <li><code>java.util.FileHandler.count</code> - specifies the number - * of log files through which this handler cycles. Default value: - * 1.</li> - * - * <li><code>java.util.FileHandler.pattern</code> - specifies a - * pattern for the location and name of the produced log files. - * See the section on <a href="#filePatterns">file name - * patterns</a> for details. Default value: - * <code>"%h/java%u.log"</code>.</li> - * - * <li><code>java.util.FileHandler.append</code> - specifies - * whether the handler will append log records to existing - * files, or whether the handler will clear log files - * upon switching to them. Default value: <code>false</code>, - * indicating that files will be cleared.</li> - * - * </ul> - * - * <p><a name="filePatterns"><strong>File Name Patterns:</strong></a> - * The name and location and log files are specified with pattern - * strings. The handler will replace the following character sequences - * when opening log files: - * - * <p><ul> - * <li><code>/</code> - replaced by the platform-specific path name - * separator. This value is taken from the system property - * <code>file.separator</code>.</li> - * - * <li><code>%t</code> - replaced by the platform-specific location of - * the directory intended for temporary files. This value is - * taken from the system property <code>java.io.tmpdir</code>.</li> - * - * <li><code>%h</code> - replaced by the location of the home - * directory of the current user. This value is taken from the - * system property <code>file.separator</code>.</li> - * - * <li><code>%g</code> - replaced by a generation number for - * distinguisthing the individual items in the rotating set - * of log files. The generation number cycles through the - * sequence 0, 1, ..., <code>count</code> - 1.</li> - * - * <li><code>%u</code> - replaced by a unique number for - * distinguisthing the output files of several concurrently - * running processes. The <code>FileHandler</code> starts - * with 0 when it tries to open a log file. If the file - * cannot be opened because it is currently in use, - * the unique number is incremented by one and opening - * is tried again. These steps are repeated until the - * opening operation succeeds. - * - * <p>FIXME: Is the following correct? Please review. The unique - * number is determined for each log file individually when it is - * opened upon switching to the next file. Therefore, it is not - * correct to assume that all log files in a rotating set bear the - * same unique number. - * - * <p>FIXME: The Javadoc for the Sun reference implementation - * says: "Note that the use of unique ids to avoid conflicts is - * only guaranteed to work reliably when using a local disk file - * system." Why? This needs to be mentioned as well, in case - * the reviewers decide the statement is true. Otherwise, - * file a bug report with Sun.</li> - * - * <li><code>%%</code> - replaced by a single percent sign.</li> - * </ul> - * - * <p>If the pattern string does not contain <code>%g</code> and - * <code>count</code> is greater than one, the handler will append - * the string <code>.%g</code> to the specified pattern. - * - * <p>If the handler attempts to open a log file, this log file - * is being used at the time of the attempt, and the pattern string - * does not contain <code>%u</code>, the handler will append - * the string <code>.%u</code> to the specified pattern. This - * step is performed after any generation number has been - * appended. - * - * <p><em>Examples for the GNU platform:</em> - * - * <p><ul> - * - * <li><code>%h/java%u.log</code> will lead to a single log file - * <code>/home/janet/java0.log</code>, assuming <code>count</code> - * equals 1, the user's home directory is - * <code>/home/janet</code>, and the attempt to open the file - * succeeds.</li> - * - * <li><code>%h/java%u.log</code> will lead to three log files - * <code>/home/janet/java0.log.0</code>, - * <code>/home/janet/java0.log.1</code>, and - * <code>/home/janet/java0.log.2</code>, - * assuming <code>count</code> equals 3, the user's home - * directory is <code>/home/janet</code>, and all attempts - * to open files succeed.</li> - * - * <li><code>%h/java%u.log</code> will lead to three log files - * <code>/home/janet/java0.log.0</code>, - * <code>/home/janet/java1.log.1</code>, and - * <code>/home/janet/java0.log.2</code>, - * assuming <code>count</code> equals 3, the user's home - * directory is <code>/home/janet</code>, and the attempt - * to open <code>/home/janet/java0.log.1</code> fails.</li> - * - * </ul> - * - * @author Sascha Brawer (brawer@acm.org) - */ -public class FileHandler - extends StreamHandler -{ - /** - * The number of bytes a log file is approximately allowed to reach - * before it is closed and the handler switches to the next file in - * the rotating set. A value of zero means that files can grow - * without limit. - */ - private final int limit; - - - /** - * The number of log files through which this handler cycles. - */ - private final int count; - - - /** - * The pattern for the location and name of the produced log files. - * See the section on <a href="#filePatterns">file name patterns</a> - * for details. - */ - private final String pattern; - - - /** - * Indicates whether the handler will append log records to existing - * files (<code>true</code>), or whether the handler will clear log files - * upon switching to them (<code>false</code>). - */ - private final boolean append; - - - /** - * Constructs a <code>FileHandler</code>, taking all property values - * from the current {@link LogManager LogManager} configuration. - * - * @throws java.io.IOException FIXME: The Sun Javadoc says: "if - * there are IO problems opening the files." This conflicts - * with the general principle that configuration errors do - * not prohibit construction. Needs review. - * - * @throws SecurityException if a security manager exists and - * the caller is not granted the permission to control - * the logging infrastructure. - */ - public FileHandler() - throws IOException, SecurityException - { - this(/* pattern: use configiguration */ null, - - LogManager.getIntProperty("java.util.logging.FileHandler.limit", - /* default */ 0), - - LogManager.getIntProperty("java.util.logging.FileHandler.count", - /* default */ 1), - - LogManager.getBooleanProperty("java.util.logging.FileHandler.append", - /* default */ false)); - } - - - /* FIXME: Javadoc missing. */ - public FileHandler(String pattern) - throws IOException, SecurityException - { - this(pattern, - /* limit */ 0, - /* count */ 1, - /* append */ false); - } - - - /* FIXME: Javadoc missing. */ - public FileHandler(String pattern, boolean append) - throws IOException, SecurityException - { - this(pattern, - /* limit */ 0, - /* count */ 1, - append); - } - - - /* FIXME: Javadoc missing. */ - public FileHandler(String pattern, int limit, int count) - throws IOException, SecurityException - { - this(pattern, limit, count, - LogManager.getBooleanProperty( - "java.util.logging.FileHandler.append", - /* default */ false)); - } - - - /** - * Constructs a <code>FileHandler</code> given the pattern for the - * location and name of the produced log files, the size limit, the - * number of log files thorough which the handler will rotate, and - * the <code>append</code> property. All other property values are - * taken from the current {@link LogManager LogManager} - * configuration. - * - * @param pattern The pattern for the location and name of the - * produced log files. See the section on <a - * href="#filePatterns">file name patterns</a> for details. - * If <code>pattern</code> is <code>null</code>, the value is - * taken from the {@link LogManager LogManager} configuration - * property - * <code>java.util.logging.FileHandler.pattern</code>. - * However, this is a pecularity of the GNU implementation, - * and Sun's API specification does not mention what behavior - * is to be expected for <code>null</code>. Therefore, - * applications should not rely on this feature. - * - * @param limit specifies the number of bytes a log file is - * approximately allowed to reach before it is closed and the - * handler switches to the next file in the rotating set. A - * value of zero means that files can grow without limit. - * - * @param count specifies the number of log files through which this - * handler cycles. - * - * @param append specifies whether the handler will append log - * records to existing files (<code>true</code>), or whether the - * handler will clear log files upon switching to them - * (<code>false</code>). - * - * @throws java.io.IOException FIXME: The Sun Javadoc says: "if - * there are IO problems opening the files." This conflicts - * with the general principle that configuration errors do - * not prohibit construction. Needs review. - * - * @throws SecurityException if a security manager exists and - * the caller is not granted the permission to control - * the logging infrastructure. - * <p>FIXME: This seems in contrast to all other handler - * constructors -- verify this by running tests against - * the Sun reference implementation. - */ - public FileHandler(String pattern, - int limit, - int count, - boolean append) - throws IOException, SecurityException - { - super(createFileStream(pattern, limit, count, append, - /* generation */ 0), - "java.util.logging.FileHandler", - /* default level */ Level.ALL, - /* formatter */ null, - /* default formatter */ XMLFormatter.class); - - if ((limit <0) || (count < 1)) - throw new IllegalArgumentException(); - - this.pattern = pattern; - this.limit = limit; - this.count = count; - this.append = append; - } - - - /* FIXME: Javadoc missing. */ - private static java.io.OutputStream createFileStream(String pattern, - int limit, - int count, - boolean append, - int generation) - { - String path; - int unique = 0; - - /* Throws a SecurityException if the caller does not have - * LoggingPermission("control"). - */ - LogManager.getLogManager().checkAccess(); - - /* Default value from the java.util.logging.FileHandler.pattern - * LogManager configuration property. - */ - if (pattern == null) - pattern = LogManager.getLogManager().getProperty( - "java.util.logging.FileHandler.pattern"); - if (pattern == null) - pattern = "%h/java%u.log"; - - do - { - path = replaceFileNameEscapes(pattern, generation, unique, count); - - try - { - File file = new File(path); - if (file.createNewFile()) - return new FileOutputStream(path, append); - } - catch (Exception ex) - { - ex.printStackTrace(); - } - - unique = unique + 1; - if (pattern.indexOf("%u") < 0) - pattern = pattern + ".%u"; - } - while (true); - } - - - /** - * Replaces the substrings <code>"/"</code> by the value of the - * system property <code>"file.separator"</code>, <code>"%t"</code> - * by the value of the system property - * <code>"java.io.tmpdir"</code>, <code>"%h"</code> by the value of - * the system property <code>"user.home"</code>, <code>"%g"</code> - * by the value of <code>generation</code>, <code>"%u"</code> by the - * value of <code>uniqueNumber</code>, and <code>"%%"</code> by a - * single percent character. If <code>pattern</code> does - * <em>not</em> contain the sequence <code>"%g"</code>, - * the value of <code>generation</code> will be appended to - * the result. - * - * @throws NullPointerException if one of the system properties - * <code>"file.separator"</code>, - * <code>"java.io.tmpdir"</code>, or - * <code>"user.home"</code> has no value and the - * corresponding escape sequence appears in - * <code>pattern</code>. - */ - private static String replaceFileNameEscapes(String pattern, - int generation, - int uniqueNumber, - int count) - { - StringBuffer buf = new StringBuffer(pattern); - String replaceWith; - boolean foundGeneration = false; - - int pos = 0; - do - { - // Uncomment the next line for finding bugs. - // System.out.println(buf.substring(0,pos) + '|' + buf.substring(pos)); - - if (buf.charAt(pos) == '/') - { - /* The same value is also provided by java.io.File.separator. */ - replaceWith = System.getProperty("file.separator"); - buf.replace(pos, pos + 1, replaceWith); - pos = pos + replaceWith.length() - 1; - continue; - } - - if (buf.charAt(pos) == '%') - { - switch (buf.charAt(pos + 1)) - { - case 't': - replaceWith = System.getProperty("java.io.tmpdir"); - break; - - case 'h': - replaceWith = System.getProperty("user.home"); - break; - - case 'g': - replaceWith = Integer.toString(generation); - foundGeneration = true; - break; - - case 'u': - replaceWith = Integer.toString(uniqueNumber); - break; - - case '%': - replaceWith = "%"; - break; - - default: - replaceWith = "??"; - break; // FIXME: Throw exception? - } - - buf.replace(pos, pos + 2, replaceWith); - pos = pos + replaceWith.length() - 1; - continue; - } - } - while (++pos < buf.length() - 1); - - if (!foundGeneration && (count > 1)) - { - buf.append('.'); - buf.append(generation); - } - - return buf.toString(); - } - - - /* FIXME: Javadoc missing, implementation incomplete. */ - public void publish(LogRecord record) - { - super.publish(record); - - /* FIXME: Decide when to switch over. How do we get to - * the number of bytes published so far? Two possibilities: - * 1. File.length, 2. have metering wrapper around - * output stream counting the number of written bytes. - */ - - /* FIXME: Switch over if needed! This implementation always - * writes into a single file, i.e. behaves as if limit - * always was zero. So, the implementation is somewhat - * functional but incomplete. - */ - } -} diff --git a/libjava/java/util/logging/Filter.java b/libjava/java/util/logging/Filter.java deleted file mode 100644 index ec4597670d5..00000000000 --- a/libjava/java/util/logging/Filter.java +++ /dev/null @@ -1,64 +0,0 @@ -/* Filter.java -- an interface for filters that decide whether a - LogRecord should be published or discarded - Copyright (C) 2002, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util.logging; - -/** - * By implementing the <code>Filter</code> interface, applications - * can control what is being logged based on arbitrary properties, - * not just the severity level. Both <code>Handler</code> and - * <code>Logger</code> allow to register Filters whose - * <code>isLoggable</code> method will be called when a - * <code>LogRecord</code> has passed the test based on the - * severity level. - * - * @author Sascha Brawer (brawer@acm.org) - */ -public interface Filter -{ - /** - * Determines whether a LogRecord should be published or discarded. - * - * @param record the <code>LogRecord</code> to be inspected. - * - * @return <code>true</code> if the record should be published, - * <code>false</code> if it should be discarded. - */ - boolean isLoggable(LogRecord record); -} diff --git a/libjava/java/util/logging/Formatter.java b/libjava/java/util/logging/Formatter.java deleted file mode 100644 index ee747b0b978..00000000000 --- a/libjava/java/util/logging/Formatter.java +++ /dev/null @@ -1,171 +0,0 @@ -/* Formatter.java -- - A class for formatting log messages by localizing message texts - and performing substitution of parameters - Copyright (C) 2002, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util.logging; - -import java.text.MessageFormat; -import java.util.ResourceBundle; - -/** - * A <code>Formatter</code> supports handlers by localizing - * message texts and by subsituting parameter values for their - * placeholders. - * - * @author Sascha Brawer (brawer@acm.org) - */ -public abstract class Formatter -{ - /** - * Constructs a new Formatter. - */ - protected Formatter() - { - } - - - /** - * Formats a LogRecord into a string. Usually called by handlers - * which need a string for a log record, for example to append - * a record to a log file or to transmit a record over the network. - * - * @param record the log record for which a string form is requested. - */ - public abstract String format(LogRecord record); - - - /** - * Returns a string that handlers are supposed to emit before - * the first log record. The base implementation returns an - * empty string, but subclasses such as {@link XMLFormatter} - * override this method in order to provide a suitable header. - * - * @return a string for the header. - * - * @param handler the handler which will prepend the returned - * string in front of the first log record. This method - * may inspect certain properties of the handler, for - * example its encoding, in order to construct the header. - */ - public String getHead(Handler handler) - { - return ""; - } - - - /** - * Returns a string that handlers are supposed to emit after - * the last log record. The base implementation returns an - * empty string, but subclasses such as {@link XMLFormatter} - * override this method in order to provide a suitable tail. - * - * @return a string for the header. - * - * @param handler the handler which will append the returned - * string after the last log record. This method - * may inspect certain properties of the handler - * in order to construct the tail. - */ - public String getTail(Handler handler) - { - return ""; - } - - - /** - * Formats the message part of a log record. - * - * <p>First, the Formatter localizes the record message to the - * default locale by looking up the message in the record's - * localization resource bundle. If this step fails because there - * is no resource bundle associated with the record, or because the - * record message is not a key in the bundle, the raw message is - * used instead. - * - * <p>Second, the Formatter substitutes appropriate strings for - * the message parameters. If the record returns a non-empty - * array for <code>getParameters()</code> and the localized - * message string contains the character sequence "{0", the - * formatter uses <code>java.text.MessageFormat</code> to format - * the message. Otherwise, no parameter substitution is performed. - * - * @param record the log record to be localized and formatted. - * - * @return the localized message text where parameters have been - * substituted by suitable strings. - * - * @throws NullPointerException if <code>record</code> - * is <code>null</code>. - */ - public String formatMessage(LogRecord record) - { - String msg; - ResourceBundle bundle; - Object[] params; - - /* This will throw a NullPointerExceptionif record is null. */ - msg = record.getMessage(); - if (msg == null) - msg = ""; - - /* Try to localize the message. */ - bundle = record.getResourceBundle(); - if (bundle != null) - { - try - { - msg = bundle.getString(msg); - } - catch (java.util.MissingResourceException _) - { - } - } - - /* Format the message if there are parameters. */ - params = record.getParameters(); - if ((params != null) - && (params.length > 0) - && (msg.indexOf("{0") >= 0)) - { - msg = MessageFormat.format(msg, params); - } - - return msg; - } -} diff --git a/libjava/java/util/logging/Handler.java b/libjava/java/util/logging/Handler.java deleted file mode 100644 index c3227d6f531..00000000000 --- a/libjava/java/util/logging/Handler.java +++ /dev/null @@ -1,386 +0,0 @@ -/* Handler.java -- a class for publishing log messages - Copyright (C) 2002, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util.logging; - -import java.io.UnsupportedEncodingException; - -/** - * A <code>Handler</code> publishes <code>LogRecords</code> to - * a sink, for example a file, the console or a network socket. - * There are different subclasses of <code>Handler</code> - * to deal with different kinds of sinks. - * - * <p>FIXME: Are handlers thread-safe, or is the assumption that only - * loggers are, and a handler can belong only to one single logger? If - * the latter, should we enforce it? (Spec not clear). In any - * case, it needs documentation. - * - * @author Sascha Brawer (brawer@acm.org) - */ -public abstract class Handler -{ - Formatter formatter; - Filter filter; - Level level; - ErrorManager errorManager; - String encoding; - - /** - * Constructs a Handler with a logging severity level of - * <code>Level.ALL</code>, no formatter, no filter, and - * an instance of <code>ErrorManager</code> managing errors. - * - * <p><strong>Specification Note:</strong> The specification of the - * Java<sup>TM</sup> Logging API does not mention which character - * encoding is to be used by freshly constructed Handlers. The GNU - * implementation uses the default platform encoding, but other - * Java implementations might behave differently. - * - * <p><strong>Specification Note:</strong> While a freshly constructed - * Handler is required to have <em>no filter</em> according to the - * specification, <code>null</code> is not a valid parameter for - * <code>Handler.setFormatter</code>. Therefore, the following - * code will throw a <code>java.lang.NullPointerException</code>: - * - * <p><pre>Handler h = new MyConcreteSubclassOfHandler(); -h.setFormatter(h.getFormatter());</pre> - * - * It seems strange that a freshly constructed Handler is not - * supposed to provide a Formatter, but this is what the specification - * says. - */ - protected Handler() - { - level = Level.ALL; - } - - - /** - * Publishes a <code>LogRecord</code> to an appropriate sink, - * provided the record passes all tests for being loggable. The - * <code>Handler</code> will localize the message of the log - * record and substitute any message parameters. - * - * <p>Most applications do not need to call this method directly. - * Instead, they will use use a {@link Logger}, which will - * create LogRecords and distribute them to registered handlers. - * - * <p>In case of an I/O failure, the <code>ErrorManager</code> - * of this <code>Handler</code> will be informed, but the caller - * of this method will not receive an exception. - * - * @param record the log event to be published. - */ - public abstract void publish(LogRecord record); - - - /** - * Forces any data that may have been buffered to the underlying - * output device. - * - * <p>In case of an I/O failure, the <code>ErrorManager</code> - * of this <code>Handler</code> will be informed, but the caller - * of this method will not receive an exception. - */ - public abstract void flush(); - - - /** - * Closes this <code>Handler</code> after having flushed - * the buffers. As soon as <code>close</code> has been called, - * a <code>Handler</code> should not be used anymore. Attempts - * to publish log records, to flush buffers, or to modify the - * <code>Handler</code> in any other way may throw runtime - * exceptions after calling <code>close</code>. - * - * <p>In case of an I/O failure, the <code>ErrorManager</code> - * of this <code>Handler</code> will be informed, but the caller - * of this method will not receive an exception. - * - * @throws SecurityException if a security manager exists and - * the caller is not granted the permission to control - * the logging infrastructure. - */ - public abstract void close() - throws SecurityException; - - - /** - * Returns the <code>Formatter</code> which will be used to - * localize the text of log messages and to substitute - * message parameters. A <code>Handler</code> is encouraged, - * but not required to actually use an assigned - * <code>Formatter</code>. - * - * @return the <code>Formatter</code> being used, or - * <code>null</code> if this <code>Handler</code> - * does not use formatters and no formatter has - * ever been set by calling <code>setFormatter</code>. - */ - public Formatter getFormatter() - { - return formatter; - } - - - /** - * Sets the <code>Formatter</code> which will be used to - * localize the text of log messages and to substitute - * message parameters. A <code>Handler</code> is encouraged, - * but not required to actually use an assigned - * <code>Formatter</code>. - * - * @param formatter the new <code>Formatter</code> to use. - * - * @throws SecurityException if a security manager exists and - * the caller is not granted the permission to control - * the logging infrastructure. - * - * @throws NullPointerException if <code>formatter</code> is - * <code>null</code>. - */ - public void setFormatter(Formatter formatter) - throws SecurityException - { - LogManager.getLogManager().checkAccess(); - - /* Throws a NullPointerException if formatter is null. */ - formatter.getClass(); - - this.formatter = formatter; - } - - - /** - * Returns the character encoding which this handler uses for publishing - * log records. - * - * @param encoding the name of a character encoding, or <code>null</code> - * for the default platform encoding. - */ - public String getEncoding() - { - return encoding; - } - - - /** - * Sets the character encoding which this handler uses for publishing - * log records. The encoding of a <code>Handler</code> must be - * set before any log records have been published. - * - * @param encoding the name of a character encoding, or <code>null</code> - * for the default encoding. - * - * @exception SecurityException if a security manager exists and - * the caller is not granted the permission to control - * the logging infrastructure. - * - */ - public void setEncoding(String encoding) - throws SecurityException, UnsupportedEncodingException - { - /* Should any developer ever change this implementation, they are - * advised to have a look at StreamHandler.setEncoding(String), - * which overrides this method without calling super.setEncoding. - */ - LogManager.getLogManager().checkAccess(); - - /* Simple check for supported encodings. This is more expensive - * than it could be, but this method is overwritten by StreamHandler - * anyway. - */ - if (encoding != null) - new String(new byte[0], encoding); - - this.encoding = encoding; - } - - - /** - * Returns the <code>Filter</code> that currently controls which - * log records are being published by this <code>Handler</code>. - * - * @return the currently active <code>Filter</code>, or - * <code>null</code> if no filter has been associated. - * In the latter case, log records are filtered purely - * based on their severity level. - */ - public Filter getFilter() - { - return filter; - } - - - /** - * Sets the <code>Filter</code> for controlling which - * log records will be published by this <code>Handler</code>. - * - * @return the <code>Filter</code> to use, or - * <code>null</code> to filter log records purely based - * on their severity level. - */ - public void setFilter(Filter filter) - throws SecurityException - { - LogManager.getLogManager().checkAccess(); - this.filter = filter; - } - - - /** - * Returns the <code>ErrorManager</code> that currently deals - * with errors originating from this Handler. - * - * @exception SecurityException if a security manager exists and - * the caller is not granted the permission to control - * the logging infrastructure. - */ - public ErrorManager getErrorManager() - { - LogManager.getLogManager().checkAccess(); - - /* Developers wanting to change the subsequent code should - * have a look at Handler.reportError -- it also can create - * an ErrorManager, but does so without checking permissions - * to control the logging infrastructure. - */ - if (errorManager == null) - errorManager = new ErrorManager(); - - return errorManager; - } - - - public void setErrorManager(ErrorManager manager) - { - LogManager.getLogManager().checkAccess(); - - /* Make sure manager is not null. */ - manager.getClass(); - - this.errorManager = manager; - } - - - protected void reportError(String message, Exception ex, int code) - { - if (errorManager == null) - errorManager = new ErrorManager(); - - errorManager.error(message, ex, code); - } - - - /** - * Returns the severity level threshold for this <code>Handler</code> - * All log records with a lower severity level will be discarded; - * a log record of the same or a higher level will be published - * unless an installed <code>Filter</code> decides to discard it. - * - * @return the severity level below which all log messages - * will be discarded. - */ - public Level getLevel() - { - return level; - } - - - /** - * Sets the severity level threshold for this <code>Handler</code>. - * All log records with a lower severity level will be discarded; - * a log record of the same or a higher level will be published - * unless an installed <code>Filter</code> decides to discard it. - * - * @param level the severity level below which all log messages - * will be discarded. - * - * @exception SecurityException if a security manager exists and - * the caller is not granted the permission to control - * the logging infrastructure. - * - * @exception NullPointerException if <code>level</code> is - * <code>null</code>. - */ - public void setLevel(Level level) - { - LogManager.getLogManager().checkAccess(); - - /* Throw NullPointerException if level is null. */ - level.getClass(); - this.level = level; - } - - - /** - * Checks whether a <code>LogRecord</code> would be logged - * if it was passed to this <code>Handler</code> for publication. - * - * <p>The <code>Handler</code> implementation considers a record as - * loggable if its level is greater than or equal to the severity - * level threshold. In a second step, if a {@link Filter} has - * been installed, its {@link Filter#isLoggable(LogRecord) isLoggable} - * method is invoked. Subclasses of <code>Handler</code> can override - * this method to impose their own constraints. - * - * @param record the <code>LogRecord</code> to be checked. - * - * @return <code>true</code> if <code>record</code> would - * be published by {@link #publish(LogRecord) publish}, - * <code>false</code> if it would be discarded. - * - * @see #setLevel(Level) - * @see #setFilter(Filter) - * @see Filter#isLoggable(LogRecord) - * - * @throws NullPointerException if <code>record</code> - * is <code>null</code>. - */ - public boolean isLoggable(LogRecord record) - { - if (record.getLevel().intValue() < level.intValue()) - return false; - - if (filter != null) - return filter.isLoggable(record); - else - return true; - } -} diff --git a/libjava/java/util/logging/Level.java b/libjava/java/util/logging/Level.java deleted file mode 100644 index 2c400dc3a90..00000000000 --- a/libjava/java/util/logging/Level.java +++ /dev/null @@ -1,414 +0,0 @@ -/* Level.java -- a class for indicating logging levels - Copyright (C) 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util.logging; - -import java.io.Serializable; -import java.util.ResourceBundle; - -/** - * A class for indicating logging levels. A number of commonly used - * levels is pre-defined (such as <code>java.util.logging.Level.INFO</code>), - * and applications should utilize those whenever possible. For specialized - * purposes, however, applications can sub-class Level in order to define - * custom logging levels. - * - * @author Sascha Brawer (brawer@acm.org) - */ -public class Level implements Serializable -{ - /* The integer values are the same as in the Sun J2SE 1.4. - * They have been obtained with a test program. In J2SE 1.4.1, - * Sun has amended the API documentation; these values are now - * publicly documented. - */ - - /** - * The <code>OFF</code> level is used as a threshold for filtering - * log records, meaning that no message should be logged. - * - * @see Logger#setLevel(java.util.logging.Level) - */ - public static final Level OFF = new Level ("OFF", Integer.MAX_VALUE); - - /** - * Log records whose level is <code>SEVERE</code> indicate a serious - * failure that prevents normal program execution. Messages at this - * level should be understandable to an inexperienced, non-technical - * end user. Ideally, they explain in simple words what actions the - * user can take in order to resolve the problem. - */ - public static final Level SEVERE = new Level ("SEVERE", 1000); - - - /** - * Log records whose level is <code>WARNING</code> indicate a - * potential problem that does not prevent normal program execution. - * Messages at this level should be understandable to an - * inexperienced, non-technical end user. Ideally, they explain in - * simple words what actions the user can take in order to resolve - * the problem. - */ - public static final Level WARNING = new Level ("WARNING", 900); - - - /** - * Log records whose level is <code>INFO</code> are used in purely - * informational situations that do not constitute serious errors or - * potential problems. In the default logging configuration, INFO - * messages will be written to the system console. For this reason, - * the INFO level should be used only for messages that are - * important to end users and system administrators. Messages at - * this level should be understandable to an inexperienced, - * non-technical user. - */ - public static final Level INFO = new Level ("INFO", 800); - - - /** - * Log records whose level is <code>CONFIG</code> are used for - * describing the static configuration, for example the windowing - * environment, the operating system version, etc. - */ - public static final Level CONFIG = new Level ("CONFIG", 700); - - - /** - * Log records whose level is <code>FINE</code> are typically used - * for messages that are relevant for developers using - * the component generating log messages. Examples include minor, - * recoverable failures, or possible inefficiencies. - */ - public static final Level FINE = new Level ("FINE", 500); - - - /** - * Log records whose level is <code>FINER</code> are intended for - * rather detailed tracing, for example entering a method, returning - * from a method, or throwing an exception. - */ - public static final Level FINER = new Level ("FINER", 400); - - - /** - * Log records whose level is <code>FINEST</code> are used for - * highly detailed tracing, for example to indicate that a certain - * point inside the body of a method has been reached. - */ - public static final Level FINEST = new Level ("FINEST", 300); - - - /** - * The <code>ALL</code> level is used as a threshold for filtering - * log records, meaning that every message should be logged. - * - * @see Logger#setLevel(java.util.logging.Level) - */ - public static final Level ALL = new Level ("ALL", Integer.MIN_VALUE); - - - private static final Level[] knownLevels = { - ALL, FINEST, FINER, FINE, CONFIG, INFO, WARNING, SEVERE, OFF - }; - - - /** - * The name of the Level without localizing it, for example - * "WARNING". - */ - private String name; - - - /** - * The integer value of this <code>Level</code>. - */ - private int value; - - - /** - * The name of the resource bundle used for localizing the level - * name, or <code>null</code> if the name does not undergo - * localization. - */ - private String resourceBundleName; - - - /** - * Creates a logging level given a name and an integer value. - * It rarely is necessary to create custom levels, - * as most applications should be well served with one of the - * standard levels such as <code>Level.CONFIG</code>, - * <code>Level.INFO</code>, or <code>Level.FINE</code>. - * - * @param name the name of the level. - * - * @param value the integer value of the level. Please note - * that the Java<small><sup>TM</sup></small> - * Logging API does not specify integer - * values for standard levels (such as - * Level.FINE). Therefore, a custom - * level should pass an integer value that - * is calculated at run-time, e.g. - * <code>(Level.FINE.intValue() + Level.CONFIG.intValue()) - * / 2</code> for a level between FINE and CONFIG. - */ - protected Level(String name, int value) - { - this(name, value, null); - } - - - /** - * Create a logging level given a name, an integer value and a name - * of a resource bundle for localizing the level name. It rarely - * is necessary to create custom levels, as most applications - * should be well served with one of the standard levels such as - * <code>Level.CONFIG</code>, <code>Level.INFO</code>, or - * <code>Level.FINE</code>. - * - * @param name the name of the level. - * - * @param value the integer value of the level. Please note - * that the Java<small><sup>TM</sup></small> - * Logging API does not specify integer - * values for standard levels (such as - * Level.FINE). Therefore, a custom - * level should pass an integer value that - * is calculated at run-time, e.g. - * <code>(Level.FINE.intValue() + Level.CONFIG.intValue()) - * / 2</code> for a level between FINE and CONFIG. - * - * @param resourceBundleName the name of a resource bundle - * for localizing the level name, or <code>null</code> - * if the name does not need to be localized. - */ - protected Level(String name, int value, String resourceBundleName) - { - this.name = name; - this.value = value; - this.resourceBundleName = resourceBundleName; - } - - - static final long serialVersionUID = -8176160795706313070L; - - - /** - * Checks whether the Level has the same intValue as one of the - * pre-defined levels. If so, the pre-defined level object is - * returned. - * - * <br/>Since the resource bundle name is not taken into - * consideration, it is possible to resolve Level objects that have - * been de-serialized by another implementation, even if the other - * implementation uses a different resource bundle for localizing - * the names of pre-defined levels. - */ - private Object readResolve() - { - for (int i = 0; i < knownLevels.length; i++) - if (value == knownLevels[i].intValue()) - return knownLevels[i]; - - return this; - } - - - /** - * Returns the name of the resource bundle used for localizing the - * level name. - * - * @return the name of the resource bundle used for localizing the - * level name, or <code>null</code> if the name does not undergo - * localization. - */ - public String getResourceBundleName() - { - return resourceBundleName; - } - - - /** - * Returns the name of the Level without localizing it, for example - * "WARNING". - */ - public String getName() - { - return name; - } - - - /** - * Returns the name of the Level after localizing it, for example - * "WARNUNG". - */ - public String getLocalizedName() - { - String localizedName = null; - - if (resourceBundleName != null) - { - try - { - ResourceBundle b = ResourceBundle.getBundle(resourceBundleName); - localizedName = b.getString(name); - } - catch (Exception _) - { - } - } - - if (localizedName != null) - return localizedName; - else - return name; - } - - - /** - * Returns the name of the Level without localizing it, for example - * "WARNING". - */ - public final String toString() - { - return getName(); - } - - - /** - * Returns the integer value of the Level. - */ - public final int intValue() - { - return value; - } - - - /** - * Returns one of the standard Levels given either its name or its - * integer value. Custom subclasses of Level will not be returned - * by this method. - * - * @throws IllegalArgumentException if <code>name</code> is neither - * the name nor the integer value of one of the pre-defined standard - * logging levels. - * - * @throws NullPointerException if <code>name</code> is null. - * - */ - public static Level parse(String name) - throws IllegalArgumentException - { - /* This will throw a NullPointerException if name is null, - * as required by the API specification. - */ - name = name.intern(); - - for (int i = 0; i < knownLevels.length; i++) - { - if (name == knownLevels[i].name) - return knownLevels[i]; - } - - try - { - int num = Integer.parseInt(name); - for (int i = 0; i < knownLevels.length; i++) - if (num == knownLevels[i].value) - return knownLevels[i]; - } - catch (NumberFormatException _) - { - } - - String msg = "Not the name of a standard logging level: \"" + name + "\""; - throw new IllegalArgumentException(msg); - } - - - /** - * Checks whether this Level's integer value is equal to that of - * another object. - * - * @return <code>true</code> if <code>other</code> is an instance of - * <code>java.util.logging.Level</code> and has the same integer - * value, <code>false</code> otherwise. - */ - public boolean equals(Object other) - { - if (!(other instanceof Level)) - return false; - - return value == ((Level) other).value; - } - - - /** - * Returns a hash code for this Level which is based on its numeric - * value. - */ - public int hashCode() - { - return value; - } - - - /** - * Determines whether or not this Level is one of the standard - * levels specified in the Logging API. - * - * <p>This method is package-private because it is not part - * of the logging API specification. However, an XMLFormatter - * is supposed to emit the numeric value for a custom log - * level, but the name for a pre-defined level. It seems - * cleaner to put this method to Level than to write some - * procedural code for XMLFormatter. - * - * @return <code>true</code> if this Level is a standard level, - * <code>false</code> otherwise. - */ - final boolean isStandardLevel() - { - for (int i = 0; i < knownLevels.length; i++) - if (knownLevels[i] == this) - return true; - - return false; - } -} - diff --git a/libjava/java/util/logging/LogRecord.java b/libjava/java/util/logging/LogRecord.java deleted file mode 100644 index af7f2058dbe..00000000000 --- a/libjava/java/util/logging/LogRecord.java +++ /dev/null @@ -1,672 +0,0 @@ -/* LogRecord.java -- - A class for the state associated with individual logging events - Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util.logging; - -import java.util.ResourceBundle; - - -/** - * A <code>LogRecord</code> contains the state for an individual - * event to be logged. - * - * <p>As soon as a LogRecord instance has been handed over to the - * logging framework, applications should not manipulate it anymore. - * - * @author Sascha Brawer (brawer@acm.org) - */ -public class LogRecord - implements java.io.Serializable -{ - /** - * The severity level of this <code>LogRecord</code>. - */ - private Level level; - - - /** - * The sequence number of this <code>LogRecord</code>. - */ - private long sequenceNumber; - - - /** - * The name of the class that issued the logging request, or - * <code>null</code> if this information could not be obtained. - */ - private String sourceClassName; - - - /** - * The name of the method that issued the logging request, or - * <code>null</code> if this information could not be obtained. - */ - private String sourceMethodName; - - - /** - * The message for this <code>LogRecord</code> before - * any localization or formatting. - */ - private String message; - - - /** - * An identifier for the thread in which this <code>LogRecord</code> - * was created. The identifier is not necessarily related to any - * thread identifiers used by the operating system. - */ - private int threadID; - - - /** - * The time when this <code>LogRecord</code> was created, - * in milliseconds since the beginning of January 1, 1970. - */ - private long millis; - - - /** - * The Throwable associated with this <code>LogRecord</code>, or - * <code>null</code> if the logged event is not related to an - * exception or error. - */ - private Throwable thrown; - - - /** - * The name of the logger where this <code>LogRecord</code> has - * originated, or <code>null</code> if this <code>LogRecord</code> - * does not originate from a <code>Logger</code>. - */ - private String loggerName; - - - /** - * The name of the resource bundle used for localizing log messages, - * or <code>null</code> if no bundle has been specified. - */ - private String resourceBundleName; - - private transient Object[] parameters; - - private transient ResourceBundle bundle; - - - /** - * Constructs a <code>LogRecord</code> given a severity level and - * an unlocalized message text. In addition, the sequence number, - * creation time (as returned by <code>getMillis()</code>) and - * thread ID are assigned. All other properties are set to - * <code>null</code>. - * - * @param level the severity level, for example <code>Level.WARNING</code>. - * - * @param message the message text (which will be used as key - * for looking up the localized message text - * if a resource bundle has been associated). - */ - public LogRecord(Level level, String message) - { - this.level = level; - this.message = message; - this.millis = System.currentTimeMillis(); - - /* A subclass of java.lang.Thread could override hashCode(), - * in which case the result would not be guaranteed anymore - * to be unique among all threads. While System.identityHashCode - * is not necessarily unique either, it at least cannot be - * overridden by user code. However, is might be a good idea - * to use something better for generating thread IDs. - */ - this.threadID = System.identityHashCode(Thread.currentThread()); - - sequenceNumber = allocateSeqNum(); - } - - - /** - * Determined with the serialver tool of the Sun J2SE 1.4. - */ - static final long serialVersionUID = 5372048053134512534L; - - private void readObject(java.io.ObjectInputStream in) - throws java.io.IOException, java.lang.ClassNotFoundException - { - in.defaultReadObject(); - - /* We assume that future versions will be downwards compatible, - * so we can ignore the versions. - */ - byte majorVersion = in.readByte(); - byte minorVersion = in.readByte(); - - int numParams = in.readInt(); - if (numParams >= 0) - { - parameters = new Object[numParams]; - for (int i = 0; i < numParams; i++) - parameters[i] = in.readObject(); - } - } - - - /** - * @serialData The default fields, followed by a major byte version - * number, followed by a minor byte version number, followed by - * information about the log record parameters. If - * <code>parameters</code> is <code>null</code>, the integer -1 is - * written, otherwise the length of the <code>parameters</code> - * array (which can be zero), followed by the result of calling - * {@link Object#toString() toString()} on the parameter (or - * <code>null</code> if the parameter is <code>null</code>). - * - * <p><strong>Specification Note:</strong> The Javadoc for the - * Sun reference implementation does not specify the version - * number. FIXME: Reverse-engineer the JDK and file a bug - * report with Sun, asking for amendment of the specification. - */ - private void writeObject(java.io.ObjectOutputStream out) - throws java.io.IOException - { - out.defaultWriteObject(); - - /* Major, minor version number: The Javadoc for J2SE1.4 does not - * specify the values. - */ - out.writeByte(0); - out.writeByte(0); - - if (parameters == null) - out.writeInt(-1); - else - { - out.writeInt(parameters.length); - for (int i = 0; i < parameters.length; i++) - { - if (parameters[i] == null) - out.writeObject(null); - else - out.writeObject(parameters[i].toString()); - } - } - } - - - /** - * Returns the name of the logger where this <code>LogRecord</code> - * has originated. - * - * @return the name of the source {@link Logger}, or - * <code>null</code> if this <code>LogRecord</code> - * does not originate from a <code>Logger</code>. - */ - public String getLoggerName() - { - return loggerName; - } - - - /** - * Sets the name of the logger where this <code>LogRecord</code> - * has originated. - * - * <p>As soon as a <code>LogRecord</code> has been handed over - * to the logging framework, applications should not modify it - * anymore. Therefore, this method should only be called on - * freshly constructed LogRecords. - * - * @param name the name of the source logger, or <code>null</code> to - * indicate that this <code>LogRecord</code> does not - * originate from a <code>Logger</code>. - */ - public void setLoggerName(String name) - { - loggerName = name; - } - - - /** - * Returns the resource bundle that is used when the message - * of this <code>LogRecord</code> needs to be localized. - * - * @return the resource bundle used for localization, - * or <code>null</code> if this message does not need - * to be localized. - */ - public ResourceBundle getResourceBundle() - { - return bundle; - } - - - /** - * Sets the resource bundle that is used when the message - * of this <code>LogRecord</code> needs to be localized. - * - * <p>As soon as a <code>LogRecord</code> has been handed over - * to the logging framework, applications should not modify it - * anymore. Therefore, this method should only be called on - * freshly constructed LogRecords. - * - * @param bundle the resource bundle to be used, or - * <code>null</code> to indicate that this - * message does not need to be localized. - */ - public void setResourceBundle(ResourceBundle bundle) - { - this.bundle = bundle; - - /* FIXME: Is there a way to infer the name - * of a resource bundle from a ResourceBundle object? - */ - this.resourceBundleName = null; - } - - - /** - * Returns the name of the resource bundle that is used when the - * message of this <code>LogRecord</code> needs to be localized. - * - * @return the name of the resource bundle used for localization, - * or <code>null</code> if this message does not need - * to be localized. - */ - public String getResourceBundleName() - { - return resourceBundleName; - } - - - /** - * Sets the name of the resource bundle that is used when the - * message of this <code>LogRecord</code> needs to be localized. - * - * <p>As soon as a <code>LogRecord</code> has been handed over - * to the logging framework, applications should not modify it - * anymore. Therefore, this method should only be called on - * freshly constructed LogRecords. - * - * @param name the name of the resource bundle to be used, or - * <code>null</code> to indicate that this message - * does not need to be localized. - */ - public void setResourceBundleName(String name) - { - resourceBundleName = name; - bundle = null; - - try - { - if (resourceBundleName != null) - bundle = ResourceBundle.getBundle(resourceBundleName); - } - catch (java.util.MissingResourceException _) - { - } - } - - - /** - * Returns the level of the LogRecord. - * - * <p>Applications should be aware of the possibility that the - * result is not necessarily one of the standard logging levels, - * since the logging framework allows to create custom subclasses - * of <code>java.util.logging.Level</code>. Therefore, filters - * should perform checks like <code>theRecord.getLevel().intValue() - * == Level.INFO.intValue()</code> instead of <code>theRecord.getLevel() - * == Level.INFO</code>. - */ - public Level getLevel() - { - return level; - } - - - /** - * Sets the severity level of this <code>LogRecord</code> to a new - * value. - * - * <p>As soon as a <code>LogRecord</code> has been handed over - * to the logging framework, applications should not modify it - * anymore. Therefore, this method should only be called on - * freshly constructed LogRecords. - * - * @param level the new severity level, for example - * <code>Level.WARNING</code>. - */ - public void setLevel(Level level) - { - this.level = level; - } - - - /** - * The last used sequence number for any LogRecord. - */ - private static long lastSeqNum; - - - /** - * Allocates a sequence number for a new LogRecord. This class - * method is only called by the LogRecord constructor. - */ - private static synchronized long allocateSeqNum() - { - lastSeqNum += 1; - return lastSeqNum; - } - - - /** - * Returns the sequence number of this <code>LogRecord</code>. - */ - public long getSequenceNumber() - { - return sequenceNumber; - } - - - /** - * Sets the sequence number of this <code>LogRecord</code> to a new - * value. - * - * <p>As soon as a <code>LogRecord</code> has been handed over - * to the logging framework, applications should not modify it - * anymore. Therefore, this method should only be called on - * freshly constructed LogRecords. - * - * @param seqNum the new sequence number. - */ - public void setSequenceNumber(long seqNum) - { - this.sequenceNumber = seqNum; - } - - - /** - * Returns the name of the class where the event being logged - * has had its origin. This information can be passed as - * parameter to some logging calls, and in certain cases, the - * logging framework tries to determine an approximation - * (which may or may not be accurate). - * - * @return the name of the class that issued the logging request, - * or <code>null</code> if this information could not - * be obtained. - */ - public String getSourceClassName() - { - if (sourceClassName != null) - return sourceClassName; - - /* FIXME: Should infer this information from the call stack. */ - return null; - } - - - /** - * Sets the name of the class where the event being logged - * has had its origin. - * - * <p>As soon as a <code>LogRecord</code> has been handed over - * to the logging framework, applications should not modify it - * anymore. Therefore, this method should only be called on - * freshly constructed LogRecords. - * - * @param sourceClassName the name of the class that issued the - * logging request, or <code>null</code> to indicate that - * this information could not be obtained. - */ - public void setSourceClassName(String sourceClassName) - { - this.sourceClassName = sourceClassName; - } - - - /** - * Returns the name of the method where the event being logged - * has had its origin. This information can be passed as - * parameter to some logging calls, and in certain cases, the - * logging framework tries to determine an approximation - * (which may or may not be accurate). - * - * @return the name of the method that issued the logging request, - * or <code>null</code> if this information could not - * be obtained. - */ - public String getSourceMethodName() - { - if (sourceMethodName != null) - return sourceMethodName; - - /* FIXME: Should infer this information from the call stack. */ - return null; - } - - - /** - * Sets the name of the method where the event being logged - * has had its origin. - * - * <p>As soon as a <code>LogRecord</code> has been handed over - * to the logging framework, applications should not modify it - * anymore. Therefore, this method should only be called on - * freshly constructed LogRecords. - * - * @param sourceMethodName the name of the method that issued the - * logging request, or <code>null</code> to indicate that - * this information could not be obtained. - */ - public void setSourceMethodName(String sourceMethodName) - { - this.sourceMethodName = sourceMethodName; - } - - - /** - * Returns the message for this <code>LogRecord</code> before - * any localization or parameter substitution. - * - * <p>A {@link Logger} will try to localize the message - * if a resource bundle has been associated with this - * <code>LogRecord</code>. In this case, the logger will call - * <code>getMessage()</code> and use the result as the key - * for looking up the localized message in the bundle. - * If no bundle has been associated, or if the result of - * <code>getMessage()</code> is not a valid key in the - * bundle, the logger will use the raw message text as - * returned by this method. - * - * @return the message text, or <code>null</code> if there - * is no message text. - */ - public String getMessage() - { - return message; - } - - - /** - * Sets the message for this <code>LogRecord</code>. - * - * <p>A <code>Logger</code> will try to localize the message - * if a resource bundle has been associated with this - * <code>LogRecord</code>. In this case, the logger will call - * <code>getMessage()</code> and use the result as the key - * for looking up the localized message in the bundle. - * If no bundle has been associated, or if the result of - * <code>getMessage()</code> is not a valid key in the - * bundle, the logger will use the raw message text as - * returned by this method. - * - * <p>It is possible to set the message to either an empty String or - * <code>null</code>, although this does not make the the message - * very helpful to human users. - * - * @param message the message text (which will be used as key - * for looking up the localized message text - * if a resource bundle has been associated). - */ - public void setMessage(String message) - { - this.message = message; - } - - - /** - * Returns the parameters to the log message. - * - * @return the parameters to the message, or <code>null</code> if - * the message has no parameters. - */ - public Object[] getParameters() - { - return parameters; - } - - - /** - * Sets the parameters to the log message. - * - * <p>As soon as a <code>LogRecord</code> has been handed over - * to the logging framework, applications should not modify it - * anymore. Therefore, this method should only be called on - * freshly constructed LogRecords. - * - * @param parameters the parameters to the message, or <code>null</code> - * to indicate that the message has no parameters. - */ - public void setParameters(Object[] parameters) - { - this.parameters = parameters; - } - - - /** - * Returns an identifier for the thread in which this - * <code>LogRecord</code> was created. The identifier is not - * necessarily related to any thread identifiers used by the - * operating system. - * - * @return an identifier for the source thread. - */ - public int getThreadID() - { - return threadID; - } - - - /** - * Sets the identifier indicating in which thread this - * <code>LogRecord</code> was created. The identifier is not - * necessarily related to any thread identifiers used by the - * operating system. - * - * <p>As soon as a <code>LogRecord</code> has been handed over - * to the logging framework, applications should not modify it - * anymore. Therefore, this method should only be called on - * freshly constructed LogRecords. - * - * @param threadID the identifier for the source thread. - */ - public void setThreadID(int threadID) - { - this.threadID = threadID; - } - - - /** - * Returns the time when this <code>LogRecord</code> was created. - * - * @return the time of creation in milliseconds since the beginning - * of January 1, 1970. - */ - public long getMillis() - { - return millis; - } - - - /** - * Sets the time when this <code>LogRecord</code> was created. - * - * <p>As soon as a <code>LogRecord</code> has been handed over - * to the logging framework, applications should not modify it - * anymore. Therefore, this method should only be called on - * freshly constructed LogRecords. - * - * @param millis the time of creation in milliseconds since the - * beginning of January 1, 1970. - */ - public void setMillis(long millis) - { - this.millis = millis; - } - - - /** - * Returns the Throwable associated with this <code>LogRecord</code>, - * or <code>null</code> if the logged event is not related to an exception - * or error. - */ - public Throwable getThrown() - { - return thrown; - } - - - /** - * Associates this <code>LogRecord</code> with an exception or error. - * - * <p>As soon as a <code>LogRecord</code> has been handed over - * to the logging framework, applications should not modify it - * anymore. Therefore, this method should only be called on - * freshly constructed LogRecords. - * - * @param thrown the exception or error to associate with, or - * <code>null</code> if this <code>LogRecord</code> - * should be made unrelated to an exception or error. - */ - public void setThrown(Throwable thrown) - { - this.thrown = thrown; - } -} diff --git a/libjava/java/util/logging/LoggingPermission.java b/libjava/java/util/logging/LoggingPermission.java deleted file mode 100644 index c7a2255ecea..00000000000 --- a/libjava/java/util/logging/LoggingPermission.java +++ /dev/null @@ -1,73 +0,0 @@ -/* LoggingPermission.java -- a class for logging permissions. - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util.logging; - -public final class LoggingPermission - extends java.security.BasicPermission -{ - /** - * Creates a new LoggingPermission. - * - * @param name the name of the permission, which must be "control". - * - * @param actions the list of actions for the permission, which - * must be either <code>null</code> or an empty - * string. - * - * @exception IllegalArgumentException if <code>name</code> - * is not "control", or <code>actions</code> is - * neither <code>null</code> nor empty. - */ - public LoggingPermission(String name, String actions) - { - super("control", ""); - - if (!"control".equals(name)) - { - throw new IllegalArgumentException( - "name of LoggingPermission must be \"control\""); - } - - if ((actions != null) && (actions.length() != 0)) - { - throw new IllegalArgumentException( - "actions of LoggingPermissions must be null or empty"); - } - } -} diff --git a/libjava/java/util/logging/MemoryHandler.java b/libjava/java/util/logging/MemoryHandler.java deleted file mode 100644 index ffa589f1668..00000000000 --- a/libjava/java/util/logging/MemoryHandler.java +++ /dev/null @@ -1,345 +0,0 @@ -/* MemoryHandler.java -- a class for buffering log messages in a memory buffer - Copyright (C) 2002, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.util.logging; - -/** - * A <code>MemoryHandler</code> maintains a circular buffer of - * log records. - * - * <p><strong>Configuration:</strong> Values of the subsequent - * <code>LogManager</code> properties are taken into consideration - * when a <code>MemoryHandler</code> is initialized. - * If a property is not defined, or if it has an invalid - * value, a default is taken without an exception being thrown. - * - * <ul> - * <li><code>java.util.MemoryHandler.level</code> - specifies - * the initial severity level threshold. Default value: - * <code>Level.ALL</code>.</li> - * <li><code>java.util.MemoryHandler.filter</code> - specifies - * the name of a Filter class. Default value: No Filter.</li> - * <li><code>java.util.MemoryHandler.size</code> - specifies the - * maximum number of log records that are kept in the circular - * buffer. Default value: 1000.</li> - * <li><code>java.util.MemoryHandler.push</code> - specifies the - * <code>pushLevel</code>. Default value: - * <code>Level.SEVERE</code>.</li> - * <li><code>java.util.MemoryHandler.target</code> - specifies the - * name of a subclass of {@link Handler} that will be used as the - * target handler. There is no default value for this property; - * if it is not set, the no-argument MemoryHandler constructor - * will throw an exception.</li> - * </ul> - * - * @author Sascha Brawer (brawer@acm.org) - */ -public class MemoryHandler - extends Handler -{ - /** - * The storage area used for buffering the unpushed log records in - * memory. - */ - private final LogRecord[] buffer; - - - /** - * The current position in the circular buffer. For a new - * MemoryHandler, or immediately after {@link #push()} was called, - * the value of this variable is zero. Each call to {@link - * #publish(LogRecord)} will store the published LogRecord into - * <code>buffer[position]</code> before position is incremented by - * one. If position becomes greater than the size of the buffer, it - * is reset to zero. - */ - private int position; - - - /** - * The number of log records which have been published, but not - * pushed yet to the target handler. - */ - private int numPublished; - - - /** - * The push level threshold for this <code>Handler</code>. When a - * record is published whose severity level is greater than or equal - * to the <code>pushLevel</code> of this <code>MemoryHandler</code>, - * the {@link #push()} method will be invoked for pushing the buffer - * contents to the target <code>Handler</code>. - */ - private Level pushLevel; - - - /** - * The Handler to which log records are forwarded for actual - * publication. - */ - private final Handler target; - - - /** - * Constructs a <code>MemoryHandler</code> for keeping a circular - * buffer of LogRecords; the initial configuration is determined by - * the <code>LogManager</code> properties described above. - */ - public MemoryHandler() - { - this((Handler) LogManager.getInstanceProperty( - "java.util.logging.MemoryHandler.target", - Handler.class, /* default */ null), - LogManager.getIntPropertyClamped( - "java.util.logging.MemoryHandler.size", - /* default */ 1000, - /* minimum value */ 1, - /* maximum value */ Integer.MAX_VALUE), - LogManager.getLevelProperty( - "java.util.logging.MemoryHandler.push", - /* default push level */ Level.SEVERE)); - } - - - /** - * Constructs a <code>MemoryHandler</code> for keeping a circular - * buffer of LogRecords, given some parameters. The values of the - * other parameters are taken from LogManager properties, as - * described above. - * - * @param target the target handler that will receive those - * log records that are passed on for publication. - * - * @param size the number of log records that are kept in the buffer. - * The value must be a at least one. - * - * @param pushLevel the push level threshold for this - * <code>MemoryHandler</code>. When a record is published whose - * severity level is greater than or equal to - * <code>pushLevel</code>, the {@link #push()} method will be - * invoked in order to push the bufffer contents to - * <code>target</code>. - * - * @throws java.lang.IllegalArgumentException if <code>size</code> - * is negative or zero. The GNU implementation also throws - * an IllegalArgumentException if <code>target</code> or - * <code>pushLevel</code> are <code>null</code>, but the - * API specification does not prescribe what should happen - * in those cases. - */ - public MemoryHandler(Handler target, int size, Level pushLevel) - { - if ((target == null) || (size <= 0) || (pushLevel == null)) - throw new IllegalArgumentException(); - - buffer = new LogRecord[size]; - this.pushLevel = pushLevel; - this.target = target; - - setLevel(LogManager.getLevelProperty( - "java.util.logging.MemoryHandler.level", - /* default value */ Level.ALL)); - - setFilter((Filter) LogManager.getInstanceProperty( - "java.util.logging.MemoryHandler.filter", - /* must be instance of */ Filter.class, - /* default value */ null)); - } - - - /** - * Stores a <code>LogRecord</code> in a fixed-size circular buffer, - * provided the record passes all tests for being loggable. If the - * buffer is full, the oldest record will be discarded. - * - * <p>If the record has a severity level which is greater than or - * equal to the <code>pushLevel</code> of this - * <code>MemoryHandler</code>, the {@link #push()} method will be - * invoked for pushing the buffer contents to the target - * <code>Handler</code>. - * - * <p>Most applications do not need to call this method directly. - * Instead, they will use use a {@link Logger}, which will create - * LogRecords and distribute them to registered handlers. - * - * @param record the log event to be published. - */ - public void publish(LogRecord record) - { - if (!isLoggable(record)) - return; - - buffer[position] = record; - position = (position + 1) % buffer.length; - numPublished = numPublished + 1; - - if (record.getLevel().intValue() >= pushLevel.intValue()) - push(); - } - - - /** - * Pushes the contents of the memory buffer to the target - * <code>Handler</code> and clears the buffer. Note that - * the target handler will discard those records that do - * not satisfy its own severity level threshold, or that are - * not considered loggable by an installed {@link Filter}. - * - * <p>In case of an I/O failure, the {@link ErrorManager} of the - * target <code>Handler</code> will be notified, but the caller of - * this method will not receive an exception. - */ - public void push() - { - int i; - - if (numPublished < buffer.length) - { - for (i = 0; i < position; i++) - target.publish(buffer[i]); - } - else - { - for (i = position; i < buffer.length; i++) - target.publish(buffer[i]); - for (i = 0; i < position; i++) - target.publish(buffer[i]); - } - - numPublished = 0; - position = 0; - } - - - /** - * Forces any data that may have been buffered by the target - * <code>Handler</code> to the underlying output device, but - * does <em>not</em> push the contents of the circular memory - * buffer to the target handler. - * - * <p>In case of an I/O failure, the {@link ErrorManager} of the - * target <code>Handler</code> will be notified, but the caller of - * this method will not receive an exception. - * - * @see #push() - */ - public void flush() - { - target.flush(); - } - - - /** - * Closes this <code>MemoryHandler</code> and its associated target - * handler, discarding the contents of the memory buffer. However, - * any data that may have been buffered by the target - * <code>Handler</code> is forced to the underlying output device. - * - * <p>As soon as <code>close</code> has been called, - * a <code>Handler</code> should not be used anymore. Attempts - * to publish log records, to flush buffers, or to modify the - * <code>Handler</code> in any other way may throw runtime - * exceptions after calling <code>close</code>.</p> - * - * <p>In case of an I/O failure, the <code>ErrorManager</code> of - * the associated target <code>Handler</code> will be informed, but - * the caller of this method will not receive an exception.</p> - * - * @throws SecurityException if a security manager exists and - * the caller is not granted the permission to control - * the logging infrastructure. - * - * @see #push() - */ - public void close() - throws SecurityException - { - push(); - - /* This will check for LoggingPermission("control"). If the - * current security context does not grant this permission, - * push() has been executed, but this does not impose a - * security risk. - */ - target.close(); - } - - - - /** - * Returns the push level threshold for this <code>Handler</code>. - * When a record is published whose severity level is greater - * than or equal to the <code>pushLevel</code> of this - * <code>MemoryHandler</code>, the {@link #push()} method will be - * invoked for pushing the buffer contents to the target - * <code>Handler</code>. - * - * @return the push level threshold for automatic pushing. - */ - public Level getPushLevel() - { - return pushLevel; - } - - - /** - * Sets the push level threshold for this <code>Handler</code>. - * When a record is published whose severity level is greater - * than or equal to the <code>pushLevel</code> of this - * <code>MemoryHandler</code>, the {@link #push()} method will be - * invoked for pushing the buffer contents to the target - * <code>Handler</code>. - * - * @param pushLevel the push level threshold for automatic pushing. - * - * @exception SecurityException if a security manager exists and - * the caller is not granted the permission to control - * the logging infrastructure. - * - * @exception NullPointerException if <code>pushLevel</code> is - * <code>null</code>. - */ - public void setPushLevel(Level pushLevel) - { - LogManager.getLogManager().checkAccess(); - - /* Throws a NullPointerException if pushLevel is null. */ - pushLevel.getClass(); - - this.pushLevel = pushLevel; - } -} diff --git a/libjava/java/util/logging/SimpleFormatter.java b/libjava/java/util/logging/SimpleFormatter.java deleted file mode 100644 index f7a442792f9..00000000000 --- a/libjava/java/util/logging/SimpleFormatter.java +++ /dev/null @@ -1,119 +0,0 @@ -/* SimpleFormatter.java -- - A class for formatting log records into short human-readable messages - Copyright (C) 2002, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util.logging; - -import java.text.DateFormat; -import java.util.Date; - -/** - * A <code>SimpleFormatter</code> formats log records into - * short human-readable messages, typically one or two lines. - * - * @author Sascha Brawer (brawer@acm.org) - */ -public class SimpleFormatter - extends Formatter -{ - /** - * Constructs a SimpleFormatter. - */ - public SimpleFormatter() - { - } - - - /** - * An instance of a DateFormatter that is used for formatting - * the time of a log record into a human-readable string, - * according to the rules of the current locale. The value - * is set after the first invocation of format, since it is - * common that a JVM will instantiate a SimpleFormatter without - * ever using it. - */ - private DateFormat dateFormat; - - /** - * The character sequence that is used to separate lines in the - * generated stream. Somewhat surprisingly, the Sun J2SE 1.4 - * reference implementation always uses UNIX line endings, even on - * platforms that have different line ending conventions (i.e., - * DOS). The GNU implementation does not replicate this bug. - * - * @see Sun bug parade, bug #4462871, - * "java.util.logging.SimpleFormatter uses hard-coded line separator". - */ - static final String lineSep = System.getProperty("line.separator"); - - - /** - * Formats a log record into a String. - * - * @param the log record to be formatted. - * - * @return a short human-readable message, typically one or two - * lines. Lines are separated using the default platform line - * separator. - * - * @throws NullPointerException if <code>record</code> - * is <code>null</code>. - */ - public String format(LogRecord record) - { - StringBuffer buf = new StringBuffer(180); - - if (dateFormat == null) - dateFormat = DateFormat.getDateTimeInstance(); - - buf.append(dateFormat.format(new Date(record.getMillis()))); - buf.append(' '); - buf.append(record.getSourceClassName()); - buf.append(' '); - buf.append(record.getSourceMethodName()); - buf.append(lineSep); - - buf.append(record.getLevel()); - buf.append(": "); - buf.append(formatMessage(record)); - - buf.append(lineSep); - - return buf.toString(); - } -} diff --git a/libjava/java/util/logging/SocketHandler.java b/libjava/java/util/logging/SocketHandler.java deleted file mode 100644 index 002dfdbbe5e..00000000000 --- a/libjava/java/util/logging/SocketHandler.java +++ /dev/null @@ -1,221 +0,0 @@ -/* SocketHandler.java -- a class for publishing log messages to network sockets - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util.logging; - - -/** - * A <code>SocketHandler</code> publishes log records to - * a TCP/IP socket. - * - * <p><strong>Configuration:</strong> Values of the subsequent - * <code>LogManager</code> properties are taken into consideration - * when a <code>SocketHandler</code> is initialized. - * If a property is not defined, or if it has an invalid - * value, a default is taken without an exception being thrown. - * - * <ul> - * - * <li><code>java.util.SocketHandler.level</code> - specifies - * the initial severity level threshold. Default value: - * <code>Level.ALL</code>.</li> - * - * <li><code>java.util.SocketHandler.filter</code> - specifies - * the name of a Filter class. Default value: No Filter.</li> - * - * <li><code>java.util.SocketHandler.formatter</code> - specifies - * the name of a Formatter class. Default value: - * <code>java.util.logging.XMLFormatter</code>.</li> - * - * <li><code>java.util.SocketHandler.encoding</code> - specifies - * the name of the character encoding. Default value: - * the default platform encoding.</li> - * - * <li><code>java.util.SocketHandler.host</code> - specifies - * the name of the host to which records are published. - * There is no default value for this property; if it is - * not set, the SocketHandler constructor will throw - * an exception.</li> - * - * <li><code>java.util.SocketHandler.port</code> - specifies - * the TCP/IP port to which records are published. - * There is no default value for this property; if it is - * not set, the SocketHandler constructor will throw - * an exception.</li> - * - * </ul> - * - * @author Sascha Brawer (brawer@acm.org) - */ -public class SocketHandler - extends StreamHandler -{ - /** - * Constructs a <code>SocketHandler</code> that publishes log - * records to a TCP/IP socket. Tthe initial configuration is - * determined by the <code>LogManager</code> properties described - * above. - * - * @throws java.io.IOException if the connection to the specified - * network host and port cannot be established. - * - * @throws java.lang.IllegalArgumentException if either the - * <code>java.util.logging.SocketHandler.host</code> - * or <code>java.util.logging.SocketHandler.port</code> - * LogManager properties is not defined, or specifies - * an invalid value. - */ - public SocketHandler() - throws java.io.IOException - { - this(LogManager.getLogManager().getProperty("java.util.logging.SocketHandler.host"), - getPortNumber()); - } - - - /** - * Constructs a <code>SocketHandler</code> that publishes log - * records to a TCP/IP socket. With the exception of the internet - * host and port, the initial configuration is determined by the - * <code>LogManager</code> properties described above. - * - * @param host the Internet host to which log records will be - * forwarded. - * - * @param port the port at the host which will accept a request - * for a TCP/IP connection. - * - * @throws java.io.IOException if the connection to the specified - * network host and port cannot be established. - * - * @throws java.lang.IllegalArgumentException if either - * <code>host</code> or <code>port</code> specify - * an invalid value. - */ - public SocketHandler(String host, int port) - throws java.io.IOException - { - super(createSocket(host, port), - "java.util.logging.SocketHandler", - /* default level */ Level.ALL, - /* formatter */ null, - /* default formatter */ XMLFormatter.class); - } - - - /** - * Retrieves the port number from the java.util.logging.SocketHandler.port - * LogManager property. - * - * @throws IllegalArgumentException if the property is not defined or - * does not specify an integer value. - */ - private static int getPortNumber() - { - try { - return Integer.parseInt(LogManager.getLogManager().getProperty("java.util.logging.SocketHandler.port")); - } catch (Exception ex) { - throw new IllegalArgumentException(); - } - } - - - /** - * Creates an OutputStream for publishing log records to an Internet - * host and port. This private method is a helper for use by the - * constructor of SocketHandler. - * - * @param host the Internet host to which log records will be - * forwarded. - * - * @param port the port at the host which will accept a request - * for a TCP/IP connection. - * - * @throws java.io.IOException if the connection to the specified - * network host and port cannot be established. - * - * @throws java.lang.IllegalArgumentException if either - * <code>host</code> or <code>port</code> specify - * an invalid value. - */ - private static java.io.OutputStream createSocket(String host, int port) - throws java.io.IOException, java.lang.IllegalArgumentException - { - java.net.Socket socket; - - if ((host == null) || (port < 1)) - throw new IllegalArgumentException(); - - socket = new java.net.Socket(host, port); - - socket.shutdownInput(); - - /* The architecture of the logging framework provides replaceable - * formatters. Because these formatters perform their task by - * returning one single String for each LogRecord to be formatted, - * there is no need to buffer. - */ - socket.setTcpNoDelay(true); - - return socket.getOutputStream(); - } - - - /** - * Publishes a <code>LogRecord</code> to the network socket, - * provided the record passes all tests for being loggable. - * In addition, all data that may have been buffered will - * be forced to the network stream. - * - * <p>Most applications do not need to call this method directly. - * Instead, they will use a {@link Logger} instance, which will - * create LogRecords and distribute them to registered handlers. - * - * <p>In case of an I/O failure, the <code>ErrorManager</code> - * of this <code>SocketHandler</code> will be informed, but the caller - * of this method will not receive an exception. - * - * @param record the log event to be published. - */ - public void publish(LogRecord record) - { - super.publish(record); - flush(); - } -} - diff --git a/libjava/java/util/logging/StreamHandler.java b/libjava/java/util/logging/StreamHandler.java deleted file mode 100644 index 5c35c1e481d..00000000000 --- a/libjava/java/util/logging/StreamHandler.java +++ /dev/null @@ -1,521 +0,0 @@ -/* StreamHandler.java -- - A class for publishing log messages to instances of java.io.OutputStream - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util.logging; - -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.UnsupportedEncodingException; -import java.io.Writer; - -/** - * A <code>StreamHandler</code> publishes <code>LogRecords</code> to - * a instances of <code>java.io.OutputStream</code>. - * - * @author Sascha Brawer (brawer@acm.org) - */ -public class StreamHandler - extends Handler -{ - private OutputStream out; - private Writer writer; - - - /** - * Indicates the current state of this StreamHandler. The value - * should be one of STATE_FRESH, STATE_PUBLISHED, or STATE_CLOSED. - */ - private int streamState = STATE_FRESH; - - - /** - * streamState having this value indicates that the StreamHandler - * has been created, but the publish(LogRecord) method has not been - * called yet. If the StreamHandler has been constructed without an - * OutputStream, writer will be null, otherwise it is set to a - * freshly created OutputStreamWriter. - */ - private static final int STATE_FRESH = 0; - - - /** - * streamState having this value indicates that the publish(LocRecord) - * method has been called at least once. - */ - private static final int STATE_PUBLISHED = 1; - - - /** - * streamState having this value indicates that the close() method - * has been called. - */ - private static final int STATE_CLOSED = 2; - - - /** - * Creates a <code>StreamHandler</code> without an output stream. - * Subclasses can later use {@link - * #setOutputStream(java.io.OutputStream)} to associate an output - * stream with this StreamHandler. - */ - public StreamHandler() - { - this(null, null); - } - - - /** - * Creates a <code>StreamHandler</code> that formats log messages - * with the specified Formatter and publishes them to the specified - * output stream. - * - * @param out the output stream to which the formatted log messages - * are published. - * - * @param formatter the <code>Formatter</code> that will be used - * to format log messages. - */ - public StreamHandler(OutputStream out, Formatter formatter) - { - this(out, "java.util.logging.StreamHandler", Level.INFO, - formatter, SimpleFormatter.class); - } - - - StreamHandler( - OutputStream out, - String propertyPrefix, - Level defaultLevel, - Formatter formatter, Class defaultFormatterClass) - { - this.level = LogManager.getLevelProperty(propertyPrefix + ".level", - defaultLevel); - - this.filter = (Filter) LogManager.getInstanceProperty( - propertyPrefix + ".filter", - /* must be instance of */ Filter.class, - /* default: new instance of */ null); - - if (formatter != null) - this.formatter = formatter; - else - this.formatter = (Formatter) LogManager.getInstanceProperty( - propertyPrefix + ".formatter", - /* must be instance of */ Formatter.class, - /* default: new instance of */ defaultFormatterClass); - - try - { - String enc = LogManager.getLogManager().getProperty(propertyPrefix - + ".encoding"); - - /* make sure enc actually is a valid encoding */ - if ((enc != null) && (enc.length() > 0)) - new String(new byte[0], enc); - - this.encoding = enc; - } - catch (Exception _) - { - } - - if (out != null) - { - try - { - changeWriter(out, getEncoding()); - } - catch (UnsupportedEncodingException uex) - { - /* This should never happen, since the validity of the encoding - * name has been checked above. - */ - throw new RuntimeException(uex.getMessage()); - } - } - } - - - private void checkOpen() - { - if (streamState == STATE_CLOSED) - throw new IllegalStateException(this.toString() + " has been closed"); - } - - private void checkFresh() - { - checkOpen(); - if (streamState != STATE_FRESH) - throw new IllegalStateException("some log records have been published to " + this); - } - - - private void changeWriter(OutputStream out, String encoding) - throws UnsupportedEncodingException - { - OutputStreamWriter writer; - - /* The logging API says that a null encoding means the default - * platform encoding. However, java.io.OutputStreamWriter needs - * another constructor for the default platform encoding, - * passing null would throw an exception. - */ - if (encoding == null) - writer = new OutputStreamWriter(out); - else - writer = new OutputStreamWriter(out, encoding); - - /* Closing the stream has side effects -- do this only after - * creating a new writer has been successful. - */ - if ((streamState != STATE_FRESH) || (this.writer != null)) - close(); - - this.writer = writer; - this.out = out; - this.encoding = encoding; - streamState = STATE_FRESH; - } - - - /** - * Sets the character encoding which this handler uses for publishing - * log records. The encoding of a <code>StreamHandler</code> must be - * set before any log records have been published. - * - * @param encoding the name of a character encoding, or <code>null</code> - * for the default encoding. - * - * @throws SecurityException if a security manager exists and - * the caller is not granted the permission to control the - * the logging infrastructure. - * - * @exception IllegalStateException if any log records have been - * published to this <code>StreamHandler</code> before. Please - * be aware that this is a pecularity of the GNU implementation. - * While the API specification indicates that it is an error - * if the encoding is set after records have been published, - * it does not mandate any specific behavior for that case. - */ - public void setEncoding(String encoding) - throws SecurityException, UnsupportedEncodingException - { - /* The inherited implementation first checks whether the invoking - * code indeed has the permission to control the logging infra- - * structure, and throws a SecurityException if this was not the - * case. - * - * Next, it verifies that the encoding is supported and throws - * an UnsupportedEncodingExcpetion otherwise. Finally, it remembers - * the name of the encoding. - */ - super.setEncoding(encoding); - - checkFresh(); - - /* If out is null, setEncoding is being called before an output - * stream has been set. In that case, we need to check that the - * encoding is valid, and remember it if this is the case. Since - * this is exactly what the inherited implementation of - * Handler.setEncoding does, we can delegate. - */ - if (out != null) - { - /* The logging API says that a null encoding means the default - * platform encoding. However, java.io.OutputStreamWriter needs - * another constructor for the default platform encoding, passing - * null would throw an exception. - */ - if (encoding == null) - writer = new OutputStreamWriter(out); - else - writer = new OutputStreamWriter(out, encoding); - } - } - - - /** - * Changes the output stream to which this handler publishes - * logging records. - * - * @throws SecurityException if a security manager exists and - * the caller is not granted the permission to control - * the logging infrastructure. - * - * @throws NullPointerException if <code>out</code> - * is <code>null</code>. - */ - protected void setOutputStream(OutputStream out) - throws SecurityException - { - LogManager.getLogManager().checkAccess(); - - /* Throw a NullPointerException if out is null. */ - out.getClass(); - - try - { - changeWriter(out, getEncoding()); - } - catch (UnsupportedEncodingException ex) - { - /* This seems quite unlikely to happen, unless the underlying - * implementation of java.io.OutputStreamWriter changes its - * mind (at runtime) about the set of supported character - * encodings. - */ - throw new RuntimeException(ex.getMessage()); - } - } - - - /** - * Publishes a <code>LogRecord</code> to the associated output - * stream, provided the record passes all tests for being loggable. - * The <code>StreamHandler</code> will localize the message of the - * log record and substitute any message parameters. - * - * <p>Most applications do not need to call this method directly. - * Instead, they will use use a {@link Logger}, which will create - * LogRecords and distribute them to registered handlers. - * - * <p>In case of an I/O failure, the <code>ErrorManager</code> - * of this <code>Handler</code> will be informed, but the caller - * of this method will not receive an exception. - * - * <p>If a log record is being published to a - * <code>StreamHandler</code> that has been closed earlier, the Sun - * J2SE 1.4 reference can be observed to silently ignore the - * call. The GNU implementation, however, intentionally behaves - * differently by informing the <code>ErrorManager</code> associated - * with this <code>StreamHandler</code>. Since the condition - * indicates a programming error, the programmer should be - * informed. It also seems extremely unlikely that any application - * would depend on the exact behavior in this rather obscure, - * erroneous case -- especially since the API specification does not - * prescribe what is supposed to happen. - * - * @param record the log event to be published. - */ - public void publish(LogRecord record) - { - String formattedMessage; - - if (!isLoggable(record)) - return; - - if (streamState == STATE_FRESH) - { - try - { - writer.write(formatter.getHead(this)); - } - catch (java.io.IOException ex) - { - reportError(null, ex, ErrorManager.WRITE_FAILURE); - return; - } - catch (Exception ex) - { - reportError(null, ex, ErrorManager.GENERIC_FAILURE); - return; - } - - streamState = STATE_PUBLISHED; - } - - try - { - formattedMessage = formatter.format(record); - } - catch (Exception ex) - { - reportError(null, ex, ErrorManager.FORMAT_FAILURE); - return; - } - - try - { - writer.write(formattedMessage); - } - catch (Exception ex) - { - reportError(null, ex, ErrorManager.WRITE_FAILURE); - } - } - - - /** - * Checks whether or not a <code>LogRecord</code> would be logged - * if it was passed to this <code>StreamHandler</code> for publication. - * - * <p>The <code>StreamHandler</code> implementation first checks - * whether a writer is present and the handler's level is greater - * than or equal to the severity level threshold. In a second step, - * if a {@link Filter} has been installed, its {@link - * Filter#isLoggable(LogRecord) isLoggable} method is - * invoked. Subclasses of <code>StreamHandler</code> can override - * this method to impose their own constraints. - * - * @param record the <code>LogRecord</code> to be checked. - * - * @return <code>true</code> if <code>record</code> would - * be published by {@link #publish(LogRecord) publish}, - * <code>false</code> if it would be discarded. - * - * @see #setLevel(Level) - * @see #setFilter(Filter) - * @see Filter#isLoggable(LogRecord) - * - * @throws NullPointerException if <code>record</code> is - * <code>null</code>. */ - public boolean isLoggable(LogRecord record) - { - return (writer != null) && super.isLoggable(record); - } - - - /** - * Forces any data that may have been buffered to the underlying - * output device. - * - * <p>In case of an I/O failure, the <code>ErrorManager</code> - * of this <code>Handler</code> will be informed, but the caller - * of this method will not receive an exception. - * - * <p>If a <code>StreamHandler</code> that has been closed earlier - * is closed a second time, the Sun J2SE 1.4 reference can be - * observed to silently ignore the call. The GNU implementation, - * however, intentionally behaves differently by informing the - * <code>ErrorManager</code> associated with this - * <code>StreamHandler</code>. Since the condition indicates a - * programming error, the programmer should be informed. It also - * seems extremely unlikely that any application would depend on the - * exact behavior in this rather obscure, erroneous case -- - * especially since the API specification does not prescribe what is - * supposed to happen. - */ - public void flush() - { - try - { - checkOpen(); - if (writer != null) - writer.flush(); - } - catch (Exception ex) - { - reportError(null, ex, ErrorManager.FLUSH_FAILURE); - } - } - - - /** - * Closes this <code>StreamHandler</code> after having forced any - * data that may have been buffered to the underlying output - * device. - * - * <p>As soon as <code>close</code> has been called, - * a <code>Handler</code> should not be used anymore. Attempts - * to publish log records, to flush buffers, or to modify the - * <code>Handler</code> in any other way may throw runtime - * exceptions after calling <code>close</code>.</p> - * - * <p>In case of an I/O failure, the <code>ErrorManager</code> - * of this <code>Handler</code> will be informed, but the caller - * of this method will not receive an exception.</p> - * - * <p>If a <code>StreamHandler</code> that has been closed earlier - * is closed a second time, the Sun J2SE 1.4 reference can be - * observed to silently ignore the call. The GNU implementation, - * however, intentionally behaves differently by informing the - * <code>ErrorManager</code> associated with this - * <code>StreamHandler</code>. Since the condition indicates a - * programming error, the programmer should be informed. It also - * seems extremely unlikely that any application would depend on the - * exact behavior in this rather obscure, erroneous case -- - * especially since the API specification does not prescribe what is - * supposed to happen. - * - * @throws SecurityException if a security manager exists and - * the caller is not granted the permission to control - * the logging infrastructure. - */ - public void close() - throws SecurityException - { - LogManager.getLogManager().checkAccess(); - - try - { - /* Although flush also calls checkOpen, it catches - * any exceptions and reports them to the ErrorManager - * as flush failures. However, we want to report - * a closed stream as a close failure, not as a - * flush failure here. Therefore, we call checkOpen() - * before flush(). - */ - checkOpen(); - flush(); - - if (writer != null) - { - if (formatter != null) - { - /* Even if the StreamHandler has never published a record, - * it emits head and tail upon closing. An earlier version - * of the GNU Classpath implementation did not emitted - * anything. However, this had caused XML log files to be - * entirely empty instead of containing no log records. - */ - if (streamState == STATE_FRESH) - writer.write(formatter.getHead(this)); - if (streamState != STATE_CLOSED) - writer.write(formatter.getTail(this)); - } - streamState = STATE_CLOSED; - writer.close(); - } - } - catch (Exception ex) - { - reportError(null, ex, ErrorManager.CLOSE_FAILURE); - } - } -} diff --git a/libjava/java/util/logging/XMLFormatter.java b/libjava/java/util/logging/XMLFormatter.java deleted file mode 100644 index 4dd63281727..00000000000 --- a/libjava/java/util/logging/XMLFormatter.java +++ /dev/null @@ -1,387 +0,0 @@ -/* XMLFormatter.java -- - A class for formatting log messages into a standard XML format - Copyright (C) 2002, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util.logging; - -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.ResourceBundle; - -/** - * An <code>XMLFormatter</code> formats LogRecords into - * a standard XML format. - * - * @author Sascha Brawer (brawer@acm.org) - */ -public class XMLFormatter - extends Formatter -{ - /** - * Constructs a new XMLFormatter. - */ - public XMLFormatter() - { - } - - - /** - * The character sequence that is used to separate lines in the - * generated XML stream. Somewhat surprisingly, the Sun J2SE 1.4 - * reference implementation always uses UNIX line endings, even on - * platforms that have different line ending conventions (i.e., - * DOS). The GNU Classpath implementation does not replicates this - * bug. - * - * See also the Sun bug parade, bug #4462871, - * "java.util.logging.SimpleFormatter uses hard-coded line separator". - */ - private static final String lineSep = SimpleFormatter.lineSep; - - - /** - * A DateFormat for emitting time in the ISO 8601 format. - * Since the API specification of SimpleDateFormat does not talk - * about its thread-safety, we cannot share a singleton instance. - */ - private final SimpleDateFormat iso8601 - = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); - - - /** - * Appends a line consisting of indentation, opening element tag, - * element content, closing element tag and line separator to - * a StringBuffer, provided that the element content is - * actually existing. - * - * @param buf the StringBuffer to which the line will be appended. - * - * @param indent the indentation level. - * - * @param tag the element tag name, for instance <code>method</code>. - * - * @param content the element content, or <code>null</code> to - * have no output whatsoever appended to <code>buf</code>. - */ - private static void appendTag(StringBuffer buf, int indent, - String tag, String content) - { - int i; - - if (content == null) - return; - - for (i = 0; i < indent * 2; i++) - buf.append(' '); - - buf.append("<"); - buf.append(tag); - buf.append('>'); - - /* Append the content, but escape for XML by replacing - * '&', '<', '>' and all non-ASCII characters with - * appropriate escape sequences. - * The Sun J2SE 1.4 reference implementation does not - * escape non-ASCII characters. This is a bug in their - * implementation which has been reported in the Java - * bug parade as bug number (FIXME: Insert number here). - */ - for (i = 0; i < content.length(); i++) - { - char c = content.charAt(i); - switch (c) - { - case '&': - buf.append("&"); - break; - - case '<': - buf.append("<"); - break; - - case '>': - buf.append(">"); - break; - - default: - if (((c >= 0x20) && (c <= 0x7e)) - || (c == /* line feed */ 10) - || (c == /* carriage return */ 13)) - buf.append(c); - else - { - buf.append("&#"); - buf.append((int) c); - buf.append(';'); - } - break; - } /* switch (c) */ - } /* for i */ - - buf.append("</"); - buf.append(tag); - buf.append(">"); - buf.append(lineSep); - } - - - /** - * Appends a line consisting of indentation, opening element tag, - * numeric element content, closing element tag and line separator - * to a StringBuffer. - * - * @param buf the StringBuffer to which the line will be appended. - * - * @param indent the indentation level. - * - * @param tag the element tag name, for instance <code>method</code>. - * - * @param content the element content. - */ - private static void appendTag(StringBuffer buf, int indent, - String tag, long content) - { - appendTag(buf, indent, tag, Long.toString(content)); - } - - - public String format(LogRecord record) - { - StringBuffer buf = new StringBuffer(400); - Level level = record.getLevel(); - long millis = record.getMillis(); - Object[] params = record.getParameters(); - ResourceBundle bundle = record.getResourceBundle(); - String message; - - buf.append("<record>"); - buf.append(lineSep); - - - appendTag(buf, 1, "date", iso8601.format(new Date(millis))); - appendTag(buf, 1, "millis", record.getMillis()); - appendTag(buf, 1, "sequence", record.getSequenceNumber()); - appendTag(buf, 1, "logger", record.getLoggerName()); - - if (level.isStandardLevel()) - appendTag(buf, 1, "level", level.toString()); - else - appendTag(buf, 1, "level", level.intValue()); - - appendTag(buf, 1, "class", record.getSourceClassName()); - appendTag(buf, 1, "method", record.getSourceMethodName()); - appendTag(buf, 1, "thread", record.getThreadID()); - - /* The Sun J2SE 1.4 reference implementation does not emit the - * message in localized form. This is in violation of the API - * specification. The GNU Classpath implementation intentionally - * replicates the buggy behavior of the Sun implementation, as - * different log files might be a big nuisance to users. - */ - try - { - record.setResourceBundle(null); - message = formatMessage(record); - } - finally - { - record.setResourceBundle(bundle); - } - appendTag(buf, 1, "message", message); - - /* The Sun J2SE 1.4 reference implementation does not - * emit key, catalog and param tags. This is in violation - * of the API specification. The Classpath implementation - * intentionally replicates the buggy behavior of the - * Sun implementation, as different log files might be - * a big nuisance to users. - * - * FIXME: File a bug report with Sun. Insert bug number here. - * - * - * key = record.getMessage(); - * if (key == null) - * key = ""; - * - * if ((bundle != null) && !key.equals(message)) - * { - * appendTag(buf, 1, "key", key); - * appendTag(buf, 1, "catalog", record.getResourceBundleName()); - * } - * - * if (params != null) - * { - * for (int i = 0; i < params.length; i++) - * appendTag(buf, 1, "param", params[i].toString()); - * } - */ - - /* FIXME: We have no way to obtain the stacktrace before free JVMs - * support the corresponding method in java.lang.Throwable. Well, - * it would be possible to parse the output of printStackTrace, - * but this would be pretty kludgy. Instead, we postpose the - * implementation until Throwable has made progress. - */ - Throwable thrown = record.getThrown(); - if (thrown != null) - { - buf.append(" <exception>"); - buf.append(lineSep); - - /* The API specification is not clear about what exactly - * goes into the XML record for a thrown exception: It - * could be the result of getMessage(), getLocalizedMessage(), - * or toString(). Therefore, it was necessary to write a - * Mauve testlet and run it with the Sun J2SE 1.4 reference - * implementation. It turned out that the we need to call - * toString(). - * - * FIXME: File a bug report with Sun, asking for clearer - * specs. - */ - appendTag(buf, 2, "message", thrown.toString()); - - /* FIXME: The Logging DTD specifies: - * - * <!ELEMENT exception (message?, frame+)> - * - * However, java.lang.Throwable.getStackTrace() is - * allowed to return an empty array. So, what frame should - * be emitted for an empty stack trace? We probably - * should file a bug report with Sun, asking for the DTD - * to be changed. - */ - - buf.append(" </exception>"); - buf.append(lineSep); - } - - - buf.append("</record>"); - buf.append(lineSep); - - return buf.toString(); - } - - - /** - * Returns a string that handlers are supposed to emit before - * the first log record. The base implementation returns an - * empty string, but subclasses such as {@link XMLFormatter} - * override this method in order to provide a suitable header. - * - * @return a string for the header. - * - * @param handler the handler which will prepend the returned - * string in front of the first log record. This method - * will inspect certain properties of the handler, for - * example its encoding, in order to construct the header. - */ - public String getHead(Handler h) - { - StringBuffer buf; - String encoding; - - buf = new StringBuffer(80); - buf.append("<?xml version=\"1.0\" encoding=\""); - - encoding = h.getEncoding(); - - /* file.encoding is a system property with the Sun JVM, indicating - * the platform-default file encoding. Unfortunately, the API - * specification for java.lang.System.getProperties() does not - * list this property. - */ - if (encoding == null) - encoding = System.getProperty("file.encoding"); - - /* Since file.encoding is not listed with the API specification of - * java.lang.System.getProperties(), there might be some VMs that - * do not define this system property. Therefore, we use UTF-8 as - * a reasonable default. Please note that if the platform encoding - * uses the same codepoints as US-ASCII for the US-ASCII character - * set (e.g, 65 for A), it does not matter whether we emit the - * wrong encoding into the XML header -- the GNU Classpath will - * emit XML escape sequences like Ӓ for any non-ASCII - * character. Virtually all character encodings use the same code - * points as US-ASCII for ASCII characters. Probably, EBCDIC is - * the only exception. - */ - if (encoding == null) - encoding = "UTF-8"; - - /* On Windows XP localized for Swiss German (this is one of - * my [Sascha Brawer's] test machines), the default encoding - * has the canonical name "windows-1252". The "historical" name - * of this encoding is "Cp1252" (see the Javadoc for the class - * java.nio.charset.Charset for the distinction). Now, that class - * does have a method for mapping historical to canonical encoding - * names. However, if we used it here, we would be come dependent - * on java.nio.*, which was only introduced with J2SE 1.4. - * Thus, we do this little hack here. As soon as Classpath supports - * java.nio.charset.CharSet, this hack should be replaced by - * code that correctly canonicalizes the encoding name. - */ - if ((encoding.length() > 2) && encoding.startsWith("Cp")) - encoding = "windows-" + encoding.substring(2); - - buf.append(encoding); - - buf.append("\" standalone=\"no\"?>"); - buf.append(lineSep); - - /* SYSTEM is not a fully qualified URL so that validating - * XML parsers do not need to connect to the Internet in - * order to read in a log file. See also the Sun Bug Parade, - * bug #4372790, "Logging APIs: need to use relative URL for XML - * doctype". - */ - buf.append("<!DOCTYPE log SYSTEM \"logger.dtd\">"); - buf.append(lineSep); - buf.append("<log>"); - buf.append(lineSep); - - return buf.toString(); - } - - - public String getTail(Handler h) - { - return "</log>" + lineSep; - } -} diff --git a/libjava/java/util/prefs/AbstractPreferences.java b/libjava/java/util/prefs/AbstractPreferences.java deleted file mode 100644 index 1c40ea8a92f..00000000000 --- a/libjava/java/util/prefs/AbstractPreferences.java +++ /dev/null @@ -1,1272 +0,0 @@ -/* AbstractPreferences -- Partial implementation of a Preference node - Copyright (C) 2001, 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util.prefs; - -import gnu.java.util.prefs.NodeWriter; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.util.HashMap; -import java.util.Iterator; -import java.util.TreeSet; - -/** - * Partial implementation of a Preference node. - * - * @since 1.4 - * @author Mark Wielaard (mark@klomp.org) - */ -public abstract class AbstractPreferences extends Preferences { - - // protected fields - - /** - * Object used to lock this preference node. Any thread only locks nodes - * downwards when it has the lock on the current node. No method should - * synchronize on the lock of any of its parent nodes while holding the - * lock on the current node. - */ - protected final Object lock = new Object(); - - /** - * Set to true in the contructor if the node did not exist in the backing - * store when this preference node object was created. Should be set in - * the contructor of a subclass. Defaults to false. Used to fire node - * changed events. - */ - protected boolean newNode = false; - - // private fields - - /** - * The parent preferences node or null when this is the root node. - */ - private final AbstractPreferences parent; - - /** - * The name of this node. - * Only when this is a root node (parent == null) the name is empty. - * It has a maximum of 80 characters and cannot contain any '/' characters. - */ - private final String name; - - /** True when this node has been remove, false otherwise. */ - private boolean removed = false; - - /** - * Holds all the child names and nodes of this node that have been - * accessed by earlier <code>getChild()</code> or <code>childSpi()</code> - * invocations and that have not been removed. - */ - private HashMap childCache = new HashMap(); - - // constructor - - /** - * Creates a new AbstractPreferences node with the given parent and name. - * - * @param parent the parent of this node or null when this is the root node - * @param name the name of this node, can not be null, only 80 characters - * maximum, must be empty when parent is null and cannot - * contain any '/' characters - * @exception IllegalArgumentException when name is null, greater then 80 - * characters, not the empty string but parent is null or - * contains a '/' character - */ - protected AbstractPreferences(AbstractPreferences parent, String name) { - if ( (name == null) // name should be given - || (name.length() > MAX_NAME_LENGTH) // 80 characters max - || (parent == null && name.length() != 0) // root has no name - || (parent != null && name.length() == 0) // all other nodes do - || (name.indexOf('/') != -1)) // must not contain '/' - throw new IllegalArgumentException("Illegal name argument '" - + name - + "' (parent is " - + (parent == null ? "" : "not ") - + "null)"); - this.parent = parent; - this.name = name; - } - - // identification methods - - /** - * Returns the absolute path name of this preference node. - * The absolute path name of a node is the path name of its parent node - * plus a '/' plus its own name. If the node is the root node and has no - * parent then its path name is "" and its absolute path name is "/". - */ - public String absolutePath() { - if (parent == null) - return "/"; - else - return parent.path() + '/' + name; - } - - /** - * Private helper method for absolutePath. Returns the empty string for a - * root node and otherwise the parentPath of its parent plus a '/'. - */ - private String path() { - if (parent == null) - return ""; - else - return parent.path() + '/' + name; - } - - /** - * Returns true if this node comes from the user preferences tree, false - * if it comes from the system preferences tree. - */ - public boolean isUserNode() { - AbstractPreferences root = this; - while (root.parent != null) - root = root.parent; - return root == Preferences.userRoot(); - } - - /** - * Returns the name of this preferences node. The name of the node cannot - * be null, can be mostly 80 characters and cannot contain any '/' - * characters. The root node has as name "". - */ - public String name() { - return name; - } - - /** - * Returns the String given by - * <code> - * (isUserNode() ? "User":"System") + " Preference Node: " + absolutePath() - * </code> - */ - public String toString() { - return (isUserNode() ? "User":"System") - + " Preference Node: " - + absolutePath(); - } - - /** - * Returns all known unremoved children of this node. - * - * @return All known unremoved children of this node - */ - protected final AbstractPreferences[] cachedChildren() - { - return (AbstractPreferences[]) childCache.values().toArray(); - } - - /** - * Returns all the direct sub nodes of this preferences node. - * Needs access to the backing store to give a meaningfull answer. - * <p> - * This implementation locks this node, checks if the node has not yet - * been removed and throws an <code>IllegalStateException</code> when it - * has been. Then it creates a new <code>TreeSet</code> and adds any - * already cached child nodes names. To get any uncached names it calls - * <code>childrenNamesSpi()</code> and adds the result to the set. Finally - * it calls <code>toArray()</code> on the created set. When the call to - * <code>childrenNamesSpi</code> thows an <code>BackingStoreException</code> - * this method will not catch that exception but propagate the exception - * to the caller. - * - * @exception BackingStoreException when the backing store cannot be - * reached - * @exception IllegalStateException when this node has been removed - */ - public String[] childrenNames() throws BackingStoreException { - synchronized(lock) { - if (isRemoved()) - throw new IllegalStateException("Node removed"); - - TreeSet childrenNames = new TreeSet(); - - // First get all cached node names - childrenNames.addAll(childCache.keySet()); - - // Then add any others - String names[] = childrenNamesSpi(); - for (int i = 0; i < names.length; i++) { - childrenNames.add(names[i]); - } - - // And return the array of names - String[] children = new String[childrenNames.size()]; - childrenNames.toArray(children); - return children; - - } - } - - /** - * Returns a sub node of this preferences node if the given path is - * relative (does not start with a '/') or a sub node of the root - * if the path is absolute (does start with a '/'). - * <p> - * This method first locks this node and checks if the node has not been - * removed, if it has been removed it throws an exception. Then if the - * path is relative (does not start with a '/') it checks if the path is - * legal (does not end with a '/' and has no consecutive '/' characters). - * Then it recursively gets a name from the path, gets the child node - * from the child-cache of this node or calls the <code>childSpi()</code> - * method to create a new child sub node. This is done recursively on the - * newly created sub node with the rest of the path till the path is empty. - * If the path is absolute (starts with a '/') the lock on this node is - * droped and this method is called on the root of the preferences tree - * with as argument the complete path minus the first '/'. - * - * @exception IllegalStateException if this node has been removed - * @exception IllegalArgumentException if the path contains two or more - * consecutive '/' characters, ends with a '/' charactor and is not the - * string "/" (indicating the root node) or any name on the path is more - * then 80 characters long - */ - public Preferences node(String path) { - synchronized(lock) { - if (isRemoved()) - throw new IllegalStateException("Node removed"); - - // Is it a relative path? - if (!path.startsWith("/")) { - - // Check if it is a valid path - if (path.indexOf("//") != -1 || path.endsWith("/")) - throw new IllegalArgumentException(path); - - return getNode(path); - } - } - - // path started with a '/' so it is absolute - // we drop the lock and start from the root (omitting the first '/') - Preferences root = isUserNode() ? userRoot() : systemRoot(); - return root.node(path.substring(1)); - - } - - /** - * Private helper method for <code>node()</code>. Called with this node - * locked. Returns this node when path is the empty string, if it is not - * empty the next node name is taken from the path (all chars till the - * next '/' or end of path string) and the node is either taken from the - * child-cache of this node or the <code>childSpi()</code> method is called - * on this node with the name as argument. Then this method is called - * recursively on the just constructed child node with the rest of the - * path. - * - * @param path should not end with a '/' character and should not contain - * consecutive '/' characters - * @exception IllegalArgumentException if path begins with a name that is - * larger then 80 characters. - */ - private Preferences getNode(String path) { - // if mark is dom then goto end - - // Empty String "" indicates this node - if (path.length() == 0) - return this; - - // Calculate child name and rest of path - String childName; - String childPath; - int nextSlash = path.indexOf('/'); - if (nextSlash == -1) { - childName = path; - childPath = ""; - } else { - childName = path.substring(0, nextSlash); - childPath = path.substring(nextSlash+1); - } - - // Get the child node - AbstractPreferences child; - child = (AbstractPreferences)childCache.get(childName); - if (child == null) { - - if (childName.length() > MAX_NAME_LENGTH) - throw new IllegalArgumentException(childName); - - // Not in childCache yet so create a new sub node - child = childSpi(childName); - // XXX - check if node is new - childCache.put(childName, child); - } - - // Lock the child and go down - synchronized(child.lock) { - return child.getNode(childPath); - } - } - - /** - * Returns true if the node that the path points to exists in memory or - * in the backing store. Otherwise it returns false or an exception is - * thrown. When this node is removed the only valid parameter is the - * empty string (indicating this node), the return value in that case - * will be false. - * - * @exception BackingStoreException when the backing store cannot be - * reached - * @exception IllegalStateException if this node has been removed - * and the path is not the empty string (indicating this node) - * @exception IllegalArgumentException if the path contains two or more - * consecutive '/' characters, ends with a '/' charactor and is not the - * string "/" (indicating the root node) or any name on the path is more - * then 80 characters long - */ - public boolean nodeExists(String path) throws BackingStoreException { - synchronized(lock) { - if (isRemoved() && path.length() != 0) - throw new IllegalStateException("Node removed"); - - // Is it a relative path? - if (!path.startsWith("/")) { - - // Check if it is a valid path - if (path.indexOf("//") != -1 || path.endsWith("/")) - throw new IllegalArgumentException(path); - - return existsNode(path); - } - } - - // path started with a '/' so it is absolute - // we drop the lock and start from the root (omitting the first '/') - Preferences root = isUserNode() ? userRoot() : systemRoot(); - return root.nodeExists(path.substring(1)); - - } - - private boolean existsNode(String path) throws BackingStoreException { - - // Empty String "" indicates this node - if (path.length() == 0) - return(!isRemoved()); - - // Calculate child name and rest of path - String childName; - String childPath; - int nextSlash = path.indexOf('/'); - if (nextSlash == -1) { - childName = path; - childPath = ""; - } else { - childName = path.substring(0, nextSlash); - childPath = path.substring(nextSlash+1); - } - - // Get the child node - AbstractPreferences child; - child = (AbstractPreferences)childCache.get(childName); - if (child == null) { - - if (childName.length() > MAX_NAME_LENGTH) - throw new IllegalArgumentException(childName); - - // Not in childCache yet so create a new sub node - child = getChild(childName); - - if (child == null) - return false; - - childCache.put(childName, child); - } - - // Lock the child and go down - synchronized(child.lock) { - return child.existsNode(childPath); - } - } - - /** - * Returns the child sub node if it exists in the backing store or null - * if it does not exist. Called (indirectly) by <code>nodeExists()</code> - * when a child node name can not be found in the cache. - * <p> - * Gets the lock on this node, calls <code>childrenNamesSpi()</code> to - * get an array of all (possibly uncached) children and compares the - * given name with the names in the array. If the name is found in the - * array <code>childSpi()</code> is called to get an instance, otherwise - * null is returned. - * - * @exception BackingStoreException when the backing store cannot be - * reached - */ - protected AbstractPreferences getChild(String name) - throws BackingStoreException - { - synchronized(lock) { - // Get all the names (not yet in the cache) - String[] names = childrenNamesSpi(); - for (int i=0; i < names.length; i++) - if (name.equals(names[i])) - return childSpi(name); - - // No child with that name found - return null; - } - } - - /** - * Returns true if this node has been removed with the - * <code>removeNode()</code> method, false otherwise. - * <p> - * Gets the lock on this node and then returns a boolean field set by - * <code>removeNode</code> methods. - */ - protected boolean isRemoved() { - synchronized(lock) { - return removed; - } - } - - /** - * Returns the parent preferences node of this node or null if this is - * the root of the preferences tree. - * <p> - * Gets the lock on this node, checks that the node has not been removed - * and returns the parent given to the constructor. - * - * @exception IllegalStateException if this node has been removed - */ - public Preferences parent() { - synchronized(lock) { - if (isRemoved()) - throw new IllegalStateException("Node removed"); - - return parent; - } - } - - // export methods - - /** - * XXX - */ - public void exportNode(OutputStream os) - throws BackingStoreException, - IOException - { - NodeWriter nodeWriter = new NodeWriter(this, os); - nodeWriter.writePrefs(); - } - - /** - * XXX - */ - public void exportSubtree(OutputStream os) - throws BackingStoreException, - IOException - { - NodeWriter nodeWriter = new NodeWriter(this, os); - nodeWriter.writePrefsTree(); - } - - // preference entry manipulation methods - - /** - * Returns an (possibly empty) array with all the keys of the preference - * entries of this node. - * <p> - * This method locks this node and checks if the node has not been - * removed, if it has been removed it throws an exception, then it returns - * the result of calling <code>keysSpi()</code>. - * - * @exception BackingStoreException when the backing store cannot be - * reached - * @exception IllegalStateException if this node has been removed - */ - public String[] keys() throws BackingStoreException { - synchronized(lock) { - if (isRemoved()) - throw new IllegalStateException("Node removed"); - - return keysSpi(); - } - } - - - /** - * Returns the value associated with the key in this preferences node. If - * the default value of the key cannot be found in the preferences node - * entries or something goes wrong with the backing store the supplied - * default value is returned. - * <p> - * Checks that key is not null and not larger then 80 characters, - * locks this node, and checks that the node has not been removed. - * Then it calls <code>keySpi()</code> and returns - * the result of that method or the given default value if it returned - * null or throwed an exception. - * - * @exception IllegalArgumentException if key is larger then 80 characters - * @exception IllegalStateException if this node has been removed - * @exception NullPointerException if key is null - */ - public String get(String key, String defaultVal) { - if (key.length() > MAX_KEY_LENGTH) - throw new IllegalArgumentException(key); - - synchronized(lock) { - if (isRemoved()) - throw new IllegalStateException("Node removed"); - - String value; - try { - value = getSpi(key); - } catch (ThreadDeath death) { - throw death; - } catch (Throwable t) { - value = null; - } - - if (value != null) { - return value; - } else { - return defaultVal; - } - } - } - - /** - * Convenience method for getting the given entry as a boolean. - * When the string representation of the requested entry is either - * "true" or "false" (ignoring case) then that value is returned, - * otherwise the given default boolean value is returned. - * - * @exception IllegalArgumentException if key is larger then 80 characters - * @exception IllegalStateException if this node has been removed - * @exception NullPointerException if key is null - */ - public boolean getBoolean(String key, boolean defaultVal) { - String value = get(key, null); - - if ("true".equalsIgnoreCase(value)) - return true; - - if ("false".equalsIgnoreCase(value)) - return false; - - return defaultVal; - } - - /** - * Convenience method for getting the given entry as a byte array. - * When the string representation of the requested entry is a valid - * Base64 encoded string (without any other characters, such as newlines) - * then the decoded Base64 string is returned as byte array, - * otherwise the given default byte array value is returned. - * - * @exception IllegalArgumentException if key is larger then 80 characters - * @exception IllegalStateException if this node has been removed - * @exception NullPointerException if key is null - */ - public byte[] getByteArray(String key, byte[] defaultVal) { - String value = get(key, null); - - byte[] b = null; - if (value != null) { - b = decode64(value); - } - - if (b != null) - return b; - else - return defaultVal; - } - - /** - * Helper method for decoding a Base64 string as an byte array. - * Returns null on encoding error. This method does not allow any other - * characters present in the string then the 65 special base64 chars. - */ - private static byte[] decode64(String s) { - ByteArrayOutputStream bs = new ByteArrayOutputStream((s.length()/4)*3); - char[] c = new char[s.length()]; - s.getChars(0, s.length(), c, 0); - - // Convert from base64 chars - int endchar = -1; - for(int j = 0; j < c.length && endchar == -1; j++) { - if (c[j] >= 'A' && c[j] <= 'Z') { - c[j] -= 'A'; - } else if (c[j] >= 'a' && c[j] <= 'z') { - c[j] = (char) (c[j] + 26 - 'a'); - } else if (c[j] >= '0' && c[j] <= '9') { - c[j] = (char) (c[j] + 52 - '0'); - } else if (c[j] == '+') { - c[j] = 62; - } else if (c[j] == '/') { - c[j] = 63; - } else if (c[j] == '=') { - endchar = j; - } else { - return null; // encoding exception - } - } - - int remaining = endchar == -1 ? c.length : endchar; - int i = 0; - while (remaining > 0) { - // Four input chars (6 bits) are decoded as three bytes as - // 000000 001111 111122 222222 - - byte b0 = (byte) (c[i] << 2); - if (remaining >= 2) { - b0 += (c[i+1] & 0x30) >> 4; - } - bs.write(b0); - - if (remaining >= 3) { - byte b1 = (byte) ((c[i+1] & 0x0F) << 4); - b1 += (byte) ((c[i+2] & 0x3C) >> 2); - bs.write(b1); - } - - if (remaining >= 4) { - byte b2 = (byte) ((c[i+2] & 0x03) << 6); - b2 += c[i+3]; - bs.write(b2); - } - - i += 4; - remaining -= 4; - } - - return bs.toByteArray(); - } - - /** - * Convenience method for getting the given entry as a double. - * When the string representation of the requested entry can be decoded - * with <code>Double.parseDouble()</code> then that double is returned, - * otherwise the given default double value is returned. - * - * @exception IllegalArgumentException if key is larger then 80 characters - * @exception IllegalStateException if this node has been removed - * @exception NullPointerException if key is null - */ - public double getDouble(String key, double defaultVal) { - String value = get(key, null); - - if (value != null) { - try { - return Double.parseDouble(value); - } catch (NumberFormatException nfe) { /* ignore */ } - } - - return defaultVal; - } - - /** - * Convenience method for getting the given entry as a float. - * When the string representation of the requested entry can be decoded - * with <code>Float.parseFloat()</code> then that float is returned, - * otherwise the given default float value is returned. - * - * @exception IllegalArgumentException if key is larger then 80 characters - * @exception IllegalStateException if this node has been removed - * @exception NullPointerException if key is null - */ - public float getFloat(String key, float defaultVal) { - String value = get(key, null); - - if (value != null) { - try { - return Float.parseFloat(value); - } catch (NumberFormatException nfe) { /* ignore */ } - } - - return defaultVal; - } - - /** - * Convenience method for getting the given entry as an integer. - * When the string representation of the requested entry can be decoded - * with <code>Integer.parseInt()</code> then that integer is returned, - * otherwise the given default integer value is returned. - * - * @exception IllegalArgumentException if key is larger then 80 characters - * @exception IllegalStateException if this node has been removed - * @exception NullPointerException if key is null - */ - public int getInt(String key, int defaultVal) { - String value = get(key, null); - - if (value != null) { - try { - return Integer.parseInt(value); - } catch (NumberFormatException nfe) { /* ignore */ } - } - - return defaultVal; - } - - /** - * Convenience method for getting the given entry as a long. - * When the string representation of the requested entry can be decoded - * with <code>Long.parseLong()</code> then that long is returned, - * otherwise the given default long value is returned. - * - * @exception IllegalArgumentException if key is larger then 80 characters - * @exception IllegalStateException if this node has been removed - * @exception NullPointerException if key is null - */ - public long getLong(String key, long defaultVal) { - String value = get(key, null); - - if (value != null) { - try { - return Long.parseLong(value); - } catch (NumberFormatException nfe) { /* ignore */ } - } - - return defaultVal; - } - - /** - * Sets the value of the given preferences entry for this node. - * Key and value cannot be null, the key cannot exceed 80 characters - * and the value cannot exceed 8192 characters. - * <p> - * The result will be immediatly visible in this VM, but may not be - * immediatly written to the backing store. - * <p> - * Checks that key and value are valid, locks this node, and checks that - * the node has not been removed. Then it calls <code>putSpi()</code>. - * - * @exception NullPointerException if either key or value are null - * @exception IllegalArgumentException if either key or value are to large - * @exception IllegalStateException when this node has been removed - */ - public void put(String key, String value) { - if (key.length() > MAX_KEY_LENGTH - || value.length() > MAX_VALUE_LENGTH) - throw new IllegalArgumentException("key (" - + key.length() + ")" - + " or value (" - + value.length() + ")" - + " to large"); - synchronized(lock) { - if (isRemoved()) - throw new IllegalStateException("Node removed"); - - putSpi(key, value); - - // XXX - fire events - } - - } - - /** - * Convenience method for setting the given entry as a boolean. - * The boolean is converted with <code>Boolean.toString(value)</code> - * and then stored in the preference entry as that string. - * - * @exception NullPointerException if key is null - * @exception IllegalArgumentException if the key length is to large - * @exception IllegalStateException when this node has been removed - */ - public void putBoolean(String key, boolean value) { - put(key, String.valueOf(value)); - // XXX - Use when using 1.4 compatible Boolean - // put(key, Boolean.toString(value)); - } - - /** - * Convenience method for setting the given entry as an array of bytes. - * The byte array is converted to a Base64 encoded string - * and then stored in the preference entry as that string. - * <p> - * Note that a byte array encoded as a Base64 string will be about 1.3 - * times larger then the original length of the byte array, which means - * that the byte array may not be larger about 6 KB. - * - * @exception NullPointerException if either key or value are null - * @exception IllegalArgumentException if either key or value are to large - * @exception IllegalStateException when this node has been removed - */ - public void putByteArray(String key, byte[] value) { - put(key, encode64(value)); - } - - /** - * Helper method for encoding an array of bytes as a Base64 String. - */ - private static String encode64(byte[] b) { - StringBuffer sb = new StringBuffer((b.length/3)*4); - - int i = 0; - int remaining = b.length; - char c[] = new char[4]; - while (remaining > 0) { - // Three input bytes are encoded as four chars (6 bits) as - // 00000011 11112222 22333333 - - c[0] = (char) ((b[i] & 0xFC) >> 2); - c[1] = (char) ((b[i] & 0x03) << 4); - if (remaining >= 2) { - c[1] += (char) ((b[i+1] & 0xF0) >> 4); - c[2] = (char) ((b[i+1] & 0x0F) << 2); - if (remaining >= 3) { - c[2] += (char) ((b[i+2] & 0xC0) >> 6); - c[3] = (char) (b[i+2] & 0x3F); - } else { - c[3] = 64; - } - } else { - c[2] = 64; - c[3] = 64; - } - - // Convert to base64 chars - for(int j = 0; j < 4; j++) { - if (c[j] < 26) { - c[j] += 'A'; - } else if (c[j] < 52) { - c[j] = (char) (c[j] - 26 + 'a'); - } else if (c[j] < 62) { - c[j] = (char) (c[j] - 52 + '0'); - } else if (c[j] == 62) { - c[j] = '+'; - } else if (c[j] == 63) { - c[j] = '/'; - } else { - c[j] = '='; - } - } - - sb.append(c); - i += 3; - remaining -= 3; - } - - return sb.toString(); - } - - /** - * Convenience method for setting the given entry as a double. - * The double is converted with <code>Double.toString(double)</code> - * and then stored in the preference entry as that string. - * - * @exception NullPointerException if the key is null - * @exception IllegalArgumentException if the key length is to large - * @exception IllegalStateException when this node has been removed - */ - public void putDouble(String key, double value) { - put(key, Double.toString(value)); - } - - /** - * Convenience method for setting the given entry as a float. - * The float is converted with <code>Float.toString(float)</code> - * and then stored in the preference entry as that string. - * - * @exception NullPointerException if the key is null - * @exception IllegalArgumentException if the key length is to large - * @exception IllegalStateException when this node has been removed - */ - public void putFloat(String key, float value) { - put(key, Float.toString(value)); - } - - /** - * Convenience method for setting the given entry as an integer. - * The integer is converted with <code>Integer.toString(int)</code> - * and then stored in the preference entry as that string. - * - * @exception NullPointerException if the key is null - * @exception IllegalArgumentException if the key length is to large - * @exception IllegalStateException when this node has been removed - */ - public void putInt(String key, int value) { - put(key, Integer.toString(value)); - } - - /** - * Convenience method for setting the given entry as a long. - * The long is converted with <code>Long.toString(long)</code> - * and then stored in the preference entry as that string. - * - * @exception NullPointerException if the key is null - * @exception IllegalArgumentException if the key length is to large - * @exception IllegalStateException when this node has been removed - */ - public void putLong(String key, long value) { - put(key, Long.toString(value)); - } - - /** - * Removes the preferences entry from this preferences node. - * <p> - * The result will be immediatly visible in this VM, but may not be - * immediatly written to the backing store. - * <p> - * This implementation checks that the key is not larger then 80 - * characters, gets the lock of this node, checks that the node has - * not been removed and calls <code>removeSpi</code> with the given key. - * - * @exception NullPointerException if the key is null - * @exception IllegalArgumentException if the key length is to large - * @exception IllegalStateException when this node has been removed - */ - public void remove(String key) { - if (key.length() > MAX_KEY_LENGTH) - throw new IllegalArgumentException(key); - - synchronized(lock) { - if (isRemoved()) - throw new IllegalStateException("Node removed"); - - removeSpi(key); - } - } - - /** - * Removes all entries from this preferences node. May need access to the - * backing store to get and clear all entries. - * <p> - * The result will be immediatly visible in this VM, but may not be - * immediatly written to the backing store. - * <p> - * This implementation locks this node, checks that the node has not been - * removed and calls <code>keys()</code> to get a complete array of keys - * for this node. For every key found <code>removeSpi()</code> is called. - * - * @exception BackingStoreException when the backing store cannot be - * reached - * @exception IllegalStateException if this node has been removed - */ - public void clear() throws BackingStoreException { - synchronized(lock) { - if (isRemoved()) - throw new IllegalStateException("Node Removed"); - - String[] keys = keys(); - for (int i = 0; i < keys.length; i++) { - removeSpi(keys[i]); - } - } - } - - /** - * Writes all preference changes on this and any subnode that have not - * yet been written to the backing store. This has no effect on the - * preference entries in this VM, but it makes sure that all changes - * are visible to other programs (other VMs might need to call the - * <code>sync()</code> method to actually see the changes to the backing - * store. - * <p> - * Locks this node, calls the <code>flushSpi()</code> method, gets all - * the (cached - already existing in this VM) subnodes and then calls - * <code>flushSpi()</code> on every subnode with this node unlocked and - * only that particular subnode locked. - * - * @exception BackingStoreException when the backing store cannot be - * reached - */ - public void flush() throws BackingStoreException { - flushNode(false); - } - - /** - * Writes and reads all preference changes to and from this and any - * subnodes. This makes sure that all local changes are written to the - * backing store and that all changes to the backing store are visible - * in this preference node (and all subnodes). - * <p> - * Checks that this node is not removed, locks this node, calls the - * <code>syncSpi()</code> method, gets all the subnodes and then calls - * <code>syncSpi()</code> on every subnode with this node unlocked and - * only that particular subnode locked. - * - * @exception BackingStoreException when the backing store cannot be - * reached - * @exception IllegalStateException if this node has been removed - */ - public void sync() throws BackingStoreException { - flushNode(true); - } - - - /** - * Private helper method that locks this node and calls either - * <code>flushSpi()</code> if <code>sync</code> is false, or - * <code>flushSpi()</code> if <code>sync</code> is true. Then it gets all - * the currently cached subnodes. For every subnode it calls this method - * recursively with this node no longer locked. - * <p> - * Called by either <code>flush()</code> or <code>sync()</code> - */ - private void flushNode(boolean sync) throws BackingStoreException { - String[] keys = null; - synchronized(lock) { - if (sync) { - syncSpi(); - } else { - flushSpi(); - } - keys = (String[]) childCache.keySet().toArray(); - } - - if (keys != null) { - for (int i = 0; i < keys.length; i++) { - // Have to lock this node again to access the childCache - AbstractPreferences subNode; - synchronized(this) { - subNode = (AbstractPreferences) childCache.get(keys[i]); - } - - // The child could already have been removed from the cache - if (subNode != null) { - subNode.flushNode(sync); - } - } - } - } - - /** - * Removes this and all subnodes from the backing store and clears all - * entries. After removal this instance will not be useable (except for - * a few methods that don't throw a <code>InvalidStateException</code>), - * even when a new node with the same path name is created this instance - * will not be usable again. - * <p> - * Checks that this is not a root node. If not it locks the parent node, - * then locks this node and checks that the node has not yet been removed. - * Then it makes sure that all subnodes of this node are in the child cache, - * by calling <code>childSpi()</code> on any children not yet in the cache. - * Then for all children it locks the subnode and removes it. After all - * subnodes have been purged the child cache is cleared, this nodes removed - * flag is set and any listeners are called. Finally this node is removed - * from the child cache of the parent node. - * - * @exception BackingStoreException when the backing store cannot be - * reached - * @exception IllegalStateException if this node has already been removed - * @exception UnsupportedOperationException if this is a root node - */ - public void removeNode() throws BackingStoreException { - // Check if it is a root node - if (parent == null) - throw new UnsupportedOperationException("Cannot remove root node"); - - synchronized(parent) { - synchronized(this) { - if (isRemoved()) - throw new IllegalStateException("Node Removed"); - - purge(); - } - parent.childCache.remove(name); - } - } - - /** - * Private helper method used to completely remove this node. - * Called by <code>removeNode</code> with the parent node and this node - * locked. - * <p> - * Makes sure that all subnodes of this node are in the child cache, - * by calling <code>childSpi()</code> on any children not yet in the - * cache. Then for all children it locks the subnode and calls this method - * on that node. After all subnodes have been purged the child cache is - * cleared, this nodes removed flag is set and any listeners are called. - */ - private void purge() throws BackingStoreException - { - // Make sure all children have an AbstractPreferences node in cache - String children[] = childrenNamesSpi(); - for (int i = 0; i < children.length; i++) { - if (childCache.get(children[i]) == null) - childCache.put(children[i], childSpi(children[i])); - } - - // purge all children - Iterator i = childCache.values().iterator(); - while (i.hasNext()) { - AbstractPreferences node = (AbstractPreferences) i.next(); - synchronized(node) { - node.purge(); - } - } - - // Cache is empty now - childCache.clear(); - - // remove this node - removeNodeSpi(); - removed = true; - - // XXX - check for listeners - } - - // listener methods - - /** - * XXX - */ - public void addNodeChangeListener(NodeChangeListener listener) { - // XXX - } - - public void addPreferenceChangeListener(PreferenceChangeListener listener) { - // XXX - } - - public void removeNodeChangeListener(NodeChangeListener listener) { - // XXX - } - - public void removePreferenceChangeListener - (PreferenceChangeListener listener) - { - // XXX - } - - // abstract spi methods - - /** - * Returns the names of the sub nodes of this preference node. - * This method only has to return any not yet cached child names, - * but may return all names if that is easier. It must not return - * null when there are no children, it has to return an empty array - * in that case. Since this method must consult the backing store to - * get all the sub node names it may throw a BackingStoreException. - * <p> - * Called by <code>childrenNames()</code> with this node locked. - */ - protected abstract String[] childrenNamesSpi() throws BackingStoreException; - - /** - * Returns a child note with the given name. - * This method is called by the <code>node()</code> method (indirectly - * through the <code>getNode()</code> helper method) with this node locked - * if a sub node with this name does not already exist in the child cache. - * If the child node did not aleady exist in the backing store the boolean - * field <code>newNode</code> of the returned node should be set. - * <p> - * Note that this method should even return a non-null child node if the - * backing store is not available since it may not throw a - * <code>BackingStoreException</code>. - */ - protected abstract AbstractPreferences childSpi(String name); - - /** - * Returns an (possibly empty) array with all the keys of the preference - * entries of this node. - * <p> - * Called by <code>keys()</code> with this node locked if this node has - * not been removed. May throw an exception when the backing store cannot - * be accessed. - * - * @exception BackingStoreException when the backing store cannot be - * reached - */ - protected abstract String[] keysSpi() throws BackingStoreException; - - /** - * Returns the value associated with the key in this preferences node or - * null when the key does not exist in this preferences node. - * <p> - * Called by <code>key()</code> with this node locked after checking that - * key is valid, not null and that the node has not been removed. - * <code>key()</code> will catch any exceptions that this method throws. - */ - protected abstract String getSpi(String key); - - /** - * Sets the value of the given preferences entry for this node. - * The implementation is not required to propagate the change to the - * backing store immediatly. It may not throw an exception when it tries - * to write to the backing store and that operation fails, the failure - * should be registered so a later invocation of <code>flush()</code> - * or <code>sync()</code> can signal the failure. - * <p> - * Called by <code>put()</code> with this node locked after checking that - * key and value are valid and non-null. - */ - protected abstract void putSpi(String key, String value); - - /** - * Removes the given key entry from this preferences node. - * The implementation is not required to propagate the change to the - * backing store immediatly. It may not throw an exception when it tries - * to write to the backing store and that operation fails, the failure - * should be registered so a later invocation of <code>flush()</code> - * or <code>sync()</code> can signal the failure. - * <p> - * Called by <code>remove()</code> with this node locked after checking - * that the key is valid and non-null. - */ - protected abstract void removeSpi(String key); - - /** - * Writes all entries of this preferences node that have not yet been - * written to the backing store and possibly creates this node in the - * backing store, if it does not yet exist. Should only write changes to - * this node and not write changes to any subnodes. - * Note that the node can be already removed in this VM. To check if - * that is the case the implementation can call <code>isRemoved()</code>. - * <p> - * Called (indirectly) by <code>flush()</code> with this node locked. - */ - protected abstract void flushSpi() throws BackingStoreException; - - /** - * Writes all entries of this preferences node that have not yet been - * written to the backing store and reads any entries that have changed - * in the backing store but that are not yet visible in this VM. - * Should only sync this node and not change any of the subnodes. - * Note that the node can be already removed in this VM. To check if - * that is the case the implementation can call <code>isRemoved()</code>. - * <p> - * Called (indirectly) by <code>sync()</code> with this node locked. - */ - protected abstract void syncSpi() throws BackingStoreException; - - /** - * Clears this node from this VM and removes it from the backing store. - * After this method has been called the node is marked as removed. - * <p> - * Called (indirectly) by <code>removeNode()</code> with this node locked - * after all the sub nodes of this node have already been removed. - */ - protected abstract void removeNodeSpi() throws BackingStoreException; -} diff --git a/libjava/java/util/prefs/BackingStoreException.java b/libjava/java/util/prefs/BackingStoreException.java deleted file mode 100644 index 0ba358a5688..00000000000 --- a/libjava/java/util/prefs/BackingStoreException.java +++ /dev/null @@ -1,104 +0,0 @@ -/* BackingStoreException.java - chained exception thrown when backing store - fails - Copyright (C) 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.util.prefs; - -import java.io.NotSerializableException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; - -/** - * Chained exception thrown when backing store fails. This exception is - * only thrown from methods that actually have to access the backing store, - * such as <code>clear(), keys(), childrenNames(), nodeExists(), removeNode(), - * flush(), sync(), exportNode(), exportSubTree()</code>; normal operations - * do not throw BackingStoreExceptions. - * - * <p>Note that although this class inherits the Serializable interface, an - * attempt to serialize will fail with a <code>NotSerializableException</code>. - * - * @author Mark Wielaard (mark@klomp.org) - * @since 1.4 - * @status updated to 1.4 - */ -public class BackingStoreException extends Exception -{ - static final long serialVersionUID = 859796500401108469L; - - /** - * Creates a new exception with a descriptive message. - * - * @param message the message - */ - public BackingStoreException(String message) - { - super(message); - } - - /** - * Create a new exception with the given cause. - * - * @param cause the cause - */ - public BackingStoreException(Throwable cause) - { - super(cause); - } - - /** - * This class should not be serialized. - * - * @param o the output stream - */ - private void writeObject(ObjectOutputStream o) throws NotSerializableException - { - throw new NotSerializableException - ("java.util.prefs.BackingStoreException"); - } - - /** - * This class should not be serialized. - * - * @param i the input stream - */ - private void readObject(ObjectInputStream i) throws NotSerializableException - { - throw new NotSerializableException - ("java.util.prefs.BackingStoreException"); - } -} diff --git a/libjava/java/util/prefs/InvalidPreferencesFormatException.java b/libjava/java/util/prefs/InvalidPreferencesFormatException.java deleted file mode 100644 index f929b56f68e..00000000000 --- a/libjava/java/util/prefs/InvalidPreferencesFormatException.java +++ /dev/null @@ -1,116 +0,0 @@ -/* InvalidPreferencesFormatException - indicates reading prefs from stream - failed - Copyright (C) 2001, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.util.prefs; - -import java.io.NotSerializableException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; - -/** - * Indicates reading prefs from stream failed. Thrown by the - * <code>importPreferences()</code> method when the supplied input stream - * could not be read because it was not in the correct XML format. - * - * <p>Note that although this class inherits the Serializable interface, an - * attempt to serialize will fail with a <code>NotSerializableException</code>. - * </p> - * - * @author Mark Wielaard (mark@klomp.org) - * @see Preferences - * @since 1.4 - * @status updated to 1.4 - */ -public class InvalidPreferencesFormatException extends Exception -{ - static final long serialVersionUID = -791715184232119669L; - - /** - * Creates a new exception with a descriptive message. The cause remains - * uninitialized. - * - * @param message the message - */ - public InvalidPreferencesFormatException(String message) - { - super(message); - } - - /** - * Creates a new exception with the given cause. - * - * @param cause the cause - */ - public InvalidPreferencesFormatException(Throwable cause) - { - super(cause); - } - - /** - * Creates a new exception with a descriptive message and a cause. - * - * @param message the message - * @param cause the cause - */ - public InvalidPreferencesFormatException(String message, Throwable cause) - { - super(message, cause); - } - - /** - * This class should not be serialized. - * - * @param o the output stream - */ - private void writeObject(ObjectOutputStream o) throws NotSerializableException - { - throw new NotSerializableException - ("java.util.prefs.InvalidPreferencesFormatException"); - } - - /** - * This class should not be serialized. - * - * @param i the input stream - */ - private void readObject(ObjectInputStream i) throws NotSerializableException - { - throw new NotSerializableException - ("java.util.prefs.InvalidPreferencesFormatException"); - } -} diff --git a/libjava/java/util/prefs/NodeChangeEvent.java b/libjava/java/util/prefs/NodeChangeEvent.java deleted file mode 100644 index 89986db88b3..00000000000 --- a/libjava/java/util/prefs/NodeChangeEvent.java +++ /dev/null @@ -1,91 +0,0 @@ -/* NodeChangeEvent - ObjectEvent fired when a Preference node is added/removed - Copyright (C) 2001 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.util.prefs; - -import java.util.EventObject; - -/** - * ObjectEvent fired when a Preference node is added/removed. - * This event is only generated when a new subnode is added or a subnode is - * removed from a preference node. Changes in the entries of a preference node - * are indicated with a <code>PreferenceChangeEvent</code>. - * - * @since 1.4 - * @author Mark Wielaard (mark@klomp.org) - */ -public class NodeChangeEvent extends EventObject { - - private static final long serialVersionUID =8068949086596572957L; - - /** - * The sub node that was added or removed. - * Defined transient just like <code>EventObject.source</code> since - * this object should be serializable, but Preferences is in general not - * serializable. - */ - private final transient Preferences child; - - /** - * Creates a new NodeChangeEvent. - * - * @param parentNode The source preference node from which a subnode was - * added or removed - * @param childNode The preference node that was added or removed - */ - public NodeChangeEvent(Preferences parentNode, Preferences childNode) { - super(parentNode); - child = childNode; - } - - /** - * Returns the source parent preference node from which a subnode was - * added or removed. - */ - public Preferences getParent() { - return (Preferences) source; - } - - /** - * Returns the child preference subnode that was added or removed. - * To see wether it is still a valid preference node one has to call - * <code>event.getChild().nodeExists("")</code>. - */ - public Preferences getChild() { - return child; - } -} diff --git a/libjava/java/util/prefs/NodeChangeListener.java b/libjava/java/util/prefs/NodeChangeListener.java deleted file mode 100644 index 19664c6652d..00000000000 --- a/libjava/java/util/prefs/NodeChangeListener.java +++ /dev/null @@ -1,64 +0,0 @@ -/* NodeChangeListener - EventListener for Preferences node addition/removal - Copyright (C) 2001 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.util.prefs; - -import java.util.EventListener; - -/** - * EventListener for Preferences node addition/removal. - * <p> - * Note that these events are only generated for the addition and removal - * of sub nodes from the preference node. Entry changes in the preference - * node can be monitored with a <code>PreferenceChangeListener</code>. - * - * @since 1.4 - * @author Mark Wielaard (mark@klomp.org) - */ -public interface NodeChangeListener extends EventListener { - - /** - * Fired when a sub node is added to the preference node. - */ - void childAdded(NodeChangeEvent event); - - /** - * Fired when a sub node is removed from the preference node. - */ - void childRemoved(NodeChangeEvent event); - -} diff --git a/libjava/java/util/prefs/PreferenceChangeEvent.java b/libjava/java/util/prefs/PreferenceChangeEvent.java deleted file mode 100644 index fe371f15e4e..00000000000 --- a/libjava/java/util/prefs/PreferenceChangeEvent.java +++ /dev/null @@ -1,105 +0,0 @@ -/* PreferenceChangeEvent - ObjectEvent fired when a Preferences entry changes - Copyright (C) 2001 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.util.prefs; - -import java.util.EventObject; - -/** - * ObjectEvent fired when a Preferences entry changes. - * This event is generated when a entry is added, changed or removed. - * When an entry is removed then <code>getNewValue</code> will return null. - * <p> - * Preference change events are only generated for entries in one particular - * preference node. Notification of subnode addition/removal is given by a - * <code>NodeChangeEvent</code>. - * - * @since 1.4 - * @author Mark Wielaard (mark@klomp.org) - */ -public class PreferenceChangeEvent extends EventObject { - - private static final long serialVersionUID = 793724513368024975L; - - /** - * The key of the changed entry. - */ - private final String key; - - /** - * The new value of the changed entry, or null when the entry was removed. - */ - private final String newValue; - - /** - * Creates a new PreferenceChangeEvent. - * - * @param node The source preference node for which an entry was added, - * changed or removed - * @param key The key of the entry that was added, changed or removed - * @param value The new value of the entry that was added or changed, or - * null when the entry was removed - */ - public PreferenceChangeEvent(Preferences node, String key, String value) { - super(node); - this.key = key; - this.newValue = value; - } - - /** - * Returns the source Preference node from which an entry was added, - * changed or removed. - */ - public Preferences getNode() { - return (Preferences) source; - } - - /** - * Returns the key of the entry that was added, changed or removed. - */ - public String getKey() { - return key; - } - - /** - * Returns the new value of the entry that was added or changed, or - * returns null when the entry was removed. - */ - public String getNewValue() { - return newValue; - } -} diff --git a/libjava/java/util/prefs/PreferenceChangeListener.java b/libjava/java/util/prefs/PreferenceChangeListener.java deleted file mode 100644 index adff3582079..00000000000 --- a/libjava/java/util/prefs/PreferenceChangeListener.java +++ /dev/null @@ -1,60 +0,0 @@ -/* PreferenceChangeListener - EventListener for Preferences entry changes - Copyright (C) 2001 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.util.prefs; - -import java.util.EventListener; - -/** - * EventListener for Preferences entry addition, change or removal. - * <p> - * Preference change events are only generated for entries in one particular - * preference node. Notification of subnode addition/removal can be monitored - * with a <code>NodeChangeListener</code>. - * - * @since 1.4 - * @author Mark Wielaard (mark@klomp.org) - */ -public interface PreferenceChangeListener extends EventListener { - - /** - * Fired when a entry has been added, changed or removed from the - * preference node. - */ - void preferenceChange(PreferenceChangeEvent event); - -} diff --git a/libjava/java/util/prefs/Preferences.java b/libjava/java/util/prefs/Preferences.java deleted file mode 100644 index c407ae6127a..00000000000 --- a/libjava/java/util/prefs/Preferences.java +++ /dev/null @@ -1,668 +0,0 @@ -/* Preferences -- Preference node containing key value entries and subnodes - Copyright (C) 2001, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.util.prefs; - -import gnu.java.util.prefs.NodeReader; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.security.AccessController; -import java.security.Permission; -import java.security.PrivilegedAction; - -/** - * Preference node containing key value entries and subnodes. - * <p> - * There are two preference node trees, a system tree which can be accessed - * by calling <code>systemRoot()</code> containing system preferences usefull - * for all users, and a user tree that can be accessed by calling - * <code>userRoot()</code> containing preferences that can differ between - * different users. How different users are identified is implementation - * depended. It can be determined by Thread, Access Control Context or Subject. - * <p> - * This implementation uses the "java.util.prefs.PreferencesFactory" system - * property to find a class that implement <code>PreferencesFactory</code> - * and initialized that class (if it has a public no arguments contructor) - * to get at the actual system or user root. If the system property is not set, - * or the class cannot be initialized it uses the default implementation - * <code>gnu.java.util.prefs.FileBasedFactory</code>. - * <p> - * Besides the two static method above to get the roots of the system and user - * preference node trees there are also two convenience methods to access the - * default preference node for a particular package an object is in. These are - * <code>userNodeForPackage()</code> and <code>systemNodeForPackage()</code>. - * Both methods take an Object as an argument so accessing preferences values - * can be as easy as calling <code>Preferences.userNodeForPackage(this)</code>. - * <p> - * Note that if a security manager is installed all static methods check for - * <code>RuntimePermission("preferences")</code>. But if this permission is - * given to the code then it can access and change all (user) preference nodes - * and entries. So you should be carefull not to store to sensitive information - * or make security decissions based on preference values since there is no - * more fine grained control over what preference values can be changed once - * code has been given the correct runtime permission. - * <p> - * XXX - * - * @since 1.4 - * @author Mark Wielaard (mark@klomp.org) - */ -public abstract class Preferences { - - // Static Fields - - /** - * Default PreferencesFactory class used when the system property - * "java.util.prefs.PreferencesFactory" is not set. - * <p> - * XXX - Currently set to MemoryBasedFactory, should be changed - * when FileBasedPreferences backend works. - */ - private static final String defaultFactoryClass - = "gnu.java.util.prefs.MemoryBasedFactory"; - - /** Permission needed to access system or user root. */ - private static final Permission prefsPermission - = new RuntimePermission("preferences"); - - /** - * The preferences factory object that supplies the system and user root. - * Set and returned by the getFactory() method. - */ - private static PreferencesFactory factory; - - /** Maximum node name length. 80 characters. */ - public static final int MAX_NAME_LENGTH = 80; - - /** Maximum entry key length. 80 characters. */ - public static final int MAX_KEY_LENGTH = 80; - - /** Maximum entry value length. 8192 characters. */ - public static final int MAX_VALUE_LENGTH = 8192; - - // Constructors - - /** - * Creates a new Preferences node. Can only be used by subclasses. - * Empty implementation. - */ - protected Preferences() {} - - // Static methods - - /** - * Returns the system preferences root node containing usefull preferences - * for all users. It is save to cache this value since it should always - * return the same preference node. - * - * @return the root system preference node - * @exception SecurityException when a security manager is installed and - * the caller does not have <code>RuntimePermission("preferences")</code>. - */ - public static Preferences systemRoot() throws SecurityException { - // Get the preferences factory and check for permission - PreferencesFactory factory = getFactory(); - - return factory.systemRoot(); - } - - /** - * Returns the user preferences root node containing preferences for the - * the current user. How different users are identified is implementation - * depended. It can be determined by Thread, Access Control Context or - * Subject. - * - * @return the root user preference node - * @exception SecurityException when a security manager is installed and - * the caller does not have <code>RuntimePermission("preferences")</code>. - */ - public static Preferences userRoot() throws SecurityException { - // Get the preferences factory and check for permission - PreferencesFactory factory = getFactory(); - return factory.userRoot(); - } - - /** - * Private helper method for <code>systemRoot()</code> and - * <code>userRoot()</code>. Checks security permission and instantiates the - * correct factory if it has not yet been set. - * <p> - * When the preferences factory has not yet been set this method first - * tries to get the system propery "java.util.prefs.PreferencesFactory" - * and tries to initializes that class. If the system property is not set - * or initialization fails it returns an instance of the default factory - * <code>gnu.java.util.prefs.FileBasedPreferencesFactory</code>. - * - * @return the preferences factory to use - * @exception SecurityException when a security manager is installed and - * the caller does not have <code>RuntimePermission("preferences")</code>. - */ - private static PreferencesFactory getFactory() throws SecurityException { - - // First check for permission - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - sm.checkPermission(prefsPermission); - } - - // Get the factory - if (factory == null) { - // Caller might not have enough permissions - factory = (PreferencesFactory) AccessController.doPrivileged( - new PrivilegedAction() { - public Object run() { - PreferencesFactory pf = null; - String className = System.getProperty - ("java.util.prefs.PreferencesFactory"); - if (className != null) { - try { - Class fc = Class.forName(className); - Object o = fc.newInstance(); - pf = (PreferencesFactory) o; - } catch (ClassNotFoundException cnfe) - {/*ignore*/} - catch (InstantiationException ie) - {/*ignore*/} - catch (IllegalAccessException iae) - {/*ignore*/} - catch (ClassCastException cce) - {/*ignore*/} - } - return pf; - } - }); - - // Still no factory? Use our default. - if (factory == null) - { - try - { - Class cls = Class.forName (defaultFactoryClass); - factory = (PreferencesFactory) cls.newInstance(); - } - catch (Exception e) - { - throw new RuntimeException ("Couldn't load default factory" - + " '"+ defaultFactoryClass +"'"); - // XXX - when using 1.4 compatible throwables add cause - } - } - - } - - return factory; - } - - /** - * Returns the system preferences node for the package of an object. - * The package node name of the object is determined by dropping the - * class name of the object of the fully quallified class name and - * replacing all '.' to '/' in the package name. If the class of the - * object has no package then the package node name is "<unnamed>". - * The returened node is <code>systemRoot().node(packageNodeName)</code>. - * - * @param o Object whose default system preference node is requested - * @returns system preferences node that should be used by object o - * @exception SecurityException when a security manager is installed and - * the caller does not have <code>RuntimePermission("preferences")</code>. - */ - public static Preferences systemNodeForPackage(Class c) - throws SecurityException - { - return nodeForPackage(c, systemRoot()); - } - - /** - * Returns the user preferences node for the package of an object. - * The package node name of the object is determined by dropping the - * class name of the object of the fully quallified class name and - * replacing all '.' to '/' in the package name. If the class of the - * object has no package then the package node name is "<unnamed>". - * The returened node is <code>userRoot().node(packageNodeName)</code>. - * - * @param o Object whose default user preference node is requested - * @returns user preferences node that should be used by object o - * @exception SecurityException when a security manager is installed and - * the caller does not have <code>RuntimePermission("preferences")</code>. - */ - public static Preferences userNodeForPackage(Class c) - throws SecurityException - { - return nodeForPackage(c, userRoot()); - } - - /** - * Private helper method for <code>systemNodeForPackage()</code> and - * <code>userNodeForPackage()</code>. Given the correct system or user - * root it returns the correct Preference node for the package node name - * of the given object. - */ - private static Preferences nodeForPackage(Class c, Preferences root) { - // Get the package path - String className = c.getName(); - String packagePath; - int index = className.lastIndexOf('.'); - if(index == -1) { - packagePath = "<unnamed>"; - } else { - packagePath = className.substring(0,index).replace('.','/'); - } - - return root.node(packagePath); - } - - /** - * XXX - */ - public static void importPreferences(InputStream is) - throws InvalidPreferencesFormatException, - IOException - { - PreferencesFactory factory = getFactory(); - NodeReader reader = new NodeReader(is, factory); - reader.importPreferences(); - } - - // abstract methods (identification) - - /** - * Returns the absolute path name of this preference node. - * The absolute path name of a node is the path name of its parent node - * plus a '/' plus its own name. If the node is the root node and has no - * parent then its name is "" and its absolute path name is "/". - */ - public abstract String absolutePath(); - - /** - * Returns true if this node comes from the user preferences tree, false - * if it comes from the system preferences tree. - */ - public abstract boolean isUserNode(); - - /** - * Returns the name of this preferences node. The name of the node cannot - * be null, can be mostly 80 characters and cannot contain any '/' - * characters. The root node has as name "". - */ - public abstract String name(); - - /** - * Returns the String given by - * <code> - * (isUserNode() ? "User":"System") + " Preference Node: " + absolutePath() - * </code> - */ - public abstract String toString(); - - // abstract methods (navigation) - - /** - * Returns all the direct sub nodes of this preferences node. - * Needs access to the backing store to give a meaningfull answer. - * - * @exception BackingStoreException when the backing store cannot be - * reached - * @exception IllegalStateException when this node has been removed - */ - public abstract String[] childrenNames() throws BackingStoreException; - - /** - * Returns a sub node of this preferences node if the given path is - * relative (does not start with a '/') or a sub node of the root - * if the path is absolute (does start with a '/'). - * - * @exception IllegalStateException if this node has been removed - * @exception IllegalArgumentException if the path contains two or more - * consecutive '/' characters, ends with a '/' charactor and is not the - * string "/" (indicating the root node) or any name on the path is more - * then 80 characters long - */ - public abstract Preferences node(String path); - - /** - * Returns true if the node that the path points to exists in memory or - * in the backing store. Otherwise it returns false or an exception is - * thrown. When this node is removed the only valid parameter is the - * empty string (indicating this node), the return value in that case - * will be false. - * - * @exception BackingStoreException when the backing store cannot be - * reached - * @exception IllegalStateException if this node has been removed - * and the path is not the empty string (indicating this node) - * @exception IllegalArgumentException if the path contains two or more - * consecutive '/' characters, ends with a '/' charactor and is not the - * string "/" (indicating the root node) or any name on the path is more - * then 80 characters long - */ - public abstract boolean nodeExists(String path) - throws BackingStoreException; - - /** - * Returns the parent preferences node of this node or null if this is - * the root of the preferences tree. - * - * @exception IllegalStateException if this node has been removed - */ - public abstract Preferences parent(); - - // abstract methods (export) - - /** - * XXX - */ - public abstract void exportNode(OutputStream os) - throws BackingStoreException, - IOException; - - /** - * XXX - */ - public abstract void exportSubtree(OutputStream os) - throws BackingStoreException, - IOException; - - // abstract methods (preference entry manipulation) - - /** - * Returns an (possibly empty) array with all the keys of the preference - * entries of this node. - * - * @exception BackingStoreException when the backing store cannot be - * reached - * @exception IllegalStateException if this node has been removed - */ - public abstract String[] keys() throws BackingStoreException; - - /** - * Returns the value associated with the key in this preferences node. If - * the default value of the key cannot be found in the preferences node - * entries or something goes wrong with the backing store the supplied - * default value is returned. - * - * @exception IllegalArgumentException if key is larger then 80 characters - * @exception IllegalStateException if this node has been removed - * @exception NullPointerException if key is null - */ - public abstract String get(String key, String defaultVal); - - /** - * Convenience method for getting the given entry as a boolean. - * When the string representation of the requested entry is either - * "true" or "false" (ignoring case) then that value is returned, - * otherwise the given default boolean value is returned. - * - * @exception IllegalArgumentException if key is larger then 80 characters - * @exception IllegalStateException if this node has been removed - * @exception NullPointerException if key is null - */ - public abstract boolean getBoolean(String key, boolean defaultVal); - - /** - * Convenience method for getting the given entry as a byte array. - * When the string representation of the requested entry is a valid - * Base64 encoded string (without any other characters, such as newlines) - * then the decoded Base64 string is returned as byte array, - * otherwise the given default byte array value is returned. - * - * @exception IllegalArgumentException if key is larger then 80 characters - * @exception IllegalStateException if this node has been removed - * @exception NullPointerException if key is null - */ - public abstract byte[] getByteArray(String key, byte[] defaultVal); - - /** - * Convenience method for getting the given entry as a double. - * When the string representation of the requested entry can be decoded - * with <code>Double.parseDouble()</code> then that double is returned, - * otherwise the given default double value is returned. - * - * @exception IllegalArgumentException if key is larger then 80 characters - * @exception IllegalStateException if this node has been removed - * @exception NullPointerException if key is null - */ - public abstract double getDouble(String key, double defaultVal); - - /** - * Convenience method for getting the given entry as a float. - * When the string representation of the requested entry can be decoded - * with <code>Float.parseFloat()</code> then that float is returned, - * otherwise the given default float value is returned. - * - * @exception IllegalArgumentException if key is larger then 80 characters - * @exception IllegalStateException if this node has been removed - * @exception NullPointerException if key is null - */ - public abstract float getFloat(String key, float defaultVal); - - /** - * Convenience method for getting the given entry as an integer. - * When the string representation of the requested entry can be decoded - * with <code>Integer.parseInt()</code> then that integer is returned, - * otherwise the given default integer value is returned. - * - * @exception IllegalArgumentException if key is larger then 80 characters - * @exception IllegalStateException if this node has been removed - * @exception NullPointerException if key is null - */ - public abstract int getInt(String key, int defaultVal); - - /** - * Convenience method for getting the given entry as a long. - * When the string representation of the requested entry can be decoded - * with <code>Long.parseLong()</code> then that long is returned, - * otherwise the given default long value is returned. - * - * @exception IllegalArgumentException if key is larger then 80 characters - * @exception IllegalStateException if this node has been removed - * @exception NullPointerException if key is null - */ - public abstract long getLong(String key, long defaultVal); - - /** - * Sets the value of the given preferences entry for this node. - * Key and value cannot be null, the key cannot exceed 80 characters - * and the value cannot exceed 8192 characters. - * <p> - * The result will be immediatly visible in this VM, but may not be - * immediatly written to the backing store. - * - * @exception NullPointerException if either key or value are null - * @exception IllegalArgumentException if either key or value are to large - * @exception IllegalStateException when this node has been removed - */ - public abstract void put(String key, String value); - - /** - * Convenience method for setting the given entry as a boolean. - * The boolean is converted with <code>Boolean.toString(value)</code> - * and then stored in the preference entry as that string. - * - * @exception NullPointerException if key is null - * @exception IllegalArgumentException if the key length is to large - * @exception IllegalStateException when this node has been removed - */ - public abstract void putBoolean(String key, boolean value); - - /** - * Convenience method for setting the given entry as an array of bytes. - * The byte array is converted to a Base64 encoded string - * and then stored in the preference entry as that string. - * <p> - * Note that a byte array encoded as a Base64 string will be about 1.3 - * times larger then the original length of the byte array, which means - * that the byte array may not be larger about 6 KB. - * - * @exception NullPointerException if either key or value are null - * @exception IllegalArgumentException if either key or value are to large - * @exception IllegalStateException when this node has been removed - */ - public abstract void putByteArray(String key, byte[] value); - - /** - * Convenience method for setting the given entry as a double. - * The double is converted with <code>Double.toString(double)</code> - * and then stored in the preference entry as that string. - * - * @exception NullPointerException if the key is null - * @exception IllegalArgumentException if the key length is to large - * @exception IllegalStateException when this node has been removed - */ - public abstract void putDouble(String key, double value); - - /** - * Convenience method for setting the given entry as a float. - * The float is converted with <code>Float.toString(float)</code> - * and then stored in the preference entry as that string. - * - * @exception NullPointerException if the key is null - * @exception IllegalArgumentException if the key length is to large - * @exception IllegalStateException when this node has been removed - */ - public abstract void putFloat(String key, float value); - - /** - * Convenience method for setting the given entry as an integer. - * The integer is converted with <code>Integer.toString(int)</code> - * and then stored in the preference entry as that string. - * - * @exception NullPointerException if the key is null - * @exception IllegalArgumentException if the key length is to large - * @exception IllegalStateException when this node has been removed - */ - public abstract void putInt(String key, int value); - - /** - * Convenience method for setting the given entry as a long. - * The long is converted with <code>Long.toString(long)</code> - * and then stored in the preference entry as that string. - * - * @exception NullPointerException if the key is null - * @exception IllegalArgumentException if the key length is to large - * @exception IllegalStateException when this node has been removed - */ - public abstract void putLong(String key, long value); - - /** - * Removes the preferences entry from this preferences node. - * <p> - * The result will be immediatly visible in this VM, but may not be - * immediatly written to the backing store. - * - * @exception NullPointerException if the key is null - * @exception IllegalArgumentException if the key length is to large - * @exception IllegalStateException when this node has been removed - */ - public abstract void remove(String key); - - // abstract methods (preference node manipulation) - - /** - * Removes all entries from this preferences node. May need access to the - * backing store to get and clear all entries. - * <p> - * The result will be immediatly visible in this VM, but may not be - * immediatly written to the backing store. - * - * @exception BackingStoreException when the backing store cannot be - * reached - * @exception IllegalStateException if this node has been removed - */ - public abstract void clear() throws BackingStoreException; - - /** - * Writes all preference changes on this and any subnode that have not - * yet been written to the backing store. This has no effect on the - * preference entries in this VM, but it makes sure that all changes - * are visible to other programs (other VMs might need to call the - * <code>sync()</code> method to actually see the changes to the backing - * store. - * - * @exception BackingStoreException when the backing store cannot be - * reached - * @exception IllegalStateException if this node has been removed - */ - public abstract void flush() throws BackingStoreException; - - /** - * Writes and reads all preference changes to and from this and any - * subnodes. This makes sure that all local changes are written to the - * backing store and that all changes to the backing store are visible - * in this preference node (and all subnodes). - * - * @exception BackingStoreException when the backing store cannot be - * reached - * @exception IllegalStateException if this node has been removed - */ - public abstract void sync() throws BackingStoreException; - - /** - * Removes this and all subnodes from the backing store and clears all - * entries. After removal this instance will not be useable (except for - * a few methods that don't throw a <code>InvalidStateException</code>), - * even when a new node with the same path name is created this instance - * will not be usable again. The root (system or user) may never be removed. - * <p> - * Note that according to the specification an implementation may delay - * removal of the node from the backing store till the <code>flush()</code> - * method is called. But the <code>flush()</code> method may throw a - * <code>IllegalStateException</code> when the node has been removed. - * So most implementations will actually remove the node and any subnodes - * from the backing store immediatly. - * - * @exception BackingStoreException when the backing store cannot be - * reached - * @exception IllegalStateException if this node has already been removed - * @exception UnsupportedOperationException if this is a root node - */ - public abstract void removeNode() throws BackingStoreException; - - // abstract methods (listeners) - - public abstract void addNodeChangeListener(NodeChangeListener listener); - - public abstract void addPreferenceChangeListener - (PreferenceChangeListener listener); - - public abstract void removeNodeChangeListener(NodeChangeListener listener); - - public abstract void removePreferenceChangeListener - (PreferenceChangeListener listener); -} - diff --git a/libjava/java/util/prefs/PreferencesFactory.java b/libjava/java/util/prefs/PreferencesFactory.java deleted file mode 100644 index f4fe7e37ffe..00000000000 --- a/libjava/java/util/prefs/PreferencesFactory.java +++ /dev/null @@ -1,65 +0,0 @@ -/* PreferencesFactory - Preferences system and user root factory interface - Copyright (C) 2001 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util.prefs; - -/** - * Preferences system and user root factory interface. Defines how to get - * to the system and user root preferences objects. Should be implemented by - * new preferences backends. - * - * @since 1.4 - * @author Mark Wielaard (mark@klomp.org) - */ -public interface PreferencesFactory { - - /** - * Returns the system root preferences node. Should always return the - * same object. - */ - Preferences systemRoot(); - - /** - * Returns the user root preferences node. May return different objects - * depending on the user that called this method. The user may for example - * be determined by the current Thread or the Subject associated with the - * current AccessControllContext. - */ - Preferences userRoot(); - -} diff --git a/libjava/java/util/regex/Matcher.java b/libjava/java/util/regex/Matcher.java deleted file mode 100644 index bd97ace54a8..00000000000 --- a/libjava/java/util/regex/Matcher.java +++ /dev/null @@ -1,301 +0,0 @@ -/* Matcher.java -- Instance of a regular expression applied to a char sequence. - Copyright (C) 2002, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util.regex; - -import gnu.regexp.REMatch; - -/** - * Instance of a regular expression applied to a char sequence. - * - * @since 1.4 - */ -public final class Matcher -{ - private Pattern pattern; - private CharSequence input; - private int position; - private int appendPosition; - private REMatch match; - - Matcher(Pattern pattern, CharSequence input) - { - this.pattern = pattern; - this.input = input; - } - - /** - * @param sb The target string buffer - * @param replacement The replacement string - * - * @exception IllegalStateException If no match has yet been attempted, - * or if the previous match operation failed - * @exception IndexOutOfBoundsException If the replacement string refers - * to a capturing group that does not exist in the pattern - */ - public Matcher appendReplacement (StringBuffer sb, String replacement) - throws IllegalStateException - { - assertMatchOp(); - sb.append(input.subSequence(appendPosition, - match.getStartIndex()).toString()); - sb.append(match.substituteInto(replacement)); - appendPosition = match.getEndIndex(); - return this; - } - - /** - * @param sb The target string buffer - */ - public StringBuffer appendTail (StringBuffer sb) - { - sb.append(input.subSequence(appendPosition, input.length()).toString()); - return sb; - } - - /** - * @exception IllegalStateException If no match has yet been attempted, - * or if the previous match operation failed - */ - public int end () - throws IllegalStateException - { - assertMatchOp(); - return match.getEndIndex(); - } - - /** - * @param group The index of a capturing group in this matcher's pattern - * - * @exception IllegalStateException If no match has yet been attempted, - * or if the previous match operation failed - * @exception IndexOutOfBoundsException If the replacement string refers - * to a capturing group that does not exist in the pattern - */ - public int end (int group) - throws IllegalStateException - { - assertMatchOp(); - return match.getEndIndex(group); - } - - public boolean find () - { - boolean first = (match == null); - match = pattern.getRE().getMatch(input, position); - if (match != null) - { - int endIndex = match.getEndIndex(); - // Are we stuck at the same position? - if (!first && endIndex == position) - { - match = null; - // Not at the end of the input yet? - if (position < input.length() - 1) - { - position++; - return find(position); - } - else - return false; - } - position = endIndex; - return true; - } - return false; - } - - /** - * @param start The index to start the new pattern matching - * - * @exception IndexOutOfBoundsException If the replacement string refers - * to a capturing group that does not exist in the pattern - */ - public boolean find (int start) - { - match = pattern.getRE().getMatch(input, start); - if (match != null) - { - position = match.getEndIndex(); - return true; - } - return false; - } - - /** - * @exception IllegalStateException If no match has yet been attempted, - * or if the previous match operation failed - */ - public String group () - { - assertMatchOp(); - return match.toString(); - } - - /** - * @param group The index of a capturing group in this matcher's pattern - * - * @exception IllegalStateException If no match has yet been attempted, - * or if the previous match operation failed - * @exception IndexOutOfBoundsException If the replacement string refers - * to a capturing group that does not exist in the pattern - */ - public String group (int group) - throws IllegalStateException - { - assertMatchOp(); - return match.toString(group); - } - - /** - * @param replacement The replacement string - */ - public String replaceFirst (String replacement) - { - reset(); - // Semantics might not quite match - return pattern.getRE().substitute(input, replacement, position); - } - - /** - * @param replacement The replacement string - */ - public String replaceAll (String replacement) - { - reset(); - return pattern.getRE().substituteAll(input, replacement, position); - } - - public int groupCount () - { - return pattern.getRE().getNumSubs(); - } - - public boolean lookingAt () - { - match = pattern.getRE().getMatch(input, 0); - if (match != null) - { - if (match.getStartIndex() == 0) - { - position = match.getEndIndex(); - return true; - } - match = null; - } - return false; - } - - /** - * Attempts to match the entire input sequence against the pattern. - * - * If the match succeeds then more information can be obtained via the - * start, end, and group methods. - * - * @see #start - * @see #end - * @see #group - */ - public boolean matches () - { - if (lookingAt()) - { - if (position == input.length()) - return true; - match = null; - } - return false; - } - - /** - * Returns the Pattern that is interpreted by this Matcher - */ - public Pattern pattern () - { - return pattern; - } - - public Matcher reset () - { - position = 0; - match = null; - return this; - } - - /** - * @param input The new input character sequence - */ - public Matcher reset (CharSequence input) - { - this.input = input; - return reset(); - } - - /** - * @param group The index of a capturing group in this matcher's pattern - * - * @exception IllegalStateException If no match has yet been attempted, - * or if the previous match operation failed - */ - public int start () - throws IllegalStateException - { - assertMatchOp(); - return match.getStartIndex(); - } - - /** - * @param group The index of a capturing group in this matcher's pattern - * - * @exception IllegalStateException If no match has yet been attempted, - * or if the previous match operation failed - * @exception IndexOutOfBoundsException If the replacement string refers - * to a capturing group that does not exist in the pattern - */ - public int start (int group) - throws IllegalStateException - { - assertMatchOp(); - return match.getStartIndex(group); - } - - private void assertMatchOp() - { - if (match == null) throw new IllegalStateException(); - } -} diff --git a/libjava/java/util/regex/Pattern.java b/libjava/java/util/regex/Pattern.java deleted file mode 100644 index ddd0c257800..00000000000 --- a/libjava/java/util/regex/Pattern.java +++ /dev/null @@ -1,253 +0,0 @@ -/* Pattern.java -- Compiled regular expression ready to be applied. - Copyright (C) 2002, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.util.regex; - -import gnu.regexp.RE; -import gnu.regexp.REException; -import gnu.regexp.RESyntax; - -import java.io.Serializable; -import java.util.ArrayList; - - -/** - * Compiled regular expression ready to be applied. - * - * @since 1.4 - */ -public final class Pattern implements Serializable -{ - private static final long serialVersionUID = 5073258162644648461L; - - public static final int CANON_EQ = 128; - public static final int CASE_INSENSITIVE = 2; - public static final int COMMENTS = 4; - public static final int DOTALL = 32; - public static final int MULTILINE = 8; - public static final int UNICODE_CASE = 64; - public static final int UNIX_LINES = 1; - - private final String regex; - private final int flags; - - private final RE re; - - private Pattern (String regex, int flags) - throws PatternSyntaxException - { - this.regex = regex; - this.flags = flags; - - int gnuFlags = 0; - if ((flags & CASE_INSENSITIVE) != 0) - gnuFlags |= RE.REG_ICASE; - if ((flags & MULTILINE) != 0) - gnuFlags |= RE.REG_MULTILINE; - if ((flags & DOTALL) != 0) - gnuFlags |= RE.REG_DOT_NEWLINE; - // not yet supported: - // if ((flags & UNICODE_CASE) != 0) gnuFlags = - // if ((flags & CANON_EQ) != 0) gnuFlags = - - RESyntax syntax = RESyntax.RE_SYNTAX_JAVA_1_4; - if ((flags & UNIX_LINES) != 0) - { - // Use a syntax set with \n for linefeeds? - syntax = new RESyntax(syntax); - syntax.setLineSeparator("\n"); - } - - if ((flags & COMMENTS) != 0) - { - // Use a syntax with support for comments? - } - - try - { - this.re = new RE(regex, gnuFlags, syntax); - } - catch (REException e) - { - throw new PatternSyntaxException(e.getMessage(), - regex, e.getPosition()); - } - } - - // package private accessor method - RE getRE() - { - return re; - } - - /** - * @param regex The regular expression - * - * @exception PatternSyntaxException If the expression's syntax is invalid - */ - public static Pattern compile (String regex) - throws PatternSyntaxException - { - return compile(regex, 0); - } - - /** - * @param regex The regular expression - * @param flags The match flags, a bit mask - * - * @exception PatternSyntaxException If the expression's syntax is invalid - * @exception IllegalArgumentException If bit values other than those - * corresponding to the defined match flags are set in flags - */ - public static Pattern compile (String regex, int flags) - throws PatternSyntaxException - { - // FIXME: check which flags are really accepted - if ((flags & ~0xEF) != 0) - throw new IllegalArgumentException (); - - return new Pattern (regex, flags); - } - - public int flags () - { - return this.flags; - } - - /** - * @param regex The regular expression - * @param input The character sequence to be matched - * - * @exception PatternSyntaxException If the expression's syntax is invalid - */ - public static boolean matches (String regex, CharSequence input) - { - return compile(regex).matcher(input).matches(); - } - - /** - * @param input The character sequence to be matched - */ - public Matcher matcher (CharSequence input) - { - return new Matcher(this, input); - } - - /** - * @param input The character sequence to be matched - */ - public String[] split (CharSequence input) - { - return split(input, 0); - } - - /** - * @param input The character sequence to be matched - * @param limit The result threshold - */ - public String[] split (CharSequence input, int limit) - { - Matcher matcher = new Matcher(this, input); - ArrayList list = new ArrayList(); - int empties = 0; - int count = 0; - int start = 0; - int end; - boolean matched; - - while (matched = matcher.find() && (limit <= 0 || count < limit - 1)) - { - ++count; - end = matcher.start(); - if (start == end) - empties++; - else - { - while (empties > 0) - { - list.add(""); - empties--; - } - - String text = input.subSequence(start, end).toString(); - list.add(text); - } - start = matcher.end(); - } - - // We matched nothing. - if (!matched && count == 0) - return new String[] { input.toString() }; - - // Is the last token empty? - boolean emptyLast = (start == input.length()); - - // Can/Must we add empties or an extra last token at the end? - if (list.size() < limit || limit < 0 || (limit == 0 && !emptyLast)) - { - if (limit > list.size()) - { - int max = limit - list.size(); - empties = (empties > max) ? max : empties; - } - while (empties > 0) - { - list.add(""); - empties--; - } - } - - // last token at end - if (limit != 0 || (limit == 0 && !emptyLast)) - { - String t = input.subSequence(start, input.length()).toString(); - if ("".equals(t) && limit == 0) - ; // Don't add. - else - list.add(t); - } - - String[] output = new String [list.size()]; - list.toArray(output); - return output; - } - - public String pattern () - { - return regex; - } -} diff --git a/libjava/java/util/regex/PatternSyntaxException.java b/libjava/java/util/regex/PatternSyntaxException.java deleted file mode 100644 index 0c80e119c37..00000000000 --- a/libjava/java/util/regex/PatternSyntaxException.java +++ /dev/null @@ -1,132 +0,0 @@ -/* PatternSyntaxException - Indicates illegal pattern for regular expression. - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.util.regex; - -/** - * Indicates illegal pattern for regular expression. - * Includes state to inspect the pattern and what and where the expression - * was not valid regular expression. - */ -public class PatternSyntaxException extends IllegalArgumentException -{ - private static final long serialVersionUID = -3864639126226059218L; - - /** - * Human readable escription of the syntax error. - */ - private final String desc; - - /** - * The original pattern that contained the syntax error. - */ - private final String pattern; - - /** - * Index of the first character in the String that was probably invalid, - * or -1 when unknown. - */ - private final int index; - - /** - * Creates a new PatternSyntaxException. - * - * @param description Human readable escription of the syntax error. - * @param pattern The original pattern that contained the syntax error. - * @param index Index of the first character in the String that was - * probably invalid, or -1 when unknown. - */ - public PatternSyntaxException(String description, - String pattern, - int index) - { - super(description); - this.desc = description; - this.pattern = pattern; - this.index = index; - } - - /** - * Returns a human readable escription of the syntax error. - */ - public String getDescription() - { - return desc; - } - - /** - * Returns the original pattern that contained the syntax error. - */ - public String getPattern() - { - return pattern; - } - - /** - * Returns the index of the first character in the String that was probably - * invalid, or -1 when unknown. - */ - public int getIndex() - { - return index; - } - - /** - * Returns a string containing a line with the description, a line with - * the original pattern and a line indicating with a ^ which character is - * probably the first invalid character in the pattern if the index is not - * negative. - */ - public String getMessage() - { - String lineSep = System.getProperty("line.separator"); - StringBuffer sb = new StringBuffer(desc); - sb.append(lineSep); - sb.append('\t'); - sb.append(pattern); - if (index != -1) - { - sb.append(lineSep); - sb.append('\t'); - for (int i=0; i<index; i++) - sb.append(' '); - sb.append('^'); - } - return sb.toString(); - } - -} diff --git a/libjava/java/util/zip/Adler32.java b/libjava/java/util/zip/Adler32.java deleted file mode 100644 index 7c411384057..00000000000 --- a/libjava/java/util/zip/Adler32.java +++ /dev/null @@ -1,205 +0,0 @@ -/* Adler32.java - Computes Adler32 data checksum of a data stream - Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.util.zip; - -/* - * Written using on-line Java Platform 1.2 API Specification, as well - * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998). - * The actual Adler32 algorithm is taken from RFC 1950. - * Status: Believed complete and correct. - */ - -/** - * Computes Adler32 checksum for a stream of data. An Adler32 - * checksum is not as reliable as a CRC32 checksum, but a lot faster to - * compute. - *<p> - * The specification for Adler32 may be found in RFC 1950. - * (ZLIB Compressed Data Format Specification version 3.3) - *<p> - *<p> - * From that document: - *<p> - * "ADLER32 (Adler-32 checksum) - * This contains a checksum value of the uncompressed data - * (excluding any dictionary data) computed according to Adler-32 - * algorithm. This algorithm is a 32-bit extension and improvement - * of the Fletcher algorithm, used in the ITU-T X.224 / ISO 8073 - * standard. - *<p> - * Adler-32 is composed of two sums accumulated per byte: s1 is - * the sum of all bytes, s2 is the sum of all s1 values. Both sums - * are done modulo 65521. s1 is initialized to 1, s2 to zero. The - * Adler-32 checksum is stored as s2*65536 + s1 in most- - * significant-byte first (network) order." - *<p> - * "8.2. The Adler-32 algorithm - *<p> - * The Adler-32 algorithm is much faster than the CRC32 algorithm yet - * still provides an extremely low probability of undetected errors. - *<p> - * The modulo on unsigned long accumulators can be delayed for 5552 - * bytes, so the modulo operation time is negligible. If the bytes - * are a, b, c, the second sum is 3a + 2b + c + 3, and so is position - * and order sensitive, unlike the first sum, which is just a - * checksum. That 65521 is prime is important to avoid a possible - * large class of two-byte errors that leave the check unchanged. - * (The Fletcher checksum uses 255, which is not prime and which also - * makes the Fletcher check insensitive to single byte changes 0 <-> - * 255.) - *<p> - * The sum s1 is initialized to 1 instead of zero to make the length - * of the sequence part of s2, so that the length does not have to be - * checked separately. (Any sequence of zeroes has a Fletcher - * checksum of zero.)" - * - * @author John Leuner, Per Bothner - * @since JDK 1.1 - * - * @see InflaterInputStream - * @see DeflaterOutputStream - */ -public class Adler32 implements Checksum -{ - - /** largest prime smaller than 65536 */ - private static final int BASE = 65521; - - private int checksum; //we do all in int. - - //Note that java doesn't have unsigned integers, - //so we have to be careful with what arithmetic - //we do. We return the checksum as a long to - //avoid sign confusion. - - /** - * Creates a new instance of the <code>Adler32</code> class. - * The checksum starts off with a value of 1. - */ - public Adler32 () - { - reset(); - } - - /** - * Resets the Adler32 checksum to the initial value. - */ - public void reset () - { - checksum = 1; //Initialize to 1 - } - - /** - * Updates the checksum with the byte b. - * - * @param bval the data value to add. The high byte of the int is ignored. - */ - public void update (int bval) - { - //We could make a length 1 byte array and call update again, but I - //would rather not have that overhead - int s1 = checksum & 0xffff; - int s2 = checksum >>> 16; - - s1 = (s1 + (bval & 0xFF)) % BASE; - s2 = (s1 + s2) % BASE; - - checksum = (s2 << 16) + s1; - } - - /** - * Updates the checksum with the bytes taken from the array. - * - * @param buffer an array of bytes - */ - public void update (byte[] buffer) - { - update(buffer, 0, buffer.length); - } - - /** - * Updates the checksum with the bytes taken from the array. - * - * @param buf an array of bytes - * @param off the start of the data used for this update - * @param len the number of bytes to use for this update - */ - public void update (byte[] buf, int off, int len) - { - //(By Per Bothner) - int s1 = checksum & 0xffff; - int s2 = checksum >>> 16; - - while (len > 0) - { - // We can defer the modulo operation: - // s1 maximally grows from 65521 to 65521 + 255 * 3800 - // s2 maximally grows by 3800 * median(s1) = 2090079800 < 2^31 - int n = 3800; - if (n > len) - n = len; - len -= n; - while (--n >= 0) - { - s1 = s1 + (buf[off++] & 0xFF); - s2 = s2 + s1; - } - s1 %= BASE; - s2 %= BASE; - } - - /*Old implementation, borrowed from somewhere: - int n; - - while (len-- > 0) { - - s1 = (s1 + (bs[offset++] & 0xff)) % BASE; - s2 = (s2 + s1) % BASE; - }*/ - - checksum = (s2 << 16) | s1; - } - - /** - * Returns the Adler32 data checksum computed so far. - */ - public long getValue() - { - return (long) checksum & 0xffffffffL; - } -} diff --git a/libjava/java/util/zip/CRC32.java b/libjava/java/util/zip/CRC32.java deleted file mode 100644 index 1c2b3973852..00000000000 --- a/libjava/java/util/zip/CRC32.java +++ /dev/null @@ -1,132 +0,0 @@ -/* CRC32.java - Computes CRC32 data checksum of a data stream - Copyright (C) 1999. 2000, 2001 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.util.zip; - -/* - * Written using on-line Java Platform 1.2 API Specification, as well - * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998). - * The actual CRC32 algorithm is taken from RFC 1952. - * Status: Believed complete and correct. - */ - -/** - * Computes CRC32 data checksum of a data stream. - * The actual CRC32 algorithm is described in RFC 1952 - * (GZIP file format specification version 4.3). - * Can be used to get the CRC32 over a stream if used with checked input/output - * streams. - * - * @see InflaterInputStream - * @see DeflaterOutputStream - * - * @author Per Bothner - * @date April 1, 1999. - */ -public class CRC32 implements Checksum -{ - /** The crc data checksum so far. */ - private int crc = 0; - - /** The fast CRC table. Computed once when the CRC32 class is loaded. */ - private static int[] crc_table = make_crc_table(); - - /** Make the table for a fast CRC. */ - private static int[] make_crc_table () - { - int[] crc_table = new int[256]; - for (int n = 0; n < 256; n++) - { - int c = n; - for (int k = 8; --k >= 0; ) - { - if ((c & 1) != 0) - c = 0xedb88320 ^ (c >>> 1); - else - c = c >>> 1; - } - crc_table[n] = c; - } - return crc_table; - } - - /** - * Returns the CRC32 data checksum computed so far. - */ - public long getValue () - { - return (long) crc & 0xffffffffL; - } - - /** - * Resets the CRC32 data checksum as if no update was ever called. - */ - public void reset () { crc = 0; } - - /** - * Updates the checksum with the int bval. - * - * @param bval (the byte is taken as the lower 8 bits of bval) - */ - - public void update (int bval) - { - int c = ~crc; - c = crc_table[(c ^ bval) & 0xff] ^ (c >>> 8); - crc = ~c; - } - - /** - * Adds the byte array to the data checksum. - * - * @param buf the buffer which contains the data - * @param off the offset in the buffer where the data starts - * @param len the length of the data - */ - public void update (byte[] buf, int off, int len) - { - int c = ~crc; - while (--len >= 0) - c = crc_table[(c ^ buf[off++]) & 0xff] ^ (c >>> 8); - crc = ~c; - } - - /** - * Adds the complete byte array to the data checksum. - */ - public void update (byte[] buf) { update(buf, 0, buf.length); } -} diff --git a/libjava/java/util/zip/CheckedInputStream.java b/libjava/java/util/zip/CheckedInputStream.java deleted file mode 100644 index d743fbb2447..00000000000 --- a/libjava/java/util/zip/CheckedInputStream.java +++ /dev/null @@ -1,135 +0,0 @@ -/* CheckedInputStream.java - Compute checksum of data being read - Copyright (C) 1999, 2000, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util.zip; - -import java.io.FilterInputStream; -import java.io.IOException; -import java.io.InputStream; - -/* Written using on-line Java Platform 1.2 API Specification - * and JCL book. - * Believed complete and correct. - */ - -/** - * InputStream that computes a checksum of the data being read using a - * supplied Checksum object. - * - * @see Checksum - * - * @author Tom Tromey - * @date May 17, 1999 - */ -public class CheckedInputStream extends FilterInputStream -{ - /** - * Creates a new CheckInputStream on top of the supplied OutputStream - * using the supplied Checksum. - */ - public CheckedInputStream (InputStream in, Checksum sum) - { - super (in); - this.sum = sum; - } - - /** - * Returns the Checksum object used. To get the data checksum computed so - * far call <code>getChecksum.getValue()</code>. - */ - public Checksum getChecksum () - { - return sum; - } - - /** - * Reads one byte, updates the checksum and returns the read byte - * (or -1 when the end of file was reached). - */ - public int read () throws IOException - { - int x = in.read(); - if (x != -1) - sum.update(x); - return x; - } - - /** - * Reads at most len bytes in the supplied buffer and updates the checksum - * with it. Returns the number of bytes actually read or -1 when the end - * of file was reached. - */ - public int read (byte[] buf, int off, int len) throws IOException - { - int r = in.read(buf, off, len); - if (r != -1) - sum.update(buf, off, r); - return r; - } - - /** - * Skips n bytes by reading them in a temporary buffer and updating the - * the checksum with that buffer. Returns the actual number of bytes skiped - * which can be less then requested when the end of file is reached. - */ - public long skip (long n) throws IOException - { - if (n == 0) - return 0; - - int min = (int) Math.min(n, 1024); - byte[] buf = new byte[min]; - - long s = 0; - while (n > 0) - { - int r = in.read(buf, 0, min); - if (r == -1) - break; - n -= r; - s += r; - min = (int) Math.min(n, 1024); - sum.update(buf, 0, r); - } - - return s; - } - - /** The checksum object. */ - private Checksum sum; -} diff --git a/libjava/java/util/zip/CheckedOutputStream.java b/libjava/java/util/zip/CheckedOutputStream.java deleted file mode 100644 index a3c19292fae..00000000000 --- a/libjava/java/util/zip/CheckedOutputStream.java +++ /dev/null @@ -1,100 +0,0 @@ -/* CheckedOutputStream.java - Compute checksum of data being written. - Copyright (C) 1999, 2000 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util.zip; - -import java.io.FilterOutputStream; -import java.io.IOException; -import java.io.OutputStream; - -/* Written using on-line Java Platform 1.2 API Specification - * and JCL book. - * Believed complete and correct. - */ - -/** - * OutputStream that computes a checksum of data being written using a - * supplied Checksum object. - * - * @see Checksum - * - * @author Tom Tromey - * @date May 17, 1999 - */ -public class CheckedOutputStream extends FilterOutputStream -{ - /** - * Creates a new CheckInputStream on top of the supplied OutputStream - * using the supplied Checksum. - */ - public CheckedOutputStream (OutputStream out, Checksum cksum) - { - super (out); - this.sum = cksum; - } - - /** - * Returns the Checksum object used. To get the data checksum computed so - * far call <code>getChecksum.getValue()</code>. - */ - public Checksum getChecksum () - { - return sum; - } - - /** - * Writes one byte to the OutputStream and updates the Checksum. - */ - public void write (int bval) throws IOException - { - out.write(bval); - sum.update(bval); - } - - /** - * Writes the byte array to the OutputStream and updates the Checksum. - */ - public void write (byte[] buf, int off, int len) throws IOException - { - out.write(buf, off, len); - sum.update(buf, off, len); - } - - /** The checksum object. */ - private Checksum sum; -} diff --git a/libjava/java/util/zip/Checksum.java b/libjava/java/util/zip/Checksum.java deleted file mode 100644 index 3342ba3a609..00000000000 --- a/libjava/java/util/zip/Checksum.java +++ /dev/null @@ -1,86 +0,0 @@ -/* Checksum.java - Interface to compute a data checksum - Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.util.zip; - -/* - * Written using on-line Java Platform 1.2 API Specification, as well - * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998). - * Status: Believed complete and correct. - */ - -/** - * Interface to compute a data checksum used by checked input/output streams. - * A data checksum can be updated by one byte or with a byte array. After each - * update the value of the current checksum can be returned by calling - * <code>getValue</code>. The complete checksum object can also be reset - * so it can be used again with new data. - * - * @see CheckedInputStream - * @see CheckedOutputStream - * - * @author Per Bothner - * @author Jochen Hoenicke - */ -public interface Checksum -{ - /** - * Returns the data checksum computed so far. - */ - long getValue(); - - /** - * Resets the data checksum as if no update was ever called. - */ - void reset(); - - /** - * Adds one byte to the data checksum. - * - * @param bval the data value to add. The high byte of the int is ignored. - */ - void update (int bval); - - /** - * Adds the byte array to the data checksum. - * - * @param buf the buffer which contains the data - * @param off the offset in the buffer where the data starts - * @param len the length of the data - */ - void update (byte[] buf, int off, int len); -} diff --git a/libjava/java/util/zip/DataFormatException.java b/libjava/java/util/zip/DataFormatException.java deleted file mode 100644 index dc5b10dec90..00000000000 --- a/libjava/java/util/zip/DataFormatException.java +++ /dev/null @@ -1,71 +0,0 @@ -/* DataformatException.java -- thrown when compressed data is corrupt - Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.util.zip; - -/** - * Exception thrown when compressed data is corrupt. - * - * @author Tom Tromey - * @author John Leuner - * @since 1.1 - * @status updated to 1.4 - */ -public class DataFormatException extends Exception -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = 2219632870893641452L; - - /** - * Create an exception without a message. - */ - public DataFormatException() - { - } - - /** - * Create an exception with a message. - * - * @param msg the message - */ - public DataFormatException(String msg) - { - super(msg); - } -} diff --git a/libjava/java/util/zip/ZipConstants.java b/libjava/java/util/zip/ZipConstants.java deleted file mode 100644 index 952a44def4c..00000000000 --- a/libjava/java/util/zip/ZipConstants.java +++ /dev/null @@ -1,97 +0,0 @@ -/* java.util.zip.ZipConstants - Copyright (C) 2001 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.util.zip; - -interface ZipConstants -{ - /* The local file header */ - int LOCHDR = 30; - int LOCSIG = 'P'|('K'<<8)|(3<<16)|(4<<24); - - int LOCVER = 4; - int LOCFLG = 6; - int LOCHOW = 8; - int LOCTIM = 10; - int LOCCRC = 14; - int LOCSIZ = 18; - int LOCLEN = 22; - int LOCNAM = 26; - int LOCEXT = 28; - - /* The Data descriptor */ - int EXTSIG = 'P'|('K'<<8)|(7<<16)|(8<<24); - int EXTHDR = 16; - - int EXTCRC = 4; - int EXTSIZ = 8; - int EXTLEN = 12; - - /* The central directory file header */ - int CENSIG = 'P'|('K'<<8)|(1<<16)|(2<<24); - int CENHDR = 46; - - int CENVEM = 4; - int CENVER = 6; - int CENFLG = 8; - int CENHOW = 10; - int CENTIM = 12; - int CENCRC = 16; - int CENSIZ = 20; - int CENLEN = 24; - int CENNAM = 28; - int CENEXT = 30; - int CENCOM = 32; - int CENDSK = 34; - int CENATT = 36; - int CENATX = 38; - int CENOFF = 42; - - /* The entries in the end of central directory */ - int ENDSIG = 'P'|('K'<<8)|(5<<16)|(6<<24); - int ENDHDR = 22; - - /* The following two fields are missing in SUN JDK */ - int ENDNRD = 4; - int ENDDCD = 6; - int ENDSUB = 8; - int ENDTOT = 10; - int ENDSIZ = 12; - int ENDOFF = 16; - int ENDCOM = 20; -} - diff --git a/libjava/java/util/zip/ZipException.java b/libjava/java/util/zip/ZipException.java deleted file mode 100644 index c5bfc1e7c39..00000000000 --- a/libjava/java/util/zip/ZipException.java +++ /dev/null @@ -1,72 +0,0 @@ -/* ZipException.java - exception representing a zip related error - Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.util.zip; - -import java.io.IOException; - -/** - * Thrown during the creation or input of a zip file. - * - * @author Jochen Hoenicke - * @author Per Bothner - * @status updated to 1.4 - */ -public class ZipException extends IOException -{ - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = 8000196834066748623L; - - /** - * Create an exception without a message. - */ - public ZipException() - { - } - - /** - * Create an exception with a message. - * - * @param msg the message - */ - public ZipException (String msg) - { - super(msg); - } -} diff --git a/libjava/java/util/zip/ZipInputStream.java b/libjava/java/util/zip/ZipInputStream.java deleted file mode 100644 index 5732523238e..00000000000 --- a/libjava/java/util/zip/ZipInputStream.java +++ /dev/null @@ -1,371 +0,0 @@ -/* ZipInputStream.java -- - Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util.zip; - -import java.io.EOFException; -import java.io.IOException; -import java.io.InputStream; - -/** - * This is a FilterInputStream that reads the files in an zip archive - * one after another. It has a special method to get the zip entry of - * the next file. The zip entry contains information about the file name - * size, compressed size, CRC, etc. - * - * It includes support for STORED and DEFLATED entries. - * - * @author Jochen Hoenicke - */ -public class ZipInputStream extends InflaterInputStream implements ZipConstants -{ - private CRC32 crc = new CRC32(); - private ZipEntry entry = null; - - private int csize; - private int size; - private int method; - private int flags; - private int avail; - private boolean entryAtEOF; - - /** - * Creates a new Zip input stream, reading a zip archive. - */ - public ZipInputStream(InputStream in) - { - super(in, new Inflater(true)); - } - - private void fillBuf() throws IOException - { - avail = len = in.read(buf, 0, buf.length); - } - - private int readBuf(byte[] out, int offset, int length) throws IOException - { - if (avail <= 0) - { - fillBuf(); - if (avail <= 0) - return -1; - } - if (length > avail) - length = avail; - System.arraycopy(buf, len - avail, out, offset, length); - avail -= length; - return length; - } - - private void readFully(byte[] out) throws IOException - { - int off = 0; - int len = out.length; - while (len > 0) - { - int count = readBuf(out, off, len); - if (count == -1) - throw new EOFException(); - off += count; - len -= count; - } - } - - private int readLeByte() throws IOException - { - if (avail <= 0) - { - fillBuf(); - if (avail <= 0) - throw new ZipException("EOF in header"); - } - return buf[len - avail--] & 0xff; - } - - /** - * Read an unsigned short in little endian byte order. - */ - private int readLeShort() throws IOException - { - return readLeByte() | (readLeByte() << 8); - } - - /** - * Read an int in little endian byte order. - */ - private int readLeInt() throws IOException - { - return readLeShort() | (readLeShort() << 16); - } - - /** - * Open the next entry from the zip archive, and return its description. - * If the previous entry wasn't closed, this method will close it. - */ - public ZipEntry getNextEntry() throws IOException - { - if (crc == null) - throw new IOException("Stream closed."); - if (entry != null) - closeEntry(); - - int header = readLeInt(); - if (header == CENSIG) - { - /* Central Header reached. */ - close(); - return null; - } - if (header != LOCSIG) - throw new ZipException("Wrong Local header signature: " - + Integer.toHexString(header)); - /* skip version */ - readLeShort(); - flags = readLeShort(); - method = readLeShort(); - int dostime = readLeInt(); - int crc = readLeInt(); - csize = readLeInt(); - size = readLeInt(); - int nameLen = readLeShort(); - int extraLen = readLeShort(); - - if (method == ZipOutputStream.STORED && csize != size) - throw new ZipException("Stored, but compressed != uncompressed"); - - - byte[] buffer = new byte[nameLen]; - readFully(buffer); - String name = new String(buffer); - - entry = createZipEntry(name); - entryAtEOF = false; - entry.setMethod(method); - if ((flags & 8) == 0) - { - entry.setCrc(crc & 0xffffffffL); - entry.setSize(size & 0xffffffffL); - entry.setCompressedSize(csize & 0xffffffffL); - } - entry.setDOSTime(dostime); - if (extraLen > 0) - { - byte[] extra = new byte[extraLen]; - readFully(extra); - entry.setExtra(extra); - } - - if (method == ZipOutputStream.DEFLATED && avail > 0) - { - System.arraycopy(buf, len - avail, buf, 0, avail); - len = avail; - avail = 0; - inf.setInput(buf, 0, len); - } - return entry; - } - - private void readDataDescr() throws IOException - { - if (readLeInt() != EXTSIG) - throw new ZipException("Data descriptor signature not found"); - entry.setCrc(readLeInt() & 0xffffffffL); - csize = readLeInt(); - size = readLeInt(); - entry.setSize(size & 0xffffffffL); - entry.setCompressedSize(csize & 0xffffffffL); - } - - /** - * Closes the current zip entry and moves to the next one. - */ - public void closeEntry() throws IOException - { - if (crc == null) - throw new IOException("Stream closed."); - if (entry == null) - return; - - if (method == ZipOutputStream.DEFLATED) - { - if ((flags & 8) != 0) - { - /* We don't know how much we must skip, read until end. */ - byte[] tmp = new byte[2048]; - while (read(tmp) > 0) - ; - /* read will close this entry */ - return; - } - csize -= inf.getTotalIn(); - avail = inf.getRemaining(); - } - - if (avail > csize && csize >= 0) - avail -= csize; - else - { - csize -= avail; - avail = 0; - while (csize != 0) - { - long skipped = in.skip(csize & 0xffffffffL); - if (skipped <= 0) - throw new ZipException("zip archive ends early."); - csize -= skipped; - } - } - - size = 0; - crc.reset(); - if (method == ZipOutputStream.DEFLATED) - inf.reset(); - entry = null; - entryAtEOF = true; - } - - public int available() throws IOException - { - return entryAtEOF ? 0 : 1; - } - - /** - * Reads a byte from the current zip entry. - * @return the byte or -1 on EOF. - * @exception IOException if a i/o error occured. - * @exception ZipException if the deflated stream is corrupted. - */ - public int read() throws IOException - { - byte[] b = new byte[1]; - if (read(b, 0, 1) <= 0) - return -1; - return b[0] & 0xff; - } - - /** - * Reads a block of bytes from the current zip entry. - * @return the number of bytes read (may be smaller, even before - * EOF), or -1 on EOF. - * @exception IOException if a i/o error occured. - * @exception ZipException if the deflated stream is corrupted. - */ - public int read(byte[] b, int off, int len) throws IOException - { - if (len == 0) - return 0; - if (crc == null) - throw new IOException("Stream closed."); - if (entry == null) - return -1; - boolean finished = false; - switch (method) - { - case ZipOutputStream.DEFLATED: - len = super.read(b, off, len); - if (len < 0) - { - if (!inf.finished()) - throw new ZipException("Inflater not finished!?"); - avail = inf.getRemaining(); - if ((flags & 8) != 0) - readDataDescr(); - - if (inf.getTotalIn() != csize - || inf.getTotalOut() != size) - throw new ZipException("size mismatch: "+csize+";"+size+" <-> "+inf.getTotalIn()+";"+inf.getTotalOut()); - inf.reset(); - finished = true; - } - break; - - case ZipOutputStream.STORED: - - if (len > csize && csize >= 0) - len = csize; - - len = readBuf(b, off, len); - if (len > 0) - { - csize -= len; - size -= len; - } - - if (csize == 0) - finished = true; - else if (len < 0) - throw new ZipException("EOF in stored block"); - break; - } - - if (len > 0) - crc.update(b, off, len); - - if (finished) - { - if ((crc.getValue() & 0xffffffffL) != entry.getCrc()) - throw new ZipException("CRC mismatch"); - crc.reset(); - entry = null; - entryAtEOF = true; - } - return len; - } - - /** - * Closes the zip file. - * @exception IOException if a i/o error occured. - */ - public void close() throws IOException - { - super.close(); - crc = null; - entry = null; - entryAtEOF = true; - } - - /** - * Creates a new zip entry for the given name. This is equivalent - * to new ZipEntry(name). - * @param name the name of the zip entry. - */ - protected ZipEntry createZipEntry(String name) - { - return new ZipEntry(name); - } -} diff --git a/libjava/java/util/zip/ZipOutputStream.java b/libjava/java/util/zip/ZipOutputStream.java deleted file mode 100644 index 5699ff046f5..00000000000 --- a/libjava/java/util/zip/ZipOutputStream.java +++ /dev/null @@ -1,399 +0,0 @@ -/* ZipOutputStream.java -- - Copyright (C) 2001, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.util.zip; - -import java.io.IOException; -import java.io.OutputStream; -import java.util.Enumeration; -import java.util.Vector; - -/** - * This is a FilterOutputStream that writes the files into a zip - * archive one after another. It has a special method to start a new - * zip entry. The zip entries contains information about the file name - * size, compressed size, CRC, etc. - * - * It includes support for STORED and DEFLATED entries. - * - * This class is not thread safe. - * - * @author Jochen Hoenicke - */ -public class ZipOutputStream extends DeflaterOutputStream implements ZipConstants -{ - private Vector entries = new Vector(); - private CRC32 crc = new CRC32(); - private ZipEntry curEntry = null; - - private int curMethod; - private int size; - private int offset = 0; - - private byte[] zipComment = new byte[0]; - private int defaultMethod = DEFLATED; - - /** - * Our Zip version is hard coded to 1.0 resp. 2.0 - */ - private static final int ZIP_STORED_VERSION = 10; - private static final int ZIP_DEFLATED_VERSION = 20; - - /** - * Compression method. This method doesn't compress at all. - */ - public static final int STORED = 0; - - /** - * Compression method. This method uses the Deflater. - */ - public static final int DEFLATED = 8; - - /** - * Creates a new Zip output stream, writing a zip archive. - * @param out the output stream to which the zip archive is written. - */ - public ZipOutputStream(OutputStream out) - { - super(out, new Deflater(Deflater.DEFAULT_COMPRESSION, true)); - } - - /** - * Set the zip file comment. - * @param comment the comment. - * @exception IllegalArgumentException if encoding of comment is - * longer than 0xffff bytes. - */ - public void setComment(String comment) - { - byte[] commentBytes; - commentBytes = comment.getBytes(); - if (commentBytes.length > 0xffff) - throw new IllegalArgumentException("Comment too long."); - zipComment = commentBytes; - } - - /** - * Sets default compression method. If the Zip entry specifies - * another method its method takes precedence. - * @param method the method. - * @exception IllegalArgumentException if method is not supported. - * @see #STORED - * @see #DEFLATED - */ - public void setMethod(int method) - { - if (method != STORED && method != DEFLATED) - throw new IllegalArgumentException("Method not supported."); - defaultMethod = method; - } - - /** - * Sets default compression level. The new level will be activated - * immediately. - * @exception IllegalArgumentException if level is not supported. - * @see Deflater - */ - public void setLevel(int level) - { - def.setLevel(level); - } - - /** - * Write an unsigned short in little endian byte order. - */ - private void writeLeShort(int value) throws IOException - { - out.write(value & 0xff); - out.write((value >> 8) & 0xff); - } - - /** - * Write an int in little endian byte order. - */ - private void writeLeInt(int value) throws IOException - { - writeLeShort(value); - writeLeShort(value >> 16); - } - - /** - * Starts a new Zip entry. It automatically closes the previous - * entry if present. If the compression method is stored, the entry - * must have a valid size and crc, otherwise all elements (except - * name) are optional, but must be correct if present. If the time - * is not set in the entry, the current time is used. - * @param entry the entry. - * @exception IOException if an I/O error occured. - * @exception ZipException if stream was finished. - */ - public void putNextEntry(ZipEntry entry) throws IOException - { - if (entries == null) - throw new ZipException("ZipOutputStream was finished"); - - int method = entry.getMethod(); - int flags = 0; - if (method == -1) - method = defaultMethod; - - if (method == STORED) - { - if (entry.getCompressedSize() >= 0) - { - if (entry.getSize() < 0) - entry.setSize(entry.getCompressedSize()); - else if (entry.getSize() != entry.getCompressedSize()) - throw new ZipException - ("Method STORED, but compressed size != size"); - } - else - entry.setCompressedSize(entry.getSize()); - - if (entry.getSize() < 0) - throw new ZipException("Method STORED, but size not set"); - if (entry.getCrc() < 0) - throw new ZipException("Method STORED, but crc not set"); - } - else if (method == DEFLATED) - { - if (entry.getCompressedSize() < 0 - || entry.getSize() < 0 || entry.getCrc() < 0) - flags |= 8; - } - - if (curEntry != null) - closeEntry(); - - if (entry.getTime() < 0) - entry.setTime(System.currentTimeMillis()); - - entry.flags = flags; - entry.offset = offset; - entry.setMethod(method); - curMethod = method; - /* Write the local file header */ - writeLeInt(LOCSIG); - writeLeShort(method == STORED - ? ZIP_STORED_VERSION : ZIP_DEFLATED_VERSION); - writeLeShort(flags); - writeLeShort(method); - writeLeInt(entry.getDOSTime()); - if ((flags & 8) == 0) - { - writeLeInt((int)entry.getCrc()); - writeLeInt((int)entry.getCompressedSize()); - writeLeInt((int)entry.getSize()); - } - else - { - writeLeInt(0); - writeLeInt(0); - writeLeInt(0); - } - byte[] name = entry.getName().getBytes(); - if (name.length > 0xffff) - throw new ZipException("Name too long."); - byte[] extra = entry.getExtra(); - if (extra == null) - extra = new byte[0]; - writeLeShort(name.length); - writeLeShort(extra.length); - out.write(name); - out.write(extra); - - offset += LOCHDR + name.length + extra.length; - - /* Activate the entry. */ - - curEntry = entry; - crc.reset(); - if (method == DEFLATED) - def.reset(); - size = 0; - } - - /** - * Closes the current entry. - * @exception IOException if an I/O error occured. - * @exception ZipException if no entry is active. - */ - public void closeEntry() throws IOException - { - if (curEntry == null) - throw new ZipException("No open entry"); - - /* First finish the deflater, if appropriate */ - if (curMethod == DEFLATED) - super.finish(); - - int csize = curMethod == DEFLATED ? def.getTotalOut() : size; - - if (curEntry.getSize() < 0) - curEntry.setSize(size); - else if (curEntry.getSize() != size) - throw new ZipException("size was "+size - +", but I expected "+curEntry.getSize()); - - if (curEntry.getCompressedSize() < 0) - curEntry.setCompressedSize(csize); - else if (curEntry.getCompressedSize() != csize) - throw new ZipException("compressed size was "+csize - +", but I expected "+curEntry.getSize()); - - if (curEntry.getCrc() < 0) - curEntry.setCrc(crc.getValue()); - else if (curEntry.getCrc() != crc.getValue()) - throw new ZipException("crc was " + Long.toHexString(crc.getValue()) - + ", but I expected " - + Long.toHexString(curEntry.getCrc())); - - offset += csize; - - /* Now write the data descriptor entry if needed. */ - if (curMethod == DEFLATED && (curEntry.flags & 8) != 0) - { - writeLeInt(EXTSIG); - writeLeInt((int)curEntry.getCrc()); - writeLeInt((int)curEntry.getCompressedSize()); - writeLeInt((int)curEntry.getSize()); - offset += EXTHDR; - } - - entries.addElement(curEntry); - curEntry = null; - } - - /** - * Writes the given buffer to the current entry. - * @exception IOException if an I/O error occured. - * @exception ZipException if no entry is active. - */ - public void write(byte[] b, int off, int len) throws IOException - { - if (curEntry == null) - throw new ZipException("No open entry."); - - switch (curMethod) - { - case DEFLATED: - super.write(b, off, len); - break; - - case STORED: - out.write(b, off, len); - break; - } - - crc.update(b, off, len); - size += len; - } - - /** - * Finishes the stream. This will write the central directory at the - * end of the zip file and flush the stream. - * @exception IOException if an I/O error occured. - */ - public void finish() throws IOException - { - if (entries == null) - return; - if (curEntry != null) - closeEntry(); - - int numEntries = 0; - int sizeEntries = 0; - - Enumeration e = entries.elements(); - while (e.hasMoreElements()) - { - ZipEntry entry = (ZipEntry) e.nextElement(); - - int method = entry.getMethod(); - writeLeInt(CENSIG); - writeLeShort(method == STORED - ? ZIP_STORED_VERSION : ZIP_DEFLATED_VERSION); - writeLeShort(method == STORED - ? ZIP_STORED_VERSION : ZIP_DEFLATED_VERSION); - writeLeShort(entry.flags); - writeLeShort(method); - writeLeInt(entry.getDOSTime()); - writeLeInt((int)entry.getCrc()); - writeLeInt((int)entry.getCompressedSize()); - writeLeInt((int)entry.getSize()); - - byte[] name = entry.getName().getBytes(); - if (name.length > 0xffff) - throw new ZipException("Name too long."); - byte[] extra = entry.getExtra(); - if (extra == null) - extra = new byte[0]; - String strComment = entry.getComment(); - byte[] comment = strComment != null - ? strComment.getBytes() : new byte[0]; - if (comment.length > 0xffff) - throw new ZipException("Comment too long."); - - writeLeShort(name.length); - writeLeShort(extra.length); - writeLeShort(comment.length); - writeLeShort(0); /* disk number */ - writeLeShort(0); /* internal file attr */ - writeLeInt(0); /* external file attr */ - writeLeInt(entry.offset); - - out.write(name); - out.write(extra); - out.write(comment); - numEntries++; - sizeEntries += CENHDR + name.length + extra.length + comment.length; - } - - writeLeInt(ENDSIG); - writeLeShort(0); /* disk number */ - writeLeShort(0); /* disk with start of central dir */ - writeLeShort(numEntries); - writeLeShort(numEntries); - writeLeInt(sizeEntries); - writeLeInt(offset); - writeLeShort(zipComment.length); - out.write(zipComment); - out.flush(); - entries = null; - } -} |